[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [digikam/gsoc18-twitter-onedrive] core: add pinterest webservice
From: Tarek Talaat <null () kde ! org>
Date: 2018-08-11 21:39:02
Message-ID: E1fobbC-0005aG-WD () code ! kde ! org
[Download RAW message or body]
Git commit 402e255bb3117cc5f1c8958d35a557a06284b977 by Tarek Talaat.
Committed on 10/08/2018 at 21:45.
Pushed by tarektalaat into branch 'gsoc18-twitter-onedrive'.
add pinterest webservice
M +4 -8 core/app/main/digikamapp_export.cpp
M +1 -2 core/app/main/digikamapp_p.h
M +1 -2 core/app/main/digikamui5.rc
M +7 -17 core/libs/widgets/mainview/dxmlguiwindow.cpp
M +1 -2 core/libs/widgets/mainview/dxmlguiwindow.h
M +12 -0 core/showfoto/main/showfoto_export.cpp
M +2 -0 core/showfoto/main/showfoto_p.h
M +1 -2 core/showfoto/main/showfotoui5.rc
M +35 -8 core/utilities/assistants/webservices/CMakeLists.txt
A +60 -0 core/utilities/assistants/webservices/pinterest/pitem.h [License: \
GPL (v2+)] A +69 -0 core/utilities/assistants/webservices/pinterest/pmpform.cpp \
[License: GPL (v2+)] A +54 -0 \
core/utilities/assistants/webservices/pinterest/pmpform.h [License: GPL (v2+)] A \
+52 -0 core/utilities/assistants/webservices/pinterest/pnewalbumdlg.cpp \
[License: GPL (v2+)] A +50 -0 \
core/utilities/assistants/webservices/pinterest/pnewalbumdlg.h [License: GPL \
(v2+)] A +561 -0 core/utilities/assistants/webservices/pinterest/ptalker.cpp \
[License: GPL (v2+)] A +105 -0 \
core/utilities/assistants/webservices/pinterest/ptalker.h [License: GPL (v2+)] A \
+70 -0 core/utilities/assistants/webservices/pinterest/pwidget.cpp [License: \
GPL (v2+)] A +62 -0 core/utilities/assistants/webservices/pinterest/pwidget.h \
[License: GPL (v2+)] A +465 -0 \
core/utilities/assistants/webservices/pinterest/pwindow.cpp [License: GPL (v2+)] \
A +98 -0 core/utilities/assistants/webservices/pinterest/pwindow.h \
[License: GPL (v2+)] M +1 -2 core/utilities/imageeditor/main/imageeditorui5.rc
M +1 -2 core/utilities/lighttable/lighttablewindowui5.rc
https://commits.kde.org/digikam/402e255bb3117cc5f1c8958d35a557a06284b977
diff --git a/core/app/main/digikamapp_export.cpp \
b/core/app/main/digikamapp_export.cpp index 3c1e333a4f..7e5ea7009f 100644
--- a/core/app/main/digikamapp_export.cpp
+++ b/core/app/main/digikamapp_export.cpp
@@ -102,18 +102,14 @@ void DigikamApp::slotExportTool()
w->exec();
delete w;
}
- else if (tool == m_exportTwitterAction)
- {
- QPointer<TwWindow> w = new TwWindow(new DBInfoIface(this, QList<QUrl>(), \
ApplicationSettings::ImportExport), this);
- w->exec();
- delete w;
- }
- else if (tool == m_exportLinkedInAction)
+
+ else if (tool == m_exportPinterestAction)
{
- QPointer<LIWindow> w = new LIWindow(new DBInfoIface(this, QList<QUrl>(), \
ApplicationSettings::ImportExport), this); + QPointer<PWindow> w = new \
PWindow(new DBInfoIface(this, QList<QUrl>(), ApplicationSettings::ImportExport), \
this); w->exec();
delete w;
}
+
else if (tool == m_exportFacebookAction)
{
QPointer<FbWindow> w = new FbWindow(new DBInfoIface(this, QList<QUrl>(), \
ApplicationSettings::ImportExport), this);
diff --git a/core/app/main/digikamapp_p.h b/core/app/main/digikamapp_p.h
index 23cd9bd210..c1a48ca97d 100644
--- a/core/app/main/digikamapp_p.h
+++ b/core/app/main/digikamapp_p.h
@@ -132,9 +132,8 @@
#include "dmediaserverdlg.h"
#include "dbwindow.h"
#include "odwindow.h"
-#include "twitterwindow.h"
+#include "pwindow.h"
#include "fbwindow.h"
-#include "liwindow.h"
#include "flickrwindow.h"
#include "gswindow.h"
#include "imageshackwindow.h"
diff --git a/core/app/main/digikamui5.rc b/core/app/main/digikamui5.rc
index 2cd34eb409..6137e2e24b 100644
--- a/core/app/main/digikamui5.rc
+++ b/core/app/main/digikamui5.rc
@@ -155,11 +155,10 @@
<Action name="export_googlephoto" />
<Action name="export_imageshack" />
<Action name="export_imgur" />
- <Action name="export_linkedin" />
<Action name="export_onedrive" />
+ <Action name="export_pinterest" />
<Action name="export_rajce" />
<Action name="export_smugmug" />
- <Action name="export_twitter" />
<Action name="export_yandexfotki" />
<Action name="export_mediawiki" />
<Action name="export_vkontakte" />
diff --git a/core/libs/widgets/mainview/dxmlguiwindow.cpp \
b/core/libs/widgets/mainview/dxmlguiwindow.cpp index 9bcc32b4c5..79ba392211 100644
--- a/core/libs/widgets/mainview/dxmlguiwindow.cpp
+++ b/core/libs/widgets/mainview/dxmlguiwindow.cpp
@@ -189,8 +189,7 @@ DXmlGuiWindow::DXmlGuiWindow(QWidget* const parent, \
Qt::WindowFlags f)
m_exportDropboxAction = 0;
m_exportOnedriveAction = 0;
- m_exportLinkedInAction = 0;
- m_exportTwitterAction = 0;
+ m_exportPinterestAction = 0;
m_exportFacebookAction = 0;
m_exportFlickrAction = 0;
m_exportGdriveAction = 0;
@@ -1054,20 +1053,12 @@ void DXmlGuiWindow::createExportActions()
connect(m_exportOnedriveAction, SIGNAL(triggered(bool)),
this, SLOT(slotExportTool()));
- m_exportLinkedInAction = new QAction(i18n("Export to &LinkedIn..."), this);
- m_exportLinkedInAction->setIcon(QIcon::fromTheme(QString::fromLatin1("linkedin")));
- actionCollection()->addAction(QLatin1String("export_linkedin"), \
m_exportLinkedInAction);
- actionCollection()->setDefaultShortcut(m_exportLinkedInAction, Qt::ALT + \
Qt::SHIFT + Qt::CTRL + Qt::Key_L); + m_exportPinterestAction = new \
QAction(i18n("Export to &Pinterest..."), this); + \
m_exportPinterestAction->setIcon(QIcon::fromTheme(QString::fromLatin1("pinterest"))); \
+ actionCollection()->addAction(QLatin1String("export_pinterest"), \
m_exportPinterestAction); + \
actionCollection()->setDefaultShortcut(m_exportPinterestAction, Qt::ALT + Qt::SHIFT + \
Qt::CTRL + Qt::Key_I);
- connect(m_exportLinkedInAction, SIGNAL(triggered(bool)),
- this, SLOT(slotExportTool()));
-
- m_exportTwitterAction = new QAction(i18n("Export to &Twitter..."), this);
- m_exportTwitterAction->setIcon(QIcon::fromTheme(QString::fromLatin1("twitter")));
- actionCollection()->addAction(QLatin1String("export_twitter"), \
m_exportTwitterAction);
- actionCollection()->setDefaultShortcut(m_exportTwitterAction, Qt::ALT + \
Qt::SHIFT + Qt::CTRL + Qt::Key_T);
-
- connect(m_exportTwitterAction, SIGNAL(triggered(bool)),
+ connect(m_exportPinterestAction, SIGNAL(triggered(bool)),
this, SLOT(slotExportTool()));
m_exportFacebookAction = new QAction(i18n("Export to &Facebook..."), this);
@@ -1218,8 +1209,7 @@ QList<QAction*> DXmlGuiWindow::exportActions() const
{
return QList<QAction*>() << m_exportDropboxAction
<< m_exportOnedriveAction
- << m_exportLinkedInAction
- << m_exportTwitterAction
+ << m_exportPinterestAction
<< m_exportFacebookAction
<< m_exportFlickrAction
<< m_exportGdriveAction
diff --git a/core/libs/widgets/mainview/dxmlguiwindow.h \
b/core/libs/widgets/mainview/dxmlguiwindow.h index 64fafe6988..bb7d3a1fe4 100644
--- a/core/libs/widgets/mainview/dxmlguiwindow.h
+++ b/core/libs/widgets/mainview/dxmlguiwindow.h
@@ -231,8 +231,7 @@ protected:
QAction* m_exportDropboxAction;
QAction* m_exportOnedriveAction;
- QAction* m_exportLinkedInAction;
- QAction* m_exportTwitterAction;
+ QAction* m_exportPinterestAction;
QAction* m_exportFacebookAction;
QAction* m_exportFlickrAction;
QAction* m_exportGdriveAction;
diff --git a/core/showfoto/main/showfoto_export.cpp \
b/core/showfoto/main/showfoto_export.cpp index bc41664cdb..42932bb9bd 100644
--- a/core/showfoto/main/showfoto_export.cpp
+++ b/core/showfoto/main/showfoto_export.cpp
@@ -92,6 +92,18 @@ void ShowFoto::slotExportTool()
w->exec();
delete w;
}
+ if (tool == m_exportOnedriveAction)
+ {
+ QPointer<ODWindow> w = new ODWindow(new DMetaInfoIface(this, \
d->thumbBar->urls()), this); + w->exec();
+ delete w;
+ }
+ if (tool == m_exportPinterestAction)
+ {
+ QPointer<PWindow> w = new PWindow(new DMetaInfoIface(this, \
d->thumbBar->urls()), this); + w->exec();
+ delete w;
+ }
else if (tool == m_exportFacebookAction)
{
QPointer<FbWindow> w = new FbWindow(new DMetaInfoIface(this, \
d->thumbBar->urls()), this);
diff --git a/core/showfoto/main/showfoto_p.h b/core/showfoto/main/showfoto_p.h
index a6db2f9607..fef7907d8a 100644
--- a/core/showfoto/main/showfoto_p.h
+++ b/core/showfoto/main/showfoto_p.h
@@ -108,6 +108,8 @@
#include "dmediaservermngr.h"
#include "dmediaserverdlg.h"
#include "dbwindow.h"
+#include "odwindow.h"
+#include "pwindow.h"
#include "fbwindow.h"
#include "flickrwindow.h"
#include "gswindow.h"
diff --git a/core/showfoto/main/showfotoui5.rc b/core/showfoto/main/showfotoui5.rc
index bd139578c5..c1cfccbc01 100644
--- a/core/showfoto/main/showfotoui5.rc
+++ b/core/showfoto/main/showfotoui5.rc
@@ -161,11 +161,10 @@
<Action name="export_googlephoto" />
<Action name="export_imageshack" />
<Action name="export_imgur" />
- <Action name="export_linkedin" />
<Action name="export_onedrive" />
+ <Action name="export_pinterest" />
<Action name="export_rajce" />
<Action name="export_smugmug" />
- <Action name="export_twitter" />
<Action name="export_yandexfotki" />
<Action name="export_mediawiki" />
<Action name="export_vkontakte" />
diff --git a/core/utilities/assistants/webservices/CMakeLists.txt \
b/core/utilities/assistants/webservices/CMakeLists.txt index ddb8dcbe10..20d5d587ef \
100644
--- a/core/utilities/assistants/webservices/CMakeLists.txt
+++ b/core/utilities/assistants/webservices/CMakeLists.txt
@@ -14,13 +14,18 @@ include_directories($<TARGET_PROPERTY:Qt5::Widgets,INTERFACE_INCLUDE_DIRECTORIES
$<TARGET_PROPERTY:Qt5::Gui,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:Qt5::Xml,INTERFACE_INCLUDE_DIRECTORIES>
\
$<TARGET_PROPERTY:Qt5::XmlPatterns,INTERFACE_INCLUDE_DIRECTORIES>
- \
$<TARGET_PROPERTY:Qt5::WebEngineWidgets,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:KF5::XmlGui,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:KF5::I18n,INTERFACE_INCLUDE_DIRECTORIES>
$<TARGET_PROPERTY:KF5::ConfigCore,INTERFACE_INCLUDE_DIRECTORIES>
)
+if(ENABLE_QWEBENGINE)
+ include_directories($<TARGET_PROPERTY:Qt5::WebEngineWidgets,INTERFACE_INCLUDE_DIRECTORIES>)
+else()
+ include_directories($<TARGET_PROPERTY:Qt5::WebKitWidgets,INTERFACE_INCLUDE_DIRECTORIES>)
+endif()
+
if(KF5KIO_FOUND)
include_directories($<TARGET_PROPERTY:KF5::KIOCore,INTERFACE_INCLUDE_DIRECTORIES>
@@ -72,6 +77,17 @@ set(libwso2_SRCS
#${CMAKE_CURRENT_SOURCE_DIR}/common/o2/src/o2hubic.cpp
#${CMAKE_CURRENT_SOURCE_DIR}/common/o2/src/o2uber.cpp
)
+if(ENABLE_QWEBENGINE)
+ set(libwso2_SRCS
+ ${libwso2_SRCS}
+ ${CMAKE_CURRENT_SOURCE_DIR}/common/webwidget_qwebengine.cpp
+ )
+else()
+ set(libwso2_SRCS
+ ${libwso2_SRCS}
+ ${CMAKE_CURRENT_SOURCE_DIR}/common/webwidget.cpp
+ )
+endif()
# Helper classes ------------------------------------------------------------------
@@ -128,15 +144,25 @@ set(libwsonedrive_SRCS \
${CMAKE_CURRENT_SOURCE_DIR}/onedrive/odnewalbumdlg.cpp \
${CMAKE_CURRENT_SOURCE_DIR}/onedrive/odwindow.cpp )
-# LinkedIn tool --------------------------------------------------------------
+# Pinterest tool --------------------------------------------------------------
-set(libwslinkedin_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/linkedIn/linewalbumdlg.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/linkedIn/limpform.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/linkedIn/litalker.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/linkedIn/liwidget.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/linkedIn/liwindow.cpp
+set(libwspinterest_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/pinterest/pnewalbumdlg.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/pinterest/pmpform.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/pinterest/ptalker.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/pinterest/pwidget.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/pinterest/pwindow.cpp
)
+# Box tool --------------------------------------------------------------
+
+set(libwsbox_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/box/boxnewalbumdlg.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/box/boxmpform.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/box/boxtalker.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/box/boxwidget.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/box/boxwindow.cpp
+)
+
+
# Twitter tool --------------------------------------------------------------
set(libwstwitter_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/twitter/twitternewalbumdlg.cpp
@@ -265,8 +291,9 @@ add_library(webservices_src OBJECT ${libwebservices_SRCS}
${libwsimgur_SRCS}
${libwsdropbox_SRCS}
${libwsonedrive_SRCS}
+ ${libwspinterest_SRCS}
${libwstwitter_SRCS}
- ${libwslinkedin_SRCS}
+ ${libwsbox_SRCS}
${libwssmugmug_SRCS}
${libwsimageshack_SRCS}
${libwsfacebook_SRCS}
diff --git a/core/utilities/assistants/webservices/pinterest/pitem.h \
b/core/utilities/assistants/webservices/pinterest/pitem.h new file mode 100644
index 0000000000..19b9a10ca5
--- /dev/null
+++ b/core/utilities/assistants/webservices/pinterest/pitem.h
@@ -0,0 +1,60 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2018-05-20
+ * Description : a tool to export images to Onedrive web service
+ *
+ * Copyright (C) 2013 by Pankaj Kumar <me at panks dot me>
+ * Copyright (C) 2013-2018 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+
+#ifndef P_ITEM_H
+#define P_ITEM_H
+
+// Qt includes
+
+#include <QString>
+
+namespace Digikam{
+
+class PPhoto
+{
+public:
+
+ PPhoto()
+ {
+
+ }
+
+ QString title;
+};
+
+class PFolder
+{
+
+public:
+
+ PFolder()
+ {
+
+ }
+
+ QString title;
+};
+
+} //namespace Digikam
+
+#endif // P_ITEM_H
diff --git a/core/utilities/assistants/webservices/pinterest/pmpform.cpp \
b/core/utilities/assistants/webservices/pinterest/pmpform.cpp new file mode 100644
index 0000000000..0657a3fd59
--- /dev/null
+++ b/core/utilities/assistants/webservices/pinterest/pmpform.cpp
@@ -0,0 +1,69 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2018-05-20
+ * Description : a tool to export images to Onedrive web service
+ *
+ * Copyright (C) 2013 by Pankaj Kumar <me at panks dot me>
+ * Copyright (C) 2013-2018 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+
+ // local includes
+
+ #include "pmpform.h"
+
+ // Qt includes
+
+ #include <QFile>
+ #include <QUrl>
+ #include <QMimeDatabase>
+ #include <QMimeType>
+
+ // Local includes
+
+ #include "digikam_debug.h"
+
+ namespace Digikam
+ {
+
+ PMPForm::PMPForm()
+ {
+ }
+
+ PMPForm::~PMPForm()
+ {
+ }
+
+ bool PMPForm::addFile(const QString& imgPath)
+ {
+ QFile file(imgPath);
+
+ if (!file.open(QIODevice::ReadOnly))
+ {
+ return false;
+ }
+
+ m_buffer = file.readAll();
+
+ return true;
+ }
+
+ QByteArray PMPForm::formData() const
+ {
+ return m_buffer;
+ }
+
+} // namespace Digikam
diff --git a/core/utilities/assistants/webservices/pinterest/pmpform.h \
b/core/utilities/assistants/webservices/pinterest/pmpform.h new file mode 100644
index 0000000000..ac99d62f2e
--- /dev/null
+++ b/core/utilities/assistants/webservices/pinterest/pmpform.h
@@ -0,0 +1,54 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2018-05-20
+ * Description : a tool to export images to Onedrive web service
+ *
+ * Copyright (C) 2013 by Pankaj Kumar <me at panks dot me>
+ * Copyright (C) 2013-2018 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+
+#ifndef P_MPFORM_H
+#define P_MPFORM_H
+
+// Qt includes
+
+#include <QByteArray>
+#include <QString>
+#include "wstoolutils.h"
+
+namespace Digikam
+{
+
+class PMPForm
+{
+
+public:
+
+ explicit PMPForm();
+ ~PMPForm();
+
+ bool addFile(const QString& imgPath);
+ QByteArray formData() const;
+
+private:
+
+ QByteArray m_buffer;
+};
+
+} // namespace Digikam
+
+#endif // P_MPFORM_H
diff --git a/core/utilities/assistants/webservices/pinterest/pnewalbumdlg.cpp \
b/core/utilities/assistants/webservices/pinterest/pnewalbumdlg.cpp new file mode \
100644 index 0000000000..6c6cfe4def
--- /dev/null
+++ b/core/utilities/assistants/webservices/pinterest/pnewalbumdlg.cpp
@@ -0,0 +1,52 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2018-05-20
+ * Description : a tool to export images to Onedrive web service
+ *
+ * Copyright (C) 2013 by Pankaj Kumar <me at panks dot me>
+ * Copyright (C) 2013-2018 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+
+ #include "pnewalbumdlg.h"
+
+ // Local includes
+
+ #include "digikam_debug.h"
+ #include "pitem.h"
+
+namespace Digikam
+{
+
+PNewAlbumDlg::PNewAlbumDlg(QWidget* const parent, const QString& toolName)
+ : WSNewAlbumDialog(parent, toolName)
+{
+ hideDateTime();
+ hideDesc();
+ hideLocation();
+ getMainWidget()->setMinimumSize(300, 0);
+}
+
+PNewAlbumDlg::~PNewAlbumDlg()
+{
+}
+
+void PNewAlbumDlg::getFolderTitle(PFolder& folder)
+{
+ folder.title = getTitleEdit()->text();
+}
+
+} // namespace Digikam
diff --git a/core/utilities/assistants/webservices/pinterest/pnewalbumdlg.h \
b/core/utilities/assistants/webservices/pinterest/pnewalbumdlg.h new file mode 100644
index 0000000000..a195a37a16
--- /dev/null
+++ b/core/utilities/assistants/webservices/pinterest/pnewalbumdlg.h
@@ -0,0 +1,50 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2018-05-20
+ * Description : a tool to export images to Onedrive web service
+ *
+ * Copyright (C) 2013 by Pankaj Kumar <me at panks dot me>
+ * Copyright (C) 2013-2018 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+
+#ifndef P_NEW_ALBUM_DLG_H
+#define P_NEW_ALBUM_DLG_H
+
+// Local includes
+
+#include "wsnewalbumdialog.h"
+
+namespace Digikam
+{
+
+class PFolder;
+
+class PNewAlbumDlg : public WSNewAlbumDialog
+{
+ Q_OBJECT
+
+public:
+
+ explicit PNewAlbumDlg(QWidget* const parent, const QString& toolName);
+ ~PNewAlbumDlg();
+
+ void getFolderTitle(PFolder& folder);
+};
+
+} // namespace Digikam
+
+#endif // P_NEW_ALBUM_DLG_H
diff --git a/core/utilities/assistants/webservices/pinterest/ptalker.cpp \
b/core/utilities/assistants/webservices/pinterest/ptalker.cpp new file mode 100644
index 0000000000..44488d5859
--- /dev/null
+++ b/core/utilities/assistants/webservices/pinterest/ptalker.cpp
@@ -0,0 +1,561 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2018-05-20
+ * Description : a tool to export images to Onedrive web service
+ *
+ * Copyright (C) 2013 by Pankaj Kumar <me at panks dot me>
+ * Copyright (C) 2013-2018 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+#include <ptalker.h>
+#include "digikam_config.h"
+
+// Qt includes
+
+#include <QJsonDocument>
+#include <QJsonParseError>
+#include <QJsonObject>
+#include <QJsonValue>
+#include <QJsonArray>
+#include <QByteArray>
+#include <QList>
+#include <QPair>
+#include <QFileInfo>
+#include <QWidget>
+#include <QMessageBox>
+#include <QApplication>
+#include <QDesktopServices>
+#include <QUrlQuery>
+#include <QHttpMultiPart>
+
+
+// Local includes
+
+#include "digikam_debug.h"
+#include "digikam_version.h"
+#include "wstoolutils.h"
+#include "pwindow.h"
+#include "pitem.h"
+#include "pmpform.h"
+#include "previewloadthread.h"
+
+#ifdef HAVE_QWEBENGINE
+# include "webwidget_qwebengine.h"
+#else
+# include "webwidget.h"
+#endif
+
+namespace Digikam
+{
+
+class PTalker::Private
+{
+public:
+
+ enum State
+ {
+ P_USERNAME = 0,
+ P_LISTBOARDS,
+ P_CREATEBOARD,
+ P_ADDPIN,
+ P_ACCESSTOKEN
+ };
+
+public:
+
+ explicit Private()
+ {
+ clientId = QLatin1String("4982378732590216737");
+ clientSecret = \
QLatin1String("b18a848371ab898b4746c3d958d96b118810bcf06ae3ff48b7b7461dffa2f283"); +
+ authUrl = QLatin1String("https://api.pinterest.com/oauth/");
+ tokenUrl = \
QLatin1String("https://api.pinterest.com/v1/oauth/token"); + redirectUrl = \
QLatin1String("https://127.0.0.1:8000/"); +
+ scope = QLatin1String("read_public,write_public");
+
+ state = P_USERNAME;
+ netMngr = 0;
+ reply = 0;
+ accessToken = "";
+ }
+
+public:
+
+ QString clientId;
+ QString clientSecret;
+ QString authUrl;
+ QString tokenUrl;
+ QString redirectUrl;
+ QString accessToken;
+ QString scope;
+ QWidget* parent;
+
+ QNetworkAccessManager* netMngr;
+
+ QNetworkReply* reply;
+
+ State state;
+
+ QByteArray buffer;
+
+ DMetadata meta;
+
+ QMap<QString,QString> urlParametersMap;
+
+ WebWidget* view;
+
+ QString userName;
+
+};
+PTalker::PTalker(QWidget* const parent)
+ : d(new Private)
+{
+ d->parent = parent;
+ d->netMngr = new QNetworkAccessManager(this);
+
+ connect(d->netMngr, SIGNAL(finished(QNetworkReply*)),
+ this, SLOT(slotFinished(QNetworkReply*)));
+
+ connect(this, SIGNAL(pinterestLinkingFailed()),
+ this, SLOT(slotLinkingFailed()));
+
+ connect(this, SIGNAL(pinterestLinkingSucceeded()),
+ this, SLOT(slotLinkingSucceeded()));
+
+}
+PTalker::~PTalker()
+{
+ if (d->reply)
+ {
+ d->reply->abort();
+ }
+ delete d;
+}
+void PTalker::link()
+{
+ emit signalBusy(true);
+ QUrl url(d->authUrl);
+ QUrlQuery query(url);
+ query.addQueryItem(QLatin1String("client_id"), d->clientId);
+ query.addQueryItem(QLatin1String("scope"), d->scope);
+ query.addQueryItem(QLatin1String("redirect_uri"), d->redirectUrl);
+ query.addQueryItem(QLatin1String("response_type"), "code");
+ url.setQuery(query);
+
+ d->view = new WebWidget(d->parent);
+ d->view->setWindowFlags(Qt::Dialog);
+ d->view->load(url);
+ d->view->show();
+
+ connect(d->view, SIGNAL(urlChanged(QUrl)), this, SLOT(slotCatchUrl(QUrl)));
+}
+void PTalker::unLink()
+{
+ d->accessToken = "";
+ #ifdef HAVE_QWEBENGINE
+ d->view->page()->profile()->cookieStore()->deleteAllCookies();
+ #else
+
+ #endif
+
+ Q_EMIT pinterestLinkingSucceeded();
+}
+void PTalker::slotOpenBrowser(const QUrl& url)
+{
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Open Browser..." << url;
+ QDesktopServices::openUrl(url);
+}
+void PTalker::slotCatchUrl(const QUrl& url)
+{
+ d->view->close();
+ d->urlParametersMap = ParseUrlParameters(url.toString());
+ QString code = d->urlParametersMap.value("code");
+
+ QUrl url2(d->tokenUrl);
+ QUrlQuery query(url2);
+ query.addQueryItem(QLatin1String("grant_type"), "authorization_code");
+ query.addQueryItem(QLatin1String("client_id"), d->clientId);
+ query.addQueryItem(QLatin1String("client_secret"), d->clientSecret);
+ query.addQueryItem(QLatin1String("code"), code);
+ url2.setQuery(query);
+
+ QNetworkRequest netRequest(url2);
+ netRequest.setHeader(QNetworkRequest::ContentTypeHeader, \
"application/x-www-form-urlencoded"); + netRequest.setRawHeader("Accept", \
"application/json"); +
+ d->reply = d->netMngr->post(netRequest,QByteArray());
+
+ d->state = Private::P_ACCESSTOKEN;
+ d->buffer.resize(0);
+ emit signalBusy(true);
+}
+
+QMap<QString,QString> PTalker::ParseUrlParameters(const QString &url)
+{
+ QMap<QString,QString> urlParameters;
+ if(url.indexOf('?')==-1)
+ {
+ return urlParameters;
+ }
+
+ QString tmp = url.right(url.length()-url.indexOf('?')-1);
+ QStringList paramlist = tmp.split('&');
+
+ for(int i=0;i<paramlist.count();i++)
+ {
+ QStringList paramarg = paramlist.at(i).split('=');
+ urlParameters.insert(paramarg.at(0),paramarg.at(1));
+ }
+
+ return urlParameters;
+}
+
+void PTalker::slotLinkingFailed()
+{
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "LINK to Pinterest fail";
+ emit signalBusy(false);
+}
+
+void PTalker::slotLinkingSucceeded()
+{
+ if (d->accessToken == "")
+ {
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "UNLINK to Pinterest ok";
+ emit signalBusy(false);
+ return;
+ }
+
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "LINK to Pinterest ok";
+ emit signalLinkingSucceeded();
+}
+
+bool PTalker::authenticated()
+{
+ if(d->accessToken != ""){
+ return true;
+ }else{
+ return false;
+ }
+}
+void PTalker::cancel()
+{
+ if (d->reply)
+ {
+ d->reply->abort();
+ d->reply = 0;
+ }
+
+ emit signalBusy(false);
+}
+void PTalker::createBoard(QString& boardName)
+{
+ QUrl url("https://api.pinterest.com/v1/boards/");
+ QNetworkRequest netRequest(url);
+ netRequest.setHeader(QNetworkRequest::ContentTypeHeader, \
QLatin1String("application/json")); + netRequest.setRawHeader("Authorization", \
QString::fromLatin1("Bearer %1").arg(d->accessToken).toUtf8()); +
+ QByteArray postData = QString::fromUtf8("{\"name\": \
\"%1\"}").arg(boardName).toUtf8(); + qCDebug(DIGIKAM_WEBSERVICES_LOG) << \
"createBoard:" << postData; + d->reply = d->netMngr->post(netRequest, postData);
+
+ d->state = Private::P_CREATEBOARD;
+ d->buffer.resize(0);
+ emit signalBusy(true);
+}
+void PTalker::getUserName()
+{
+ QUrl url(QLatin1String("https://api.pinterest.com/v1/me/?fields=username"));
+
+ QNetworkRequest netRequest(url);
+ netRequest.setRawHeader("Authorization", QString::fromLatin1("Bearer \
%1").arg(d->accessToken).toUtf8()); +
+ d->reply = d->netMngr->get(netRequest);
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "AFter Request Usar " << d->reply;
+ d->state = Private::P_USERNAME;
+ d->buffer.resize(0);
+ emit signalBusy(true);
+}
+
+/** Get list of boards by parsing json sent by pinterest
+ */
+void PTalker::listBoards(const QString& path)
+{
+ QUrl url(QLatin1String("https://api.pinterest.com/v1/me/boards/"));;
+
+ QNetworkRequest netRequest(url);
+ netRequest.setRawHeader("Authorization", QString::fromLatin1("Bearer \
%1").arg(d->accessToken).toUtf8()); +
+ d->reply = d->netMngr->get(netRequest);
+
+ d->state = Private::P_LISTBOARDS;
+ d->buffer.resize(0);
+ emit signalBusy(true);
+}
+
+bool PTalker::addPin(const QString& imgPath, const QString& uploadBoard, bool \
rescale, int maxDim, int imageQuality) +{
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "PATH " << imgPath;
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Board " << uploadBoard;
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Others: " << rescale << " " << maxDim << " \
" <<imageQuality; + if (d->reply)
+ {
+ d->reply->abort();
+ d->reply = 0;
+ }
+
+ emit signalBusy(true);
+
+ PMPForm form;
+ QImage image = PreviewLoadThread::loadHighQualitySynchronously(imgPath).copyQImage();
+
+ if (image.isNull())
+ {
+ return false;
+ }
+
+ QString path = WSToolUtils::makeTemporaryDir("pinterest").filePath(QFileInfo(imgPath)
+ .baseName().trimmed() + \
QLatin1String(".jpg")); +
+ if (rescale && (image.width() > maxDim || image.height() > maxDim))
+ {
+ image = image.scaled(maxDim,maxDim, \
Qt::KeepAspectRatio,Qt::SmoothTransformation); + }
+
+ image.save(path,"JPEG",imageQuality);
+
+ if (d->meta.load(imgPath))
+ {
+ d->meta.setImageDimensions(image.size());
+ d->meta.setImageOrientation(DMetadata::ORIENTATION_NORMAL);
+ d->meta.setImageProgramId(QLatin1String("digiKam"), digiKamVersion());
+ d->meta.setMetadataWritingMode((int)DMetadata::WRITETOIMAGEONLY);
+ d->meta.save(path);
+ }
+
+ QString boardparam = d->userName + "/" + uploadBoard;
+
+
+ if (!form.addFile(path))
+ {
+ emit signalBusy(false);
+ return false;
+ }
+
+ QUrl url(QString::fromLatin1("https://api.pinterest.com/v1/pins/?access_token=%1").arg(d->accessToken));
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "URL: " << url.toString();
+
+
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Board Name: " << uploadBoard << "UserName: \
" << d->userName; +
+
+ QHttpMultiPart * multipart = new QHttpMultiPart (QHttpMultiPart::FormDataType);
+
+ ///Board Section
+ QHttpPart board;
+ QString boardHeader = QString("form-data; name=\"board\"") ;
+ board.setHeader(QNetworkRequest::ContentDispositionHeader,boardHeader);
+
+ QByteArray postData = boardparam.toUtf8();
+ board.setBody(postData);
+ multipart->append(board);
+
+ ///Note section
+ QHttpPart note;
+ QString noteHeader = QString("form-data; name=\"note\"") ;
+ note.setHeader(QNetworkRequest::ContentDispositionHeader,noteHeader);
+
+ postData = "";
+
+ note.setBody(postData);
+ multipart->append(note);
+
+ ///image section
+ QFile* file = new QFile(imgPath);
+ file->open(QIODevice::ReadOnly);
+
+ QHttpPart imagepart;
+ QString imagepartHeader = QString::fromLatin1("form-data; name=\"image\"; \
filename=\"") + + QFileInfo(imgPath).fileName() + \
QString::fromLatin1("\"") ; +
+ imagepart.setHeader(QNetworkRequest::ContentDispositionHeader,imagepartHeader);
+ imagepart.setHeader(QNetworkRequest::ContentTypeHeader, \
QLatin1String("image/jpeg")); +
+ imagepart.setBodyDevice(file);
+ multipart->append(imagepart);
+
+
+
+ QString content = \
QString::fromLatin1("multipart/form-data;boundary=")+multipart->boundary(); + \
QNetworkRequest netRequest(url); + \
netRequest.setHeader(QNetworkRequest::ContentTypeHeader, content); +
+ d->reply = d->netMngr->post(netRequest, multipart);
+
+
+ d->state = Private::P_ADDPIN;
+ d->buffer.resize(0);
+ emit signalBusy(true);
+ return true;
+}
+void PTalker::slotFinished(QNetworkReply* reply)
+{
+ if (reply != d->reply)
+ {
+ return;
+ }
+
+ d->reply = 0;
+
+ if (reply->error() != QNetworkReply::NoError)
+ {
+ if (d->state != Private::P_CREATEBOARD)
+ {
+ emit signalBusy(false);
+ QMessageBox::critical(QApplication::activeWindow(),
+ i18n("Error"), reply->errorString());
+
+ //qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Error content: " << \
QString(reply->readAll()); + reply->deleteLater();
+ return;
+ }
+ }
+
+ d->buffer.append(reply->readAll());
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "BUFFER" << QString(d->buffer);
+ switch (d->state)
+ {
+ case Private::P_LISTBOARDS:
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "In P_LISTBOARDS";
+ parseResponseListBoards(d->buffer);
+ break;
+ case Private::P_CREATEBOARD:
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "In P_CREATEBOARD";
+ parseResponseCreateBoard(d->buffer);
+ break;
+ case Private::P_ADDPIN:
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "In P_ADDPIN";
+ parseResponseAddPin(d->buffer);
+ break;
+ case Private::P_USERNAME:
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "In P_USERNAME";
+ parseResponseUserName(d->buffer);
+ break;
+ case Private::P_ACCESSTOKEN:
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "In P_ACCESSTOKEN";
+ parseResponseAccessToken(d->buffer);
+ break;
+ default:
+ break;
+ }
+
+ reply->deleteLater();
+}
+void PTalker::parseResponseAccessToken(const QByteArray& data)
+{
+ QJsonDocument doc = QJsonDocument::fromJson(data);
+ QJsonObject jsonObject = doc.object();
+ d->accessToken = jsonObject[QLatin1String("access_token")].toString();
+ if(d->accessToken != ""){
+ Q_EMIT pinterestLinkingSucceeded();
+ }else{
+ Q_EMIT pinterestLinkingFailed();
+ }
+ emit signalBusy(false);
+}
+void PTalker::parseResponseAddPin(const QByteArray& data)
+{
+ QJsonDocument doc = QJsonDocument::fromJson(data);
+ QJsonObject jsonObject = doc.object()[QLatin1String("data")].toObject();
+ bool success = jsonObject.contains(QLatin1String("id"));
+ emit signalBusy(false);
+
+ if (!success)
+ {
+ emit signalAddPinFailed(i18n("Failed to upload Pin"));
+ }
+ else
+ {
+ emit signalAddPinSucceeded();
+ }
+}
+void PTalker::parseResponseUserName(const QByteArray& data)
+{
+ QJsonDocument doc = QJsonDocument::fromJson(data);
+ QJsonObject jsonObject = doc.object()[QLatin1String("data")].toObject();
+ QString name = jsonObject[QLatin1String("username")].toString();
+
+ emit signalBusy(false);
+ d->userName = name;
+ emit signalSetUserName(name);
+}
+
+void PTalker::parseResponseListBoards(const QByteArray& data)
+{
+ QJsonParseError err;
+ QJsonDocument doc = QJsonDocument::fromJson(data, &err);
+
+ if (err.error != QJsonParseError::NoError)
+ {
+ emit signalBusy(false);
+ emit signalListBoardsFailed(i18n("Failed to list boards"));
+ return;
+ }
+
+ QJsonObject jsonObject = doc.object();
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "Json Listing Boards : " << doc;
+ QJsonArray jsonArray = jsonObject[QLatin1String("data")].toArray();
+
+ QList<QPair<QString, QString> > list;
+ QString boardID;
+ QString boardName;
+
+ foreach (const QJsonValue& value, jsonArray)
+ {
+ QString boardID;
+ QString boardName;
+ QJsonObject obj = value.toObject();
+ boardID = obj[QLatin1String("id")].toString();
+ boardName = obj[QLatin1String("name")].toString();
+ list.append(qMakePair(boardID, boardName));
+ }
+
+ emit signalBusy(false);
+ emit signalListBoardsDone(list);
+}
+
+void PTalker::parseResponseCreateBoard(const QByteArray& data)
+{
+ QJsonDocument doc = QJsonDocument::fromJson(data);
+ QJsonObject jsonObject = doc.object();
+ bool fail = jsonObject.contains(QLatin1String("error"));
+
+ emit signalBusy(false);
+
+ if (fail)
+ {
+ QJsonParseError err;
+ QJsonDocument doc = QJsonDocument::fromJson(data, &err);
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "parseResponseCreateBoard ERROR: " << doc;
+ emit signalCreateBoardFailed(jsonObject[QLatin1String("error_summary")].toString());
+ }
+ else
+ {
+ emit signalCreateBoardSucceeded();
+ }
+}
+
+} // namespace Digikam
diff --git a/core/utilities/assistants/webservices/pinterest/ptalker.h \
b/core/utilities/assistants/webservices/pinterest/ptalker.h new file mode 100644
index 0000000000..acf7e22a10
--- /dev/null
+++ b/core/utilities/assistants/webservices/pinterest/ptalker.h
@@ -0,0 +1,105 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2018-05-20
+ * Description : a tool to export images to Onedrive web service
+ *
+ * Copyright (C) 2013 by Pankaj Kumar <me at panks dot me>
+ * Copyright (C) 2013-2018 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+
+#ifndef P_TALKER_H
+#define P_TALKER_H
+
+// Qt includes
+
+#include <QList>
+#include <QPair>
+#include <QString>
+#include <QSettings>
+#include <QNetworkReply>
+#include <QNetworkAccessManager>
+
+// Local includes
+
+#include "pitem.h"
+#include "dmetadata.h"
+
+namespace Digikam
+{
+
+class PTalker : public QObject
+{
+ Q_OBJECT
+
+public:
+
+ explicit PTalker(QWidget* const parent);
+ ~PTalker();
+
+public:
+
+ void link();
+ void unLink();
+ void getUserName();
+ bool authenticated();
+ void cancel();
+ bool addPin(const QString& imgPath, const QString& uploadFolder, bool rescale, \
int maxDim, int imageQuality); + void listBoards(const QString& path = QString());
+ void createBoard(QString& boardName);
+ void setAccessToken(const QString& token);
+ QMap<QString,QString> ParseUrlParameters(const QString& url);
+
+Q_SIGNALS:
+
+ void signalBusy(bool val);
+ void signalLinkingSucceeded();
+ void signalLinkingFailed();
+ void signalSetUserName(const QString& msg);
+ void signalListBoardsFailed(const QString& msg);
+ void signalListBoardsDone(const QList<QPair<QString, QString> >& list);
+ void signalCreateBoardFailed(const QString& msg);
+ void signalCreateBoardSucceeded();
+ void signalAddPinFailed(const QString& msg);
+ void signalAddPinSucceeded();
+ void pinterestLinkingSucceeded();
+ void pinterestLinkingFailed();
+
+private Q_SLOTS:
+
+ void slotLinkingFailed();
+ void slotLinkingSucceeded();
+ void slotCatchUrl(const QUrl& url);
+ void slotOpenBrowser(const QUrl& url);
+ void slotFinished(QNetworkReply* reply);
+
+private:
+
+ void parseResponseUserName(const QByteArray& data);
+ void parseResponseListBoards(const QByteArray& data);
+ void parseResponseCreateBoard(const QByteArray& data);
+ void parseResponseAddPin(const QByteArray& data);
+ void parseResponseAccessToken(const QByteArray& data);
+
+private:
+
+ class Private;
+ Private* const d;
+};
+
+} // namespace Digikam
+
+#endif // P_TALKER_H
diff --git a/core/utilities/assistants/webservices/pinterest/pwidget.cpp \
b/core/utilities/assistants/webservices/pinterest/pwidget.cpp new file mode 100644
index 0000000000..3376b409d6
--- /dev/null
+++ b/core/utilities/assistants/webservices/pinterest/pwidget.cpp
@@ -0,0 +1,70 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2018-05-20
+ * Description : a tool to export images to Onedrive web service
+ *
+ * Copyright (C) 2013 by Pankaj Kumar <me at panks dot me>
+ * Copyright (C) 2013-2018 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+ #include "pwidget.h"
+
+// Qt includes
+
+#include <QLabel>
+#include <QGroupBox>
+
+// Local includes
+
+namespace Digikam
+{
+
+PWidget::PWidget(QWidget* const parent,
+ DInfoInterface* const iface,
+ const QString& toolName)
+ : WSSettingsWidget(parent, iface, toolName)
+{
+ getUploadBox()->hide();
+ getSizeBox()->hide();
+}
+
+PWidget::~PWidget()
+{
+}
+
+void PWidget::updateLabels(const QString& name, const QString& url)
+{
+ QString web(QLatin1String("https://www.pinterest.com/"));
+
+ if (!url.isEmpty())
+ web = url;
+
+ getHeaderLbl()->setText(QString::fromLatin1(
+ "<b><h2><a href='%1'>"
+ "<font color=\"#9ACD32\">Pinterest</font>"
+ "</a></h2></b>").arg(web));
+
+ if (name.isEmpty())
+ {
+ getUserNameLabel()->clear();
+ }
+ else
+ {
+ getUserNameLabel()->setText(QString::fromLatin1("<b>%1</b>").arg(name));
+ }
+}
+
+} // namespace Digikam
diff --git a/core/utilities/assistants/webservices/pinterest/pwidget.h \
b/core/utilities/assistants/webservices/pinterest/pwidget.h new file mode 100644
index 0000000000..82af27ee78
--- /dev/null
+++ b/core/utilities/assistants/webservices/pinterest/pwidget.h
@@ -0,0 +1,62 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2018-05-20
+ * Description : a tool to export images to Onedrive web service
+ *
+ * Copyright (C) 2013 by Pankaj Kumar <me at panks dot me>
+ * Copyright (C) 2013-2018 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+
+#ifndef P_WIDGET_H
+#define P_WIDGET_H
+
+// Qt includes
+
+#include <QWidget>
+
+// Local includes
+
+#include "wssettingswidget.h"
+#include "pitem.h"
+#include "dinfointerface.h"
+
+class QButtonGroup;
+
+namespace Digikam
+{
+
+class PWidget : public WSSettingsWidget
+{
+ Q_OBJECT
+
+public:
+
+ explicit PWidget(QWidget* const parent,
+ DInfoInterface* const iface,
+ const QString& toolName);
+ ~PWidget();
+
+ void updateLabels(const QString& name = QString(),
+ const QString& url = QString()) Q_DECL_OVERRIDE;
+
+private:
+ friend class PWindow;
+};
+
+} // namespace Digikam
+
+#endif // P_WIDGET_H
diff --git a/core/utilities/assistants/webservices/pinterest/pwindow.cpp \
b/core/utilities/assistants/webservices/pinterest/pwindow.cpp new file mode 100644
index 0000000000..836f7165f0
--- /dev/null
+++ b/core/utilities/assistants/webservices/pinterest/pwindow.cpp
@@ -0,0 +1,465 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2018-05-20
+ * Description : a tool to export images to Onedrive web service
+ *
+ * Copyright (C) 2013 by Pankaj Kumar <me at panks dot me>
+ * Copyright (C) 2013-2018 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+
+#include "pwindow.h"
+
+// Qt includes
+
+#include <QWindow>
+#include <QSpinBox>
+#include <QCheckBox>
+#include <QMessageBox>
+#include <QCloseEvent>
+
+// KDE includes
+
+#include <klocalizedstring.h>
+#include <kconfig.h>
+#include <kwindowconfig.h>
+
+// Local includes
+
+#include "digikam_debug.h"
+#include "dimageslist.h"
+#include "digikam_version.h"
+#include "ptalker.h"
+#include "pitem.h"
+#include "pnewalbumdlg.h"
+#include "pwidget.h"
+
+namespace Digikam
+{
+
+class PWindow::Private
+{
+public:
+
+ explicit Private()
+ {
+ imagesCount = 0;
+ imagesTotal = 0;
+ widget = 0;
+ albumDlg = 0;
+ talker = 0;
+ }
+
+ unsigned int imagesCount;
+ unsigned int imagesTotal;
+
+ PWidget* widget;
+ PNewAlbumDlg* albumDlg;
+ PTalker* talker;
+
+ QString currentAlbumName;
+ QList<QUrl> transferQueue;
+};
+
+PWindow::PWindow(DInfoInterface* const iface,
+ QWidget* const /*parent*/)
+ : WSToolDialog(0),
+ d(new Private)
+{
+ d->widget = new PWidget(this, iface, QLatin1String("Pinterest"));
+
+ d->widget->imagesList()->setIface(iface);
+
+ setMainWidget(d->widget);
+ setModal(false);
+ setWindowTitle(i18n("Export to Pinterest"));
+
+ startButton()->setText(i18n("Start Upload"));
+ startButton()->setToolTip(i18n("Start upload to Pinterest"));
+
+ d->widget->setMinimumSize(700, 500);
+
+ connect(d->widget->imagesList(), SIGNAL(signalImageListChanged()),
+ this, SLOT(slotImageListChanged()));
+
+ connect(d->widget->getChangeUserBtn(), SIGNAL(clicked()),
+ this, SLOT(slotUserChangeRequest()));
+
+ connect(d->widget->getNewAlbmBtn(), SIGNAL(clicked()),
+ this, SLOT(slotNewBoardRequest()));
+
+ connect(d->widget->getReloadBtn(), SIGNAL(clicked()),
+ this, SLOT(slotReloadBoardsRequest()));
+
+ connect(startButton(), SIGNAL(clicked()),
+ this, SLOT(slotStartTransfer()));
+
+ d->albumDlg = new PNewAlbumDlg(this, QLatin1String("Pinterest"));
+ d->talker = new PTalker(this);
+
+ connect(d->talker,SIGNAL(signalBusy(bool)),
+ this,SLOT(slotBusy(bool)));
+
+ connect(d->talker,SIGNAL(signalLinkingFailed()),
+ this,SLOT(slotSignalLinkingFailed()));
+
+ connect(d->talker,SIGNAL(signalLinkingSucceeded()),
+ this,SLOT(slotSignalLinkingSucceeded()));
+
+ connect(d->talker,SIGNAL(signalSetUserName(QString)),
+ this,SLOT(slotSetUserName(QString)));
+
+ connect(d->talker,SIGNAL(signalListBoardsFailed(QString)),
+ this,SLOT(slotListBoardsFailed(QString)));
+
+ connect(d->talker,SIGNAL(signalListBoardsDone(QList<QPair<QString,QString> >)),
+ this,SLOT(slotListBoardsDone(QList<QPair<QString,QString> >)));
+
+ connect(d->talker,SIGNAL(signalCreateBoardFailed(QString)),
+ this,SLOT(slotCreateBoardFailed(QString)));
+
+ connect(d->talker,SIGNAL(signalCreateBoardSucceeded()),
+ this,SLOT(slotCreateBoardSucceeded()));
+
+ connect(d->talker,SIGNAL(signalAddPinFailed(QString)),
+ this,SLOT(slotAddPinFailed(QString)));
+
+ connect(d->talker,SIGNAL(signalAddPinSucceeded()),
+ this,SLOT(slotAddPinSucceeded()));
+
+ connect(this, SIGNAL(finished(int)),
+ this, SLOT(slotFinished()));
+
+ readSettings();
+ buttonStateChange(false);
+
+ d->talker->link();
+}
+
+PWindow::~PWindow()
+{
+ delete d->widget;
+ delete d->albumDlg;
+ delete d->talker;
+ delete d;
+}
+
+void PWindow::readSettings()
+{
+ KConfig config;
+ KConfigGroup grp = config.group("Pinterest Settings");
+ d->currentAlbumName = grp.readEntry("Current Album",QString());
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "readsettings:" << d->currentAlbumName;
+
+ if (grp.readEntry("Resize", false))
+ {
+ d->widget->getResizeCheckBox()->setChecked(true);
+ d->widget->getDimensionSpB()->setEnabled(true);
+ d->widget->getImgQualitySpB()->setEnabled(true);
+ }
+ else
+ {
+ d->widget->getResizeCheckBox()->setChecked(false);
+ d->widget->getDimensionSpB()->setEnabled(false);
+ d->widget->getImgQualitySpB()->setEnabled(false);
+ }
+
+ d->widget->getDimensionSpB()->setValue(grp.readEntry("Maximum Width", 1600));
+ d->widget->getImgQualitySpB()->setValue(grp.readEntry("Image Quality", 90));
+
+ KConfigGroup dialogGroup = config.group("Pinterest Export Dialog");
+
+ winId();
+ KWindowConfig::restoreWindowSize(windowHandle(), dialogGroup);
+ resize(windowHandle()->size());
+}
+
+void PWindow::writeSettings()
+{
+ KConfig config;
+ KConfigGroup grp = config.group("Pinterest Settings");
+
+ grp.writeEntry("Current Album", d->currentAlbumName);
+ grp.writeEntry("Resize", d->widget->getResizeCheckBox()->isChecked());
+ grp.writeEntry("Maximum Width", d->widget->getDimensionSpB()->value());
+ grp.writeEntry("Image Quality", d->widget->getImgQualitySpB()->value());
+
+ KConfigGroup dialogGroup = config.group("Pinterest Export Dialog");
+ KWindowConfig::saveWindowSize(windowHandle(), dialogGroup);
+
+ config.sync();
+}
+
+void PWindow::reactivate()
+{
+ d->widget->imagesList()->loadImagesFromCurrentSelection();
+ d->widget->progressBar()->hide();
+
+ show();
+}
+
+void PWindow::setItemsList(const QList<QUrl>& urls)
+{
+ d->widget->imagesList()->slotAddImages(urls);
+}
+
+void PWindow::slotBusy(bool val)
+{
+ if (val)
+ {
+ setCursor(Qt::WaitCursor);
+ d->widget->getChangeUserBtn()->setEnabled(false);
+ buttonStateChange(false);
+ }
+ else
+ {
+ setCursor(Qt::ArrowCursor);
+ d->widget->getChangeUserBtn()->setEnabled(true);
+ buttonStateChange(true);
+ }
+}
+
+void PWindow::slotSetUserName(const QString& msg)
+{
+ d->widget->updateLabels(msg, QLatin1String(""));
+}
+
+void PWindow::slotListBoardsDone(const QList<QPair<QString,QString> >& list)
+{
+ d->widget->getAlbumsCoB()->clear();
+ for (int i = 0 ; i < list.size() ; i++)
+ {
+ d->widget->getAlbumsCoB()->addItem(
+ QIcon::fromTheme(QLatin1String("system-users")),
+ list.value(i).second, list.value(i).second);
+ if (d->currentAlbumName == list.value(i).first)
+ {
+ d->widget->getAlbumsCoB()->setCurrentIndex(i);
+ }
+ }
+
+ buttonStateChange(true);
+ d->talker->getUserName();
+}
+
+void PWindow::slotStartTransfer()
+{
+ d->widget->imagesList()->clearProcessedStatus();
+
+ if (d->widget->imagesList()->imageUrls().isEmpty())
+ {
+ QMessageBox::critical(this, i18nc("@title:window", "Error"),
+ i18n("No image selected. Please select which images \
should be uploaded.")); + return;
+ }
+
+ if (!(d->talker->authenticated()))
+ {
+ QMessageBox warn(QMessageBox::Warning,
+ i18n("Warning"),
+ i18n("Authentication failed. Click \"Continue\" to \
authenticate."), + QMessageBox::Yes | QMessageBox::No);
+
+ (warn.button(QMessageBox::Yes))->setText(i18n("Continue"));
+ (warn.button(QMessageBox::No))->setText(i18n("Cancel"));
+
+ if (warn.exec() == QMessageBox::Yes)
+ {
+ d->talker->link();
+ return;
+ }
+ else
+ {
+ return;
+ }
+ }
+
+ d->transferQueue = d->widget->imagesList()->imageUrls();
+
+ if (d->transferQueue.isEmpty())
+ {
+ return;
+ }
+
+ d->currentAlbumName = \
d->widget->getAlbumsCoB()->itemData(d->widget->getAlbumsCoB()->currentIndex()).toString();
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "StartTransfer:" << d->currentAlbumName << \
"INDEX: " << d->widget->getAlbumsCoB()->currentIndex(); + d->imagesTotal = \
d->transferQueue.count(); + d->imagesCount = 0;
+
+ d->widget->progressBar()->setFormat(i18n("%v / %m"));
+ d->widget->progressBar()->setMaximum(d->imagesTotal);
+ d->widget->progressBar()->setValue(0);
+ d->widget->progressBar()->show();
+ d->widget->progressBar()->progressScheduled(i18n("Pinterest export"), true, \
true); + d->widget->progressBar()->progressThumbnailChanged(QIcon(QLatin1String("pinterest")).pixmap(22, \
22)); +
+ uploadNextPhoto();
+}
+
+void PWindow::uploadNextPhoto()
+{
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "uploadNextPhoto:" << \
d->transferQueue.count(); +
+ if (d->transferQueue.isEmpty())
+ {
+ qCDebug(DIGIKAM_WEBSERVICES_LOG) << "empty";
+ d->widget->progressBar()->progressCompleted();
+ return;
+ }
+
+ QString imgPath = d->transferQueue.first().toLocalFile();
+ QString temp = d->currentAlbumName;
+
+ bool result = d->talker->addPin(imgPath,
+ temp,
+ d->widget->getResizeCheckBox()->isChecked(),
+ d->widget->getDimensionSpB()->value(),
+ d->widget->getImgQualitySpB()->value());
+
+ if (!result)
+ {
+ slotAddPinFailed(QLatin1String(""));
+ return;
+ }
+}
+
+void PWindow::slotAddPinFailed(const QString& msg)
+{
+ if (QMessageBox::question(this, i18n("Uploading Failed"),
+ i18n("Failed to upload photo to Pinterest."
+ "\n%1\n"
+ "Do you want to continue?", msg))
+ != QMessageBox::Yes)
+ {
+ d->transferQueue.clear();
+ d->widget->progressBar()->hide();
+ }
+ else
+ {
+ d->transferQueue.pop_front();
+ d->imagesTotal--;
+ d->widget->progressBar()->setMaximum(d->imagesTotal);
+ d->widget->progressBar()->setValue(d->imagesCount);
+ uploadNextPhoto();
+ }
+}
+
+void PWindow::slotAddPinSucceeded()
+{
+ // Remove photo uploaded from the list
+ d->widget->imagesList()->removeItemByUrl(d->transferQueue.first());
+ d->transferQueue.pop_front();
+ d->imagesCount++;
+ d->widget->progressBar()->setMaximum(d->imagesTotal);
+ d->widget->progressBar()->setValue(d->imagesCount);
+ uploadNextPhoto();
+}
+
+void PWindow::slotImageListChanged()
+{
+ startButton()->setEnabled(!(d->widget->imagesList()->imageUrls().isEmpty()));
+}
+
+void PWindow::slotNewBoardRequest()
+{
+ if (d->albumDlg->exec() == QDialog::Accepted)
+ {
+ PFolder newFolder;
+ d->albumDlg->getFolderTitle(newFolder);
+ d->currentAlbumName = \
d->widget->getAlbumsCoB()->itemData(d->widget->getAlbumsCoB()->currentIndex()).toString();
+ QString temp = newFolder.title;
+ d->talker->createBoard(temp);
+ }
+}
+
+void PWindow::slotReloadBoardsRequest()
+{
+ d->talker->listBoards();
+}
+
+void PWindow::slotSignalLinkingFailed()
+{
+ slotSetUserName(QLatin1String(""));
+ d->widget->getAlbumsCoB()->clear();
+
+ if (QMessageBox::question(this, i18n("Login Failed"),
+ i18n("Authentication failed. Do you want to try \
again?")) + == QMessageBox::Yes)
+ {
+ d->talker->link();
+ }
+}
+
+void PWindow::slotSignalLinkingSucceeded()
+{
+ d->talker->listBoards();
+}
+
+void PWindow::slotListBoardsFailed(const QString& msg)
+{
+ QMessageBox::critical(this, QString(), i18n("Pinterest call failed:\n%1", msg));
+}
+
+void PWindow::slotCreateBoardFailed(const QString& msg)
+{
+ QMessageBox::critical(this, QString(), i18n("Pinterest call failed:\n%1", msg));
+}
+
+void PWindow::slotCreateBoardSucceeded()
+{
+ d->talker->listBoards();
+}
+
+void PWindow::slotTransferCancel()
+{
+ d->transferQueue.clear();
+ d->widget->progressBar()->hide();
+ d->talker->cancel();
+}
+
+void PWindow::slotUserChangeRequest()
+{
+ slotSetUserName(QLatin1String(""));
+ d->widget->getAlbumsCoB()->clear();
+ d->talker->unLink();
+ d->talker->link();
+}
+
+void PWindow::buttonStateChange(bool state)
+{
+ d->widget->getNewAlbmBtn()->setEnabled(state);
+ d->widget->getReloadBtn()->setEnabled(state);
+ startButton()->setEnabled(state);
+}
+
+void PWindow::slotFinished()
+{
+ writeSettings();
+ d->widget->imagesList()->listView()->clear();
+}
+
+void PWindow::closeEvent(QCloseEvent* e)
+{
+ if (!e)
+ {
+ return;
+ }
+
+ slotFinished();
+ e->accept();
+}
+
+} // namespace Digikam
diff --git a/core/utilities/assistants/webservices/pinterest/pwindow.h \
b/core/utilities/assistants/webservices/pinterest/pwindow.h new file mode 100644
index 0000000000..e6d08947ac
--- /dev/null
+++ b/core/utilities/assistants/webservices/pinterest/pwindow.h
@@ -0,0 +1,98 @@
+/* ============================================================
+ *
+ * This file is a part of digiKam project
+ * http://www.digikam.org
+ *
+ * Date : 2018-05-20
+ * Description : a tool to export images to Onedrive web service
+ *
+ * Copyright (C) 2013 by Pankaj Kumar <me at panks dot me>
+ * Copyright (C) 2013-2018 by Gilles Caulier <caulier dot gilles at gmail dot com>
+ *
+ * This program is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * ============================================================ */
+
+#ifndef P_WINDOW_H
+#define P_WINDOW_H
+
+// Qt includes
+
+#include <QList>
+#include <QUrl>
+#include <QPair>
+
+// Local includes
+
+#include "wstooldialog.h"
+#include "digikam_export.h"
+#include "dinfointerface.h"
+
+class QCloseEvent;
+class QUrl;
+
+namespace Digikam
+{
+
+class DIGIKAM_EXPORT PWindow : public WSToolDialog
+{
+ Q_OBJECT
+
+public:
+
+ explicit PWindow(DInfoInterface* const iface, QWidget* const parent);
+ ~PWindow();
+
+ void reactivate();
+
+ void setItemsList(const QList<QUrl>& urls);
+
+private:
+
+ void readSettings();
+ void writeSettings();
+
+ void uploadNextPhoto();
+
+ void buttonStateChange(bool state);
+ void closeEvent(QCloseEvent*) Q_DECL_OVERRIDE;
+
+private Q_SLOTS:
+
+ void slotImageListChanged();
+ void slotUserChangeRequest();
+ void slotNewBoardRequest();
+ void slotReloadBoardsRequest();
+ void slotStartTransfer();
+
+ void slotBusy(bool);
+ void slotSignalLinkingFailed();
+ void slotSignalLinkingSucceeded();
+ void slotSetUserName(const QString& msg);
+ void slotListBoardsFailed(const QString& msg);
+ void slotListBoardsDone(const QList<QPair<QString, QString> >& list);
+ void slotCreateBoardFailed(const QString& msg);
+ void slotCreateBoardSucceeded();
+ void slotAddPinFailed(const QString& msg);
+ void slotAddPinSucceeded();
+ void slotTransferCancel();
+
+ void slotFinished();
+
+private:
+
+ class Private;
+ Private* const d;
+};
+
+} // namespace Digikam
+
+#endif // P_WINDOW_H
diff --git a/core/utilities/imageeditor/main/imageeditorui5.rc \
b/core/utilities/imageeditor/main/imageeditorui5.rc index daac3aa403..92c614a1cd \
100644
--- a/core/utilities/imageeditor/main/imageeditorui5.rc
+++ b/core/utilities/imageeditor/main/imageeditorui5.rc
@@ -163,11 +163,10 @@
<Action name="export_googlephoto" />
<Action name="export_imageshack" />
<Action name="export_imgur" />
- <Action name="export_linkedin" />
<Action name="export_onedrive" />
+ <Action name="export_pinterest" />
<Action name="export_rajce" />
<Action name="export_smugmug" />
- <Action name="export_twitter" />
<Action name="export_yandexfotki" />
<Action name="export_mediawiki" />
<Action name="export_vkontakte" />
diff --git a/core/utilities/lighttable/lighttablewindowui5.rc \
b/core/utilities/lighttable/lighttablewindowui5.rc index cf2acf8d05..ea2589427e \
100644
--- a/core/utilities/lighttable/lighttablewindowui5.rc
+++ b/core/utilities/lighttable/lighttablewindowui5.rc
@@ -77,11 +77,10 @@
<Action name="export_googlephoto" />
<Action name="export_imageshack" />
<Action name="export_imgur" />
- <Action name="export_linkedin" />
<Action name="export_onedrive" />
+ <Action name="export_pinterest" />
<Action name="export_rajce" />
<Action name="export_smugmug" />
- <Action name="export_twitter" />
<Action name="export_yandexfotki" />
<Action name="export_mediawiki" />
<Action name="export_vkontakte" />
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic