on ad34824 help sign in
unity8/plugins/Wizard/System.cpp
87 lines 2.9 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 <QMap>
24#include <QProcess>
26System::System()
27 : QObject(),
28 m_fsWatcher()
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 (enabled) {
52 QFile::remove(wizardEnabledPath());
53 } else {
54 QDir(wizardEnabledPath()).mkpath("..");
55 QFile(wizardEnabledPath()).open(QIODevice::WriteOnly);
56 }
59void System::setSessionVariable(const QString &variable, const QString &value)
61 // We need to update both upstart's and DBus's environment
62 QProcess::execute(QString("initctl set-env --global %1=%2").arg(variable, value));
64 QDBusInterface iface("org.freedesktop.DBus",
65 "/org/freedesktop/DBus",
66 "org.freedesktop.DBus",
67 QDBusConnection::sessionBus());
69 QMap<QString,QString> valueMap;
70 valueMap.insert(variable, value);
71 iface.call("UpdateActivationEnvironment", QVariant::fromValue(valueMap));
74void System::updateSessionLanguage(const QString &locale)
76 QString language = locale.split(".")[0];
78 setSessionVariable("LANGUAGE", language);
79 setSessionVariable("LANG", locale);
80 setSessionVariable("LC_ALL", locale);
82 // Indicators and OSK need to pick up new language
83 QProcess::startDetached("sh -c \"initctl emit indicator-services-end; \
84 stop maliit-server; \
85 initctl emit --no-wait indicator-services-start; \
86 initctl start --no-wait maliit-server\"");