/* * 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 . */ #include "syncedlaunchers.h" // local #include #include "../lattecorona.h" #include "../layout/centrallayout.h" #include "../layouts/manager.h" #include "../layouts/synchronizer.h" // Qt #include // Plasma #include #include namespace Latte { namespace Layouts { SyncedLaunchers::SyncedLaunchers(QObject *parent) : QObject(parent) { m_manager = qobject_cast(parent); } SyncedLaunchers::~SyncedLaunchers() { } void SyncedLaunchers::addAbilityClient(QQuickItem *client) { if (m_clients.contains(client)) { return; } m_clients << client; connect(client, &QObject::destroyed, this, &SyncedLaunchers::removeClientObject); } void SyncedLaunchers::removeAbilityClient(QQuickItem *client) { if (!m_clients.contains(client)) { return; } disconnect(client, &QObject::destroyed, this, &SyncedLaunchers::removeClientObject); m_clients.removeAll(client); } void SyncedLaunchers::removeClientObject(QObject *obj) { QQuickItem *item = qobject_cast(obj); if (item) { removeAbilityClient(item); } } QList SyncedLaunchers::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 items; } void SyncedLaunchers::addLauncher(QString layoutName, int launcherGroup, QString launcher) { Types::LaunchersGroup group = static_cast(launcherGroup); if ((Types::LaunchersGroup)group == Types::UniqueLaunchers) { return; } QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; for(const auto client : clients(lName)) { if (auto *metaObject = client->metaObject()) { int methodIndex = metaObject->indexOfMethod("addSyncedLauncher(QVariant,QVariant)"); if (methodIndex == -1) { qDebug() << "Launchers Syncer Ability: addSyncedLauncher(QVariant,QVariant) was NOT found..."; continue; } QMetaMethod method = metaObject->method(methodIndex); method.invoke(client, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher)); } } } void SyncedLaunchers::removeLauncher(QString layoutName, int launcherGroup, QString launcher) { Types::LaunchersGroup group = static_cast(launcherGroup); if ((Types::LaunchersGroup)group == Types::UniqueLaunchers) { return; } QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; for(const auto client : clients(lName)) { if (auto *metaObject = client->metaObject()) { int methodIndex = metaObject->indexOfMethod("removeSyncedLauncher(QVariant,QVariant)"); if (methodIndex == -1) { qDebug() << "Launchers Syncer Ability: removeSyncedLauncher(QVariant,QVariant) was NOT found..."; continue; } QMetaMethod method = metaObject->method(methodIndex); method.invoke(client, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher)); } } } void SyncedLaunchers::addLauncherToActivity(QString layoutName, int launcherGroup, QString launcher, QString activity) { Types::LaunchersGroup group = static_cast(launcherGroup); if ((Types::LaunchersGroup)group == Types::UniqueLaunchers) { return; } QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; for(const auto client : clients(lName)) { if (auto *metaObject = client->metaObject()) { int methodIndex = metaObject->indexOfMethod("addSyncedLauncherToActivity(QVariant,QVariant,QVariant)"); if (methodIndex == -1) { qDebug() << "Launchers Syncer Ability: addSyncedLauncherToActivity(QVariant,QVariant,QVariant) was NOT found..."; continue; } QMetaMethod method = metaObject->method(methodIndex); method.invoke(client, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher), Q_ARG(QVariant, activity)); } } } void SyncedLaunchers::removeLauncherFromActivity(QString layoutName, int launcherGroup, QString launcher, QString activity) { Types::LaunchersGroup group = static_cast(launcherGroup); if ((Types::LaunchersGroup)group == Types::UniqueLaunchers) { return; } QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; for(const auto client : clients(lName)) { if (auto *metaObject = client->metaObject()) { int methodIndex = metaObject->indexOfMethod("removeSyncedLauncherFromActivity(QVariant,QVariant,QVariant)"); if (methodIndex == -1) { qDebug() << "Launchers Syncer Ability: removeSyncedLauncherFromActivity(QVariant,QVariant,QVariant) was NOT found..."; continue; } QMetaMethod method = metaObject->method(methodIndex); method.invoke(client, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher), Q_ARG(QVariant, activity)); } } } void SyncedLaunchers::urlsDropped(QString layoutName, int launcherGroup, QStringList urls) { Types::LaunchersGroup group = static_cast(launcherGroup); if ((Types::LaunchersGroup)group == Types::UniqueLaunchers) { return; } QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; for(const auto client : clients(lName)) { if (auto *metaObject = client->metaObject()) { int methodIndex = metaObject->indexOfMethod("dropSyncedUrls(QVariant,QVariant)"); if (methodIndex == -1) { qDebug() << "Launchers Syncer Ability: dropSyncedUrls(QVariant,QVariant) was NOT found..."; continue; } QMetaMethod method = metaObject->method(methodIndex); method.invoke(client, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, urls)); } } } void SyncedLaunchers::validateLaunchersOrder(QString layoutName, uint senderId, int launcherGroup, QStringList launchers) { Types::LaunchersGroup group = static_cast(launcherGroup); if ((Types::LaunchersGroup)group == Types::UniqueLaunchers) { return; } QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; for(const auto client : clients(lName)) { uint clientId = client->property("clientId").toUInt(); 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; } QMetaMethod method = metaObject->method(methodIndex); method.invoke(client, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launchers)); } } } } } } //end of namespace