extragear/multimedia/amarok/src
Alejandro Daniel Wainzinger
aikawarazuni at gmail.com
Tue Jul 15 19:31:58 CEST 2008
SVN commit 832869 by awainzinger:
When tags get edited, the updates happen one by one. There's no built-in system for dealing with a final update after all metadata changes have been registered, such as forcing a collection to update to no longer display possibly now-gone artists etc.
Introducing the UpdateCapability! Self-explanatory for the most part. Only implemented in IpodTrack for the moment, but works like a charm.
CCMAIL: amarok-devel at kde.org
M +1 -0 CMakeLists.txt
M +2 -0 collection/Collection.h
M +1 -0 collection/ipodcollection/IpodCollection.cpp
M +3 -1 collection/ipodcollection/IpodCollection.h
M +31 -21 collection/ipodcollection/IpodMeta.cpp
M +30 -0 dialogs/TagDialog.cpp
M +2 -1 meta/Capability.h
A meta/UpdateCapability.cpp [License: GPL (v2+)]
A meta/UpdateCapability.h [License: GPL (v2+)]
--- trunk/extragear/multimedia/amarok/src/CMakeLists.txt #832868:832869
@@ -201,6 +201,7 @@
meta/PlaylistFileSupport.cpp
meta/SourceInfoCapability.cpp
meta/StreamInfoCapability.cpp
+ meta/UpdateCapability.cpp
meta/XSPFPlaylist.cpp
meta/file/File.cpp
meta/proxy/MetaProxy.cpp
--- trunk/extragear/multimedia/amarok/src/collection/Collection.h #832868:832869
@@ -70,6 +70,8 @@
virtual QString collectionId() const = 0;
virtual QString prettyName() const = 0;
+ virtual void collectionUpdated() { emit updated(); }
+
virtual CollectionLocation* location() const;
//convenience methods so that it is not necessary to create a CollectionLocation
--- trunk/extragear/multimedia/amarok/src/collection/ipodcollection/IpodCollection.cpp #832868:832869
@@ -261,6 +261,7 @@
void
IpodCollection::updateTags( Meta::IpodTrack *track)
{
+ DEBUG_BLOCK
Meta::IpodTrackPtr trackPtr( track );
KUrl trackUrl = KUrl::fromPath( trackPtr->url() );
--- trunk/extragear/multimedia/amarok/src/collection/ipodcollection/IpodCollection.h #832868:832869
@@ -23,6 +23,8 @@
#include <gpod/itdb.h>
}
+#include "Debug.h"
+
#include "Collection.h"
#include "MemoryCollection.h"
#include "IpodHandler.h"
@@ -83,7 +85,7 @@
virtual QString collectionId() const;
virtual QString prettyName() const;
- void collectionUpdated() { emit updated(); }
+ virtual void collectionUpdated() { DEBUG_BLOCK emit updated(); }
Ipod::IpodHandler* handler() { return m_handler; }
--- trunk/extragear/multimedia/amarok/src/collection/ipodcollection/IpodMeta.cpp #832868:832869
@@ -28,6 +28,7 @@
#include "SvgHandler.h"
#include "meta/EditCapability.h"
#include "meta/CustomActionsCapability.h"
+#include "meta/UpdateCapability.h"
#include "context/popupdropper/PopupDropperAction.h"
@@ -129,7 +130,22 @@
};
+class UpdateCapabilityIpod : public Meta::UpdateCapability
+{
+ Q_OBJECT
+ public:
+ UpdateCapabilityIpod( IpodTrack *track )
+ : Meta::UpdateCapability()
+ , m_track( track ) {}
+ virtual void collectionUpdated() const { m_track->collection()->collectionUpdated(); }
+
+
+ private:
+ KSharedPtr<IpodTrack> m_track;
+};
+
+
IpodTrack::IpodTrack( IpodCollection *collection, const QString &format)
: Meta::Track()
, m_collection( collection )
@@ -427,6 +443,8 @@
return true;
case Meta::Capability::CustomActions:
return true;
+ case Meta::Capability::Updatable:
+ return true;
default:
return false;
@@ -443,6 +461,8 @@
return new EditCapabilityIpod( this );
case Meta::Capability::CustomActions:
return new CustomActionsCapabilityIpod( this );
+ case Meta::Capability::Updatable:
+ return new UpdateCapabilityIpod( this );
default:
return 0;
@@ -490,10 +510,6 @@
m_collection->setAlbumMap( albumMap );
m_collection->releaseLock();
- // Also update info in ipod's database
-
- m_collection->updateTags( this );
-
}
void
@@ -538,15 +554,12 @@
m_collection->setArtistMap( artistMap );
m_collection->releaseLock();
- // Also update info in ipod's database
-
- m_collection->updateTags( this );
-
}
void
IpodTrack::setGenre( const QString &newGenre )
{
+ DEBUG_BLOCK
IpodGenrePtr genrePtr;
IpodTrackPtr track( this );
@@ -585,15 +598,12 @@
m_collection->setGenreMap( genreMap );
m_collection->releaseLock();
- // Also update info in ipod's database
-
- m_collection->updateTags( this );
-
}
void
IpodTrack::setComposer( const QString &newComposer )
{
+ DEBUG_BLOCK
IpodComposerPtr composerPtr;
IpodTrackPtr track( this );
@@ -632,15 +642,12 @@
m_collection->setComposerMap( composerMap );
m_collection->releaseLock();
- // Also update info in ipod's database
-
- m_collection->updateTags( this );
-
}
void
IpodTrack::setYear( const QString &newYear )
{
+ DEBUG_BLOCK
IpodYearPtr yearPtr;
IpodTrackPtr track( this );
@@ -679,10 +686,6 @@
m_collection->setYearMap( yearMap );
m_collection->releaseLock();
- // Also update info in ipod's database
-
- m_collection->updateTags( this );
-
}
void
@@ -736,9 +739,16 @@
void
IpodTrack::endMetaDataUpdate()
{
+ // Update info in ipod's database
+
+ m_collection->updateTags( this );
m_collection->writeDatabase();
+
// hack to force refresh of collection in treeview
- m_collection->collectionUpdated();
+
+// m_collection->collectionUpdated();
+
+ notifyObservers();
}
//IpodArtist
--- trunk/extragear/multimedia/amarok/src/dialogs/TagDialog.cpp #832868:832869
@@ -35,6 +35,7 @@
#include "TagGuesser.h"
#include "trackpickerdialog.h"
#include "ui_tagdialogbase.h"
+#include "UpdateCapability.h"
#include <KApplication>
#include <KComboBox>
@@ -55,6 +56,7 @@
#include <QFile>
#include <QLabel>
#include <QLayout>
+#include <QMap>
#include <QPair>
#include <QPushButton>
#include <QTimer>
@@ -1455,6 +1457,34 @@
ec->setDiscNumber( data.value( Meta::Field::DISCNUMBER ).toInt() );
ec->endMetaDataUpdate();
}
+
+ // build a map, such that at least one track represents a unique collection
+
+ QMap<QString, Meta::TrackPtr> collectionsToUpdateMap;
+
+ foreach( Meta::TrackPtr track, m_tracks )
+ {
+ Meta::UpdateCapability *uc = track->as<Meta::UpdateCapability>();
+ if( !uc )
+ {
+ continue;
+ }
+
+ QString collId = track->collection()->collectionId();
+
+ if( !collectionsToUpdateMap.contains( collId ) )
+ collectionsToUpdateMap.insert( collId, track );
+ }
+
+ // use the representative tracks to send updated signals
+
+ foreach( Meta::TrackPtr track, collectionsToUpdateMap.values() )
+ {
+ Meta::UpdateCapability *uc = track->as<Meta::UpdateCapability>();
+
+ uc->collectionUpdated();
+ }
+
//TODO: port 2.0
/*
QMap<QString, QStringList>::ConstIterator endLabels( newLabels.constEnd() );
--- trunk/extragear/multimedia/amarok/src/meta/Capability.h #832868:832869
@@ -42,7 +42,8 @@
, Organisable = 7
, SourceInfo = 8
, CurrentTrackActions = 9
- , StreamInfo = 10};
+ , StreamInfo = 10
+ , Updatable = 11};
virtual ~Capability();
More information about the Amarok-devel
mailing list