20#include <QDBusPendingCall>
21#include <QDBusMessage>
22#include <QDBusConnection>
23#include <QDBusMetaType>
31#include <QStringBuilder>
40 qDBusRegisterMetaType<QMap<QString,QString>>();
42 if(!wizardEnabled()) {
43 m_fsWatcher.addPath(wizardEnabledPath());
45 connect(&m_fsWatcher, &QFileSystemWatcher::fileChanged,
this, &System::watcherFileChanged);
48QString System::wizardEnabledPath()
50 return QDir::home().filePath(QStringLiteral(
".config/lomiri/wizard-has-run"));
53QString System::currentFrameworkPath()
55 QFileInfo f(
"/usr/share/click/frameworks/current");
56 return f.canonicalFilePath();
67bool System::wizardPathExists() {
68 return QFile::exists(wizardEnabledPath());
71bool System::wizardEnabled()
const
73 if (!wizardPathExists()) {
79QString System::readCurrentFramework()
81 QFile f(currentFrameworkPath());
82 if (!f.open(QFile::ReadOnly | QFile::Text))
return "";
87QString System::readWizardEnabled()
89 QFile f(wizardEnabledPath());
90 if (!f.open(QFile::ReadOnly | QFile::Text))
return "";
95QString System::version()
const
97 return readCurrentFramework();
100bool System::isUpdate()
const
102 if (!wizardPathExists()) {
106 return readCurrentFramework() != readWizardEnabled();
109void System::setWizardEnabled(
bool enabled)
111 if (wizardEnabled() == enabled && !isUpdate())
115 QFile::remove(wizardEnabledPath());
117 QDir(wizardEnabledPath()).mkpath(QStringLiteral(
".."));
118 if (QFile::exists(wizardEnabledPath())) {
119 QFile::remove(wizardEnabledPath());
122 if (QDir(wizardEnabledPath()).exists()) {
123 QDir(wizardEnabledPath()).removeRecursively();
125 if (!QFile::copy(currentFrameworkPath(), wizardEnabledPath())) {
127 QFile f(wizardEnabledPath());
128 f.open(QFile::WriteOnly);
130 m_fsWatcher.addPath(wizardEnabledPath());
131 Q_EMIT wizardEnabledChanged();
132 Q_EMIT isUpdateChanged();
136void System::watcherFileChanged()
138 Q_EMIT wizardEnabledChanged();
139 Q_EMIT isUpdateChanged();
140 m_fsWatcher.removePath(wizardEnabledPath());
143void System::setSessionVariable(
const QString &variable,
const QString &value)
146 QStringList vars = { variable % QChar(
'=') % value };
147 QDBusMessage systemdMsg = QDBusMessage::createMethodCall(QStringLiteral(
"org.freedesktop.systemd1"),
148 QStringLiteral(
"/org/freedesktop/systemd1"),
149 QStringLiteral(
"org.freedesktop.systemd1.Manager"),
150 QStringLiteral(
"SetEnvironment"));
151 systemdMsg << QVariant::fromValue(vars);
152 QDBusConnection::sessionBus().asyncCall(systemdMsg);
154 QMap<QString,QString> valueMap;
155 valueMap.insert(variable, value);
157 QDBusMessage dbusMsg = QDBusMessage::createMethodCall(QStringLiteral(
"org.freedesktop.DBus"),
158 QStringLiteral(
"/org/freedesktop/DBus"),
159 QStringLiteral(
"org.freedesktop.DBus"),
160 QStringLiteral(
"UpdateActivationEnvironment"));
162 dbusMsg << QVariant::fromValue(valueMap);
163 QDBusConnection::sessionBus().asyncCall(dbusMsg);
166void System::restartUnit(
const QString &unitName)
168 QDBusMessage systemdMsg = QDBusMessage::createMethodCall(QStringLiteral(
"org.freedesktop.systemd1"),
169 QStringLiteral(
"/org/freedesktop/systemd1"),
170 QStringLiteral(
"org.freedesktop.systemd1.Manager"),
171 QStringLiteral(
"TryRestartUnit"));
172 systemdMsg << QVariant::fromValue(unitName);
173 systemdMsg << QVariant::fromValue(QStringLiteral(
"replace"));
174 QDBusConnection::sessionBus().asyncCall(systemdMsg);
177void System::updateSessionLocale(
const QString &locale)
179 const QString language = locale.split(QStringLiteral(
"."))[0];
181 setSessionVariable(QStringLiteral(
"LANGUAGE"), language);
182 setSessionVariable(QStringLiteral(
"LANG"), locale);
183 setSessionVariable(QStringLiteral(
"LC_ALL"), locale);
187 QLocale::setDefault(QLocale(locale));
190 const QStringList units {
191 "lomiri-indicators.target",
192 "lomiri-location-service-trust-stored.service",
193 "pulseaudio-trust-stored.service",
194 "lomiri-sync-monitor.service",
195 "maliit-server.service",
198 for (
const QString& unit : units) {
203void System::skipUntilFinishedPage()
206 settings.setValue(QStringLiteral(
"Wizard/SkipUntilFinishedPage"),
true);
210QString System::distroName()
const
212#ifdef LOMIRI_DISPLAYED_DISTRO_NAME
213 return QStringLiteral(LOMIRI_DISPLAYED_DISTRO_NAME);
215 g_autofree gchar * name = g_get_os_info(G_OS_INFO_KEY_NAME);
217 return QString::fromUtf8(gettext(
"Lomiri on %1"))
218 .arg(QString::fromLocal8Bit(name));
220 return QStringLiteral(
"Lomiri");