[Digikam-devel] extragear/graphics/digikam/libs

Gilles Caulier caulier.gilles at free.fr
Thu Mar 30 11:48:07 BST 2006


SVN commit 524347 by cgilles:

digikam from trunk : Writing digiKam comments into photograph !!!

- DMetadata : new method to write comments into pictures using Exiv2. The string is writte as image comments (JPEG COM for example), Exif comments, and IPTC comments.

- Comments & tags sidebar use this method to set comments into image.

CCMAIL: digikam-devel at kde.org

 M  +47 -0     dmetadata/dmetadata.cpp  
 M  +1 -0      dmetadata/dmetadata.h  
 M  +5 -13     imageproperties/imagedescedittab.cpp  


--- trunk/extragear/graphics/digikam/libs/dmetadata/dmetadata.cpp #524346:524347
@@ -524,4 +524,51 @@
     return QDateTime();
 }
 
+bool DMetadata::writeImageComment(const QString& filePath, const QString& comment)
+{
+    try
+    {    
+        if (filePath.isEmpty())
+            return false;
+            
+        if (comment.isEmpty())
+        {
+            kdDebug() << k_funcinfo << "Comment to write is empty!" << endl;
+            return false;
+        }
+            
+        Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open((const char*)
+                                      (QFile::encodeName(filePath)));
+        
+        // In first we write comments outside of Exif and IPTC if possible.
+                                              
+        image->readMetadata();
+        const std::string &str(comment.latin1());
+        image->setComment(str);
+
+        // In Second we write comments into Exif.
+                
+        Exiv2::ExifData &exifData = image->exifData();
+        exifData["Exif.Photo.UserComment"] = comment.latin1();
+        image->setExifData(exifData);
+        
+        // In Third we write comments into Iptc.
+
+        Exiv2::IptcData &iptcData = image->iptcData();
+        iptcData["Iptc.Application2.Caption"] = comment.ascii();
+        image->setIptcData(iptcData);
+    
+        image->writeMetadata();
+        return true;
+    }
+    catch( Exiv2::Error &e )
+    {
+        kdDebug() << "Cannot set Comment into image using Exiv2 (" 
+                  << QString::fromLocal8Bit(e.what().c_str())
+                  << ")" << endl;
+    }        
+    
+    return false;
+}
+    
 }  // NameSpace Digikam
--- trunk/extragear/graphics/digikam/libs/dmetadata/dmetadata.h #524346:524347
@@ -66,6 +66,7 @@
     bool    save(const QString& filePath, const QString& format);
 
     bool    writeExifImageOrientation(const QString& filePath, ImageOrientation orientation);
+    bool    writeImageComment(const QString& filePath, const QString& comment);
     
     /** Metadata manipulation methods */
     QByteArray       getExif() const;
--- trunk/extragear/graphics/digikam/libs/imageproperties/imagedescedittab.cpp #524346:524347
@@ -48,13 +48,13 @@
 #include <kmessagebox.h>
 #include <ktextedit.h>
 #include <kconfig.h>
-#include <kfilemetainfo.h>
 #include <klineedit.h>
 #include <kdialogbase.h>
 #include <kdatetimeedit.h>
 
 // Local includes.
 
+#include "dmetadata.h"
 #include "albumiconitem.h"
 #include "albummanager.h"
 #include "albumdb.h"
@@ -371,18 +371,10 @@
     if (AlbumSettings::instance() &&
         AlbumSettings::instance()->getSaveExifComments())
     {
-        // store as JPEG Exif comment
-        KFileMetaInfo metaInfo(info->filePath(), "image/jpeg", KFileMetaInfo::Fastest);
-
-        // set Jpeg comment
-        if (metaInfo.isValid () && metaInfo.mimeType() == "image/jpeg"
-            && metaInfo.containsGroup("Jpeg EXIF Data"))
-        {
-            kdDebug() << k_funcinfo << "Contains JPEG Exif data, setting comment" << endl;
-
-            metaInfo["Jpeg EXIF Data"].item("Comment").setValue(d->commentsEdit->text());
-            metaInfo.applyChanges();
-        }
+        // Store comments in image as JPEG Exif comment, Exif comments, and Iptc Comments.
+        
+        DMetadata metadata;
+        metadata.writeImageComment(info->filePath(), d->commentsEdit->text());
     }
 
     info->removeAllTags();



More information about the Digikam-devel mailing list