on 2aa49e8 help sign in
unity8/plugins/Wizard/System.cpp
107 lines 3.5 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(),
29 m_fsWatcher()
31 // Register the argument needed for UpdateActivationEnvironment below
32 qDBusRegisterMetaType<QMap<QString,QString>>();
34 if(!wizardEnabled()) {
35 m_fsWatcher.addPath(wizardEnabledPath());
36 }
37 connect(&m_fsWatcher, SIGNAL(fileChanged(const QString &)),
38 this, SLOT(watcherFileChanged()));
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 Q_EMIT wizardEnabledChanged();
64 }
67void System::watcherFileChanged()
69 Q_EMIT wizardEnabledChanged();
70 m_fsWatcher.removePath(wizardEnabledPath());
73void System::setSessionVariable(const QString &variable, const QString &value)
75 // We need to update both upstart's and DBus's environment
76 QProcess::execute(QString("initctl set-env --global %1=%2").arg(variable, value));
78 QDBusInterface iface("org.freedesktop.DBus",
79 "/org/freedesktop/DBus",
80 "org.freedesktop.DBus",
81 QDBusConnection::sessionBus());
83 QMap<QString,QString> valueMap;
84 valueMap.insert(variable, value);
85 iface.call("UpdateActivationEnvironment", QVariant::fromValue(valueMap));
88void System::updateSessionLanguage(const QString &locale)
90 QString language = locale.split(".")[0];
92 setSessionVariable("LANGUAGE", language);
93 setSessionVariable("LANG", locale);
94 setSessionVariable("LC_ALL", locale);
96 // QLocale caches the default locale on startup, and Qt uses that cached
97 // copy when formatting dates. So manually update it here.
98 QLocale::setDefault(QLocale(locale));
100 // Restart bits of the session to pick up new language.
101 QProcess::startDetached("sh -c \"initctl emit indicator-services-end; \
102 initctl stop scope-registry; \
103 initctl stop smart-scopes-proxy; \
104 initctl emit --no-wait indicator-services-start; \
105 initctl restart --no-wait maliit-server; \
106 initctl restart --no-wait unity8-dash\"");