diff --git a/Plugins/PurposeMenu.cpp b/Plugins/PurposeMenu.cpp
index a157aef2..9d61dfa6 100644
--- a/Plugins/PurposeMenu.cpp
+++ b/Plugins/PurposeMenu.cpp
@@ -1,97 +1,97 @@
/* Copyright (C) 2019 The KPhotoAlbum Development Team
*
* 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 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e. V. (or its successor approved
* by the membership of KDE e. V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include "PurposeMenu.h"
#include "Logging.h"
#include
#include
#include
#include
#include
#include
#include
Plugins::PurposeMenu::PurposeMenu(QMenu *parent)
: QObject(parent)
, m_parentMenu(parent)
, m_purposeMenu(new Purpose::Menu(parent))
, m_menuUpdateNeeded(true)
{
loadPurposeMenu();
}
void Plugins::PurposeMenu::slotSelectionChanged()
{
m_menuUpdateNeeded = true;
m_purposeMenu->clear();
qCDebug(PluginsLog) << "Purpose menu items invalidated...";
}
void Plugins::PurposeMenu::loadPurposeMenu()
{
// attach the menu
QAction *purposeMenu = m_parentMenu->addMenu(m_purposeMenu);
purposeMenu->setText(i18n("Share"));
purposeMenu->setIcon(QIcon::fromTheme(QStringLiteral("document-share")));
// set up the callback signal
connect(m_purposeMenu, &Purpose::Menu::finished, this, [this](const QJsonObject &output, int error, const QString &message) {
if (error) {
qCDebug(PluginsLog) << "Failed to share image:" << message;
emit imageSharingFailed(message);
} else {
- auto filename = DB::FileName::fromAbsolutePath(output[QStringLiteral("url")].toString());
- qCDebug(PluginsLog) << "Image shared successfully: " << filename.relative();
- qCDebug(PluginsLog) << "Raw url: " << output[QStringLiteral("url")].toString();
+ // Note: most plugins don't seem to actually return anything in the url field...
+ const QUrl returnUrl = QUrl(output[QStringLiteral("url")].toString(), QUrl::ParsingMode::StrictMode);
+ qCDebug(PluginsLog) << "Image shared successfully.";
qCDebug(PluginsLog) << "Raw json data: " << output;
- emit imageShared(filename);
+ emit imageShared(returnUrl);
}
});
// update available options based on the latest picture
connect(m_purposeMenu, &QMenu::aboutToShow, this, &PurposeMenu::loadPurposeItems);
qCDebug(PluginsLog) << "Purpose menu loaded...";
}
void Plugins::PurposeMenu::loadPurposeItems()
{
if (!m_menuUpdateNeeded) {
return;
}
m_menuUpdateNeeded = false;
const DB::FileNameList images = MainWindow::Window::theMainWindow()->selected(ThumbnailView::NoExpandCollapsedStacks);
QJsonArray urls;
for (const auto &image : images)
{
urls.append(QUrl(image).toString());
}
// "image/jpeg" is certainly not always true, but the interface does not allow a mimeType list
// and the plugins likely won't care...
m_purposeMenu->model()->setInputData(QJsonObject {
{ QStringLiteral("mimeType"), QStringLiteral("image/jpeg") },
{ QStringLiteral("urls"), urls }
});
m_purposeMenu->model()->setPluginType(QStringLiteral("Export"));
m_purposeMenu->reload();
qCDebug(PluginsLog) << "Purpose menu items loaded...";
}
diff --git a/Plugins/PurposeMenu.h b/Plugins/PurposeMenu.h
index c3159060..bc3e2ea3 100644
--- a/Plugins/PurposeMenu.h
+++ b/Plugins/PurposeMenu.h
@@ -1,71 +1,76 @@
/* Copyright (C) 2019 The KPhotoAlbum Development Team
*
* 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 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e. V. (or its successor approved
* by the membership of KDE e. V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef KPHOTOALBUM_PURPOSEMENU_H
#define KPHOTOALBUM_PURPOSEMENU_H
#include
-#include
#include
#include
+#include
class QMenu;
namespace Purpose {
class Menu;
}
namespace Plugins
{
class PurposeMenu: public QObject
{
Q_OBJECT
public:
explicit PurposeMenu( QMenu *parent);
public slots:
void slotSelectionChanged();
signals:
- void imageShared(DB::FileName);
+ /**
+ * @brief imageShared is emitted when an image was shared successfully.
+ * The url contains the optional location of the shared data
+ * (e.g. for plugins that upload to a remote location).
+ */
+ void imageShared(QUrl);
void imageSharingFailed(QString message);
private:
QMenu *m_parentMenu;
Purpose::Menu *m_purposeMenu;
bool m_menuUpdateNeeded; ///< Keeps track of changed image selection
/**
* @brief Load the Purpose::Menu, add it to the parent menu, and set up connections.
*/
void loadPurposeMenu();
/**
* @brief Load Purpose menu items into the Purpose::Menu.
* This is dependent on the current set of images.
*/
void loadPurposeItems();
};
}
#endif /* PURPOSEMENU_H */
// vi:expandtab:tabstop=4 shiftwidth=4: