1#include "formfactormanager.h"
3#include "settingsstore.h"
4#include "mauimanutils.h"
9#include <QGuiApplication>
11#if !defined Q_OS_ANDROID
12#include <QDBusInterface>
15#include <QInputDevice>
19#if !defined Q_OS_ANDROID
24 if (
type.testFlag(QInputDevice::DeviceType::Mouse))
25 typeString << QStringLiteral(
"Mouse");
26 if (
type.testFlag(QInputDevice::DeviceType::TouchPad))
27 typeString << QStringLiteral(
"TouchPad");
28 if (
type.testFlag(QInputDevice::DeviceType::TouchScreen))
29 typeString << QStringLiteral(
"TouchScreen");
30 if (
type.testFlag(QInputDevice::DeviceType::Keyboard))
31 typeString << QStringLiteral(
"Keyboard");
33 typeString << QStringLiteral(
"Unknown");
34 return typeString.
join((QStringLiteral(
", ")));
40#if !defined Q_OS_ANDROID
41 if (m_interface && m_interface->isValid())
43 m_interface->call(key, value);
51void FormFactorManager::setConnections()
53#if !defined Q_OS_ANDROID
56 m_interface->disconnect();
57 m_interface->deleteLater();
58 m_interface =
nullptr;
61 m_interface =
new QDBusInterface(QStringLiteral(
"org.mauiman.Manager"),
62 QStringLiteral(
"/FormFactor"),
63 QStringLiteral(
"org.mauiman.FormFactor"),
66 if (m_interface->isValid())
68 connect(m_interface, SIGNAL(preferredModeChanged(uint)),
this, SLOT(onPreferredModeChanged(uint)));
69 connect(m_interface, SIGNAL(forceTouchScreenChanged(
bool)),
this, SLOT(onForceTouchScreenChanged(
bool)));
74void FormFactorManager::loadSettings()
76 m_settings->beginModule(QStringLiteral(
"FormFactor"));
78#if !defined Q_OS_ANDROID
79 if(m_interface && m_interface->isValid())
81 m_preferredMode = m_interface->property(
"preferredMode").toUInt();
82 m_forceTouchScreen = m_interface->property(
"forceTouchScreen").toBool();
87 m_preferredMode = m_settings->load(QStringLiteral(
"PreferredMode"), m_preferredMode).toUInt();
88 m_forceTouchScreen = m_settings->load(QStringLiteral(
"ForceTouchScreen"), m_forceTouchScreen).toBool();
91FormFactorManager::FormFactorManager(QObject *parent) : MauiMan::
FormFactorInfo(parent)
95 qDebug(
" INIT FORMFACTOR MANAGER");
97#if !defined Q_OS_ANDROID
99 if(server->serverRunning())
101 this->setConnections();
104 connect(server, &MauiManUtils::serverRunningChanged, [
this](
bool state)
108 this->setConnections();
112 m_preferredMode = defaultMode();
119 return m_preferredMode;
129 return m_defaultMode;
134 return m_hasKeyboard;
139 return m_hasTouchscreen;
149 return m_hasTouchpad;
152void FormFactorManager::setPreferredMode(uint preferredMode)
159 sync(QStringLiteral(
"setPreferredMode"), m_preferredMode);
160 m_settings->save(QStringLiteral(
"PreferredMode"), m_preferredMode);
162 Q_EMIT preferredModeChanged(m_preferredMode);
167 return m_forceTouchScreen;
170void FormFactorManager::setForceTouchScreen(
bool newForceTouchScreen)
172 if (m_forceTouchScreen == newForceTouchScreen)
175 m_forceTouchScreen = newForceTouchScreen;
177 sync(QStringLiteral(
"forceTouchScreen"), m_forceTouchScreen);
178 m_settings->save(QStringLiteral(
"ForceTouchScreen"), m_forceTouchScreen);
180 Q_EMIT forceTouchScreenChanged(m_forceTouchScreen);
183void FormFactorManager::onPreferredModeChanged(uint preferredMode)
189 Q_EMIT preferredModeChanged(m_preferredMode);
192void FormFactorManager::onForceTouchScreenChanged(
bool value)
194 if (m_forceTouchScreen == value)
197 m_forceTouchScreen = value;
198 Q_EMIT forceTouchScreenChanged(m_forceTouchScreen);
201void FormFactorInfo::findBestMode()
212 if(m_screenSize.width() > 1500)
214 if(m_hasKeyboard || m_hasMouse || m_hasTouchpad)
222 else if(m_screenSize.width() > 500)
234 if(m_screenSize.width() > 1500)
239 else if(m_screenSize.width() > 500)
256 Q_EMIT bestModeChanged(m_bestMode);
261 QScreen *screen = qApp->primaryScreen();
267 QScreen *screen = qApp->primaryScreen();
271void FormFactorInfo::checkInputs(
const QList<const QInputDevice *> &devices)
274for(
const auto &dev : devices)
275 qDebug() <<
"DEVICE:::" << dev->type();
279 qDebug() <<
"CHECXKING IF DEVICE HAS TYPE" <<
type;
280 auto res= std::find_if(devices.constBegin(), devices.constEnd(), [type](
const QInputDevice *device)
282 return device->type() == type;
285 return res != std::end(devices);
289 m_hasMouse = hasType(QInputDevice::DeviceType::Mouse);
290 m_hasTouchscreen = hasType(QInputDevice::DeviceType::TouchScreen);
291 m_hasTouchpad = hasType(QInputDevice::DeviceType::TouchPad);
293 qDebug() <<
"CHECXKING IF DEVICE HAS TYPE" << m_hasKeyboard;
296 Q_EMIT hasKeyboardChanged(m_hasKeyboard);
297 Q_EMIT hasMouseChanged(m_hasMouse);
298 Q_EMIT hasTouchscreenChanged(m_hasTouchscreen);
299 Q_EMIT hasTouchpadChanged(m_hasTouchpad);
302FormFactorInfo::FormFactorInfo(QObject *parent) : QObject(parent)
304 qDebug(
"INIT FORMFACTOR INFO");
306#if !defined Q_OS_ANDROID
The SettingsStore class Allows to store and read settings for MauiMan from the local conf file.
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
The MauiMan name-space contains all of the available modules for configuring the Maui Applications an...
QDBusConnection sessionBus()
bool isEmpty() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString join(QChar separator) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)