MauiMan

screenmanager.cpp
1#include "screenmanager.h"
2
3#include "settingsstore.h"
4#include "mauimanutils.h"
5
6#include <QDebug>
7
8#if !defined Q_OS_ANDROID
9#include <QDBusInterface>
10#endif
11
12using namespace MauiMan;
13
14ScreenManager::ScreenManager(QObject * parent ) : QObject(parent)
15 ,m_settings(new MauiMan::SettingsStore(this))
16{
17 qDebug( " INIT SCREEN MANAGER");
18
19#if !defined Q_OS_ANDROID
20 auto server = new MauiManUtils(this);
21 if(server->serverRunning())
22 {
23 this->setConnections();
24 }
25
26 connect(server, &MauiManUtils::serverRunningChanged, [this](bool state)
27 {
28 if(state)
29 {
30 this->setConnections();
31 }
32 });
33#endif
34
35 loadSettings();
36}
37
38double ScreenManager::scaleFactor() const
39{
40 return m_scaleFactor;
41}
42
43void ScreenManager::setScaleFactor(double scaleFactor)
44{
45 if (m_scaleFactor == scaleFactor)
46 return;
47
48 m_scaleFactor = scaleFactor;
49 sync(QStringLiteral("setScaleFactor"), m_scaleFactor);
50 m_settings->save(QStringLiteral("ScaleFactor"), m_scaleFactor);
51 Q_EMIT scaleFactorChanged(m_scaleFactor);
52}
53
55{
56 return m_orientation;
57}
58
59void ScreenManager::setOrientation(uint orientation)
60{
61 if (m_orientation == orientation)
62 return;
63
64 m_orientation = orientation;
65 sync(QStringLiteral("setOrientation"), m_orientation);
66 m_settings->save(QStringLiteral("Orientation"), m_orientation);
67 Q_EMIT orientationChanged(m_orientation);
68}
69
70void ScreenManager::onScaleFactorChanged(double scale)
71{
72 if (m_scaleFactor == scale)
73 return;
74
75 m_scaleFactor = scale;
76 Q_EMIT scaleFactorChanged(m_scaleFactor);
77}
78
79void ScreenManager::onOrientationChanged(uint orientation)
80{
81 if (m_orientation == orientation)
82 return;
83
84 m_orientation = orientation;
85 Q_EMIT orientationChanged(m_orientation);
86}
87
88void ScreenManager::sync(const QString &key, const QVariant &value)
89{
90#if !defined Q_OS_ANDROID
91 if (m_interface && m_interface->isValid())
92 {
93 m_interface->call(key, value);
94 }
95#else
96 Q_UNUSED(key)
97 Q_UNUSED(value)
98#endif
99}
100
101void ScreenManager::setConnections()
102{
103#if !defined Q_OS_ANDROID
104 if(m_interface)
105 {
106 m_interface->disconnect();
107 m_interface->deleteLater();
108 m_interface = nullptr;
109 }
110
111 m_interface = new QDBusInterface (QStringLiteral("org.mauiman.Manager"),
112 QStringLiteral("/Screen"),
113 QStringLiteral("org.mauiman.Screen"),
115 if (m_interface->isValid())
116 {
117 connect(m_interface, SIGNAL(scaleFactorChanged(double)), this, SLOT(onScaleFactorChanged(double)));
118 connect(m_interface, SIGNAL(orientationChanged(uint)), this, SLOT(onOrientationChanged(uint)));
119
120 }
121#endif
122}
123
124void ScreenManager::loadSettings()
125{
126 m_settings->beginModule(QStringLiteral("Screen"));
127
128#if !defined Q_OS_ANDROID
129
130 if(m_interface && m_interface->isValid())
131 {
132 m_scaleFactor = m_interface->property("scaleFactor").toDouble();
133 m_orientation = m_interface->property("orientation").toUInt();
134 return;
135 }
136#endif
137
138 m_scaleFactor = m_settings->load(QStringLiteral("ScaleFactor"), m_scaleFactor).toDouble();
139 m_orientation = m_settings->load(QStringLiteral("Orientation"), m_orientation).toUInt();
140}
The MauiManUtils class.
double scaleFactor
The preferred scale factor for the main screen.
uint orientation
The preferred orientation of the main screen.
The SettingsStore class Allows to store and read settings for MauiMan from the local conf file.
void save(const QString &key, const QVariant &value)
Save a conf value entry to the local file.
void beginModule(const QString &module)
Set up the module section to write to.
QVariant load(const QString &key, const QVariant &defaultValue)
Load the value of a conf entry, with a possible default value.
The MauiMan name-space contains all of the available modules for configuring the Maui Applications an...
QDBusMessage call(QDBus::CallMode mode, const QString &method, Args &&... args)
bool isValid() const const
QDBusConnection sessionBus()
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
bool disconnect(const QMetaObject::Connection &connection)
QVariant property(const char *name) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
double toDouble(bool *ok) const const
uint toUInt(bool *ok) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:03:39 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.