Remove here

wilder
Laurent Montel 8 years ago
parent 938f89cfed
commit afb5d34a28
  1. 14
      CMakeLists.txt
  2. 5
      src/CMakeLists.txt
  3. 95
      src/widgets/purposemenuwidget.cpp
  4. 52
      src/widgets/purposemenuwidget.h

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.0)
set(PIM_VERSION "5.9.42")
set(PIM_VERSION "5.9.43")
project(mailcommon VERSION ${PIM_VERSION})
@ -77,18 +77,6 @@ ecm_setup_version(PROJECT VARIABLE_PREFIX MAILCOMMON
SOVERSION 5
)
find_package(KF5Purpose CONFIG QUIET)
set_package_properties(KF5Purpose PROPERTIES DESCRIPTION "Support for sharing file"
TYPE OPTIONAL
)
if (KF5Purpose_FOUND)
message(STATUS "Found KF5 Purpose, filesharing enabled")
set(KF5_USE_PURPOSE true)
add_definitions(-DKF5_USE_PURPOSE)
else()
message(STATUS "KF5 Purpose not found, filesharing disabled")
endif()
find_package(Xsltproc)
set_package_properties(Xsltproc PROPERTIES DESCRIPTION "XSLT processor from libxslt" TYPE REQUIRED PURPOSE "Required to generate D-Bus interfaces for all Akonadi resources.")

@ -156,7 +156,6 @@ set(libmailcommon_widget_SRCS
widgets/redirectdialog.cpp
widgets/redirectwidget.cpp
widgets/favoritecollectionwidget.cpp
widgets/purposemenuwidget.cpp
)
set(libmailcommon_mdn_SRCS
@ -249,9 +248,6 @@ PRIVATE
KF5::SyntaxHighlighting
)
if (KF5_USE_PURPOSE)
target_link_libraries(KF5MailCommon PRIVATE KF5::Purpose KF5::PurposeWidgets)
endif()
target_include_directories(KF5MailCommon INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR_KF5}/MailCommon/;${KDE_INSTALL_INCLUDEDIR_KF5}/mailcommon>")
target_include_directories(KF5MailCommon PUBLIC "$<BUILD_INTERFACE:${mailcommon_SOURCE_DIR}/src;${mailcommon_BINARY_DIR}/src;${mailcommon_SOURCE_DIR}/src/search;${mailcommon_SOURCE_DIR}/src/folder>")
@ -429,7 +425,6 @@ ecm_generate_headers(MailCommon_Camelcasewidgets_HEADERS
HEADER_NAMES
RedirectDialog
FavoriteCollectionWidget
PurposeMenuWidget
REQUIRED_HEADERS MailCommon_widgets_HEADERS
PREFIX MailCommon
RELATIVE widgets

@ -1,95 +0,0 @@
/*
Copyright (c) 2018 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "purposemenuwidget.h"
#ifdef KF5_USE_PURPOSE
#include <Purpose/AlternativesModel>
#include <PurposeWidgets/Menu>
#include <QJsonArray>
#include <QTemporaryFile>
#include <KMessageBox>
#include <KLocalizedString>
#include <QUrl>
#endif
using namespace MailCommon;
PurposeMenuWidget::PurposeMenuWidget(QWidget *parentWidget, QObject *parent)
: QObject(parent),
mParentWidget(parentWidget)
{
#ifdef KF5_USE_PURPOSE
mShareMenu = new Purpose::Menu(mParentWidget);
mShareMenu->model()->setPluginType(QStringLiteral("Export"));
connect(mShareMenu, &Purpose::Menu::aboutToShow, this, &PurposeMenuWidget::slotInitializeShareMenu);
connect(mShareMenu, &Purpose::Menu::finished, this, &PurposeMenuWidget::slotShareActionFinished);
#endif
}
PurposeMenuWidget::~PurposeMenuWidget()
{
#ifdef KF5_USE_PURPOSE
delete mTemporaryShareFile;
#endif
}
QMenu *PurposeMenuWidget::menu() const
{
#ifdef KF5_USE_PURPOSE
return mShareMenu;
#else
return nullptr;
#endif
}
void PurposeMenuWidget::slotInitializeShareMenu()
{
#ifdef KF5_USE_PURPOSE
delete mTemporaryShareFile;
mTemporaryShareFile = new QTemporaryFile();
mTemporaryShareFile->open();
mTemporaryShareFile->setPermissions(QFile::ReadUser);
mTemporaryShareFile->write(text());
mTemporaryShareFile->close();
mShareMenu->model()->setInputData(QJsonObject {
{ QStringLiteral("urls"), QJsonArray { {QUrl::fromLocalFile(mTemporaryShareFile->fileName()).toString()} } },
{ QStringLiteral("mimeType"), { QStringLiteral("text/plain") } }
});
mShareMenu->reload();
#endif
}
void PurposeMenuWidget::slotShareActionFinished(const QJsonObject &output, int error, const QString &message)
{
#ifdef KF5_USE_PURPOSE
if (error) {
KMessageBox::error(mParentWidget, i18n("There was a problem sharing the document: %1", message),
i18n("Share"));
} else {
const QString url = output[QLatin1String("url")].toString();
if (url.isEmpty()) {
KMessageBox::information(mParentWidget, i18n("File was shared."));
} else {
KMessageBox::information(mParentWidget, i18n("<qt>You can find the new request at:<br /><a href='%1'>%1</a> </qt>", url),
QString(), QString(), KMessageBox::AllowLink);
}
}
#endif
}

@ -1,52 +0,0 @@
/*
Copyright (c) 2018 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef PURPOSEMENUWIDGET_H
#define PURPOSEMENUWIDGET_H
#include <QObject>
#include "mailcommon_export.h"
#ifdef KF5_USE_PURPOSE
namespace Purpose {
class Menu;
}
#endif
class QMenu;
class QTemporaryFile;
namespace MailCommon
{
class MAILCOMMON_EXPORT PurposeMenuWidget : public QObject
{
Q_OBJECT
public:
explicit PurposeMenuWidget(QWidget *parentWidget, QObject *parent = nullptr);
~PurposeMenuWidget() override;
virtual QByteArray text() = 0;
QMenu *menu() const;
private:
void slotInitializeShareMenu();
void slotShareActionFinished(const QJsonObject &output, int error, const QString &message);
#ifdef KF5_USE_PURPOSE
Purpose::Menu *mShareMenu = nullptr;
QTemporaryFile *mTemporaryShareFile = nullptr;
#endif
QWidget *mParentWidget = nullptr;
};
}
#endif // PURPOSEMENUWIDGET_H
Loading…
Cancel
Save