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