exiv2plugin.cpp (krename-4.0.9) | : | exiv2plugin.cpp (krename-4.90.90) | ||
---|---|---|---|---|
skipping to change at line 18 | skipping to change at line 18 | |||
/*************************************************************************** | /*************************************************************************** | |||
* * | * * | |||
* This program is free software; you can redistribute it and/or modify * | * 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 * | * it under the terms of the GNU General Public License as published by * | |||
* the Free Software Foundation; either version 2 of the License, or * | * the Free Software Foundation; either version 2 of the License, or * | |||
* (at your option) any later version. * | * (at your option) any later version. * | |||
* * | * * | |||
***************************************************************************/ | ***************************************************************************/ | |||
#include "../config-krename.h" | ||||
#ifdef HAVE_EXIV2 | ||||
#include "exiv2plugin.h" | #include "exiv2plugin.h" | |||
#include <klocale.h> | #include <KLocalizedString> | |||
#include <exiv2/error.hpp> | #include <exiv2/error.hpp> | |||
#include <exiv2/exif.hpp> | #include <exiv2/exif.hpp> | |||
#include <exiv2/image.hpp> | #include <exiv2/image.hpp> | |||
#include <exiv2/iptc.hpp> | #include <exiv2/iptc.hpp> | |||
#include <exiv2/xmp.hpp> | #include <exiv2/xmp.hpp> | |||
#include <exiv2/tags.hpp> | #include <exiv2/tags.hpp> | |||
#include "batchrenamer.h" | #include "batchrenamer.h" | |||
#include "tokenhelpdialog.h" | #include "tokenhelpdialog.h" | |||
using namespace Exiv2; | using namespace Exiv2; | |||
static const char* exifTags[] = { | static const char *exifTags[] = { | |||
"Exif.Image.ImageWidth", | "Exif.Image.ImageWidth", | |||
"Exif.Image.ImageLength", | "Exif.Image.ImageLength", | |||
"Exif.Image.BitsPerSample", | "Exif.Image.BitsPerSample", | |||
"Exif.Image.Compression", | "Exif.Image.Compression", | |||
"Exif.Image.PhotometricInterpretation", | "Exif.Image.PhotometricInterpretation", | |||
"Exif.Image.Orientation", | "Exif.Image.Orientation", | |||
"Exif.Image.SamplesPerPixel", | "Exif.Image.SamplesPerPixel", | |||
"Exif.Image.PlanarConfiguration", | "Exif.Image.PlanarConfiguration", | |||
"Exif.Image.YCbCrSubSampling", | "Exif.Image.YCbCrSubSampling", | |||
"Exif.Image.YCbCrPositioning", | "Exif.Image.YCbCrPositioning", | |||
skipping to change at line 144 | skipping to change at line 141 | |||
"Exif.GPSInfo.GPSDestBearingRef", | "Exif.GPSInfo.GPSDestBearingRef", | |||
"Exif.GPSInfo.GPSDestBearing", | "Exif.GPSInfo.GPSDestBearing", | |||
"Exif.GPSInfo.GPSDestDistanceRef", | "Exif.GPSInfo.GPSDestDistanceRef", | |||
"Exif.GPSInfo.GPSDestDistance", | "Exif.GPSInfo.GPSDestDistance", | |||
"Exif.GPSInfo.GPSProcessingMethod", | "Exif.GPSInfo.GPSProcessingMethod", | |||
"Exif.GPSInfo.GPSAreaInformation", | "Exif.GPSInfo.GPSAreaInformation", | |||
"Exif.GPSInfo.GPSDifferential", | "Exif.GPSInfo.GPSDifferential", | |||
NULL | NULL | |||
}; | }; | |||
static const char* xmpTags[] = { | static const char *xmpTags[] = { | |||
"Xmp.tiff.ImageWidth", | "Xmp.tiff.ImageWidth", | |||
"Xmp.tiff.ImageLength", | "Xmp.tiff.ImageLength", | |||
"Xmp.tiff.BitsPerSample", | "Xmp.tiff.BitsPerSample", | |||
"Xmp.tiff.Compression", | "Xmp.tiff.Compression", | |||
"Xmp.tiff.PhotometricInterpretation", | "Xmp.tiff.PhotometricInterpretation", | |||
"Xmp.tiff.Orientation", | "Xmp.tiff.Orientation", | |||
"Xmp.tiff.SamplesPerPixe", | "Xmp.tiff.SamplesPerPixe", | |||
"Xmp.tiff.PlanarConfiguration", | "Xmp.tiff.PlanarConfiguration", | |||
"Xmp.tiff.YCbCrSubSampling", | "Xmp.tiff.YCbCrSubSampling", | |||
"Xmp.tiff.YCbCrPositioning", | "Xmp.tiff.YCbCrPositioning", | |||
skipping to change at line 272 | skipping to change at line 269 | |||
"Xmp.photoshop.TransmissionReference", | "Xmp.photoshop.TransmissionReference", | |||
"Xmp.photoshop.Headline", | "Xmp.photoshop.Headline", | |||
"Xmp.photoshop.Credit", | "Xmp.photoshop.Credit", | |||
"Xmp.photoshop.Source", | "Xmp.photoshop.Source", | |||
"Xmp.dc.rights", | "Xmp.dc.rights", | |||
"Xmp.dc.description", | "Xmp.dc.description", | |||
"Xmp.photoshop.CaptionWriter", | "Xmp.photoshop.CaptionWriter", | |||
NULL | NULL | |||
}; | }; | |||
static const char* iptcTags[] = { | static const char *iptcTags[] = { | |||
"Iptc.Application2.ObjectName", | "Iptc.Application2.ObjectName", | |||
"Iptc.Application2.Urgency", | "Iptc.Application2.Urgency", | |||
"Iptc.Application2.Category", | "Iptc.Application2.Category", | |||
"Iptc.Application2.SuppCategory", | "Iptc.Application2.SuppCategory", | |||
"Iptc.Application2.Keywords", | "Iptc.Application2.Keywords", | |||
"Iptc.Application2.LocationName", | "Iptc.Application2.LocationName", | |||
"Iptc.Application2.SpecialInstructions", | "Iptc.Application2.SpecialInstructions", | |||
"Iptc.Application2.DateCreated", | "Iptc.Application2.DateCreated", | |||
"Iptc.Application2.Byline", | "Iptc.Application2.Byline", | |||
"Iptc.Application2.BylineTitle", | "Iptc.Application2.BylineTitle", | |||
skipping to change at line 297 | skipping to change at line 294 | |||
"Iptc.Application2.TransmissionReference", | "Iptc.Application2.TransmissionReference", | |||
"Iptc.Application2.Headline", | "Iptc.Application2.Headline", | |||
"Iptc.Application2.Credit", | "Iptc.Application2.Credit", | |||
"Iptc.Application2.Source", | "Iptc.Application2.Source", | |||
"Iptc.Application2.Copyright", | "Iptc.Application2.Copyright", | |||
"Iptc.Application2.Caption", | "Iptc.Application2.Caption", | |||
"Iptc.Application2.Writer", | "Iptc.Application2.Writer", | |||
NULL | NULL | |||
}; | }; | |||
Exiv2Plugin::Exiv2Plugin( PluginLoader* loader ) | Exiv2Plugin::Exiv2Plugin(PluginLoader *loader) | |||
: FilePlugin( loader ) | : FilePlugin(loader) | |||
{ | { | |||
const QString prefix("exif"); | const QString prefix("exif"); | |||
const char** token; | const char **token; | |||
this->addSupportedToken("exifComment"); | this->addSupportedToken("exifComment"); | |||
//this->addSupportedToken("exifWidth"); | //this->addSupportedToken("exifWidth"); | |||
//this->addSupportedToken("exifHeight"); | //this->addSupportedToken("exifHeight"); | |||
m_help.append( "[exifComment]" + TokenHelpDialog::getTokenSeparator() + i18n ("Insert the comment of an image") ); | m_help.append("[exifComment]" + TokenHelpDialog::getTokenSeparator() + i18n( "Insert the comment of an image")); | |||
//m_help.append( "[exifWidth]" + TokenHelpDialog::getTokenSeparator() + i18n ("Insert the width in pixel of an image") ); | //m_help.append( "[exifWidth]" + TokenHelpDialog::getTokenSeparator() + i18n ("Insert the width in pixel of an image") ); | |||
//m_help.append( "[exifHeight]" + TokenHelpDialog::getTokenSeparator() + i18 n("Insert the height in pixel of an image") ); | //m_help.append( "[exifHeight]" + TokenHelpDialog::getTokenSeparator() + i18 n("Insert the height in pixel of an image") ); | |||
// Add exif taks | // Add exif taks | |||
token = exifTags; | token = exifTags; | |||
while( *token ) | while (*token) { | |||
{ | ExifKey key(*token); | |||
ExifKey key( *token ); | ||||
QString help; | QString help; | |||
try { | try { | |||
help = QString::fromUtf8(key.tagLabel().c_str()); | help = QString::fromUtf8(key.tagLabel().c_str()); | |||
} catch( std::exception e ) { | } catch (std::exception e) { | |||
help = ""; | help = ""; | |||
// exiv2 throws sometimes exceptions | // exiv2 throws sometimes exceptions | |||
// because it trys to create std::string from NULL pointers | // because it tries to create std::string from NULL pointers | |||
} | } | |||
QString cur( *token ); | QString cur(*token); | |||
this->addSupportedToken( prefix + cur ); | this->addSupportedToken(prefix + cur); | |||
m_help.append( QString("[") + prefix + cur + QString("]") + TokenHelpDi | m_help.append(QString("[") + prefix + cur + QString("]") + TokenHelpDia | |||
alog::getTokenSeparator() + help ); | log::getTokenSeparator() + help); | |||
m_mapRealKeys[QString( prefix + cur ).toLower()] = cur; | m_mapRealKeys[QString(prefix + cur).toLower()] = cur; | |||
++token; | ++token; | |||
} | } | |||
// Add exif taks | // Add exif taks | |||
token = xmpTags; | token = xmpTags; | |||
while( *token ) | while (*token) { | |||
{ | XmpKey key(*token); | |||
XmpKey key( *token ); | ||||
QString help; | QString help; | |||
try { | try { | |||
help = QString::fromUtf8(key.tagLabel().c_str()); | help = QString::fromUtf8(key.tagLabel().c_str()); | |||
} catch( std::exception e ) { | } catch (std::exception e) { | |||
help = ""; | help = ""; | |||
// exiv2 throws sometimes exceptions | // exiv2 throws sometimes exceptions | |||
// because it trys to create std::string from NULL pointers | // because it tries to create std::string from NULL pointers | |||
} | } | |||
QString cur( *token ); | QString cur(*token); | |||
this->addSupportedToken( prefix + cur ); | this->addSupportedToken(prefix + cur); | |||
m_help.append( QString("[") + prefix + cur + QString("]") + TokenHelpDia | m_help.append(QString("[") + prefix + cur + QString("]") + TokenHelpDial | |||
log::getTokenSeparator() + help ); | og::getTokenSeparator() + help); | |||
m_mapRealKeys[QString( prefix + cur ).toLower()] = cur; | m_mapRealKeys[QString(prefix + cur).toLower()] = cur; | |||
++token; | ++token; | |||
} | } | |||
// Add exif taks | // Add exif taks | |||
token = iptcTags; | token = iptcTags; | |||
while( *token ) | while (*token) { | |||
{ | IptcKey key(*token); | |||
IptcKey key( *token ); | ||||
QString help; | QString help; | |||
try { | try { | |||
help = QString::fromUtf8(key.tagLabel().c_str()); | help = QString::fromUtf8(key.tagLabel().c_str()); | |||
} catch( std::exception e ) { | } catch (std::exception e) { | |||
help = ""; | help = ""; | |||
// exiv2 throws sometimes exceptions | // exiv2 throws sometimes exceptions | |||
// because it trys to create std::string from NULL pointers | // because it tries to create std::string from NULL pointers | |||
} | } | |||
QString cur( *token ); | QString cur(*token); | |||
this->addSupportedToken( prefix + cur ); | this->addSupportedToken(prefix + cur); | |||
m_help.append( QString("[") + prefix + cur + QString("]") + TokenHelpDia | m_help.append(QString("[") + prefix + cur + QString("]") + TokenHelpDial | |||
log::getTokenSeparator() + help ); | og::getTokenSeparator() + help); | |||
m_mapRealKeys[QString( prefix + cur ).toLower()] = cur; | m_mapRealKeys[QString(prefix + cur).toLower()] = cur; | |||
++token; | ++token; | |||
} | } | |||
m_name = i18n("Exiv2 (JPEG/TIFF Exif) Plugin"); | m_name = i18n("Exiv2 (JPEG/TIFF Exif) Plugin"); | |||
m_comment = i18n("<qt>This plugin supports reading tags from " | m_comment = i18n("<qt>This plugin supports reading tags from " | |||
"JPEG and TIFF files.</qt>"); | "JPEG and TIFF files.</qt>"); | |||
m_icon = "image-x-generic"; | m_icon = "image-x-generic"; | |||
} | } | |||
QString Exiv2Plugin::processFile( BatchRenamer* b, int index, const QString & fi lenameOrToken, EPluginType ) | QString Exiv2Plugin::processFile(BatchRenamer *b, int index, const QString &file nameOrToken, EPluginType) | |||
{ | { | |||
QString token( filenameOrToken.toLower() ); | QString token(filenameOrToken.toLower()); | |||
QString filename = (*b->files())[index].srcUrl().path(); | QString filename = (*b->files())[index].srcUrl().path(); | |||
if( !this->supports( token ) ) | if (!this->supports(token)) { | |||
return QString(""); | return QString(""); | |||
} | ||||
//const QByteArray asc = filename.toAscii(); | //const QByteArray asc = filename.toAscii(); | |||
// Use toUtf8 so that unicode filenames will work | // Use toUtf8 so that unicode filenames will work | |||
const QByteArray asc = filename.toUtf8(); | const QByteArray asc = filename.toUtf8(); | |||
std::string strFilename(asc.constData(), asc.length()); | std::string strFilename(asc.constData(), asc.length()); | |||
try | try { | |||
{ | Image::AutoPtr image = Exiv2::ImageFactory::open(strFilename); | |||
Image::AutoPtr image = Exiv2::ImageFactory::open( strFilename ); | if (image.get() != nullptr && image->good()) { | |||
if( image.get() != NULL && image->good() ) | ||||
{ | ||||
image->readMetadata(); | image->readMetadata(); | |||
if( token == "exifcomment" ) | if (token == "exifcomment") { | |||
return QString::fromUtf8( image->comment().c_str() ); | return QString::fromUtf8(image->comment().c_str()); | |||
} | ||||
/* | /* | |||
else if( token =="exifwidth" ) | else if( token =="exifwidth" ) | |||
return QString::number( image->pixelWidth() ); | return QString::number( image->pixelWidth() ); | |||
else if( token =="exifheight" ) | else if( token =="exifheight" ) | |||
return QString::number( image->pixelHeight() ); | return QString::number( image->pixelHeight() ); | |||
*/ | */ | |||
if( token.startsWith("exifexif.") ) | if (token.startsWith(QLatin1String("exifexif."))) { | |||
{ | ExifKey key(m_mapRealKeys[token].toLatin1().data()); | |||
ExifKey key( m_mapRealKeys[token].toAscii().data() ); | ExifData::const_iterator it = image->exifData().findKey(key); | |||
ExifData::const_iterator it = image->exifData().findKey( key ); | if (it != image->exifData().end()) { | |||
if( it != image->exifData().end() ) | ||||
{ | ||||
std::string val = (*it).toString(); | std::string val = (*it).toString(); | |||
return QString::fromUtf8( val.c_str() ); | return QString::fromUtf8(val.c_str()); | |||
} | } | |||
} | } else if (token.startsWith(QLatin1String("exifxmp."))) { | |||
else if( token.startsWith("exifxmp.") ) | XmpKey key(m_mapRealKeys[token].toLatin1().data()); | |||
{ | XmpData::const_iterator it = image->xmpData().findKey(key); | |||
XmpKey key( m_mapRealKeys[token].toAscii().data() ); | if (it != image->xmpData().end()) { | |||
XmpData::const_iterator it = image->xmpData().findKey( key ); | ||||
if( it != image->xmpData().end() ) | ||||
{ | ||||
std::string val = (*it).toString(); | std::string val = (*it).toString(); | |||
return QString::fromUtf8( val.c_str() ); | return QString::fromUtf8(val.c_str()); | |||
} | } | |||
} | } else if (token.startsWith(QLatin1String("exifiptc."))) { | |||
else if( token.startsWith("exifiptc.") ) | IptcKey key(m_mapRealKeys[token].toLatin1().data()); | |||
{ | IptcData::const_iterator it = image->iptcData().findKey(key); | |||
IptcKey key( m_mapRealKeys[token].toAscii().data() ); | if (it != image->iptcData().end()) { | |||
IptcData::const_iterator it = image->iptcData().findKey( key ); | ||||
if( it != image->iptcData().end() ) | ||||
{ | ||||
std::string val = (*it).toString(); | std::string val = (*it).toString(); | |||
return QString::fromUtf8( val.c_str() ); | return QString::fromUtf8(val.c_str()); | |||
} | } | |||
} | } | |||
} | } | |||
} | } catch (std::exception &err) { | |||
catch( std::exception & err ) | return QString::fromUtf8(err.what()); | |||
{ | ||||
return QString::fromUtf8( err.what() ); | ||||
} | } | |||
return QString(""); | return QString(""); | |||
} | } | |||
#endif // HAVE_EXIV2 | ||||
End of changes. 37 change blocks. | ||||
78 lines changed or deleted | 62 lines changed or added |