~aacid/unity8/fix_testDash

« back to all changes in this revision

Viewing changes to plugins/Wizard/System.cpp

  • Committer: CI Train Bot
  • Author(s): Michael Terry
  • Date: 2014-12-04 20:54:46 UTC
  • mfrom: (1432.3.19 wizard-plugin)
  • Revision ID: ci-train-bot@canonical.com-20141204205446-pbuftf6d5yt854oj
Convert the welcome wizard from a separate executable into a qml plugin (with a small C++ plugin for support).

- This changes the path for adding customized wizard pages (drops system-settings namespacing).  I checked with cwayne, that support isn't being used yet.  So that's safe to adjust while we're here.

- I did not change the path for the 'has the wizard run yet' marker, since that is being used in the wild.  But I added a comment as to why we're using the phrase "ubuntu-system-settings" in that filename.

- I fleshed out unity8's support for changing the language on the fly, since that's now done in-process.  I believe I caught all cases (anything that used a qml binding to i18n worked automatically, just had to catch the cases that were pulling from outside sources like infographics).

- If an incoming call happens during the wizard, we just bail out of it and the edge demo. I'm not sure what the ideal behavior is, but this is at least reasonable. There's nothing in the wizard that *needs* to be done.

- Making the wizard a plugin lets us drop the gap between the end of the wizard and the start of the shell.  Yay! 
Approved by: Andrea Cimitan

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * This file is part of system-settings
3
 
 *
4
2
 * Copyright (C) 2014 Canonical Ltd.
5
3
 *
6
4
 * This program is free software: you can redistribute it and/or modify it
16
14
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
17
15
 */
18
16
 
19
 
#include "system.h"
 
17
#include "System.h"
 
18
 
20
19
#include <QDBusInterface>
21
 
#include <QDBusPendingCall>
22
 
#include <QDBusPendingReply>
 
20
#include <QDBusMetaType>
 
21
#include <QDir>
23
22
#include <QFile>
 
23
#include <QLocale>
 
24
#include <QMap>
24
25
#include <QProcess>
25
 
#include <unistd.h>
26
 
 
27
 
#define HERE_IFACE   "com.ubuntu.location.providers.here.AccountsService"
28
 
#define ENABLED_PROP "LicenseAccepted"
29
 
#define PATH_PROP    "LicenseBasePath"
30
26
 
31
27
System::System()
32
28
    : QObject(),
33
 
      m_accounts(nullptr),
34
 
      m_hereEnabled(false),
35
 
      m_hereLicensePath(" ") // use a single space to indicate it is unasssigned
36
 
{
37
 
    m_accounts = new QDBusInterface("org.freedesktop.Accounts",
38
 
                                    "/org/freedesktop/Accounts/User" + QString::number(geteuid()),
39
 
                                    "org.freedesktop.DBus.Properties",
40
 
                                    QDBusConnection::systemBus(),
41
 
                                    this);
42
 
 
43
 
    m_accounts->connection().connect(m_accounts->service(),
44
 
                                     m_accounts->path(),
45
 
                                     m_accounts->interface(),
46
 
                                     "PropertiesChanged",
47
 
                                     this,
48
 
                                     SLOT(propertiesChanged(QString, QVariantMap, QStringList)));
49
 
 
50
 
    QDBusPendingCall call = m_accounts->asyncCall("Get", HERE_IFACE, PATH_PROP);
51
 
    QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
52
 
    QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher *)),
53
 
                     this, SLOT(getHereLicensePathFinished(QDBusPendingCallWatcher *)));
54
 
}
55
 
 
56
 
void System::propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalid)
57
 
{
58
 
    if (interface == HERE_IFACE) {
59
 
        if (changed.contains(ENABLED_PROP)) {
60
 
            m_hereEnabled = changed[ENABLED_PROP].toBool();
61
 
            Q_EMIT hereEnabledChanged();
62
 
        } else if (invalid.contains(ENABLED_PROP)) {
63
 
            QDBusPendingCall call = m_accounts->asyncCall("Get", HERE_IFACE, ENABLED_PROP);
64
 
            QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
65
 
            QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher *)),
66
 
                             this, SLOT(getHereEnabledFinished(QDBusPendingCallWatcher *)));
67
 
        }
68
 
    }
69
 
}
70
 
 
71
 
void System::getHereEnabledFinished(QDBusPendingCallWatcher *watcher)
72
 
{
73
 
    QDBusPendingReply<QVariant> reply = *watcher;
74
 
    if (!reply.isError()) {
75
 
        QVariant value = reply.argumentAt<0>();
76
 
        m_hereEnabled = value.toBool();
77
 
        Q_EMIT hereEnabledChanged();
78
 
    }
79
 
    watcher->deleteLater();
80
 
}
81
 
 
82
 
