diff --git a/CMakeLists.txt b/CMakeLists.txt
index 63579cae7..bcbd4cd49 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -246,6 +246,7 @@ if(KF5Kipi_FOUND)
add_subdirectory(yandexfotki)
add_subdirectory(googleservices)
add_subdirectory(jalbum)
+ add_subdirectory(reverseimagesearch)
if(KF5Archive_FOUND)
add_subdirectory(flashexport)
diff --git a/reverseimagesearch/CMakeLists.txt b/reverseimagesearch/CMakeLists.txt
new file mode 100644
index 000000000..9c45bdac1
--- /dev/null
+++ b/reverseimagesearch/CMakeLists.txt
@@ -0,0 +1,33 @@
+#
+# Copyright (c) 2017 Vladislav Mileshkin
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+add_subdirectory(icons)
+add_subdirectory(data)
+
+add_definitions(-DTRANSLATION_DOMAIN=\"kipiplugin_reverseimagesearch\")
+
+set(kipiplugin_reverseimagesearch_PART_SRCS
+ plugin_reverseimagesearch.cpp
+ reverseimagesearchengine.cpp
+)
+
+add_library(kipiplugin_reverseimagesearch MODULE ${kipiplugin_reverseimagesearch_PART_SRCS})
+
+target_link_libraries(kipiplugin_reverseimagesearch
+ Qt5::Network
+
+ KF5::Kipi
+ KF5::WindowSystem
+ KF5::I18n
+
+ KF5kipiplugins
+)
+
+configure_file(kipiplugin_reverseimagesearch.desktop.cmake ${CMAKE_CURRENT_BINARY_DIR}/kipiplugin_reverseimagesearch.desktop)
+
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kipiplugin_reverseimagesearch.desktop DESTINATION ${SERVICES_INSTALL_DIR})
+install(TARGETS kipiplugin_reverseimagesearch DESTINATION ${PLUGIN_INSTALL_DIR})
+install(FILES kipiplugin_reverseimagesearchui.rc DESTINATION ${KXMLGUI_INSTALL_DIR}/kipi)
diff --git a/reverseimagesearch/Messages.sh b/reverseimagesearch/Messages.sh
new file mode 100755
index 000000000..2c8f46bfd
--- /dev/null
+++ b/reverseimagesearch/Messages.sh
@@ -0,0 +1,4 @@
+#! /bin/sh
+$EXTRACTRC `find . -name "*.ui" -o -name "*.rc" -o -name "*.kcfg" ` >> rc.cpp
+$XGETTEXT `find . -name "*.cpp" -o -name "*.h"` -o $podir/kipiplugin_reverseimagesearch.pot
+rm -f rc.cpp
diff --git a/reverseimagesearch/data/3diqdb.html.template b/reverseimagesearch/data/3diqdb.html.template
new file mode 100644
index 000000000..57c511926
--- /dev/null
+++ b/reverseimagesearch/data/3diqdb.html.template
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+ Please wait...
+
+
+
diff --git a/reverseimagesearch/data/CMakeLists.txt b/reverseimagesearch/data/CMakeLists.txt
new file mode 100644
index 000000000..6065b426d
--- /dev/null
+++ b/reverseimagesearch/data/CMakeLists.txt
@@ -0,0 +1,19 @@
+#
+# Copyright (c) 2017 Vladislav Mileshkin
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+install(FILES common.js DESTINATION ${DATA_INSTALL_DIR}/kipiplugin_reverseimagesearch)
+install(FILES ascii2d.html.template DESTINATION ${DATA_INSTALL_DIR}/kipiplugin_reverseimagesearch)
+install(FILES baidu.html.template DESTINATION ${DATA_INSTALL_DIR}/kipiplugin_reverseimagesearch)
+install(FILES deepfeatures.html.template DESTINATION ${DATA_INSTALL_DIR}/kipiplugin_reverseimagesearch)
+install(FILES google.html.template DESTINATION ${DATA_INSTALL_DIR}/kipiplugin_reverseimagesearch)
+install(FILES imgops.html.template DESTINATION ${DATA_INSTALL_DIR}/kipiplugin_reverseimagesearch)
+install(FILES iqdb.html.template DESTINATION ${DATA_INSTALL_DIR}/kipiplugin_reverseimagesearch)
+install(FILES 3diqdb.html.template DESTINATION ${DATA_INSTALL_DIR}/kipiplugin_reverseimagesearch)
+install(FILES karmadecay.html.template DESTINATION ${DATA_INSTALL_DIR}/kipiplugin_reverseimagesearch)
+install(FILES saucenao.html.template DESTINATION ${DATA_INSTALL_DIR}/kipiplugin_reverseimagesearch)
+install(FILES tineye.html.template DESTINATION ${DATA_INSTALL_DIR}/kipiplugin_reverseimagesearch)
+install(FILES viral.html.template DESTINATION ${DATA_INSTALL_DIR}/kipiplugin_reverseimagesearch)
+install(FILES harrylu.html.template DESTINATION ${DATA_INSTALL_DIR}/kipiplugin_reverseimagesearch)
diff --git a/reverseimagesearch/data/ascii2d.html.template b/reverseimagesearch/data/ascii2d.html.template
new file mode 100644
index 000000000..ed5983836
--- /dev/null
+++ b/reverseimagesearch/data/ascii2d.html.template
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+ Please wait...
+
+
+
diff --git a/reverseimagesearch/data/baidu.html.template b/reverseimagesearch/data/baidu.html.template
new file mode 100644
index 000000000..da6b3429f
--- /dev/null
+++ b/reverseimagesearch/data/baidu.html.template
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+ Please wait...
+
+
+
diff --git a/reverseimagesearch/data/common.js b/reverseimagesearch/data/common.js
new file mode 100644
index 000000000..165a26e1c
--- /dev/null
+++ b/reverseimagesearch/data/common.js
@@ -0,0 +1,96 @@
+/* ============================================================
+ *
+ * This file is a part of kipi-plugins project
+ * http://www.kipi-plugins.org
+ *
+ * Date : 2017-03-09
+ * Description : a tool to use reverse image search engines api
+ *
+ * Copyright (C) 2017 Vladislav Mileshkin
+ *
+ * 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.
+ *
+ * ============================================================ */
+
+function replaceCurrentDocument(doc) {
+ // Not using XMLSerializer because of it's sanitizer broke js
+ var html = doc.documentElement.outerHTML;
+ document.open();
+ document.write(html);
+ document.close();
+}
+
+function addBaseURL(doc, url) {
+ var head = doc.head;
+ var base = doc.createElement("base");
+ base.setAttribute("href", url);
+ head.insertBefore(base, head.firstChild);
+}
+
+function showMessage(message) {
+ document.getElementById("progress").innerHTML = message;
+ console.log(message);
+}
+
+function base64ToByteArray(base64) {
+ showMessage("Please wait... Decoding image");
+ var binaryString = atob(base64);
+ var binaryStringLength = binaryString.length;
+ var buffer = new ArrayBuffer(binaryString.length);
+ var byteArray = new Uint8Array(buffer);
+ var i;
+ for (i = 0; i < binaryStringLength; i++) {
+ byteArray[i] = binaryString.charCodeAt(i);
+ }
+ showMessage("Please wait...");
+ return byteArray;
+}
+
+function sendRequest(url, baseUrl, formData) {
+ var request = new XMLHttpRequest();
+
+ request.responseType = "document";
+
+ request.onreadystatechange = function () {
+ switch (request.readyState) {
+ case XMLHttpRequest.UNSENT:
+ showMessage("Please wait... Request created");
+ break;
+ case XMLHttpRequest.OPENED:
+ showMessage("Please wait... Request opened");
+ break;
+ case XMLHttpRequest.HEADERS_RECEIVED:
+ showMessage("Please wait... Sending data");
+ break;
+ case XMLHttpRequest.LOADING:
+ showMessage("Please wait... Receiving answer");
+ break;
+ case XMLHttpRequest.DONE:
+ showMessage("Please wait... Data transfer completed");
+ if (request.status === 200) {
+ var newDocument = request.response;
+ addBaseURL(newDocument, baseUrl);
+ replaceCurrentDocument(newDocument);
+ } else {
+ showMessage(`Error: HTTP status code ${request.status}`);
+ }
+ break;
+ }
+ };
+
+ request.onerror = function () {
+ showMessage("An error occurred during the request!");
+ };
+
+ request.withCredentials = true;
+ request.open("POST", url, true);
+ request.send(formData);
+}
diff --git a/reverseimagesearch/data/deepfeatures.html.template b/reverseimagesearch/data/deepfeatures.html.template
new file mode 100644
index 000000000..95995f7ab
--- /dev/null
+++ b/reverseimagesearch/data/deepfeatures.html.template
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+ Please wait...
+
+
+
diff --git a/reverseimagesearch/data/google.html.template b/reverseimagesearch/data/google.html.template
new file mode 100644
index 000000000..4b520c5c2
--- /dev/null
+++ b/reverseimagesearch/data/google.html.template
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+ Please wait...
+
+
+
diff --git a/reverseimagesearch/data/harrylu.html.template b/reverseimagesearch/data/harrylu.html.template
new file mode 100644
index 000000000..abf11b999
--- /dev/null
+++ b/reverseimagesearch/data/harrylu.html.template
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+ Please wait...
+
+
+
diff --git a/reverseimagesearch/data/imgops.html.template b/reverseimagesearch/data/imgops.html.template
new file mode 100644
index 000000000..1e234e69c
--- /dev/null
+++ b/reverseimagesearch/data/imgops.html.template
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+ Please wait...
+
+
+
diff --git a/reverseimagesearch/data/iqdb.html.template b/reverseimagesearch/data/iqdb.html.template
new file mode 100644
index 000000000..d1433da3a
--- /dev/null
+++ b/reverseimagesearch/data/iqdb.html.template
@@ -0,0 +1,38 @@
+
+
+
+
+
+
+
+
+
+ Please wait...
+
+
+
diff --git a/reverseimagesearch/data/karmadecay.html.template b/reverseimagesearch/data/karmadecay.html.template
new file mode 100644
index 000000000..6a29e3d44
--- /dev/null
+++ b/reverseimagesearch/data/karmadecay.html.template
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+
+ Please wait...
+
+
+
diff --git a/reverseimagesearch/data/saucenao.html.template b/reverseimagesearch/data/saucenao.html.template
new file mode 100644
index 000000000..87d465fae
--- /dev/null
+++ b/reverseimagesearch/data/saucenao.html.template
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+ Please wait...
+
+
+
diff --git a/reverseimagesearch/data/tineye.html.template b/reverseimagesearch/data/tineye.html.template
new file mode 100644
index 000000000..7a00569ba
--- /dev/null
+++ b/reverseimagesearch/data/tineye.html.template
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+ Please wait...
+
+
+
diff --git a/reverseimagesearch/data/viral.html.template b/reverseimagesearch/data/viral.html.template
new file mode 100644
index 000000000..4540eff42
--- /dev/null
+++ b/reverseimagesearch/data/viral.html.template
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+ Please wait...
+
+
+
diff --git a/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-3diqdb.png b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-3diqdb.png
new file mode 100644
index 000000000..a1ed85730
Binary files /dev/null and b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-3diqdb.png differ
diff --git a/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-ascii2d.png b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-ascii2d.png
new file mode 100644
index 000000000..b88cd2255
Binary files /dev/null and b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-ascii2d.png differ
diff --git a/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-baidu.png b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-baidu.png
new file mode 100644
index 000000000..4ab21b170
Binary files /dev/null and b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-baidu.png differ
diff --git a/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-google.png b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-google.png
new file mode 100644
index 000000000..60b87cf45
Binary files /dev/null and b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-google.png differ
diff --git a/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-harrylu.png b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-harrylu.png
new file mode 100644
index 000000000..6e3df48bf
Binary files /dev/null and b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-harrylu.png differ
diff --git a/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-imgops.png b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-imgops.png
new file mode 100644
index 000000000..29c01e442
Binary files /dev/null and b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-imgops.png differ
diff --git a/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-iqdb.png b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-iqdb.png
new file mode 100644
index 000000000..a1ed85730
Binary files /dev/null and b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-iqdb.png differ
diff --git a/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-karmadecay.png b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-karmadecay.png
new file mode 100644
index 000000000..9f1ddd779
Binary files /dev/null and b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-karmadecay.png differ
diff --git a/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-saucenao.png b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-saucenao.png
new file mode 100644
index 000000000..db3d307af
Binary files /dev/null and b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-saucenao.png differ
diff --git a/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-tineye.png b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-tineye.png
new file mode 100644
index 000000000..f0ab2edbe
Binary files /dev/null and b/reverseimagesearch/icons/16-apps-kipi-reverseimagesearch-tineye.png differ
diff --git a/reverseimagesearch/icons/CMakeLists.txt b/reverseimagesearch/icons/CMakeLists.txt
new file mode 100644
index 000000000..42d26e171
--- /dev/null
+++ b/reverseimagesearch/icons/CMakeLists.txt
@@ -0,0 +1,20 @@
+#
+# Copyright (c) 2017 Vladislav Mileshkin
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+ecm_install_icons(
+ ICONS
+ 16-apps-kipi-reverseimagesearch-ascii2d.png
+ 16-apps-kipi-reverseimagesearch-baidu.png
+ 16-apps-kipi-reverseimagesearch-google.png
+ 16-apps-kipi-reverseimagesearch-imgops.png
+ 16-apps-kipi-reverseimagesearch-iqdb.png
+ 16-apps-kipi-reverseimagesearch-3diqdb.png
+ 16-apps-kipi-reverseimagesearch-karmadecay.png
+ 16-apps-kipi-reverseimagesearch-saucenao.png
+ 16-apps-kipi-reverseimagesearch-tineye.png
+ 16-apps-kipi-reverseimagesearch-harrylu.png
+ DESTINATION ${ICON_INSTALL_DIR}
+)
diff --git a/reverseimagesearch/kipiplugin_reverseimagesearch.desktop.cmake b/reverseimagesearch/kipiplugin_reverseimagesearch.desktop.cmake
new file mode 100644
index 000000000..db27a3014
--- /dev/null
+++ b/reverseimagesearch/kipiplugin_reverseimagesearch.desktop.cmake
@@ -0,0 +1,10 @@
+[Desktop Entry]
+UntranslatedGenericName=Reverse image search
+Name=Reverse image search
+Type=Service
+Icon=kipi-reverseimagesearch
+ServiceTypes=KIPI/Plugin
+X-KDE-Library=kipiplugin_reverseimagesearch
+X-KIPI-PluginCategories=Tools
+X-KIPI-BinaryVersion=${KIPI_LIB_SO_CUR_VERSION}
+author=Vladislav Mileshkin
diff --git a/reverseimagesearch/kipiplugin_reverseimagesearchui.rc b/reverseimagesearch/kipiplugin_reverseimagesearchui.rc
new file mode 100644
index 000000000..4f27b02fc
--- /dev/null
+++ b/reverseimagesearch/kipiplugin_reverseimagesearchui.rc
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+ Main Toolbar
+
+
+
+
diff --git a/reverseimagesearch/plugin_reverseimagesearch.cpp b/reverseimagesearch/plugin_reverseimagesearch.cpp
new file mode 100644
index 000000000..896e17302
--- /dev/null
+++ b/reverseimagesearch/plugin_reverseimagesearch.cpp
@@ -0,0 +1,163 @@
+/* ============================================================
+ *
+ * This file is a part of kipi-plugins project
+ * http://www.kipi-plugins.org
+ *
+ * Date : 2017-03-09
+ * Description : a tool to use reverse image search engines api
+ *
+ * Copyright (C) 2017 Vladislav Mileshkin
+ *
+ * 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 "plugin_reverseimagesearch.h"
+
+// Qt includes
+
+#include
+#include
+#include
+#include
+
+// KDE includes
+
+#include
+#include
+#include
+#include
+
+// Libkipi includes
+
+#include
+#include
+
+// Local includes
+
+#include "kipiplugins_debug.h"
+#include "reverseimagesearchengine.h"
+
+namespace KIPIReverseImageSearchPlugin
+{
+
+K_PLUGIN_FACTORY( ReverseImageSearchFactory, registerPlugin(); )
+
+class Plugin_ReverseImageSearch::Private
+{
+public:
+
+ Private(){}
+ ~Private()
+ {
+ for(QTemporaryFile* file : files)
+ {
+ delete file;
+ }
+ }
+
+ QList engines;
+ QList actions;
+ QList files;
+};
+
+Plugin_ReverseImageSearch::Plugin_ReverseImageSearch(QObject* const parent, const QVariantList& args)
+ : Plugin(parent, "ReverseImageSearch"),
+ d(new Private)
+{
+ Q_UNUSED(args);
+
+ qCDebug(KIPIPLUGINS_LOG) << "ReverseImageSearch plugin loaded";
+
+ setUiBaseName("kipiplugin_reverseimagesearchui.rc");
+ setupXML();
+}
+
+Plugin_ReverseImageSearch::~Plugin_ReverseImageSearch()
+{
+ delete d;
+}
+
+void Plugin_ReverseImageSearch::setup(QWidget* const widget)
+{
+ Plugin::setup(widget);
+
+ if (interface())
+ {
+ setupActions();
+ }
+ else
+ {
+ qCCritical(KIPIPLUGINS_LOG) << "Kipi interface is null!";
+ }
+}
+
+void Plugin_ReverseImageSearch::setupActions()
+{
+ setDefaultCategory(ToolsPlugin);
+
+ QMap enginesToLabels;
+ enginesToLabels[QLatin1String("ascii2d")] = i18n("&ASCII2d");
+ enginesToLabels[QLatin1String("baidu")] = i18n("&Baidu");
+ enginesToLabels[QLatin1String("deepfeatures")] = i18n("&DeepFeatures");
+ enginesToLabels[QLatin1String("google")] = i18n("&Google");
+ enginesToLabels[QLatin1String("imgops")] = i18n("&ImageOps");
+ enginesToLabels[QLatin1String("iqdb")] = i18n("&IQDB");
+ enginesToLabels[QLatin1String("3diqdb")] = i18n("&3D IQDB");
+ enginesToLabels[QLatin1String("karmadecay")] = i18n("&KarmaDecay");
+ enginesToLabels[QLatin1String("saucenao")] = i18n("&SauceNAO");
+ enginesToLabels[QLatin1String("tineye")] = i18n("&TinEye");
+ enginesToLabels[QLatin1String("viral")] = i18n("&Viral");
+ enginesToLabels[QLatin1String("harrylu")] = i18n("&Harry.lu");
+
+ for (auto name : enginesToLabels.keys())
+ {
+ ReverseImageSearchEngine * engine = new ReverseImageSearchEngine(name, this);
+
+ connect(engine, &ReverseImageSearchEngine::ready,
+ this, &Plugin_ReverseImageSearch::openInDefaulWebBrowser);
+
+ d->engines.append(engine);
+
+ QAction * action = new QAction(this);
+ action->setText(enginesToLabels.value(name));
+ action->setIcon(QIcon::fromTheme(QString::fromLatin1("kipi-reverseimagesearch-%1").arg(name)));
+
+ connect(action, &QAction::triggered, [this, engine](){
+ ImageCollection collection = interface()->currentSelection();
+ for(auto url : collection.images())
+ {
+ if (url.isLocalFile())
+ {
+ engine->find(url.toLocalFile());
+ }
+ else
+ {
+ qCDebug(KIPIPLUGINS_LOG) << "URL doesn't contain a local file path";
+ }
+ }
+ });
+
+ addAction(name, action);
+
+ d->actions.append(action);
+ }
+}
+
+void Plugin_ReverseImageSearch::openInDefaulWebBrowser(QTemporaryFile* file)
+{
+ d->files.append(file);
+ QDesktopServices::openUrl(QUrl::fromLocalFile(file->fileName()));
+}
+
+} // namespace KIPIReverseImageSearchPlugin
+
+#include "plugin_reverseimagesearch.moc"
diff --git a/reverseimagesearch/plugin_reverseimagesearch.h b/reverseimagesearch/plugin_reverseimagesearch.h
new file mode 100644
index 000000000..ea1d1b94d
--- /dev/null
+++ b/reverseimagesearch/plugin_reverseimagesearch.h
@@ -0,0 +1,67 @@
+/* ============================================================
+ *
+ * This file is a part of kipi-plugins project
+ * http://www.kipi-plugins.org
+ *
+ * Date : 2017-03-09
+ * Description : a tool to use reverse image search engines api
+ *
+ * Copyright (C) 2017 Vladislav Mileshkin
+ *
+ * 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_REVERSEIMAGESEARCH_H
+#define PLUGIN_REVERSEIMAGESEARCH_H
+
+// Qt includes
+
+#include
+#include
+
+// Libkipi includes
+
+#include
+
+using namespace KIPI;
+
+namespace KIPIReverseImageSearchPlugin
+{
+
+class Plugin_ReverseImageSearch : public Plugin
+{
+ Q_OBJECT
+
+public:
+
+ explicit Plugin_ReverseImageSearch(QObject* const parent, const QVariantList& args);
+ ~Plugin_ReverseImageSearch();
+
+ void setup(QWidget* const);
+
+public Q_SLOTS:
+
+ void openInDefaulWebBrowser(QTemporaryFile* file);
+
+private:
+
+ void setupActions();
+
+private:
+
+ class Private;
+ Private* const d;
+};
+
+} // namespace KIPIReverseImageSearchPlugin
+
+#endif // PLUGIN_REVERSEIMAGESEARCH_H
diff --git a/reverseimagesearch/reverseimagesearchengine.cpp b/reverseimagesearch/reverseimagesearchengine.cpp
new file mode 100644
index 000000000..d869158ee
--- /dev/null
+++ b/reverseimagesearch/reverseimagesearchengine.cpp
@@ -0,0 +1,102 @@
+/* ============================================================
+ *
+ * This file is a part of kipi-plugins project
+ * http://www.kipi-plugins.org
+ *
+ * Date : 2017-03-09
+ * Description : a tool to use reverse image search engines api
+ *
+ * Copyright (C) 2017 Vladislav Mileshkin
+ *
+ * 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
+#include
+#include
+
+// Local includes
+
+#include "kipiplugins_debug.h"
+#include "reverseimagesearchengine.h"
+
+namespace KIPIReverseImageSearchPlugin
+{
+
+ReverseImageSearchEngine::ReverseImageSearchEngine(QString name, QObject* const parent)
+ : QObject(parent),
+ name(name)
+{}
+
+void ReverseImageSearchEngine::find(QString imagePath)
+{
+ QFile imageFile(imagePath);
+
+ QFileInfo imageFileInfo(imageFile);
+ QString fileName = imageFileInfo.fileName();
+
+ if (!imageFile.open(QIODevice::ReadOnly))
+ {
+ qCDebug(KIPIPLUGINS_LOG) << "Could not open image file: "
+ << imagePath;
+ return;
+ }
+
+ QByteArray fileContent = imageFile.readAll();
+ QString base64FileContent = QString::fromUtf8(fileContent.toBase64());
+ imageFile.close();
+
+ QMimeDatabase db;
+ QString fileMimetype = db.mimeTypeForData(fileContent).name();
+
+ QString commonJSName = QLatin1String("kipiplugin_reverseimagesearch/common.js");
+ QString commonJSPath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, commonJSName);
+
+ QString templateName = QString::fromLatin1("kipiplugin_reverseimagesearch/%1.html.template").arg(name);
+ QString templatePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation,
+ templateName);
+
+ QFile templateFile(templatePath);
+
+ if (!templateFile.open(QIODevice::ReadOnly))
+ {
+ qCDebug(KIPIPLUGINS_LOG) << "Could not open template file: "
+ << templatePath;
+ return;
+ }
+
+ QTextStream in(&templateFile);
+ QString templateContent = in.readAll();
+ templateFile.close();
+
+ templateContent.replace(QLatin1String("#{COMMONJSFILE}#"), commonJSPath);
+ templateContent.replace(QLatin1String("#{FILENAME}#"), fileName);
+ templateContent.replace(QLatin1String("#{MIMETYPE}#"), fileMimetype);
+ templateContent.replace(QLatin1String("#{FILECONTENT}#"), base64FileContent);
+
+ QTemporaryFile * resultHTMLFile = new QTemporaryFile();
+
+ if (!resultHTMLFile->open())
+ {
+ qCDebug(KIPIPLUGINS_LOG) << "Could not open temporary file";
+ return;
+ }
+
+ resultHTMLFile->write(templateContent.toUtf8());
+ emit ready(resultHTMLFile);
+}
+
+} // namespace KIPIReverseImageSearchPlugins
+
+#include "reverseimagesearchengine.moc"
diff --git a/reverseimagesearch/reverseimagesearchengine.h b/reverseimagesearch/reverseimagesearchengine.h
new file mode 100644
index 000000000..83816c75a
--- /dev/null
+++ b/reverseimagesearch/reverseimagesearchengine.h
@@ -0,0 +1,60 @@
+/* ============================================================
+ *
+ * This file is a part of kipi-plugins project
+ * http://www.kipi-plugins.org
+ *
+ * Date : 2017-03-09
+ * Description : a tool to use reverse image search engines api
+ *
+ * Copyright (C) 2017 Vladislav Mileshkin
+ *
+ * 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 REVERSEIMAGESEARCHENGINE_H
+#define REVERSEIMAGESEARCHENGINE_H
+
+// Qt includes
+
+#include
+
+// Local includes
+
+#include "kpmultipart.h"
+
+namespace KIPIReverseImageSearchPlugin
+{
+
+class ReverseImageSearchEngine : public QObject
+{
+ Q_OBJECT
+
+public:
+
+ explicit ReverseImageSearchEngine(QString name, QObject* parent);
+
+Q_SIGNALS:
+
+ void ready(QTemporaryFile* file);
+
+public Q_SLOTS:
+
+ void find(QString filepath);
+
+private:
+
+ QString name;
+};
+
+} // namespace KIPIReverseImageSearchPlugin
+
+#endif // REVERSEIMAGESEARCHENGINE_H