19 #include <QDBusPendingCall>
20 #include <QDBusMessage>
21 #include <QDBusConnection>
22 #include <QDBusMetaType>
34 qDBusRegisterMetaType<QMap<QString,QString>>();
36 if(!wizardEnabled()) {
37 m_fsWatcher.addPath(wizardEnabledPath());
39 connect(&m_fsWatcher, &QFileSystemWatcher::fileChanged,
this, &System::watcherFileChanged);
42 QString System::wizardEnabledPath()
45 return QDir::home().filePath(QStringLiteral(
".config/ubuntu-system-settings/wizard-has-run"));
48 bool System::wizardEnabled()
const
50 return !QFile::exists(wizardEnabledPath());
53 void System::setWizardEnabled(
bool enabled)
55 if (wizardEnabled() == enabled)
59 QFile::remove(wizardEnabledPath());
61 QDir(wizardEnabledPath()).mkpath(QStringLiteral(
".."));
62 QFile(wizardEnabledPath()).open(QIODevice::WriteOnly);
63 m_fsWatcher.addPath(wizardEnabledPath());
64 Q_EMIT wizardEnabledChanged();
68 void System::watcherFileChanged()
70 Q_EMIT wizardEnabledChanged();
71 m_fsWatcher.removePath(wizardEnabledPath());
74 void System::setSessionVariable(
const QString &variable,
const QString &value)
77 QProcess::startDetached(QStringLiteral(
"initctl set-env --global %1=%2").arg(variable, value));
79 QMap<QString,QString> valueMap;
80 valueMap.insert(variable, value);
82 QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral(
"org.freedesktop.DBus"),
83 QStringLiteral(
"/org/freedesktop/DBus"),
84 QStringLiteral(
"org.freedesktop.DBus"),
85 QStringLiteral(
"UpdateActivationEnvironment"));
87 msg << QVariant::fromValue(valueMap);
88 QDBusConnection::sessionBus().asyncCall(msg);
91 void System::updateSessionLanguage(
const QString &locale)
93 const QString language = locale.split(QStringLiteral(
"."))[0];
95 setSessionVariable(QStringLiteral(
"LANGUAGE"), language);
96 setSessionVariable(QStringLiteral(
"LANG"), locale);
97 setSessionVariable(QStringLiteral(
"LC_ALL"), locale);
101 QLocale::setDefault(QLocale(locale));
104 QProcess::startDetached(QStringLiteral(
"sh -c \"initctl emit indicator-services-end; \
105 initctl stop scope-registry; \
106 initctl stop smart-scopes-proxy; \
107 initctl emit --no-wait indicator-services-start; \
108 initctl restart --no-wait maliit-server; \
109 initctl restart --no-wait unity8-dash\""));