File indexing completed on 2022-11-29 15:03:59

0001 /*
0002     SPDX-FileCopyrightText: 2020 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "interfaces.h"
0007 
0008 #include <PlasmaQuick/AppletQuickItem>
0009 
0010 namespace Latte{
0011 
0012 Interfaces::Interfaces(QObject *parent)
0013     : QObject(parent)
0014 {
0015 }
0016 
0017 QObject *Interfaces::globalShortcuts() const
0018 {
0019     return m_globalShortcuts;
0020 }
0021 
0022 void Interfaces::setGlobalShortcuts(QObject *shortcuts)
0023 {
0024     if (m_globalShortcuts == shortcuts) {
0025         return;
0026     }
0027 
0028     m_globalShortcuts = shortcuts;
0029 
0030     if (m_globalShortcuts) {
0031         connect(m_globalShortcuts, &QObject::destroyed, this, [&]() {
0032             setGlobalShortcuts(nullptr);
0033         });
0034     }
0035 
0036     emit globalShortcutsChanged();
0037 }
0038 
0039 QObject *Interfaces::layoutsManager() const
0040 {
0041     return m_layoutsManager;
0042 }
0043 
0044 void Interfaces::setLayoutsManager(QObject *manager)
0045 {
0046     if (m_layoutsManager == manager) {
0047         return;
0048     }
0049 
0050     m_layoutsManager = manager;
0051 
0052     if (m_layoutsManager) {
0053         connect(m_layoutsManager, &QObject::destroyed, this, [&]() {
0054             setLayoutsManager(nullptr);
0055         });
0056     }
0057 
0058     emit layoutsManagerChanged();
0059 }
0060 
0061 QObject *Interfaces::themeExtended() const
0062 {
0063     return m_themeExtended;
0064 }
0065 
0066 void Interfaces::setThemeExtended(QObject *theme)
0067 {
0068     if (m_themeExtended == theme) {
0069         return;
0070     }
0071 
0072     m_themeExtended = theme;
0073 
0074     if (m_themeExtended) {
0075         connect(m_themeExtended, &QObject::destroyed, this, [&]() {
0076             setThemeExtended(nullptr);
0077         });
0078     }
0079 
0080     emit themeExtendedChanged();
0081 }
0082 
0083 QObject *Interfaces::universalSettings() const
0084 {
0085     return m_universalSettings;
0086 }
0087 
0088 void Interfaces::setUniversalSettings(QObject *settings)
0089 {
0090     if (m_universalSettings == settings) {
0091         return;
0092     }
0093 
0094     m_universalSettings = settings;
0095 
0096     if (m_universalSettings) {
0097         connect(m_universalSettings, &QObject::destroyed, this, [&]() {
0098             setUniversalSettings(nullptr);
0099         });
0100     }
0101 
0102     emit universalSettingsChanged();
0103 }
0104 
0105 void Interfaces::updateView()
0106 {
0107     if (m_plasmoid) {
0108         setView(m_plasmoid->property("_latte_view_object").value<QObject *>());
0109     }
0110 }
0111 
0112 QObject *Interfaces::view() const
0113 {
0114     return m_view;
0115 }
0116 
0117 void Interfaces::setView(QObject *view)
0118 {
0119     if (m_view == view) {
0120         return;
0121     }
0122 
0123     m_view = view;
0124 
0125     if (m_view) {
0126         connect(m_view, &QObject::destroyed, this, [&]() {
0127             setView(nullptr);
0128         });
0129     }
0130 
0131     emit viewChanged();
0132 }
0133 
0134 QObject *Interfaces::plasmoidInterface() const
0135 {
0136     return m_plasmoid;
0137 }
0138 
0139 void Interfaces::setPlasmoidInterface(QObject *interface)
0140 {
0141     PlasmaQuick::AppletQuickItem *plasmoid = qobject_cast<PlasmaQuick::AppletQuickItem *>(interface);
0142 
0143     if (plasmoid && m_plasmoid != plasmoid) {
0144         m_plasmoid = plasmoid;
0145 
0146         setGlobalShortcuts(plasmoid->property("_latte_globalShortcuts_object").value<QObject *>());
0147         setLayoutsManager(plasmoid->property("_latte_layoutsManager_object").value<QObject *>());
0148         setThemeExtended(plasmoid->property("_latte_themeExtended_object").value<QObject *>());
0149         setUniversalSettings(plasmoid->property("_latte_universalSettings_object").value<QObject *>());
0150         setView(plasmoid->property("_latte_view_object").value<QObject *>());
0151 
0152         emit interfaceChanged();
0153     }
0154 }
0155 
0156 }