diff --git a/app/launcherssignals.cpp b/app/launcherssignals.cpp index 01e83fbb..0cbbcba2 100644 --- a/app/launcherssignals.cpp +++ b/app/launcherssignals.cpp @@ -1,314 +1,315 @@ /* * Copyright 2017 Smith AR * 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 "launcherssignals.h" // local #include "lattecorona.h" +#include "layoutmanager.h" #include "layout/layout.h" // Qt #include // Plasma #include #include namespace Latte { LaunchersSignals::LaunchersSignals(QObject *parent) : QObject(parent) { m_manager = qobject_cast(parent); } LaunchersSignals::~LaunchersSignals() { } QList LaunchersSignals::lattePlasmoids(QString layoutName) { QList applets; Layout *layout = m_manager->activeLayout(layoutName); QList containments; if (layoutName.isEmpty()) { containments = m_manager->corona()->containments(); } else if (layout) { containments = *(layout->containments()); } foreach (auto containment, containments) { for (auto *applet : containment->applets()) { KPluginMetaData meta = applet->kPackage().metadata(); if (meta.pluginId() == "org.kde.latte.plasmoid") { applets.append(applet); } } } return applets; } void LaunchersSignals::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 : ""; foreach (auto applet, lattePlasmoids(lName)) { 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("extSignalAddLauncher(QVariant,QVariant)"); if (methodIndex == -1) { continue; } QMetaMethod method = metaObject->method(methodIndex); method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher)); } } } } } void LaunchersSignals::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 : ""; foreach (auto applet, lattePlasmoids(lName)) { 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("extSignalRemoveLauncher(QVariant,QVariant)"); if (methodIndex == -1) { continue; } QMetaMethod method = metaObject->method(methodIndex); method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launcher)); } } } } } void LaunchersSignals::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 : ""; foreach (auto applet, lattePlasmoids(lName)) { 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("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)); } } } } } void LaunchersSignals::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 : ""; foreach (auto applet, lattePlasmoids(lName)) { 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("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)); } } } } } void LaunchersSignals::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 : ""; foreach (auto applet, lattePlasmoids(lName)) { 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("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, int 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 : ""; foreach (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)); } } } } } } void LaunchersSignals::validateLaunchersOrder(QString layoutName, int senderId, int launcherGroup, QStringList launchers) { Types::LaunchersGroup group = static_cast(launcherGroup); if ((Types::LaunchersGroup)group == Types::UniqueLaunchers) { return; } QString lName = (group == Types::LayoutLaunchers) ? layoutName : ""; foreach (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("extSignalValidateLaunchersOrder(QVariant,QVariant)"); if (methodIndex == -1) { continue; } QMetaMethod method = metaObject->method(methodIndex); method.invoke(item, Q_ARG(QVariant, launcherGroup), Q_ARG(QVariant, launchers)); } } } } } } } //end of namespace diff --git a/app/launcherssignals.h b/app/launcherssignals.h index d4ef4045..7eb2ecae 100644 --- a/app/launcherssignals.h +++ b/app/launcherssignals.h @@ -1,74 +1,73 @@ /* * Copyright 2017 Smith AR * 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 . */ #ifndef LAUNCHERSSIGNALS_H #define LAUNCHERSSIGNALS_H // local -#include "layoutmanager.h" #include "../liblatte2/types.h" // Qt #include namespace Plasma { class Applet; } namespace Latte { class LayoutManager; } namespace Latte { //! in order to support property the launcher groups Layout and Global //! the latte plasmoids must communicate between them with signals when //! there are changes in their models. This way we are trying to avoid //! crashes that occur by setting the launcherList of the tasksModel so //! often. The plasma devs of libtaskmanager have designed the launchers //! model to be initialized only once during startup class LaunchersSignals : public QObject { Q_OBJECT public: LaunchersSignals(QObject *parent); ~LaunchersSignals() override; public slots: 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, int senderId, int launcherGroup, int from, int to); Q_INVOKABLE void validateLaunchersOrder(QString layoutName, int senderId, int launcherGroup, QStringList launchers); private: QList lattePlasmoids(QString layoutName); private: LayoutManager *m_manager{nullptr}; }; } #endif diff --git a/app/layoutmanager.h b/app/layoutmanager.h index f46bf9e1..6f9971e1 100644 --- a/app/layoutmanager.h +++ b/app/layoutmanager.h @@ -1,200 +1,201 @@ /* * Copyright 2017 Smith AR * 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 . */ #ifndef LAYOUTMANAGER_H #define LAYOUTMANAGER_H // local +#include "launcherssignals.h" #include "settings/settingsdialog.h" // Qt #include #include #include // KDE #include namespace Plasma { class Containment; class Types; } namespace KActivities { class Controller; } namespace Latte { class Corona; class Importer; class Layout; class LaunchersSignals; class View; } namespace Latte { //! This class is responsible to manipulate all layouts. //! add,remove,rename, update configurations etc. class LayoutManager : public QObject { Q_OBJECT Q_PROPERTY(QString currentLayoutName READ currentLayoutName NOTIFY currentLayoutNameChanged) Q_PROPERTY(QStringList layouts READ layouts NOTIFY layoutsChanged) Q_PROPERTY(QStringList menuLayouts READ menuLayouts NOTIFY menuLayoutsChanged) Q_PROPERTY(LaunchersSignals *launchersSignals READ launchersSignals NOTIFY launchersSignalsChanged) public: LayoutManager(QObject *parent = nullptr); ~LayoutManager() override; Latte::Corona *corona(); Importer *importer(); void load(); void loadLayoutOnStartup(QString layoutName); void unload(); void addView(Plasma::Containment *containment, bool forceLoading = false, int explicitScreen = -1); void hideAllViews(); void pauseLayout(QString layoutName); void syncLatteViewsToScreens(); void syncActiveLayoutsToOriginalFiles(); bool latteViewExists(Latte::View *view) const; bool layoutExists(QString layoutName) const; QString shouldSwitchToLayout(QString activityId); QString currentLayoutName() const; QString defaultLayoutName() const; QStringList layouts() const; QStringList menuLayouts() const; QStringList presetsPaths() const; Types::LayoutsMemoryUsage memoryUsage() const; void setMemoryUsage(Types::LayoutsMemoryUsage memoryUsage); QHash *currentLatteViews() const; QHash *layoutLatteViews(const QString &layoutName) const; QList currentViewsWithPlasmaShortcuts(); //! returns an active layout with that #id (name), it returns null if such //! layout cant be found Layout *activeLayout(QString id) const; int activeLayoutPos(QString id) const; LaunchersSignals *launchersSignals(); QStringList activities(); QStringList runningActivities(); QStringList orphanedActivities(); //! These are activities that haven't been assigned to specific layout void importDefaultLayout(bool newInstanceIfPresent = false); void importPresets(bool includeDefault = false); public slots: void showAboutDialog(); void hideLatteSettingsDialog(); Q_INVOKABLE void showLatteSettingsDialog(int page = Latte::Types::LayoutPage); //! switch to specified layout, default previousMemoryUsage means that it didn't change Q_INVOKABLE bool switchToLayout(QString layoutName, int previousMemoryUsage = -1); Q_INVOKABLE int layoutsMemoryUsage(); //! creates a new layout with layoutName based on the preset Q_INVOKABLE QString newLayout(QString layoutName, QString preset = i18n("Default")); Q_INVOKABLE QStringList activeLayoutsNames(); signals: void activeLayoutsChanged(); void currentLayoutChanged(); void currentLayoutNameChanged(); void launchersSignalsChanged(); void layoutsChanged(); void menuLayoutsChanged(); void currentLayoutIsSwitching(QString layoutName); private slots: void currentActivityChanged(const QString &id); void showInfoWindowChanged(); void syncMultipleLayoutsToActivities(QString layoutForOrphans = QString()); private: void addLayout(Layout *layout); void cleanupOnStartup(QString path); //!remove deprecated or oldstyle config options void clearUnloadedContainmentsFromLinkedFile(QStringList containmentsIds, bool bypassChecks = false); void confirmDynamicSwitch(); //! it is used just in order to provide translations for the presets void ghostForTranslatedPresets(); //! This function figures in the beginning if a view with tasks //! in it will be loaded taking into account also the screens are present. //! returns true if it will be loaded, false otherwise //! firstContainmentWithTasks = the first containment containing a taskmanager plasmoid bool heuresticForLoadingViewWithTasks(int *firstContainmentWithTasks); void importLatteLayout(QString layoutPath); void importPreset(int presetNo, bool newInstanceIfPresent = false); void loadLatteLayout(QString layoutPath); void loadLayouts(); void setMenuLayouts(QStringList layouts); void showInfoWindow(QString info, int duration, QStringList activities = {"0"}); void updateCurrentLayoutNameInMultiEnvironment(); bool layoutIsAssigned(QString layoutName); QString layoutPath(QString layoutName); QStringList validActivities(QStringList currentList); private: QString m_currentLayoutNameInMultiEnvironment; QString m_shouldSwitchToLayout; QStringList m_layouts; QStringList m_menuLayouts; QStringList m_presetsPaths; QHash m_assignedLayouts; QTimer m_dynamicSwitchTimer; QPointer m_latteSettingsDialog; Latte::Corona *m_corona{nullptr}; Importer *m_importer{nullptr}; LaunchersSignals *m_launchersSignals{nullptr}; QList m_activeLayouts; KActivities::Controller *m_activitiesController; friend class SettingsDialog; }; } #endif // LAYOUTMANAGER_H