diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ *.user *.svn *.pri +*.swp +*.swo tags diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,6 +92,7 @@ Svg Concurrent Network + Quick ) if(BUILD_TESTING) @@ -105,6 +106,7 @@ WindowSystem XmlGui I18n + Service ) find_package(KF5 ${KF5_MIN_VERSION} @@ -242,20 +244,20 @@ add_definitions(-DQT_NO_URL_CAST_FROM_STRING) add_subdirectory(common) - add_subdirectory(printimages) - add_subdirectory(kmlexport) - add_subdirectory(sendimages) - add_subdirectory(flickr) - add_subdirectory(dropbox) - add_subdirectory(facebook) - add_subdirectory(imgur) - add_subdirectory(piwigo) - add_subdirectory(rajce) - add_subdirectory(smug) - add_subdirectory(imageshack) - add_subdirectory(yandexfotki) - add_subdirectory(googleservices) - add_subdirectory(jalbum) + #add_subdirectory(printimages) + #add_subdirectory(kmlexport) + #add_subdirectory(sendimages) + #add_subdirectory(flickr) + #add_subdirectory(dropbox) + #add_subdirectory(facebook) + #add_subdirectory(imgur) + #add_subdirectory(piwigo) + #add_subdirectory(rajce) + #add_subdirectory(smug) + #add_subdirectory(imageshack) + #add_subdirectory(yandexfotki) + #add_subdirectory(googleservices) + #add_subdirectory(jalbum) if(KF5Archive_FOUND) add_subdirectory(flashexport) diff --git a/common/libkipiplugins/CMakeLists.txt b/common/libkipiplugins/CMakeLists.txt --- a/common/libkipiplugins/CMakeLists.txt +++ b/common/libkipiplugins/CMakeLists.txt @@ -17,6 +17,14 @@ ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpversion.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpaboutdata.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpthreadmanager.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpquickimageinfo.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpquickimagecollection.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpimagecollectionmodel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpquickinterface.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpquickinit.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpquickglobal.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpquickasyncimageprovider.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tools/kpquickimagerequestresponse.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpprogresswidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpsavesettingswidget.cpp ${CMAKE_CURRENT_SOURCE_DIR}/widgets/kpimageslist.cpp @@ -77,6 +85,7 @@ PUBLIC Qt5::Gui Qt5::Network + Qt5::Quick PRIVATE diff --git a/common/libkipiplugins/tools/kpimagecollectionmodel.h b/common/libkipiplugins/tools/kpimagecollectionmodel.h new file mode 100644 --- /dev/null +++ b/common/libkipiplugins/tools/kpimagecollectionmodel.h @@ -0,0 +1,84 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.digikam.org + * + * Date : 2012-02-06 + * Description : QAbstractItmModel interface around libkipi ImageCollection to manage easily + * item properties with KIPI host application. + * + * Copyright (C) 2017 by Artem Serebriyskiy + * + * 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 KPQUICKIMAGECOLLECTIONMODEL_H +#define KPQUICKIMAGECOLLECTIONMODEL_H + +// Qt includes + +#include +#include +#include +#include + +// KIPI includes +#include + +// Local includes +#include "kpquickimagecollection.h" +#include "kipiplugins_export.h" + +namespace KIPIPlugins +{ + +/** Wrapper for KIPI/ImageCollection. Provides signals and slots + * for using class in QML applications + */ + +class KIPIPLUGINS_EXPORT KPImageCollectionModel : public QAbstractListModel +{ + Q_OBJECT + +public: + enum ImageRoles { + UrlRole = Qt::UserRole + 1, + ThumbnailUrlRole, + PreviewUrlRole + }; + + KPImageCollectionModel( QObject* parent = 0 ); + KPImageCollectionModel( KPQuickImageCollection* collection, QObject* parent = 0 ); + virtual ~KPImageCollectionModel() {} + + void setImageCollection(KPQuickImageCollection* collection); + KPQuickImageCollection* imageCollection() const { return m_collection; } + + int rowCount(const QModelIndex &parent = QModelIndex()) const; + QVariant data(const QModelIndex &index, int role) const; + QHash roleNames() const; + +Q_SIGNALS: + void imageCollectionChanged(KPQuickImageCollection*); + +public: + Q_PROPERTY(KPQuickImageCollection* imageCollection READ imageCollection WRITE setImageCollection NOTIFY imageCollectionChanged); + +private: + QPointer m_collection; + QList m_images; +}; + +} + +#endif + diff --git a/common/libkipiplugins/tools/kpimagecollectionmodel.cpp b/common/libkipiplugins/tools/kpimagecollectionmodel.cpp new file mode 100644 --- /dev/null +++ b/common/libkipiplugins/tools/kpimagecollectionmodel.cpp @@ -0,0 +1,122 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.digikam.org + * + * Date : 2012-02-06 + * Description : QAbstractItmModel interface around libkipi ImageCollection to manage easily + * item properties with KIPI host application. + * + * Copyright (C) 2017 by Artem Serebriyskiy + * + * 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 "kpimagecollectionmodel.h" + +// Qt includes + +#include +#include +#include +#include +#include +#include +// Local includes + +#include "kipiplugins_export.h" +#include "kpimagecollectionmodel.h" +#include "kpquickglobal.h" +#include "kipiplugins_debug.h" + +using namespace KIPIPlugins; +using namespace KIPI; + +KPImageCollectionModel::KPImageCollectionModel(QObject* parent) : + QAbstractListModel(parent) +{ +} + +KPImageCollectionModel::KPImageCollectionModel( KPQuickImageCollection* collection, QObject* parent) : + QAbstractListModel(parent), m_collection(collection) +{ +} + +void KPImageCollectionModel::setImageCollection( KPQuickImageCollection* collection ) +{ + beginResetModel(); + m_collection = collection; + if(m_collection != 0) { + m_images = m_collection->images(); + } + endResetModel(); + emit imageCollectionChanged(m_collection); +} + +int KPImageCollectionModel::rowCount(const QModelIndex &parent) const +{ + if(m_collection == 0 || !m_collection->isValid()) { + return 0; + } + if(parent.isValid()) { + return 0; + } + + return m_images.size(); +} + +QVariant KPImageCollectionModel::data(const QModelIndex &index, int role) const +{ + int pos = index.row(); + + if(!index.isValid()) { + return QVariant(); + } + if(index.column() > 0) { + return QVariant(); + } + if(m_collection == 0 || !m_collection->isValid()) { + return QVariant(); + } + if(pos < 0 || pos >= m_images.size()) { + return QVariant(); + } + + + // qCDebug(KIPIPLUGINS_LOG) << "Requesting at: " << pos << " total count: " << m_collection->images().size(); // TODO: REMOVE + QUrl url = m_images.at(pos); + // qCDebug(KIPIPLUGINS_LOG) << "Model::data url: " << url; // TODO: REMOVE + switch(role) { + case Qt::DisplayRole: + case UrlRole: + return url; + case ThumbnailUrlRole: + return createThumbnailUrl(url); + case PreviewUrlRole: + return createPreviewUrl(url); + default: + return QVariant(); + } + + return QVariant(); +} + +QHash KPImageCollectionModel::roleNames() const +{ + QHash result = QAbstractItemModel::roleNames(); + result[UrlRole] = "url"; + result[ThumbnailUrlRole] = "thumbnailUrl"; + result[PreviewUrlRole] = "previewUrl"; + + return result; +} + diff --git a/common/libkipiplugins/tools/kpimageinfo.h b/common/libkipiplugins/tools/kpimageinfo.h --- a/common/libkipiplugins/tools/kpimageinfo.h +++ b/common/libkipiplugins/tools/kpimageinfo.h @@ -32,6 +32,9 @@ #include #include +// KIPI includes +#include + // Local includes #include "kipiplugins_export.h" @@ -54,6 +57,7 @@ /** return item url. */ QUrl url() const; + void setUrl(const QUrl& url); /** Clone all attributes from current KPImageInfo instance to item pointed by destination url. * In other words, url of KPImageInfo instance is the source of attributes to clone on destination. @@ -137,6 +141,7 @@ void setLongitude(double lng); double longitude() const; bool hasLongitude() const; + bool isValidLongtitude() const; // TODO: Implement? /** Manage item altitude geolocation information : double value in meters. */ @@ -182,6 +187,12 @@ QString source() const; bool hasSource() const; +protected: + /** For descendants. For some purposes (usually optimization) descendant may require access to interface + */ + KIPI::Interface* interface() const; + + private: class Private; diff --git a/common/libkipiplugins/tools/kpimageinfo.cpp b/common/libkipiplugins/tools/kpimageinfo.cpp --- a/common/libkipiplugins/tools/kpimageinfo.cpp +++ b/common/libkipiplugins/tools/kpimageinfo.cpp @@ -124,6 +124,11 @@ return d->url; } +void KPImageInfo::setUrl(const QUrl& url) +{ + d->url = url; +} + void KPImageInfo::cloneData(const QUrl& destination) { if (d->hasValidData()) @@ -503,4 +508,9 @@ return d->hasAttribute(QLatin1String("source")); } +Interface* KPImageInfo::interface() const +{ + return d->iface; +} + } // namespace KIPIPlugins diff --git a/common/libkipiplugins/tools/kpquickasyncimageprovider.h b/common/libkipiplugins/tools/kpquickasyncimageprovider.h new file mode 100644 --- /dev/null +++ b/common/libkipiplugins/tools/kpquickasyncimageprovider.h @@ -0,0 +1,67 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.digikam.org + * + * Date : 2012-02-06 + * Description : image provider for thumbnails/previews obtained via KIPI interface + * + * Copyright (C) 2017 by Artem Serebriyskiy + * + * 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 KPQUICK_ASYNC_IMAGE_PROVIDER_H +#define KPQUICK_ASYNC_IMAGE_PROVIDER_H + +// Qt includes + +#include +#include +#include + +// KIPI includes +#include + +// Local includes + +#include "kipiplugins_export.h" +#include "kpquickimagerequestresponse.h" +#include "kpquickglobal.h" + +namespace KIPIPlugins +{ + +/** QuickAsyncImageProvider via KIPI interface + * */ + +class KIPIPLUGINS_EXPORT KPQuickAsyncImageProvider : public QQuickAsyncImageProvider +{ +public: + + KPQuickAsyncImageProvider( KIPI::Interface* interface, + RequestType request ); + virtual ~KPQuickAsyncImageProvider() {} + + virtual QQuickImageResponse* requestImageResponse(const QString& id, const QSize& requestedSize); + +private: + KIPI::Interface* m_interface; + RequestType m_requestType; + +}; + +} + +#endif + + diff --git a/common/libkipiplugins/tools/kpquickasyncimageprovider.cpp b/common/libkipiplugins/tools/kpquickasyncimageprovider.cpp new file mode 100644 --- /dev/null +++ b/common/libkipiplugins/tools/kpquickasyncimageprovider.cpp @@ -0,0 +1,63 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.digikam.org + * + * Date : 2012-02-06 + * Description : + * + * Copyright (C) 2017 by Artem Serebriyskiy + * + * 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 "kpquickasyncimageprovider.h" + +// Qt includes + +#include +#include + +// Libkipi includes + +#include +#include +#include +#include + +// Local includes + +#include "kipiplugins_debug.h" + +using namespace KIPI; +using namespace KIPIPlugins; + +KPQuickAsyncImageProvider::KPQuickAsyncImageProvider( KIPI::Interface* interface, + RequestType requestType) : + QQuickAsyncImageProvider(), m_interface(interface), m_requestType(requestType) +{ + if( interface == 0 ) { + qCCritical(KIPIPLUGINS_LOG) << "Interface can't be null"; + return; + } +} + +QQuickImageResponse* KPQuickAsyncImageProvider::requestImageResponse(const QString& id, const QSize& requestedSize) +{ + QUrl url = decodeUrl(id); + + return new KPQuickImageRequestResponse(m_interface, url, + requestedSize, + m_requestType); +} + + diff --git a/common/libkipiplugins/tools/kpquickglobal.h b/common/libkipiplugins/tools/kpquickglobal.h new file mode 100644 --- /dev/null +++ b/common/libkipiplugins/tools/kpquickglobal.h @@ -0,0 +1,60 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.digikam.org + * + * Date : 2012-02-06 + * Description : Global definitions for KIPI plugins QML wrappers + * + * Copyright (C) 2012-2017 by Artem Serebriyskiy + * + * 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 KPQUICKGLOBAL_H +#define KPQUICKGLOBAL_H + +// Qt includes + +#include +#include +#include +#include +#include +#include + +// Local includes + +#include "kipiplugins_export.h" +#include "kpimageinfo.h" + +namespace KIPIPlugins +{ + + // Type of request for special image provider + enum RequestType { + RequestThumbnail = 0, + RequestPreview + }; + + extern QString ThumbnailsImageProvider; + extern QString PreviewsImageProvider; + + // Encodes KIPI-provided url into Base64. To use with image custom image provider + QString encodeUrl( const QUrl& url); + QUrl decodeUrl(const QString& encodedUrl); + + QUrl createThumbnailUrl(const QUrl& url); + QUrl createPreviewUrl(const QUrl& url); +} + +#endif diff --git a/common/libkipiplugins/tools/kpquickglobal.cpp b/common/libkipiplugins/tools/kpquickglobal.cpp new file mode 100644 --- /dev/null +++ b/common/libkipiplugins/tools/kpquickglobal.cpp @@ -0,0 +1,87 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.digikam.org + * + * Date : 2012-02-06 + * Description : Global definitions for KIPI plugins QML wrappers + * + * Copyright (C) 2012-2017 by Artem Serebriyskiy + * + * 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 "kpquickglobal.h" + +// Qt includes + +#include +#include +#include +#include +#include +#include + +// Local includes + +#include "kipiplugins_export.h" +#include "kipiplugins_debug.h" +#include "kpimageinfo.h" + +using namespace KIPI; + +namespace KIPIPlugins { + +QString ThumbnailsImageProvider( QStringLiteral("KIPIThumbnail")); +QString PreviewsImageProvider( QStringLiteral("KIPIPreview")); + +// Encodes KIPI-provided url into Base64. To use with image custom image provider +QString encodeUrl( const QUrl& url) +{ + QByteArray plainUrl = url.toEncoded(); + QByteArray encodedUrl = plainUrl.toBase64(); + return QString(encodedUrl); +} + +QUrl decodeUrl(const QString& encodedUrl) +{ + // id is base64-encoded KIPI-provided url + QByteArray urlEncodedArray = encodedUrl.toUtf8(); + QByteArray urlDecoded = QByteArray::fromBase64(urlEncodedArray); + QString urlString = QString(urlDecoded); + QUrl url = QUrl(urlString); + return url; +} + +static QUrl createProviderUrl( const QUrl& url, const QString& provider ) +{ + QString data = encodeUrl(url); + QUrl result; + result.setScheme("image"); + + result.setHost(provider); + result.setPath('/' + data); + + return result; +} + +QUrl createThumbnailUrl(const QUrl& url) +{ + return createProviderUrl(url, ThumbnailsImageProvider); +} + +QUrl createPreviewUrl(const QUrl& url) +{ + return createProviderUrl(url, PreviewsImageProvider); +} + +} diff --git a/common/libkipiplugins/tools/kpquickimagecollection.h b/common/libkipiplugins/tools/kpquickimagecollection.h new file mode 100644 --- /dev/null +++ b/common/libkipiplugins/tools/kpquickimagecollection.h @@ -0,0 +1,80 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.digikam.org + * + * Date : 2012-02-06 + * Description : help wrapper around libkipi ImageCollection to manage easily + * item properties with KIPI host application. + * + * Copyright (C) 2017 by Artem Serebriyskiy + * + * 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 KPQUICKIMAGECOLLECTION_H +#define KPQUICKIMAGECOLLECTION_H + +// Qt includes + +#include +#include +#include +#include +#include +#include + +// KIPI includes +#include + +// Local includes + +#include "kipiplugins_export.h" + +namespace KIPIPlugins +{ + +/** Wrapper for KIPI/ImageCollection. Provides signals and slots + * for using class in QML applications + */ + +class KIPIPLUGINS_EXPORT KPQuickImageCollection : public QObject, public KIPI::ImageCollection +{ + Q_OBJECT + +public: + KPQuickImageCollection( const KIPI::ImageCollection& collection, QObject* parent = 0 ); + /* + KPQuickImageCollection(const KPQuickImageCollection& other); + KPQuickImageCollection( QObject* parent = 0 ); + KPQuickImageCollection& operator=(const KPQuickImageCollection& other); + */ // TODO: REMOVE + virtual ~KPQuickImageCollection() {} + + operator QString() const; + + Q_PROPERTY( QList images READ images CONSTANT ); + Q_PROPERTY( QString name READ name CONSTANT ); + Q_PROPERTY( QString comment READ comment CONSTANT); + Q_PROPERTY( QString category READ category CONSTANT); + Q_PROPERTY( QDate date READ date CONSTANT); + Q_PROPERTY( QUrl url READ url CONSTANT); + Q_PROPERTY( QUrl uploadUrl READ uploadUrl CONSTANT); + Q_PROPERTY( QUrl uploadRootUrl READ uploadRootUrl CONSTANT); + Q_PROPERTY( bool isDirectory READ isDirectory CONSTANT); + Q_PROPERTY( QString uploadRootName READ uploadRootName CONSTANT); + Q_PROPERTY( bool isValid READ isValid CONSTANT); +}; + +} + +#endif diff --git a/common/libkipiplugins/tools/kpquickimagecollection.cpp b/common/libkipiplugins/tools/kpquickimagecollection.cpp new file mode 100644 --- /dev/null +++ b/common/libkipiplugins/tools/kpquickimagecollection.cpp @@ -0,0 +1,76 @@ +/* ============================================================ + * + * 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) 2017 by Artem Serebriyskiy + * + * 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 "kpquickimagecollection.h" + +// Qt includes + +#include +#include + +// Libkipi includes + +#include +#include +#include +#include + +// Local includes + +#include "kipiplugins_debug.h" + +using namespace KIPI; + +namespace KIPIPlugins +{ + +KPQuickImageCollection::KPQuickImageCollection(const ImageCollection& collection, QObject* parent) : + QObject(parent), ImageCollection(collection) +{ +} + +/* +KPQuickImageCollection::KPQuickImageCollection(const KPQuickImageCollection& other) : + QObject(0), KIPI::ImageCollection(other) +{ +} + +KPQuickImageCollection::KPQuickImageCollection( QObject* parent ) : + QObject(parent) +{ +} + +KPQuickImageCollection& KPQuickImageCollection::operator=(const KPQuickImageCollection& other) +{ + static_cast(*this) = other; + return *this; +}*/ // TODO: REMOVE + +KPQuickImageCollection::operator QString() const +{ + QString result; + QTextStream(&result) << "KIPI::ImageCollection at " << static_cast(this); + return result; +} + +} diff --git a/common/libkipiplugins/tools/kpquickimageinfo.h b/common/libkipiplugins/tools/kpquickimageinfo.h new file mode 100644 --- /dev/null +++ b/common/libkipiplugins/tools/kpquickimageinfo.h @@ -0,0 +1,162 @@ +/* ============================================================ + * + * 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-2017 by Gilles Caulier + * + * 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 KPQUICKIMAGEINFO_H +#define KPQUICKIMAGEINFO_H + +// Qt includes + +#include +#include +#include +#include +#include +#include + +// Local includes + +#include "kipiplugins_export.h" +#include "kpimageinfo.h" + +namespace KIPIPlugins +{ + +/** Extension for KPImageInfo. Provides signals and slots + * for using class in QML applications + */ +// TODO: Finish wrapping other hasXXX methods in Q_INVOKABLE +class KIPIPLUGINS_EXPORT KPQuickImageInfo : public QObject, public KPImageInfo +{ + Q_OBJECT + +public: + + /** Contructor with item url that you want to manage. KIPI interface from plugin loader instance is used + * to fill item info from kipi host. If no interface is available, for ex when plugin is loaded as + * stand-alone application, some info are filled with image file metadata. + */ + KPQuickImageInfo(QObject* parent = 0); + KPQuickImageInfo(const QUrl& url, QObject* parent = 0); + ~KPQuickImageInfo(); + + void setUrl(const QUrl& url); + + void setDescription(const QString& desc); + Q_INVOKABLE bool hasDescription() const { return KPImageInfo::hasDescription(); } + + void setTagsPath(const QStringList& tp); + + void setRating(int r); + + void setColorLabel(int cl); + + void setPickLabel(int pl); + + void setDate(const QDateTime& date); + + bool isExactDate() const; + + void setTitle(const QString& title); + + void setName(const QString& name); + + void setLatitude(double lat); + + void setLongitude(double lng); + + void setAltitude(double alt); + + void setOrientation(int); + + void setCreators(const QStringList& list); + + void setCredit(const QString& val); + + void setRights(const QString& val); + + void setSource(const QString& val); + +public: + QUrl thumbnailUrl() const { return m_thumbnailUrl; } + QUrl previewUrl() const { return m_previewUrl; } + +Q_SIGNALS: + /** Qt Meta Type system declarations + */ + void urlChanged(const QUrl&); + void fileSizeChanged(qlonglong); + void descriptionChanged(const QString&); + void tagsPathChanged(const QStringList&); + void keywordsChanged(const QStringList&); + void ratingChanged(int); + void colorLabelChanged(int); + void pickLabelChanged(int); + void dateChanged(const QDateTime&); + void nameChanged(const QString&); + void titleChanged(const QString&); + void latitudeChanged(double); + void longitudeChanged(double); + void altitudeChanged(double); + void orientationChanged(int); + void creatorsChanged(const QStringList&); + void creditChanged(const QString&); + void rightsChanged(const QString&); + void sourceChanged(const QString&); + +public: + Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged); + Q_PROPERTY(QUrl thumbnailUrl READ thumbnailUrl NOTIFY urlChanged); + Q_PROPERTY(QUrl previewUrl READ previewUrl NOTIFY urlChanged); + Q_PROPERTY(qlonglong fileSize READ fileSize CONSTANT); + Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged); + Q_PROPERTY(QStringList tagsPath READ tagsPath WRITE setTagsPath NOTIFY tagsPathChanged); + Q_PROPERTY(QStringList keywords READ keywords CONSTANT); + Q_PROPERTY(int rating READ rating WRITE setRating NOTIFY ratingChanged); + Q_PROPERTY(int colorLabel READ colorLabel WRITE setColorLabel NOTIFY colorLabelChanged); + Q_PROPERTY(int pickLabel READ pickLabel WRITE setPickLabel NOTIFY pickLabelChanged); + Q_PROPERTY(QDateTime date READ date WRITE setDate NOTIFY dateChanged); + Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged); + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged); + Q_PROPERTY(double latitude READ latitude WRITE setLatitude NOTIFY latitudeChanged); + Q_PROPERTY(double longitude READ longitude WRITE setLongitude NOTIFY longitudeChanged); + Q_PROPERTY(double altitude READ altitude WRITE setAltitude NOTIFY altitudeChanged); + Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged); + Q_PROPERTY(QStringList creators READ creators WRITE setCreators NOTIFY creatorsChanged); + Q_PROPERTY(QString credit READ credit WRITE setCredit NOTIFY creditChanged); + Q_PROPERTY(QString rights READ rights WRITE setRights NOTIFY rightsChanged); + Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged); + + +private Q_SLOTS: + void onUrlChanged(const QUrl& newUrl); + +private: + QUrl m_thumbnailUrl; + QUrl m_previewUrl; + + void updateDependentData(); +}; + +} // namespace KIPIPlugins + +#endif // KPIMAGEINFO_H diff --git a/common/libkipiplugins/tools/kpquickimageinfo.cpp b/common/libkipiplugins/tools/kpquickimageinfo.cpp new file mode 100644 --- /dev/null +++ b/common/libkipiplugins/tools/kpquickimageinfo.cpp @@ -0,0 +1,138 @@ +/* ============================================================ + * + * 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-2017 by Gilles Caulier + * + * 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 "kpquickimageinfo.h" + +// Qt includes + +#include +#include + +// Libkipi includes + +#include +#include +#include +#include + +// Local includes + +#include "kipiplugins_debug.h" +#include "kpquickglobal.h" + +#define KP_QUICK_FQN( ns_or_class, member ) ns_or_class::member + +// Macros creates wrapper that sets new value and emits changed signal. To avoid duplicating +// params checks, wrapper first sets new value using original setter, and only then checks +// if value has changed. Downside is that there are 2 calls to getter instead of one +#define KP_QUICK_SETTER_WRAPPER( type, setter, getter, signal ) \ +void KP_QUICK_FQN( KPQuickImageInfo, setter) ( type newValue )\ +{\ + type oldValue = KP_QUICK_FQN(KPImageInfo, getter)();\ + KP_QUICK_FQN(KPImageInfo, setter)(newValue);\ + if( oldValue != newValue ) {\ + emit signal(newValue);\ + }\ +} + +using namespace KIPI; + +namespace KIPIPlugins +{ + +KPQuickImageInfo::KPQuickImageInfo(QObject* parent) : + QObject(parent), KPImageInfo(QUrl()) +{ +} + +KPQuickImageInfo::KPQuickImageInfo(const QUrl& url, QObject* parent): + QObject(parent), KPImageInfo(url) +{ + connect( this, &KPQuickImageInfo::urlChanged, this, &KPQuickImageInfo::onUrlChanged ); + updateDependentData(); +} + +KPQuickImageInfo::~KPQuickImageInfo() +{ +} + +void KPQuickImageInfo::updateDependentData() +{ + m_thumbnailUrl = createThumbnailUrl(url()); + m_previewUrl = createPreviewUrl(url()); + //qCDebug(KIPIPLUGINS_LOG) << "Thumbnail url: " << m_thumbnailUrl; // TODO: REMOVE +} + +void KPQuickImageInfo::setUrl( const QUrl& newValue ) +{ + QUrl oldValue = KPImageInfo::url(); + KPImageInfo::setUrl(newValue); + if( oldValue != newValue ) { + updateDependentData(); + emit urlChanged(newValue); + } +} + +KP_QUICK_SETTER_WRAPPER(const QString&, setDescription, description, descriptionChanged) +KP_QUICK_SETTER_WRAPPER(const QStringList&, setTagsPath, tagsPath, tagsPathChanged) +KP_QUICK_SETTER_WRAPPER(int, setRating, rating, ratingChanged) +KP_QUICK_SETTER_WRAPPER(int, setColorLabel, colorLabel, colorLabelChanged) +KP_QUICK_SETTER_WRAPPER(int, setPickLabel, pickLabel, pickLabelChanged) +KP_QUICK_SETTER_WRAPPER(const QDateTime&, setDate, date, dateChanged) +KP_QUICK_SETTER_WRAPPER(const QString&, setTitle, title, titleChanged) +KP_QUICK_SETTER_WRAPPER(const QString&, setName, name, nameChanged) +KP_QUICK_SETTER_WRAPPER(double, setLatitude, latitude, latitudeChanged) +KP_QUICK_SETTER_WRAPPER(double, setLongitude, longitude, longitudeChanged) +KP_QUICK_SETTER_WRAPPER(double, setAltitude, altitude, altitudeChanged) +KP_QUICK_SETTER_WRAPPER(int, setOrientation, orientation, orientationChanged) +KP_QUICK_SETTER_WRAPPER(const QStringList&, setCreators, creators, creatorsChanged ) +KP_QUICK_SETTER_WRAPPER(const QString&, setCredit, credit, creditChanged) +KP_QUICK_SETTER_WRAPPER(const QString&, setRights, rights, rightsChanged) +KP_QUICK_SETTER_WRAPPER(const QString&, setSource, source, sourceChanged) + +#define KP_QUICK_EMIT_UPDATE(attribute) emit attribute ## Changed (attribute()); + +/* Emit all xxxChanged signals with new values */ +void KPQuickImageInfo::onUrlChanged(const QUrl&) +{ + KP_QUICK_EMIT_UPDATE(fileSize); + KP_QUICK_EMIT_UPDATE(description); + KP_QUICK_EMIT_UPDATE(tagsPath); + KP_QUICK_EMIT_UPDATE(keywords); + KP_QUICK_EMIT_UPDATE(rating); + KP_QUICK_EMIT_UPDATE(colorLabel); + KP_QUICK_EMIT_UPDATE(pickLabel); + KP_QUICK_EMIT_UPDATE(date); + KP_QUICK_EMIT_UPDATE(title); + KP_QUICK_EMIT_UPDATE(name); + KP_QUICK_EMIT_UPDATE(latitude); + KP_QUICK_EMIT_UPDATE(longitude); + KP_QUICK_EMIT_UPDATE(altitude); + KP_QUICK_EMIT_UPDATE(orientation); + KP_QUICK_EMIT_UPDATE(creators); + KP_QUICK_EMIT_UPDATE(credit); + KP_QUICK_EMIT_UPDATE(rights); + KP_QUICK_EMIT_UPDATE(source); +} + +} // namespace KIPIPlugins diff --git a/common/libkipiplugins/tools/kpquickimagerequestresponse.h b/common/libkipiplugins/tools/kpquickimagerequestresponse.h new file mode 100644 --- /dev/null +++ b/common/libkipiplugins/tools/kpquickimagerequestresponse.h @@ -0,0 +1,77 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.digikam.org + * + * Date : 2012-02-06 + * Description : part of image provider for thumbnails/previews obtained via KIPI interface + * + * Copyright (C) 2017 by Artem Serebriyskiy + * + * 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 KPQUICK_IMAGE_REQUESTRESPONSE_H +#define KPQUICK_IMAGE_REQUESTRESPONSE_H + +// Qt includes + +#include +#include +#include + +// KIPI includes +#include + +// Local includes + +#include "kipiplugins_export.h" +#include "kpquickglobal.h" + +namespace KIPIPlugins +{ + +/** Request/response class for thumbnails/previes via KIPI interface + */ + +class KIPIPLUGINS_EXPORT KPQuickImageRequestResponse : public QQuickImageResponse +{ + Q_OBJECT + +public: + + KPQuickImageRequestResponse( KIPI::Interface* interface, const QUrl& url, const QSize& size, + RequestType request = RequestThumbnail ); + virtual ~KPQuickImageRequestResponse() {} + + virtual QQuickTextureFactory* textureFactory() const; + +public Q_SLOTS: + void cancel(); + +private Q_SLOTS: + void onGotThumbnail(const QUrl& url, const QPixmap& pixmap); + void onGotPreview(const QUrl& url, const QImage& image); + void handleNullRequest(); + +private: + QSize m_size; + QUrl m_url; + QImage m_resultImage; + + QImage scaleImage(const QImage& image); +}; + +} + +#endif + diff --git a/common/libkipiplugins/tools/kpquickimagerequestresponse.cpp b/common/libkipiplugins/tools/kpquickimagerequestresponse.cpp new file mode 100644 --- /dev/null +++ b/common/libkipiplugins/tools/kpquickimagerequestresponse.cpp @@ -0,0 +1,142 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.digikam.org + * + * Date : 2012-02-06 + * Description : + * + * Copyright (C) 2017 by Artem Serebriyskiy + * + * 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 "kpquickimagerequestresponse.h" + +// Qt includes + +#include +#include +#include + +// Libkipi includes + +#include +#include +#include +#include + +// Local includes + +#include "kipiplugins_debug.h" + +using namespace KIPI; +using namespace KIPIPlugins; + +KPQuickImageRequestResponse::KPQuickImageRequestResponse( KIPI::Interface* interface, + const QUrl& url, + const QSize& size, + RequestType requestType ): + QQuickImageResponse(), m_size(size), m_url(url) +{ + if( interface == 0 ) { + return; + } + + if(m_size.isNull()) { + // No point in calling interface for empty thumbnail + QTimer::singleShot(0, this, &KPQuickImageRequestResponse::handleNullRequest); + return; + } + + int boundSize = 0; + + // if any m_size width or height is 0, then make it equal to other parameters + if(m_size.width() == 0 ) { + boundSize = m_size.height(); + } else if(m_size.height() == 0) { + boundSize = m_size.width(); + } else { + boundSize = qMax(m_size.width(), m_size.height()); + } + + qCDebug(KIPIPLUGINS_LOG) << "Request for " << + (requestType == RequestThumbnail?"thumbnail":"preview") << url << " size: " << size << " boundSize:" << boundSize; + + switch( requestType ) { + case RequestPreview: + case RequestThumbnail: + connect( interface, &Interface::gotThumbnail, this, &KPQuickImageRequestResponse::onGotThumbnail); + interface->thumbnail(url, boundSize); + break; + //case RequestPreview: + // TODO: Crushes digikam. Blocking for now + /* + connect( interface, &Interface::gotPreview, this, &KPQuickImageRequestResponse::onGotPreview); + interface->preview(url, boundSize); + */ + break; + } +} + +void KPQuickImageRequestResponse::onGotThumbnail(const QUrl& url, const QPixmap& pixmap) +{ + /* + qCDebug(KIPIPLUGINS_LOG) << "Got thumbnail for " << + url << " size: " << pixmap.size() << " downscale to: " << m_size;*/ // TODO: REMOVE + if( url != m_url ) { + return; + } + + m_resultImage = scaleImage(pixmap.toImage()); + emit finished(); +} + +void KPQuickImageRequestResponse::onGotPreview(const QUrl& url, const QImage& image) +{ + qCDebug(KIPIPLUGINS_LOG) << "Got preview for " << + url << " size: " << image.size() << " downscale to: " << m_size; + if( url != m_url ) { + return; + } + + m_resultImage = scaleImage(image); + emit finished(); +} + +QImage KPQuickImageRequestResponse::scaleImage(const QImage& image) +{ + if(m_size.width() == 0 ) { + return image.scaledToHeight(m_size.height()); + } else if(m_size.height() == 0) { + return image.scaledToWidth(m_size.width()); + } else { + return image.scaled(m_size); + } +} + +void KPQuickImageRequestResponse::cancel() +{ + m_url = QUrl(); + emit finished(); +} + +// When no call to interface was made, but we need to emit 'finished' signal +void KPQuickImageRequestResponse::handleNullRequest() +{ + emit finished(); +} + +QQuickTextureFactory* KPQuickImageRequestResponse::textureFactory() const +{ + return QQuickTextureFactory::textureFactoryForImage(m_resultImage); +} diff --git a/common/libkipiplugins/tools/kpquickinit.h b/common/libkipiplugins/tools/kpquickinit.h new file mode 100644 --- /dev/null +++ b/common/libkipiplugins/tools/kpquickinit.h @@ -0,0 +1,49 @@ +/* ============================================================ + * + * 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) 2017 by Artem Serebriyskiy + * + * 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 KPQUICK_INIT_H +#define KPQUICK_INIT_H + +// Qt includes + +#include + +// Libkipi includes +#include + +// Local includes + +#include "kipiplugins_export.h" + + +namespace KIPIPlugins +{ + /** Registers all QtQuick wrappers form kipiplugins + */ + void KIPIPLUGINS_EXPORT InitKIPIQuick(); + void KIPIPLUGINS_EXPORT InitKIPIQmlEngine(QQmlEngine& engine, KIPI::Interface* interface); + +} + +#endif + diff --git a/common/libkipiplugins/tools/kpquickinit.cpp b/common/libkipiplugins/tools/kpquickinit.cpp new file mode 100644 --- /dev/null +++ b/common/libkipiplugins/tools/kpquickinit.cpp @@ -0,0 +1,74 @@ +/* ============================================================ + * + * 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) 2017 by Artem Serebriyskiy + * + * 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 "kpquickinit.h" + +// Qt includes +#include + +// Libkipi includes + +#include +#include +#include +#include + +// Local includes + +#include "kipiplugins_debug.h" +#include "kpquickimageinfo.h" +#include "kpquickimagecollection.h" +#include "kpimagecollectionmodel.h" +#include "kpquickinterface.h" +#include "kpquickglobal.h" +#include "kpquickasyncimageprovider.h" + +using namespace KIPI; + +namespace KIPIPlugins +{ + +const char* const kipi_qml_namespace = "com.kde.kipiplugins"; +const int kipi_qml_version_major = 0; +const int kipi_qml_version_minor = 1; + +void InitKIPIQuick() +{ + qmlRegisterType(kipi_qml_namespace, kipi_qml_version_major, + kipi_qml_version_minor, "ImageInfo" ); + qmlRegisterType(kipi_qml_namespace, kipi_qml_version_major, + kipi_qml_version_minor, "ImageCollectionModel" ); + qmlRegisterUncreatableType(kipi_qml_namespace, kipi_qml_version_major, + kipi_qml_version_minor, "ImageCollection", QLatin1String("Plugin should never create ImageCollection. Only host can do that") ); + qmlRegisterUncreatableType(kipi_qml_namespace, kipi_qml_version_major, + kipi_qml_version_minor, "Interface", QLatin1String("Plugin can't create Interface. It is provided by host") ); + +} + +void InitKIPIQmlEngine(QQmlEngine& engine, KIPI::Interface* interface) +{ + engine.addImageProvider( ThumbnailsImageProvider, new KPQuickAsyncImageProvider( interface, RequestThumbnail) ); + engine.addImageProvider( PreviewsImageProvider, new KPQuickAsyncImageProvider( interface, RequestPreview) ); +} + +} diff --git a/common/libkipiplugins/tools/kpquickinterface.h b/common/libkipiplugins/tools/kpquickinterface.h new file mode 100644 --- /dev/null +++ b/common/libkipiplugins/tools/kpquickinterface.h @@ -0,0 +1,89 @@ +/* ============================================================ + * + * 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) 2017 by Artem Serebriyskiy + * + * 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 KPQUICKINTERFACE_H +#define KPQUICKINTERFACE_H + +// Qt includes + +#include +#include +#include +#include +#include +#include +#include + +// Libkipi includes +// +#include + +// Local includes + +#include "kpquickimagecollection.h" +#include "kipiplugins_export.h" + +namespace KIPIPlugins +{ + +/** Wrapper for KIPI/Interface. Provides signals and slots + * for using class in QML applications + */ + +class KIPIPLUGINS_EXPORT KPQuickInterface : public QObject +{ + Q_OBJECT + +public: + KPQuickInterface(KIPI::Interface* interface, QObject* parent = 0); + + const KPQuickImageCollection* currentAlbum() const { return m_currentAlbum; } + KPQuickImageCollection* currentAlbum() { return m_currentAlbum; } + + const KPQuickImageCollection* currentSelection() const { return m_currentSelection; } + KPQuickImageCollection* currentSelection() { return m_currentSelection; } + + operator QString() const; + +Q_SIGNALS: + void currentAlbumChanged(KPQuickImageCollection*); + void currentSelectionChanged(KPQuickImageCollection*); + +public: + Q_PROPERTY( KPQuickImageCollection* currentAlbum READ currentAlbum NOTIFY currentAlbumChanged ); + Q_PROPERTY( KPQuickImageCollection* currentSelection READ currentSelection NOTIFY currentSelectionChanged ); + +private Q_SLOTS: + void onCurrentAlbumChanged(bool); + void onCurrentSelectionChanged(bool); + +private: + QPointer m_interface; + QPointer m_currentAlbum; + QPointer m_currentSelection; +}; + +} + +#endif + diff --git a/common/libkipiplugins/tools/kpquickinterface.cpp b/common/libkipiplugins/tools/kpquickinterface.cpp new file mode 100644 --- /dev/null +++ b/common/libkipiplugins/tools/kpquickinterface.cpp @@ -0,0 +1,93 @@ +/* ============================================================ + * + * 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) 2017 by Artem Serebriyskiy + * + * 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 "kpquickinterface.h" + +// Qt includes + +#include +#include + +// Libkipi includes + +#include +#include +#include +#include + +// Local includes + +#include "kipiplugins_debug.h" + +using namespace KIPI; + +namespace KIPIPlugins +{ + +KPQuickInterface::KPQuickInterface(KIPI::Interface* interface, QObject* parent) : + QObject(parent), + m_interface(interface) +{ + if (m_interface) { + m_currentAlbum = new KPQuickImageCollection(m_interface->currentAlbum(), this); + m_currentSelection = new KPQuickImageCollection(m_interface->currentSelection(), this); + } +} + +void KPQuickInterface::onCurrentAlbumChanged(bool) +{ + if (m_interface == 0 ) { + qCritical() << "Signal from non-existent interface pointer"; + return; + } + + if( m_currentAlbum != 0 ) { + m_currentAlbum->deleteLater(); + } + + m_currentAlbum = new KPQuickImageCollection(m_interface->currentAlbum(), this); + emit currentAlbumChanged(m_currentAlbum); +} + +void KPQuickInterface::onCurrentSelectionChanged(bool) +{ + if (m_interface == 0 ) { + qCritical() << "Signal from non-existent interface pointer"; + return; + } + + if( m_currentSelection != 0 ) { + m_currentSelection->deleteLater(); + } + + m_currentSelection = new KPQuickImageCollection(m_interface->currentSelection(), this); + emit currentSelectionChanged(m_currentSelection); +} + +KPQuickInterface::operator QString() const +{ + QString result; + QTextStream(&result) << "KIPI::Interface at " << static_cast(this); + return result; +} +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -9,3 +9,4 @@ endif (POLICY CMP0063) add_subdirectory(imageselector) +add_subdirectory(qmlimageviewer) diff --git a/tests/qmlimageviewer/CMakeLists.txt b/tests/qmlimageviewer/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/tests/qmlimageviewer/CMakeLists.txt @@ -0,0 +1,32 @@ +# +# Copyright (c) 2010-2015, Gilles Caulier, +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +add_definitions(-DTRANSLATION_DOMAIN=\"kipiplugin_qmlimageviewer\") + +add_subdirectory(data) + +set(qmlimageviewer_SRCS qmlimageviewer_plugin.cpp + qmlimageviewer.cpp +) + +add_library(kipiplugin_qmlimageviewer MODULE ${qmlimageviewer_SRCS}) + +target_link_libraries(kipiplugin_qmlimageviewer + PRIVATE + Qt5::Gui + Qt5::Core + + KF5::Kipi + KF5::I18n + KF5::WindowSystem + + KF5kipiplugins +) + +configure_file(kipiplugin_qmlimageviewer.desktop.cmake ${CMAKE_CURRENT_BINARY_DIR}/kipiplugin_qmlimageviewer.desktop) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kipiplugin_qmlimageviewer.desktop DESTINATION ${SERVICES_INSTALL_DIR}) +install(TARGETS kipiplugin_qmlimageviewer DESTINATION ${PLUGIN_INSTALL_DIR}) +install(FILES kipiplugin_qmlimageviewerui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/kipi) diff --git a/tests/qmlimageviewer/data/CMakeLists.txt b/tests/qmlimageviewer/data/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/tests/qmlimageviewer/data/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (c) 2010-2014, Gilles Caulier, +# Copyright (c) 2017, Artem Serebriyskiy, +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +install(FILES main.qml DESTINATION ${DATA_INSTALL_DIR}/kipiplugin_qmlimageviewer) +install(FILES ObjectIntrospection.qml DESTINATION ${DATA_INSTALL_DIR}/kipiplugin_qmlimageviewer) +install(FILES ImageCollectionView.qml DESTINATION ${DATA_INSTALL_DIR}/kipiplugin_qmlimageviewer) +install(FILES PhotoDelegate.qml DESTINATION ${DATA_INSTALL_DIR}/kipiplugin_qmlimageviewer) + diff --git a/tests/qmlimageviewer/data/ImageCollectionInfo.qml b/tests/qmlimageviewer/data/ImageCollectionInfo.qml new file mode 100644 --- /dev/null +++ b/tests/qmlimageviewer/data/ImageCollectionInfo.qml @@ -0,0 +1,18 @@ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 + +Rectangle { + property ImageCollection imageCollection : null + width: 200 + height: 100 + border.width: 2 + border.color: "black" + + GridLayout { + anchors.fill: parent + Text { + text: "Hello, World!" + } + } +} + diff --git a/tests/qmlimageviewer/data/ImageCollectionView.qml b/tests/qmlimageviewer/data/ImageCollectionView.qml new file mode 100644 --- /dev/null +++ b/tests/qmlimageviewer/data/ImageCollectionView.qml @@ -0,0 +1,67 @@ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import com.kde.kipiplugins 0.1 + +Rectangle { + id: imageCollectionView + property var imageCollection : null + border.width: 2 + border.color: "black" + + ImageCollectionModel { + id: imagesModel + imageCollection : imageCollectionView.imageCollection + } + +/* + onImageCollectionChanged : { + imagesModel.clear(); + if( imageCollection !== null && imageCollection !== undefined ) { + for( var i = 0; i < Math.min(10, imageCollection.images.length); i++ ) { + console.log(i) + var u = imageCollection.images[i]; + imagesModel.append( { "url" : u } ); + } + } + } +*/ + + +/* + MouseArea { + anchors.fill: parent + onClicked : { console.log( "Collection: ", imageCollection, " images count: ", imageCollection.images.length); } + } +*/ + // Three flickables - thumbnails, preview, photo + ColumnLayout { + anchors.fill : parent + ListView { + property int mode : 0 + id: thumbnailsView + orientation : ListView.Horizontal + delegate: PhotoDelegate {} + model : imagesModel + Layout.preferredWidth : imageCollectionView.width + Layout.preferredHeight : imageCollectionView.height / 3 + } + ListView { + id: previewView + property int mode : 1 + orientation : ListView.Horizontal + Layout.preferredWidth : imageCollectionView.width + Layout.preferredHeight : imageCollectionView.height / 3 + delegate: PhotoDelegate {} + model : imagesModel + } + ListView { + property int mode : 2 + orientation : ListView.Horizontal + Layout.preferredWidth : imageCollectionView.width + Layout.preferredHeight : imageCollectionView.height / 3 + delegate: PhotoDelegate {} + model : imagesModel + } + } +} + diff --git a/tests/qmlimageviewer/data/ObjectIntrospection.qml b/tests/qmlimageviewer/data/ObjectIntrospection.qml new file mode 100644 --- /dev/null +++ b/tests/qmlimageviewer/data/ObjectIntrospection.qml @@ -0,0 +1,97 @@ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 + +Rectangle { + property var target : null + property var title : "Unnamed" + //border.width: 4 + //border.color: "green" + height: childrenRect.height + + Text { + id: titleObject + text: title + anchors.top: parent.top + anchors.horizontalCenter : parent.horizontalCenter + height: contentHeight + font.pointSize: 12 + } + Column { + id: grid + width: parent.width + anchors.top: titleObject.bottom + height: childrenRect.height + + Repeater { + id: propertiesRepeater + model: propertiesModel + delegate: propertyDelegate + } + + } + + ListModel { + id: propertiesModel + } + + Component { + id: propertyDelegate + + Rectangle { + //border.color: "black" + //border.width: 2 + width: grid.width + //height: childrenRect.height + height: 40 + readonly property int margin : Math.max( width / 10, 5) + Text { + id: propertyNameText + width: parent.width / 2 + height: contentHeight + anchors.left : parent.left + anchors.top: parent.top + anchors.bottom: parent.bottom + anchors.leftMargin : margin + anchors.rightMargin : margin + text: model.name + } + Text { + id: propertyValueText + width: parent.width / 2 + height: contentHeight + anchors.right : parent.right + anchors.top: parent.top + anchors.bottom: parent.bottom + anchors.leftMargin : margin + anchors.rightMargin : margin + text : "\"" + model.value + "\"" + } + } + } + + Component.onCompleted : updateTargetProperties(); + + onTargetChanged : updateTargetProperties(); + + function updateTargetProperties() { + propertiesModel.clear(); + if( target !== null && target !== undefined ) { + for( var p in target ) { + if( target.hasOwnProperty(p) && typeof(target[p]) != 'function' ) { + console.log("OI: adding property", p, " of type: ", typeof(target[pName]) ); + var pName = p; + if( pName === "images" ) { + continue; // images is concatination of all urls, it's waay to long + } + var pValue = "".concat(target[pName]); + var element = { "name" : pName, "value" : pValue } + propertiesModel.append(element) + console.log("OI: \tadded property", p, " value: ", pValue); + } + } + } + console.log( "Properties count in model: ", propertiesModel.count ) + propertiesRepeater.model = propertiesModel + } +} + diff --git a/tests/qmlimageviewer/data/PhotoDelegate.qml b/tests/qmlimageviewer/data/PhotoDelegate.qml new file mode 100644 --- /dev/null +++ b/tests/qmlimageviewer/data/PhotoDelegate.qml @@ -0,0 +1,73 @@ +import QtQuick 2.6 +import QtQuick.Layouts 1.3 +import com.kde.kipiplugins 0.1 + +Rectangle { + id: root + border.width: 3 + border.color: "green" + height: ListView.view.height + width: image.width + + ImageInfo { + id: imageInfo + url: model.url + } + + Image { + id: image + x: 0 + y: 0 + height: parent.height + width: 40 // We need to have non-zero width at all times, otherwise views overloads + asynchronous : true + fillMode: Image.PreserveAspectFit + sourceSize.height : parent.height + sourceSize.width : 0 + source: { + if( root.ListView.view.mode === 0) { + return model.thumbnailUrl; + } else if( root.ListView.view.mode === 1) { + console.log("requesting preview", model.previewUrl); + return model.previewUrl; + } else if( root.ListView.view.mode === 2) { + return model.url + } else { + console.error("Please select photo display mode"); + } + } + states : [ + State { + name: "unloaded" + when: image.status !== Image.Ready || image.implicitWidth === 0 + PropertyChanges { + target: image + width: image.height + } + }, + State { + name: "loaded" + when: image.status === Image.Ready && image.implicitWidth !== 0 + PropertyChanges { + target: image + width: implicitWidth + } + /* TODO: REMOVE + StateChangeScript { + name: "dbgScript" + script : { console.log("Implicit width: ", image.implicitWidth);} + }*/ + } + ] + } + + MouseArea { + anchors.fill: parent + onClicked: { console.log( + "state: ", image.state, + "source size: ", image.sourceSize, " width,height: ", + image.width, ",", image.height, " implicit: ", image.implicitWidth, ",", + image.implicitHeight ); + mouse.accepted = false; } + } +} diff --git a/tests/qmlimageviewer/data/main.qml b/tests/qmlimageviewer/data/main.qml new file mode 100644 --- /dev/null +++ b/tests/qmlimageviewer/data/main.qml @@ -0,0 +1,74 @@ +import QtQuick 2.6 +import QtQuick.Window 2.2 +import QtQuick.Layouts 1.3 +import QtQuick.Controls 1.4 + +/* +Rectangle { + width: 200 + height: 100 + color: "red" + + Text { + anchors.centerIn: parent + text: "Hello, World!" + } +}*/ + +Window { + id: root + visible: true + width: 640 + height: 480 + title: qsTr("Hello World") + + TabView { + anchors.fill : parent + Tab { + title: "Interface" + id: introspectionTab + Flickable { + anchors.fill: parent + contentWidth: mainColumn.width + contentHeight: mainColumn.height + Column { + id: mainColumn + width: introspectionTab.width + height: childrenRect.height + ObjectIntrospection { + id: kipiInterfaceIntrospection + target: KIPIInterface + title: "KIPI Interface" + width: parent.width + } + ObjectIntrospection { + id: currentAlbumIntrospection + target: KIPIInterface.currentAlbum + title: "Current Album Collection" + width: parent.width + } + ObjectIntrospection { + id: currentSelectionIntrospection + target: KIPIInterface.currentSelection + title: "Current Selection Collection" + width: parent.width + } + } + } + } + Tab { + title: "Current Album" + ImageCollectionView { + imageCollection : KIPIInterface.currentAlbum + anchors.fill: parent + } + } + Tab { + title: "Current Selection" + ImageCollectionView { + imageCollection : KIPIInterface.currentSelection + anchors.fill: parent + } + } + } +} diff --git a/tests/qmlimageviewer/kipiplugin_qmlimageviewer.desktop.cmake b/tests/qmlimageviewer/kipiplugin_qmlimageviewer.desktop.cmake new file mode 100644 --- /dev/null +++ b/tests/qmlimageviewer/kipiplugin_qmlimageviewer.desktop.cmake @@ -0,0 +1,10 @@ +[Desktop Entry] +UntranslatedGenericName=Qml Image Viewer +Name=Qml Image Viewer +Type=Service +Icon=kipi-googledrive +ServiceTypes=KIPI/Plugin +X-KDE-Library=kipiplugin_qmlimageviewer +X-KIPI-PluginCategories=Tools +X-KIPI-BinaryVersion=${KIPI_LIB_SO_CUR_VERSION} + diff --git a/tests/qmlimageviewer/kipiplugin_qmlimageviewerui.rc b/tests/qmlimageviewer/kipiplugin_qmlimageviewerui.rc new file mode 100644 --- /dev/null +++ b/tests/qmlimageviewer/kipiplugin_qmlimageviewerui.rc @@ -0,0 +1,17 @@ + + + + + + + &Export + + + + + + Main Toolbar + + + + diff --git a/tests/qmlimageviewer/main.cpp b/tests/qmlimageviewer/main.cpp new file mode 100644 --- /dev/null +++ b/tests/qmlimageviewer/main.cpp @@ -0,0 +1,55 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.digikam.org + * + * Date : 2011-12-28 + * Description : test for implementation of threadWeaver api + * + * Copyright (C) 2011-2012 by A Janardhan Reddy + * Copyright (C) 2011-2017 by Gilles Caulier + * + * 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. + * + * ============================================================ */ + +// Qt includes + +#include + +// Local includes + +#include "qmlimageviewer.h" +#include "kpaboutdata.h" +#include "kpquickinit.h" + +using namespace KIPIPlugins; + +/** Test application for qml binding. Shows specified albums +*/ +int main(int argc, char* argv[]) +{ + KPAboutData* const about = new KPAboutData(ki18n("QmlImageViewer"), + ki18n("A test application to to view images in QML."), + ki18n("(c) 2017-2017, Artem Serebriyskiy\n")); + + about->addAuthor(ki18n("Artem Serebriyskiy").toString(), + ki18n("Author").toString(), + QLatin1String("v.for.vandal@gmail.com")); + + InitKIPIQuick(); + + QApplication app(argc, argv); + KPQmlImageViewer* const viewer = new KPQmlImageViewer(about); + viewer->show(); + app.exec(); + return 0; +} diff --git a/tests/qmlimageviewer/qmlimageviewer.h b/tests/qmlimageviewer/qmlimageviewer.h new file mode 100644 --- /dev/null +++ b/tests/qmlimageviewer/qmlimageviewer.h @@ -0,0 +1,61 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.digikam.org + * + * Date : 2011-12-28 + * Description : test for implementation of threadWeaver api + * + * Copyright (C) 2011-2012 by A Janardhan Reddy + * Copyright (C) 2011-2017 by Gilles Caulier + * + * 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 QML_IMAGE_VIEWER_H +#define QML_IMAGE_VIEWER_H + +// Qt includes + +#include +#include +#include + +// Libkipi +#include + +// Local includes + +#include "kpaboutdata.h" + +using namespace KIPIPlugins; + +class QQmlApplicationEngine; + +class KPQmlImageViewer : public QObject +{ + Q_OBJECT + +public: + + KPQmlImageViewer(KPAboutData* const about, KIPI::Interface* iface, QWindow* parent = 0); + ~KPQmlImageViewer(); + +private: + /* TODO: REMOVE + QHBoxLayout* m_layout = 0; + QQuickView* m_view = 0; */ + KIPI::Interface* m_iface = 0; + QQmlApplicationEngine* m_qmlAppEngine = 0; +}; + +#endif // QML_IMAGE_VIEWER_H diff --git a/tests/qmlimageviewer/qmlimageviewer.cpp b/tests/qmlimageviewer/qmlimageviewer.cpp new file mode 100644 --- /dev/null +++ b/tests/qmlimageviewer/qmlimageviewer.cpp @@ -0,0 +1,102 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.digikam.org + * + * Date : 2011-12-28 + * Description : test for implementation of threadWeaver api + * + * Copyright (C) 2011-2012 by A Janardhan Reddy + * Copyright (C) 2011-2017 by Gilles Caulier + * + * 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 "qmlimageviewer.h" + +// Qt includes + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// KDE includes + +#include + +// Libkipi includes +#include +#include +#include + +// Local includes + +#include "kpquickinterface.h" +#include "kpquickinit.h" +#include "kipiplugins_debug.h" + +using namespace KIPIPlugins; +using namespace KIPI; + +KPQmlImageViewer::KPQmlImageViewer(KPAboutData* const about, KIPI::Interface* iface, QWindow* parent) + : QObject(parent), m_iface(iface) +{ + // setAboutData(about); TODO: KDE specific ? + Q_UNUSED(about); + + + /* + m_view = new QQuickView(); + m_layout = new QHBoxLayout(); + + m_layout->addWidget(m_view); + setLayout(m_layout);*/ + + QString dataDir = QStandardPaths::locate(QStandardPaths::GenericDataLocation, + QStringLiteral("kipiplugin_qmlimageviewer"), QStandardPaths::LocateDirectory); + + if( dataDir.isEmpty() ) { + qCCritical(KIPIPLUGINS_LOG) << "Can't find data dir"; + return; + } else { + qCDebug(KIPIPLUGINS_LOG) << "Data dir is " << dataDir; + } + + QString qmlUi = QDir(dataDir).filePath(QStringLiteral("main.qml")); + QFileInfo qmlUiInfo(qmlUi); + + if( !qmlUiInfo.exists() ) { + qCCritical(KIPIPLUGINS_LOG) << "Can't find main ui file"; + return; + } + + if (m_iface != 0 && !qmlUi.isEmpty()) { + m_qmlAppEngine = new QQmlApplicationEngine(this); + QPointer qmlKPInterface( new KPQuickInterface(m_iface)); + InitKIPIQmlEngine(*m_qmlAppEngine, m_iface); + m_qmlAppEngine->rootContext()->setContextProperty(QStringLiteral("KIPIInterface"), qmlKPInterface); + + // Searching for qml file + m_qmlAppEngine->load(QUrl::fromLocalFile(qmlUi)); + } +} + +KPQmlImageViewer::~KPQmlImageViewer() +{ +} + diff --git a/tests/qmlimageviewer/qmlimageviewer_plugin.h b/tests/qmlimageviewer/qmlimageviewer_plugin.h new file mode 100644 --- /dev/null +++ b/tests/qmlimageviewer/qmlimageviewer_plugin.h @@ -0,0 +1,64 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.digikam.org + * + * Date : 2013-11-18 + * Description : a kipi plugin to test bindings to QML + * + * 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 PLUGIN_QMLIMAGEVIEWER_H +#define PLUGIN_QMLIMAGEVIEWER_H + +// Qt includes + +#include +#include +#include + +// Libkipi includes + +#include + +class QAction; +class KPQmlImageViewer; + +class Plugin_QmlImageViewer : public KIPI::Plugin +{ + Q_OBJECT + +public: + + Plugin_QmlImageViewer(QObject* const parent, const QVariantList& args); + ~Plugin_QmlImageViewer(); + + void setup(QWidget* const); + +public Q_SLOTS: + + void slotView(); + +private: + + void setupActions(); + QString getTempDirPath(); + +private: + + QAction* m_actionView = 0; + + KPQmlImageViewer* m_viewer = 0; +}; + +#endif diff --git a/tests/qmlimageviewer/qmlimageviewer_plugin.cpp b/tests/qmlimageviewer/qmlimageviewer_plugin.cpp new file mode 100644 --- /dev/null +++ b/tests/qmlimageviewer/qmlimageviewer_plugin.cpp @@ -0,0 +1,108 @@ +/* ============================================================ + * + * This file is a part of kipi-plugins project + * http://www.digikam.org + * + * Date : 2013-11-18 + * Description : a kipi plugin to test bindings to QML + * + * 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 "qmlimageviewer_plugin.h" + +//Qt includes + +#include +#include + +// KDE includes + +#include +#include +#include +#include + +// LibKIPI includes + +#include + +// Local includes + +#include "kputil.h" +#include "kpquickinit.h" +#include "kipiplugins_debug.h" +#include "qmlimageviewer.h" + +using namespace KIPIPlugins; +using namespace KIPI; + +K_PLUGIN_FACTORY(QmlImageViewerFactory, registerPlugin(); ) + +Plugin_QmlImageViewer::Plugin_QmlImageViewer(QObject* const parent, const QVariantList&) : + Plugin(parent, "QmlImageViewer") +{ + qCDebug(KIPIPLUGINS_LOG) << "Plugin_GoogleServices Plugin Loaded"; + + setUiBaseName("kipiplugin_qmlimageviewerui.rc"); + setupXML(); + + InitKIPIQuick(); +} + +Plugin_QmlImageViewer::~Plugin_QmlImageViewer() +{ +} + +void Plugin_QmlImageViewer::setup(QWidget* const widget) +{ + Plugin::setup(widget); + + if (!interface()) + { + qCCritical(KIPIPLUGINS_LOG) << "kipi interface is null"; + return; + } + + setupActions(); +} + +void Plugin_QmlImageViewer::setupActions() +{ + setDefaultCategory(ImagesPlugin); + m_actionView = new QAction(this); + m_actionView->setText(i18n("View in QmlImageViewer")); + + connect(m_actionView, SIGNAL(triggered(bool)), + this,SLOT(slotView())); + + addAction(QString::fromLatin1("qmlimageviewer"), m_actionView); +} + +void Plugin_QmlImageViewer::slotView() +{ + if( m_viewer == 0 ) { + m_viewer = new KPQmlImageViewer(0, interface(), QApplication::activeWindow()->windowHandle()); + } else { + /* TODO: How to implement ? + if (m_viewer->isMinimized()) + { + KWindowSystem::unminimizeWindow(m_viewer->winId()); + }*/ + + //KWindowSystem::activateWindow(m_viewer->winId()); + } + + //m_viewer->show(); +} + +#include "qmlimageviewer_plugin.moc"