[Digikam-users] extragear/graphics/digikam/digikam

Gilles Caulier caulier.gilles at free.fr
Wed Oct 4 21:10:43 BST 2006


SVN commit 592444 by cgilles:

digikam from trunk : first step to tag new pictures automaticly during startup, import, or when "scan for new items" is invoqued for album gui.

This commit check IPTC keywords contents to tag pictures in database only if the tag already exist. This commit is not intrusive to database. No new tag is created.

A second step will be done to create new tags if current keywords are not found in database. This way is intrusive to tags DB table and the implementation need to be checked indeep to prevent indeep problems. Still TODO.

Note to digikam users: i need Jpeg pictures to test :

- witch have been tagged using digikam and tags saved in IPTC keywords.
- witch have been tagged to IPTC keywords using another application (linux, mac, win32).

The digikam tags are saved to IPTC keywords using a separated '/' like this:

Countries/France
City/Paris/Monuments
Countries/GB
City/London/Monuments

Thanks in advance for your help

CCMAIL: digikam-devel at kde.org, digikam-users at kde.org

 M  +71 -7     albumdb.cpp  
 M  +19 -7     albumdb.h  
 M  +13 -7     scanlib.cpp  


--- trunk/extragear/graphics/digikam/digikam/albumdb.cpp #592443:592444
@@ -1,10 +1,14 @@
 /* ============================================================
- * Author: Renchi Raju <renchi at pooh.tam.uiuc.edu>
- * Date  : 2004-06-18
- * Description :
+ * Authors: Renchi Raju <renchi at pooh.tam.uiuc.edu>
+ *          Gilles Caulier <caulier dot gilles at kdemail dot net>
+ *          Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
+ * Date   : 2004-06-18
+ * Description : album interafce with database.
  *
- * Copyright 2004 by Renchi Raju
-
+ * Copyright 2004-2005 by Renchi Raju
+ * Copyright 2006 by Gilles Caulier
+ * Copyright 2006 by Marcel Wiesweg
+ * 
  * This program is free software; you can redistribute it
  * and/or modify it under the terms of the GNU General
  * Public License as published by the Free Software Foundation;
@@ -26,13 +30,13 @@
 {
 #include <sqlite3.h>
 #include <sys/time.h>
-#include <time.h>
 }
 
 // C++ includes.
 
 #include <cstdio>
 #include <cstdlib>
+#include <ctime>
 
 // Qt includes.
 
@@ -48,6 +52,7 @@
 // Local includes.
 
 #include "albummanager.h"
+#include "album.h"
 #include "albumdb.h"
 
 namespace Digikam
@@ -983,7 +988,8 @@
                          const QString& name,
                          const QDateTime& datetime,
                          const QString& comment,
-                         int rating)
+                         int rating,
+                         QStringList& keywordsList)
 {
     execSql ( QString ("REPLACE INTO Images "
                        "( caption , datetime, name, dirid ) "
@@ -995,9 +1001,67 @@
     
     Q_LLONG item = sqlite3_last_insert_rowid(m_db);
     
+    // Set Rating value to item in database.
     if ( item != -1 && rating != -1 )               
         setItemRating(item, rating);
     
+    // Set existing tags in database or create new tags if not exist.
+    if ( item != -1 && !keywordsList.isEmpty() )               
+    {
+        TagInfo::List tagsList = scanTags();
+
+        for (QStringList::iterator kwd = keywordsList.begin(); 
+            kwd != keywordsList.end(); ++kwd )
+        {
+            QStringList tagHierarchy = QStringList::split('/', *kwd);
+            if (tagHierarchy.isEmpty())
+                continue;
+
+            QString tagName = tagHierarchy.back();
+            tagHierarchy.pop_back();
+
+            for (TagInfo::List::iterator tag = tagsList.begin();
+                 tag != tagsList.end(); ++tag )
+            {
+                if ((*tag).name == tagName)
+                {
+                    int parentID = (*tag).pid;
+                    bool foundTag = true;
+                    // make a copy, we pop_back. Better traverse with iterators
+                    QStringList parentTagHierarchy = tagHierarchy;
+
+                    while (foundTag && !parentTagHierarchy.isEmpty())
+                    {
+                        QString parenttagName = parentTagHierarchy.back();
+                        parentTagHierarchy.pop_back();
+                        foundTag = false;
+
+                        for (TagInfo::List::iterator parenttag = tagsList.begin();
+                             parenttag != tagsList.end(); ++parenttag )
+                        {
+                            if ((*parenttag).name == parenttagName && (!parentID || (*parenttag).id == parentID))
+                            {
+                                parentID = (*parenttag).pid;
+                                foundTag = true;
+                                break;
+                            }
+                        }
+                    }
+
+                    if (foundTag)
+                    {
+                        addItemTag(item, (*tag).id);
+                        break;
+                    }
+		    else
+		    {
+		    // TODO : add new tag in DB and tags item with it.
+		    }
+                }
+            }
+        }
+    }
+
     return item;
 }
 
--- trunk/extragear/graphics/digikam/digikam/albumdb.h #592443:592444
@@ -1,10 +1,14 @@
 /* ============================================================
- * Author: Renchi Raju <renchi at pooh.tam.uiuc.edu>
- * Date  : 2004-06-18
- * Description : 
+ * Authors: Renchi Raju <renchi at pooh.tam.uiuc.edu>
+ *          Gilles Caulier <caulier dot gilles at kdemail dot net>
+ *          Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
+ * Date   : 2004-06-18
+ * Description : album interface with database.
  * 
- * Copyright 2004 by Renchi Raju
-
+ * Copyright 2004-2005 by Renchi Raju
+ * Copyright 2006 by Gilles Caulier
+ * Copyright 2006 by Marcel Wiesweg
+ *
  * This program is free software; you can redistribute it
  * and/or modify it under the terms of the GNU General
  * Public License as published by the Free Software Foundation;
@@ -258,12 +262,15 @@
      * file.
      * @param rating The user rating as found in the iptc-headers of the 
      * file.
+     * @param keywords The user keywords as found in the iptc-headers of the 
+     * file.
      * @return the id of item added or -1 if it fails
      */
     Q_LLONG addItem(int albumID, const QString& name,
                     const QDateTime& datetime,
                     const QString& comment,
-                    int rating);
+                    int rating,
+                    QStringList& keywordsList);
 
     /**
      * Update the date of a item to supplied date
@@ -544,8 +551,13 @@
      */
     QString escapeString(QString str) const;
 
