parent
938f89cfed
commit
afb5d34a28
4 changed files with 1 additions and 165 deletions
@ -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…
Reference in new issue