20#include <QDBusPendingCall>
21#include <QDBusMessage>
22#include <QDBusConnection>
23#include <QDBusMetaType>
31#include <QStringBuilder>
37 qDBusRegisterMetaType<QMap<QString,QString>>();
39 if(!wizardEnabled()) {
40 m_fsWatcher.addPath(wizardEnabledPath());
42 connect(&m_fsWatcher, &QFileSystemWatcher::fileChanged,
this, &System::watcherFileChanged);
45QString System::wizardEnabledPath()
47 return QDir::home().filePath(QStringLiteral(
".config/lomiri/wizard-has-run"));
50QString System::currentFrameworkPath()
52 QFileInfo f(
"/usr/share/click/frameworks/current");
53 return f.canonicalFilePath();
64bool System::wizardPathExists() {
65 return QFile::exists(wizardEnabledPath());
68bool System::wizardEnabled()
const
70 if (!wizardPathExists()) {
76QString System::readCurrentFramework()
78 QFile f(currentFrameworkPath());
79 if (!f.open(QFile::ReadOnly | QFile::Text))
return "";
84QString System::readWizardEnabled()
86 QFile f(wizardEnabledPath());
87 if (!f.open(QFile::ReadOnly | QFile::Text))
return "";
92QString System::version()
const
94 return readCurrentFramework();
97bool System::isUpdate()
const
99 if (!wizardPathExists()) {
103 return readCurrentFramework() != readWizardEnabled();
106void System::setWizardEnabled(
bool enabled)
108 if (wizardEnabled() == enabled && !isUpdate())
112 QFile::remove(wizardEnabledPath());
114 QDir(wizardEnabledPath()).mkpath(QStringLiteral(
".."));
115 if (QFile::exists(wizardEnabledPath())) {
116 QFile::remove(wizardEnabledPath());
119 if (QDir(wizardEnabledPath()).exists()) {
120 QDir(wizardEnabledPath()).removeRecursively();
122 if (!QFile::copy(currentFrameworkPath(), wizardEnabledPath())) {
124 QFile f(wizardEnabledPath());
125 f.open(QFile::WriteOnly);
127 m_fsWatcher.addPath(wizardEnabledPath());
128 Q_EMIT wizardEnabledChanged();
129 Q_EMIT isUpdateChanged();
133void System::watcherFileChanged()
135 Q_EMIT wizardEnabledChanged();
136 Q_EMIT isUpdateChanged();
137 m_fsWatcher.removePath(wizardEnabledPath());
140void System::setSessionVariable(
const QString &variable,
const QString &value)
143 QStringList vars = { variable % QChar(
'=') % value };
144 QDBusMessage systemdMsg = QDBusMessage::createMethodCall(QStringLiteral(
"org.freedesktop.systemd1"),
145 QStringLiteral(
"/org/freedesktop/systemd1"),
146 QStringLiteral(
"org.freedesktop.systemd1.Manager"),
147 QStringLiteral(
"SetEnvironment"));
148 systemdMsg << QVariant::fromValue(vars);
149 QDBusConnection::sessionBus().asyncCall(systemdMsg);
151 QMap<QString,QString> valueMap;
152 valueMap.insert(variable, value);
154 QDBusMessage dbusMsg = QDBusMessage::createMethodCall(QStringLiteral(
"org.freedesktop.DBus"),
155 QStringLiteral(
"/org/freedesktop/DBus"),
156 QStringLiteral(
"org.freedesktop.DBus"),
157 QStringLiteral(
"UpdateActivationEnvironment"));
159 dbusMsg << QVariant::fromValue(valueMap);
160 QDBusConnection::sessionBus().asyncCall(dbusMsg);
163void System::restartUnit(
const QString &unitName)
165 QDBusMessage systemdMsg = QDBusMessage::createMethodCall(QStringLiteral(
"org.freedesktop.systemd1"),
166 QStringLiteral(
"/org/freedesktop/systemd1"),
167 QStringLiteral(
"org.freedesktop.systemd1.Manager"),
168 QStringLiteral(
"TryRestartUnit"));
169 systemdMsg << QVariant::fromValue(unitName);
170 systemdMsg << QVariant::fromValue(QStringLiteral(
"replace"));
171 QDBusConnection::sessionBus().asyncCall(systemdMsg);
174void System::updateSessionLocale(
const QString &locale)
176 const QString language = locale.split(QStringLiteral(
"."))[0];
178 setSessionVariable(QStringLiteral(
"LANGUAGE"), language);
179 setSessionVariable(QStringLiteral(
"LANG"), locale);
180 setSessionVariable(QStringLiteral(
"LC_ALL"), locale);
184 QLocale::setDefault(QLocale(locale));
187 const QStringList units {
188 "ayatana-indicators.target",
189 "lomiri-location-service-trust-stored.service",
190 "pulseaudio-trust-stored.service",
191 "sync-monitor.service",
192 "maliit-server.service",
195 for (
const QString& unit : units) {
200void System::skipUntilFinishedPage()
203 settings.setValue(QStringLiteral(
"Wizard/SkipUntilFinishedPage"),
true);