on 224ee85 help sign in
unity8/plugins/Wizard/System.cpp
103 lines 3.6 kB history raw
1/*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "System.h"
19#include <QDBusPendingCall>
20#include <QDBusMessage>
21#include <QDBusConnection>
22#include <QDBusMetaType>
23#include <QDir>
24#include <QFile>
25#include <QLocale>
26#include <QMap>
27#include <QProcess>
29System::System()
30 : QObject(),
31 m_fsWatcher()
33 // Register the argument needed for UpdateActivationEnvironment below
34 qDBusRegisterMetaType<QMap<QString,QString>>();
36 m_fsWatcher.addPath(wizardEnabledPath());
37 connect(&m_fsWatcher, SIGNAL(fileChanged(const QString &)),
38 this, SIGNAL(wizardEnabledChanged()));
41QString System::wizardEnabledPath()
43 // Uses ubuntu-system-settings namespace for historic compatibility reasons
44 return QDir::home().filePath(".config/ubuntu-system-settings/wizard-has-run");
47bool System::wizardEnabled() const
49 return !QFile::exists(wizardEnabledPath());
52void System::setWizardEnabled(bool enabled)
54 if (wizardEnabled() == enabled)
55 return;
57 if (enabled) {
58 QFile::remove(wizardEnabledPath());
59 } else {
60 QDir(wizardEnabledPath()).mkpath("..");
61 QFile(wizardEnabledPath()).open(QIODevice::WriteOnly);
62 m_fsWatcher.addPath(wizardEnabledPath());
63 wizardEnabledChanged();
64 }
67void System::setSessionVariable(const QString &variable, const QString &value)
69 // We need to update both upstart's and DBus's environment
70 QProcess::startDetached(QStringLiteral("initctl set-env --global %1=%2").arg(variable, value));
72 QMap<QString,QString> valueMap;
73 valueMap.insert(variable, value);
75 QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.DBus",
76 "/org/freedesktop/DBus",
77 "org.freedesktop.DBus",
78 "UpdateActivationEnvironment");
80 msg << QVariant::fromValue(valueMap);
81 QDBusConnection::sessionBus().asyncCall(msg);
84void System::updateSessionLanguage(const QString &locale)
86 const QString language = locale.split(".")[0];
88 setSessionVariable("LANGUAGE", language);
89 setSessionVariable("LANG", locale);
90 setSessionVariable("LC_ALL", locale);
92 // QLocale caches the default locale on startup, and Qt uses that cached
93 // copy when formatting dates. So manually update it here.
94 QLocale::setDefault(QLocale(locale));
96 // Restart bits of the session to pick up new language.
97 QProcess::startDetached("sh -c \"initctl emit indicator-services-end; \
98 initctl stop scope-registry; \
99 initctl stop smart-scopes-proxy; \
100 initctl emit --no-wait indicator-services-start; \
101 initctl restart --no-wait maliit-server; \
102 initctl restart --no-wait unity8-dash\"");