[KimDaBa] Another fix

Robert L Krawitz rlk at alum.mit.edu
Sat Jan 8 14:14:02 CET 2005


The code to read the EXIF data wasn't being selective enough about
what it read from the file, and it was also setting things even if the
values didn't come from the EXIF data.

--- imageinfo.cpp~      2005-01-07 17:50:14.000000000 -0500
+++ imageinfo.cpp       2005-01-08 14:07:32.010061649 -0500
@@ -363,6 +363,7 @@
     QFileInfo fi( fullPath );
     FileInfo exifInfo = FileInfo::read( fullPath );
     static bool hasShownWarning = false;
+    bool foundInExif = 0;
     if ( exifInfo.isEmpty() && !hasShownWarning ) {
         hasShownWarning = true;
         KMessageBox::information( 0, i18n("<qt><p><b>KimDaBa was unable to read EXIF information.</b></p>"
@@ -377,8 +378,8 @@
     //Time
     if ( mode & EXIFMODE_TIME ) {
         if ( (mode & EXIFMODE_FORCE) || Options::instance()->trustTimeStamps() ) {
-            QTime time = exifInfo.time();
-            if ( time.isValid() )
+            QTime time = exifInfo.time( &foundInExif );
+            if ( foundInExif && time.isValid() )
                 _startDate.setTime( time );
         }
     }
@@ -386,13 +387,13 @@
     // Date
     if ( mode & EXIFMODE_DATE ) {
         if ( (mode & EXIFMODE_FORCE) || Options::instance()->trustTimeStamps() ) {
-            bool foundDateInfExit;
-            QDate date = exifInfo.date( &foundDateInfExit );
+            QDate date = exifInfo.date( &foundInExif );
             if ( date.isValid() ) {
-                _startDate.setDate( date );
+               if ( foundInExif)
+                   _startDate.setDate( date );
                 _endDate = ImageDate();
             }
-            if ( !foundDateInfExit && !hasShownWarning &&
+            if ( !foundInExif && !hasShownWarning &&
                  ( _fileName.endsWith( QString::fromLatin1( ".jpg" ) ) ||
                    _fileName.endsWith( QString::fromLatin1( ".jpeg" ) ) ||
                    _fileName.endsWith( QString::fromLatin1( ".JPG" ) ) ||
@@ -412,17 +413,19 @@
     // Orientation
     if ( mode & EXIFMODE_ORIENTATION ) {
         if ( Options::instance()->useEXIFRotate() ) {
-            bool ok;
-            int angle = exifInfo.angle( &ok );
-            if ( ok )
+            int angle = exifInfo.angle( &foundInExif );
+            if ( foundInExif )
                 _angle = angle;
         }
     }
 
     // Description
     if ( mode & EXIFMODE_DESCRIPTION ) {
-        if ( Options::instance()->useEXIFComments() )
-            _description = exifInfo.description();
+        if ( Options::instance()->useEXIFComments() ) {
+           QString desc = exifInfo.description( &foundInExif );
+           if ( foundInExif )
+               _description = exifInfo.description();
+       }
     }
 }
 
--- imageinfo.cpp~      2005-01-07 17:50:14.000000000 -0500
+++ imageinfo.cpp       2005-01-08 14:07:32.010061649 -0500
@@ -363,6 +363,7 @@
     QFileInfo fi( fullPath );
     FileInfo exifInfo = FileInfo::read( fullPath );
     static bool hasShownWarning = false;
+    bool foundInExif = 0;
     if ( exifInfo.isEmpty() && !hasShownWarning ) {
         hasShownWarning = true;
         KMessageBox::information( 0, i18n("<qt><p><b>KimDaBa was unable to read EXIF information.</b></p>"
@@ -377,8 +378,8 @@
     //Time
     if ( mode & EXIFMODE_TIME ) {
         if ( (mode & EXIFMODE_FORCE) || Options::instance()->trustTimeStamps() ) {
-            QTime time = exifInfo.time();
-            if ( time.isValid() )
+            QTime time = exifInfo.time( &foundInExif );
+            if ( foundInExif && time.isValid() )
                 _startDate.setTime( time );
         }
     }
@@ -386,13 +387,13 @@
     // Date
     if ( mode & EXIFMODE_DATE ) {
         if ( (mode & EXIFMODE_FORCE) || Options::instance()->trustTimeStamps() ) {
-            bool foundDateInfExit;
-            QDate date = exifInfo.date( &foundDateInfExit );
+            QDate date = exifInfo.date( &foundInExif );
             if ( date.isValid() ) {
-                _startDate.setDate( date );
+               if ( foundInExif)
+                   _startDate.setDate( date );
                 _endDate = ImageDate();
             }
-            if ( !foundDateInfExit && !hasShownWarning &&
+            if ( !foundInExif && !hasShownWarning &&
                  ( _fileName.endsWith( QString::fromLatin1( ".jpg" ) ) ||
                    _fileName.endsWith( QString::fromLatin1( ".jpeg" ) ) ||
                    _fileName.endsWith( QString::fromLatin1( ".JPG" ) ) ||
@@ -412,17 +413,19 @@
     // Orientation
     if ( mode & EXIFMODE_ORIENTATION ) {
         if ( Options::instance()->useEXIFRotate() ) {
-            bool ok;
-            int angle = exifInfo.angle( &ok );
-            if ( ok )
+            int angle = exifInfo.angle( &foundInExif );
+            if ( foundInExif )
                 _angle = angle;
         }
     }
 
     // Description
     if ( mode & EXIFMODE_DESCRIPTION ) {
-        if ( Options::instance()->useEXIFComments() )
-            _description = exifInfo.description();
+        if ( Options::instance()->useEXIFComments() ) {
+           QString desc = exifInfo.description( &foundInExif );
+           if ( foundInExif )
+               _description = exifInfo.description();
+       }
     }
 }
 
[2(rlk)||{!78}<rlk-mobile>/home/rlk/sandbox/kimdaba-2005-01-02-noi18n/kimdaba]
$ diff -u fileinfo.cpp{~,}
--- fileinfo.cpp~       2005-01-07 17:48:37.000000000 -0500
+++ fileinfo.cpp        2005-01-08 14:07:56.006747970 -0500
@@ -25,7 +25,9 @@
     QStringList keys = metainfo.supportedKeys();
     for( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) {
         KFileMetaInfoItem item = metainfo.item( *it );
-        fi._map.insert( *it, item.value() );
+       if (item.type() != QVariant::Invalid) {
+         fi._map.insert( *it, item.value() );
+       }
     }
     return fi;
 }
@@ -35,13 +37,21 @@
     return _map.count() == 0;
 }
 
-QTime FileInfo::time() const
+QTime FileInfo::time( bool* foundTimeInExif ) const
 {
-    QTime res;
-    if ( _map.contains( QString::fromLatin1( "CreationTime" ) ) )
-        return _map[QString::fromLatin1( "CreationTime" )].toTime();
-    else
-        return QFileInfo( _fullPath ).lastModified().time();
+    if ( _map.contains( QString::fromLatin1( "CreationTime" ) ) ) {
+        QTime time = _map[QString::fromLatin1( "CreationTime" )].toTime();
+        if ( time.isValid() ) {
+            if ( foundTimeInExif )
+                *foundTimeInExif = true;
+            return time;
+        }
+    }
+
+    if ( foundTimeInExif )
+        *foundTimeInExif = false;
+
+    return QFileInfo( _fullPath ).lastModified().time();
 }
 
 QDate FileInfo::date( bool* foundDateInExif ) const
@@ -65,7 +75,7 @@
 {
     if ( !_map.contains(QString::fromLatin1( "Orientation" )) ) {
         if ( found )
-            found = false;
+            *found = false;
         return 0;
     }
 
@@ -87,7 +97,11 @@
     }
 }
 
-QString FileInfo::description() const
+QString FileInfo::description( bool* found) const
 {
+    if ( !_map.contains(QString::fromLatin1( "Orientation" )) ) {
+        if ( found )
+            found = false;
+    }
     return _map[QString::fromLatin1( "Comment" )].toString();
 }
--- fileinfo.h~ 2004-12-30 06:47:34.000000000 -0500
+++ fileinfo.h  2005-01-08 13:39:18.000000000 -0500
@@ -28,10 +28,10 @@
 public:
     static FileInfo read( const QString& fileName );
     bool isEmpty() const;
-    QTime time() const;
+    QTime time( bool* foundTimeInExif = 0 ) const;
     QDate date( bool* foundDateInExif = 0 ) const;
     int angle( bool* found = 0 ) const;
-    QString description() const;
+    QString description( bool* found = 0 ) const;
 
 private:
     QMap<QString,QVariant> _map;



More information about the KimDaBa mailing list