[KimDaBa] Patch to improve EXIF handling
Robert L Krawitz
rlk at alum.mit.edu
Sun Jan 9 00:51:38 GMT 2005
The following patch improves handling of EXIF data, in particular in
the Read EXIF Data dialog. It does not overwrite the time, date,
orientation, or comment data unless the EXIF data is actually
present. It also adds two new options (EXIF_FORCE_TIME and
EXIF_FORCE_DATE) that do overwrite the time and date information with
the file modification date/time if the EXIF data isn't present.
-------------- next part --------------
diff -ru kimdaba-2005-01-02-old/kimdaba/fileinfo.cpp kimdaba-2005-01-02-noi18n/kimdaba/fileinfo.cpp
--- kimdaba-2005-01-02-old/kimdaba/fileinfo.cpp 2005-01-02 11:04:27.000000000 -0500
+++ kimdaba-2005-01-02-noi18n/kimdaba/fileinfo.cpp 2005-01-08 14:07:56.006747970 -0500
@@ -10,11 +10,12 @@
fi._fullPath = fileName;
QString tempFileName( fileName );
if ( Util::isCRW( fileName ) ) {
+ QString dirName = QFileInfo( fileName ).dirPath();
QString baseName = QFileInfo( fileName ).baseName();
- tempFileName = baseName + QString::fromLatin1( ".thm" );
+ tempFileName = dirName + QString::fromLatin1("/") + baseName + QString::fromLatin1( ".thm" );
QFileInfo tempFile (tempFileName);
if ( !tempFile.exists() )
- tempFileName = baseName + QString::fromLatin1( ".THM" );
+ tempFileName = dirName + QString::fromLatin1("/") + baseName + QString::fromLatin1( ".THM" );
}
KFileMetaInfo metainfo( tempFileName );
@@ -24,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;
}
@@ -34,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
@@ -64,7 +75,7 @@
{
if ( !_map.contains(QString::fromLatin1( "Orientation" )) ) {
if ( found )
- found = false;
+ *found = false;
return 0;
}
@@ -86,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();
}
diff -ru kimdaba-2005-01-02-old/kimdaba/fileinfo.h kimdaba-2005-01-02-noi18n/kimdaba/fileinfo.h
--- kimdaba-2005-01-02-old/kimdaba/fileinfo.h 2004-12-30 06:47:34.000000000 -0500
+++ kimdaba-2005-01-02-noi18n/kimdaba/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;
diff -ru kimdaba-2005-01-02-old/kimdaba/imageinfo.cpp kimdaba-2005-01-02-noi18n/kimdaba/imageinfo.cpp
--- kimdaba-2005-01-02-old/kimdaba/imageinfo.cpp 2004-12-30 06:47:34.000000000 -0500
+++ kimdaba-2005-01-02-noi18n/kimdaba/imageinfo.cpp 2005-01-08 19:25:56.279145030 -0500
@@ -349,6 +349,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>"
@@ -363,22 +364,24 @@
//Time
if ( mode & EXIFMODE_TIME ) {
if ( (mode & EXIFMODE_FORCE) || Options::instance()->trustTimeStamps() ) {
- QTime time = exifInfo.time();
- if ( time.isValid() )
- _startDate.setTime( time );
+ QTime time = exifInfo.time( &foundInExif );
+ if ( time.isValid() ) {
+ if ( foundInExif || (mode & EXIFMODE_FORCE_TIME) )
+ _startDate.setTime( time );
+ }
}
}
// 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 || (mode & EXIFMODE_FORCE_DATE) )
+ _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" ) ) ||
@@ -398,17 +401,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();
+ }
}
}
diff -ru kimdaba-2005-01-02-old/kimdaba/imageinfo.h kimdaba-2005-01-02-noi18n/kimdaba/imageinfo.h
--- kimdaba-2005-01-02-old/kimdaba/imageinfo.h 2005-01-02 15:38:10.000000000 -0500
+++ kimdaba-2005-01-02-noi18n/kimdaba/imageinfo.h 2005-01-08 15:03:57.350538422 -0500
@@ -37,7 +37,9 @@
#define EXIFMODE_ORIENTATION 0x04
#define EXIFMODE_DESCRIPTION 0x08
#define EXIFMODE_FORCE 0x10
-#define EXIFMODE_INIT ( EXIFMODE_TIME | EXIFMODE_DATE | EXIFMODE_ORIENTATION | EXIFMODE_DESCRIPTION )
+#define EXIFMODE_FORCE_TIME 0x20
+#define EXIFMODE_FORCE_DATE 0x40
+#define EXIFMODE_INIT ( EXIFMODE_TIME | EXIFMODE_DATE | EXIFMODE_ORIENTATION | EXIFMODE_DESCRIPTION | EXIFMODE_FORCE_TIME | EXIFMODE_FORCE_DATE )
class ImageInfo {
diff -ru kimdaba-2005-01-02-old/kimdaba/readinfodialog.cpp kimdaba-2005-01-02-noi18n/kimdaba/readinfodialog.cpp
--- kimdaba-2005-01-02-old/kimdaba/readinfodialog.cpp 2004-08-23 11:52:27.000000000 -0400
+++ kimdaba-2005-01-02-noi18n/kimdaba/readinfodialog.cpp 2005-01-08 15:18:24.654485919 -0500
@@ -42,9 +42,15 @@
_time = new QCheckBox( i18n( "Read time" ), top );
lay1->addWidget( _time );
+ _force_time = new QCheckBox( i18n( "Use modification time if EXIF not present" ), top );
+ lay1->addWidget( _force_time );
+
_date = new QCheckBox( i18n( "Read date" ), top );
lay1->addWidget( _date );
+ _force_date = new QCheckBox( i18n( "Use modification date if EXIF not present" ), top );
+ lay1->addWidget( _force_date );
+
_orientation = new QCheckBox( i18n( "Read EXIF orientation" ), top );
lay1->addWidget( _orientation );
@@ -59,7 +65,9 @@
_label->setText( i18n("<qt><b><center><font size=\"+3\">Read File Info<br>%1 selected</font></center></b></qt>").arg( list.count() ) );
_time->setChecked( true );
+ _force_time->setChecked( true );
_date->setChecked( true );
+ _force_date->setChecked( true );
_orientation->setChecked( false );
_description->setChecked( false );
_list = list;
@@ -73,8 +81,12 @@
if ( _time->isChecked() )
mode |= EXIFMODE_TIME;
+ if ( _force_time->isChecked() )
+ mode |= EXIFMODE_FORCE_TIME;
if ( _date->isChecked() )
mode |= EXIFMODE_DATE;
+ if ( _force_date->isChecked() )
+ mode |= EXIFMODE_FORCE_DATE;
if ( _orientation->isChecked() )
mode |= EXIFMODE_ORIENTATION;
if ( _description->isChecked() )
diff -ru kimdaba-2005-01-02-old/kimdaba/readinfodialog.h kimdaba-2005-01-02-noi18n/kimdaba/readinfodialog.h
--- kimdaba-2005-01-02-old/kimdaba/readinfodialog.h 2005-01-02 15:38:10.000000000 -0500
+++ kimdaba-2005-01-02-noi18n/kimdaba/readinfodialog.h 2005-01-08 15:04:37.613642063 -0500
@@ -40,6 +40,8 @@
QCheckBox* _date;
QCheckBox* _orientation;
QCheckBox* _description;
+ QCheckBox* _force_time;
+ QCheckBox* _force_date;
};
More information about the Kphotoalbum
mailing list