From 0d325f827f5101f5d2bda38e308e2f95d7a594b6 Mon Sep 17 00:00:00 2001 From: Johan Smith Agudelo Rodriguez Date: Tue, 14 Feb 2017 23:54:41 -0500 Subject: [PATCH] fix #48, Support Alternatives from the Context Menu --- app/dockcorona.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++-- app/dockcorona.h | 11 ++++++--- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/app/dockcorona.cpp b/app/dockcorona.cpp index 1e884f6eb..faeb7b634 100644 --- a/app/dockcorona.cpp +++ b/app/dockcorona.cpp @@ -22,10 +22,12 @@ #include "dockview.h" #include "packageplugins/shell/dockpackage.h" #include "../liblattedock/windowsystem.h" +#include "alternativeshelper.h" #include #include #include +#include #include #include @@ -36,8 +38,7 @@ #include #include #include - -#include +#include namespace Latte { @@ -333,6 +334,9 @@ void DockCorona::addDock(Plasma::Containment *containment) connect(containment, &QObject::destroyed, this, &DockCorona::dockContainmentDestroyed); connect(containment, &Plasma::Applet::destroyedChanged, this, &DockCorona::destroyedChanged); connect(containment, &Plasma::Applet::locationChanged, this, &DockCorona::dockLocationChanged); + connect(containment, &Plasma::Containment::appletAlternativesRequested + , this, &DockCorona::showAlternativesForApplet, Qt::QueuedConnection); + dockView->show(); m_dockViews[containment] = dockView; emit docksCountChanged(); @@ -365,6 +369,58 @@ void DockCorona::dockContainmentDestroyed(QObject *cont) emit docksCountChanged(); } +void DockCorona::showAlternativesForApplet(Plasma::Applet *applet) +{ + const QString alternativesQML = kPackage().filePath("appletalternativesui"); + if (alternativesQML.isEmpty()) { + return; + } + + KDeclarative::QmlObject *qmlObj = new KDeclarative::QmlObject(this); + qmlObj->setInitializationDelayed(true); + qmlObj->setSource(QUrl::fromLocalFile(alternativesQML)); + + AlternativesHelper *helper = new AlternativesHelper(applet, qmlObj); + qmlObj->rootContext()->setContextProperty(QStringLiteral("alternativesHelper"), helper); + + m_alternativesObjects << qmlObj; + qmlObj->completeInitialization(); + connect(qmlObj->rootObject(), SIGNAL(visibleChanged(bool)), + this, SLOT(alternativesVisibilityChanged(bool))); + + connect(applet, &Plasma::Applet::destroyedChanged, this, [this, qmlObj] (bool destroyed) { + if (!destroyed) { + return; + } + QMutableListIterator it(m_alternativesObjects); + while (it.hasNext()) { + KDeclarative::QmlObject *obj = it.next(); + if (obj == qmlObj) { + it.remove(); + obj->deleteLater(); + } + } + }); +} + +void DockCorona::alternativesVisibilityChanged(bool visible) +{ + if (visible) { + return; + } + + QObject *root = sender(); + + QMutableListIterator it(m_alternativesObjects); + while (it.hasNext()) { + KDeclarative::QmlObject *obj = it.next(); + if (obj->rootObject() == root) { + it.remove(); + obj->deleteLater(); + } + } +} + void DockCorona::loadDefaultLayout() { qDebug() << "loading default layout"; diff --git a/app/dockcorona.h b/app/dockcorona.h index e0133cf77..9f0e800ec 100644 --- a/app/dockcorona.h +++ b/app/dockcorona.h @@ -18,14 +18,15 @@ * along with this program. If not, see . */ -#ifndef NOWDOCKCORONA_H -#define NOWDOCKCORONA_H +#ifndef DOCKCORONA_H +#define DOCKCORONA_H #include "dockview.h" #include #include +#include namespace Plasma { class Corona; @@ -74,6 +75,8 @@ signals: private slots: void destroyedChanged(bool destroyed); + void showAlternativesForApplet(Plasma::Applet *applet); + void alternativesVisibilityChanged(bool visible); void load(); private: @@ -86,8 +89,10 @@ private: bool m_activitiesStarting{true}; QStringList m_debugFlags; + QHash m_dockViews; QHash m_waitingDockViews; + QList m_alternativesObjects; KActivities::Consumer *m_activityConsumer; QPointer aboutDialog; @@ -95,4 +100,4 @@ private: } -#endif +#endif // DOCKCORONA_H