on 87f587d help sign in
unity8/plugins/Unity/Launcher/gsettings.cpp
70 lines 2.3 kB history raw
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Michael Zanetti <michael.zanetti@canonical.com>
18 */
20#include "gsettings.h"
22#include <QVariant>
24GSettings::GSettings(QObject *parent):
25 QObject(parent)
27 m_gSettings = new QGSettings("com.canonical.Unity.Launcher", "/com/canonical/unity/launcher/", this);
28 connect(m_gSettings, &QGSettings::changed, this, &GSettings::onSettingsChanged);
31QStringList GSettings::storedApplications() const
33 QStringList storedApps;
35 Q_FOREACH(const QString &entry, m_gSettings->get("items").toStringList()) {
36 if (entry.startsWith("application:///")) {
37 // convert legacy entries to new world appids
38 QString appId = entry;
39 // Transform "application://foobar.desktop" to "foobar"
40 appId.remove(QRegExp("^application:///"));
41 appId.remove(QRegExp(".desktop$"));
42 storedApps << appId;
43 } else if (entry.startsWith("appid://")) {
44 QString appId = entry;
45 appId.remove("appid://");
46 if (appId.split('/').count() == 3) {
47 // Strip current-user-version in case its there
48 appId = appId.split('/').first() + "_" + appId.split('/').at(1);
49 }
50 storedApps << appId;
51 }
52 }
53 return storedApps;
56void GSettings::setStoredApplications(const QStringList &storedApplications)
58 QStringList gSettingsList;
59 Q_FOREACH(const QString &entry, storedApplications) {
60 gSettingsList << QString("appid://%1").arg(entry);
61 }
62 m_gSettings->set("items", gSettingsList);
65void GSettings::onSettingsChanged(const QString &key)
67 if (key == "items") {
68 Q_EMIT changed();
69 }