diff --git a/DB/FileName.cpp b/DB/FileName.cpp index d0469951..29c73b1c 100644 --- a/DB/FileName.cpp +++ b/DB/FileName.cpp @@ -1,103 +1,108 @@ /* Copyright 2012 Jesper K. Pedersen 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 "FileName.h" #include "ImageDB.h" #include #include #include #include DB::FileName::FileName() : m_isNull(true) { } DB::FileName DB::FileName::fromAbsolutePath(const QString &fileName) { const QString imageRoot = Utilities::stripEndingForwardSlash( Settings::SettingsData::instance()->imageDirectory() ) + QLatin1String("/"); if (!fileName.startsWith(imageRoot)) return FileName(); FileName res; res.m_isNull = false; res.m_absoluteFilePath = fileName; res.m_relativePath = fileName.mid(imageRoot.length()); return res; } DB::FileName DB::FileName::fromRelativePath(const QString &fileName) { Q_ASSERT(!fileName.startsWith(QChar::fromLatin1('/'))); FileName res; res.m_isNull = false; res.m_relativePath = fileName; res.m_absoluteFilePath = Utilities::stripEndingForwardSlash( Settings::SettingsData::instance()->imageDirectory() ) + QLatin1String("/") + fileName; return res; } QString DB::FileName::absolute() const { Q_ASSERT(!isNull()); return m_absoluteFilePath; } QString DB::FileName::relative() const { Q_ASSERT(!m_isNull); return m_relativePath; } bool DB::FileName::isNull() const { return m_isNull; } bool DB::FileName::operator ==(const DB::FileName &other) const { return m_isNull == other.m_isNull && m_relativePath == other.m_relativePath; } bool DB::FileName::operator !=(const DB::FileName &other) const { return !(*this == other); } bool DB::FileName::operator <(const DB::FileName &other) const { return relative() < other.relative(); } bool DB::FileName::exists() const { return QFile::exists(absolute()); } DB::ImageInfoPtr DB::FileName::info() const { return ImageDB::instance()->info(*this); } +DB::FileName::operator QUrl() const +{ + return QUrl::fromLocalFile(absolute()); +} + uint DB::qHash( const DB::FileName& fileName ) { return qHash(fileName.relative()); } // vi:expandtab:tabstop=4 shiftwidth=4: diff --git a/DB/FileName.h b/DB/FileName.h index 5ade91c9..09fd3724 100644 --- a/DB/FileName.h +++ b/DB/FileName.h @@ -1,62 +1,68 @@ /* Copyright 2012 Jesper K. Pedersen 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 FILENAME_H #define FILENAME_H #include #include +#include #include "ImageInfoPtr.h" #include namespace DB { class FileName { public: FileName(); static FileName fromAbsolutePath( const QString& fileName ); static FileName fromRelativePath( const QString& fileName ); QString absolute() const; QString relative() const; bool isNull() const; bool operator==( const FileName& other ) const; bool operator!=( const FileName& other ) const; bool operator<( const FileName& other ) const; bool exists() const; ImageInfoPtr info() const; + /** + * @brief Conversion to absolute local file url. + */ + explicit operator QUrl() const; + private: // During previous profilation it showed that converting between absolute and relative took quite some time, // so to avoid that, I store both. QString m_relativePath; QString m_absoluteFilePath; bool m_isNull; }; uint qHash( const DB::FileName& fileName ); typedef QSet FileNameSet; } Q_DECLARE_METATYPE(DB::FileName) #endif // FILENAME_H // vi:expandtab:tabstop=4 shiftwidth=4: diff --git a/Plugins/PurposeMenu.cpp b/Plugins/PurposeMenu.cpp index 91a42d4e..a157aef2 100644 --- a/Plugins/PurposeMenu.cpp +++ b/Plugins/PurposeMenu.cpp @@ -1,91 +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(); qCDebug(PluginsLog) << "Raw json data: " << output; emit imageShared(filename); } }); // 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"), QJsonArray::fromStringList(images.toStringList(DB::AbsolutePath)) } + { QStringLiteral("urls"), urls } }); m_purposeMenu->model()->setPluginType(QStringLiteral("Export")); m_purposeMenu->reload(); qCDebug(PluginsLog) << "Purpose menu items loaded..."; }