aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-05-24 22:50:22 +0200
committerLars Uebernickel <lars.uebernickel@canonical.com>2012-05-24 22:50:22 +0200
commit9763d347aabc9050e4f17133bcf287ed1cbc190d (patch)
tree3366cd980b8e571b359c4395284dd245fdedaabd /src
parente3c0e7048e032a5a8678c25341fc61b9c191a5db (diff)
downloadayatana-indicator-messages-9763d347aabc9050e4f17133bcf287ed1cbc190d.tar.gz
ayatana-indicator-messages-9763d347aabc9050e4f17133bcf287ed1cbc190d.tar.bz2
ayatana-indicator-messages-9763d347aabc9050e4f17133bcf287ed1cbc190d.zip
message-service: replace the server list with a hash table of appmenuitems
Diffstat (limited to 'src')
-rw-r--r--src/messages-service.c61
1 files changed, 12 insertions, 49 deletions
diff --git a/src/messages-service.c b/src/messages-service.c
index 432846e..fbbfb9d 100644
--- a/src/messages-service.c
+++ b/src/messages-service.c
@@ -36,7 +36,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include "status-items.h"
static IndicatorService * service = NULL;
-static GList * serverList = NULL;
+static GHashTable *applications;
static GDBusConnection *bus;
static GSimpleActionGroup *actions;
@@ -47,32 +47,6 @@ static GMainLoop * mainloop = NULL;
static MessageServiceDbus * dbus_interface = NULL;
-/*
- * Server List
- */
-
-typedef struct _serverList_t serverList_t;
-struct _serverList_t {
- AppMenuItem * menuitem;
- gboolean attention;
- guint count;
- GList * imList;
-};
-
-static gint
-serverList_sort (gconstpointer a, gconstpointer b)
-{
- serverList_t * pa, * pb;
-
- pa = (serverList_t *)a;
- pb = (serverList_t *)b;
-
- const gchar * pan = app_menu_item_get_name(pa->menuitem);
- const gchar * pbn = app_menu_item_get_name(pb->menuitem);
-
- return g_strcmp0(pan, pbn);
-}
-
/* This function turns a specific desktop id into a menu
item and registers it appropriately with everyone */
static gboolean
@@ -80,31 +54,20 @@ build_launcher (gpointer data)
{
gchar *desktop_id = data;
GDesktopAppInfo *appinfo;
- GList *listitem;
+ const gchar *desktop_file;
appinfo = g_desktop_app_info_new (desktop_id);
+ desktop_file = g_desktop_app_info_get_filename (appinfo);
- /* Check to see if we already have a launcher */
- for (listitem = serverList; listitem != NULL; listitem = listitem->next) {
- serverList_t * slt = listitem->data;
- if (!g_strcmp0(app_menu_item_get_desktop(slt->menuitem),
- g_desktop_app_info_get_filename (appinfo))) {
- break;
- }
- }
-
- if (listitem == NULL) {
- /* If not */
- /* Build the item */
- serverList_t * sl_item = g_new0(serverList_t, 1);
- sl_item->menuitem = app_menu_item_new(appinfo);
-
- serverList = g_list_insert_sorted (serverList, sl_item, serverList_sort);
+ if (!g_hash_table_lookup (applications, desktop_file)) {
+ AppMenuItem *menuitem = app_menu_item_new(appinfo);
/* TODO insert it at the right position (alphabetically by application name) */
g_menu_insert_section (menu, 2,
- app_menu_item_get_name (sl_item->menuitem),
- app_menu_item_get_menu (sl_item->menuitem));
+ app_menu_item_get_name (menuitem),
+ app_menu_item_get_menu (menuitem));
+
+ g_hash_table_insert (applications, g_strdup (desktop_file), menuitem);
}
g_object_unref (appinfo);
@@ -129,8 +92,6 @@ build_launchers (gpointer data)
g_idle_add(build_launcher, g_strdup (*app));
}
- serverList = g_list_sort(serverList, serverList_sort);
-
g_strfreev (applications);
return FALSE;
}
@@ -224,6 +185,8 @@ main (int argc, char ** argv)
settings = g_settings_new ("com.canonical.indicator.messages");
+ applications = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+
g_idle_add(build_launchers, NULL);
/* Let's run a mainloop */
@@ -233,6 +196,6 @@ main (int argc, char ** argv)
/* Clean up */
status_items_cleanup();
g_object_unref (settings);
-
+ g_hash_table_unref (applications);
return 0;
}