File indexing completed on 2024-09-15 12:59:02
0001 /* 0002 * Copyright 2017 Smith AR <audoban@openmailbox.org> 0003 * Michail Vourlakos <mvourlakos@gmail.com> 0004 * 0005 * This file is part of Latte-Dock 0006 * 0007 * Latte-Dock is free software; you can redistribute it and/or 0008 * modify it under the terms of the GNU General Public License as 0009 * published by the Free Software Foundation; either version 2 of 0010 * the License, or (at your option) any later version. 0011 * 0012 * Latte-Dock is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 * GNU General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU General Public License 0018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #include "launcherssignals.h" 0022 0023 // local 0024 #include "../lattecorona.h" 0025 #include "../layout/centrallayout.h" 0026 #include "../layouts/manager.h" 0027 #include "../layouts/synchronizer.h" 0028 0029 // Qt 0030 #include <QQuickItem> 0031 0032 // Plasma 0033 #include <Plasma/Applet> 0034 #include <Plasma/Containment> 0035 0036 namespace Latte { 0037 namespace Layouts { 0038 0039 LaunchersSignals::LaunchersSignals(QObject *parent) 0040 : QObject(parent) 0041 { 0042 m_manager = qobject_cast<Layouts::Manager *>(parent); 0043 } 0044 0045 LaunchersSignals::~LaunchersSignals() 0046 { 0047 } 0048 0049 QList<Plasma::Applet *> LaunchersSignals::lattePlasmoids(QString layoutName) 0050 { 0051 QList<Plasma::Applet *> applets; 0052 0053 CentralLayout *layout = m_manager->synchronizer()->centralLayout(layoutName); 0054 QList<Plasma::Containment *> containments; 0055 0056 if (layoutName.isEmpty()) { 0057 containments = m_manager->corona()->containments(); 0058 } else if (layout) { 0059 containments = *(layout->containments()); 0060 } 0061 0062 for(const auto containment : containments) { 0063 for(auto *applet : containment->applets()) { 0064 KPluginMetaData meta = applet->kPackage().metadata(); 0065 0066 if (meta.pluginId() == "org.kde.latte.plasmoid") { 0067 applets.append(applet); 0068 } 0069 } 0070 } 0071 0072 return applets; 0073 } 0074 0075 void LaunchersSignals::addLauncher(QString layoutName, int launcherGroup, QString launcher) 0076 { 0077 Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); 0078 0079 if ((Types::LaunchersGroup)group == Types::UniqueLaunchers) { 0080 return; 0081 } 0082 0083 QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; 0084 0085 for(const auto applet : lattePlasmoids(lName)) { 0086 if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>()) { 0087 const auto &childItems = appletInterface->childItems(); 0088 0089 if (childItems.isEmpty()) { 0090 continue; 0091 } 0092 0093 for (QQuickItem *item : childItems) { 0094 if (auto *metaObject = item->metaObject()) { 0095 int methodIndex = metaObject->indexOfMethod("extSignalAddLauncher(QVariant,QVariant)"); 0096 0097 if (methodIndex == -1) { 0098 continue; 0099 } 0100 0101 QMetaMethod method = metaObject->method(methodIndex); 0102 method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher)); 0103 } 0104 } 0105 } 0106 } 0107 } 0108 0109 void LaunchersSignals::removeLauncher(QString layoutName, int launcherGroup, QString launcher) 0110 { 0111 Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); 0112 0113 if ((Types::LaunchersGroup)group == Types::UniqueLaunchers) { 0114 return; 0115 } 0116 0117 QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; 0118 0119 for(const auto applet : lattePlasmoids(lName)) { 0120 if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>()) { 0121 const auto &childItems = appletInterface->childItems(); 0122 0123 if (childItems.isEmpty()) { 0124 continue; 0125 } 0126 0127 for (QQuickItem *item : childItems) { 0128 if (auto *metaObject = item->metaObject()) { 0129 int methodIndex = metaObject->indexOfMethod("extSignalRemoveLauncher(QVariant,QVariant)"); 0130 0131 if (methodIndex == -1) { 0132 continue; 0133 } 0134 0135 QMetaMethod method = metaObject->method(methodIndex); 0136 method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher)); 0137 } 0138 } 0139 } 0140 } 0141 } 0142 0143 void LaunchersSignals::addLauncherToActivity(QString layoutName, int launcherGroup, QString launcher, QString activity) 0144 { 0145 Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); 0146 0147 if ((Types::LaunchersGroup)group == Types::UniqueLaunchers) { 0148 return; 0149 } 0150 0151 QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; 0152 0153 for(const auto applet : lattePlasmoids(lName)) { 0154 if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>()) { 0155 const auto &childItems = appletInterface->childItems(); 0156 0157 if (childItems.isEmpty()) { 0158 continue; 0159 } 0160 0161 for (QQuickItem *item : childItems) { 0162 if (auto *metaObject = item->metaObject()) { 0163 int methodIndex = metaObject->indexOfMethod("extSignalAddLauncherToActivity(QVariant,QVariant,QVariant)"); 0164 0165 if (methodIndex == -1) { 0166 continue; 0167 } 0168 0169 QMetaMethod method = metaObject->method(methodIndex); 0170 method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher), Q_ARG(QVariant, activity)); 0171 } 0172 } 0173 } 0174 } 0175 } 0176 0177 void LaunchersSignals::removeLauncherFromActivity(QString layoutName, int launcherGroup, QString launcher, QString activity) 0178 { 0179 Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); 0180 0181 if ((Types::LaunchersGroup)group == Types::UniqueLaunchers) { 0182 return; 0183 } 0184 0185 QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; 0186 0187 for(const auto applet : lattePlasmoids(lName)) { 0188 if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>()) { 0189 const auto &childItems = appletInterface->childItems(); 0190 0191 if (childItems.isEmpty()) { 0192 continue; 0193 } 0194 0195 for (QQuickItem *item : childItems) { 0196 if (auto *metaObject = item->metaObject()) { 0197 int methodIndex = metaObject->indexOfMethod("extSignalRemoveLauncherFromActivity(QVariant,QVariant,QVariant)"); 0198 0199 if (methodIndex == -1) { 0200 continue; 0201 } 0202 0203 QMetaMethod method = metaObject->method(methodIndex); 0204 method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher), Q_ARG(QVariant, activity)); 0205 } 0206 } 0207 } 0208 } 0209 } 0210 0211 void LaunchersSignals::urlsDropped(QString layoutName, int launcherGroup, QStringList urls) 0212 { 0213 Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); 0214 0215 if ((Types::LaunchersGroup)group == Types::UniqueLaunchers) { 0216 return; 0217 } 0218 0219 QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; 0220 0221 for(const auto applet : lattePlasmoids(lName)) { 0222 if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>()) { 0223 const auto &childItems = appletInterface->childItems(); 0224 0225 if (childItems.isEmpty()) { 0226 continue; 0227 } 0228 0229 for (QQuickItem *item : childItems) { 0230 if (auto *metaObject = item->metaObject()) { 0231 int methodIndex = metaObject->indexOfMethod("extSignalUrlsDropped(QVariant,QVariant)"); 0232 0233 if (methodIndex == -1) { 0234 continue; 0235 } 0236 0237 QMetaMethod method = metaObject->method(methodIndex); 0238 method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, urls)); 0239 } 0240 } 0241 } 0242 } 0243 } 0244 0245 void LaunchersSignals::moveTask(QString layoutName, int senderId, int launcherGroup, int from, int to) 0246 { 0247 Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); 0248 0249 if ((Types::LaunchersGroup)group == Types::UniqueLaunchers) { 0250 return; 0251 } 0252 0253 QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; 0254 0255 for(const auto applet : lattePlasmoids(lName)) { 0256 if (applet->id() != senderId) { 0257 if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>()) { 0258 const auto &childItems = appletInterface->childItems(); 0259 0260 if (childItems.isEmpty()) { 0261 continue; 0262 } 0263 0264 for (QQuickItem *item : childItems) { 0265 if (auto *metaObject = item->metaObject()) { 0266 int methodIndex = metaObject->indexOfMethod("extSignalMoveTask(QVariant,QVariant,QVariant)"); 0267 0268 if (methodIndex == -1) { 0269 continue; 0270 } 0271 0272 QMetaMethod method = metaObject->method(methodIndex); 0273 method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, from), Q_ARG(QVariant, to)); 0274 } 0275 } 0276 } 0277 } 0278 } 0279 } 0280 0281 void LaunchersSignals::validateLaunchersOrder(QString layoutName, int senderId, int launcherGroup, QStringList launchers) 0282 { 0283 Types::LaunchersGroup group = static_cast<Types::LaunchersGroup>(launcherGroup); 0284 0285 if ((Types::LaunchersGroup)group == Types::UniqueLaunchers) { 0286 return; 0287 } 0288 0289 QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; 0290 0291 for(const auto applet : lattePlasmoids(lName)) { 0292 if (applet->id() != senderId) { 0293 if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>()) { 0294 const auto &childItems = appletInterface->childItems(); 0295 0296 if (childItems.isEmpty()) { 0297 continue; 0298 } 0299 0300 for (QQuickItem *item : childItems) { 0301 if (auto *metaObject = item->metaObject()) { 0302 int methodIndex = metaObject->indexOfMethod("extSignalValidateLaunchersOrder(QVariant,QVariant)"); 0303 0304 if (methodIndex == -1) { 0305 continue; 0306 } 0307 0308 QMetaMethod method = metaObject->method(methodIndex); 0309 method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launchers)); 0310 } 0311 } 0312 } 0313 } 0314 } 0315 } 0316 0317 } 0318 } //end of namespace