File: input-gsettings.cpp

package info (click to toggle)
ukui-settings-daemon 4.0.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,324 kB
  • sloc: cpp: 39,120; ansic: 3,240; xml: 1,570; sh: 88; makefile: 4
file content (141 lines) | stat: -rw-r--r-- 4,071 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* -*- Mode: C++; indent-tabs-mode: nil; tab-width: 4 -*-
 * -*- coding: utf-8 -*-
 *
 * Copyright (C) 2023 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors: sundagao <sundagao@kylinos.cn>
 */
#include "input-gsettings.h"
#include "clib-syslog.h"

InputGsettings::InputGsettings(QObject *parent) : QObject(parent)
{

}

InputGsettings::~InputGsettings()
{
    clearMapData();
}

InputGsettings *InputGsettings::instance()
{
    static InputGsettings inputGsettings;
    return &inputGsettings;
}

const QList<QString> InputGsettings::getGsettingsKeys(DeviceType type)
{
    switch (type) {
    case DeviceType::IN_MOUSE:
        return m_mouseData.keys();
        break;
    case DeviceType::IN_TOUCHPAD:
        return m_touchpadData.keys();
        break;
    default:
        break;
    }
}

QVariant InputGsettings::getGsettingsValue( const QString &key, DeviceType type)
{
    switch (type) {
    case DeviceType::IN_MOUSE:
        return m_mouseData.value(key, QVariant(QVariant::Type::Invalid));
        break;
    case DeviceType::IN_TOUCHPAD:
        return m_touchpadData.value(key, QVariant(QVariant::Type::Invalid));
        break;
    default:
        break;
    }
    return QVariant(QVariant::Type::Invalid);
}

void InputGsettings::setGsettingsValue(const QString &key, const QVariant &value, DeviceType type)
{
    switch (type) {
    case DeviceType::IN_MOUSE:
        m_mouseSettings->set(key, value);
        break;
    case DeviceType::IN_TOUCHPAD:
        m_touchpadSettings->set(key, value);
        break;
    default:
        break;
    }
}

void InputGsettings::initGsettings()
{
    initMouseGsettings();
    initTouchpadGsettings();
}

bool InputGsettings::resultInitGsettings()
{
    //包含GSETTINGS_INIT_RESULT ,配置初始化失败
    return !(m_mouseData.contains(GSETTINGS_INIT_RESULT) && m_touchpadData.contains(GSETTINGS_INIT_RESULT));
}

void InputGsettings::initMouseGsettings()
{
    if (QGSettings::isSchemaInstalled(UKUI_MOUSE_SCHEMA)) {
        m_mouseSettings = GsettingsPtr(new QGSettings(UKUI_MOUSE_SCHEMA));
        for (QString& key : m_mouseSettings->keys()) {
            m_mouseData.insert(key,m_mouseSettings->get(key));
        }
        connect(m_mouseSettings.data(),SIGNAL(changed(const QString&)),this,SLOT(onMouseChanged(const QString&)),Qt::DirectConnection);
    } else {
        m_mouseData.insert(GSETTINGS_INIT_RESULT,false);
    }
}

void InputGsettings::initTouchpadGsettings()
{
    if (QGSettings::isSchemaInstalled(UKUI_TOUCHPAD_SCHEMA)) {
        m_touchpadSettings = GsettingsPtr(new QGSettings(UKUI_TOUCHPAD_SCHEMA));

        for (QString& key : m_touchpadSettings->keys()) {
            m_touchpadData.insert(key,m_touchpadSettings->get(key));
        }
        connect(m_touchpadSettings.data(),SIGNAL(changed(const QString&)),this,SLOT(onTouchpadChanged(const QString&)),Qt::DirectConnection);
    } else {
        m_touchpadData.insert(GSETTINGS_INIT_RESULT,false);
    }
}

void InputGsettings::clearMapData()
{
    GsettingsMap().swap(m_mouseData);
    GsettingsMap().swap(m_touchpadData);
}

//slots
void InputGsettings::onMouseChanged(const QString &key)
{
    QVariant value = m_mouseSettings->get(key);
    m_mouseData.insert(key,value);
    Q_EMIT mouseChanged(key,value);
}

void InputGsettings::onTouchpadChanged(const QString &key)
{
    QVariant value = m_touchpadSettings->get(key);
    m_touchpadData.insert(key,value);
    Q_EMIT touchpadChanged(key,value);
}