File: PropertiesServer.cpp

package info (click to toggle)
lomiri 0.5.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,088 kB
  • sloc: cpp: 39,498; python: 2,559; javascript: 1,426; ansic: 1,012; sh: 289; xml: 252; makefile: 69
file content (163 lines) | stat: -rw-r--r-- 6,783 bytes parent folder | download | duplicates (3)
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
 * Copyright 2013 Canonical Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 3, as published
 * by the  Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY 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
 * version 3 along with this program.  If not, see
 * <http://www.gnu.org/licenses/>
 *
 * Authored by: Michael Terry <michael.terry@canonical.com>
 */

#include "PropertiesServer.h"
#include "AccountsService.h"

// Qt
#include <QDebug>
#include <QDBusMessage>
#include <QDBusMetaType>

#define IFACE_ACCOUNTS_USER QStringLiteral("org.freedesktop.Accounts.User")
#define IFACE_LOMIRI QStringLiteral ("com.lomiri.shell.AccountsService")

PropertiesServer::PropertiesServer(QObject *parent)
    : QObject(parent)
{
    qDBusRegisterMetaType<QList<QVariantMap>>();
    qDBusRegisterMetaType<StringMap>();
    qDBusRegisterMetaType<StringMapList>();
    Reset();
}

QDBusVariant PropertiesServer::Get(const QString &interface, const QString &property) const
{
    if (m_properties.contains(interface) && m_properties[interface].contains(property)) {
        return QDBusVariant(m_properties[interface][property]);
    } else {
        sendErrorReply(QDBusError::InvalidArgs, "Bad interface or property");
        return QDBusVariant(QVariant());
    }
}

QVariantMap PropertiesServer::GetAll(const QString &interface) const
{
    if (m_properties.contains(interface)) {
        return m_properties[interface];
    } else {
        sendErrorReply(QDBusError::InvalidArgs, "Bad interface");
        return QVariantMap();
    }
}

void PropertiesServer::Set(const QString &interface, const QString &property, const QDBusVariant &variant)
{
    QVariant newValue = variant.variant();

    if (interface == IFACE_ACCOUNTS_USER) {
        sendErrorReply(QDBusError::InvalidArgs, QStringLiteral("Property is not writable"));
        return;
    }

    internalSet(interface, property, newValue);
}

void PropertiesServer::SetBackgroundFile(const QString &backgroundFile)
{
    #ifdef ENABLE_UBUNTU_ACCOUNTSSERVICE
        internalSet (IFACE_ACCOUNTS_USER, QStringLiteral ("BackgroundFile"), backgroundFile);
    #else
        internalSet (IFACE_LOMIRI, QStringLiteral ("BackgroundFile"), backgroundFile);
    #endif
}

void PropertiesServer::SetEmail(const QString &email)
{
    internalSet(IFACE_ACCOUNTS_USER, QStringLiteral("Email"), email);
}

void PropertiesServer::SetInputSources(const StringMapList &inputSources)
{
    #ifdef ENABLE_UBUNTU_ACCOUNTSSERVICE
        internalSet(IFACE_ACCOUNTS_USER, QStringLiteral("InputSources"), QVariant::fromValue(inputSources));
    #else
        internalSet(IFACE_LOMIRI, QStringLiteral("InputSources"), QVariant::fromValue(inputSources));
    #endif
}

void PropertiesServer::SetRealName(const QString &realName)
{
    internalSet(IFACE_ACCOUNTS_USER, QStringLiteral("RealName"), realName);
}

void PropertiesServer::internalSet(const QString &interface, const QString &property, const QVariant &variant)
{
    QVariant newValue = variant;

    if (m_properties[interface].contains(property)) {
        QVariant& oldValue = m_properties[interface][property];
        if (oldValue != newValue) {
            // complex types have an extra layer of wrapping via QDBusArgument
            if (interface == QStringLiteral("com.lomiri.shell.AccountsService") &&
                    property == QStringLiteral("LauncherItems")) {
                newValue = QVariant::fromValue(qdbus_cast<QList<QVariantMap>>(newValue.value<QDBusArgument>()));
            }
            else if (interface == QStringLiteral("com.lomiri.shell.AccountsService") &&
                    property == QStringLiteral("InputSources")) {
                newValue = QVariant::fromValue(qdbus_cast<StringMapList>(newValue.value<QDBusArgument>()));
            }

            oldValue = newValue;

            // Special case for user properties.
            if (interface == IFACE_ACCOUNTS_USER) {
                Q_EMIT Changed();
            } else {
                QVariantMap propertyChanges;
                propertyChanges[property] = newValue;
                Q_EMIT PropertiesChanged(interface, propertyChanges, QStringList());

                // FIXME: Here to replicate current behaviour
                // Not sure why accounts-service is triggering Changed when we're
                // emitting PropertyChanges from org.freedesktop.DBus.Properties as well.
                Q_EMIT Changed();
            }
        }
    } else {
        sendErrorReply(QDBusError::InvalidArgs, "Bad interface or property");
    }
}

void PropertiesServer::Reset()
{
    m_properties["com.lomiri.shell.AccountsService"]["DemoEdges2"] = false;
    m_properties["com.lomiri.shell.AccountsService"]["DemoEdgesCompleted"] = QStringList();
    m_properties["com.lomiri.shell.AccountsService"]["LauncherItems"] = QVariant::fromValue(QList<QVariantMap>());
    m_properties["com.lomiri.shell.AccountsService"]["BackgroundFile"] = "";
    m_properties["com.lomiri.shell.AccountsService.Private"]["FailedLogins"] = 0;
    m_properties["com.lomiri.touch.AccountsService.SecurityPrivacy"]["StatsWelcomeScreen"] = true;
    m_properties["com.lomiri.AccountsService.Input"]["MousePrimaryButton"] = "right";
    m_properties["com.lomiri.AccountsService.SecurityPrivacy"]["EnableLauncherWhileLocked"] = true;
    m_properties["com.lomiri.AccountsService.SecurityPrivacy"]["EnableIndicatorsWhileLocked"] = true;
    m_properties["com.lomiri.AccountsService.SecurityPrivacy"]["HideNotificationContentWhileLocked"] = false;
    m_properties["com.lomiri.AccountsService.SecurityPrivacy"]["PasswordDisplayHint"] = AccountsService::Keyboard;
    m_properties["com.lomiri.AccountsService.SecurityPrivacy"]["PinCodePromptManager"] = "PinPrompt";
    m_properties["com.ubuntu.location.providers.here.AccountsService"]["LicenseAccepted"] = false;
    m_properties["com.ubuntu.location.providers.here.AccountsService"]["LicenseBasePath"] = "";
    m_properties["org.freedesktop.Accounts.User"]["BackgroundFile"] = "";
    m_properties["org.freedesktop.Accounts.User"]["Email"] = "";
    m_properties["org.freedesktop.Accounts.User"]["RealName"] = "";

    #ifdef ENABLE_UBUNTU_ACCOUNTSSERVICE
        m_properties["org.freedesktop.Accounts.User"]["InputSources"] = QVariant::fromValue(StringMapList());
    #else
        m_properties["com.lomiri.shell.AccountsService"]["InputSources"] = QVariant::fromValue(StringMapList());
    #endif
}