mirror of https://github.com/cutefishos/settings
feat(settings): add touchscreen page
parent
d972020d3f
commit
b14e02844a
@ -0,0 +1,4 @@
|
||||
<svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M2 2H14A1 1 0 0 1 15 3V13A1 1 0 0 1 14 14H2A1 1 0 0 1 1 13V3A1 1 0 0 1 2 2ZM2.5 3A0.5 0.5 0 0 0 2 3.5V12.5A0.5 0.5 0 0 0 2.5 13H13.5A0.5 0.5 0 0 0 14 12.5V3.5A0.5 0.5 0 0 0 13.5 3Z" fill="#fff" fill-rule="evenodd"/>
|
||||
<path d="M8 5.5A2.5 2.5 0 1 1 8 10.5A2.5 2.5 0 1 1 8 5.5Z" fill="#fff"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 405 B |
@ -0,0 +1,48 @@
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Controls 2.12
|
||||
import QtQuick.Layouts 1.12
|
||||
import FishUI 1.0 as FishUI
|
||||
import Cutefish.Settings 1.0
|
||||
import "../"
|
||||
|
||||
ItemPage {
|
||||
headerTitle: qsTr("Touchscreen")
|
||||
|
||||
Touchscreen {
|
||||
id: touchscreen
|
||||
}
|
||||
|
||||
Scrollable {
|
||||
anchors.fill: parent
|
||||
contentHeight: layout.implicitHeight
|
||||
|
||||
ColumnLayout {
|
||||
id: layout
|
||||
anchors.fill: parent
|
||||
spacing: Metrics.sectionSpacing
|
||||
|
||||
ListCard {
|
||||
visible: touchscreen.available
|
||||
|
||||
Repeater {
|
||||
model: touchscreen.devices
|
||||
|
||||
ListRow {
|
||||
required property string modelData
|
||||
|
||||
interactive: false
|
||||
text: modelData
|
||||
|
||||
FishUI.Switch {
|
||||
Layout.alignment: Qt.AlignVCenter | Qt.AlignRight
|
||||
checked: touchscreen.disabledDevices.indexOf(modelData) < 0
|
||||
rightPadding: 0
|
||||
rightInset: 0
|
||||
onToggled: touchscreen.setDeviceEnabled(modelData, checked)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,77 @@
|
||||
#include "touchscreen.h"
|
||||
#include <QDBusPendingCall>
|
||||
#include <QDBusPendingCallWatcher>
|
||||
#include <QDBusPendingReply>
|
||||
#include <QDBusServiceWatcher>
|
||||
#include <QDebug>
|
||||
|
||||
namespace {
|
||||
constexpr auto service = "com.cutefish.Touchscreen1";
|
||||
constexpr auto path = "/com/cutefish/Touchscreen1";
|
||||
} // namespace
|
||||
|
||||
Touchscreen::Touchscreen(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
auto *watcher = new QDBusServiceWatcher(QLatin1String(service), QDBusConnection::sessionBus(),
|
||||
QDBusServiceWatcher::WatchForOwnerChange, this);
|
||||
connect(watcher, &QDBusServiceWatcher::serviceOwnerChanged, this,
|
||||
&Touchscreen::refreshInterface);
|
||||
refreshInterface();
|
||||
}
|
||||
|
||||
void Touchscreen::refreshInterface()
|
||||
{
|
||||
delete m_interface;
|
||||
m_interface = new QDBusInterface(QLatin1String(service), QLatin1String(path),
|
||||
QLatin1String(service), QDBusConnection::sessionBus(), this);
|
||||
if (m_interface->isValid()) {
|
||||
connect(m_interface, SIGNAL(devicesChanged()), this, SIGNAL(devicesChanged()));
|
||||
connect(m_interface, SIGNAL(disabledDevicesChanged()), this,
|
||||
SIGNAL(disabledDevicesChanged()));
|
||||
}
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
void Touchscreen::notifyChanged()
|
||||
{
|
||||
emit devicesChanged();
|
||||
emit disabledDevicesChanged();
|
||||
}
|
||||
|
||||
QStringList Touchscreen::list(const char *name) const
|
||||
{
|
||||
return m_interface->isValid() ? m_interface->property(name).toStringList() : QStringList();
|
||||
}
|
||||
|
||||
bool Touchscreen::available() const
|
||||
{
|
||||
return !devices().isEmpty();
|
||||
}
|
||||
|
||||
QStringList Touchscreen::devices() const
|
||||
{
|
||||
return list("devices");
|
||||
}
|
||||
|
||||
QStringList Touchscreen::disabledDevices() const
|
||||
{
|
||||
return list("disabledDevices");
|
||||
}
|
||||
|
||||
void Touchscreen::setDeviceEnabled(const QString &name, bool enabled)
|
||||
{
|
||||
if (!m_interface->isValid())
|
||||
return;
|
||||
auto *watcher = new QDBusPendingCallWatcher(
|
||||
m_interface->asyncCall(QStringLiteral("setDeviceEnabled"), name, enabled), this);
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, this,
|
||||
[this](QDBusPendingCallWatcher *reply) {
|
||||
const QDBusPendingReply<> result = *reply;
|
||||
if (result.isError()) {
|
||||
qWarning() << "Cannot update touchscreen setting" << result.error().message();
|
||||
notifyChanged();
|
||||
}
|
||||
reply->deleteLater();
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
#ifndef TOUCHSCREEN_H
|
||||
#define TOUCHSCREEN_H
|
||||
|
||||
#include <QDBusInterface>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
class Touchscreen : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool available READ available NOTIFY devicesChanged)
|
||||
Q_PROPERTY(QStringList devices READ devices NOTIFY devicesChanged)
|
||||
Q_PROPERTY(QStringList disabledDevices READ disabledDevices NOTIFY disabledDevicesChanged)
|
||||
|
||||
public:
|
||||
explicit Touchscreen(QObject *parent = nullptr);
|
||||
|
||||
bool available() const;
|
||||
QStringList devices() const;
|
||||
QStringList disabledDevices() const;
|
||||
|
||||
Q_INVOKABLE void setDeviceEnabled(const QString &name, bool enabled);
|
||||
|
||||
signals:
|
||||
void devicesChanged();
|
||||
void disabledDevicesChanged();
|
||||
|
||||
private:
|
||||
void refreshInterface();
|
||||
void notifyChanged();
|
||||
QStringList list(const char *name) const;
|
||||
QDBusInterface *m_interface = nullptr;
|
||||
};
|
||||
|
||||
#endif // TOUCHSCREEN_H
|
||||
Loading…
Reference in New Issue