shell: Simplify desktop file loading
By using known patterns for the desktop file name.
This commit is contained in:
parent
2ee0d35844
commit
4dd36b4279
3 changed files with 42 additions and 83 deletions
|
@ -123,82 +123,23 @@ cc_shell_model_new (void)
|
||||||
return g_object_new (CC_TYPE_SHELL_MODEL, NULL);
|
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
|
void
|
||||||
cc_shell_model_add_item (CcShellModel *model,
|
cc_shell_model_add_item (CcShellModel *model,
|
||||||
const gchar *category_name,
|
const gchar *category_name,
|
||||||
GMenuTreeEntry *item)
|
GMenuTreeEntry *item,
|
||||||
|
const char *id)
|
||||||
{
|
{
|
||||||
GAppInfo *appinfo = G_APP_INFO (gmenu_tree_entry_get_app_info (item));
|
GAppInfo *appinfo = G_APP_INFO (gmenu_tree_entry_get_app_info (item));
|
||||||
GIcon *icon = g_app_info_get_icon (appinfo);
|
GIcon *icon = g_app_info_get_icon (appinfo);
|
||||||
const gchar *name = g_app_info_get_name (appinfo);
|
const gchar *name = g_app_info_get_name (appinfo);
|
||||||
const gchar *desktop = gmenu_tree_entry_get_desktop_file_path (item);
|
const gchar *desktop = gmenu_tree_entry_get_desktop_file_path (item);
|
||||||
const gchar *comment = g_app_info_get_description (appinfo);
|
const gchar *comment = g_app_info_get_description (appinfo);
|
||||||
gchar *id;
|
|
||||||
GdkPixbuf *pixbuf = NULL;
|
GdkPixbuf *pixbuf = NULL;
|
||||||
GKeyFile *key_file;
|
const char * const * keywords;
|
||||||
gchar **keywords;
|
GDesktopAppInfo *app;
|
||||||
|
|
||||||
/* load the .desktop file since gnome-menus doesn't have a way to read
|
app = gmenu_tree_entry_get_app_info (item);
|
||||||
* custom properties from desktop files */
|
keywords = g_desktop_app_info_get_keywords (app);
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
g_key_file_free (key_file);
|
|
||||||
key_file = NULL;
|
|
||||||
|
|
||||||
pixbuf = load_pixbuf_for_gicon (icon);
|
pixbuf = load_pixbuf_for_gicon (icon);
|
||||||
|
|
||||||
|
@ -213,6 +154,5 @@ cc_shell_model_add_item (CcShellModel *model,
|
||||||
COL_KEYWORDS, keywords,
|
COL_KEYWORDS, keywords,
|
||||||
-1);
|
-1);
|
||||||
|
|
||||||
g_free (id);
|
g_object_unref (app);
|
||||||
g_strfreev (keywords);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,8 @@ CcShellModel *cc_shell_model_new (void);
|
||||||
|
|
||||||
void cc_shell_model_add_item (CcShellModel *model,
|
void cc_shell_model_add_item (CcShellModel *model,
|
||||||
const gchar *category_name,
|
const gchar *category_name,
|
||||||
GMenuTreeEntry *item);
|
GMenuTreeEntry *item,
|
||||||
|
const char *id);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -330,17 +330,7 @@ item_activated_cb (CcShellCategoryView *view,
|
||||||
gchar *desktop_file,
|
gchar *desktop_file,
|
||||||
GnomeControlCenter *shell)
|
GnomeControlCenter *shell)
|
||||||
{
|
{
|
||||||
GError *err = NULL;
|
cc_shell_set_active_panel_from_id (CC_SHELL (shell), id, NULL, 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@ -792,6 +782,20 @@ maybe_add_category_view (GnomeControlCenter *shell,
|
||||||
g_hash_table_insert (shell->priv->category_views, g_strdup (name), categoryview);
|
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
|
static void
|
||||||
reload_menu (GnomeControlCenter *shell)
|
reload_menu (GnomeControlCenter *shell)
|
||||||
{
|
{
|
||||||
|
@ -832,10 +836,24 @@ reload_menu (GnomeControlCenter *shell)
|
||||||
{
|
{
|
||||||
if (sub_next_type == GMENU_TREE_ITEM_ENTRY)
|
if (sub_next_type == GMENU_TREE_ITEM_ENTRY)
|
||||||
{
|
{
|
||||||
GMenuTreeEntry *item = gmenu_tree_iter_get_entry (sub_iter);
|
GMenuTreeEntry *item;
|
||||||
cc_shell_model_add_item (CC_SHELL_MODEL (shell->priv->store),
|
char *id;
|
||||||
dir_name,
|
|
||||||
item);
|
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);
|
gmenu_tree_item_unref (item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue