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 "X-GNOME-Keywords"
30
G_DEFINE_TYPE (CcShellModel, cc_shell_model, GTK_TYPE_LIST_STORE)
33
load_pixbuf_for_string (const char *icon)
43
theme = gtk_icon_theme_get_default ();
48
pixbuf = gdk_pixbuf_new_from_file_at_scale (icon, 32, 32, TRUE, &err);
52
if (g_str_has_suffix (icon, ".png"))
53
icon2 = g_strndup (icon, strlen (icon) - strlen (".png"));
55
pixbuf = gtk_icon_theme_load_icon (theme,
56
icon2 ? icon2 : icon, 32,
57
GTK_ICON_LOOKUP_FORCE_SIZE,
63
g_warning ("Could not load icon '%s': %s", icon2 ? icon2 : icon,
74
icon_theme_changed (GtkIconTheme *theme,
81
model = GTK_TREE_MODEL (self);
82
cont = gtk_tree_model_get_iter_first (model, &iter);
88
gtk_tree_model_get (model, &iter,
91
pixbuf = load_pixbuf_for_string (icon);
93
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
97
cont = gtk_tree_model_iter_next (model, &iter);
102
cc_shell_model_class_init (CcShellModelClass *klass)
107
cc_shell_model_init (CcShellModel *self)
109
GType types[] = {G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
110
GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRV};
112
gtk_list_store_set_column_types (GTK_LIST_STORE (self),
115
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (self), COL_NAME,
118
g_signal_connect (G_OBJECT (gtk_icon_theme_get_default ()), "changed",
119
G_CALLBACK (icon_theme_changed), self);
123
cc_shell_model_new (void)
125
return g_object_new (CC_TYPE_SHELL_MODEL, NULL);
129
desktop_entry_has_panel_category (GKeyFile *key_file)
135
strv = g_key_file_get_string_list (key_file,
143
for (i = 0; strv[i]; i++)
145
if (g_str_equal (strv[i], GNOME_SETTINGS_PANEL_CATEGORY))
159
cc_shell_model_add_item (CcShellModel *model,
160
const gchar *category_name,
161
GMenuTreeEntry *item)
163
const gchar *icon = gmenu_tree_entry_get_icon (item);
164
const gchar *name = gmenu_tree_entry_get_name (item);
165
const gchar *desktop = gmenu_tree_entry_get_desktop_file_path (item);
166
const gchar *comment = gmenu_tree_entry_get_comment (item);
168
GdkPixbuf *pixbuf = NULL;
169
gchar *search_target;
173
/* load the .desktop file since gnome-menus doesn't have a way to read
174
* custom properties from desktop files */
176
key_file = g_key_file_new ();
177
g_key_file_load_from_file (key_file, desktop, 0, NULL);
179
id = g_key_file_get_string (key_file, "Desktop Entry",
180
GNOME_SETTINGS_PANEL_ID_KEY, NULL);
184
/* Refuse to load desktop files without a panel ID, but
185
* with the X-GNOME-Settings-Panel category */
186
if (desktop_entry_has_panel_category (key_file))
188
g_warning ("Not loading desktop file '%s' because it uses the "
189
GNOME_SETTINGS_PANEL_CATEGORY
190
" category but isn't a panel.",
192
g_key_file_free (key_file);
195
id = g_strdup (gmenu_tree_entry_get_desktop_file_id (item));
198
keywords = g_key_file_get_locale_string_list (key_file, "Desktop Entry",
199
GNOME_SETTINGS_PANEL_ID_KEYWORDS,
202
g_key_file_free (key_file);
205
pixbuf = load_pixbuf_for_string (icon);
207
search_target = g_strconcat (name, " - ", comment, NULL);
209
gtk_list_store_insert_with_values (GTK_LIST_STORE (model), NULL, 0,
211
COL_DESKTOP_FILE, desktop,
214
COL_CATEGORY, category_name,
215
COL_SEARCH_TARGET, search_target,
217
COL_KEYWORDS, keywords,
221
g_free (search_target);
222
g_strfreev (keywords);