[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/work/amarok-dynamic-collection/src
From:       Maximilian Kossick <maximilian.kossick () googlemail ! com>
Date:       2006-07-14 15:40:57
Message-ID: 1152891657.671740.2884.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 562365 by mkossick:

make sure we don't lose stats when updating to dynamic collection

 M  +3 -2      collectiondb.cpp  
 M  +31 -1     mountpointmanager.cpp  
 M  +3 -0      mountpointmanager.h  


--- branches/work/amarok-dynamic-collection/src/collectiondb.cpp #562364:562365
@@ -4804,8 +4804,9 @@
                 debug() << "Updating " << oldURLs.count() << " rows in statistics" \
<< endl;  foreach( oldURLs )
                 {
-                    int deviceid = MountPointManager::instance()->getIdForUrl( *it \
                );
-                    QString rpath = MountPointManager::instance()->getRelativePath( \
deviceid, *it ); +                    bool exists = QFile::exists( *it );
+                    int deviceid = exists ? \
MountPointManager::instance()->getIdForUrl( *it ) : -2; +                    QString \
rpath = exists ? MountPointManager::instance()->getRelativePath( deviceid, *it ) : \
                *it;
                     QString update = QString( "UPDATE statistics SET deviceid = %1, \
                url = '%2' WHERE " )
                                      .arg( deviceid )
                                      .arg( escapeString( rpath ) );
--- branches/work/amarok-dynamic-collection/src/mountpointmanager.cpp #562364:562365
@@ -21,7 +21,9 @@
 
 #include <ktrader.h>
 
+#include <qfile.h>
 #include <qstringlist.h>
+#include <qtimer.h>
 #include <qvaluelist.h>
 
 typedef Medium::List MediumList;
@@ -29,12 +31,21 @@
 MountPointManager::MountPointManager():QObject( 0, "MountPointManager" )
 {
     //we are only interested in the mounting or unmounting of mediums
-    //therefore it is enough to listen to MediaDeviceManager's mediumChanged signal
+    //therefore it is enough to listen to DeviceManager's mediumChanged signal
     connect( DeviceManager::instance(), SIGNAL( mediumChanged( const Medium*, \
QString ) ), SLOT( mediumChanged( const Medium* ) ) );  
     m_mediumFactories.setAutoDelete( true );
     m_remoteFactories.setAutoDelete( true );
     init();
+
+    CollectionDB *collDB = CollectionDB::instance();
+
+    if ( collDB->adminValue( "Database Stats Version" ).toInt() >= 9 && /* make sure \
that deviceid actually exists*/ +         collDB->query( "SELECT COUNT(url) FROM \
statistics WHERE deviceid = -2;" ).first().toInt() != 0 ) +    {
+        connect( this, SIGNAL( mediumChanged( int ) ), SLOT( migrateStatistics( int \
) ) ); +        QTimer::singleShot( 0, this, SLOT(migrateStatistics( 0 ) ) );
+    }
 }
 
 
@@ -250,4 +261,23 @@
     }
 }
 
+void MountPointManager::migrateStatistics( int /* deviceid */ )
+{
+    QStringList urls = CollectionDB::instance()->query( "SELECT url FROM statistics \
WHERE deviceid = -2;" ); +    foreach( urls )
+    {
+        if ( QFile::exists( *it) )
+        {
+            int deviceid = getIdForUrl( *it );
+            QString rpath = getRelativePath( deviceid, *it );
+            QString update = QString( "UPDATE statistics SET deviceid = %1, url = \
'%2'" ) +                                      .arg( deviceid )
+                                      .arg( CollectionDB::instance()->escapeString( \
rpath ) ); +            update += QString( " WHERE url = '%1' AND deviceid = -2;" )
+                               .arg( CollectionDB::instance()->escapeString( *it ) \
); +            CollectionDB::instance()->query( update );
+        }
+    }
+}
+
 #include "mountpointmanager.moc"
--- branches/work/amarok-dynamic-collection/src/mountpointmanager.h #562364:562365
@@ -205,6 +205,9 @@
      */
     void mediumChanged( const Medium* m );
 
+private slots:
+    void migrateStatistics( int deviceid );
+
 private:
     MountPointManager();
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic