File indexing completed on 2024-12-01 05:02:11
0001 /* 0002 SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "syncedlaunchers.h" 0007 0008 // local 0009 #include "../lattecorona.h" 0010 #include "../layout/centrallayout.h" 0011 #include "../layouts/manager.h" 0012 #include "../layouts/synchronizer.h" 0013 0014 // Qt 0015 #include <QQuickItem> 0016 0017 // Plasma 0018 #include <Plasma/Applet> 0019 #include <Plasma/Containment> 0020 0021 0022 namespace Latte { 0023 namespace Layouts { 0024 0025 SyncedLaunchers::SyncedLaunchers(QObject *parent) 0026 : QObject(parent) 0027 { 0028 m_manager = qobject_cast<Layouts::Manager *>(parent); 0029 } 0030 0031 SyncedLaunchers::~SyncedLaunchers() 0032 { 0033 } 0034 0035 void SyncedLaunchers::addAbilityClient(QQuickItem *client) 0036 { 0037 if (m_clients.contains(client)) { 0038 return; 0039 } 0040 0041 m_clients << client; 0042 0043 connect(client, &QObject::destroyed, this, &SyncedLaunchers::removeClientObject); 0044 } 0045 0046 void SyncedLaunchers::removeAbilityClient(QQuickItem *client) 0047 { 0048 if (!m_clients.contains(client)) { 0049 return; 0050 } 0051 0052 disconnect(client, &QObject::destroyed, this, &SyncedLaunchers::removeClientObject); 0053 m_clients.removeAll(client); 0054 } 0055 0056 void SyncedLaunchers::removeClientObject(QObject *obj) 0057 { 0058 QQuickItem *item = qobject_cast<QQuickItem *>(obj); 0059 0060 if (item) { 0061 removeAbilityClient(item); 0062 } 0063 } 0064 0065 QQuickItem *SyncedLaunchers::client(const int &id) 0066 { 0067 if (id <= 0) { 0068 return nullptr; 0069 } 0070 0071 for(const auto client: m_clients) { 0072 int clientid = client->property("clientId").toInt(); 0073 if (clientid == id) { 0074 return client; 0075 } 0076 } 0077 0078 return nullptr; 0079 } 0080 0081 QList<QQuickItem *> SyncedLaunchers::clients(QString layoutName, QString groupId) 0082 { 0083 QList<QQuickItem *> items; 0084 0085 for(const auto client: m_clients) { 0086 QString cLayoutName = layoutName.isEmpty() ? QString() : client->property("layoutName").toString(); 0087 QString gid = client->property("syncedGroupId").toString(); 0088 if (cLayoutName == layoutName && gid == groupId) { 0089 items << client; 0090 } 0091 } 0092 0093 return items; 0094 } 0095 0096 QList<QQuickItem *> SyncedLaunchers::clients(QString layoutName, uint senderId, Latte::Types::LaunchersGroup launcherGroup, QString launcherGroupId) 0097 { 0098 QList<QQuickItem *> temclients; 0099 0100 if (launcherGroup == Types::UniqueLaunchers && launcherGroupId.isEmpty()) { 0101 //! on its own, single taskmanager 0102 auto c = client(senderId); 0103 if (c) { 0104 temclients << client(senderId); 0105 } 0106 } else { 0107 temclients << clients(layoutName, launcherGroupId); 0108 } 0109 0110 return temclients; 0111 } 0112 0113 void SyncedLaunchers::addLauncher(QString layoutName, uint senderId, int launcherGroup, QString launcherGroupId, QString launcher) 0114 { 0115 Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); 0116 QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; 0117 0118 for(const auto c : clients(lName, senderId, group, launcherGroupId)) { 0119 if (auto *metaObject = c->metaObject()) { 0120 int methodIndex = metaObject->indexOfMethod("addSyncedLauncher(QVariant,QVariant)"); 0121 0122 if (methodIndex == -1) { 0123 qDebug() << "Launchers Syncer Ability: addSyncedLauncher(QVariant,QVariant) was NOT found..."; 0124 continue; 0125 } 0126 0127 QMetaMethod method = metaObject->method(methodIndex); 0128 method.invoke(c, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher)); 0129 } 0130 } 0131 } 0132 0133 void SyncedLaunchers::removeLauncher(QString layoutName, uint senderId, int launcherGroup, QString launcherGroupId, QString launcher) 0134 { 0135 Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); 0136 QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; 0137 0138 for(const auto c : clients(lName, senderId, group, launcherGroupId)) { 0139 if (auto *metaObject = c->metaObject()) { 0140 int methodIndex = metaObject->indexOfMethod("removeSyncedLauncher(QVariant,QVariant)"); 0141 0142 if (methodIndex == -1) { 0143 qDebug() << "Launchers Syncer Ability: removeSyncedLauncher(QVariant,QVariant) was NOT found..."; 0144 continue; 0145 } 0146 0147 QMetaMethod method = metaObject->method(methodIndex); 0148 method.invoke(c, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher)); 0149 } 0150 } 0151 } 0152 0153 void SyncedLaunchers::addLauncherToActivity(QString layoutName, uint senderId, int launcherGroup, QString launcherGroupId, QString launcher, QString activity) 0154 { 0155 Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); 0156 QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; 0157 0158 for(const auto c : clients(lName, senderId, group, launcherGroupId)) { 0159 if (auto *metaObject = c->metaObject()) { 0160 int methodIndex = metaObject->indexOfMethod("addSyncedLauncherToActivity(QVariant,QVariant,QVariant)"); 0161 0162 if (methodIndex == -1) { 0163 qDebug() << "Launchers Syncer Ability: addSyncedLauncherToActivity(QVariant,QVariant,QVariant) was NOT found..."; 0164 continue; 0165 } 0166 0167 QMetaMethod method = metaObject->method(methodIndex); 0168 method.invoke(c, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher), Q_ARG(QVariant, activity)); 0169 } 0170 } 0171 } 0172 0173 void SyncedLaunchers::removeLauncherFromActivity(QString layoutName, uint senderId, int launcherGroup, QString launcherGroupId, QString launcher, QString activity) 0174 { 0175 Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); 0176 QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; 0177 0178 for(const auto c : clients(lName, senderId, group, launcherGroupId)) { 0179 if (auto *metaObject = c->metaObject()) { 0180 int methodIndex = metaObject->indexOfMethod("removeSyncedLauncherFromActivity(QVariant,QVariant,QVariant)"); 0181 0182 if (methodIndex == -1) { 0183 qDebug() << "Launchers Syncer Ability: removeSyncedLauncherFromActivity(QVariant,QVariant,QVariant) was NOT found..."; 0184 continue; 0185 } 0186 0187 QMetaMethod method = metaObject->method(methodIndex); 0188 method.invoke(c, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher), Q_ARG(QVariant, activity)); 0189 } 0190 } 0191 } 0192 0193 void SyncedLaunchers::urlsDropped(QString layoutName, uint senderId, int launcherGroup, QString launcherGroupId, QStringList urls) 0194 { 0195 Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); 0196 QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; 0197 0198 for(const auto c : clients(lName, senderId, group, launcherGroupId)) { 0199 if (auto *metaObject = c->metaObject()) { 0200 int methodIndex = metaObject->indexOfMethod("dropSyncedUrls(QVariant,QVariant)"); 0201 0202 if (methodIndex == -1) { 0203 qDebug() << "Launchers Syncer Ability: dropSyncedUrls(QVariant,QVariant) was NOT found..."; 0204 continue; 0205 } 0206 0207 QMetaMethod method = metaObject->method(methodIndex); 0208 method.invoke(c, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, urls)); 0209 } 0210 } 0211 } 0212 0213 void SyncedLaunchers::validateLaunchersOrder(QString layoutName, uint senderId, int launcherGroup, QString launcherGroupId, QStringList launchers) 0214 { 0215 Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); 0216 QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; 0217 0218 for(const auto c : clients(lName, senderId, group, launcherGroupId)) { 0219 auto tc = client(senderId); 0220 0221 if (c != tc) { 0222 if (auto *metaObject = c->metaObject()) { 0223 int methodIndex = metaObject->indexOfMethod("validateSyncedLaunchersOrder(QVariant,QVariant)"); 0224 0225 if (methodIndex == -1) { 0226 qDebug() << "Launchers Syncer Ability: validateSyncedLaunchersOrder(QVariant,QVariant) was NOT found..."; 0227 continue; 0228 } 0229 0230 QMetaMethod method = metaObject->method(methodIndex); 0231 method.invoke(c, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launchers)); 0232 } 0233 } 0234 } 0235 } 0236 0237 } 0238 } //end of namespace