[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [amarok] src/core-impl/collections/umscollection: UmsCollection: when tracks are changed, update col
From: Matěj_Laitl <matej () laitl ! cz>
Date: 2012-05-05 12:49:14
Message-ID: 20120505124914.C1F92A60BB () git ! kde ! org
[Download RAW message or body]
Git commit b529db57c47c62f7a2e87c322770c7cf89d6f962 by Matěj Laitl.
Committed on 02/05/2012 at 01:42.
Pushed by laitl into branch 'master'.
UmsCollection: when tracks are changed, update collection more promptly
This is a rip-off of commit 7a8edcd8dffb6d682e19ea4b5738cf939dee1267
applied to IpodCollection.
M +19 -4 src/core-impl/collections/umscollection/UmsCollection.cpp
M +7 -1 src/core-impl/collections/umscollection/UmsCollection.h
http://commits.kde.org/amarok/b529db57c47c62f7a2e87c322770c7cf89d6f962
diff --git a/src/core-impl/collections/umscollection/UmsCollection.cpp \
b/src/core-impl/collections/umscollection/UmsCollection.cpp index 1471c51..033451e \
100644
--- a/src/core-impl/collections/umscollection/UmsCollection.cpp
+++ b/src/core-impl/collections/umscollection/UmsCollection.cpp
@@ -225,12 +225,13 @@ UmsCollection::UmsCollection( Solid::Device device )
, m_replaceText( QString() )
, m_collectionName( QString() )
, m_scanManager( 0 )
+ , m_lastUpdated( 0 )
{
debug() << "Creating UmsCollection for device with udi: " << m_device.udi();
m_updateTimer.setSingleShot( true );
connect( this, SIGNAL(startUpdateTimer()), SLOT(slotStartUpdateTimer()) );
- connect( &m_updateTimer, SIGNAL(timeout()), SIGNAL(updated()) );
+ connect( &m_updateTimer, SIGNAL(timeout()), SLOT(collectionUpdated()) );
m_configureAction = new QAction( KIcon( "configure" ), i18n( "&Configure Device" \
), this ); m_configureAction->setProperty( "popupdropper_svg_id", "configure" );
@@ -584,6 +585,13 @@ UmsCollection::slotTrackRemoved( const Meta::TrackPtr &track )
}
void
+UmsCollection::collectionUpdated()
+{
+ m_lastUpdated = QDateTime::currentMSecsSinceEpoch();
+ emit updated();
+}
+
+void
UmsCollection::slotParseTracks()
{
if( !m_scanManager )
@@ -764,16 +772,23 @@ UmsCollection::slotDirectoryScanned( \
CollectionScanner::Directory *dir )
foreach( const CollectionScanner::Track *scannerTrack, dir->tracks() )
{
//TODO: use proxy tracks so no real file read is required
+ // following method calls startUpdateTimer(), no need to emit updated()
slotTrackAdded( scannerTrack->path() );
}
- emit updated();
-
//TODO: read playlists
}
void
UmsCollection::slotStartUpdateTimer()
{
- m_updateTimer.start( 2000 );
+ // there are no concurrency problems, this method can only be called from the \
main + // thread and that's where the timer fires
+ if( m_updateTimer.isActive() )
+ return; // already running, nothing to do
+
+ // number of milliseconds to next desired update, may be negative
+ int timeout = m_lastUpdated + 1000 - QDateTime::currentMSecsSinceEpoch();
+ // give at least 50 msecs to catch multi-tracks edits nicely on the first frame
+ m_updateTimer.start( qBound( 50, timeout, 1000 ) );
}
diff --git a/src/core-impl/collections/umscollection/UmsCollection.h \
b/src/core-impl/collections/umscollection/UmsCollection.h index 8169f84..c5f303a \
100644
--- a/src/core-impl/collections/umscollection/UmsCollection.h
+++ b/src/core-impl/collections/umscollection/UmsCollection.h
@@ -169,6 +169,11 @@ class UmsCollection : public Collection, public Meta::Observer
void slotTrackAdded( KUrl trackLocation );
void slotTrackRemoved( const Meta::TrackPtr &track );
+ /**
+ * Overriden to update m_lastUpdated timestamp
+ */
+ virtual void collectionUpdated();
+
private slots:
void slotParseTracks();
void slotParseActionTriggered();
@@ -177,7 +182,7 @@ class UmsCollection : public Collection, public Meta::Observer
void slotDirectoryScanned( CollectionScanner::Directory *dir );
/**
- * Starts a timer that emits updated() signal after 2 seconds.
+ * Starts a timer that ensures we emit updated() signal sometime in future.
*/
void slotStartUpdateTimer();
@@ -227,6 +232,7 @@ class UmsCollection : public Collection, public Meta::Observer
QAction *m_configureAction;
QAction *m_ejectAction;
QTimer m_updateTimer;
+ qint64 m_lastUpdated; /* msecs since epoch */
};
#endif
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic