[Digikam-devel] [kipi-plugins] common/libkipiplugins: new KIPI ImageInfo wrapper to easy manage item properties with KIPI host application.

Gilles Caulier caulier.gilles at gmail.com
Mon Feb 6 09:31:59 GMT 2012


Git commit 54e8062e048f5b291426e50801f2814001a6b0bc by Gilles Caulier.
Committed on 06/02/2012 at 10:25.
Pushed by cgilles into branch 'master'.

new KIPI ImageInfo wrapper to easy manage item properties with KIPI host application.
This class will prevent to patch libkipi in the future to be able to manage more properties,
_WITHOUT_ to break binary compatibility between plugin and host application.
The goal is to always use KIPI::*attributes*() methods to exange information between plugin and host.
This wrapper will be a collection of methods to help developpers to items get/set properties without complixity.
It can be extended without any problem and without to touch libkipi.
Currently only description properties is managed, others lead item properties will be supported later...
CCMAIL: kde-imaging at kde.org
CCMAIL: digikam-devel at kde.org

M  +3    -2    common/libkipiplugins/CMakeLists.txt
A  +90   -0    common/libkipiplugins/tools/kpimageinfo.cpp     [License: GPL (v2+)]
A  +70   -0    common/libkipiplugins/tools/kpimageinfo.h     [License: GPL (v2+)]

http://commits.kde.org/kipi-plugins/54e8062e048f5b291426e50801f2814001a6b0bc

diff --git a/common/libkipiplugins/CMakeLists.txt b/common/libkipiplugins/CMakeLists.txt
index d2d2fb8..486c52f 100644
--- a/common/libkipiplugins/CMakeLists.txt
+++ b/common/libkipiplugins/CMakeLists.txt
@@ -4,9 +4,10 @@ INCLUDE_DIRECTORIES(${JPEG_INCLUDE_DIR} ${PNG_INCLUDE_DIR} ${TIFF_INCLUDE_DIR})
 
 SET(kipiplugins_LIB_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpaboutdata.cpp
                          ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpwriteimage.cpp
+                         ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpimageinfo.cpp
+                         ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpwritehelp.cpp
                          ${CMAKE_CURRENT_SOURCE_DIR}/tools/binaryiface.cpp
                          ${CMAKE_CURRENT_SOURCE_DIR}/tools/iccjpeg.c
-                         ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpwritehelp.cpp
                          ${CMAKE_CURRENT_SOURCE_DIR}/dialogs/batchprogressdialog.cpp
                          ${CMAKE_CURRENT_SOURCE_DIR}/dialogs/imagedialog.cpp
                          ${CMAKE_CURRENT_SOURCE_DIR}/dialogs/wizardpage.cpp
@@ -41,4 +42,4 @@ SET_TARGET_PROPERTIES(kipiplugins PROPERTIES VERSION 2.0.0 SOVERSION 2)
 
 INSTALL(TARGETS kipiplugins ${INSTALL_TARGETS_DEFAULT_ARGS})
 
-install( PROGRAMS kipiplugins.desktop  DESTINATION  ${XDG_APPS_INSTALL_DIR})
+INSTALL(PROGRAMS kipiplugins.desktop  DESTINATION  ${XDG_APPS_INSTALL_DIR})
diff --git a/common/libkipiplugins/tools/kpimageinfo.cpp b/common/libkipiplugins/tools/kpimageinfo.cpp
new file mode 100644
index 0000000..b5de13d
--- /dev/null
+++ b/common/libkipiplugins/tools/kpimageinfo.cpp
@@ -0,0 +1,90 @@
+/* ============================================================
+ *
+ * This file is a part of kipi-plugins project
+ * http://www.digikam.org
+ *
+ * Date        : 2012-02-06
+ * Description : help wrapper around libkipi ImageInfo to manage easily
+ *               item properties with KIPI host application.
+ *
+ * Copyright (C) 2012 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * 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 the Free Software Foundation;
+ * either version 2, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+
+#include "kpimageinfo.h"
+
+// Qt includes
+
+#include <QMap>
+#include <QVariant>
+
+// KDE includes
+
+#include <kdebug.h>
+
+// Libkipi includes
+
+#include <libkipi/interface.h>
+#include <libkipi/imageinfo.h>
+
+namespace KIPIPlugins
+{
+
+class KPImageInfo::KPImageInfoPrivate
+{
+public:
+
+    KPImageInfoPrivate()
+    {
+        iface = 0;
+    }
+
+    KUrl             url;
+    KIPI::Interface* iface;
+};
+
+KPImageInfo::KPImageInfo(KIPI::Interface* iface, const KUrl& url)
+    : d(new KPImageInfoPrivate)
+{
+    d->iface = iface;
+    d->url   = url;
+}
+
+KPImageInfo::~KPImageInfo()
+{
+    delete d;
+}
+
+void KPImageInfo::setDescription(const QString& desc)
+{
+    if (d->iface)
+    {
+        KIPI::ImageInfo info = d->iface->info(d->url);
+        QMap<QString, QVariant> map;
+        map.insert("comment", desc);
+        info.addAttributes(map);
+    }
+}
+
+QString KPImageInfo::description() const
+{
+    if (d->iface)
+    {
+        KIPI::ImageInfo info = d->iface->info(d->url);
+        QMap<QString, QVariant> map = info.attributes();
+        if (!map.isEmpty()) return map.value("comment", QString()).toString();
+    }
+    return QString();
+}
+
+}  // namespace KIPIPlugins
diff --git a/common/libkipiplugins/tools/kpimageinfo.h b/common/libkipiplugins/tools/kpimageinfo.h
new file mode 100644
index 0000000..867c566
--- /dev/null
+++ b/common/libkipiplugins/tools/kpimageinfo.h
@@ -0,0 +1,70 @@
+/* ============================================================
+ *
+ * This file is a part of kipi-plugins project
+ * http://www.digikam.org
+ *
+ * Date        : 2012-02-06
+ * Description : help wrapper around libkipi ImageInfo to manage easily
+ *               item properties with KIPI host application.
+ *
+ * Copyright (C) 2012 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * 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 the Free Software Foundation;
+ * either version 2, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+
+#ifndef KPIMAGEINFO_H
+#define KPIMAGEINFO_H
+
+// Qt includes
+
+#include <QString>
+
+// KDE includes
+
+#include <kurl.h>
+
+// Local includes
+
+#include "kipiplugins_export.h"
+
+namespace KIPI
+{
+    class Interface;
+}
+
+namespace KIPIPlugins
+{
+
+class KIPIPLUGINS_EXPORT KPImageInfo
+{
+
+public:
+
+    /** Contructor with KIPI interface instance get from plugin and item url that you want to manage.
+     */
+    KPImageInfo(KIPI::Interface* iface, const KUrl& url);
+    ~KPImageInfo();
+
+    /** Manage description (lead comment) of item.
+     */
+    void    setDescription(const QString& desc);
+    QString description() const;
+
+private:
+
+    class KPImageInfoPrivate;
+    KPImageInfoPrivate* const d;
+};
+
+} // namespace KIPIPlugins
+
+#endif  // KPIMAGEINFO_H




More information about the Digikam-devel mailing list