20#include <QDBusPendingCall>
21#include <QDBusMessage>
22#include <QDBusConnection>
23#include <QDBusMetaType>
31#include <QStringBuilder>
33#include <initializer_list>
39 qDBusRegisterMetaType<QMap<QString,QString>>();
41 if(!wizardEnabled()) {
42 m_fsWatcher.addPath(wizardEnabledPath());
44 connect(&m_fsWatcher, &QFileSystemWatcher::fileChanged,
this, &System::watcherFileChanged);
47QString System::wizardEnabledPath()
49 return QDir::home().filePath(QStringLiteral(
".config/lomiri/wizard-has-run"));
52QString System::currentFrameworkPath()
54 QFileInfo f(
"/usr/share/click/frameworks/current");
55 return f.canonicalFilePath();
66bool System::wizardPathExists() {
67 return QFile::exists(wizardEnabledPath());
70bool System::wizardEnabled()
const
72 if (!wizardPathExists()) {
78QString System::readCurrentFramework()
80 QFile f(currentFrameworkPath());
81 if (!f.open(QFile::ReadOnly | QFile::Text))
return "";
86QString System::readWizardEnabled()
88 QFile f(wizardEnabledPath());
89 if (!f.open(QFile::ReadOnly | QFile::Text))
return "";
94QString System::version()
const
96 return readCurrentFramework();
99bool System::isUpdate()
const
101 if (!wizardPathExists()) {
105 return readCurrentFramework() != readWizardEnabled();
108void System::setWizardEnabled(
bool enabled)
110 if (wizardEnabled() == enabled && !isUpdate())
114 QFile::remove(wizardEnabledPath());
116 QDir(wizardEnabledPath()).mkpath(QStringLiteral(
".."));
117 if (QFile::exists(wizardEnabledPath())) {
118 QFile::remove(wizardEnabledPath());
121 if (QDir(wizardEnabledPath()).exists()) {
122 QDir(wizardEnabledPath()).removeRecursively();
124 if (!QFile::copy(currentFrameworkPath(), wizardEnabledPath())) {
126 QFile f(wizardEnabledPath());
127 f.open(QFile::WriteOnly);
129 m_fsWatcher.addPath(wizardEnabledPath());
130 Q_EMIT wizardEnabledChanged();
131 Q_EMIT isUpdateChanged();
135void System::watcherFileChanged()
137 Q_EMIT wizardEnabledChanged();
138 Q_EMIT isUpdateChanged();
139 m_fsWatcher.removePath(wizardEnabledPath());
142void System::setSessionVariable(
const QString &variable,
const QString &value)
145 QStringList vars = { variable % QChar(
'=') % value };
146 QDBusMessage systemdMsg = QDBusMessage::createMethodCall(QStringLiteral(
"org.freedesktop.systemd1"),
147 QStringLiteral(
"/org/freedesktop/systemd1"),
148 QStringLiteral(
"org.freedesktop.systemd1.Manager"),
149 QStringLiteral(
"SetEnvironment"));
150 systemdMsg << QVariant::fromValue(vars);
151 QDBusConnection::sessionBus().asyncCall(systemdMsg);
153 QMap<QString,QString> valueMap;
154 valueMap.insert(variable, value);
156 QDBusMessage dbusMsg = QDBusMessage::createMethodCall(QStringLiteral(
"org.freedesktop.DBus"),
157 QStringLiteral(
"/org/freedesktop/DBus"),
158 QStringLiteral(
"org.freedesktop.DBus"),
159 QStringLiteral(
"UpdateActivationEnvironment"));
161 dbusMsg << QVariant::fromValue(valueMap);
162 QDBusConnection::sessionBus().asyncCall(dbusMsg);
165void System::restartUnit(
const QString &unitName)
167 QDBusMessage systemdMsg = QDBusMessage::createMethodCall(QStringLiteral(
"org.freedesktop.systemd1"),
168 QStringLiteral(
"/org/freedesktop/systemd1"),
169 QStringLiteral(
"org.freedesktop.systemd1.Manager"),
170 QStringLiteral(
"TryRestartUnit"));
171 systemdMsg << QVariant::fromValue(unitName);
172 systemdMsg << QVariant::fromValue(QStringLiteral(
"replace"));
173 QDBusConnection::sessionBus().asyncCall(systemdMsg);
176void System::updateSessionLocale(
const QString &locale)
178 const QString language = locale.split(QStringLiteral(
"."))[0];
180 setSessionVariable(QStringLiteral(
"LANGUAGE"), language);
181 setSessionVariable(QStringLiteral(
"LANG"), locale);
182 setSessionVariable(QStringLiteral(
"LC_ALL"), locale);
186 QLocale::setDefault(QLocale(locale));
189 const QStringList units {
190 "ayatana-indicators.target",
191 "lomiri-location-service-trust-stored.service",
192 "pulseaudio-trust-stored.service",
193 "sync-monitor.service",
194 "maliit-server.service",
197 for (
const QString& unit : units) {
202void System::skipUntilFinishedPage()
205 settings.setValue(QStringLiteral(
"Wizard/SkipUntilFinishedPage"),
true);
209QString System::distroName()
const
211#ifdef LOMIRI_DISPLAYED_DISTRO_NAME
212 return QStringLiteral(LOMIRI_DISPLAYED_DISTRO_NAME);
214 for (
const QString &fileName : {
215 QStringLiteral(
"/etc/os-release"),
216 QStringLiteral(
"/usr/lib/os-release"),
218 QFile file(fileName);
219 if (!file.open(QIODevice::ReadOnly))
222 QTextStream fileIO(&file);
225 while (!(line = fileIO.readLine()).isEmpty()) {
226 if (line.startsWith(QStringLiteral(
"NAME="))) {
227 line = line.right(line.length() - 5);
229 line = line.replace(
"\"",
"");
236 return QStringLiteral(
"Lomiri");