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

0001 #pragma once
0002 
0003 #include <QObject>
0004 #include "mauiman_export.h"
0005 
0006 class QDBusInterface;
0007 namespace MauiMan
0008 {
0009 
0010 class SettingsStore;
0011 
0012 /**
0013  * @brief The AccessibilityManager class contains properties for changing visual and hearing clues.
0014  */
0015 class MAUIMAN_EXPORT AccessibilityManager : public QObject
0016 {
0017     Q_OBJECT
0018     /**
0019      * Whether to open items with a single click.
0020      * By default this is set to `true` for mobile, and `false` for desktop.
0021      */
0022     Q_PROPERTY(bool singleClick READ singleClick WRITE setSingleClick NOTIFY singleClickChanged)
0023     
0024     /**
0025      * The policy for showing the scroll bars. The possible values are:
0026      * - 0 Always visible
0027      * - 1 Visible when needed
0028      * - 2 Auto Hide
0029      * - 3 Always hidden
0030      */
0031     Q_PROPERTY(uint scrollBarPolicy READ scrollBarPolicy WRITE setScrollBarPolicy NOTIFY scrollBarPolicyChanged)
0032     
0033     /**
0034      * Whether the user prefers the application to emit notification or alarm sounds.
0035      */
0036     Q_PROPERTY(bool playSounds READ playSounds WRITE setPlaySounds NOTIFY playSoundsChanged)
0037 
0038 public:
0039 
0040     struct DefaultValues
0041     {
0042         static bool isMobile()
0043         {
0044 #if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(UBUNTU_TOUCH)
0045             return true;
0046 #else
0047             return QByteArrayList{"1", "true"}.contains(qgetenv("QT_QUICK_CONTROLS_MOBILE"));
0048 #endif
0049         }
0050         static inline const bool singleClick = DefaultValues::isMobile();
0051         static inline const bool playSounds = true;
0052         static inline const uint scrollBarPolicy = DefaultValues::isMobile() ? 3 : 0;
0053     };
0054 
0055     explicit AccessibilityManager(QObject *parent = nullptr);
0056 
0057     bool singleClick() const;
0058     void setSingleClick(bool singleClick);
0059 
0060     uint scrollBarPolicy() const;
0061     void setScrollBarPolicy(uint newScrollBarPolicy);
0062 
0063     bool playSounds() const;
0064     void setPlaySounds(bool newPlaySounds);
0065 
0066 private Q_SLOTS:
0067     void onSingleClickChanged(bool singleClick);
0068     void onScrollBarPolicyChanged(uint scrollBarPolicy);
0069     void onPlaySoundsChanged(bool playSounds);
0070 
0071 private:
0072 #if !defined Q_OS_ANDROID
0073     QDBusInterface *m_interface = nullptr;
0074 #endif
0075     MauiMan::SettingsStore *m_settings;
0076 
0077     bool m_singleClick = AccessibilityManager::DefaultValues::singleClick;
0078     uint m_scrollBarPolicy = AccessibilityManager::DefaultValues::scrollBarPolicy;
0079     bool m_playSounds = AccessibilityManager::DefaultValues::playSounds;
0080 
0081     void sync(const QString &key, const QVariant &value);
0082     void setConnections();
0083     void loadSettings();
0084 
0085 Q_SIGNALS:
0086     void singleClickChanged(bool);
0087     void scrollBarPolicyChanged(uint);
0088     void playSoundsChanged(bool);
0089 };
0090 
0091 }