Warning, file /plasma/latte-dock/app/settings/universalsettings.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 #ifndef UNIVERSALSETTINGS_H
0022 #define UNIVERSALSETTINGS_H
0023 
0024 // local
0025 #include "../lattecorona.h"
0026 #include "../liblatte2/types.h"
0027 
0028 // Qt
0029 #include <QObject>
0030 #include <QAbstractItemModel>
0031 #include <QHash>
0032 #include <QPair>
0033 #include <QPointer>
0034 #include <QQmlListProperty>
0035 #include <QScreen>
0036 
0037 // KDE
0038 #include <KConfigGroup>
0039 #include <KSharedConfig>
0040 
0041 namespace Latte {
0042 namespace Layouts {
0043 class Manager;
0044 }
0045 }
0046 
0047 namespace Latte {
0048 //width_scale, height_scale
0049 typedef QPair<float, float> ScreenScales;
0050 
0051 //! This class holds all the settings that are universally available
0052 //! independent of layouts
0053 class UniversalSettings : public QObject
0054 {
0055     Q_OBJECT
0056     Q_PROPERTY(bool autostart READ autostart WRITE setAutostart NOTIFY autostartChanged)
0057     Q_PROPERTY(bool badges3DStyle READ badges3DStyle WRITE setBadges3DStyle NOTIFY badges3DStyleChanged)
0058     Q_PROPERTY(bool colorsScriptIsPresent READ colorsScriptIsPresent NOTIFY colorsScriptIsPresentChanged)
0059     Q_PROPERTY(bool showInfoWindow READ showInfoWindow WRITE setShowInfoWindow NOTIFY showInfoWindowChanged)
0060 
0061     Q_PROPERTY(QString currentLayoutName READ currentLayoutName WRITE setCurrentLayoutName NOTIFY currentLayoutNameChanged)
0062 
0063     Q_PROPERTY(QStringList launchers READ launchers WRITE setLaunchers NOTIFY launchersChanged)
0064 
0065     Q_PROPERTY(Latte::Types::MouseSensitivity mouseSensitivity READ mouseSensitivity WRITE setMouseSensitivity NOTIFY mouseSensitivityChanged)
0066 
0067     Q_PROPERTY(QQmlListProperty<QScreen> screens READ screens)
0068 
0069 public:
0070     UniversalSettings(KSharedConfig::Ptr config, QObject *parent = nullptr);
0071     ~UniversalSettings() override;
0072 
0073     void load();
0074 
0075     bool autostart() const;
0076     void setAutostart(bool state);
0077 
0078     bool badges3DStyle() const;
0079     void setBadges3DStyle(bool enable);
0080 
0081     bool canDisableBorders() const;
0082     void setCanDisableBorders(bool enable);
0083 
0084     bool colorsScriptIsPresent() const;
0085 
0086     bool kwin_metaForwardedToLatte() const;
0087     void kwin_forwardMetaToLatte(bool forward);
0088 
0089     bool kwin_borderlessMaximizedWindowsEnabled() const;
0090     void kwin_setDisabledMaximizedBorders(bool disable);
0091 
0092     bool metaPressAndHoldEnabled() const;
0093     void setMetaPressAndHoldEnabled(bool enabled);
0094 
0095     bool showInfoWindow() const;
0096     void setShowInfoWindow(bool show);
0097 
0098     int version() const;
0099     void setVersion(int ver);
0100 
0101     int screenTrackerInterval() const;
0102     void setScreenTrackerInterval(int duration);
0103 
0104     QString currentLayoutName() const;
0105     void setCurrentLayoutName(QString layoutName);
0106 
0107     QString lastNonAssignedLayoutName() const;
0108     void setLastNonAssignedLayoutName(QString layoutName);
0109 
0110     QSize downloadWindowSize() const;
0111     void setDownloadWindowSize(QSize size);
0112 
0113     QSize layoutsWindowSize() const;
0114     void setLayoutsWindowSize(QSize size);
0115 
0116     QStringList layoutsColumnWidths() const;
0117     void setLayoutsColumnWidths(QStringList widths);
0118 
0119     QStringList launchers() const;
0120     void setLaunchers(QStringList launcherList);
0121 
0122     Types::MouseSensitivity mouseSensitivity() const;
0123     void setMouseSensitivity(Types::MouseSensitivity sensitivity);
0124 
0125     QQmlListProperty<QScreen> screens();
0126     static int countScreens(QQmlListProperty<QScreen> *property); //! is needed by screens()
0127     static QScreen *atScreens(QQmlListProperty<QScreen> *property, int index); //! is needed by screens()
0128 
0129 public slots:
0130     Q_INVOKABLE QString splitterIconPath();
0131     Q_INVOKABLE QString trademarkIconPath();
0132 
0133     Q_INVOKABLE float screenWidthScale(QString screenName) const;
0134     Q_INVOKABLE float screenHeightScale(QString screenName) const;
0135     Q_INVOKABLE void setScreenScales(QString screenName, float widthScale, float heightScale);
0136 
0137 signals:
0138     void autostartChanged();
0139     void badges3DStyleChanged();
0140     void canDisableBordersChanged();
0141     void colorsScriptIsPresentChanged();
0142     void currentLayoutNameChanged();
0143     void downloadWindowSizeChanged();
0144     void lastNonAssignedLayoutNameChanged();
0145     void layoutsColumnWidthsChanged();
0146     void layoutsWindowSizeChanged();
0147     void launchersChanged();
0148     void layoutsMemoryUsageChanged();
0149     void metaPressAndHoldEnabledChanged();
0150     void mouseSensitivityChanged();
0151     void screensCountChanged();
0152     void screenScalesChanged();
0153     void screenTrackerIntervalChanged();
0154     void showInfoWindowChanged();
0155     void versionChanged();
0156 
0157 private slots:
0158     void loadConfig();
0159     void loadScalesConfig();
0160     void saveConfig();
0161     void saveScalesConfig();
0162 
0163     void recoverKWinOptions();
0164     void updateColorsScriptIsPresent();
0165     void trackedFileChanged(const QString &file);
0166 
0167 private:
0168     void cleanupSettings();
0169 
0170     void setColorsScriptIsPresent(bool present);
0171 
0172     Types::LayoutsMemoryUsage layoutsMemoryUsage() const;
0173     void setLayoutsMemoryUsage(Types::LayoutsMemoryUsage layoutsMemoryUsage);
0174 
0175 private:
0176     bool m_badges3DStyle{false};
0177     bool m_canDisableBorders{false};
0178     bool m_colorsScriptIsPresent{false};
0179     bool m_metaPressAndHoldEnabled{true};
0180     bool m_showInfoWindow{true};
0181 
0182     //!kwinrc tracking
0183     bool m_kwinMetaForwardedToLatte{false};
0184     bool m_kwinBorderlessMaximizedWindows{false};
0185 
0186     //when there isnt a version it is an old universal file
0187     int m_version{1};
0188 
0189     int m_screenTrackerInterval{2500};
0190 
0191     QString m_currentLayoutName;
0192     QString m_lastNonAssignedLayoutName;
0193     QSize m_downloadWindowSize{800, 550};
0194     QSize m_layoutsWindowSize{700, 450};
0195 
0196     QStringList m_layoutsColumnWidths;
0197     QStringList m_launchers;
0198 
0199     Types::LayoutsMemoryUsage m_memoryUsage;
0200     Types::MouseSensitivity m_mouseSensitivity{Types::HighSensitivity};
0201 
0202     //! ScreenName, <width_scale, height_scale>
0203     QHash<QString, ScreenScales> m_screenScales;
0204 
0205     QPointer<Latte::Corona> m_corona;
0206 
0207     KConfigGroup m_screenScalesGroup;
0208     KConfigGroup m_universalGroup;
0209     KSharedConfig::Ptr m_config;
0210 
0211     friend class Layouts::Manager;
0212     friend class Latte::Corona;
0213 };
0214 
0215 }
0216 
0217 #endif //UNIVERSALSETTINGS_H