19 #include <QDBusPendingCall>
20 #include <QDBusMessage>
21 #include <QDBusConnection>
22 #include <QDBusMetaType>
34 qDBusRegisterMetaType<QMap<QString,QString>>();
36 m_fsWatcher.addPath(wizardEnabledPath());
37 connect(&m_fsWatcher, &QFileSystemWatcher::fileChanged,
this, &System::wizardEnabledChanged);
40 QString System::wizardEnabledPath()
43 return QDir::home().filePath(
".config/ubuntu-system-settings/wizard-has-run");
46 bool System::wizardEnabled()
const
48 return !QFile::exists(wizardEnabledPath());
51 void System::setWizardEnabled(
bool enabled)
53 if (wizardEnabled() == enabled)
57 QFile::remove(wizardEnabledPath());
59 QDir(wizardEnabledPath()).mkpath(
"..");
60 QFile(wizardEnabledPath()).open(QIODevice::WriteOnly);
61 m_fsWatcher.addPath(wizardEnabledPath());
62 wizardEnabledChanged();
66 void System::setSessionVariable(
const QString &variable,
const QString &value)
69 QProcess::startDetached(QStringLiteral(
"initctl set-env --global %1=%2").arg(variable, value));
71 QMap<QString,QString> valueMap;
72 valueMap.insert(variable, value);
74 QDBusMessage msg = QDBusMessage::createMethodCall(
"org.freedesktop.DBus",
75 "/org/freedesktop/DBus",
76 "org.freedesktop.DBus",
77 "UpdateActivationEnvironment");
79 msg << QVariant::fromValue(valueMap);
80 QDBusConnection::sessionBus().asyncCall(msg);
83 void System::updateSessionLanguage(
const QString &locale)
85 const QString language = locale.split(
".")[0];
87 setSessionVariable(
"LANGUAGE", language);
88 setSessionVariable(
"LANG", locale);
89 setSessionVariable(
"LC_ALL", locale);
93 QLocale::setDefault(QLocale(locale));
96 QProcess::startDetached(
"sh -c \"initctl emit indicator-services-end; \
97 initctl stop scope-registry; \
98 initctl stop smart-scopes-proxy; \
99 initctl emit --no-wait indicator-services-start; \
100 initctl restart --no-wait maliit-server; \
101 initctl restart --no-wait unity8-dash\"");