[gnome-control-center] shell: Simplify desktop file loading
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] shell: Simplify desktop file loading
- Date: Tue, 11 Dec 2012 16:13:06 +0000 (UTC)
commit 4dd36b42792ff26df293a64e1afdbaa8991569ad
Author: Bastien Nocera <hadess hadess net>
Date: Tue Dec 11 13:25:25 2012 +0100
shell: Simplify desktop file loading
By using known patterns for the desktop file name.
shell/cc-shell-model.c | 74 ++++--------------------------------------
shell/cc-shell-model.h | 3 +-
shell/gnome-control-center.c | 48 ++++++++++++++++++--------
3 files changed, 42 insertions(+), 83 deletions(-)
---
diff --git a/shell/cc-shell-model.c b/shell/cc-shell-model.c
index 08bcaa8..5ae2fbe 100644
--- a/shell/cc-shell-model.c
+++ b/shell/cc-shell-model.c
@@ -123,82 +123,23 @@ cc_shell_model_new (void)
return g_object_new (CC_TYPE_SHELL_MODEL, NULL);
}
-static gboolean
-desktop_entry_has_panel_category (GKeyFile *key_file)
-{
- char **strv;
- gsize len;
- int i;
-
- strv = g_key_file_get_string_list (key_file,
- "Desktop Entry",
- "Categories",
- &len,
- NULL);
- if (!strv)
- return FALSE;
-
- for (i = 0; strv[i]; i++)
- {
- if (g_str_equal (strv[i], GNOME_SETTINGS_PANEL_CATEGORY))
- {
- g_strfreev (strv);
- return TRUE;
- }
- }
-
- g_strfreev (strv);
-
- return FALSE;
-
-}
-
void
cc_shell_model_add_item (CcShellModel *model,
const gchar *category_name,
- GMenuTreeEntry *item)
+ GMenuTreeEntry *item,
+ const char *id)
{
GAppInfo *appinfo = G_APP_INFO (gmenu_tree_entry_get_app_info (item));
GIcon *icon = g_app_info_get_icon (appinfo);
const gchar *name = g_app_info_get_name (appinfo);
const gchar *desktop = gmenu_tree_entry_get_desktop_file_path (item);
const gchar *comment = g_app_info_get_description (appinfo);
- gchar *id;
GdkPixbuf *pixbuf = NULL;
- GKeyFile *key_file;
- gchar **keywords;
-
- /* load the .desktop file since gnome-menus doesn't have a way to read
- * custom properties from desktop files */
-
- key_file = g_key_file_new ();
- g_key_file_load_from_file (key_file, desktop, 0, NULL);
-
- id = g_key_file_get_string (key_file, "Desktop Entry",
- GNOME_SETTINGS_PANEL_ID_KEY, NULL);
-
- if (!id)
- {
- /* Refuse to load desktop files without a panel ID, but
- * with the X-GNOME-Settings-Panel category */
- if (desktop_entry_has_panel_category (key_file))
- {
- g_warning ("Not loading desktop file '%s' because it uses the "
- GNOME_SETTINGS_PANEL_CATEGORY
- " category but isn't a panel.",
- desktop);
- g_key_file_free (key_file);
- return;
- }
- id = g_strdup (gmenu_tree_entry_get_desktop_file_id (item));
- }
-
- keywords = g_key_file_get_locale_string_list (key_file, "Desktop Entry",
- GNOME_SETTINGS_PANEL_ID_KEYWORDS,
- NULL, NULL, NULL);
+ const char * const * keywords;
+ GDesktopAppInfo *app;
- g_key_file_free (key_file);
- key_file = NULL;
+ app = gmenu_tree_entry_get_app_info (item);
+ keywords = g_desktop_app_info_get_keywords (app);
pixbuf = load_pixbuf_for_gicon (icon);
@@ -213,6 +154,5 @@ cc_shell_model_add_item (CcShellModel *model,
COL_KEYWORDS, keywords,
-1);
- g_free (id);
- g_strfreev (keywords);
+ g_object_unref (app);
}
diff --git a/shell/cc-shell-model.h b/shell/cc-shell-model.h
index 5279b99..8f1f0b9 100644
--- a/shell/cc-shell-model.h
+++ b/shell/cc-shell-model.h
@@ -83,7 +83,8 @@ CcShellModel *cc_shell_model_new (void);
void cc_shell_model_add_item (CcShellModel *model,
const gchar *category_name,
- GMenuTreeEntry *item);
+ GMenuTreeEntry *item,
+ const char *id);
G_END_DECLS
diff --git a/shell/gnome-control-center.c b/shell/gnome-control-center.c
index aafc87e..fe142b1 100644
--- a/shell/gnome-control-center.c
+++ b/shell/gnome-control-center.c
@@ -330,17 +330,7 @@ item_activated_cb (CcShellCategoryView *view,
gchar *desktop_file,
GnomeControlCenter *shell)
{
- GError *err = NULL;
-
- if (!cc_shell_set_active_panel_from_id (CC_SHELL (shell), id, NULL, &err))
- {
- /* TODO: show message to user */
- if (err)
- {
- g_warning ("Could not active panel \"%s\": %s", id, err->message);
- g_error_free (err);
- }
- }
+ cc_shell_set_active_panel_from_id (CC_SHELL (shell), id, NULL, NULL);
}
static gboolean
@@ -792,6 +782,20 @@ maybe_add_category_view (GnomeControlCenter *shell,
g_hash_table_insert (shell->priv->category_views, g_strdup (name), categoryview);
}
+static char *
+get_id_for_menu_entry (GMenuTreeEntry *item)
+{
+ const char *desktop_name;
+
+ desktop_name = gmenu_tree_entry_get_desktop_file_id (item);
+ if (!g_str_has_prefix (desktop_name, "gnome-") ||
+ !g_str_has_suffix (desktop_name, "-panel.desktop"))
+ return NULL;
+
+ return g_strndup (desktop_name + strlen ("gnome-"),
+ strlen (desktop_name) - strlen ("-panel.desktop") - strlen ("gnome-"));
+}
+
static void
reload_menu (GnomeControlCenter *shell)
{
@@ -832,10 +836,24 @@ reload_menu (GnomeControlCenter *shell)
{
if (sub_next_type == GMENU_TREE_ITEM_ENTRY)
{
- GMenuTreeEntry *item = gmenu_tree_iter_get_entry (sub_iter);
- cc_shell_model_add_item (CC_SHELL_MODEL (shell->priv->store),
- dir_name,
- item);
+ GMenuTreeEntry *item;
+ char *id;
+
+ item = gmenu_tree_iter_get_entry (sub_iter);
+ id = get_id_for_menu_entry (item);
+
+ if (id != NULL &&
+ g_io_extension_point_get_extension_by_name (shell->priv->extension_point, id))
+ {
+ cc_shell_model_add_item (CC_SHELL_MODEL (shell->priv->store),
+ dir_name, item, id);
+ }
+ else
+ {
+ g_warning ("Not adding broken desktop file %s",
+ gmenu_tree_entry_get_desktop_file_id (item));
+ }
+ g_free (id);
gmenu_tree_item_unref (item);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]