From 1ca43ee13f42fa1e77350b821f97a6e55a774775 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Wed, 13 Jan 2021 22:53:55 +0200 Subject: [PATCH] use Launchers Ability for syncing --move internal synced launchers infrastructure in order to use Launchers Ability. Things this way will become much cleaner and at the same reusable and maintainable --- app/layouts/launcherssignals.cpp | 232 +++++++----------- app/layouts/launcherssignals.h | 14 +- .../contents/ui/abilities/Launchers.qml | 74 ++++++ .../package/contents/ui/applet/AppletItem.qml | 1 + .../ui/applet/communicator/LatteBridge.qml | 1 + containment/package/contents/ui/main.qml | 6 + plasmoid/package/contents/ui/ContextMenu.qml | 3 +- .../contents/ui/TasksExtendedManager.qml | 6 +- .../contents/ui/abilities/Launchers.qml | 98 +++++--- .../ui/abilities/launchers/Syncer.qml | 91 +++++++ plasmoid/package/contents/ui/main.qml | 140 +---------- .../contents/ui/taskslayout/MouseHandler.qml | 4 +- 12 files changed, 347 insertions(+), 323 deletions(-) create mode 100644 containment/package/contents/ui/abilities/Launchers.qml diff --git a/app/layouts/launcherssignals.cpp b/app/layouts/launcherssignals.cpp index 7d7009622..1cda151ea 100644 --- a/app/layouts/launcherssignals.cpp +++ b/app/layouts/launcherssignals.cpp @@ -48,30 +48,52 @@ LaunchersSignals::~LaunchersSignals() { } -QList LaunchersSignals::lattePlasmoids(QString layoutName) +void LaunchersSignals::addAbilityClient(QQuickItem *client) { - QList applets; - - CentralLayout *layout = m_manager->synchronizer()->centralLayout(layoutName); - QList containments; - - if (layoutName.isEmpty()) { - containments = m_manager->corona()->containments(); - } else if (layout) { - containments = *(layout->containments()); + if (m_clients.contains(client)) { + return; } - for(const auto containment : containments) { - for(auto *applet : containment->applets()) { - KPluginMetaData meta = applet->kPackage().metadata(); + m_clients << client; - if (meta.pluginId() == "org.kde.latte.plasmoid") { - applets.append(applet); + connect(client, &QObject::destroyed, this, &LaunchersSignals::removeClientObject); +} + +void LaunchersSignals::removeAbilityClient(QQuickItem *client) +{ + if (!m_clients.contains(client)) { + return; + } + + disconnect(client, &QObject::destroyed, this, &LaunchersSignals::removeClientObject); + m_clients.removeAll(client); +} + +void LaunchersSignals::removeClientObject(QObject *obj) +{ + QQuickItem *item = qobject_cast(obj); + + if (item) { + removeAbilityClient(item); + } +} + +QList LaunchersSignals::clients(QString layoutName) +{ + QList items; + + if (!layoutName.isEmpty()) { + for(const auto client: m_clients) { + QString cLayoutName = client->property("layoutName").toString(); + if (cLayoutName == layoutName) { + items << client; } } + } else { + items = m_clients; } - return applets; + return items; } void LaunchersSignals::addLauncher(QString layoutName, int launcherGroup, QString launcher) @@ -84,26 +106,17 @@ void LaunchersSignals::addLauncher(QString layoutName, int launcherGroup, QStrin QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; - for(const auto applet : lattePlasmoids(lName)) { - if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value()) { - const auto &childItems = appletInterface->childItems(); + for(const auto client : clients(lName)) { + if (auto *metaObject = client->metaObject()) { + int methodIndex = metaObject->indexOfMethod("addSyncedLauncher(QVariant,QVariant)"); - if (childItems.isEmpty()) { + if (methodIndex == -1) { + qDebug() << "Launchers Syncer Ability: addSyncedLauncher(QVariant,QVariant) was NOT found..."; continue; } - for (QQuickItem *item : childItems) { - if (auto *metaObject = item->metaObject()) { - int methodIndex = metaObject->indexOfMethod("extSignalAddLauncher(QVariant,QVariant)"); - - if (methodIndex == -1) { - continue; - } - - QMetaMethod method = metaObject->method(methodIndex); - method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher)); - } - } + QMetaMethod method = metaObject->method(methodIndex); + method.invoke(client, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher)); } } } @@ -118,26 +131,17 @@ void LaunchersSignals::removeLauncher(QString layoutName, int launcherGroup, QSt QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; - for(const auto applet : lattePlasmoids(lName)) { - if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value()) { - const auto &childItems = appletInterface->childItems(); + for(const auto client : clients(lName)) { + if (auto *metaObject = client->metaObject()) { + int methodIndex = metaObject->indexOfMethod("removeSyncedLauncher(QVariant,QVariant)"); - if (childItems.isEmpty()) { + if (methodIndex == -1) { + qDebug() << "Launchers Syncer Ability: removeSyncedLauncher(QVariant,QVariant) was NOT found..."; continue; } - for (QQuickItem *item : childItems) { - if (auto *metaObject = item->metaObject()) { - int methodIndex = metaObject->indexOfMethod("extSignalRemoveLauncher(QVariant,QVariant)"); - - if (methodIndex == -1) { - continue; - } - - QMetaMethod method = metaObject->method(methodIndex); - method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher)); - } - } + QMetaMethod method = metaObject->method(methodIndex); + method.invoke(client, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher)); } } } @@ -152,26 +156,17 @@ void LaunchersSignals::addLauncherToActivity(QString layoutName, int launcherGro QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; - for(const auto applet : lattePlasmoids(lName)) { - if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value()) { - const auto &childItems = appletInterface->childItems(); + for(const auto client : clients(lName)) { + if (auto *metaObject = client->metaObject()) { + int methodIndex = metaObject->indexOfMethod("addSyncedLauncherToActivity(QVariant,QVariant,QVariant)"); - if (childItems.isEmpty()) { + if (methodIndex == -1) { + qDebug() << "Launchers Syncer Ability: addSyncedLauncherToActivity(QVariant,QVariant,QVariant) was NOT found..."; continue; } - for (QQuickItem *item : childItems) { - if (auto *metaObject = item->metaObject()) { - int methodIndex = metaObject->indexOfMethod("extSignalAddLauncherToActivity(QVariant,QVariant,QVariant)"); - - if (methodIndex == -1) { - continue; - } - - QMetaMethod method = metaObject->method(methodIndex); - method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher), Q_ARG(QVariant, activity)); - } - } + QMetaMethod method = metaObject->method(methodIndex); + method.invoke(client, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher), Q_ARG(QVariant, activity)); } } } @@ -186,26 +181,17 @@ void LaunchersSignals::removeLauncherFromActivity(QString layoutName, int launch QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; - for(const auto applet : lattePlasmoids(lName)) { - if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value()) { - const auto &childItems = appletInterface->childItems(); + for(const auto client : clients(lName)) { + if (auto *metaObject = client->metaObject()) { + int methodIndex = metaObject->indexOfMethod("removeSyncedLauncherFromActivity(QVariant,QVariant,QVariant)"); - if (childItems.isEmpty()) { + if (methodIndex == -1) { + qDebug() << "Launchers Syncer Ability: removeSyncedLauncherFromActivity(QVariant,QVariant,QVariant) was NOT found..."; continue; } - for (QQuickItem *item : childItems) { - if (auto *metaObject = item->metaObject()) { - int methodIndex = metaObject->indexOfMethod("extSignalRemoveLauncherFromActivity(QVariant,QVariant,QVariant)"); - - if (methodIndex == -1) { - continue; - } - - QMetaMethod method = metaObject->method(methodIndex); - method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher), Q_ARG(QVariant, activity)); - } - } + QMetaMethod method = metaObject->method(methodIndex); + method.invoke(client, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher), Q_ARG(QVariant, activity)); } } } @@ -220,62 +206,17 @@ void LaunchersSignals::urlsDropped(QString layoutName, int launcherGroup, QStrin QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; - for(const auto applet : lattePlasmoids(lName)) { - if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value()) { - const auto &childItems = appletInterface->childItems(); + for(const auto client : clients(lName)) { + if (auto *metaObject = client->metaObject()) { + int methodIndex = metaObject->indexOfMethod("dropSyncedUrls(QVariant,QVariant)"); - if (childItems.isEmpty()) { + if (methodIndex == -1) { + qDebug() << "Launchers Syncer Ability: dropSyncedUrls(QVariant,QVariant) was NOT found..."; continue; } - for (QQuickItem *item : childItems) { - if (auto *metaObject = item->metaObject()) { - int methodIndex = metaObject->indexOfMethod("extSignalUrlsDropped(QVariant,QVariant)"); - - if (methodIndex == -1) { - continue; - } - - QMetaMethod method = metaObject->method(methodIndex); - method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, urls)); - } - } - } - } -} - -void LaunchersSignals::moveTask(QString layoutName, uint senderId, int launcherGroup, int from, int to) -{ - Types::LaunchersGroup group = static_cast(launcherGroup); - - if ((Types::LaunchersGroup)group == Types::UniqueLaunchers) { - return; - } - - QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; - - for(const auto applet : lattePlasmoids(lName)) { - if (applet->id() != senderId) { - if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value()) { - const auto &childItems = appletInterface->childItems(); - - if (childItems.isEmpty()) { - continue; - } - - for (QQuickItem *item : childItems) { - if (auto *metaObject = item->metaObject()) { - int methodIndex = metaObject->indexOfMethod("extSignalMoveTask(QVariant,QVariant,QVariant)"); - - if (methodIndex == -1) { - continue; - } - - QMetaMethod method = metaObject->method(methodIndex); - method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, from), Q_ARG(QVariant, to)); - } - } - } + QMetaMethod method = metaObject->method(methodIndex); + method.invoke(client, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, urls)); } } } @@ -290,27 +231,20 @@ void LaunchersSignals::validateLaunchersOrder(QString layoutName, uint senderId, QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; - for(const auto applet : lattePlasmoids(lName)) { - if (applet->id() != senderId) { - if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value()) { - const auto &childItems = appletInterface->childItems(); + for(const auto client : clients(lName)) { + uint clientId = client->property("clientId").toUInt(); - if (childItems.isEmpty()) { + if (clientId != senderId) { + if (auto *metaObject = client->metaObject()) { + int methodIndex = metaObject->indexOfMethod("validateSyncedLaunchersOrder(QVariant,QVariant)"); + + if (methodIndex == -1) { + qDebug() << "Launchers Syncer Ability: validateSyncedLaunchersOrder(QVariant,QVariant) was NOT found..."; continue; } - for (QQuickItem *item : childItems) { - if (auto *metaObject = item->metaObject()) { - int methodIndex = metaObject->indexOfMethod("extSignalValidateLaunchersOrder(QVariant,QVariant)"); - - if (methodIndex == -1) { - continue; - } - - QMetaMethod method = metaObject->method(methodIndex); - method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launchers)); - } - } + QMetaMethod method = metaObject->method(methodIndex); + method.invoke(client, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launchers)); } } } diff --git a/app/layouts/launcherssignals.h b/app/layouts/launcherssignals.h index 07b8953e2..d5ab41336 100644 --- a/app/layouts/launcherssignals.h +++ b/app/layouts/launcherssignals.h @@ -22,7 +22,9 @@ #define LAUNCHERSSIGNALS_H // Qt +#include #include +#include namespace Plasma { class Applet; @@ -52,20 +54,26 @@ public: ~LaunchersSignals() override; public slots: + Q_INVOKABLE void addAbilityClient(QQuickItem *client); + Q_INVOKABLE void removeAbilityClient(QQuickItem *client); + Q_INVOKABLE void addLauncher(QString layoutName, int launcherGroup, QString launcher); Q_INVOKABLE void removeLauncher(QString layoutName, int launcherGroup, QString launcher); Q_INVOKABLE void addLauncherToActivity(QString layoutName, int launcherGroup, QString launcher, QString activity); Q_INVOKABLE void removeLauncherFromActivity(QString layoutName, int launcherGroup, QString launcher, QString activity); Q_INVOKABLE void urlsDropped(QString layoutName, int launcherGroup, QStringList urls); - //!Deprecated because it could create crashes, validateLaunchersOrder provides a better approach - Q_INVOKABLE void moveTask(QString layoutName, uint senderId, int launcherGroup, int from, int to); Q_INVOKABLE void validateLaunchersOrder(QString layoutName, uint senderId, int launcherGroup, QStringList launchers); private: - QList lattePlasmoids(QString layoutName); + QList clients(QString layoutName = QString()); + +private slots: + void removeClientObject(QObject *obj); private: Layouts::Manager *m_manager{nullptr}; + + QList m_clients; }; } diff --git a/containment/package/contents/ui/abilities/Launchers.qml b/containment/package/contents/ui/abilities/Launchers.qml new file mode 100644 index 000000000..5778f77d7 --- /dev/null +++ b/containment/package/contents/ui/abilities/Launchers.qml @@ -0,0 +1,74 @@ +/* +* Copyright 2021 Michail Vourlakos +* +* This file is part of Latte-Dock +* +* Latte-Dock is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* Latte-Dock 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, see . +*/ + +import QtQuick 2.7 +import org.kde.plasma.plasmoid 2.0 + +Item { + readonly property bool isReady: root.layoutsManager !== null + + property string layoutName: "" + + function addAbilityClient(client) { + layoutsManager.launchersSignals.addAbilityClient(client); + } + + function removeAbilityClient(client) { + layoutsManager.launchersSignals.removeAbilityClient(client); + } + + function addSyncedLauncher(group, launcherUrl) { + layoutsManager.launchersSignals.addLauncher(layoutName, + group, + launcherUrl); + } + + function removeSyncedLauncher(group, launcherUrl) { + layoutsManager.launchersSignals.removeLauncher(layoutName, + group, + launcherUrl); + } + + function addSyncedLauncherToActivity(group, launcherUrl, activityId) { + layoutsManager.launchersSignals.addLauncherToActivity(layoutName, + group, + launcherUrl, + activityId); + } + + function removeSyncedLauncherFromActivity(group, launcherUrl, activityId) { + layoutsManager.launchersSignals.removeLauncherFromActivity(layoutName, + group, + launcherUrl, + activityId); + } + + function addDroppedLaunchers(group, urls) { + layoutsManager.launchersSignals.urlsDropped(layoutName, + group, + urls); + } + + function validateSyncedLaunchersOrder(senderId, group, orderedlaunchers) { + layoutsManager.launchersSignals.validateLaunchersOrder(layoutName, + senderId, + group, + orderedlaunchers); + } +} diff --git a/containment/package/contents/ui/applet/AppletItem.qml b/containment/package/contents/ui/applet/AppletItem.qml index 3b4359fb6..83c930c02 100644 --- a/containment/package/contents/ui/applet/AppletItem.qml +++ b/containment/package/contents/ui/applet/AppletItem.qml @@ -325,6 +325,7 @@ Item { property Item animations: null property Item debug: null property Item indexer: null + property Item launchers: null property Item layouter: null property Item layouts: null property Item metrics: null diff --git a/containment/package/contents/ui/applet/communicator/LatteBridge.qml b/containment/package/contents/ui/applet/communicator/LatteBridge.qml index 846c6be70..bdfcee0df 100644 --- a/containment/package/contents/ui/applet/communicator/LatteBridge.qml +++ b/containment/package/contents/ui/applet/communicator/LatteBridge.qml @@ -142,6 +142,7 @@ Item{ readonly property Item actions: Actions{} readonly property Item applet: mainCommunicator.requires readonly property Item debug: appletItem.debug.publicApi + readonly property Item launchers: appletItem.launchers readonly property Item metrics: appletItem.metrics.publicApi readonly property Item userRequests: appletItem.userRequests diff --git a/containment/package/contents/ui/main.qml b/containment/package/contents/ui/main.qml index be5b9672f..24033acc8 100644 --- a/containment/package/contents/ui/main.qml +++ b/containment/package/contents/ui/main.qml @@ -1163,6 +1163,7 @@ Item { animations: _animations debug: _debug indexer: _indexer + launchers: _launchers layouter: _layouter layouts: layoutsContainer metrics: _metrics @@ -1389,6 +1390,11 @@ Item { layouts: layoutsContainer } + Ability.Launchers { + id: _launchers + layoutName: viewLayout ? viewLayout.name : "" + } + Ability.Layouter { id: _layouter animations: _animations diff --git a/plasmoid/package/contents/ui/ContextMenu.qml b/plasmoid/package/contents/ui/ContextMenu.qml index 7594b3d65..b480f14f9 100644 --- a/plasmoid/package/contents/ui/ContextMenu.qml +++ b/plasmoid/package/contents/ui/ContextMenu.qml @@ -833,8 +833,7 @@ PlasmaComponents.ContextMenu { onClicked: { var pos=visualParent.itemIndex; - - root.addInternalSeparatorAtPos(pos); + launchers.addInternalSeparatorAtPos(pos); } } diff --git a/plasmoid/package/contents/ui/TasksExtendedManager.qml b/plasmoid/package/contents/ui/TasksExtendedManager.qml index abece5d7b..9aae9f796 100644 --- a/plasmoid/package/contents/ui/TasksExtendedManager.qml +++ b/plasmoid/package/contents/ui/TasksExtendedManager.qml @@ -344,9 +344,9 @@ Item { //! Connections Connections { target: launchers - onLauncherInRemoving: { - addToBeRemovedLauncher(launcherUrl); - } + onLauncherInRemoving: tasksExtManager.addToBeRemovedLauncher(launcherUrl); + onLauncherInAdding: tasksExtManager.addToBeAddedLauncher(launcherUrl); + onLauncherInMoving: tasksExtManager.addLauncherToBeMoved(launcherUrl, pos); } diff --git a/plasmoid/package/contents/ui/abilities/Launchers.qml b/plasmoid/package/contents/ui/abilities/Launchers.qml index e8d32f23f..97581cdc2 100644 --- a/plasmoid/package/contents/ui/abilities/Launchers.qml +++ b/plasmoid/package/contents/ui/abilities/Launchers.qml @@ -29,12 +29,15 @@ Item { id: _launchers signal launcherChanged(string launcherUrl); signal launcherRemoved(string launcherUrl); + + //! triggered just before action happens. They are used mostly for animation purposes + signal launcherInAdding(string launcherUrl); signal launcherInRemoving(string launcherUrl); + signal launcherInMoving(string launcherUrl, int pos); property int group: LatteCore.Types.UniqueLaunchers property Item bridge: null property Item layout: null - property QtObject tasksModel: null readonly property LaunchersPart.Actions actions: LaunchersPart.Actions{} @@ -90,21 +93,57 @@ Item { } function addLauncher(launcherUrl) { - if (latteView && !inUniqueGroup()) { - latteView.layoutsManager.launchersSignals.addLauncher(root.viewLayoutName, - launchers.group, - launcherUrl); + if (bridge && !inUniqueGroup()) { + bridge.launchers.addSyncedLauncher(launchers.group, + launcherUrl); } else { _launchers.tasksModel.requestAddLauncher(launcherUrl); _launchers.launcherChanged(launcherUrl); } } + function addDroppedLauncher(launcherUrl) { + //workaround to protect in case the launcher contains the iconData + var pos = launcherUrl.indexOf("?iconData="); + + if (pos>0) { + launcherUrl = launcherUrl.substring( 0, launcherUrl.indexOf("?iconData=" ) ); + } + + var path = launcherUrl; + var filename = path.split("/").pop(); + _launchers.launcherInAdding(filename); + + tasksModel.requestAddLauncher(launcherUrl); + launchers.launcherChanged(launcherUrl); + tasksModel.syncLaunchers(); + } + + function addDroppedLaunchers(urls) { + //! inform synced docks for new dropped launchers + if (bridge && !launchers.inUniqueGroup()) { + bridge.launchers.addDroppedLaunchers(launchers.group, + urls); + } else { + urls.forEach(function (item) { + addDroppedLauncher(item); + }); + } + } + + function addInternalSeparatorAtPos(pos) { + var separatorName = freeAvailableSeparatorName(); + + if (separatorName !== "") { + _launchers.launcherInMoving(separatorName, Math.max(0,pos)); + addLauncher(separatorName); + } + } + function removeLauncher(launcherUrl) { - if (latteView && !inUniqueGroup()) { - latteView.layoutsManager.launchersSignals.removeLauncher(root.viewLayoutName, - launchers.group, - launcherUrl); + if (bridge && !inUniqueGroup()) { + bridge.launchers.removeSyncedLauncher(launchers.group, + launcherUrl); } else { _launchers.launcherInRemoving(launcherUrl); _launchers.tasksModel.requestRemoveLauncher(launcherUrl); @@ -113,11 +152,10 @@ Item { } function addLauncherToActivity(launcherUrl, activityId) { - if (latteView && !inUniqueGroup()) { - latteView.layoutsManager.launchersSignals.addLauncherToActivity(root.viewLayoutName, - launchers.group, - launcherUrl, - activityId); + if (bridge && !inUniqueGroup()) { + bridge.launchers.addSyncedLauncherToActivity(launchers.group, + launcherUrl, + activityId); } else { if (activityId !== activityInfo.currentActivity && isOnAllActivities(launcherUrl)) { _launchers.launcherInRemoving(launcherUrl); @@ -129,11 +167,10 @@ Item { } function removeLauncherFromActivity(launcherUrl, activityId) { - if (latteView && !inUniqueGroup()) { - latteView.layoutsManager.launchersSignals.removeLauncherFromActivity(root.viewLayoutName, - launchers.group, - launcherUrl, - activityId); + if (bridge && !inUniqueGroup()) { + bridge.launchers.removeSyncedLauncherFromActivity(launchers.group, + launcherUrl, + activityId); } else { if (activityId === activityInfo.currentActivity) { _launchers.launcherInRemoving(launcherUrl); @@ -143,6 +180,12 @@ Item { } } + function validateLaunchersOrder(orderedLaunchers) { + validator.stop(); + validator.launchers = orderedLaunchers; + validator.start(); + } + function inCurrentActivity(launcherUrl) { var activities = _launchers.tasksModel.launcherActivities(launcherUrl); @@ -246,15 +289,7 @@ Item { return launch; } - - function validateOrder(orderedLaunchers) { - validator.stop(); - validator.launchers = orderedLaunchers; - validator.start(); - } - //! Connections - onGroupChanged:{ if(latteView) { _launchers.tasksModel.updateLaunchersList(); @@ -287,11 +322,10 @@ Item { } if (inDraggingPhase) { - if (latteView && !_launchers.inUniqueGroup()) { - latteView.layoutsManager.launchersSignals.validateLaunchersOrder(root.viewLayoutName, - plasmoid.id, - _launchers.group, - _launchers.currentShownLauncherList()); + if (_launchers.bridge && !_launchers.inUniqueGroup()) { + _launchers.bridge.launchers.validateSyncedLaunchersOrder(_launchers.syncer.clientId, + _launchers.group, + _launchers.currentShownLauncherList()); } } } else { diff --git a/plasmoid/package/contents/ui/abilities/launchers/Syncer.qml b/plasmoid/package/contents/ui/abilities/launchers/Syncer.qml index 36f2a5ba3..d764df3a3 100644 --- a/plasmoid/package/contents/ui/abilities/launchers/Syncer.qml +++ b/plasmoid/package/contents/ui/abilities/launchers/Syncer.qml @@ -24,6 +24,97 @@ import org.kde.plasma.plasmoid 2.0 import org.kde.latte.core 0.2 as LatteCore Item { + id:_syncer + property bool isBlocked: false + readonly property bool isActive: bridge !== null && group !== LatteCore.Types.UniqueLaunchers + readonly property int clientId: plasmoid.id + property string layoutName: "" + //! Connections + Component.onCompleted: { + if (isActive) { + bridge.launchers.addAbilityClient(_syncer); + } + } + + Component.onDestruction: { + if (bridge) { + bridge.launchers.removeAbilityClient(_syncer); + } + } + + onIsActiveChanged: { + if (isActive) { + bridge.launchers.addAbilityClient(_syncer); + } else if (bridge) { + bridge.launchers.removeAbilityClient(_syncer); + } + } + + Connections { + target: isActive ? bridge.launchers : null + onIsReadyChanged: { + if (isReady && _syncer.isActive) { + bridge.launchers.addAbilityClient(_syncer); + } + } + } + + //! All following actions are triggerred from Main SyncedLaunchers handler + function addSyncedLauncher(group, launcher) { + if (group === _launchers.group) { + tasksModel.requestAddLauncher(launcher); + _launchers.launcherChanged(launcher); + tasksModel.syncLaunchers(); + } + } + + function removeSyncedLauncher(group, launcher) { + if (group === _launchers.group) { + _launchers.launcherInRemoving(launcher) + tasksModel.requestRemoveLauncher(launcher); + _launchers.launcherChanged(launcher); + tasksModel.syncLaunchers(); + } + } + + function addSyncedLauncherToActivity(group, launcher, activity) { + if (group === _launchers.group) { + if (activity !== activityInfo.currentActivity && _launchers.isOnAllActivities(launcher)) { + _launchers.launcherInRemoving(launcher); + } + + tasksModel.requestAddLauncherToActivity(launcher, activity); + _launchers.launcherChanged(launcher); + tasksModel.syncLaunchers(); + } + } + + function removeSyncedLauncherFromActivity(group, launcher, activity) { + if (group === _launchers.group) { + if (activity === activityInfo.currentActivity) { + _launchers.launcherInRemoving(launcher) + } + + tasksModel.requestRemoveLauncherFromActivity(launcher, activity); + _launchers.launcherChanged(launcher); + tasksModel.syncLaunchers(); + } + } + + function dropSyncedUrls(group, urls) { + if (group === _launchers.group) { + urls.forEach(function (item) { + _launchers.addDroppedLauncher(item); + }); + } + } + + function validateSyncedLaunchersOrder(group, orderedLaunchers) { + if (group === _launchers.group && !isBlocked) { + _launchers.validateLaunchersOrder(orderedLaunchers); + } + } + } diff --git a/plasmoid/package/contents/ui/main.qml b/plasmoid/package/contents/ui/main.qml index b1b0b8694..1a0c5bb30 100644 --- a/plasmoid/package/contents/ui/main.qml +++ b/plasmoid/package/contents/ui/main.qml @@ -835,6 +835,8 @@ Item { group: plasmoid.configuration.launchersGroup layout: icList.contentItem tasksModel: tasksModel + syncer.isBlocked: inDraggingPhase + syncer.layoutName: viewLayoutName } Ability.Metrics { @@ -1040,15 +1042,16 @@ Item { }); } - function urlsDroppedOnArea(urls){ - // If all dropped URLs point to application desktop files, we'll add a launcher for each of them. + onUrlsDropped: { + //! inform synced docks for new dropped launchers if (onlyLaunchersInDroppedList(urls)) { - urls.forEach(function (item) { - addLauncher(item); - }); + launchers.addDroppedLaunchers(urls); return; } + //! if the list does not contain only launchers then just open the corresponding + //! urls with the relevant app + if (!hoveredItem) { return; } @@ -1060,20 +1063,6 @@ Item { // as you probably don't expect some of your files to open in the app and others to spawn launchers. tasksModel.requestOpenUrls(hoveredItem.modelIndex(), urlsList); } - - onUrlsDropped: { - //! inform synced docks for new dropped launchers - if (latteView && !launchers.inUniqueGroup() && onlyLaunchersInDroppedList(urls)) { - latteView.layoutsManager.launchersSignals.urlsDropped(root.viewLayoutName, - launchers.group, - urls); - return; - } - - //! if the list does not contain only launchers then just open the corresponding - //! urls with the relevant app - urlsDroppedOnArea(urls); - } } /* Rectangle { @@ -1368,22 +1357,6 @@ Item { ///////// //// functions - function addInternalSeparatorAtPos(pos) { - var separatorName = launchers.freeAvailableSeparatorName(); - - if (separatorName !== "") { - tasksExtendedManager.addLauncherToBeMoved(separatorName, Math.max(0,pos)); - - if (latteView && !launchers.inUniqueGroup()) { - latteView.layoutsManager.launchersSignals.addLauncher(root.viewLayoutName, - launchers.group, - separatorName); - } else { - tasksModel.requestAddLauncher(separatorName); - } - } - } - function activateTaskAtIndex(index) { // This is called with Meta+number shortcuts by plasmashell when Tasks are in a plasma panel. shortcuts.sglActivateEntryAtIndex(index); @@ -1430,86 +1403,6 @@ Item { return plasmoid.configuration.launchers59; } - //! BEGIN ::: external launchers signals in order to update the tasks model - function extSignalAddLauncher(group, launcher) { - if (group === launchers.group) { - tasksModel.requestAddLauncher(launcher); - launchers.launcherChanged(launcher); - tasksModel.syncLaunchers(); - } - } - - function extSignalRemoveLauncher(group, launcher) { - if (group === launchers.group) { - launchers.launcherInRemoving(launcher) - tasksModel.requestRemoveLauncher(launcher); - launchers.launcherChanged(launcher); - tasksModel.syncLaunchers(); - } - } - - function extSignalAddLauncherToActivity(group, launcher, activity) { - if (group === launchers.group) { - if (activity !== activityInfo.currentActivity && _launchers.isOnAllActivities(launcher)) { - launchers.launcherInRemoving(launcher); - } - - tasksModel.requestAddLauncherToActivity(launcher, activity); - launchers.launcherChanged(launcher); - tasksModel.syncLaunchers(); - } - } - - function extSignalRemoveLauncherFromActivity(group, launcher, activity) { - if (group === launchers.group) { - if ( activity === activityInfo.currentActivity) { - launchers.launcherInRemoving(launcher) - } - - tasksModel.requestRemoveLauncherFromActivity(launcher, activity); - launchers.launcherChanged(launcher); - tasksModel.syncLaunchers(); - } - } - - function extSignalUrlsDropped(group, urls) { - if (group === launchers.group) { - mouseHandler.urlsDroppedOnArea(urls); - } - } - - function extSignalMoveTask(group, from, to) { - if (group === launchers.group && !root.dragSource) { - tasksModel.move(from, to); - tasksModel.syncLaunchers(); - } - } - - function extSignalValidateLaunchersOrder(group, orderedLaunchers) { - if (group === launchers.group && !root.dragSource) { - launchers.validateOrder(orderedLaunchers); - } - } - - //! END ::: external launchers signals in order to update the tasks model - - - //! it is used to add the fake desktop file which represents - //! the separator (fake launcher) - function addSeparator(pos){ - var separatorName = launchers.freeAvailableSeparatorName(); - - if (separatorName !== "") { - tasksExtendedManager.addLauncherToBeMoved(separatorName, Math.max(0,pos)); - - if (latteView && !launchers.inUniqueGroup()) { - latteView.layoutsManager.launchersSignals.addLauncher(launchers.group, separatorName); - } else { - tasksModel.requestAddLauncher(separatorName); - } - } - } - function previewContainsMouse() { return windowsPreviewDlg.containsMouse; } @@ -1543,23 +1436,6 @@ Item { return false; } - function addLauncher(url) { - //workaround to protect in case the launcher contains the iconData - var pos = url.indexOf("?iconData="); - - if (pos>0) { - url = url.substring( 0, url.indexOf("?iconData=" ) ); - } - - var path = url; - var filename = path.split("/").pop(); - tasksExtendedManager.addToBeAddedLauncher(filename); - - tasksModel.requestAddLauncher(url); - launchers.launcherChanged(url); - tasksModel.syncLaunchers(); - } - function resetDragSource() { dragSource.z = 0; dragSource = null; diff --git a/plasmoid/package/contents/ui/taskslayout/MouseHandler.qml b/plasmoid/package/contents/ui/taskslayout/MouseHandler.qml index bf22e9a56..7bc607626 100644 --- a/plasmoid/package/contents/ui/taskslayout/MouseHandler.qml +++ b/plasmoid/package/contents/ui/taskslayout/MouseHandler.qml @@ -210,9 +210,9 @@ Item { if (droppingSeparator) { droppingSeparator = false; if (hoveredItem && hoveredItem.itemIndex >=0){ - root.addInternalSeparatorAtPos(hoveredItem.itemIndex); + launchers.addInternalSeparatorAtPos(hoveredItem.itemIndex); } else { - root.addInternalSeparatorAtPos(0); + launchers.addInternalSeparatorAtPos(0); } return; }