shell: Simplify desktop file loading

By using known patterns for the desktop file name.
This commit is contained in:
Bastien Nocera 2012-12-11 13:25:25 +01:00
parent 2ee0d35844
commit 4dd36b4279
3 changed files with 42 additions and 83 deletions

View file

@ -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;
const char * const * keywords;
GDesktopAppInfo *app;
/* 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);
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);
}