2 * Copyright (C) 2018 The UBports project
3 * Copyright (C) 2014-2016 Canonical Ltd.
5 * This program is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 3, as published
7 * by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranties of
11 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
20#include <QDBusPendingCall>
21#include <QDBusMessage>
22#include <QDBusConnection>
23#include <QDBusMetaType>
35 // Register the argument needed for UpdateActivationEnvironment below
36 qDBusRegisterMetaType<QMap<QString,QString>>();
38 if(!wizardEnabled()) {
39 m_fsWatcher.addPath(wizardEnabledPath());
41 connect(&m_fsWatcher, &QFileSystemWatcher::fileChanged, this, &System::watcherFileChanged);
44QString System::wizardEnabledPath()
46 // Uses ubuntu-system-settings namespace for historic compatibility reasons
47 return QDir::home().filePath(QStringLiteral(".config/ubuntu-system-settings/wizard-has-run"));
50QString System::currentFrameworkPath()
52 QFileInfo f("/usr/share/click/frameworks/current");
53 return f.canonicalFilePath();
57wizardEnabled and isUpdate logic
59if wizard-has-run does NOT exist == is new install
60if wizard-has-run exists but does NOT match current framework == is update
61if wizard-has-run exists but does match current framework == show no wizard
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());
118 // For special cases check if wizardEnabledPath is a folder
119 if (QDir(wizardEnabledPath()).exists()) {
120 QDir(wizardEnabledPath()).removeRecursively();
122 QFile::copy(currentFrameworkPath(), wizardEnabledPath());
123 m_fsWatcher.addPath(wizardEnabledPath());
124 Q_EMIT wizardEnabledChanged();
125 Q_EMIT isUpdateChanged();
129void System::watcherFileChanged()
131 Q_EMIT wizardEnabledChanged();
132 Q_EMIT isUpdateChanged();
133 m_fsWatcher.removePath(wizardEnabledPath());
136void System::setSessionVariable(const QString &variable, const QString &value)
138 // We need to update both upstart's and DBus's environment
139 QProcess::startDetached(QStringLiteral("initctl set-env --global %1=%2").arg(variable, value));
141 QMap<QString,QString> valueMap;
142 valueMap.insert(variable, value);
144 QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.DBus"),
145 QStringLiteral("/org/freedesktop/DBus"),
146 QStringLiteral("org.freedesktop.DBus"),
147 QStringLiteral("UpdateActivationEnvironment"));
149 msg << QVariant::fromValue(valueMap);
150 QDBusConnection::sessionBus().asyncCall(msg);
153void System::updateSessionLocale(const QString &locale)
155 const QString language = locale.split(QStringLiteral("."))[0];
157 setSessionVariable(QStringLiteral("LANGUAGE"), language);
158 setSessionVariable(QStringLiteral("LANG"), locale);
159 setSessionVariable(QStringLiteral("LC_ALL"), locale);
161 // QLocale caches the default locale on startup, and Qt uses that cached
162 // copy when formatting dates. So manually update it here.
163 QLocale::setDefault(QLocale(locale));
165 // Restart bits of the session to pick up new language.
166 QProcess::startDetached(QStringLiteral("sh -c \"initctl emit indicator-services-end; \
167 initctl stop scope-registry; \
168 initctl stop smart-scopes-proxy; \
169 initctl emit --no-wait indicator-services-start; \
170 initctl restart --no-wait ubuntu-location-service-trust-stored; \
171 initctl restart --no-wait maliit-server; \
172 initctl restart --no-wait indicator-messages; \
173 initctl restart --no-wait unity8-dash\""));
176void System::skipUntilFinishedPage()
179 settings.setValue(QStringLiteral("Wizard/SkipUntilFinishedPage"), true);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list