2
* Copyright (c) 2009, 2010 Intel, Inc.
3
* Copyright (c) 2010 Red Hat, Inc.
5
* The Control Center is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by the
7
* Free Software Foundation; either version 2 of the License, or (at your
8
* option) any later version.
10
* The Control Center is distributed in the hope that it will be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15
* You should have received a copy of the GNU General Public License along
16
* with the Control Center; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
* Author: Thomas Wood <thos@gnome.org>
22
#include "cc-shell-model.h"
25
#define GNOME_SETTINGS_PANEL_ID_KEY "X-GNOME-Settings-Panel"
26
#define GNOME_SETTINGS_PANEL_CATEGORY GNOME_SETTINGS_PANEL_ID_KEY
27
#define GNOME_SETTINGS_PANEL_ID_KEYWORDS "Keywords"
30
G_DEFINE_TYPE (CcShellModel, cc_shell_model, GTK_TYPE_LIST_STORE)
33
load_pixbuf_for_gicon (GIcon *icon)
36
GtkIconInfo *icon_info;
37
GdkPixbuf *pixbuf = NULL;
43
theme = gtk_icon_theme_get_default ();
45
icon_info = gtk_icon_theme_lookup_by_gicon (theme, icon,
46
32, GTK_ICON_LOOKUP_FORCE_SIZE);
49
pixbuf = gtk_icon_info_load_icon (icon_info, &err);
52
g_warning ("Could not load icon '%s': %s",
53
gtk_icon_info_get_filename (icon_info), err->message);
57
gtk_icon_info_free (icon_info);
61
g_warning ("Could not find icon");
68
icon_theme_changed (GtkIconTheme *theme,
75
model = GTK_TREE_MODEL (self);
76
cont = gtk_tree_model_get_iter_first (model, &iter);
82
gtk_tree_model_get (model, &iter,
85
pixbuf = load_pixbuf_for_gicon (icon);
86
g_object_unref (icon);
87
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
91
cont = gtk_tree_model_iter_next (model, &iter);
96
cc_shell_model_class_init (CcShellModelClass *klass)
101
cc_shell_model_init (CcShellModel *self)
103
GType types[] = {G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
104
GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_ICON, G_TYPE_STRV};
106
gtk_list_store_set_column_types (GTK_LIST_STORE (self),
109
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self), COL_NAME,
112
g_signal_connect (G_OBJECT (gtk_icon_theme_get_default ()), "changed",
113
G_CALLBACK (icon_theme_changed), self);
117
cc_shell_model_new (void)
119
return g_object_new (CC_TYPE_SHELL_MODEL, NULL);
123
desktop_entry_has_panel_category (GKeyFile *key_file)
129
strv = g_key_file_get_string_list (key_file,
137
for (i = 0; strv[i]; i++)
139
if (g_str_equal (strv[i], GNOME_SETTINGS_PANEL_CATEGORY))
153
cc_shell_model_add_item (CcShellModel *model,
154
const gchar *category_name,
155
GMenuTreeEntry *item)
157
GAppInfo *appinfo = G_APP_INFO (gmenu_tree_entry_get_app_info (item));
158
GIcon *icon = g_app_info_get_icon (appinfo);
159
const gchar *name = g_app_info_get_name (appinfo);
160
const gchar *desktop = gmenu_tree_entry_get_desktop_file_path (item);
161
const gchar *comment = g_app_info_get_description (appinfo);
163
GdkPixbuf *pixbuf = NULL;
167
/* load the .desktop file since gnome-menus doesn't have a way to read
168
* custom properties from desktop files */
170
key_file = g_key_file_new ();
171
g_key_file_load_from_file (key_file, desktop, 0, NULL);
173
id = g_key_file_get_string (key_file, "Desktop Entry",
174
GNOME_SETTINGS_PANEL_ID_KEY, NULL);
178
/* Refuse to load desktop files without a panel ID, but
179
* with the X-GNOME-Settings-Panel category */
180
if (desktop_entry_has_panel_category (key_file))
182
g_warning ("Not loading desktop file '%s' because it uses the "
183
GNOME_SETTINGS_PANEL_CATEGORY
184
" category but isn't a panel.",
186
g_key_file_free (key_file);
189
id = g_strdup (gmenu_tree_entry_get_desktop_file_id (item));
192
keywords = g_key_file_get_locale_string_list (key_file, "Desktop Entry",
193
GNOME_SETTINGS_PANEL_ID_KEYWORDS,
196
g_key_file_free (key_file);
199
pixbuf = load_pixbuf_for_gicon (icon);
201
gtk_list_store_insert_with_values (GTK_LIST_STORE (model), NULL, 0,
203
COL_DESKTOP_FILE, desktop,
206
COL_CATEGORY, category_name,
207
COL_DESCRIPTION, comment,
209
COL_KEYWORDS, keywords,
213
g_strfreev (keywords);