2
* Copyright (C) 2010 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
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 General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
19
#include <gio/gdesktopappinfo.h>
21
#include "FavoriteStoreGSettings.h"
23
FavoriteStoreGSettings::FavoriteStoreGSettings ()
25
m_settings = g_settings_new ("com.canonical.Unity.Launcher");
32
FavoriteStoreGSettings::~FavoriteStoreGSettings ()
34
g_slist_foreach (m_favorites, (GFunc)g_free, NULL);
35
g_slist_free (m_favorites);
36
g_object_unref (m_settings);
40
FavoriteStoreGSettings::Refresh ()
45
g_slist_foreach (m_favorites, (GFunc)g_free, NULL);
46
g_slist_free (m_favorites);
48
favs = g_settings_get_strv (m_settings, "favorites");
50
while (favs[i] != NULL)
52
GDesktopAppInfo *info;
54
info = g_desktop_app_info_new (favs[i]);
56
if (info == NULL || g_desktop_app_info_get_filename (info) == NULL)
58
g_warning ("Unable to load GDesktopAppInfo for '%s'", favs[i]);
64
m_favorites = g_slist_append (m_favorites, g_strdup (g_desktop_app_info_get_filename (info)));
67
g_object_unref (info);
74
FavoriteStoreGSettings::GetFavorites ()
80
FavoriteStoreGSettings::AddFavorite (const char *desktop_path,
87
g_return_if_fail (desktop_path);
89
n_total_favs = g_slist_length (m_favorites) + 1;
91
char *favs[n_total_favs + 1];
92
favs[n_total_favs] = NULL;
94
for (f = m_favorites; f; f = f->next)
98
favs[i] = g_path_get_basename (desktop_path);
102
favs[i] = g_path_get_basename ((char *)f->data);
107
if (!g_settings_set_strv (m_settings, "favorites", favs))
108
g_warning ("Unable to add a new favorite");
111
while (favs[i] != NULL)
120
FavoriteStoreGSettings::RemoveFavorite (const char *desktop_path)
126
g_return_if_fail (desktop_path);
128
n_total_favs = g_slist_length (m_favorites) - 1;
130
char *favs[n_total_favs + 1];
131
favs[n_total_favs] = NULL;
133
for (f = m_favorites; f; f = f->next)
135
if (g_strcmp0 ((char *)f->data, desktop_path))
137
favs[i] = g_path_get_basename ((char *)f->data);
142
if (!g_settings_set_strv (m_settings, "favorites", favs))
143
g_warning ("Unable to add a new favorite");
146
while (favs[i] != NULL)
155
FavoriteStoreGSettings::MoveFavorite (const char *desktop_path,