+
+private:
+
+    bool     m_valid;
+
     sqleet3* m_db;
-    bool     m_valid;
+
     IntList  m_recentlyAssignedTags;
 };
 
--- trunk/extragear/graphics/digikam/digikam/scanlib.cpp #592443:592444
@@ -397,29 +397,31 @@
     if (albumURL.isEmpty())
         return;
 
-    QString   comment;
-    QDateTime datetime;
-    int       rating;
+    QString     comment;
+    QStringList keywords;
+    QDateTime   datetime;
+    int         rating;
 
     QString filePath( AlbumManager::instance()->getLibraryPath());
     filePath += albumURL + '/' + filename;
 
     DMetadata metadata(filePath);
 
-    // Trying to get comments from image :
+    // Try to get comments from image :
     // In first, from standard JPEG comments, or
     // In second, from EXIF comments tag, or
     // In third, from IPTC comments tag.
 
     comment = metadata.getImageComment();
 
-    // Trying to get date and time from image :
+    // Try to get date and time from image :
     // In first, from EXIF date & time tags, or
     // In second, from IPTC date & time tags.
 
     datetime = metadata.getImageDateTime();
 
-    // Trying to get image rating from IPTC Urgency tag.
+    // Try to get image rating from IPTC Urgency tag 
+    // else use file system time stamp.
     rating = metadata.getImageRating();
 
     if ( !datetime.isValid() )
@@ -428,8 +430,12 @@
         datetime = info.lastModified();
     }
 
+    // Try to get image tags from IPTC keywords tags.
+
+    keywords = metadata.getImageKeywords();
+
     AlbumDB* dbstore = AlbumManager::instance()->albumDB();
-    dbstore->addItem(albumID, filename, datetime, comment, rating);
+    dbstore->addItem(albumID, filename, datetime, comment, rating, keywords);
 }
 
 void ScanLib::updateItemDate(const QString& albumURL,



More information about the Digikam-users mailing list