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::updateSessionLocale(
const QString &locale)
165 const QString language = locale.split(QStringLiteral(
"."))[0];
167 setSessionVariable(QStringLiteral(
"LANGUAGE"), language);
168 setSessionVariable(QStringLiteral(
"LANG"), locale);
169 setSessionVariable(QStringLiteral(
"LC_ALL"), locale);
173 QLocale::setDefault(QLocale(locale));
179void System::skipUntilFinishedPage()
182 settings.setValue(QStringLiteral(
"Wizard/SkipUntilFinishedPage"),
true);