File indexing completed on 2024-10-27 04:24:10

0001 #pragma once
0002 
0003 #include <QObject>
0004 #include <QString>
0005 
0006 #include "mauiman_export.h"
0007 
0008 #if !defined Q_OS_ANDROID
0009 class QDBusInterface;
0010 #endif
0011 
0012 
0013 namespace MauiMan
0014 {
0015 class SettingsStore;
0016 
0017 /**
0018  * @brief The BackgroundManager class
0019  * Helpfull for third parties to connect to property changes from the Background module setting changes.
0020  */
0021 class MAUIMAN_EXPORT BackgroundManager : public QObject
0022 {
0023     Q_OBJECT
0024 
0025     /**
0026      * The image file path to be used as the wallpaper background
0027      */
0028     Q_PROPERTY(QString wallpaperSource READ wallpaperSource WRITE setWallpaperSource NOTIFY wallpaperSourceChanged)
0029 
0030     /**
0031      * Whether the wallpaper background should have a dimmed effect. This could be used to reduce eye strain, or for a night mode effect
0032      */
0033     Q_PROPERTY(bool dimWallpaper READ dimWallpaper WRITE setDimWallpaper NOTIFY dimWallpaperChanged)
0034 
0035     /**
0036      * Whether the wallpaper image should fit the screen area, preserving its aspect ratio, instead of filling it
0037      */
0038     Q_PROPERTY(bool fitWallpaper READ fitWallpaper WRITE setFitWallpaper NOTIFY fitWallpaperChanged)
0039 
0040     /**
0041      * A color to be used in the background. If not wallpaper image is shown then, this is the color visible
0042      */
0043     Q_PROPERTY(QString solidColor READ solidColor WRITE setSolidColor NOTIFY solidColorChanged)
0044 
0045     /**
0046      * Whether to display the wallpaper image
0047      */
0048     Q_PROPERTY(bool showWallpaper READ showWallpaper WRITE setShowWallpaper NOTIFY showWallpaperChanged)
0049 
0050     /**
0051      * The preferred file path to the directory containing the wallpaper images
0052      */
0053     Q_PROPERTY(QString wallpaperSourceDir READ wallpaperSourceDir WRITE setWallpaperSourceDir NOTIFY wallpaperSourceDirChanged)
0054 
0055 public:
0056 /**
0057      * @brief The DefaultValues class
0058      */
0059     struct DefaultValues
0060     {
0061         static inline const QString wallpaperSource = QStringLiteral("qrc:/wallpapers/maui_shell_dev_bg.png");
0062         static inline const bool dimWallpaper = false;
0063         static inline const bool fitWallpaper = false; //false is to fill, true to fit
0064         static inline const QString solidColor = QStringLiteral("#333");
0065         static inline const bool showWallpaper = true;
0066         static inline const QString wallpaperSourceDir = QStringLiteral("file:///usr/share/wallpapers/Cask");
0067     };
0068 
0069     explicit BackgroundManager(QObject * parent = nullptr);
0070 
0071     QString wallpaperSource() const;
0072 
0073     bool dimWallpaper() const;
0074 
0075     bool fitWallpaper() const;
0076 
0077     QString solidColor() const;
0078 
0079     bool showWallpaper() const;
0080 
0081     void setWallpaperSource(QString wallpaperSource);
0082 
0083     void setDimWallpaper(bool dimWallpaper);
0084 
0085     void setFitWallpaper(bool fitWallpaper);
0086 
0087     void setSolidColor(QString solidColor);
0088 
0089     void setShowWallpaper(bool showWallpaper);
0090 
0091     QString wallpaperSourceDir() const;
0092     void setWallpaperSourceDir(QString wallpaperSourceDir);
0093 
0094 private Q_SLOTS:
0095     void onWallpaperChanged(const QString &wallpaperSource);
0096     void onSolidColorChanged(const QString &solidColor);
0097     void onFitWallpaperChanged(const bool &fitWallpaper);
0098     void onDimWallpaperChanged(const bool &dimWallpaper);
0099     void onShowWallpaperChanged(const bool &showWallpaper);
0100 
0101 Q_SIGNALS:
0102     void wallpaperSourceChanged(QString wallpaperSource);
0103     void dimWallpaperChanged(bool dimWallpaper);
0104     void fitWallpaperChanged(bool fitWallpaper);
0105     void solidColorChanged(QString solidColor);
0106     void showWallpaperChanged(bool showWallpaper);
0107     void wallpaperSourceDirChanged(QString wallpaperSourceDir);
0108 
0109 private:
0110 #if !defined Q_OS_ANDROID
0111     QDBusInterface *m_interface = nullptr;
0112 #endif
0113     MauiMan::SettingsStore *m_settings;
0114 
0115     QString m_wallpaperSource = MauiMan::BackgroundManager::DefaultValues::wallpaperSource;
0116     bool m_dimWallpaper = MauiMan::BackgroundManager::DefaultValues::dimWallpaper;
0117     bool m_fitWallpaper = MauiMan::BackgroundManager::DefaultValues::fitWallpaper; //false is to fill, true to fit
0118     QString m_solidColor = MauiMan::BackgroundManager::DefaultValues::solidColor;
0119     bool m_showWallpaper = MauiMan::BackgroundManager::DefaultValues::showWallpaper;
0120 
0121     QString m_wallpaperSourceDir = MauiMan::BackgroundManager::DefaultValues::wallpaperSourceDir;
0122 
0123     void sync(const QString &key, const QVariant &value);
0124     void setConnections();
0125     void loadSettings();
0126 };
0127 }
0128