app: Port to be based on GDesktopAppInfo

We weren't using the GMenuTreeEntry for anything special anymore,
so remove it.

https://bugzilla.gnome.org/show_bug.cgi?id=698486
This commit is contained in:
Jasper St. Pierre 2013-02-08 22:52:25 -05:00
parent f165cc23c0
commit 982feb85c1
4 changed files with 48 additions and 92 deletions

View File

@ -12,9 +12,9 @@ G_BEGIN_DECLS
ShellApp* _shell_app_new_for_window (MetaWindow *window);
ShellApp* _shell_app_new (GMenuTreeEntry *entry);
ShellApp* _shell_app_new (GDesktopAppInfo *info);
void _shell_app_set_entry (ShellApp *app, GMenuTreeEntry *entry);
void _shell_app_set_app_info (ShellApp *app, GDesktopAppInfo *info);
void _shell_app_handle_startup_sequence (ShellApp *app, SnStartupSequence *sequence);

View File

@ -326,7 +326,6 @@ on_apps_tree_changed_cb (GMenuTree *tree,
{
const char *id = key;
GMenuTreeEntry *entry = value;
GMenuTreeEntry *old_entry;
char *prefix;
ShellApp *app;
GDesktopAppInfo *info;
@ -342,53 +341,36 @@ on_apps_tree_changed_cb (GMenuTree *tree,
else
g_free (prefix);
info = gmenu_tree_entry_get_app_info (entry);
app = g_hash_table_lookup (self->priv->id_to_app, id);
if (app != NULL)
{
/* We hold a reference to the original entry temporarily,
* because otherwise the hash table would be referencing
* potentially free'd memory until we replace it below with
* the new data.
*/
old_entry = shell_app_get_tree_entry (app);
gmenu_tree_item_ref (old_entry);
_shell_app_set_entry (app, entry);
g_object_ref (app); /* Extra ref, removed in _replace below */
}
else
{
old_entry = NULL;
app = _shell_app_new (entry);
}
/* Note that "id" is owned by app->entry. Since we're always
* setting a new entry, even if the app already exists in the
* hash table we need to replace the key so that the new id
* string is pointed to.
*/
g_hash_table_replace (self->priv->id_to_app, (char*)id, app);
if (!gmenu_tree_entry_get_is_nodisplay_recurse (entry))
g_hash_table_replace (self->priv->visible_id_to_app, (char*)id, app);
if (old_entry)
{
GDesktopAppInfo *old_info;
const gchar *old_startup_wm_class;
old_info = gmenu_tree_entry_get_app_info (old_entry);
old_info = shell_app_get_app_info (app);
old_startup_wm_class = g_desktop_app_info_get_startup_wm_class (old_info);
if (old_startup_wm_class)
g_hash_table_remove (self->priv->startup_wm_class_to_app, old_startup_wm_class);
_shell_app_set_app_info (app, info);
g_object_ref (app); /* Extra ref, removed in _replace below */
}
else
{
app = _shell_app_new (info);
}
info = gmenu_tree_entry_get_app_info (entry);
g_hash_table_replace (self->priv->id_to_app, (char*)id, app);
if (!gmenu_tree_entry_get_is_nodisplay_recurse (entry))
g_hash_table_replace (self->priv->visible_id_to_app, (char*)id, app);
startup_wm_class = g_desktop_app_info_get_startup_wm_class (info);
if (startup_wm_class)
g_hash_table_replace (self->priv->startup_wm_class_to_app,
(char*)startup_wm_class, g_object_ref (app));
if (old_entry)
gmenu_tree_item_unref (old_entry);
}
/* Now iterate over the apps again; we need to unreference any apps
* which have been removed. The JS code may still be holding a

View File

@ -53,7 +53,7 @@ typedef struct {
* SECTION:shell-app
* @short_description: Object representing an application
*
* This object wraps a #GMenuTreeEntry, providing methods and signals
* This object wraps a #GDesktopAppInfo, providing methods and signals
* primarily useful for running applications.
*/
struct _ShellApp
@ -64,7 +64,7 @@ struct _ShellApp
ShellAppState state;
GMenuTreeEntry *entry; /* If NULL, this app is backed by one or more
GDesktopAppInfo *info; /* If NULL, this app is backed by one or more
* MetaWindow. For purposes of app title
* etc., we use the first window added,
* because it's most likely to be what we
@ -137,15 +137,15 @@ shell_app_get_property (GObject *gobject,
const char *
shell_app_get_id (ShellApp *app)
{
if (app->entry)
return gmenu_tree_entry_get_desktop_file_id (app->entry);
if (app->info)
return g_app_info_get_id (G_APP_INFO (app->info));
return app->window_id_string;
}
static MetaWindow *
window_backed_app_get_window (ShellApp *app)
{
g_assert (app->entry == NULL);
g_assert (app->info == NULL);
g_assert (app->running_state);
g_assert (app->running_state->windows);
return app->running_state->windows->data;
@ -194,10 +194,10 @@ shell_app_create_icon_texture (ShellApp *app,
ret = NULL;
if (app->entry == NULL)
if (app->info == NULL)
return window_backed_app_get_icon (app, size);
icon = g_app_info_get_icon (G_APP_INFO (gmenu_tree_entry_get_app_info (app->entry)));
icon = g_app_info_get_icon (G_APP_INFO (app->info));
if (icon != NULL)
ret = st_texture_cache_load_gicon (st_texture_cache_get_default (), NULL, icon, size);
@ -245,7 +245,7 @@ shell_app_create_faded_icon_cpu (StTextureCache *cache,
info = NULL;
icon = g_app_info_get_icon (G_APP_INFO (gmenu_tree_entry_get_app_info (app->entry)));
icon = g_app_info_get_icon (G_APP_INFO (app->info));
if (icon != NULL)
{
info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (),
@ -347,7 +347,7 @@ shell_app_get_faded_icon (ShellApp *app, int size, ClutterTextDirection directio
* property tracking bits, and this helps us visually distinguish
* app-tracked from not.
*/
if (!app->entry)
if (!app->info)
return window_backed_app_get_icon (app, size);
/* Use icon: prefix so that we get evicted from the cache on
@ -384,8 +384,8 @@ shell_app_get_faded_icon (ShellApp *app, int size, ClutterTextDirection directio
const char *
shell_app_get_name (ShellApp *app)
{
if (app->entry)
return g_app_info_get_name (G_APP_INFO (gmenu_tree_entry_get_app_info (app->entry)));
if (app->info)
return g_app_info_get_name (G_APP_INFO (app->info));
else
{
MetaWindow *window = window_backed_app_get_window (app);
@ -401,8 +401,8 @@ shell_app_get_name (ShellApp *app)
const char *
shell_app_get_description (ShellApp *app)
{
if (app->entry)
return g_app_info_get_description (G_APP_INFO (gmenu_tree_entry_get_app_info (app->entry)));
if (app->info)
return g_app_info_get_description (G_APP_INFO (app->info));
else
return NULL;
}
@ -417,7 +417,7 @@ shell_app_get_description (ShellApp *app)
gboolean
shell_app_is_window_backed (ShellApp *app)
{
return app->entry == NULL;
return app->info == NULL;
}
typedef struct {
@ -670,7 +670,7 @@ void
shell_app_open_new_window (ShellApp *app,
int workspace)
{
g_return_if_fail (app->entry != NULL);
g_return_if_fail (app->info != NULL);
/* Here we just always launch the application again, even if we know
* it was already running. For most applications this
@ -865,25 +865,24 @@ _shell_app_new_for_window (MetaWindow *window)
}
ShellApp *
_shell_app_new (GMenuTreeEntry *info)
_shell_app_new (GDesktopAppInfo *info)
{
ShellApp *app;
app = g_object_new (SHELL_TYPE_APP, NULL);
_shell_app_set_entry (app, info);
_shell_app_set_app_info (app, info);
return app;
}
void
_shell_app_set_entry (ShellApp *app,
GMenuTreeEntry *entry)
_shell_app_set_app_info (ShellApp *app,
GDesktopAppInfo *info)
{
if (app->entry != NULL)
gmenu_tree_item_unref (app->entry);
app->entry = gmenu_tree_item_ref (entry);
g_clear_object (&app->info);
app->info = g_object_ref (info);
if (app->name_collation_key != NULL)
g_free (app->name_collation_key);
app->name_collation_key = g_utf8_collate_key (shell_app_get_name (app), -1);
@ -1188,7 +1187,6 @@ shell_app_launch (ShellApp *app,
char **startup_id,
GError **error)
{
GDesktopAppInfo *gapp;
GdkAppLaunchContext *context;
gboolean ret;
ShellGlobal *global;
@ -1198,7 +1196,7 @@ shell_app_launch (ShellApp *app,
if (startup_id)
*startup_id = NULL;
if (app->entry == NULL)
if (app->info == NULL)
{
MetaWindow *window = window_backed_app_get_window (app);
/* We can't pass URIs into a window; shouldn't hit this
@ -1224,8 +1222,7 @@ shell_app_launch (ShellApp *app,
gdk_app_launch_context_set_timestamp (context, timestamp);
gdk_app_launch_context_set_desktop (context, workspace);
gapp = gmenu_tree_entry_get_app_info (app->entry);
ret = g_desktop_app_info_launch_uris_as_manager (gapp, uris,
ret = g_desktop_app_info_launch_uris_as_manager (app->info, uris,
G_APP_LAUNCH_CONTEXT (context),
G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
NULL, NULL,
@ -1245,21 +1242,7 @@ shell_app_launch (ShellApp *app,
GDesktopAppInfo *
shell_app_get_app_info (ShellApp *app)
{
if (app->entry)
return gmenu_tree_entry_get_app_info (app->entry);
return NULL;
}
/**
* shell_app_get_tree_entry:
* @app: a #ShellApp
*
* Returns: (transfer none): The #GMenuTreeEntry for this app, or %NULL if backed by a window
*/
GMenuTreeEntry *
shell_app_get_tree_entry (ShellApp *app)
{
return app->entry;
return app->info;
}
static void
@ -1374,24 +1357,22 @@ shell_app_init_search_data (ShellApp *app)
const char *exec;
const char * const *keywords;
char *normalized_exec;
GDesktopAppInfo *appinfo;
appinfo = gmenu_tree_entry_get_app_info (app->entry);
name = g_app_info_get_name (G_APP_INFO (appinfo));
name = g_app_info_get_name (G_APP_INFO (app->info));
app->casefolded_name = shell_util_normalize_casefold_and_unaccent (name);
generic_name = g_desktop_app_info_get_generic_name (appinfo);
generic_name = g_desktop_app_info_get_generic_name (app->info);
if (generic_name)
app->casefolded_generic_name = shell_util_normalize_casefold_and_unaccent (generic_name);
else
app->casefolded_generic_name = NULL;
exec = g_app_info_get_executable (G_APP_INFO (appinfo));
exec = g_app_info_get_executable (G_APP_INFO (app->info));
normalized_exec = shell_util_normalize_casefold_and_unaccent (exec);
app->casefolded_exec = trim_exec_line (normalized_exec);
g_free (normalized_exec);
keywords = g_desktop_app_info_get_keywords (appinfo);
keywords = g_desktop_app_info_get_keywords (app->info);
if (keywords)
{
@ -1512,16 +1493,14 @@ _shell_app_do_match (ShellApp *app,
GSList **substring_results)
{
ShellAppSearchMatch match;
GAppInfo *appinfo;
g_assert (app != NULL);
/* Skip window-backed apps */
appinfo = (GAppInfo*)shell_app_get_app_info (app);
if (appinfo == NULL)
if (app->info == NULL)
return;
/* Skip not-visible apps */
if (!g_app_info_should_show (appinfo))
if (!g_app_info_should_show (G_APP_INFO (app->info)))
return;
match = _shell_app_match_search_terms (app, terms);
@ -1550,11 +1529,7 @@ shell_app_dispose (GObject *object)
{
ShellApp *app = SHELL_APP (object);
if (app->entry)
{
gmenu_tree_item_unref (app->entry);
app->entry = NULL;
}
g_clear_object (&app->info);
if (app->running_state)
{

View File

@ -39,7 +39,6 @@ GType shell_app_get_type (void) G_GNUC_CONST;
const char *shell_app_get_id (ShellApp *app);
GMenuTreeEntry *shell_app_get_tree_entry (ShellApp *app);
GDesktopAppInfo *shell_app_get_app_info (ShellApp *app);
ClutterActor *shell_app_create_icon_texture (ShellApp *app, int size);