Unity 8
 All Classes Functions
gsettings.cpp
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  */
19 
20 #include "gsettings.h"
21 
22 #include <QGSettings>
23 #include <QVariant>
24 
25 GSettings::GSettings(QObject *parent):
26  QObject(parent)
27 {
28 
29 }
30 
31 QStringList GSettings::storedApplications() const
32 {
33  QStringList storedApps;
34 
35  QGSettings gSettings("com.canonical.Unity.Launcher", "/com/canonical/unity/launcher/");
36 
37  Q_FOREACH(const QString &entry, gSettings.get("items").toStringList()) {
38  if (entry.startsWith("application:///")) {
39  // convert legacy entries to new world appids
40  QString appId = entry;
41  // Transform "application://foobar.desktop" to "foobar"
42  appId.remove(QRegExp("^application:///"));
43  appId.remove(QRegExp(".desktop$"));
44  storedApps << appId;
45  } else if (entry.startsWith("appid://")) {
46  QString appId = entry;
47  appId.remove("appid://");
48  if (appId.split('/').count() == 3) {
49  // Strip current-user-version in case its there
50  appId = appId.split('/').first() + "_" + appId.split('/').at(1);
51  }
52  storedApps << appId;
53  }
54  }
55  return storedApps;
56 }
57 
58 void GSettings::setStoredApplications(const QStringList &storedApplications)
59 {
60  QGSettings gSettings("com.canonical.Unity.Launcher", "/com/canonical/unity/launcher/");
61  QStringList gSettingsList;
62  Q_FOREACH(const QString &entry, storedApplications) {
63  gSettingsList << QString("appid://%1").arg(entry);
64  }
65  gSettings.set("items", gSettingsList);
66 }