2008-11-20 19:53:11 -05:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
2009-04-22 15:21:35 -04:00
|
|
|
#include "shell-app-system.h"
|
2009-06-25 17:43:54 -04:00
|
|
|
#include <string.h>
|
2008-11-20 19:53:11 -05:00
|
|
|
|
|
|
|
#include <gio/gio.h>
|
2009-06-25 17:43:54 -04:00
|
|
|
#include <gconf/gconf.h>
|
|
|
|
#include <gconf/gconf-client.h>
|
2008-11-20 19:53:11 -05:00
|
|
|
|
2009-04-01 15:51:17 -04:00
|
|
|
#define GMENU_I_KNOW_THIS_IS_UNSTABLE
|
|
|
|
#include <gmenu-tree.h>
|
|
|
|
|
2009-06-25 17:43:54 -04:00
|
|
|
#define SHELL_APP_FAVORITES_KEY "/desktop/gnome/shell/favorite_apps"
|
|
|
|
|
2008-11-20 19:53:11 -05:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2009-06-25 17:43:54 -04:00
|
|
|
INSTALLED_CHANGED,
|
|
|
|
FAVORITES_CHANGED,
|
2008-11-20 19:53:11 -05:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2009-04-22 15:21:35 -04:00
|
|
|
struct _ShellAppSystemPrivate {
|
2009-05-14 14:14:18 -04:00
|
|
|
GMenuTree *apps_tree;
|
|
|
|
GMenuTree *settings_tree;
|
|
|
|
|
|
|
|
GSList *cached_app_menus; /* ShellAppMenuEntry */
|
2009-04-01 15:51:17 -04:00
|
|
|
|
2009-05-14 14:14:18 -04:00
|
|
|
GSList *cached_setting_ids; /* utf8 */
|
2009-06-25 17:43:54 -04:00
|
|
|
|
|
|
|
GHashTable *cached_favorites; /* <utf8,integer> */
|
|
|
|
|
|
|
|
gint app_monitor_id;
|
2008-11-20 19:53:11 -05:00
|
|
|
};
|
|
|
|
|
2009-04-22 15:21:35 -04:00
|
|
|
static void shell_app_system_finalize (GObject *object);
|
2009-04-01 15:51:17 -04:00
|
|
|
static void on_tree_changed (GMenuTree *tree, gpointer user_data);
|
2009-04-22 15:21:35 -04:00
|
|
|
static void reread_menus (ShellAppSystem *self);
|
2009-06-25 17:43:54 -04:00
|
|
|
static void on_favorite_apps_changed (GConfClient *client, guint id, GConfEntry *entry, gpointer user_data);
|
|
|
|
static void reread_favorite_apps (ShellAppSystem *system);
|
2008-11-20 19:53:11 -05:00
|
|
|
|
2009-04-22 15:21:35 -04:00
|
|
|
G_DEFINE_TYPE(ShellAppSystem, shell_app_system, G_TYPE_OBJECT);
|
2008-11-20 19:53:11 -05:00
|
|
|
|
2009-04-01 15:51:17 -04:00
|
|
|
static gpointer
|
|
|
|
shell_app_menu_entry_copy (gpointer entryp)
|
|
|
|
{
|
|
|
|
ShellAppMenuEntry *entry;
|
|
|
|
ShellAppMenuEntry *copy;
|
|
|
|
entry = entryp;
|
|
|
|
copy = g_new0 (ShellAppMenuEntry, 1);
|
|
|
|
copy->name = g_strdup (entry->name);
|
|
|
|
copy->id = g_strdup (entry->id);
|
|
|
|
copy->icon = g_strdup (entry->icon);
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shell_app_menu_entry_free (gpointer entryp)
|
|
|
|
{
|
|
|
|
ShellAppMenuEntry *entry = entryp;
|
|
|
|
g_free (entry->name);
|
|
|
|
g_free (entry->id);
|
|
|
|
g_free (entry->icon);
|
|
|
|
g_free (entry);
|
|
|
|
}
|
|
|
|
|
2009-04-22 15:21:35 -04:00
|
|
|
static void shell_app_system_class_init(ShellAppSystemClass *klass)
|
2008-11-20 19:53:11 -05:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = (GObjectClass *)klass;
|
|
|
|
|
2009-04-22 15:21:35 -04:00
|
|
|
gobject_class->finalize = shell_app_system_finalize;
|
2008-11-20 19:53:11 -05:00
|
|
|
|
2009-06-25 17:43:54 -04:00
|
|
|
signals[INSTALLED_CHANGED] =
|
|
|
|
g_signal_new ("installed-changed",
|
2009-04-22 15:21:35 -04:00
|
|
|
SHELL_TYPE_APP_SYSTEM,
|
2008-11-20 19:53:11 -05:00
|
|
|
G_SIGNAL_RUN_LAST,
|
2009-06-25 17:43:54 -04:00
|
|
|
G_STRUCT_OFFSET (ShellAppSystemClass, installed_changed),
|
2008-11-20 19:53:11 -05:00
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
2009-06-25 17:43:54 -04:00
|
|
|
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);
|
2008-11-20 19:53:11 -05:00
|
|
|
|
2009-04-22 15:21:35 -04:00
|
|
|
g_type_class_add_private (gobject_class, sizeof (ShellAppSystemPrivate));
|
2008-11-20 19:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-04-22 15:21:35 -04:00
|
|
|
shell_app_system_init (ShellAppSystem *self)
|
2008-11-20 19:53:11 -05:00
|
|
|
{
|
2009-04-22 15:21:35 -04:00
|
|
|
ShellAppSystemPrivate *priv;
|
2009-06-25 17:43:54 -04:00
|
|
|
GConfClient *client;
|
|
|
|
|
2009-04-01 15:51:17 -04:00
|
|
|
self->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
|
2009-04-22 15:21:35 -04:00
|
|
|
SHELL_TYPE_APP_SYSTEM,
|
|
|
|
ShellAppSystemPrivate);
|
2009-04-01 15:51:17 -04:00
|
|
|
|
2009-06-25 17:43:54 -04:00
|
|
|
priv->cached_favorites = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
(GDestroyNotify)g_free,
|
|
|
|
NULL);
|
|
|
|
|
2009-05-14 14:14:18 -04:00
|
|
|
priv->apps_tree = gmenu_tree_lookup ("applications.menu", GMENU_TREE_FLAGS_NONE);
|
|
|
|
priv->settings_tree = gmenu_tree_lookup ("settings.menu", GMENU_TREE_FLAGS_NONE);
|
2009-04-01 15:51:17 -04:00
|
|
|
|
2009-05-14 14:14:18 -04:00
|
|
|
gmenu_tree_add_monitor (priv->apps_tree, on_tree_changed, self);
|
|
|
|
gmenu_tree_add_monitor (priv->settings_tree, on_tree_changed, self);
|
2009-04-01 15:51:17 -04:00
|
|
|
|
|
|
|
reread_menus (self);
|
2009-06-25 17:43:54 -04:00
|
|
|
|
|
|
|
client = gconf_client_get_default ();
|
|
|
|
|
|
|
|
self->priv->app_monitor_id = gconf_client_notify_add (client, SHELL_APP_FAVORITES_KEY,
|
|
|
|
on_favorite_apps_changed, self, NULL, NULL);
|
|
|
|
reread_favorite_apps (self);
|
2008-11-20 19:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-04-22 15:21:35 -04:00
|
|
|
shell_app_system_finalize (GObject *object)
|
2008-11-20 19:53:11 -05:00
|
|
|
{
|
2009-04-22 15:21:35 -04:00
|
|
|
ShellAppSystem *self = SHELL_APP_SYSTEM (object);
|
|
|
|
ShellAppSystemPrivate *priv = self->priv;
|
2008-11-20 19:53:11 -05:00
|
|
|
|
2009-05-14 14:14:18 -04:00
|
|
|
gmenu_tree_remove_monitor (priv->apps_tree, on_tree_changed, self);
|
|
|
|
gmenu_tree_remove_monitor (priv->settings_tree, on_tree_changed, self);
|
2009-04-22 15:21:35 -04:00
|
|
|
|
2009-05-14 14:14:18 -04:00
|
|
|
gmenu_tree_unref (priv->apps_tree);
|
|
|
|
gmenu_tree_unref (priv->settings_tree);
|
|
|
|
|
|
|
|
g_slist_foreach (priv->cached_app_menus, (GFunc)shell_app_menu_entry_free, NULL);
|
|
|
|
g_slist_free (priv->cached_app_menus);
|
|
|
|
priv->cached_app_menus = NULL;
|
|
|
|
|
|
|
|
g_slist_foreach (priv->cached_setting_ids, (GFunc)g_free, NULL);
|
|
|
|
g_slist_free (priv->cached_setting_ids);
|
|
|
|
priv->cached_setting_ids = NULL;
|
2009-04-22 15:21:35 -04:00
|
|
|
|
2009-06-25 17:43:54 -04:00
|
|
|
g_hash_table_destroy (priv->cached_favorites);
|
|
|
|
|
|
|
|
gconf_client_notify_remove (gconf_client_get_default (), priv->app_monitor_id);
|
|
|
|
|
2009-04-22 15:21:35 -04:00
|
|
|
G_OBJECT_CLASS (shell_app_system_parent_class)->finalize(object);
|
2008-11-20 19:53:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-05-14 14:14:18 -04:00
|
|
|
reread_directories (ShellAppSystem *self, GSList **cache, GMenuTree *tree)
|
2009-04-01 15:51:17 -04:00
|
|
|
{
|
2009-05-14 14:14:18 -04:00
|
|
|
GMenuTreeDirectory *trunk;
|
|
|
|
GSList *entries;
|
|
|
|
GSList *iter;
|
2009-04-01 15:51:17 -04:00
|
|
|
|
2009-05-14 14:14:18 -04:00
|
|
|
trunk = gmenu_tree_get_root_directory (tree);
|
|
|
|
entries = gmenu_tree_directory_get_contents (trunk);
|
|
|
|
|
|
|
|
g_slist_foreach (*cache, (GFunc)shell_app_menu_entry_free, NULL);
|
|
|
|
g_slist_free (*cache);
|
|
|
|
*cache = NULL;
|
2009-04-01 15:51:17 -04:00
|
|
|
|
|
|
|
for (iter = entries; iter; iter = iter->next)
|
|
|
|
{
|
2009-04-08 10:54:27 -04:00
|
|
|
GMenuTreeItem *item = iter->data;
|
|
|
|
|
|
|
|
switch (gmenu_tree_item_get_type (item))
|
|
|
|
{
|
|
|
|
case GMENU_TREE_ITEM_DIRECTORY:
|
|
|
|
{
|
|
|
|
GMenuTreeDirectory *dir = iter->data;
|
|
|
|
ShellAppMenuEntry *shell_entry = g_new0 (ShellAppMenuEntry, 1);
|
|
|
|
shell_entry->name = g_strdup (gmenu_tree_directory_get_name (dir));
|
|
|
|
shell_entry->id = g_strdup (gmenu_tree_directory_get_menu_id (dir));
|
|
|
|
shell_entry->icon = g_strdup (gmenu_tree_directory_get_icon (dir));
|
|
|
|
|
2009-05-14 14:14:18 -04:00
|
|
|
*cache = g_slist_prepend (*cache, shell_entry);
|
2009-04-08 10:54:27 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-06-16 11:55:14 -04:00
|
|
|
|
|
|
|
gmenu_tree_item_unref (item);
|
2009-04-01 15:51:17 -04:00
|
|
|
}
|
2009-05-14 14:14:18 -04:00
|
|
|
*cache = g_slist_reverse (*cache);
|
2009-04-01 15:51:17 -04:00
|
|
|
|
|
|
|
g_slist_free (entries);
|
2009-05-14 14:14:18 -04:00
|
|
|
gmenu_tree_item_unref (trunk);
|
2009-04-01 15:51:17 -04:00
|
|
|
}
|
|
|
|
|
2009-05-14 14:14:18 -04:00
|
|
|
static GSList *
|
2009-05-14 13:03:18 -04:00
|
|
|
gather_entries_recurse (ShellAppSystem *monitor,
|
2009-05-14 14:14:18 -04:00
|
|
|
GSList *ids,
|
2009-05-14 13:03:18 -04:00
|
|
|
GMenuTreeDirectory *root)
|
2009-04-01 15:51:17 -04:00
|
|
|
{
|
|
|
|
GSList *contents;
|
|
|
|
GSList *iter;
|
|
|
|
|
2009-05-14 13:03:18 -04:00
|
|
|
contents = gmenu_tree_directory_get_contents (root);
|
2009-04-01 15:51:17 -04:00
|
|
|
|
|
|
|
for (iter = contents; iter; iter = iter->next)
|
|
|
|
{
|
|
|
|
GMenuTreeItem *item = iter->data;
|
|
|
|
switch (gmenu_tree_item_get_type (item))
|
|
|
|
{
|
|
|
|
case GMENU_TREE_ITEM_ENTRY:
|
|
|
|
{
|
|
|
|
GMenuTreeEntry *entry = (GMenuTreeEntry *)item;
|
|
|
|
const char *id = gmenu_tree_entry_get_desktop_file_id (entry);
|
2009-05-14 14:14:18 -04:00
|
|
|
ids = g_slist_prepend (ids, g_strdup (id));
|
2009-05-14 13:03:18 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GMENU_TREE_ITEM_DIRECTORY:
|
|
|
|
{
|
|
|
|
GMenuTreeDirectory *dir = (GMenuTreeDirectory*)item;
|
|
|
|
ids = gather_entries_recurse (monitor, ids, dir);
|
2009-04-01 15:51:17 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gmenu_tree_item_unref (item);
|
|
|
|
}
|
2009-05-14 13:03:18 -04:00
|
|
|
|
2009-04-01 15:51:17 -04:00
|
|
|
g_slist_free (contents);
|
|
|
|
|
2009-05-14 13:03:18 -04:00
|
|
|
return ids;
|
|
|
|
}
|
|
|
|
|
2009-05-14 14:14:18 -04:00
|
|
|
static void
|
|
|
|
reread_entries (ShellAppSystem *self,
|
|
|
|
GSList **cache,
|
|
|
|
GMenuTree *tree)
|
|
|
|
{
|
|
|
|
GMenuTreeDirectory *trunk;
|
|
|
|
|
|
|
|
trunk = gmenu_tree_get_root_directory (tree);
|
|
|
|
|
|
|
|
g_slist_foreach (*cache, (GFunc)g_free, NULL);
|
|
|
|
g_slist_free (*cache);
|
|
|
|
*cache = NULL;
|
|
|
|
|
|
|
|
*cache = gather_entries_recurse (self, *cache, trunk);
|
|
|
|
|
|
|
|
gmenu_tree_item_unref (trunk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
reread_menus (ShellAppSystem *self)
|
|
|
|
{
|
|
|
|
reread_directories (self, &(self->priv->cached_app_menus), self->priv->apps_tree);
|
|
|
|
reread_entries (self, &(self->priv->cached_setting_ids), self->priv->settings_tree);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_tree_changed (GMenuTree *monitor, gpointer user_data)
|
|
|
|
{
|
|
|
|
ShellAppSystem *self = SHELL_APP_SYSTEM (user_data);
|
|
|
|
|
2009-06-25 17:43:54 -04:00
|
|
|
g_signal_emit (self, signals[INSTALLED_CHANGED], 0);
|
2009-05-14 14:14:18 -04:00
|
|
|
|
|
|
|
reread_menus (self);
|
|
|
|
}
|
|
|
|
|
2009-06-25 17:43:54 -04:00
|
|
|
static void
|
|
|
|
copy_gconf_value_string_list_to_hashset (GConfValue *value,
|
|
|
|
GHashTable *dest)
|
|
|
|
{
|
|
|
|
GSList *list;
|
|
|
|
GSList *tmp;
|
|
|
|
|
|
|
|
list = gconf_value_get_list (value);
|
|
|
|
|
|
|
|
for (tmp = list ; tmp; tmp = tmp->next)
|
|
|
|
{
|
|
|
|
GConfValue *value = tmp->data;
|
|
|
|
char *str = g_strdup (gconf_value_get_string (value));
|
|
|
|
if (!str)
|
|
|
|
continue;
|
|
|
|
g_hash_table_insert (dest, str, GUINT_TO_POINTER(1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
reread_favorite_apps (ShellAppSystem *system)
|
|
|
|
{
|
|
|
|
GConfClient *client = gconf_client_get_default ();
|
|
|
|
GConfValue *val;
|
|
|
|
|
|
|
|
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))
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_hash_table_remove_all (system->priv->cached_favorites);
|
|
|
|
copy_gconf_value_string_list_to_hashset (val, system->priv->cached_favorites);
|
|
|
|
|
|
|
|
gconf_value_free (val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
on_favorite_apps_changed (GConfClient *client,
|
|
|
|
guint id,
|
|
|
|
GConfEntry *entry,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
ShellAppSystem *system = SHELL_APP_SYSTEM (user_data);
|
|
|
|
reread_favorite_apps (system);
|
|
|
|
g_signal_emit (G_OBJECT (system), signals[FAVORITES_CHANGED], 0);
|
|
|
|
}
|
|
|
|
|
2009-05-14 14:14:18 -04:00
|
|
|
GType
|
|
|
|
shell_app_menu_entry_get_type (void)
|
|
|
|
{
|
|
|
|
static GType gtype = G_TYPE_INVALID;
|
|
|
|
if (gtype == G_TYPE_INVALID)
|
|
|
|
{
|
|
|
|
gtype = g_boxed_type_register_static ("ShellAppMenuEntry",
|
|
|
|
shell_app_menu_entry_copy,
|
|
|
|
shell_app_menu_entry_free);
|
|
|
|
}
|
|
|
|
return gtype;
|
|
|
|
}
|
|
|
|
|
2009-05-14 13:03:18 -04:00
|
|
|
/**
|
|
|
|
* shell_app_system_get_applications_for_menu:
|
|
|
|
*
|
2009-05-14 14:14:18 -04:00
|
|
|
* Traverses a toplevel menu, and returns all items under it. Nested items
|
|
|
|
* are flattened.
|
|
|
|
*
|
2009-05-14 13:03:18 -04:00
|
|
|
* Return value: (transfer full) (element-type utf8): List of desktop file ids
|
|
|
|
*/
|
2009-05-14 14:14:18 -04:00
|
|
|
GSList *
|
2009-05-14 13:03:18 -04:00
|
|
|
shell_app_system_get_applications_for_menu (ShellAppSystem *monitor,
|
|
|
|
const char *menu)
|
|
|
|
{
|
|
|
|
char *path;
|
|
|
|
GMenuTreeDirectory *menu_entry;
|
2009-06-16 11:55:14 -04:00
|
|
|
GSList *apps;
|
2009-05-14 13:03:18 -04:00
|
|
|
|
|
|
|
path = g_strdup_printf ("/%s", menu);
|
2009-05-14 14:14:18 -04:00
|
|
|
menu_entry = gmenu_tree_get_directory_from_path (monitor->priv->apps_tree, path);
|
2009-05-14 13:03:18 -04:00
|
|
|
g_free (path);
|
|
|
|
g_assert (menu_entry != NULL);
|
|
|
|
|
2009-06-16 11:55:14 -04:00
|
|
|
apps = gather_entries_recurse (monitor, NULL, menu_entry);
|
|
|
|
|
|
|
|
gmenu_tree_item_unref (menu_entry);
|
|
|
|
|
|
|
|
return apps;
|
2009-04-01 15:51:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-04-22 15:21:35 -04:00
|
|
|
* shell_app_system_get_menus:
|
2009-04-01 15:51:17 -04:00
|
|
|
*
|
2009-05-14 14:14:18 -04:00
|
|
|
* Returns a list of toplevel menu names, like "Accessories", "Programming", etc.
|
|
|
|
*
|
2009-04-01 15:51:17 -04:00
|
|
|
* Return value: (transfer none) (element-type AppMenuEntry): List of toplevel menus
|
|
|
|
*/
|
2009-05-14 14:14:18 -04:00
|
|
|
GSList *
|
2009-04-22 15:21:35 -04:00
|
|
|
shell_app_system_get_menus (ShellAppSystem *monitor)
|
2009-04-01 15:51:17 -04:00
|
|
|
{
|
2009-05-14 14:14:18 -04:00
|
|
|
return monitor->priv->cached_app_menus;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* shell_app_system_get_all_settings:
|
|
|
|
*
|
|
|
|
* Returns a list of all desktop file ids under "settings.menu".
|
|
|
|
*
|
2009-06-12 11:27:27 -04:00
|
|
|
* Return value: (transfer none) (element-type utf8): List of desktop file ids
|
2009-05-14 14:14:18 -04:00
|
|
|
*/
|
|
|
|
GSList *
|
|
|
|
shell_app_system_get_all_settings (ShellAppSystem *monitor)
|
|
|
|
{
|
|
|
|
return monitor->priv->cached_setting_ids;
|
2008-11-20 19:53:11 -05:00
|
|
|
}
|
2009-06-18 12:27:19 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* shell_app_system_get_default:
|
|
|
|
*
|
|
|
|
* Return Value: (transfer none): The global #ShellAppSystem singleton
|
|
|
|
*/
|
|
|
|
ShellAppSystem *
|
|
|
|
shell_app_system_get_default ()
|
|
|
|
{
|
|
|
|
static ShellAppSystem *instance = NULL;
|
|
|
|
|
|
|
|
if (instance == NULL)
|
|
|
|
instance = g_object_new (SHELL_TYPE_APP_SYSTEM, NULL);
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
2009-06-25 17:43:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* shell_app_system_get_favorites:
|
|
|
|
*
|
|
|
|
* Return the list of applications which have been explicitly added to the
|
|
|
|
* favorites.
|
|
|
|
*
|
|
|
|
* Return value: (transfer container) (element-type utf8): List of favorite application ids
|
|
|
|
*/
|
|
|
|
GList *
|
|
|
|
shell_app_system_get_favorites (ShellAppSystem *system)
|
|
|
|
{
|
|
|
|
return g_hash_table_get_keys (system->priv->cached_favorites);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_gconf_value_string_list (GConfValue *val, GList *items)
|
|
|
|
{
|
|
|
|
GList *iter;
|
|
|
|
GSList *tmp = NULL;
|
|
|
|
|
|
|
|
for (iter = items; iter; iter = iter->next)
|
|
|
|
{
|
|
|
|
const char *str = iter->data;
|
|
|
|
GConfValue *strval = gconf_value_new (GCONF_VALUE_STRING);
|
|
|
|
gconf_value_set_string (strval, str);
|
|
|
|
tmp = g_slist_prepend (tmp, strval);
|
|
|
|
}
|
|
|
|
tmp = g_slist_reverse (tmp);
|
|
|
|
|
|
|
|
gconf_value_set_list (val, tmp);
|
|
|
|
g_slist_free (tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
shell_app_system_add_favorite (ShellAppSystem *system, const char *id)
|
|
|
|
{
|
|
|
|
GConfClient *client = gconf_client_get_default ();
|
|
|
|
GConfValue *val;
|
|
|
|
GList *favorites;
|
|
|
|
|
|
|
|
val = gconf_value_new (GCONF_VALUE_LIST);
|
|
|
|
gconf_value_set_list_type (val, GCONF_VALUE_STRING);
|
|
|
|
|
|
|
|
g_hash_table_insert (system->priv->cached_favorites, g_strdup (id), GUINT_TO_POINTER (1));
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
shell_app_system_remove_favorite (ShellAppSystem *system, const char *id)
|
|
|
|
{
|
|
|
|
GConfClient *client = gconf_client_get_default ();
|
|
|
|
GConfValue *val;
|
|
|
|
GList *favorites;
|
|
|
|
|
|
|
|
if (!g_hash_table_remove (system->priv->cached_favorites, id))
|
|
|
|
return;
|
|
|
|
|
|
|
|
val = gconf_value_new (GCONF_VALUE_LIST);
|
|
|
|
gconf_value_set_list_type (val, GCONF_VALUE_STRING);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
desktop_id_exists (ShellAppSystem *system,
|
|
|
|
const char *target_id,
|
|
|
|
GMenuTreeDirectory *root)
|
|
|
|
{
|
|
|
|
gboolean found = FALSE;
|
|
|
|
GSList *contents, *iter;
|
|
|
|
|
|
|
|
contents = gmenu_tree_directory_get_contents (root);
|
|
|
|
|
|
|
|
for (iter = contents; iter; iter = iter->next)
|
|
|
|
{
|
|
|
|
GMenuTreeItem *item = iter->data;
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (gmenu_tree_item_get_type (item))
|
|
|
|
{
|
|
|
|
case GMENU_TREE_ITEM_ENTRY:
|
|
|
|
{
|
|
|
|
GMenuTreeEntry *entry = (GMenuTreeEntry *)item;
|
|
|
|
const char *id = gmenu_tree_entry_get_desktop_file_id (entry);
|
|
|
|
if (strcmp (id, target_id) == 0)
|
|
|
|
found = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GMENU_TREE_ITEM_DIRECTORY:
|
|
|
|
{
|
|
|
|
GMenuTreeDirectory *dir = (GMenuTreeDirectory*)item;
|
|
|
|
found = desktop_id_exists (system, target_id, dir);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gmenu_tree_item_unref (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 *
|
|
|
|
shell_app_system_lookup_basename (ShellAppSystem *system,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
GMenuTreeDirectory *root;
|
|
|
|
char *result;
|
|
|
|
|
|
|
|
root = gmenu_tree_get_directory_from_path (system->priv->apps_tree, "/");
|
|
|
|
g_assert (root != NULL);
|
|
|
|
|
|
|
|
if (desktop_id_exists (system, name, root))
|
|
|
|
{
|
|
|
|
result = g_strdup (name);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* These are common "vendor prefixes". But using
|
|
|
|
* WM_CLASS as a source, we don't get the vendor
|
|
|
|
* prefix. So try stripping them.
|
|
|
|
*/
|
|
|
|
result = g_strjoin ("", "gnome-", name, NULL);
|
|
|
|
if (desktop_id_exists (system, result, root))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
result = g_strjoin ("", "fedora-", name, NULL);
|
|
|
|
if (desktop_id_exists (system, result, root))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
out:
|
|
|
|
gmenu_tree_item_unref (root);
|
|
|
|
return result;
|
|
|
|
}
|