on 8a62abb help sign in
unity8/plugins/Unity/Launcher/gsettings.cpp
73 lines 2.4 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 <QGSettings>
23#include <QVariant>
25GSettings::GSettings(QObject *parent):
26 QObject(parent)
31QStringList GSettings::storedApplications() const
33 QStringList storedApps;
35 QGSettings gSettings("com.canonical.Unity.Launcher", "/com/canonical/unity/launcher/");
37 QString settingsKey = "items";
39 // If "items" doesn't contain anything yet, import unity7's "favorites"
40 if (gSettings.get(settingsKey).toStringList().isEmpty()) {
41 settingsKey = "favorites";
42 }
44 Q_FOREACH(const QString &entry, gSettings.get(settingsKey).toStringList()) {
45 if (entry.startsWith("application://")) {
46 // convert legacy entries to new world appids
47 QString appId = entry;
48 // Transform "application://foobar.desktop" to "foobar"
49 appId.remove(QRegExp("^application://"));
50 appId.remove(QRegExp(".desktop$"));
51 storedApps << appId;
52 } else if (entry.startsWith("appid://")) {
53 QString appId = entry;
54 appId.remove("appid://");
55 if (appId.split('/').count() == 3) {
56 // Strip current-user-version in case its there
57 appId = appId.split('/').first() + "_" + appId.split('/').at(1);
58 }
59 storedApps << appId;
60 }
61 }
62 return storedApps;
65void GSettings::setStoredApplications(const QStringList &storedApplications)
67 QGSettings gSettings("com.canonical.Unity.Launcher", "/com/canonical/unity/launcher/");
68 QStringList gSettingsList;
69 Q_FOREACH(const QString &entry, storedApplications) {
70 gSettingsList << QString("appid://%1").arg(entry);
71 }
72 gSettings.set("items", gSettingsList);