16
14
* with this program. If not, see <http://www.gnu.org/licenses/>.
20
19
#include <QDBusInterface>
21
#include <QDBusPendingCall>
22
#include <QDBusPendingReply>
20
#include <QDBusMetaType>
24
25
#include <QProcess>
27
#define HERE_IFACE "com.ubuntu.location.providers.here.AccountsService"
28
#define ENABLED_PROP "LicenseAccepted"
29
#define PATH_PROP "LicenseBasePath"
35
m_hereLicensePath(" ") // use a single space to indicate it is unasssigned
37
m_accounts = new QDBusInterface("org.freedesktop.Accounts",
38
"/org/freedesktop/Accounts/User" + QString::number(geteuid()),
39
"org.freedesktop.DBus.Properties",
40
QDBusConnection::systemBus(),
43
m_accounts->connection().connect(m_accounts->service(),
45
m_accounts->interface(),
48
SLOT(propertiesChanged(QString, QVariantMap, QStringList)));
50
QDBusPendingCall call = m_accounts->asyncCall("Get", HERE_IFACE, PATH_PROP);
51
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
52
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher *)),
53
this, SLOT(getHereLicensePathFinished(QDBusPendingCallWatcher *)));
56
void System::propertiesChanged(const QString &interface, const QVariantMap &changed, const QStringList &invalid)
58
if (interface == HERE_IFACE) {
59
if (changed.contains(ENABLED_PROP)) {
60
m_hereEnabled = changed[ENABLED_PROP].toBool();
61
Q_EMIT hereEnabledChanged();
62
} else if (invalid.contains(ENABLED_PROP)) {
63
QDBusPendingCall call = m_accounts->asyncCall("Get", HERE_IFACE, ENABLED_PROP);
64
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
65
QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher *)),
66
this, SLOT(getHereEnabledFinished(QDBusPendingCallWatcher *)));
71
void System::getHereEnabledFinished(QDBusPendingCallWatcher *watcher)
73
QDBusPendingReply<QVariant> reply = *watcher;
74
if (!reply.isError()) {
75
QVariant value = reply.argumentAt<0>();
76
m_hereEnabled = value.toBool();
77
Q_EMIT hereEnabledChanged();
79
watcher->deleteLater();
82
void System::getHereLicensePathFinished(QDBusPendingCallWatcher *watcher)
84
QDBusPendingReply<QVariant> reply = *watcher;
86
m_hereLicensePath = "";
88
if (!reply.isError()) {
89
QVariant value = reply.argumentAt<0>();
90
if (QFile::exists(value.toString())) {
91
m_hereLicensePath = value.toString();
95
Q_EMIT hereLicensePathChanged();
97
watcher->deleteLater();
100
bool System::hereEnabled() const
102
return m_hereEnabled;
105
void System::setHereEnabled(bool enabled)
107
m_accounts->asyncCall("Set", HERE_IFACE, ENABLED_PROP, QVariant::fromValue(QDBusVariant(enabled)));
110
QString System::hereLicensePath() const
112
return m_hereLicensePath;
115
void System::updateSessionLanguage()
117
QProcess::startDetached("sh -c \"initctl start ubuntu-system-settings-wizard-set-lang; initctl emit --no-wait indicator-services-start; initctl start --no-wait maliit-server\"");
31
// Register the argument needed for UpdateActivationEnvironment below
32
qDBusRegisterMetaType<QMap<QString,QString>>();
34
m_fsWatcher.addPath(wizardEnabledPath());
35
connect(&m_fsWatcher, SIGNAL(fileChanged(const QString &)),
36
this, SIGNAL(wizardEnabledChanged()));
39
QString System::wizardEnabledPath()
41
// Uses ubuntu-system-settings namespace for historic compatibility reasons
42
return QDir::home().filePath(".config/ubuntu-system-settings/wizard-has-run");
45
bool System::wizardEnabled() const
47
return !QFile::exists(wizardEnabledPath());
50
void System::setWizardEnabled(bool enabled)
52
if (wizardEnabled() == enabled)
56
QFile::remove(wizardEnabledPath());
58
QDir(wizardEnabledPath()).mkpath("..");
59
QFile(wizardEnabledPath()).open(QIODevice::WriteOnly);
60
m_fsWatcher.addPath(wizardEnabledPath());
61
wizardEnabledChanged();
65
void System::setSessionVariable(const QString &variable, const QString &value)
67
// We need to update both upstart's and DBus's environment
68
QProcess::execute(QString("initctl set-env --global %1=%2").arg(variable, value));
70
QDBusInterface iface("org.freedesktop.DBus",
71
"/org/freedesktop/DBus",
72
"org.freedesktop.DBus",
73
QDBusConnection::sessionBus());
75
QMap<QString,QString> valueMap;
76
valueMap.insert(variable, value);
77
iface.call("UpdateActivationEnvironment", QVariant::fromValue(valueMap));
80
void System::updateSessionLanguage(const QString &locale)
82
QString language = locale.split(".")[0];
84
setSessionVariable("LANGUAGE", language);
85
setSessionVariable("LANG", locale);
86
setSessionVariable("LC_ALL", locale);
88
// QLocale caches the default locale on startup, and Qt uses that cached
89
// copy when formatting dates. So manually update it here.
90
QLocale::setDefault(QLocale(locale));
92
// Restart bits of the session to pick up new language.
93
QProcess::startDetached("sh -c \"initctl emit indicator-services-end; \
94
initctl stop scope-registry; \
95
initctl stop smart-scopes-proxy; \
96
initctl emit --no-wait indicator-services-start; \
97
initctl restart --no-wait maliit-server; \
98
initctl restart --no-wait unity8-dash\"");