[KimDaBa] Patch to read Exif information from files.

Marco Caldarelli caldarel at yahoo.it
Thu May 6 16:56:42 BST 2004


Hi,

I wrote a small patch to reread EXIF info from files. It adds two menu items,

  Maintenance->Read EXIF info from all files...
  
to reread info for all files in the database, and

  Images->Read EXIF info from selected files...
  
to reread info only for the selected files.

In both cases, a dialog opens and asks what information should be read. It
is possible to select any combination of
  Read time
  Read date
  Read EXIF orientation
  Read EXIF description
or, alternatively, to select the "Read all" box.
Then, clicking on "Read File Info" the whanted data is updated.

The code is easy to expand if more file data will be inserted in the future
(for example the image resolution, or some camera settings...).
It would be nice to have the "Read all" exclusive in the future (checking it
unsets all other boxes, and setting a different box clears it).

I didn't do extensive tests for the moment, I will do some in the next days,
but the code seems to work. I would appreciate very much any suggestion,
comment and help to test it.

Here follows the diff file for the modifications, and the code for two new
files, readinfodialog.h and readinfodialog.cpp.

Ciao,
Marco

-----------------------------------------------------------------------------

--- BEGIN DIFF ---

Index: Makefile.am
===================================================================
RCS file: /home/kde/kdeextragear-2/kimdaba/Makefile.am,v
retrieving revision 1.53
diff -r1.53 Makefile.am
39c39
< 	myimageinfo.cpp myimagecollection.cpp plugininterface.cpp
---
> 	myimageinfo.cpp myimagecollection.cpp plugininterface.cpp readinfodialog.cpp
Index: imagedb.cpp
===================================================================
RCS file: /home/kde/kdeextragear-2/kimdaba/imagedb.cpp,v
retrieving revision 1.38
diff -r1.38 imagedb.cpp
113c113
<             slotReread( missingTimes );
---
>             slotReread( missingTimes, EXIFMODE_TIME );
536c536
<     slotReread(missingTimes);
---
>     slotReread(missingTimes, EXIFMODE_TIME);
540c540
< void ImageDB::slotReread(ImageInfoList rereadList)
---
> void ImageDB::slotReread(ImageInfoList rereadList, int mode)
565c565
<             (*it)->readExif((*it)->fileName(),ImageInfo::Time);
---
>             (*it)->readExif((*it)->fileName(), mode);
Index: imagedb.h
===================================================================
RCS file: /home/kde/kdeextragear-2/kimdaba/imagedb.h,v
retrieving revision 1.22
diff -r1.22 imagedb.h
54c54
<     void slotReread(ImageInfoList rereadList);
---
>     void slotReread(ImageInfoList rereadList, int mode);
Index: imageinfo.cpp
===================================================================
RCS file: /home/kde/kdeextragear-2/kimdaba/imageinfo.cpp,v
retrieving revision 1.52
diff -r1.52 imageinfo.cpp
52c52
<     readExif(fullPath, ImageInfo::Init);
---
>     readExif(fullPath, EXIFMODE_INIT);
387c387
< void ImageInfo::readExif(const QString& fullPath, ExifMode mode)
---
> void ImageInfo::readExif(const QString& fullPath, int mode)
391a392
> 
403c404,405
<     if( mode == ImageInfo::Time ) {
---
>     //Time
>     if ( mode & EXIFMODE_TIME ) {
405d406
<             //Time
417,418c418,420
<     else if ( mode == ImageInfo::Init ) {
<         // Date
---
> 
>     // Date
>     if ( mode & EXIFMODE_DATE ) {
447,463d448
< 
< 
<             //Time
<             if (exif.contains( QString::fromLatin1( "CreationTime" ) ) ){
< 
<                 QTime time = exif[QString::fromLatin1( "CreationTime" )].toTime();
<                 if (time.isValid())
<                     _startDate.setTime( time );
< 
<             }
<             else{
< 
<                 QTime time = fi.lastModified().time();
<                 _startDate.setTime( time );
< 
<             }
< 
465c450,453
<         // Orientation
---
>     }
> 
>     // Orientation
>     if ( mode == EXIFMODE_ORIENTATION ) {
476a465
>     }
478c467,468
<         // Description
---
>     // Description
>     if ( mode == EXIFMODE_DESCRIPTION ) {
486d475
< 
Index: imageinfo.h
===================================================================
RCS file: /home/kde/kdeextragear-2/kimdaba/imageinfo.h,v
retrieving revision 1.32
diff -r1.32 imageinfo.h
33a34,39
> #define EXIFMODE_TIME          1
> #define EXIFMODE_DATE          2
> #define EXIFMODE_ORIENTATION   4
> #define EXIFMODE_DESCRIPTION   8
> #define EXIFMODE_INIT ( EXIFMODE_TIME | EXIFMODE_DATE | EXIFMODE_ORIENTATION | EXIFMODE_DESCRIPTION )
> 
37d42
<     enum ExifMode { Init, Time };
59c64
<     void readExif(const QString& fullPath, ExifMode mode);
---
>     void readExif(const QString& fullPath, int mode);
Index: kimdabaui.rc
===================================================================
RCS file: /home/kde/kdeextragear-2/kimdaba/kimdabaui.rc,v
retrieving revision 1.22
diff -r1.22 kimdabaui.rc
27a28
>       <Action name="readInfoSelected" />
49a51
>       <Action name="readInfo" />
Index: mainview.cpp
===================================================================
RCS file: /home/kde/kdeextragear-2/kimdaba/mainview.cpp,v
retrieving revision 1.119
diff -r1.119 mainview.cpp
72a73
> #include "readinfodialog.h"
78c79,80
<      _deleteDialog( 0 ), _dirtyIndicator(0), _htmlDialog(0)
---
>      _deleteDialog( 0 ), _readInfoDialog( 0 ), _dirtyIndicator(0),
>      _htmlDialog(0)
319a322,339
> void MainView::slotReadInfoSelected()
> {
>     if ( ! _readInfoDialog )
>         _readInfoDialog = new ReadInfoDialog( this );
>     if ( _readInfoDialog->exec( selected() ) == QDialog::Accepted )
>         setDirty( true );
> }
> 
> 
> void MainView::slotReadInfo()
> {
>     if ( ! _readInfoDialog )
>         _readInfoDialog = new ReadInfoDialog( this );
>     if ( _readInfoDialog->exec( ImageDB::instance()->images() ) == QDialog::Accepted )
>         setDirty( true );
> }
> 
> 
584a605
>     _readInfoSelected = new KAction( i18n("Read EXIF info from selected files..."), 0, this, SLOT( slotReadInfoSelected() ), actionCollection(), "readInfoSelected" );
604a626
>     new KAction( i18n("Read EXIF info from all files..."), 0, this, SLOT( slotReadInfo() ), actionCollection(), "readInfo" );
1087a1110
>     _readInfoSelected->setEnabled( thumbNailView );
Index: mainview.h
===================================================================
RCS file: /home/kde/kdeextragear-2/kimdaba/mainview.h,v
retrieving revision 1.58
diff -r1.58 mainview.h
28a29
> class ReadInfoDialog;
56a58,59
>     void slotReadInfoSelected();
>     void slotReadInfo();
125a129
>     ReadInfoDialog* _readInfoDialog;
136a141
>     KAction* _readInfoSelected;


---- END DIFF ---




---- BEGIN NEW FILE readinfodialog.h ---

#ifndef READINFODIALOG_H
#define READINFODIALOG_H
#include "imageinfo.h"
#include <kdialogbase.h>
class QLabel;
class QCheckBox;
class QRadioButton;

class ReadInfoDialog :public KDialogBase {
    Q_OBJECT

public:
    ReadInfoDialog( QWidget* parent, const char* name = 0 );
    int exec( const ImageInfoList& );

protected slots:
    void readInfo();
private:
    ImageInfoList _list;
    QLabel* _label;
    QCheckBox* _time;
    QCheckBox* _date;
    QCheckBox* _orientation;
    QCheckBox* _description;
    QCheckBox* _init;
};


#endif /* READINFODIALOG_H */

---- END FILE readinfodialog.h ---




---- BEGIN NEW FILE readinfodialog.cpp ---

#include "readinfodialog.h"
#include <klocale.h>
#include <qlabel.h>
#include <qcheckbox.h>
#include <qradiobutton.h>
#include <qlayout.h>
#include <qbuttongroup.h>
#include <qfile.h>
#include <kmessagebox.h>
#include "imagedb.h"
#include "imageinfo.h"
#include "util.h"

ReadInfoDialog::ReadInfoDialog( QWidget* parent, const char* name )
    :KDialogBase( Plain, i18n("Read File Info"), Cancel|User1, User1, parent, name,
                  true, false, i18n("Read File Info"))
{
    QWidget* top = plainPage();
    QVBoxLayout* lay1 = new QVBoxLayout( top, 6 );

    _label = new QLabel( top );
    lay1->addWidget( _label );

    _time = new QCheckBox( i18n( "Read time" ), top );
    lay1->addWidget( _time );

    _date = new QCheckBox( i18n( "Read date" ), top );
    lay1->addWidget( _date );

    _orientation = new QCheckBox( i18n( "Read EXIF orientation" ), top );
    lay1->addWidget( _orientation );

    _description = new QCheckBox( i18n( "Read EXIF description" ), top );
    lay1->addWidget( _description );

    _init = new QCheckBox( i18n( "Read all (time, date, orientation and description)" ), top );
    lay1->addWidget( _init );

    connect( this, SIGNAL( user1Clicked() ), this, SLOT( readInfo() ) );
}

int ReadInfoDialog::exec( const ImageInfoList& list )
{
    _label->setText( i18n("<qt><b><center><font size=\"+3\">Read File Info<br>%1 selected</font></center></b></qt>").arg( list.count() ) );

    _init->setChecked( true );
    _time->setChecked( false );
    _date->setChecked( false );
    _orientation->setChecked( false );
    _description->setChecked( false );
    _list = list;

    return KDialogBase::exec();
}

void ReadInfoDialog::readInfo()
{
    int mode = 0;

    if ( _init->isChecked() )
            mode |= EXIFMODE_INIT;
    else {
            if ( _time->isChecked() )
                    mode |= EXIFMODE_TIME;
            if ( _date->isChecked() )
                    mode |= EXIFMODE_DATE;
            if ( _orientation->isChecked() )
                    mode |= EXIFMODE_ORIENTATION;
            if ( _description->isChecked() )
                    mode |= EXIFMODE_DESCRIPTION;
    }
    ImageDB::instance()->slotReread(_list, mode);
    accept();
}

#include "readinfodialog.moc"

---- END FILE readinfodialog.cpp ---



More information about the Kphotoalbum mailing list