2 * Copyright (C) 2014-2016 Canonical Ltd.
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
19#include <QDBusPendingCall>
20#include <QDBusMessage>
21#include <QDBusConnection>
22#include <QDBusMetaType>
34 // Register the argument needed for UpdateActivationEnvironment below
35 qDBusRegisterMetaType<QMap<QString,QString>>();
37 if(!wizardEnabled()) {
38 m_fsWatcher.addPath(wizardEnabledPath());
40 connect(&m_fsWatcher, &QFileSystemWatcher::fileChanged, this, &System::watcherFileChanged);
43QString System::wizardEnabledPath()
45 // Uses ubuntu-system-settings namespace for historic compatibility reasons
46 return QDir::home().filePath(QStringLiteral(".config/ubuntu-system-settings/wizard-has-run"));
49QString System::currentFrameworkPath()
51 return QDir::home().filePath(QStringLiteral("/usr/share/click/frameworks/current"));
55wizardEnabled and isUpdate logic
57if wizard-has-run does NOT exists == is new install
58if wizard-has-run does exists but does NOT match current framework == is update
59if wizard-has-run does exists but does match current framework == show no wizard
62bool System::wizardPathExists() {
63 return QFile::exists(wizardEnabledPath());
66bool System::wizardEnabled() const
68 if (!wizardPathExists())
73QString System::readCurrentFramework()
75 QFile f(currentFrameworkPath());
76 if (!f.open(QFile::ReadOnly | QFile::Text)) return "";
81QString System::readWizardEnabled()
83 QFile f(wizardEnabledPath());
84 if (!f.open(QFile::ReadOnly | QFile::Text)) return "";
89QString System::version() const
91 return readCurrentFramework();
94bool System::isUpdate() const
96 if (!wizardPathExists())
99 return readCurrentFramework() != readWizardEnabled();
102void System::setWizardEnabled(bool enabled)
104 if (wizardEnabled() == enabled && !isUpdate())
108 QFile::remove(wizardEnabledPath());
110 QDir(wizardEnabledPath()).mkpath(QStringLiteral(".."));
111 if (QFile::exists(wizardEnabledPath()))
112 QFile::remove(wizardEnabledPath());
113 QFile::copy(currentFrameworkPath(), wizardEnabledPath());
114 m_fsWatcher.addPath(wizardEnabledPath());
115 Q_EMIT wizardEnabledChanged();
116 Q_EMIT isUpdateChanged();
120void System::watcherFileChanged()
122 Q_EMIT wizardEnabledChanged();
123 Q_EMIT isUpdateChanged();
124 m_fsWatcher.removePath(wizardEnabledPath());
127void System::setSessionVariable(const QString &variable, const QString &value)
129 // We need to update both upstart's and DBus's environment
130 QProcess::startDetached(QStringLiteral("initctl set-env --global %1=%2").arg(variable, value));
132 QMap<QString,QString> valueMap;
133 valueMap.insert(variable, value);
135 QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.DBus"),
136 QStringLiteral("/org/freedesktop/DBus"),
137 QStringLiteral("org.freedesktop.DBus"),
138 QStringLiteral("UpdateActivationEnvironment"));
140 msg << QVariant::fromValue(valueMap);
141 QDBusConnection::sessionBus().asyncCall(msg);
144void System::updateSessionLocale(const QString &locale)
146 const QString language = locale.split(QStringLiteral("."))[0];
148 setSessionVariable(QStringLiteral("LANGUAGE"), language);
149 setSessionVariable(QStringLiteral("LANG"), locale);
150 setSessionVariable(QStringLiteral("LC_ALL"), locale);
152 // QLocale caches the default locale on startup, and Qt uses that cached
153 // copy when formatting dates. So manually update it here.
154 QLocale::setDefault(QLocale(locale));
156 // Restart bits of the session to pick up new language.
157 QProcess::startDetached(QStringLiteral("sh -c \"initctl emit indicator-services-end; \
158 initctl stop scope-registry; \
159 initctl stop smart-scopes-proxy; \
160 initctl emit --no-wait indicator-services-start; \
161 initctl restart --no-wait ubuntu-location-service-trust-stored; \
162 initctl restart --no-wait maliit-server; \
163 initctl restart --no-wait indicator-messages; \
164 initctl restart --no-wait unity8-dash\""));
167void System::skipUntilFinishedPage()
170 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