on 85fefaa help sign in
unity8/plugins/Wizard/System.cpp
98 lines 3.3 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 <QDBusInterface>
20#include <QDBusMetaType>
21#include <QDir>
22#include <QFile>
23#include <QLocale>
24#include <QMap>
25#include <QProcess>
27System::System()
28 : QObject()
30 // Register the argument needed for UpdateActivationEnvironment below
31 qDBusRegisterMetaType<QMap<QString,QString>>();
33 m_fsWatcher.addPath(wizardEnabledPath());
34 connect(&m_fsWatcher, SIGNAL(fileChanged(const QString &)),
35 this, SIGNAL(wizardEnabledChanged()));
38QString System::wizardEnabledPath()
40 // Uses ubuntu-system-settings namespace for historic compatibility reasons
41 return QDir::home().filePath(".config/ubuntu-system-settings/wizard-has-run");
44bool System::wizardEnabled() const
46 return !QFile::exists(wizardEnabledPath());
49void System::setWizardEnabled(bool enabled)
51 if (wizardEnabled() == enabled)
52 return;
54 if (enabled) {
55 QFile::remove(wizardEnabledPath());
56 } else {
57 QDir(wizardEnabledPath()).mkpath("..");
58 QFile(wizardEnabledPath()).open(QIODevice::WriteOnly);
59 m_fsWatcher.addPath(wizardEnabledPath());
60 wizardEnabledChanged();
61 }
64void System::setSessionVariable(const QString &variable, const QString &value)
66 // We need to update both upstart's and DBus's environment
67 QProcess::execute(QString("initctl set-env --global %1=%2").arg(variable, value));
69 QDBusInterface iface("org.freedesktop.DBus",
70 "/org/freedesktop/DBus",
71 "org.freedesktop.DBus",
72 QDBusConnection::sessionBus());
74 QMap<QString,QString> valueMap;
75 valueMap.insert(variable, value);
76 iface.call("UpdateActivationEnvironment", QVariant::fromValue(valueMap));
79void System::updateSessionLanguage(const QString &locale)
81 QString language = locale.split(".")[0];
83 setSessionVariable("LANGUAGE", language);
84 setSessionVariable("LANG", locale);
85 setSessionVariable("LC_ALL", locale);
87 // QLocale caches the default locale on startup, and Qt uses that cached
88 // copy when formatting dates. So manually update it here.
89 QLocale::setDefault(QLocale(locale));
91 // Restart bits of the session to pick up new language.
92 QProcess::startDetached("sh -c \"initctl emit indicator-services-end; \
93 initctl stop scope-registry; \
94 initctl stop smart-scopes-proxy; \
95 initctl emit --no-wait indicator-services-start; \
96 initctl restart --no-wait maliit-server; \
97 initctl restart --no-wait unity8-dash\"");