File indexing completed on 2024-12-08 04:58:20

0001 /*
0002     SPDX-FileCopyrightText: 2017 Smith AR <audoban@openmailbox.org>
0003     SPDX-FileCopyrightText: 2017 Michail Vourlakos <mvourlakos@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef UNIVERSALSETTINGS_H
0009 #define UNIVERSALSETTINGS_H
0010 
0011 // local
0012 #include <coretypes.h>
0013 #include "../apptypes.h"
0014 #include "../lattecorona.h"
0015 #include "../data/preferencesdata.h"
0016 
0017 // Qt
0018 #include <QObject>
0019 #include <QAbstractItemModel>
0020 #include <QHash>
0021 #include <QPair>
0022 #include <QPointer>
0023 #include <QQmlListProperty>
0024 #include <QScreen>
0025 
0026 // KDE
0027 #include <KConfigGroup>
0028 #include <KSharedConfig>
0029 
0030 namespace Latte {
0031 namespace Layouts {
0032 class Manager;
0033 }
0034 }
0035 
0036 namespace Latte {
0037 //width_scale, height_scale
0038 typedef QPair<float, float> ScreenScales;
0039 
0040 //! This class holds all the settings that are universally available
0041 //! independent of layouts
0042 class UniversalSettings : public QObject
0043 {
0044     Q_OBJECT
0045     Q_PROPERTY(bool autostart READ autostart WRITE setAutostart NOTIFY autostartChanged)
0046     Q_PROPERTY(bool badges3DStyle READ badges3DStyle WRITE setBadges3DStyle NOTIFY badges3DStyleChanged)
0047     Q_PROPERTY(bool inAdvancedModeForEditSettings READ inAdvancedModeForEditSettings WRITE setInAdvancedModeForEditSettings NOTIFY inAdvancedModeForEditSettingsChanged)
0048     Q_PROPERTY(bool inConfigureAppletsMode READ inConfigureAppletsMode WRITE setInConfigureAppletsMode NOTIFY inConfigureAppletsModeChanged)
0049     Q_PROPERTY(bool colorsScriptIsPresent READ colorsScriptIsPresent NOTIFY colorsScriptIsPresentChanged)
0050     Q_PROPERTY(bool showInfoWindow READ showInfoWindow WRITE setShowInfoWindow NOTIFY showInfoWindowChanged)
0051 
0052     Q_PROPERTY(int parabolicSpread READ parabolicSpread WRITE setParabolicSpread NOTIFY parabolicSpreadChanged)
0053     Q_PROPERTY(float thicknessMarginInfluence READ thicknessMarginInfluence WRITE setThicknessMarginInfluence NOTIFY thicknessMarginInfluenceChanged)
0054 
0055     Q_PROPERTY(QString singleModeLayoutName READ singleModeLayoutName WRITE setSingleModeLayoutName NOTIFY singleModeLayoutNameChanged)
0056 
0057     Q_PROPERTY(QStringList launchers READ launchers WRITE setLaunchers NOTIFY launchersChanged)
0058     Q_PROPERTY(QStringList contextMenuActionsAlwaysShown READ contextMenuActionsAlwaysShown WRITE setContextMenuActionsAlwaysShown NOTIFY actionsChanged)
0059 
0060     Q_PROPERTY(Latte::Settings::MouseSensitivity sensitivity READ sensitivity WRITE setSensitivity NOTIFY sensitivityChanged)
0061 
0062     Q_PROPERTY(QQmlListProperty<QScreen> screens READ screens)
0063 
0064 public:
0065     UniversalSettings(KSharedConfig::Ptr config, QObject *parent = nullptr);
0066     ~UniversalSettings() override;
0067 
0068     void load();
0069 
0070     bool autostart() const;
0071     void setAutostart(bool state);
0072 
0073     bool badges3DStyle() const;
0074     void setBadges3DStyle(bool enable);
0075 
0076     bool canDisableBorders() const;
0077     void setCanDisableBorders(bool enable);
0078 
0079     bool colorsScriptIsPresent() const;
0080 
0081     bool inAdvancedModeForEditSettings() const;
0082     void setInAdvancedModeForEditSettings(const bool &inAdvanced);
0083 
0084     bool inConfigureAppletsMode() const;
0085     void setInConfigureAppletsMode(const bool enabled);
0086 
0087     bool isAvailableGeometryBroadcastedToPlasma() const;
0088     void setIsAvailableGeometryBroadcastedToPlasma(const bool &isBroadcasted);
0089 
0090     bool kwin_metaForwardedToLatte() const;
0091     void kwin_forwardMetaToLatte(bool forward);
0092 
0093     bool kwin_borderlessMaximizedWindowsEnabled() const;
0094     void kwin_setDisabledMaximizedBorders(bool disable);
0095 
0096     bool metaPressAndHoldEnabled() const;
0097     void setMetaPressAndHoldEnabled(bool enabled);
0098 
0099     bool showInfoWindow() const;
0100     void setShowInfoWindow(bool show);
0101 
0102     int parabolicSpread() const;
0103     void setParabolicSpread(const int &spread);
0104 
0105     int version() const;
0106     void setVersion(int ver);
0107 
0108     int screenTrackerInterval() const;
0109     void setScreenTrackerInterval(int duration);
0110 
0111     float thicknessMarginInfluence() const;
0112     void setThicknessMarginInfluence(const float &influence);
0113 
0114     QString singleModeLayoutName() const;
0115     void setSingleModeLayoutName(QString layoutName);
0116 
0117     QStringList contextMenuActionsAlwaysShown() const;
0118     void setContextMenuActionsAlwaysShown(const QStringList &actions);
0119 
0120     QStringList launchers() const;
0121     void setLaunchers(QStringList launcherList);
0122 
0123     Settings::MouseSensitivity sensitivity();
0124     void setSensitivity(Settings::MouseSensitivity sense);
0125 
0126     QQmlListProperty<QScreen> screens();
0127     static int countScreens(QQmlListProperty<QScreen> *property); //! is needed by screens()
0128     static QScreen *atScreens(QQmlListProperty<QScreen> *property, int index); //! is needed by screens()
0129 
0130 public slots:
0131     Q_INVOKABLE QString splitterIconPath();
0132     Q_INVOKABLE QString trademarkPath();
0133     Q_INVOKABLE QString trademarkIconPath();
0134 
0135     Q_INVOKABLE float screenWidthScale(QString screenName) const;
0136     Q_INVOKABLE float screenHeightScale(QString screenName) const;
0137     Q_INVOKABLE void setScreenScales(QString screenName, float widthScale, float heightScale);
0138 
0139     void syncSettings();
0140 
0141 signals:
0142     void actionsChanged();
0143     void autostartChanged();
0144     void badges3DStyleChanged();
0145     void canDisableBordersChanged();
0146     void colorsScriptIsPresentChanged();
0147     void downloadWindowSizeChanged();
0148     void inAdvancedModeForEditSettingsChanged();
0149     void inConfigureAppletsModeChanged();
0150     void layoutsColumnWidthsChanged();
0151     void layoutsWindowSizeChanged();
0152     void launchersChanged();
0153     void layoutsMemoryUsageChanged();
0154     void isAvailableGeometryBroadcastedToPlasmaChanged();
0155     void metaPressAndHoldEnabledChanged();
0156     void parabolicSpreadChanged();
0157     void sensitivityChanged();
0158     void screensCountChanged();
0159     void screenScalesChanged();
0160     void screenTrackerIntervalChanged();
0161     void showInfoWindowChanged();
0162     void singleModeLayoutNameChanged();
0163     void thicknessMarginInfluenceChanged();
0164     void versionChanged();
0165 
0166 private slots:
0167     void loadConfig();
0168     void loadScalesConfig();
0169     void saveConfig();
0170     void saveScalesConfig();
0171 
0172     void recoverKWinOptions();
0173     void updateColorsScriptIsPresent();
0174     void trackedFileChanged(const QString &file);
0175 
0176     void upgrade_v010();
0177 private:
0178     void cleanupSettings();
0179 
0180     void setColorsScriptIsPresent(bool present);
0181 
0182     MemoryUsage::LayoutsMemory layoutsMemoryUsage() const;
0183     void setLayoutsMemoryUsage(MemoryUsage::LayoutsMemory layoutsMemoryUsage);
0184 
0185 private:
0186     bool m_badges3DStyle{false};
0187     bool m_canDisableBorders{false};
0188     bool m_colorsScriptIsPresent{false};
0189     bool m_inAdvancedModeForEditSettings{false};
0190     bool m_inConfigureAppletsMode{false};
0191     bool m_isAvailableGeometryBroadcastedToPlasma{true};
0192     bool m_metaPressAndHoldEnabled{true};
0193     bool m_showInfoWindow{true};
0194 
0195     //!kwinrc tracking
0196     bool m_kwinMetaForwardedToLatte{false};
0197     bool m_kwinBorderlessMaximizedWindows{false};
0198 
0199     //when there isnt a version it is an old universal file
0200     int m_version{1};
0201 
0202     int m_screenTrackerInterval{2500};
0203     int m_parabolicSpread{Data::Preferences::PARABOLICSPREAD};
0204     float m_thicknessMarginInfluence{Data::Preferences::THICKNESSMARGININFLUENCE};
0205 
0206     QString m_singleModeLayoutName;
0207 
0208     QStringList m_launchers;
0209     QStringList m_contextMenuActionsAlwaysShown;
0210 
0211     MemoryUsage::LayoutsMemory m_memoryUsage;
0212     Settings::MouseSensitivity m_sensitivity{Settings::HighMouseSensitivity};
0213 
0214     //! ScreenName, <width_scale, height_scale>
0215     QHash<QString, ScreenScales> m_screenScales;
0216 
0217     QPointer<Latte::Corona> m_corona;
0218 
0219     KConfigGroup m_screenScalesGroup;
0220     KConfigGroup m_universalGroup;
0221     KSharedConfig::Ptr m_config;
0222 
0223     //! reading kwinrc values is costly; a tracker protects from
0224     //! reading too many times with no real reason
0225     QTimer m_kwinrcTrackerTimer;
0226     KSharedConfigPtr m_kwinrcPtr;
0227     KConfigGroup m_kwinrcModifierOnlyShortcutsGroup;
0228     KConfigGroup m_kwinrcWindowsGroup;
0229 
0230     friend class Layouts::Manager;
0231     friend class Latte::Corona;
0232 };
0233 
0234 }
0235 
0236 #endif //UNIVERSALSETTINGS_H