Update for comments on b5988a57fa

This commit is contained in:
Colin Walters 2009-06-30 14:48:07 -04:00
parent 8293f3423a
commit 39e31a3aa9
5 changed files with 84 additions and 51 deletions

View File

@ -16,7 +16,7 @@
</schema> </schema>
<schema> <schema>
<key>/schemas/desktop/gnome/favorite_apps</key> <key>/schemas/desktop/gnome/shell/favorite_apps</key>
<applyto>/desktop/gnome/shell/favorite_apps</applyto> <applyto>/desktop/gnome/shell/favorite_apps</applyto>
<owner>gnome-shell</owner> <owner>gnome-shell</owner>
<type>list</type> <type>list</type>

View File

@ -183,16 +183,15 @@ AppDisplay.prototype = {
this._appMonitor = Shell.AppMonitor.get_default(); this._appMonitor = Shell.AppMonitor.get_default();
this._appSystem = Shell.AppSystem.get_default(); this._appSystem = Shell.AppSystem.get_default();
this._appsStale = true; this._appsStale = true;
this._appSystem.connect('changed', Lang.bind(this, function(appSys) { this._appSystem.connect('installed-changed', Lang.bind(this, function(appSys) {
this._appsStale = true; this._appsStale = true;
// We still need to determine what events other than search can trigger
// a change in the set of applications that are being shown while the
// user in in the overlay mode, however let's redisplay just in case.
this._redisplay(false); this._redisplay(false);
this._redisplayMenus(); this._redisplayMenus();
})); }));
this._appSystem.connect('favorites-changed', Lang.bind(this, function(appSys) {
this._redisplay(false);
}));
this._appMonitor.connect('changed', Lang.bind(this, function(monitor) { this._appMonitor.connect('changed', Lang.bind(this, function(monitor) {
this._appsStale = true;
this._redisplay(false); this._redisplay(false);
})); }));
@ -574,7 +573,10 @@ AppWell.prototype = {
this._appSystem = Shell.AppSystem.get_default(); this._appSystem = Shell.AppSystem.get_default();
this._appMonitor = Shell.AppMonitor.get_default(); this._appMonitor = Shell.AppMonitor.get_default();
this._appSystem.connect('changed', Lang.bind(this, function(appSys) { this._appSystem.connect('installed-changed', Lang.bind(this, function(appSys) {
this._redisplay();
}));
this._appSystem.connect('favorites-changed', Lang.bind(this, function(appSys) {
this._redisplay(); this._redisplay();
})); }));
this._appMonitor.connect('changed', Lang.bind(this, function(monitor) { this._appMonitor.connect('changed', Lang.bind(this, function(monitor) {

View File

@ -279,7 +279,7 @@ get_appid_for_window (MetaWindow *window)
{ {
char *wmclass; char *wmclass;
char *with_desktop; char *with_desktop;
char *fullpath; char *result;
ShellAppSystem *appsys; ShellAppSystem *appsys;
wmclass = get_cleaned_wmclass_for_window (window); wmclass = get_cleaned_wmclass_for_window (window);
@ -291,10 +291,10 @@ get_appid_for_window (MetaWindow *window)
g_free (wmclass); g_free (wmclass);
appsys = shell_app_system_get_default (); appsys = shell_app_system_get_default ();
result = shell_app_system_lookup_basename (appsys, with_desktop);
g_free (with_desktop);
fullpath = shell_app_system_lookup_basename (appsys, with_desktop); return result;
return fullpath;
} }
static void static void

View File

@ -18,7 +18,8 @@ enum {
}; };
enum { enum {
CHANGED, INSTALLED_CHANGED,
FAVORITES_CHANGED,
LAST_SIGNAL LAST_SIGNAL
}; };
@ -74,14 +75,22 @@ static void shell_app_system_class_init(ShellAppSystemClass *klass)
gobject_class->finalize = shell_app_system_finalize; gobject_class->finalize = shell_app_system_finalize;
signals[CHANGED] = signals[INSTALLED_CHANGED] =
g_signal_new ("changed", g_signal_new ("installed-changed",
SHELL_TYPE_APP_SYSTEM, SHELL_TYPE_APP_SYSTEM,
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ShellAppSystemClass, changed), G_STRUCT_OFFSET (ShellAppSystemClass, installed_changed),
NULL, NULL, NULL, NULL,
g_cclosure_marshal_VOID__VOID, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0); G_TYPE_NONE, 0);
signals[FAVORITES_CHANGED] =
g_signal_new ("favorites-changed",
SHELL_TYPE_APP_SYSTEM,
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ShellAppSystemClass, favorites_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
g_type_class_add_private (gobject_class, sizeof (ShellAppSystemPrivate)); g_type_class_add_private (gobject_class, sizeof (ShellAppSystemPrivate));
} }
@ -254,7 +263,7 @@ on_tree_changed (GMenuTree *monitor, gpointer user_data)
{ {
ShellAppSystem *self = SHELL_APP_SYSTEM (user_data); ShellAppSystem *self = SHELL_APP_SYSTEM (user_data);
g_signal_emit (self, signals[CHANGED], 0); g_signal_emit (self, signals[INSTALLED_CHANGED], 0);
reread_menus (self); reread_menus (self);
} }
@ -284,7 +293,7 @@ reread_favorite_apps (ShellAppSystem *system)
GConfClient *client = gconf_client_get_default (); GConfClient *client = gconf_client_get_default ();
GConfValue *val; GConfValue *val;
val = gconf_client_get (client, "/desktop/gnome/shell/favorite_apps", NULL); val = gconf_client_get (client, SHELL_APP_FAVORITES_KEY, NULL);
if (!(val && val->type == GCONF_VALUE_LIST && gconf_value_get_list_type (val) == GCONF_VALUE_STRING)) if (!(val && val->type == GCONF_VALUE_LIST && gconf_value_get_list_type (val) == GCONF_VALUE_STRING))
return; return;
@ -296,11 +305,14 @@ reread_favorite_apps (ShellAppSystem *system)
} }
void void
on_favorite_apps_changed (GConfClient *client, guint id, GConfEntry *entry, gpointer user_data) on_favorite_apps_changed (GConfClient *client,
guint id,
GConfEntry *entry,
gpointer user_data)
{ {
ShellAppSystem *system = SHELL_APP_SYSTEM (user_data); ShellAppSystem *system = SHELL_APP_SYSTEM (user_data);
reread_favorite_apps (system); reread_favorite_apps (system);
g_signal_emit (G_OBJECT (system), signals[CHANGED], 0); g_signal_emit (G_OBJECT (system), signals[FAVORITES_CHANGED], 0);
} }
GType GType
@ -392,7 +404,7 @@ shell_app_system_get_default ()
* Return the list of applications which have been explicitly added to the * Return the list of applications which have been explicitly added to the
* favorites. * favorites.
* *
* Return value: (transfer none) (element-type utf8): List of favorite application ids * Return value: (transfer container) (element-type utf8): List of favorite application ids
*/ */
GList * GList *
shell_app_system_get_favorites (ShellAppSystem *system) shell_app_system_get_favorites (ShellAppSystem *system)
@ -424,13 +436,16 @@ shell_app_system_add_favorite (ShellAppSystem *system, const char *id)
{ {
GConfClient *client = gconf_client_get_default (); GConfClient *client = gconf_client_get_default ();
GConfValue *val; GConfValue *val;
GList *favorites;
val = gconf_value_new (GCONF_VALUE_LIST); val = gconf_value_new (GCONF_VALUE_LIST);
gconf_value_set_list_type (val, GCONF_VALUE_STRING); gconf_value_set_list_type (val, GCONF_VALUE_STRING);
g_hash_table_insert (system->priv->cached_favorites, g_strdup (id), GUINT_TO_POINTER (1)); g_hash_table_insert (system->priv->cached_favorites, g_strdup (id), GUINT_TO_POINTER (1));
set_gconf_value_string_list (val, g_hash_table_get_keys (system->priv->cached_favorites)); favorites = g_hash_table_get_keys (system->priv->cached_favorites);
set_gconf_value_string_list (val, favorites);
g_list_free (favorites);
gconf_client_set (client, SHELL_APP_FAVORITES_KEY, val, NULL); gconf_client_set (client, SHELL_APP_FAVORITES_KEY, val, NULL);
} }
@ -440,6 +455,7 @@ shell_app_system_remove_favorite (ShellAppSystem *system, const char *id)
{ {
GConfClient *client = gconf_client_get_default (); GConfClient *client = gconf_client_get_default ();
GConfValue *val; GConfValue *val;
GList *favorites;
if (!g_hash_table_remove (system->priv->cached_favorites, id)) if (!g_hash_table_remove (system->priv->cached_favorites, id))
return; return;
@ -447,18 +463,19 @@ shell_app_system_remove_favorite (ShellAppSystem *system, const char *id)
val = gconf_value_new (GCONF_VALUE_LIST); val = gconf_value_new (GCONF_VALUE_LIST);
gconf_value_set_list_type (val, GCONF_VALUE_STRING); gconf_value_set_list_type (val, GCONF_VALUE_STRING);
set_gconf_value_string_list (val, g_hash_table_get_keys (system->priv->cached_favorites)); favorites = g_hash_table_get_keys (system->priv->cached_favorites);
set_gconf_value_string_list (val, favorites);
g_list_free (favorites);
gconf_client_set (client, SHELL_APP_FAVORITES_KEY, val, NULL); gconf_client_set (client, SHELL_APP_FAVORITES_KEY, val, NULL);
} }
static gboolean
static char * desktop_id_exists (ShellAppSystem *system,
full_path_for_id (ShellAppSystem *system, const char *target_id,
const char *target_id, GMenuTreeDirectory *root)
GMenuTreeDirectory *root)
{ {
char *ret = NULL; gboolean found = FALSE;
GSList *contents, *iter; GSList *contents, *iter;
contents = gmenu_tree_directory_get_contents (root); contents = gmenu_tree_directory_get_contents (root);
@ -467,7 +484,7 @@ full_path_for_id (ShellAppSystem *system,
{ {
GMenuTreeItem *item = iter->data; GMenuTreeItem *item = iter->data;
if (ret != NULL) if (found)
break; break;
switch (gmenu_tree_item_get_type (item)) switch (gmenu_tree_item_get_type (item))
@ -477,15 +494,13 @@ full_path_for_id (ShellAppSystem *system,
GMenuTreeEntry *entry = (GMenuTreeEntry *)item; GMenuTreeEntry *entry = (GMenuTreeEntry *)item;
const char *id = gmenu_tree_entry_get_desktop_file_id (entry); const char *id = gmenu_tree_entry_get_desktop_file_id (entry);
if (strcmp (id, target_id) == 0) if (strcmp (id, target_id) == 0)
{ found = TRUE;
ret = g_strdup (gmenu_tree_entry_get_desktop_file_path (entry));
}
} }
break; break;
case GMENU_TREE_ITEM_DIRECTORY: case GMENU_TREE_ITEM_DIRECTORY:
{ {
GMenuTreeDirectory *dir = (GMenuTreeDirectory*)item; GMenuTreeDirectory *dir = (GMenuTreeDirectory*)item;
ret = full_path_for_id (system, target_id, dir); found = desktop_id_exists (system, target_id, dir);
} }
break; break;
default: default:
@ -494,33 +509,48 @@ full_path_for_id (ShellAppSystem *system,
gmenu_tree_item_unref (item); gmenu_tree_item_unref (item);
} }
return ret; g_slist_free (contents);
return found;
} }
/**
* shell_app_system_lookup_basename:
* @name: Probable application identifier
*
* Determine whether a valid .desktop file ID corresponding to a given
* heuristically determined application identifier
* string.
*/
char * char *
shell_app_system_lookup_basename (ShellAppSystem *system, shell_app_system_lookup_basename (ShellAppSystem *system,
const char *id) const char *name)
{ {
GMenuTreeDirectory *root; GMenuTreeDirectory *root;
char *path; char *result;
char *tmpid;
root = gmenu_tree_get_directory_from_path (system->priv->apps_tree, "/"); root = gmenu_tree_get_directory_from_path (system->priv->apps_tree, "/");
g_assert (root != NULL); g_assert (root != NULL);
path = full_path_for_id (system, id, root); if (desktop_id_exists (system, name, root))
if (path != NULL) {
return path; result = g_strdup (name);
goto out;
}
tmpid = g_strjoin ("", "gnome-", id, NULL); /* These are common "vendor prefixes". But using
path = full_path_for_id (system, tmpid, root); * WM_CLASS as a source, we don't get the vendor
g_free (tmpid); * prefix. So try stripping them.
if (path != NULL) */
return path; result = g_strjoin ("", "gnome-", name, NULL);
if (desktop_id_exists (system, result, root))
goto out;
tmpid = g_strjoin ("", "fedora-", id, NULL); result = g_strjoin ("", "fedora-", name, NULL);
path = full_path_for_id (system, tmpid, root); if (desktop_id_exists (system, result, root))
g_free (tmpid); goto out;
return path; out:
} gmenu_tree_item_unref (root);
return result;
}

View File

@ -25,7 +25,8 @@ struct _ShellAppSystemClass
{ {
GObjectClass parent_class; GObjectClass parent_class;
void (*changed)(ShellAppSystem *appsys, gpointer data); void (*installed_changed)(ShellAppSystem *appsys, gpointer user_data);
void (*favorites_changed)(ShellAppSystem *appsys, gpointer user_data);
}; };
GType shell_app_system_get_type (void) G_GNUC_CONST; GType shell_app_system_get_type (void) G_GNUC_CONST;