diff --git a/components/shellprivate/CMakeLists.txt b/components/shellprivate/CMakeLists.txt --- a/components/shellprivate/CMakeLists.txt +++ b/components/shellprivate/CMakeLists.txt @@ -12,6 +12,7 @@ widgetexplorer/kcategorizeditemsviewmodels.cpp widgetexplorer/plasmaappletitemmodel.cpp widgetexplorer/openwidgetassistant.cpp + widgetexplorer/widgetexplorerassistant.cpp widgetexplorer/widgetexplorer.cpp shellprivateplugin.cpp ${interactiveconsole_SRCS} diff --git a/components/shellprivate/shellprivateplugin.cpp b/components/shellprivate/shellprivateplugin.cpp --- a/components/shellprivate/shellprivateplugin.cpp +++ b/components/shellprivate/shellprivateplugin.cpp @@ -27,6 +27,7 @@ #include "wallpaperplugin/wallpaperplugin.h" #include "widgetexplorer/widgetexplorer.h" +#include "widgetexplorer/widgetexplorerassistant.h" #include #if KF5TextEditor_FOUND @@ -40,6 +41,7 @@ qmlRegisterType(); qmlRegisterType(uri, 2, 0, "WallpaperPlugin"); qmlRegisterType(uri, 2, 0, "WidgetExplorer"); + qmlRegisterType(uri, 2, 0, "WidgetExplorerAssistant"); #if KF5TextEditor_FOUND qmlRegisterType(uri, 2, 0, "InteractiveConsoleWindow"); #endif diff --git a/components/shellprivate/widgetexplorer/widgetexplorer.h b/components/shellprivate/widgetexplorer/widgetexplorer.h --- a/components/shellprivate/widgetexplorer/widgetexplorer.h +++ b/components/shellprivate/widgetexplorer/widgetexplorer.h @@ -35,6 +35,7 @@ class Applet; } class WidgetExplorerPrivate; +class WidgetExplorerAssistant; //We need to access the separator property that is not exported by QAction class WidgetAction : public QAction @@ -95,6 +96,12 @@ Q_PROPERTY(Plasma::Containment *containment READ containment WRITE setContainment NOTIFY containmentChanged) public: + enum class WidgetSource { + Network, + Filesystem + }; + Q_ENUM(WidgetSource) + explicit WidgetExplorer(QObject *parent = nullptr); ~WidgetExplorer() override; @@ -142,6 +149,10 @@ */ Q_INVOKABLE void uninstall(const QString &pluginName); + //external assistant to open and to keep widget dialogs + //if we want to use it then it should be set before first getNewWidgets dialog is opened + Q_INVOKABLE void setExternalAssistant(WidgetExplorerAssistant *assistant); + void classBegin() override; void componentComplete() override; @@ -159,8 +170,6 @@ * Adds currently selected applets */ void addApplet(const QString &pluginName); - void openWidgetFile(); - void downloadWidgets(); Q_SIGNALS: void showSpecialFiltersChanged() const; @@ -168,6 +177,9 @@ protected Q_SLOTS: void immutabilityChanged(Plasma::Types::ImmutabilityType); +protected: + void openWidgetDialog(WidgetExplorer::WidgetSource source); + private: Q_PRIVATE_SLOT(d, void appletAdded(Plasma::Applet*)) Q_PRIVATE_SLOT(d, void appletRemoved(Plasma::Applet*)) @@ -177,5 +189,4 @@ friend class WidgetExplorerPrivate; }; - #endif // WIDGETEXPLORER_H diff --git a/components/shellprivate/widgetexplorer/widgetexplorer.cpp b/components/shellprivate/widgetexplorer/widgetexplorer.cpp --- a/components/shellprivate/widgetexplorer/widgetexplorer.cpp +++ b/components/shellprivate/widgetexplorer/widgetexplorer.cpp @@ -28,8 +28,6 @@ #include #include -#include -#include #include #include @@ -43,9 +41,9 @@ #include #include +#include "widgetexplorerassistant.h" #include "kcategorizeditemsviewmodels_p.h" #include "plasmaappletitemmodel_p.h" -#include "openwidgetassistant_p.h" #include "config-workspace.h" using namespace KActivities; @@ -101,14 +99,14 @@ QHash runningApplets; // applet name => count //extra hash so we can look up the names of deleted applets QHash appletNames; - QPointer openAssistant; KPackage::Package *package; PlasmaAppletItemModel itemModel; KCategorizedItemsViewModels::DefaultFilterModel filterModel; bool showSpecialFilters = true; DefaultItemFilterProxyModel filterItemModel; - QPointer newStuffDialog; + + QPointer assistant; QScopedPointer activitiesConsumer; }; @@ -214,7 +212,7 @@ if (KAuthorized::authorize(QStringLiteral("ghns"))) { action = new WidgetAction(QIcon::fromTheme(QStringLiteral("internet-services")), i18n("Download New Plasma Widgets"), this); - connect(action, &QAction::triggered, this, &WidgetExplorer::downloadWidgets); + connect(action, &QAction::triggered, [this] { openWidgetDialog(WidgetSource::Network); }); actionList << action; } @@ -224,7 +222,7 @@ action = new WidgetAction(QIcon::fromTheme(QStringLiteral("package-x-generic")), i18n("Install Widget From Local File..."), this); - QObject::connect(action, &QAction::triggered, this, &WidgetExplorer::openWidgetFile); + QObject::connect(action, &QAction::triggered, [this] { openWidgetDialog(WidgetSource::Filesystem); }); actionList << action; return actionList; @@ -438,35 +436,18 @@ } } - - -void WidgetExplorer::downloadWidgets() +void WidgetExplorer::setExternalAssistant(WidgetExplorerAssistant *assistant) { - if (!d->newStuffDialog) { - d->newStuffDialog = new KNS3::DownloadDialog(QLatin1String("plasmoids.knsrc")); - d->newStuffDialog.data()->setWindowTitle(i18n("Download New Plasma Widgets")); - d->newStuffDialog.data()->setAttribute(Qt::WA_DeleteOnClose); - } - d->newStuffDialog.data()->show(); - - emit shouldClose(); + d->assistant = assistant; } -void WidgetExplorer::openWidgetFile() +void WidgetExplorer::openWidgetDialog(WidgetExplorer::WidgetSource source) { - - Plasma::OpenWidgetAssistant *assistant = d->openAssistant.data(); - if (!assistant) { - assistant = new Plasma::OpenWidgetAssistant(nullptr); - d->openAssistant = assistant; + if (d->assistant.isNull()) { + d->assistant = new WidgetExplorerAssistant(this); } - KWindowSystem::setOnDesktop(assistant->winId(), KWindowSystem::currentDesktop()); - assistant->setAttribute(Qt::WA_DeleteOnClose, true); - assistant->show(); - assistant->raise(); - assistant->setFocus(); - + d->assistant->openWidgetDialog(source); emit shouldClose(); } diff --git a/components/shellprivate/widgetexplorer/widgetexplorerassistant.h b/components/shellprivate/widgetexplorer/widgetexplorerassistant.h new file mode 100644 --- /dev/null +++ b/components/shellprivate/widgetexplorer/widgetexplorerassistant.h @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2020 by Anton Parshukov + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#ifndef WIDGETEXPLORERASSISTANT_H +#define WIDGETEXPLORERASSISTANT_H + +#include + +#include "widgetexplorer.h" + +class WidgetExplorerAssistantPrivate; + +//keeper of getNewWidgets' dialogs +class WidgetExplorerAssistant : public QObject +{ + Q_OBJECT + +public: + explicit WidgetExplorerAssistant(QObject *parent = nullptr); + ~WidgetExplorerAssistant() override; + +public Q_SLOTS: + void openWidgetDialog(WidgetExplorer::WidgetSource source); + +private: + WidgetExplorerAssistantPrivate * const d; + friend class WidgetExplorerAssistantPrivate; +}; + +#endif // WIDGETEXPLORER_H diff --git a/components/shellprivate/widgetexplorer/widgetexplorerassistant.cpp b/components/shellprivate/widgetexplorer/widgetexplorerassistant.cpp new file mode 100644 --- /dev/null +++ b/components/shellprivate/widgetexplorer/widgetexplorerassistant.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2020 by Anton Parshukov + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "widgetexplorerassistant.h" + +#include +#include +#include + +#include "openwidgetassistant_p.h" + +class WidgetExplorerAssistantPrivate +{ + +public: + WidgetExplorerAssistantPrivate(WidgetExplorerAssistant *w) + : q(w) + { + } + + WidgetExplorerAssistant *q; + QMap > dialogs; +}; + +WidgetExplorerAssistant::WidgetExplorerAssistant(QObject *parent) + : QObject(parent), + d(new WidgetExplorerAssistantPrivate(this)) +{ +} + +WidgetExplorerAssistant::~WidgetExplorerAssistant() +{ + delete d; +} + +void WidgetExplorerAssistant::openWidgetDialog(WidgetExplorer::WidgetSource source) +{ + auto &dialog = d->dialogs[source]; + if (dialog.isNull()) { + switch (source) { + case WidgetExplorer::WidgetSource::Network: + dialog = new KNS3::DownloadDialog(QLatin1String("plasmoids.knsrc")); + dialog->setWindowTitle(i18n("Download New Plasma Widgets")); + break; + + case WidgetExplorer::WidgetSource::Filesystem: + dialog = new Plasma::OpenWidgetAssistant(nullptr); + break; + } + + dialog->setAttribute(Qt::WA_DeleteOnClose); + } + + KWindowSystem::setOnDesktop(dialog->winId(), KWindowSystem::currentDesktop()); + + if (dialog->isMinimized()) { + dialog->showNormal(); + } + else { + dialog->show(); + } + dialog->raise(); + KWindowSystem::forceActiveWindow(dialog->winId()); +} + +#include "moc_widgetexplorerassistant.cpp"