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
work/spdx
Michail Vourlakos 4 years ago
parent 15c3b3630a
commit 1ca43ee13f

@ -48,67 +48,55 @@ LaunchersSignals::~LaunchersSignals()
{ {
} }
QList<Plasma::Applet *> LaunchersSignals::lattePlasmoids(QString layoutName) void LaunchersSignals::addAbilityClient(QQuickItem *client)
{ {
QList<Plasma::Applet *> applets; if (m_clients.contains(client)) {
return;
CentralLayout *layout = m_manager->synchronizer()->centralLayout(layoutName);
QList<Plasma::Containment *> containments;
if (layoutName.isEmpty()) {
containments = m_manager->corona()->containments();
} else if (layout) {
containments = *(layout->containments());
} }
for(const auto containment : containments) { m_clients << client;
for(auto *applet : containment->applets()) {
KPluginMetaData meta = applet->kPackage().metadata();
if (meta.pluginId() == "org.kde.latte.plasmoid") { connect(client, &QObject::destroyed, this, &LaunchersSignals::removeClientObject);
applets.append(applet);
}
}
}
return applets;
} }
void LaunchersSignals::addLauncher(QString layoutName, int launcherGroup, QString launcher) void LaunchersSignals::removeAbilityClient(QQuickItem *client)
{ {
Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); if (!m_clients.contains(client)) {
if ((Types::LaunchersGroup)group == Types::UniqueLaunchers) {
return; return;
} }
QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; disconnect(client, &QObject::destroyed, this, &LaunchersSignals::removeClientObject);
m_clients.removeAll(client);
}
for(const auto applet : lattePlasmoids(lName)) { void LaunchersSignals::removeClientObject(QObject *obj)
if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>()) { {
const auto &childItems = appletInterface->childItems(); QQuickItem *item = qobject_cast<QQuickItem *>(obj);
if (childItems.isEmpty()) { if (item) {
continue; removeAbilityClient(item);
} }
}
for (QQuickItem *item : childItems) { QList<QQuickItem *> LaunchersSignals::clients(QString layoutName)
if (auto *metaObject = item->metaObject()) { {
int methodIndex = metaObject->indexOfMethod("extSignalAddLauncher(QVariant,QVariant)"); QList<QQuickItem *> items;
if (methodIndex == -1) {
continue;
}
QMetaMethod method = metaObject->method(methodIndex); if (!layoutName.isEmpty()) {
method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher)); for(const auto client: m_clients) {
} QString cLayoutName = client->property("layoutName").toString();
if (cLayoutName == layoutName) {
items << client;
} }
} }
} else {
items = m_clients;
} }
return items;
} }
void LaunchersSignals::removeLauncher(QString layoutName, int launcherGroup, QString launcher) void LaunchersSignals::addLauncher(QString layoutName, int launcherGroup, QString launcher)
{ {
Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup);
@ -118,31 +106,22 @@ void LaunchersSignals::removeLauncher(QString layoutName, int launcherGroup, QSt
QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; QString lName = (group == Types::LayoutLaunchers) ? layoutName : "";
for(const auto applet : lattePlasmoids(lName)) { for(const auto client : clients(lName)) {
if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>()) { if (auto *metaObject = client->metaObject()) {
const auto &childItems = appletInterface->childItems(); int methodIndex = metaObject->indexOfMethod("addSyncedLauncher(QVariant,QVariant)");
if (childItems.isEmpty()) {
continue;
}
for (QQuickItem *item : childItems) {
if (auto *metaObject = item->metaObject()) {
int methodIndex = metaObject->indexOfMethod("extSignalRemoveLauncher(QVariant,QVariant)");
if (methodIndex == -1) { if (methodIndex == -1) {
qDebug() << "Launchers Syncer Ability: addSyncedLauncher(QVariant,QVariant) was NOT found...";
continue; continue;
} }
QMetaMethod method = metaObject->method(methodIndex); QMetaMethod method = metaObject->method(methodIndex);
method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher)); method.invoke(client, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher));
}
}
} }
} }
} }
void LaunchersSignals::addLauncherToActivity(QString layoutName, int launcherGroup, QString launcher, QString activity) void LaunchersSignals::removeLauncher(QString layoutName, int launcherGroup, QString launcher)
{ {
Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup);
@ -152,31 +131,22 @@ void LaunchersSignals::addLauncherToActivity(QString layoutName, int launcherGro
QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; QString lName = (group == Types::LayoutLaunchers) ? layoutName : "";
for(const auto applet : lattePlasmoids(lName)) { for(const auto client : clients(lName)) {
if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>()) { if (auto *metaObject = client->metaObject()) {
const auto &childItems = appletInterface->childItems(); int methodIndex = metaObject->indexOfMethod("removeSyncedLauncher(QVariant,QVariant)");
if (childItems.isEmpty()) {
continue;
}
for (QQuickItem *item : childItems) {
if (auto *metaObject = item->metaObject()) {
int methodIndex = metaObject->indexOfMethod("extSignalAddLauncherToActivity(QVariant,QVariant,QVariant)");
if (methodIndex == -1) { if (methodIndex == -1) {
qDebug() << "Launchers Syncer Ability: removeSyncedLauncher(QVariant,QVariant) was NOT found...";
continue; continue;
} }
QMetaMethod method = metaObject->method(methodIndex); QMetaMethod method = metaObject->method(methodIndex);
method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher), Q_ARG(QVariant, activity)); method.invoke(client, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher));
}
}
} }
} }
} }
void LaunchersSignals::removeLauncherFromActivity(QString layoutName, int launcherGroup, QString launcher, QString activity) void LaunchersSignals::addLauncherToActivity(QString layoutName, int launcherGroup, QString launcher, QString activity)
{ {
Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup);
@ -186,31 +156,22 @@ void LaunchersSignals::removeLauncherFromActivity(QString layoutName, int launch
QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; QString lName = (group == Types::LayoutLaunchers) ? layoutName : "";
for(const auto applet : lattePlasmoids(lName)) { for(const auto client : clients(lName)) {
if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>()) { if (auto *metaObject = client->metaObject()) {
const auto &childItems = appletInterface->childItems(); int methodIndex = metaObject->indexOfMethod("addSyncedLauncherToActivity(QVariant,QVariant,QVariant)");
if (childItems.isEmpty()) {
continue;
}
for (QQuickItem *item : childItems) {
if (auto *metaObject = item->metaObject()) {
int methodIndex = metaObject->indexOfMethod("extSignalRemoveLauncherFromActivity(QVariant,QVariant,QVariant)");
if (methodIndex == -1) { if (methodIndex == -1) {
qDebug() << "Launchers Syncer Ability: addSyncedLauncherToActivity(QVariant,QVariant,QVariant) was NOT found...";
continue; continue;
} }
QMetaMethod method = metaObject->method(methodIndex); QMetaMethod method = metaObject->method(methodIndex);
method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher), Q_ARG(QVariant, activity)); method.invoke(client, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher), Q_ARG(QVariant, activity));
}
}
} }
} }
} }
void LaunchersSignals::urlsDropped(QString layoutName, int launcherGroup, QStringList urls) void LaunchersSignals::removeLauncherFromActivity(QString layoutName, int launcherGroup, QString launcher, QString activity)
{ {
Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup);
@ -220,31 +181,22 @@ void LaunchersSignals::urlsDropped(QString layoutName, int launcherGroup, QStrin
QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; QString lName = (group == Types::LayoutLaunchers) ? layoutName : "";
for(const auto applet : lattePlasmoids(lName)) { for(const auto client : clients(lName)) {
if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>()) { if (auto *metaObject = client->metaObject()) {
const auto &childItems = appletInterface->childItems(); int methodIndex = metaObject->indexOfMethod("removeSyncedLauncherFromActivity(QVariant,QVariant,QVariant)");
if (childItems.isEmpty()) {
continue;
}
for (QQuickItem *item : childItems) {
if (auto *metaObject = item->metaObject()) {
int methodIndex = metaObject->indexOfMethod("extSignalUrlsDropped(QVariant,QVariant)");
if (methodIndex == -1) { if (methodIndex == -1) {
qDebug() << "Launchers Syncer Ability: removeSyncedLauncherFromActivity(QVariant,QVariant,QVariant) was NOT found...";
continue; continue;
} }
QMetaMethod method = metaObject->method(methodIndex); QMetaMethod method = metaObject->method(methodIndex);
method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, urls)); method.invoke(client, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher), Q_ARG(QVariant, activity));
}
}
} }
} }
} }
void LaunchersSignals::moveTask(QString layoutName, uint senderId, int launcherGroup, int from, int to) void LaunchersSignals::urlsDropped(QString layoutName, int launcherGroup, QStringList urls)
{ {
Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup);
@ -254,28 +206,17 @@ void LaunchersSignals::moveTask(QString layoutName, uint senderId, int launcherG
QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; QString lName = (group == Types::LayoutLaunchers) ? layoutName : "";
for(const auto applet : lattePlasmoids(lName)) { for(const auto client : clients(lName)) {
if (applet->id() != senderId) { if (auto *metaObject = client->metaObject()) {
if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>()) { int methodIndex = metaObject->indexOfMethod("dropSyncedUrls(QVariant,QVariant)");
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) { if (methodIndex == -1) {
qDebug() << "Launchers Syncer Ability: dropSyncedUrls(QVariant,QVariant) was NOT found...";
continue; continue;
} }
QMetaMethod method = metaObject->method(methodIndex); QMetaMethod method = metaObject->method(methodIndex);
method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, from), Q_ARG(QVariant, to)); 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 : ""; QString lName = (group == Types::LayoutLaunchers) ? layoutName : "";
for(const auto applet : lattePlasmoids(lName)) { for(const auto client : clients(lName)) {
if (applet->id() != senderId) { uint clientId = client->property("clientId").toUInt();
if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>()) {
const auto &childItems = appletInterface->childItems();
if (childItems.isEmpty()) {
continue;
}
for (QQuickItem *item : childItems) { if (clientId != senderId) {
if (auto *metaObject = item->metaObject()) { if (auto *metaObject = client->metaObject()) {
int methodIndex = metaObject->indexOfMethod("extSignalValidateLaunchersOrder(QVariant,QVariant)"); int methodIndex = metaObject->indexOfMethod("validateSyncedLaunchersOrder(QVariant,QVariant)");
if (methodIndex == -1) { if (methodIndex == -1) {
qDebug() << "Launchers Syncer Ability: validateSyncedLaunchersOrder(QVariant,QVariant) was NOT found...";
continue; continue;
} }
QMetaMethod method = metaObject->method(methodIndex); QMetaMethod method = metaObject->method(methodIndex);
method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launchers)); method.invoke(client, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launchers));
}
}
} }
} }
} }