void System::getHereLicensePathFinished(QDBusPendingCallWatcher *watcher)
83
 
{
84
 
    QDBusPendingReply<QVariant> reply = *watcher;
85
 
 
86
 
    m_hereLicensePath = "";
87
 
 
88
 
    if (!reply.isError()) {
89
 
        QVariant value = reply.argumentAt<0>();
90
 
        if (QFile::exists(value.toString())) {
91
 
            m_hereLicensePath = value.toString();
92
 
        }
93
 
    }
94
 
 
95
 
    Q_EMIT hereLicensePathChanged();
96
 
 
97
 
    watcher->deleteLater();
98
 
}
99
 
 
100
 
bool System::hereEnabled() const
101
 
{
102
 
    return m_hereEnabled;
103
 
}
104
 
 
105
 
void System::setHereEnabled(bool enabled)
106
 
{
107
 
    m_accounts->asyncCall("Set", HERE_IFACE, ENABLED_PROP, QVariant::fromValue(QDBusVariant(enabled)));
108
 
}
109
 
 
110
 
QString System::hereLicensePath() const
111
 
{
112
 
    return m_hereLicensePath;
113
 
}
114
 
 
115
 
void System::updateSessionLanguage()
116
 
{
117
 
    QProcess::startDetached("sh -c \"initctl start ubuntu-system-settings-wizard-set-lang; initctl emit --no-wait indicator-services-start; initctl start --no-wait maliit-server\"");
 
29
      m_fsWatcher()
 
30
{
 
31
    // Register the argument needed for UpdateActivationEnvironment below
 
32
    qDBusRegisterMetaType<QMap<QString,QString>>();
 
33
 
 
34
    m_fsWatcher.addPath(wizardEnabledPath());
 
35
    connect(&m_fsWatcher, SIGNAL(fileChanged(const QString &)),
 
36
            this, SIGNAL(wizardEnabledChanged()));
 
37
}
 
38
 
 
39
QString System::wizardEnabledPath()
 
40
{
 
41
    // Uses ubuntu-system-settings namespace for historic compatibility reasons
 
42
    return QDir::home().filePath(".config/ubuntu-system-settings/wizard-has-run");
 
43
}
 
44
 
 
45
bool System::wizardEnabled() const
 
46
{
 
47
    return !QFile::exists(wizardEnabledPath());
 
48
}
 
49
 
 
50
void System::setWizardEnabled(bool enabled)
 
51
{
 
52
    if (wizardEnabled() == enabled)
 
53
        return;
 
54
 
 
55
    if (enabled) {
 
56
        QFile::remove(wizardEnabledPath());
 
57
    } else {
 
58
        QDir(wizardEnabledPath()).mkpath("..");
 
59
        QFile(wizardEnabledPath()).open(QIODevice::WriteOnly);
 
60
        m_fsWatcher.addPath(wizardEnabledPath());
 
61
        wizardEnabledChanged();
 
62
    }
 
63
}
 
64
 
 
65
void System::setSessionVariable(const QString &variable, const QString &value)
 
66
{
 
67
    // We need to update both upstart's and DBus's environment
 
68
    QProcess::execute(QString("initctl set-env --global %1=%2").arg(variable, value));
 
69
 
 
70
    QDBusInterface iface("org.freedesktop.DBus",
 
71
                         "/org/freedesktop/DBus",
 
72
                         "org.freedesktop.DBus",
 
73
                         QDBusConnection::sessionBus());
 
74
 
 
75
    QMap<QString,QString> valueMap;
 
76
    valueMap.insert(variable, value);
 
77
    iface.call("UpdateActivationEnvironment", QVariant::fromValue(valueMap));
 
78
}
 
79
 
 
80
void System::updateSessionLanguage(const QString &locale)
 
81
{
 
82
    QString language = locale.split(".")[0];
 
83
 
 
84
    setSessionVariable("LANGUAGE", language);
 
85
    setSessionVariable("LANG", locale);
 
86
    setSessionVariable("LC_ALL", locale);
 
87
 
 
88
    // QLocale caches the default locale on startup, and Qt uses that cached
 
89
    // copy when formatting dates.  So manually update it here.
 
90
    QLocale::setDefault(QLocale(locale));
 
91
 
 
92
    // Restart bits of the session to pick up new language.
 
93
    QProcess::startDetached("sh -c \"initctl emit indicator-services-end; \
 
94
                                     initctl stop scope-registry; \
 
95
                                     initctl stop smart-scopes-proxy; \
 
96
                                     initctl emit --no-wait indicator-services-start; \
 
97
                                     initctl restart --no-wait maliit-server; \
 
98
                                     initctl restart --no-wait unity8-dash\"");
118
99
}