[Digikam-devel] branches/digikam/0.8-experimental/digikam/kioslave

Renchi Raju renchi at pooh.tam.uiuc.edu
Fri Jun 24 00:40:18 BST 2005


SVN commit 428388 by pahlibar:

automatically add/remove externally added/removed files to db
and refresh frontend. testing required
CCMAIL: digikam-devel at kde.org


 M  +80 -29    digikamalbums.cpp  


--- branches/digikam/0.8-experimental/digikam/kioslave/digikamalbums.cpp #428387:428388
@@ -1378,47 +1378,98 @@
     if (!url.endsWith("/"))
         subURL += "/";
     subURL = escapeString( subURL);
-    
-    QStringList currAlbumList;
-    m_sqlDB.execSql( QString("SELECT url FROM Albums WHERE ") +
-                     QString("url LIKE '") + subURL + QString("%' ") +
-                     QString("AND url NOT LIKE '") + subURL + QString("%/%' "),
-                     &currAlbumList );
 
-    const QFileInfoList* infoList = dir.entryInfoList(QDir::Dirs);
-    if (!infoList)
-        return;
+    {
+        // scan albums
+        
+        QStringList currAlbumList;
+        m_sqlDB.execSql( QString("SELECT url FROM Albums WHERE ") +
+                         QString("url LIKE '") + subURL + QString("%' ") +
+                         QString("AND url NOT LIKE '") + subURL + QString("%/%' "),
+                         &currAlbumList );
 
-    QFileInfoListIterator it(*infoList);
-    QFileInfo* fi;
 
-    QStringList newAlbumList;
-    while ((fi = it.current()) != 0)
-    {
-        ++it;
+        const QFileInfoList* infoList = dir.entryInfoList(QDir::Dirs);
+        if (!infoList)
+            return;
+        
+        QFileInfoListIterator it(*infoList);
+        QFileInfo* fi;
+        
+        QStringList newAlbumList;
+        while ((fi = it.current()) != 0)
+        {
+            ++it;
+            
+            if (fi->fileName() == "." || fi->fileName() == "..")
+            {
+                continue;
+            }
+            
+            QString u = QDir::cleanDirPath(url + "/" + fi->fileName());
+            
+            if (currAlbumList.contains(u))
+            {
+                continue;
+            }
 
-        if (fi->fileName() == "." || fi->fileName() == "..")
+            newAlbumList.append(u);
+        }
+
+        for (QStringList::iterator it = newAlbumList.begin();
+             it != newAlbumList.end(); ++it)
         {
-            continue;
+            kdDebug() << "New Album: " << *it << endl;
+            findAlbum(*it);
+            scanAlbum(*it);
         }
+    }
 
-        QString u = QDir::cleanDirPath(url + "/" + fi->fileName());
+    if (url != "/")
+    {
+        // scan files
+
+        QStringList values;
+
+        m_sqlDB.execSql( QString("SELECT id FROM Albums WHERE url='%1'")
+                         .arg(url), &values );
+        if (values.isEmpty())
+            return;
+
+        int albumID = values.first().toInt();
+
+        QStringList currItemList;
+        m_sqlDB.execSql( QString("SELECT name FROM Images WHERE dirid=%1")
+                         .arg(albumID), &currItemList );
         
-        if (currAlbumList.contains(u))
+        const QFileInfoList* infoList = dir.entryInfoList(QDir::Files);
+        if (!infoList)
+            return;
+
+        QFileInfoListIterator it(*infoList);
+        QFileInfo* fi;
+
+        // add any new files we find to the db
+        while ((fi = it.current()) != 0)
         {
-            continue;
+            ++it;
+
+            if (currItemList.contains(fi->fileName()))
+            {
+                currItemList.remove(fi->fileName());
+                continue;
+            }
+
+            addImage(albumID, m_libraryPath + url + "/" + fi->fileName());
         }
 
-        newAlbumList.append(u);
+        // currItemList now contains deleted file list. remove them from db
+        for (QStringList::iterator it = currItemList.begin();
+             it != currItemList.end(); ++it)
+        {
+            delImage(albumID, *it);
+        }
     }
-
-    for (QStringList::iterator it = newAlbumList.begin();
-         it != newAlbumList.end(); ++it)
-    {
-        kdDebug() << "New Album: " << *it << endl;
-        findAlbum(*it);
-        scanAlbum(*it);
-    }
 }
 
 void kio_digikamalbums::removeInvalidAlbums()



More information about the Digikam-devel mailing list