From kde-commits Thu Sep 27 05:58:27 2018 From: Laurent Montel Date: Thu, 27 Sep 2018 05:58:27 +0000 To: kde-commits Subject: [pim-sieve-editor] /: Use pimcommon purpose menu widget Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=153804512818323 Git commit 442f36edb322928b9f85b24714df5c3240243e32 by Laurent Montel. Committed on 27/09/2018 at 05:58. Pushed by mlaurent into branch 'master'. Use pimcommon purpose menu widget M +0 -10 CMakeLists.txt M +0 -1 config-sieveeditor.h.cmake M +1 -4 src/CMakeLists.txt M +12 -55 src/sieveeditormainwindow.cpp M +0 -10 src/sieveeditormainwindow.h A +44 -0 src/sievepurposemenuwidget.cpp [License: LGPL (v2+)] A +38 -0 src/sievepurposemenuwidget.h [License: LGPL (v2+)] https://commits.kde.org/pim-sieve-editor/442f36edb322928b9f85b24714df5c3240= 243e32 diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fd6047..c632ec2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,16 +61,6 @@ find_package(KF5Crash ${KF5_VERSION} REQUIRED) find_package(KF5Bookmarks ${KF5_VERSION} REQUIRED) find_package(KF5IconThemes ${KF5_VERSION} REQUIRED) find_package(KF5KIO ${KF5_VERSION} REQUIRED) -find_package(KF5Purpose CONFIG QUIET) -set_package_properties(KF5Purpose PROPERTIES DESCRIPTION "Support for shar= ing file" - TYPE OPTIONAL - ) -if (KF5Purpose_FOUND) - message(STATUS "Found KF5 Purpose, filesharing enabled") - set(KF5_USE_PURPOSE true) -else() - message(STATUS "KF5 Purpose not found, filesharing disabled") -endif() = # Find KdepimLibs Package find_package(KF5PimTextEdit ${KPIMTEXTEDIT_LIB_VERSION} CONFIG REQUIRED) diff --git a/config-sieveeditor.h.cmake b/config-sieveeditor.h.cmake index de85784..8b13789 100644 --- a/config-sieveeditor.h.cmake +++ b/config-sieveeditor.h.cmake @@ -1,2 +1 @@ -#cmakedefine KF5_USE_PURPOSE 1 = diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d74a6de..8102f7d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -40,6 +40,7 @@ set(sieveeditor_LIB_SRCS sieveeditorconfigureserverpage.cpp sieveeditorbookmarks.cpp sieveeditoremptytabwidgetlabel.cpp + sievepurposemenuwidget.cpp ${sieveeditor_importimapsettings_SRCS} ${sieveeditor_importimapsettings_check_SRCS} ) @@ -70,10 +71,6 @@ target_link_libraries(libsieveeditor KF5::KManageSieve ) = -if (KF5_USE_PURPOSE) - target_link_libraries(libsieveeditor PRIVATE KF5::Purpose KF5::Purpose= Widgets) -endif() - set_target_properties(libsieveeditor PROPERTIES OUTPUT_NAME sieveeditor VERSION ${KDEPIM_LIB_VERSION} SOVER= SION ${KDEPIM_LIB_SOVERSION} ) diff --git a/src/sieveeditormainwindow.cpp b/src/sieveeditormainwindow.cpp index b92d812..94046a3 100644 --- a/src/sieveeditormainwindow.cpp +++ b/src/sieveeditormainwindow.cpp @@ -25,6 +25,7 @@ #include "sieveserversettings.h" #include "sieveeditorcentralwidget.h" #include "sieveeditorglobalconfig.h" +#include "sievepurposemenuwidget.h" #include "sieveeditorbookmarks.h" #include "importwizard/importimapsettingwizard.h" #include "PimCommon/KActionMenuChangeCase" @@ -35,12 +36,6 @@ #include #include = -#ifdef KF5_USE_PURPOSE -#include -#include -#include -#endif - #include #include #include @@ -82,9 +77,6 @@ SieveEditorMainWindow::SieveEditorMainWindow(QWidget *par= ent) = SieveEditorMainWindow::~SieveEditorMainWindow() { -#ifdef KF5_USE_PURPOSE - delete mTemporaryShareFile; -#endif KSharedConfig::Ptr config =3D KSharedConfig::openConfig(); KConfigGroup group =3D config->group(QStringLiteral("SieveEditorMainWi= ndow")); group.writeEntry("Size", size()); @@ -193,16 +185,17 @@ void SieveEditorMainWindow::setupActions() ac->addAction(QStringLiteral("import_script"), mImportAction); mImportAction->setEnabled(false); = -#ifdef KF5_USE_PURPOSE - mShareAction =3D new QAction(i18n("Share..."), this); - ac->addAction(QStringLiteral("share_script"), mShareAction); - mShareMenu =3D new Purpose::Menu(this); - mShareMenu->model()->setPluginType(QStringLiteral("Export")); - connect(mShareMenu, &Purpose::Menu::aboutToShow, this, &SieveEditorMai= nWindow::slotInitializeShareMenu); - mShareAction->setMenu(mShareMenu); - mShareAction->setIcon( QIcon::fromTheme(QStringLiteral("document-share= "))); - connect(mShareMenu, &Purpose::Menu::finished, this, &SieveEditorMainWi= ndow::slotShareActionFinished); -#endif + SievePurposeMenuWidget *purposeMenu =3D new SievePurposeMenuWidget(thi= s, this); + if (purposeMenu->menu()) { + mShareAction =3D new QAction(i18n("Share..."), this); + ac->addAction(QStringLiteral("share_script"), mShareAction); + mShareAction->setMenu(purposeMenu->menu()); + mShareAction->setIcon(QIcon::fromTheme(QStringLiteral("document-sh= are"))); + purposeMenu->setEditorWidget(mMainWidget->sieveEditorMainWidget()); + } else { + delete purposeMenu; + } + mShareHotNewStuffAction =3D new QAction(i18n("Share Script..."), this); connect(mShareHotNewStuffAction, &QAction::triggered, mMainWidget->sie= veEditorMainWidget(), &SieveEditorMainWidget::slotShareScript); ac->addAction(QStringLiteral("share_hot_new_stuff_script"), mShareHotN= ewStuffAction); @@ -277,42 +270,6 @@ void SieveEditorMainWindow::setupActions() connect(act, &QAction::triggered, this, &SieveEditorMainWindow::slotIm= portImapSettings); } = -void SieveEditorMainWindow::slotInitializeShareMenu() -{ -#ifdef KF5_USE_PURPOSE - delete mTemporaryShareFile; - mTemporaryShareFile =3D new QTemporaryFile(); - mTemporaryShareFile->open(); - mTemporaryShareFile->setPermissions(QFile::ReadUser); - mTemporaryShareFile->write(mMainWidget->sieveEditorMainWidget()->curre= ntText().toUtf8()); - mTemporaryShareFile->close(); - mShareMenu->model()->setInputData(QJsonObject { - { QStringLiteral("urls"), QJsonArray { {QUrl::fromLocalFile(mTempo= raryShareFile->fileName()).toString()} } }, - { QStringLiteral("mimeType"), { QStringLiteral("text/plain") } } - }); - mShareMenu->reload(); -#endif -} - -void SieveEditorMainWindow::slotShareActionFinished(const QJsonObject &out= put, int error, const QString &message) -{ -#ifdef KF5_USE_PURPOSE - if (error) { - KMessageBox::error(this, i18n("There was a problem sharing the doc= ument: %1", message), - i18n("Share")); - } else { - const QString url =3D output[QLatin1String("url")].toString(); - if (url.isEmpty()) { - KMessageBox::information(this, i18n("File was shared.")); - } else { - KMessageBox::information(this, i18n("You can find the new = request at:
%1
", url), - QString(), QString(), KMessageBox::AllowLink); - } - } -#endif -} - - void SieveEditorMainWindow::slotImportImapSettings() { QPointer w =3D new ImportImapSettingWizard(th= is); diff --git a/src/sieveeditormainwindow.h b/src/sieveeditormainwindow.h index b5e454a..c108193 100644 --- a/src/sieveeditormainwindow.h +++ b/src/sieveeditormainwindow.h @@ -21,7 +21,6 @@ #define SIEVEEDITORMAINWINDOW_H = #include -#include "config-sieveeditor.h" #include "libsieveeditor_export.h" class QAction; class SieveEditorCentralWidget; @@ -32,9 +31,6 @@ class QTemporaryFile; namespace PimCommon { class KActionMenuChangeCase; } -namespace Purpose { -class Menu; -} class LIBSIEVEEDITOR_EXPORT SieveEditorMainWindow : public KXmlGuiWindow { Q_OBJECT @@ -69,8 +65,6 @@ private: void initStatusBar(); void readConfig(); void setupActions(); - void slotShareActionFinished(const QJsonObject &output, int error, con= st QString &message); - void slotInitializeShareMenu(); QString currentText() const; = SieveEditorCentralWidget *mMainWidget =3D nullptr; @@ -110,10 +104,6 @@ private: QLabel *mStatusBarInfo =3D nullptr; SieveEditorBookmarks *mSieveEditorBookmarks =3D nullptr; KActionMenu *mBookmarkMenu =3D nullptr; -#ifdef KF5_USE_PURPOSE - Purpose::Menu *mShareMenu =3D nullptr; - QTemporaryFile *mTemporaryShareFile =3D nullptr; -#endif bool mNetworkIsDown =3D false; }; = diff --git a/src/sievepurposemenuwidget.cpp b/src/sievepurposemenuwidget.cpp new file mode 100644 index 0000000..63011d7 --- /dev/null +++ b/src/sievepurposemenuwidget.cpp @@ -0,0 +1,44 @@ +/* + Copyright (C) 2018 Laurent Montel + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public Licen= se + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#include "sievepurposemenuwidget.h" +#include "sieveeditormainwidget.h" +#include + +SievePurposeMenuWidget::SievePurposeMenuWidget(QWidget *parentWidget, QObj= ect *parent) + : PimCommon::PurposeMenuWidget(parentWidget, parent) +{ + +} + +SievePurposeMenuWidget::~SievePurposeMenuWidget() +{ +} + +QByteArray SievePurposeMenuWidget::text() +{ + if (mSieveEditorWidget) { + return mSieveEditorWidget->currentText().toUtf8(); + } + return {}; +} + +void SievePurposeMenuWidget::setEditorWidget(SieveEditorMainWidget *editor) +{ + mSieveEditorWidget =3D editor; +} diff --git a/src/sievepurposemenuwidget.h b/src/sievepurposemenuwidget.h new file mode 100644 index 0000000..184eb3c --- /dev/null +++ b/src/sievepurposemenuwidget.h @@ -0,0 +1,38 @@ +/* + Copyright (C) 2018 Laurent Montel + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public Licen= se + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SIEVEPURPOSEMENUWIDGET_H +#define SIEVEPURPOSEMENUWIDGET_H + +#include +class SieveEditorMainWidget; +class SievePurposeMenuWidget : public PimCommon::PurposeMenuWidget +{ + Q_OBJECT +public: + explicit SievePurposeMenuWidget(QWidget *parentWidget, QObject *parent= =3D nullptr); + ~SievePurposeMenuWidget() override; + + QByteArray text() override; + void setEditorWidget(SieveEditorMainWidget *editor); +private: + SieveEditorMainWidget *mSieveEditorWidget =3D nullptr; +}; + +#endif // SIEVEPURPOSEMENUWIDGET_H