Commit c47ce5ad authored by Johannes Zarl-Zierl's avatar Johannes Zarl-Zierl
Browse files

Basic libkipi-2.0.0 support.

BUG: 307148
parent 07eb3580
......@@ -1401,11 +1401,19 @@ void MainWindow::Window::loadPlugins()
QStringList ignores;
ignores << QString::fromLatin1( "CommentsEditor" )
<< QString::fromLatin1( "HelloWorld" );
<< QString::fromLatin1( "HelloWorld" );
#if KIPI_VERSION >= 0x020000
_pluginLoader = new KIPI::PluginLoader();
_pluginLoader->setIgnoredPluginsList( ignores );
_pluginLoader->setInterface( _pluginInterface );
connect( _pluginLoader, SIGNAL( replug() ), this, SLOT( plug() ) );
_pluginLoader->loadPlugins();
#else
_pluginLoader = new KIPI::PluginLoader( ignores, _pluginInterface );
connect( _pluginLoader, SIGNAL( replug() ), this, SLOT( plug() ) );
_pluginLoader->loadPlugins();
#endif
// Setup signals
connect( _thumbnailView, SIGNAL( selectionChanged(int) ), this, SLOT( slotSelectionChanged(int) ) );
......@@ -1778,3 +1786,4 @@ void MainWindow::Window::setHistogramVisibilty( bool visible ) const
}
#include "Window.moc"
// vi:expandtab:tabstop=4 shiftwidth=4:
......@@ -41,6 +41,7 @@ class KActionMenu;
#include <QPointer>
#include <config-kpa-kipi.h>
#ifdef HASKIPI
# include <libkipi/version.h>
# include <libkipi/pluginloader.h>
#endif
#include "DB/FileNameList.h"
......
......@@ -33,31 +33,45 @@ Plugins::ImageInfo::ImageInfo( KIPI::Interface* interface, const KUrl& url )
_info = DB::ImageDB::instance()->info( DB::FileName::fromAbsolutePath(_url.path()));
}
QString Plugins::ImageInfo::title()
{
if ( _info )
return _info->label();
else
return QString();
}
QString Plugins::ImageInfo::description()
{
if ( _info )
return _info->description();
else
return QString();
}
QMap<QString,QVariant> Plugins::ImageInfo::attributes()
{
Q_ASSERT( _info );
QMap<QString,QVariant> res;
res.insert(QString::fromLatin1("name"), QFileInfo(_info->fileName().absolute()).baseName());
res.insert(QString::fromLatin1("comment"), _info->description());
res.insert(QLatin1String("date"), _info->date().start());
res.insert(QLatin1String("dateto"), _info->date().end());
res.insert(QLatin1String("isexactdate"), _info->date().start() == _info->date().end());
res.insert(QString::fromLatin1("orientation"), _info->angle());
res.insert(QString::fromLatin1("angle"), _info->angle()); // for compatibility with older versions. Now called orientation.
res.insert(QString::fromLatin1("title"), _info->label());
res.insert(QString::fromLatin1("rating"), _info->rating());
// not supported:
//res.insert(QString::fromLatin1("colorlabel"), xxx );
//res.insert(QString::fromLatin1("picklabel"), xxx );
DB::GpsCoordinates position = _info->geoPosition();
if (!position.isNull()) {
res.insert(QString::fromLatin1("longitude"), QVariant(position.longitude()));
res.insert(QString::fromLatin1("latitude"), QVariant(position.latitude()));
res.insert(QString::fromLatin1("altitude"), QVariant(position.altitude()));
if (position.precision() != DB::GpsCoordinates::NoPrecisionData) {
// XXX: attribute not mentioned in libkipi/imageinfo.h -> is this supported?
res.insert(QString::fromLatin1("positionPrecision"), QVariant(position.precision()));
}
}
// Flickr plug-in expects the item tags, so we better give them.
QString text;
QList<DB::CategoryPtr> categories = DB::ImageDB::instance()->categoryCollection()->categories();
QStringList tags;
for( QList<DB::CategoryPtr>::Iterator categoryIt = categories.begin(); categoryIt != categories.end(); ++categoryIt ) {
for( QList<DB::CategoryPtr>::Iterator categoryIt = categories.begin(); categoryIt != categories.end(); ++categoryIt ) {
QString categoryName = (*categoryIt)->name();
if ( categoryName == QString::fromLatin1( "Folder" ) || categoryName == QString::fromLatin1( "Media Type" ) || categoryName == QString::fromLatin1( "Tokens" ) )
continue;
......@@ -68,68 +82,100 @@ QMap<QString,QVariant> Plugins::ImageInfo::attributes()
}
}
}
res.insert(QString::fromLatin1( "keywords" ), tags );
res.insert(QString::fromLatin1( "tags" ), tags );
res.insert(QString::fromLatin1( "tagspath" ), tags );
if ( _info ) {
DB::GpsCoordinates position = _info->geoPosition();
if (!position.isNull()) {
res.insert(QString::fromLatin1("longitude"), QVariant(position.longitude()));
res.insert(QString::fromLatin1("latitude"), QVariant(position.latitude()));
res.insert(QString::fromLatin1("altitude"), QVariant(position.altitude()));
if (position.precision() != DB::GpsCoordinates::NoPrecisionData) {
res.insert(QString::fromLatin1("positionPrecision"), QVariant(position.precision()));
}
}
res.insert(QString::fromLatin1( "keywords" ), tags );
res.insert(QString::fromLatin1( "tags" ), tags ); // for compatibility with older versions. Now called keywords.
res.insert(QLatin1String("date"), _info->date().start());
res.insert(QLatin1String("dateto"), _info->date().end());
res.insert(QLatin1String("isexactdate"), _info->date().start() == _info->date().end());
}
// TODO: implement this:
//res.insert(QString::fromLatin1( "filesize" ), xxx );
res.insert(QString::fromLatin1("name"), QFileInfo(_info->fileName().absolute()).baseName());
// not supported:
//res.insert(QString::fromLatin1( "creators" ), xxx );
//res.insert(QString::fromLatin1( "credit" ), xxx );
//res.insert(QString::fromLatin1( "rights" ), xxx );
//res.insert(QString::fromLatin1( "source" ), xxx );
return res;
}
void Plugins::ImageInfo::setTitle( const QString& name )
{
if ( _info ) {
_info->setLabel( name );
MainWindow::DirtyIndicator::markDirty();
}
}
void Plugins::ImageInfo::setDescription( const QString& description )
{
if ( _info ) {
_info->setDescription( description );
MainWindow::DirtyIndicator::markDirty();
}
}
void Plugins::ImageInfo::clearAttributes()
{
if( _info ) {
_info->clearAllCategoryInfo();
// TODO I think it is reasonable to keep the gps position anyway, isn't it?
MainWindow::DirtyIndicator::markDirty();
_info->clearAllCategoryInfo();
// TODO I think it is reasonable to keep the gps position anyway, isn't it?
MainWindow::DirtyIndicator::markDirty();
// official behaviour is to delete all officially supported attributes:
// QStringList attr;
// attr.append("comment");
// attr.append("date");
// attr.append("title");
// attr.append("orientation");
// attr.append("tagspath");
// attr.append("rating");
// attr.append("colorlabel");
// attr.append("picklabel");
// attr.append("gpslocation");
// attr.append("copyrights");
// delAttributes(attr);
}
}
void Plugins::ImageInfo::addAttributes( const QMap<QString,QVariant>& map )
void Plugins::ImageInfo::addAttributes( const QMap<QString,QVariant>& amap )
{
if ( _info ) {
for( QMap<QString,QVariant>::ConstIterator it = map.begin(); it != map.end(); ++it ) {
QStringList list = it.value().toStringList();
if (isCategoryAttribute(it.key())) {
_info->addCategoryInfo( it.key(), list.toSet() );
}
if ( _info && ! amap.empty() ) {
QMap<QString,QVariant> map = amap;
if ( map.contains(QLatin1String("name")) )
{
// plugin renamed the item
// TODO: implement this
qWarning("File renaming by kipi-plugin not supported.");
//map.remove(QLatin1String("name"));
}
if ( map.contains(QLatin1String("comment")) )
{
// is it save to do that? digikam seems to allow multiple comments on a single image
// if a plugin assumes that it is adding a comment, not setting it, things might go badly...
_info->setDescription( map[QLatin1String("comment")].toString() );
map.remove(QLatin1String("comment"));
}
// note: this probably won't work as expected because according to the spec,
// "isexactdate" is supposed to be readonly and therefore never set here:
if (map.contains(QLatin1String("isexactdate")) && map.contains(QLatin1String("date"))) {
_info->setDate(DB::ImageDate(map[QLatin1String("date")].toDateTime()));
map.remove(QLatin1String("date"));
} else if (map.contains(QLatin1String("date")) && map.contains(QLatin1String("dateto"))) {
_info->setDate(DB::ImageDate(map[QLatin1String("date")].toDateTime(), map[QLatin1String("dateto")].toDateTime()));
map.remove(QLatin1String("date"));
map.remove(QLatin1String("dateto"));
} else if (map.contains(QLatin1String("date"))) {
_info->setDate(DB::ImageDate(map[QLatin1String("date")].toDateTime()));
map.remove(QLatin1String("date"));
}
if ( map.contains(QLatin1String("angle")) )
{
qWarning("Kipi-plugin uses deprecated attribute \"angle\".");
_info->setAngle( map[QLatin1String("angle")].toInt() );
map.remove(QLatin1String("angle"));
}
if ( map.contains(QLatin1String("orientation")) )
{
_info->setAngle( map[QLatin1String("orientation")].toInt() );
map.remove(QLatin1String("orientation"));
}
if ( map.contains(QLatin1String("title")) )
{
_info->setLabel( map[QLatin1String("title")].toString() );
map.remove(QLatin1String("title"));
}
if ( map.contains(QLatin1String("rating")) )
{
_info->setRating( map[QLatin1String("rating")].toInt() );
map.remove(QLatin1String("rating"));
}
if (map.contains(QLatin1String("longitude")) ||
map.contains(QLatin1String("latitude")) ||
map.contains(QLatin1String("altitude")) ||
map.contains(QLatin1String("positionPrecision"))) {
map.contains(QLatin1String("latitude")) ||
map.contains(QLatin1String("altitude")) ||
map.contains(QLatin1String("positionPrecision"))) {
if (map.contains(QLatin1String("longitude")) && map.contains(QLatin1String("latitude"))) {
double altitude = 0;
QVariant var = map[QLatin1String("altitude")];
......@@ -143,42 +189,152 @@ void Plugins::ImageInfo::addAttributes( const QMap<QString,QVariant>& map )
}
DB::GpsCoordinates coord(map[QLatin1String("longitude")].toDouble(), map[QLatin1String("latitude")].toDouble(), altitude, precision);
_info->setGeoPosition(coord);
map.remove(QLatin1String("longitude"));
map.remove(QLatin1String("latitude"));
map.remove(QLatin1String("altitude"));
map.remove(QLatin1String("positionPrecision"));
} else {
qWarning("Geo coordinates incomplete. Need at least 'longitude' and 'latitude', optionally 'altitude' and 'positionPrecision'");
}
}
if (map.contains(QLatin1String("isexactdate")) && map.contains(QLatin1String("date"))) {
_info->setDate(DB::ImageDate(map[QLatin1String("date")].toDateTime()));
} else if (map.contains(QLatin1String("date")) && map.contains(QLatin1String("dateto"))) {
_info->setDate(DB::ImageDate(map[QLatin1String("date")].toDateTime(), map[QLatin1String("dateto")].toDateTime()));
} else if (map.contains(QLatin1String("date"))) {
_info->setDate(DB::ImageDate(map[QLatin1String("date")].toDateTime()));
// remove read-only keywords:
map.remove(QLatin1String("filesize"));
map.remove(QLatin1String("isexactdate"));
map.remove(QLatin1String("keywords"));
map.remove(QLatin1String("tags"));
// FIXME: how exactly is this supposed to work?
// all this will do is to set the following categories to some (mostly meaningless?) value:
// colorlabel
// picklabel
// creators
// credit
// rights
// source
for( QMap<QString,QVariant>::ConstIterator it = map.begin(); it != map.end(); ++it ) {
QStringList list = it.value().toStringList();
if (isCategoryAttribute(it.key())) {
_info->addCategoryInfo( it.key(), list.toSet() );
}
}
MainWindow::DirtyIndicator::markDirty();
}
}
void Plugins::ImageInfo::delAttributes( const QStringList& delAttrs)
void Plugins::ImageInfo::delAttributes( const QStringList& attrs)
{
if (_info) {
for (QStringList::const_iterator it = delAttrs.begin(); it != delAttrs.end(); ++it) {
if (isCategoryAttribute(*it)) {
_info->setCategoryInfo(*it, Utilities::StringSet());
}
if ( _info && ! attrs.empty() ) {
QStringList delAttrs = attrs;
if ( delAttrs.contains(QLatin1String("comment")))
{
_info->setDescription( QString() );
delAttrs.removeAll(QLatin1String("comment"));
}
// not supported: date
if ( delAttrs.contains(QLatin1String("orientation")) ||
delAttrs.contains(QLatin1String("angle")) )
{
_info->setAngle( 0 );
delAttrs.removeAll(QLatin1String("orientation"));
delAttrs.removeAll(QLatin1String("angle"));
}
if (delAttrs.contains(QLatin1String("tags"))) {
//TODO very probably a misunderstanding, isn't it?
qWarning("Ignoring 'remove all tags'");
if ( delAttrs.contains(QLatin1String("title")))
{
_info->setLabel( QString() );
delAttrs.removeAll(QLatin1String("title"));
}
if (delAttrs.contains(QLatin1String("longitude")) && delAttrs.contains(QLatin1String("latitude"))) {
// TODO:
// rating
// (colorlabel)
// (picklabel)
// copyrights
// --> mail miika if the "freeform tag set/delete" works with any plugin, currently
if ( delAttrs.contains(QLatin1String("tags")) ||
delAttrs.contains(QLatin1String("keywords")) ||
delAttrs.contains(QLatin1String("tagspath")))
{
_info->clearAllCategoryInfo();
delAttrs.removeAll(QLatin1String("tags"));
delAttrs.removeAll(QLatin1String("keywords"));
delAttrs.removeAll(QLatin1String("tagspath"));
}
if ( delAttrs.contains(QLatin1String("gpslocation")) )
{
//clear position:
_info->setGeoPosition(DB::GpsCoordinates());
delAttrs.removeAll(QLatin1String("gpslocation"));
}
// FIXME: how exactly is this supposed to work?
for (QStringList::const_iterator it = delAttrs.begin(); it != delAttrs.end(); ++it) {
if (isCategoryAttribute(*it)) {
_info->setCategoryInfo(*it, Utilities::StringSet());
}
}
MainWindow::DirtyIndicator::markDirty();
}
}
#if KIPI_VERSION >= 0x010200
#define KIPI_IMAGEINFO_CONST_MODIFIER const
#else
#define KIPI_IMAGEINFO_CONST_MODIFIER
#endif
void Plugins::ImageInfo::cloneData( ImageInfoShared* KIPI_IMAGEINFO_CONST_MODIFIER other )
{
ImageInfoShared::cloneData( other );
if ( _info ) {
Plugins::ImageInfo* inf = static_cast<Plugins::ImageInfo*>( other );
_info->setDate( inf->_info->date() );
MainWindow::DirtyIndicator::markDirty();
}
}
#undef KIPI_IMAGEINFO_CONST_MODIFIER
#if KIPI_VERSION < 0x010500
#if KIPI_VERSION >= 0x010300
#define KIPI_IMAGEINFO_FILINAMEFUN_GETTER_NAME name
#define KIPI_IMAGEINFO_FILINAMEFUN_SETTER_NAME setName
#else
#define KIPI_IMAGEINFO_FILINAMEFUN_GETTER_NAME title
#define KIPI_IMAGEINFO_FILINAMEFUN_SETTER_NAME setTitle
#endif
QString Plugins::ImageInfo::KIPI_IMAGEINFO_FILINAMEFUN_GETTER_NAME()
{
if ( _info )
return _info->label();
else
return QString();
}
void Plugins::ImageInfo::KIPI_IMAGEINFO_FILINAMEFUN_SETTER_NAME( const QString& name )
{
if ( _info ) {
_info->setLabel( name );
MainWindow::DirtyIndicator::markDirty();
}
}
#undef KIPI_IMAGEINFO_FILINAMEFUN_GETTER_NAME
#undef KIPI_IMAGEINFO_FILINAMEFUN_SETTER_NAME
QString Plugins::ImageInfo::description()
{
if ( _info )
return _info->description();
else
return QString();
}
void Plugins::ImageInfo::setDescription( const QString& description )
{
if ( _info ) {
_info->setDescription( description );
MainWindow::DirtyIndicator::markDirty();
}
}
int Plugins::ImageInfo::angle()
{
if ( _info )
......@@ -229,16 +385,7 @@ void Plugins::ImageInfo::setTime( const QDateTime& time, KIPI::TimeSpec spec )
MainWindow::DirtyIndicator::markDirty();
}
}
void Plugins::ImageInfo::cloneData( ImageInfoShared* other )
{
ImageInfoShared::cloneData( other );
if ( _info ) {
Plugins::ImageInfo* inf = static_cast<Plugins::ImageInfo*>( other );
_info->setDate( inf->_info->date() );
MainWindow::DirtyIndicator::markDirty();
}
}
#endif // KIPI_VERSION < 0x010500
bool Plugins::ImageInfo::isPositionAttribute(const QString &key)
{
......@@ -251,3 +398,4 @@ bool Plugins::ImageInfo::isCategoryAttribute(const QString &key)
}
#endif // KIPI
// vi:expandtab:tabstop=4 shiftwidth=4:
......@@ -20,6 +20,7 @@
#define MYIMAGEINFO_H
#include <config-kpa-kipi.h>
#include <libkipi/version.h>
#include <libkipi/imageinfoshared.h>
#include <kdemacros.h>
#include "DB/ImageInfoPtr.h"
......@@ -36,34 +37,50 @@ class KDE_EXPORT ImageInfo :public KIPI::ImageInfoShared
{
public:
ImageInfo( KIPI::Interface* interface, const KUrl& url );
virtual QString title();
virtual void setTitle( const QString& );
virtual QString description();
virtual void setDescription( const QString& );
#if KIPI_VERSION < 0x010500
// kipi 1.5.0 uses attributes()/addAttributes() instead of these:
#if KIPI_VERSION >= 0x010300
QString name();
void setName( const QString& );
#else
// "title" means filename
QString title();
void setTitle( const QString& );
#endif
virtual QMap<QString,QVariant> attributes();
virtual void clearAttributes();
virtual void addAttributes( const QMap<QString,QVariant>& );
virtual void delAttributes( const QStringList& );
QString description();
void setDescription( const QString& );
virtual int angle();
virtual void setAngle( int );
int angle();
void setAngle( int );
virtual QDateTime time( KIPI::TimeSpec what );
virtual void setTime( const QDateTime& time, KIPI::TimeSpec spec );
virtual bool isTimeExact();
QDateTime time( KIPI::TimeSpec what );
void setTime( const QDateTime& time, KIPI::TimeSpec spec );
bool isTimeExact();
#endif // KIPI_VERSION < 0x010500
QMap<QString,QVariant> attributes();
void clearAttributes();
void addAttributes( const QMap<QString,QVariant>& );
void delAttributes( const QStringList& );
#if KIPI_VERSION >= 0x010200
void cloneData( ImageInfoShared* const other);
#else
void cloneData( ImageInfoShared* other);
#endif // KIPI_VERSION >= 0x010200
virtual void cloneData( ImageInfoShared* other );
private:
DB::ImageInfoPtr _info;
virtual bool isPositionAttribute(const QString &key);
virtual bool isCategoryAttribute(const QString &key);
bool isPositionAttribute(const QString &key);
bool isCategoryAttribute(const QString &key);
};
}
#endif /* MYIMAGEINFO_H */
// vi:expandtab:tabstop=4 shiftwidth=4:
......@@ -22,6 +22,10 @@
#include <MainWindow/Window.h>
#include <config-kpa-kipi.h>
#ifdef HASKIPI
# include <libkipi/version.h>
#if KIPI_VERSION >= 0x020000
# include <libkipi/configwidget.h>
#endif
# include <libkipi/pluginloader.h>
#endif
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment