1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-01-08 13:18:09 +03:00

fix #48, Support Alternatives from the Context Menu

This commit is contained in:
Johan Smith Agudelo Rodriguez 2017-02-14 23:54:41 -05:00
parent dd12817a24
commit 0d325f827f
2 changed files with 66 additions and 5 deletions

View File

@ -22,10 +22,12 @@
#include "dockview.h"
#include "packageplugins/shell/dockpackage.h"
#include "../liblattedock/windowsystem.h"
#include "alternativeshelper.h"
#include <QAction>
#include <QScreen>
#include <QDebug>
#include <QQmlContext>
#include <Plasma>
#include <Plasma/Corona>
@ -36,8 +38,7 @@
#include <KPackage/Package>
#include <KPackage/PackageLoader>
#include <KAboutData>
#include <kactivities/consumer.h>
#include <KActivities/Consumer>
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<KDeclarative::QmlObject *> 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<KDeclarative::QmlObject *> 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";

View File

@ -18,14 +18,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NOWDOCKCORONA_H
#define NOWDOCKCORONA_H
#ifndef DOCKCORONA_H
#define DOCKCORONA_H
#include "dockview.h"
#include <QObject>
#include <KAboutApplicationDialog>
#include <KDeclarative/QmlObject>
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<const Plasma::Containment *, DockView *> m_dockViews;
QHash<const Plasma::Containment *, DockView *> m_waitingDockViews;
QList<KDeclarative::QmlObject *> m_alternativesObjects;
KActivities::Consumer *m_activityConsumer;
QPointer<KAboutApplicationDialog> aboutDialog;
@ -95,4 +100,4 @@ private:
}
#endif
#endif // DOCKCORONA_H