@ -22,7 +22,9 @@
#define LAUNCHERSSIGNALS_H #define LAUNCHERSSIGNALS_H
// Qt // Qt
#include <QList>
#include <QObject> #include <QObject>
#include <QQuickItem>
namespace Plasma { namespace Plasma {
class Applet; class Applet;
@ -52,20 +54,26 @@ public:
~LaunchersSignals() override; ~LaunchersSignals() override;
public slots: 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 addLauncher(QString layoutName, int launcherGroup, QString launcher);
Q_INVOKABLE void removeLauncher(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 addLauncherToActivity(QString layoutName, int launcherGroup, QString launcher, QString activity);
Q_INVOKABLE void removeLauncherFromActivity(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); 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); Q_INVOKABLE void validateLaunchersOrder(QString layoutName, uint senderId, int launcherGroup, QStringList launchers);
private: private:
QList<Plasma::Applet *> lattePlasmoids(QString layoutName); QList<QQuickItem *> clients(QString layoutName = QString());
private slots:
void removeClientObject(QObject *obj);
private: private:
Layouts::Manager *m_manager{nullptr}; Layouts::Manager *m_manager{nullptr};
QList<QQuickItem *> m_clients;
}; };
} }

@ -0,0 +1,74 @@
/*
* Copyright 2021 Michail Vourlakos <mvourlakos@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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);
}
}

@ -325,6 +325,7 @@ Item {
property Item animations: null property Item animations: null
property Item debug: null property Item debug: null
property Item indexer: null property Item indexer: null
property Item launchers: null
property Item layouter: null property Item layouter: null
property Item layouts: null property Item layouts: null
property Item metrics: null property Item metrics: null

@ -142,6 +142,7 @@ Item{
readonly property Item actions: Actions{} readonly property Item actions: Actions{}
readonly property Item applet: mainCommunicator.requires readonly property Item applet: mainCommunicator.requires
readonly property Item debug: appletItem.debug.publicApi readonly property Item debug: appletItem.debug.publicApi
readonly property Item launchers: appletItem.launchers
readonly property Item metrics: appletItem.metrics.publicApi readonly property Item metrics: appletItem.metrics.publicApi
readonly property Item userRequests: appletItem.userRequests readonly property Item userRequests: appletItem.userRequests

@ -1163,6 +1163,7 @@ Item {
animations: _animations animations: _animations
debug: _debug debug: _debug
indexer: _indexer indexer: _indexer
launchers: _launchers
layouter: _layouter layouter: _layouter
layouts: layoutsContainer layouts: layoutsContainer
metrics: _metrics metrics: _metrics
@ -1389,6 +1390,11 @@ Item {
layouts: layoutsContainer layouts: layoutsContainer
} }
Ability.Launchers {
id: _launchers
layoutName: viewLayout ? viewLayout.name : ""
}
Ability.Layouter { Ability.Layouter {
id: _layouter id: _layouter
animations: _animations animations: _animations

@ -833,8 +833,7 @@ PlasmaComponents.ContextMenu {
onClicked: { onClicked: {
var pos=visualParent.itemIndex; var pos=visualParent.itemIndex;
launchers.addInternalSeparatorAtPos(pos);
root.addInternalSeparatorAtPos(pos);
} }
} }

@ -344,9 +344,9 @@ Item {
//! Connections //! Connections
Connections { Connections {
target: launchers target: launchers
onLauncherInRemoving: { onLauncherInRemoving: tasksExtManager.addToBeRemovedLauncher(launcherUrl);
addToBeRemovedLauncher(launcherUrl); onLauncherInAdding: tasksExtManager.addToBeAddedLauncher(launcherUrl);
} onLauncherInMoving: tasksExtManager.addLauncherToBeMoved(launcherUrl, pos);
} }

@ -29,12 +29,15 @@ Item {
id: _launchers id: _launchers
signal launcherChanged(string launcherUrl); signal launcherChanged(string launcherUrl);
signal launcherRemoved(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 launcherInRemoving(string launcherUrl);
signal launcherInMoving(string launcherUrl, int pos);
property int group: LatteCore.Types.UniqueLaunchers property int group: LatteCore.Types.UniqueLaunchers
property Item bridge: null property Item bridge: null
property Item layout: null property Item layout: null
property QtObject tasksModel: null property QtObject tasksModel: null
readonly property LaunchersPart.Actions actions: LaunchersPart.Actions{} readonly property LaunchersPart.Actions actions: LaunchersPart.Actions{}
@ -90,9 +93,8 @@ Item {
} }
function addLauncher(launcherUrl) { function addLauncher(launcherUrl) {
if (latteView && !inUniqueGroup()) { if (bridge && !inUniqueGroup()) {
latteView.layoutsManager.launchersSignals.addLauncher(root.viewLayoutName, bridge.launchers.addSyncedLauncher(launchers.group,
launchers.group,
launcherUrl); launcherUrl);
} else { } else {
_launchers.tasksModel.requestAddLauncher(launcherUrl); _launchers.tasksModel.requestAddLauncher(launcherUrl);
@ -100,10 +102,47 @@ Item {
} }
} }
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) { function removeLauncher(launcherUrl) {
if (latteView && !inUniqueGroup()) { if (bridge && !inUniqueGroup()) {
latteView.layoutsManager.launchersSignals.removeLauncher(root.viewLayoutName, bridge.launchers.removeSyncedLauncher(launchers.group,
launchers.group,
launcherUrl); launcherUrl);
} else { } else {
_launchers.launcherInRemoving(launcherUrl); _launchers.launcherInRemoving(launcherUrl);
@ -113,9 +152,8 @@ Item {
} }
function addLauncherToActivity(launcherUrl, activityId) { function addLauncherToActivity(launcherUrl, activityId) {
if (latteView && !inUniqueGroup()) { if (bridge && !inUniqueGroup()) {
latteView.layoutsManager.launchersSignals.addLauncherToActivity(root.viewLayoutName, bridge.launchers.addSyncedLauncherToActivity(launchers.group,
launchers.group,
launcherUrl, launcherUrl,
activityId); activityId);
} else { } else {
@ -129,9 +167,8 @@ Item {
} }
function removeLauncherFromActivity(launcherUrl, activityId) { function removeLauncherFromActivity(launcherUrl, activityId) {
if (latteView && !inUniqueGroup()) { if (bridge && !inUniqueGroup()) {
latteView.layoutsManager.launchersSignals.removeLauncherFromActivity(root.viewLayoutName, bridge.launchers.removeSyncedLauncherFromActivity(launchers.group,
launchers.group,
launcherUrl, launcherUrl,
activityId); activityId);
} else { } else {
@ -143,6 +180,12 @@ Item {
} }
} }
function validateLaunchersOrder(orderedLaunchers) {
validator.stop();
validator.launchers = orderedLaunchers;
validator.start();
}
function inCurrentActivity(launcherUrl) { function inCurrentActivity(launcherUrl) {
var activities = _launchers.tasksModel.launcherActivities(launcherUrl); var activities = _launchers.tasksModel.launcherActivities(launcherUrl);
@ -246,15 +289,7 @@ Item {
return launch; return launch;
} }
function validateOrder(orderedLaunchers) {
validator.stop();
validator.launchers = orderedLaunchers;
validator.start();
}
//! Connections //! Connections
onGroupChanged:{ onGroupChanged:{
if(latteView) { if(latteView) {
_launchers.tasksModel.updateLaunchersList(); _launchers.tasksModel.updateLaunchersList();
@ -287,9 +322,8 @@ Item {
} }
if (inDraggingPhase) { if (inDraggingPhase) {
if (latteView && !_launchers.inUniqueGroup()) { if (_launchers.bridge && !_launchers.inUniqueGroup()) {
latteView.layoutsManager.launchersSignals.validateLaunchersOrder(root.viewLayoutName, _launchers.bridge.launchers.validateSyncedLaunchersOrder(_launchers.syncer.clientId,
plasmoid.id,
_launchers.group, _launchers.group,
_launchers.currentShownLauncherList()); _launchers.currentShownLauncherList());
} }

@ -24,6 +24,97 @@ import org.kde.plasma.plasmoid 2.0
import org.kde.latte.core 0.2 as LatteCore import org.kde.latte.core 0.2 as LatteCore
Item { 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);
}
}
} }

@ -835,6 +835,8 @@ Item {
group: plasmoid.configuration.launchersGroup group: plasmoid.configuration.launchersGroup
layout: icList.contentItem layout: icList.contentItem
tasksModel: tasksModel tasksModel: tasksModel
syncer.isBlocked: inDraggingPhase
syncer.layoutName: viewLayoutName
} }
Ability.Metrics { Ability.Metrics {
@ -1040,15 +1042,16 @@ Item {
}); });
} }
function urlsDroppedOnArea(urls){ onUrlsDropped: {
// If all dropped URLs point to application desktop files, we'll add a launcher for each of them. //! inform synced docks for new dropped launchers
if (onlyLaunchersInDroppedList(urls)) { if (onlyLaunchersInDroppedList(urls)) {
urls.forEach(function (item) { launchers.addDroppedLaunchers(urls);
addLauncher(item);
});
return; return;
} }
//! if the list does not contain only launchers then just open the corresponding
//! urls with the relevant app
if (!hoveredItem) { if (!hoveredItem) {
return; 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. // 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); 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 { /* Rectangle {
@ -1368,22 +1357,6 @@ Item {
///////// /////////
//// functions //// 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) { function activateTaskAtIndex(index) {
// This is called with Meta+number shortcuts by plasmashell when Tasks are in a plasma panel. // This is called with Meta+number shortcuts by plasmashell when Tasks are in a plasma panel.
shortcuts.sglActivateEntryAtIndex(index); shortcuts.sglActivateEntryAtIndex(index);
@ -1430,86 +1403,6 @@ Item {
return plasmoid.configuration.launchers59; 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() { function previewContainsMouse() {
return windowsPreviewDlg.containsMouse; return windowsPreviewDlg.containsMouse;
} }
@ -1543,23 +1436,6 @@ Item {
return false; 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() { function resetDragSource() {
dragSource.z = 0; dragSource.z = 0;
dragSource = null; dragSource = null;

@ -210,9 +210,9 @@ Item {
if (droppingSeparator) { if (droppingSeparator) {
droppingSeparator = false; droppingSeparator = false;
if (hoveredItem && hoveredItem.itemIndex >=0){ if (hoveredItem && hoveredItem.itemIndex >=0){
root.addInternalSeparatorAtPos(hoveredItem.itemIndex); launchers.addInternalSeparatorAtPos(hoveredItem.itemIndex);
} else { } else {
root.addInternalSeparatorAtPos(0); launchers.addInternalSeparatorAtPos(0);
} }
return; return;
} }

Loading…
Cancel
Save