From d44ae676f2d89a286a8298927bdda89725d91603 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 15:39:40 -0500 Subject: Not sure why, but the naming of this file is really bugging me. Fixed now. --- src/messages-service.c | 536 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 536 insertions(+) create mode 100644 src/messages-service.c (limited to 'src/messages-service.c') diff --git a/src/messages-service.c b/src/messages-service.c new file mode 100644 index 0000000..93c926b --- /dev/null +++ b/src/messages-service.c @@ -0,0 +1,536 @@ +/* +An indicator to show information that is in messaging applications +that the user is using. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#include +#include +#include + +#include + +#include "im-menu-item.h" +#include "app-menu-item.h" +#include "launcher-menu-item.h" +#include "dbus-data.h" + +static IndicateListener * listener; +static GList * serverList; + +static DbusmenuMenuitem * root_menuitem = NULL; +static GMainLoop * mainloop = NULL; + + +static void server_count_changed (AppMenuItem * appitem, guint count, gpointer data); +static void server_name_changed (AppMenuItem * appitem, gchar * name, gpointer data); +static void im_time_changed (ImMenuItem * imitem, glong seconds, gpointer data); +static void reconsile_list_and_menu (GList * serverlist, DbusmenuMenuitem * menushell); +static void indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data); + +typedef struct _serverList_t serverList_t; +struct _serverList_t { + IndicateListenerServer * server; + AppMenuItem * menuitem; + GList * imList; +}; + +static gint +serverList_equal (gconstpointer a, gconstpointer b) +{ + serverList_t * pa, * pb; + + pa = (serverList_t *)a; + pb = (serverList_t *)b; + + const gchar * pas = INDICATE_LISTENER_SERVER_DBUS_NAME(pa->server); + const gchar * pbs = INDICATE_LISTENER_SERVER_DBUS_NAME(pb->server); + + return g_strcmp0(pas, pbs); +} + +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); +} + +typedef struct _imList_t imList_t; +struct _imList_t { + IndicateListenerServer * server; + IndicateListenerIndicator * indicator; + DbusmenuMenuitem * menuitem; + gulong timechange_cb; +}; + +static gboolean +imList_equal (gconstpointer a, gconstpointer b) +{ + imList_t * pa, * pb; + + pa = (imList_t *)a; + pb = (imList_t *)b; + + const gchar * pas = INDICATE_LISTENER_SERVER_DBUS_NAME(pa->server); + const gchar * pbs = INDICATE_LISTENER_SERVER_DBUS_NAME(pb->server); + + guint pai = INDICATE_LISTENER_INDICATOR_ID(pa->indicator); + guint pbi = INDICATE_LISTENER_INDICATOR_ID(pb->indicator); + + g_debug("\tComparing (%s %d) to (%s %d)", pas, pai, pbs, pbi); + + return !((!g_strcmp0(pas, pbs)) && (pai == pbi)); +} + +static gint +imList_sort (gconstpointer a, gconstpointer b) +{ + imList_t * pa, * pb; + + pa = (imList_t *)a; + pb = (imList_t *)b; + + return (gint)(im_menu_item_get_seconds(IM_MENU_ITEM(pb->menuitem)) - im_menu_item_get_seconds(IM_MENU_ITEM(pa->menuitem))); +} + +typedef struct _launcherList_t launcherList_t; +struct _launcherList_t { + LauncherMenuItem * menuitem; +}; + +static gint +launcherList_sort (gconstpointer a, gconstpointer b) +{ + launcherList_t * pa, * pb; + + pa = (launcherList_t *)a; + pb = (launcherList_t *)b; + + const gchar * pan = launcher_menu_item_get_name(pa->menuitem); + const gchar * pbn = launcher_menu_item_get_name(pb->menuitem); + + return g_strcmp0(pan, pbn); +} + +static void +server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) +{ + g_debug("Server Added '%s' of type '%s'.", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type); + if (type == NULL) { + return; + } + + if (type[0] == '\0') { + return; + } + + if (strncmp(type, "message", strlen("message"))) { + g_debug("\tServer type '%s' is not a message based type.", type); + return; + } + + DbusmenuMenuitem * menushell = DBUSMENU_MENUITEM(data); + if (menushell == NULL) { + g_error("\tData in callback is not a menushell"); + return; + } + + AppMenuItem * menuitem = app_menu_item_new(listener, server); + g_signal_connect(G_OBJECT(menuitem), APP_MENU_ITEM_SIGNAL_COUNT_CHANGED, G_CALLBACK(server_count_changed), NULL); + g_signal_connect(G_OBJECT(menuitem), APP_MENU_ITEM_SIGNAL_NAME_CHANGED, G_CALLBACK(server_name_changed), menushell); + + serverList_t * sl_item = g_new0(serverList_t, 1); + sl_item->server = server; + sl_item->menuitem = menuitem; + sl_item->imList = NULL; + + /* Incase we got an indicator first */ + GList * alreadythere = g_list_find_custom(serverList, sl_item, serverList_equal); + if (alreadythere != NULL) { + g_free(sl_item); + sl_item = (serverList_t *)alreadythere->data; + sl_item->menuitem = menuitem; + serverList = g_list_sort(serverList, serverList_sort); + } else { + serverList = g_list_insert_sorted(serverList, sl_item, serverList_sort); + } + + dbusmenu_menuitem_child_append(menushell, DBUSMENU_MENUITEM(menuitem)); + /* Should be prepend ^ */ + + reconsile_list_and_menu(serverList, menushell); + + return; +} + +static void +server_name_changed (AppMenuItem * appitem, gchar * name, gpointer data) +{ + serverList = g_list_sort(serverList, serverList_sort); + reconsile_list_and_menu(serverList, DBUSMENU_MENUITEM(data)); + return; +} + +static void +server_count_changed (AppMenuItem * appitem, guint count, gpointer data) +{ + static gboolean showing_new_icon = FALSE; + + /* Quick check for a common case */ + if (count != 0 && showing_new_icon) { + return; + } + + /* Odd that we'd get a signal in this case, but let's + take it out of the mix too */ + if (count == 0 && !showing_new_icon) { + return; + } + + if (count != 0) { + g_debug("Setting image to 'new'"); + showing_new_icon = TRUE; + /* gtk_image_set_from_icon_name(GTK_IMAGE(main_image), "indicator-messages-new", DESIGN_TEAM_SIZE); */ + return; + } + + /* Okay, now at this point the count is zero and it + might result in a switching of the icon back to being + the plain one. Let's check. */ + + gboolean we_have_indicators = FALSE; + GList * appitems = serverList; + for (; appitems != NULL; appitems = appitems->next) { + AppMenuItem * appitem = ((serverList_t *)appitems->data)->menuitem; + if (app_menu_item_get_count(appitem) != 0) { + we_have_indicators = TRUE; + break; + } + } + + if (!we_have_indicators) { + g_debug("Setting image to boring"); + showing_new_icon = FALSE; + /* gtk_image_set_from_icon_name(GTK_IMAGE(main_image), "indicator-messages", DESIGN_TEAM_SIZE); */ + } + + return; +} + +static void +im_time_changed (ImMenuItem * imitem, glong seconds, gpointer data) +{ + serverList_t * sl = (serverList_t *)data; + sl->imList = g_list_sort(sl->imList, imList_sort); + reconsile_list_and_menu(serverList, root_menuitem); + return; +} + +static void +server_removed (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) +{ + g_debug("Removing server: %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server)); + serverList_t slt; + slt.server = server; + GList * lookup = g_list_find_custom(serverList, &slt, serverList_equal); + + if (lookup == NULL) { + g_debug("\tUnable to find server: %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server)); + return; + } + + serverList_t * sltp = (serverList_t *)lookup->data; + + while (sltp->imList) { + imList_t * imitem = (imList_t *)sltp->imList->data; + indicator_removed(listener, server, imitem->indicator, "message", data); + } + + serverList = g_list_remove(serverList, sltp); + + if (sltp->menuitem != NULL) { + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(sltp->menuitem), "visibile", "false"); + dbusmenu_menuitem_child_delete(DBUSMENU_MENUITEM(data), DBUSMENU_MENUITEM(sltp->menuitem)); + g_object_unref(G_OBJECT(sltp->menuitem)); + } + + g_free(sltp); + + /* Simulate a server saying zero to recalculate icon */ + server_count_changed(NULL, 0, NULL); + + return; +} + +typedef struct _menushell_location menushell_location_t; +struct _menushell_location { + const IndicateListenerServer * server; + gint position; + gboolean found; +}; + +static void +menushell_foreach_cb (DbusmenuMenuitem * data_mi, gpointer data_ms) { + menushell_location_t * msl = (menushell_location_t *)data_ms; + + if (msl->found) return; + + msl->position++; + + if (!IS_APP_MENU_ITEM(data_mi)) { + return; + } + + AppMenuItem * appmenu = APP_MENU_ITEM(data_mi); + if (!g_strcmp0(INDICATE_LISTENER_SERVER_DBUS_NAME((IndicateListenerServer*)msl->server), INDICATE_LISTENER_SERVER_DBUS_NAME(app_menu_item_get_server(appmenu)))) { + msl->found = TRUE; + } + + return; +} + +static void +reconsile_list_and_menu (GList * serverlist, DbusmenuMenuitem * menushell) +{ + guint position = 0; + GList * serverentry; + + g_debug("Reordering Menu:"); + + for (serverentry = serverList; serverentry != NULL; serverentry = serverentry->next) { + serverList_t * si = (serverList_t *)serverentry->data; + if (si->menuitem != NULL) { + g_debug("\tMoving app %s to position %d", INDICATE_LISTENER_SERVER_DBUS_NAME(si->server), position); + dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(si->menuitem), position); + position++; + } + + GList * imentry; + for (imentry = si->imList; imentry != NULL; imentry = imentry->next) { + imList_t * imi = (imList_t *)imentry->data; + + if (imi->menuitem != NULL) { + g_debug("\tMoving indicator on %s id %d to position %d", INDICATE_LISTENER_SERVER_DBUS_NAME(imi->server), INDICATE_LISTENER_INDICATOR_ID(imi->indicator), position); + dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(imi->menuitem), position); + position++; + } + } + } + + return; +} + +static void +subtype_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) +{ + DbusmenuMenuitem * menushell = DBUSMENU_MENUITEM(data); + if (menushell == NULL) { + g_error("Data in callback is not a menushell"); + return; + } + + if (property == NULL || g_strcmp0(property, "subtype")) { + /* We should only ever get subtypes, but just in case */ + g_warning("Subtype callback got a property '%s'", property); + return; + } + + if (propertydata == NULL || propertydata[0] == '\0') { + /* It's possible that this message didn't have a subtype. That's + * okay, but we don't want to display those */ + g_debug("No subtype"); + return; + } + + g_debug("Message subtype: %s", propertydata); + + if (!g_strcmp0(propertydata, "im") || !g_strcmp0(propertydata, "login")) { + imList_t * listItem = g_new0(imList_t, 1); + listItem->server = server; + listItem->indicator = indicator; + + g_debug("Building IM Item"); + ImMenuItem * menuitem = im_menu_item_new(listener, server, indicator, !g_strcmp0(propertydata, "im")); + g_object_ref(G_OBJECT(menuitem)); + listItem->menuitem = DBUSMENU_MENUITEM(menuitem); + + g_debug("Finding the server entry"); + serverList_t sl_item_local; + serverList_t * sl_item = NULL; + sl_item_local.server = server; + GList * serverentry = g_list_find_custom(serverList, &sl_item_local, serverList_equal); + + if (serverentry == NULL) { + /* This sucks, we got an indicator before the server. I guess + that's the joy of being asynchronous */ + serverList_t * sl_item = g_new0(serverList_t, 1); + sl_item->server = server; + sl_item->menuitem = NULL; + sl_item->imList = NULL; + + serverList = g_list_insert_sorted(serverList, sl_item, serverList_sort); + } else { + sl_item = (serverList_t *)serverentry->data; + } + + g_debug("Adding to IM List"); + sl_item->imList = g_list_insert_sorted(sl_item->imList, listItem, imList_sort); + listItem->timechange_cb = g_signal_connect(G_OBJECT(menuitem), IM_MENU_ITEM_SIGNAL_TIME_CHANGED, G_CALLBACK(im_time_changed), sl_item); + + g_debug("Placing in Shell"); + menushell_location_t msl; + msl.found = FALSE; + msl.position = 0; + msl.server = server; + + dbusmenu_menuitem_foreach(DBUSMENU_MENUITEM(menushell), menushell_foreach_cb, &msl); + if (msl.found) { + dbusmenu_menuitem_child_add_position(menushell, DBUSMENU_MENUITEM(menuitem), msl.position); + } else { + g_warning("Unable to find server menu item"); + dbusmenu_menuitem_child_append(menushell, DBUSMENU_MENUITEM(menuitem)); + } + } + + return; +} + +static void +indicator_added (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data) +{ + if (type == NULL || g_strcmp0(type, "message")) { + /* We only care about message type indicators + all of the others can go to the bit bucket */ + g_debug("Ignoreing indicator of type '%s'", type); + return; + } + g_debug("Got a message"); + + indicate_listener_get_property(listener, server, indicator, "subtype", subtype_cb, data); + return; +} + +static void +indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data) +{ + g_debug("Removing %s %d", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator)); + if (type == NULL || g_strcmp0(type, "message")) { + /* We only care about message type indicators + all of the others can go to the bit bucket */ + g_debug("Ignoreing indicator of type '%s'", type); + return; + } + + gboolean removed = FALSE; + + serverList_t sl_item_local; + serverList_t * sl_item = NULL; + sl_item_local.server = server; + GList * serverentry = g_list_find_custom(serverList, &sl_item_local, serverList_equal); + if (serverentry == NULL) { + return; + } + sl_item = (serverList_t *)serverentry->data; + + /* Look in the IM Hash Table */ + imList_t listData; + listData.server = server; + listData.indicator = indicator; + + GList * listItem = g_list_find_custom(sl_item->imList, &listData, imList_equal); + DbusmenuMenuitem * menuitem = NULL; + imList_t * ilt = NULL; + if (listItem != NULL) { + ilt = (imList_t *)listItem->data; + menuitem = ilt->menuitem; + } + + if (!removed && menuitem != NULL) { + sl_item->imList = g_list_remove(sl_item->imList, ilt); + g_signal_handler_disconnect(menuitem, ilt->timechange_cb); + g_free(ilt); + + dbusmenu_menuitem_property_set(menuitem, "visibile", "false"); + dbusmenu_menuitem_child_delete(DBUSMENU_MENUITEM(data), menuitem); + removed = TRUE; + } + + if (!removed) { + g_warning("We were asked to remove %s %d but we didn't.", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator)); + } + + return; +} + +gboolean +build_launchers (gpointer data) +{ + + + + return FALSE; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + + DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); + DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); + GError * error = NULL; + guint nameret = 0; + + if (!org_freedesktop_DBus_request_name(bus_proxy, INDICATOR_MESSAGES_DBUS_NAME, 0, &nameret, &error)) { + g_error("Unable to call to request name"); + return 1; + } + + if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { + g_error("Unable to get name"); + return 1; + } + + listener = indicate_listener_ref_default(); + serverList = NULL; + + root_menuitem = dbusmenu_menuitem_new(); + DbusmenuServer * server = dbusmenu_server_new(INDICATOR_MESSAGES_DBUS_OBJECT); + dbusmenu_server_set_root(server, root_menuitem); + + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_ADDED, G_CALLBACK(indicator_added), root_menuitem); + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_REMOVED, G_CALLBACK(indicator_removed), root_menuitem); + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), root_menuitem); + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_REMOVED, G_CALLBACK(server_removed), root_menuitem); + + g_idle_add(build_launchers, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + return 0; +} -- cgit v1.2.3 From 24cd5919a5de12b2309ba6f9fa48f402e3d2ae11 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 16:47:04 -0500 Subject: Go through the launchers and start building items --- src/messages-service.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/messages-service.c') diff --git a/src/messages-service.c b/src/messages-service.c index 93c926b..ce3fcdb 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -30,9 +30,11 @@ with this program. If not, see . #include "app-menu-item.h" #include "launcher-menu-item.h" #include "dbus-data.h" +#include "dirs.h" static IndicateListener * listener; -static GList * serverList; +static GList * serverList = NULL; +static GList * launcherList = NULL; static DbusmenuMenuitem * root_menuitem = NULL; static GMainLoop * mainloop = NULL; @@ -489,9 +491,29 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, gboolean build_launchers (gpointer data) { + if (!g_file_test(SYSTEM_APPS_DIR, G_FILE_TEST_IS_DIR)) { + return FALSE; + } + GError * error = NULL; + GDir * dir = g_dir_open(SYSTEM_APPS_DIR, 0, &error); + if (dir == NULL) { + g_warning("Unable to open system apps directory: %s", error->message); + g_error_free(error); + return FALSE; + } + const gchar * filename = NULL; + while ((filename = g_dir_read_name(dir)) != NULL) { + gchar * path = g_build_filename(SYSTEM_APPS_DIR, filename, NULL); + launcherList_t * ll = g_new0(launcherList_t, 1); + ll->menuitem = launcher_menu_item_new(path); + g_free(path); + launcherList = g_list_append(launcherList, ll); + } + g_dir_close(dir); + launcherList = g_list_sort(launcherList, launcherList_sort); return FALSE; } -- cgit v1.2.3 From 23e2cdf7f788996e5dc429444b1fd81425bf3b05 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 16:55:57 -0500 Subject: Spliting out the building of the items as it'll read the desktop file off disk and parse it. --- src/messages-service.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/messages-service.c') diff --git a/src/messages-service.c b/src/messages-service.c index ce3fcdb..481df1d 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -488,6 +488,20 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, return; } +gboolean +build_launcher (gpointer data) +{ + gchar * path = (gchar *)data; + + launcherList_t * ll = g_new0(launcherList_t, 1); + ll->menuitem = launcher_menu_item_new(path); + + g_free(path); + + launcherList = g_list_insert_sorted(launcherList, ll, launcherList_sort); + return FALSE; +} + gboolean build_launchers (gpointer data) { @@ -506,10 +520,7 @@ build_launchers (gpointer data) const gchar * filename = NULL; while ((filename = g_dir_read_name(dir)) != NULL) { gchar * path = g_build_filename(SYSTEM_APPS_DIR, filename, NULL); - launcherList_t * ll = g_new0(launcherList_t, 1); - ll->menuitem = launcher_menu_item_new(path); - g_free(path); - launcherList = g_list_append(launcherList, ll); + g_idle_add(build_launcher, path); } g_dir_close(dir); -- cgit v1.2.3 From a32eba9041f5fb90083f5212bc58bb6d6a094912 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 17:02:27 -0500 Subject: Oops, forgot one level of redirection here --- src/messages-service.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/messages-service.c') diff --git a/src/messages-service.c b/src/messages-service.c index 481df1d..6f62b1f 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -492,11 +492,18 @@ gboolean build_launcher (gpointer data) { gchar * path = (gchar *)data; + gchar * desktop = NULL; + + g_file_get_contents(path, &desktop, NULL, NULL); + g_free(path); + + if (desktop == NULL) { + return FALSE; + } launcherList_t * ll = g_new0(launcherList_t, 1); ll->menuitem = launcher_menu_item_new(path); - g_free(path); launcherList = g_list_insert_sorted(launcherList, ll, launcherList_sort); return FALSE; -- cgit v1.2.3 From 29ce275bdc22d99ab995e260dfcee9fe49e951e1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 20:34:26 -0500 Subject: Lots of debug, but also cleaning up the desktop file name path so it gets properly into the constructor. --- src/messages-service.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/messages-service.c') diff --git a/src/messages-service.c b/src/messages-service.c index 6f62b1f..61e0ca9 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -21,6 +21,7 @@ with this program. If not, see . */ #include +#include #include #include @@ -492,6 +493,7 @@ gboolean build_launcher (gpointer data) { gchar * path = (gchar *)data; + g_debug("\tpath: %s", path); gchar * desktop = NULL; g_file_get_contents(path, &desktop, NULL, NULL); @@ -501,11 +503,17 @@ build_launcher (gpointer data) return FALSE; } - launcherList_t * ll = g_new0(launcherList_t, 1); - ll->menuitem = launcher_menu_item_new(path); + gchar * trimdesktop = pango_trim_string(desktop); + g_debug("\tcontents: %s", trimdesktop); + launcherList_t * ll = g_new0(launcherList_t, 1); + ll->menuitem = launcher_menu_item_new(trimdesktop); launcherList = g_list_insert_sorted(launcherList, ll, launcherList_sort); + + g_free(trimdesktop); + g_free(desktop); + return FALSE; } @@ -526,6 +534,7 @@ build_launchers (gpointer data) const gchar * filename = NULL; while ((filename = g_dir_read_name(dir)) != NULL) { + g_debug("Found file: %s", filename); gchar * path = g_build_filename(SYSTEM_APPS_DIR, filename, NULL); g_idle_add(build_launcher, path); } -- cgit v1.2.3 From 5fdfdc0015f5ffc7ef090688526f3bca2352155c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 20:45:23 -0500 Subject: Getting launchers to add to the menu, and changing the function to do that so it's not all server based. We want everyone involved now. --- src/messages-service.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/messages-service.c') diff --git a/src/messages-service.c b/src/messages-service.c index 61e0ca9..1d8c61c 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -44,7 +44,7 @@ static GMainLoop * mainloop = NULL; static void server_count_changed (AppMenuItem * appitem, guint count, gpointer data); static void server_name_changed (AppMenuItem * appitem, gchar * name, gpointer data); static void im_time_changed (ImMenuItem * imitem, glong seconds, gpointer data); -static void reconsile_list_and_menu (GList * serverlist, DbusmenuMenuitem * menushell); +static void resort_menu (DbusmenuMenuitem * menushell); static void indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data); typedef struct _serverList_t serverList_t; @@ -185,7 +185,7 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha dbusmenu_menuitem_child_append(menushell, DBUSMENU_MENUITEM(menuitem)); /* Should be prepend ^ */ - reconsile_list_and_menu(serverList, menushell); + resort_menu(menushell); return; } @@ -194,7 +194,7 @@ static void server_name_changed (AppMenuItem * appitem, gchar * name, gpointer data) { serverList = g_list_sort(serverList, serverList_sort); - reconsile_list_and_menu(serverList, DBUSMENU_MENUITEM(data)); + resort_menu(DBUSMENU_MENUITEM(data)); return; } @@ -249,7 +249,7 @@ im_time_changed (ImMenuItem * imitem, glong seconds, gpointer data) { serverList_t * sl = (serverList_t *)data; sl->imList = g_list_sort(sl->imList, imList_sort); - reconsile_list_and_menu(serverList, root_menuitem); + resort_menu(root_menuitem); return; } @@ -317,7 +317,7 @@ menushell_foreach_cb (DbusmenuMenuitem * data_mi, gpointer data_ms) { } static void -reconsile_list_and_menu (GList * serverlist, DbusmenuMenuitem * menushell) +resort_menu (DbusmenuMenuitem * menushell) { guint position = 0; GList * serverentry; @@ -492,6 +492,7 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, gboolean build_launcher (gpointer data) { + /* Read the file get the data */ gchar * path = (gchar *)data; g_debug("\tpath: %s", path); gchar * desktop = NULL; @@ -504,15 +505,20 @@ build_launcher (gpointer data) } gchar * trimdesktop = pango_trim_string(desktop); + g_free(desktop); g_debug("\tcontents: %s", trimdesktop); + /* Build the item */ launcherList_t * ll = g_new0(launcherList_t, 1); ll->menuitem = launcher_menu_item_new(trimdesktop); + g_free(trimdesktop); + /* Add it to the list */ launcherList = g_list_insert_sorted(launcherList, ll, launcherList_sort); - g_free(trimdesktop); - g_free(desktop); + /* Add it to the menu */ + dbusmenu_menuitem_child_append(root_menuitem, DBUSMENU_MENUITEM(ll->menuitem)); + resort_menu(root_menuitem); return FALSE; } -- cgit v1.2.3 From 74df2c7eb2914922bf68940994751b8369991300 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 21:15:37 -0500 Subject: Adding the launcher list to the resorting function. This looks more complex than it is, it's just merging the two lists on the fly in alphabetical order. --- src/messages-service.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/messages-service.c') diff --git a/src/messages-service.c b/src/messages-service.c index 1d8c61c..3f2974e 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -321,11 +321,27 @@ resort_menu (DbusmenuMenuitem * menushell) { guint position = 0; GList * serverentry; + GList * launcherentry = launcherList; g_debug("Reordering Menu:"); for (serverentry = serverList; serverentry != NULL; serverentry = serverentry->next) { serverList_t * si = (serverList_t *)serverentry->data; + + if (launcherentry != NULL) { + launcherList_t * li = (launcherList_t *)launcherentry->data; + while (launcherentry != NULL && g_strcmp0(launcher_menu_item_get_name(li->menuitem), app_menu_item_get_name(si->menuitem)) < 0) { + g_debug("\tMoving launcher '%s' to position %d", launcher_menu_item_get_name(li->menuitem), position); + dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(li->menuitem), position); + + position++; + launcherentry = launcherentry->next; + if (launcherentry != NULL) { + li = (launcherList_t *)launcherentry->data; + } + } + } + if (si->menuitem != NULL) { g_debug("\tMoving app %s to position %d", INDICATE_LISTENER_SERVER_DBUS_NAME(si->server), position); dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(si->menuitem), position); @@ -344,6 +360,15 @@ resort_menu (DbusmenuMenuitem * menushell) } } + while (launcherentry != NULL) { + launcherList_t * li = (launcherList_t *)launcherentry->data; + g_debug("\tMoving launcher '%s' to position %d", launcher_menu_item_get_name(li->menuitem), position); + dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(li->menuitem), position); + + position++; + launcherentry = launcherentry->next; + } + return; } -- cgit v1.2.3 From b8adb87bc06248378bc0d72a53c21d566a31e2b4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 21:49:55 -0500 Subject: Adding in a couple function to deal with disappearing launchers. --- src/messages-service.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/messages-service.c') diff --git a/src/messages-service.c b/src/messages-service.c index 3f2974e..c3b3db9 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -46,6 +46,8 @@ static void server_name_changed (AppMenuItem * appitem, gchar * name, gpointer d static void im_time_changed (ImMenuItem * imitem, glong seconds, gpointer data); static void resort_menu (DbusmenuMenuitem * menushell); static void indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data); +static void check_eclipses (AppMenuItem * ai); +static void remove_eclipses (AppMenuItem * ai); typedef struct _serverList_t serverList_t; struct _serverList_t { @@ -194,6 +196,7 @@ static void server_name_changed (AppMenuItem * appitem, gchar * name, gpointer data) { serverList = g_list_sort(serverList, serverList_sort); + check_eclipses(appitem); resort_menu(DBUSMENU_MENUITEM(data)); return; } @@ -268,6 +271,8 @@ server_removed (IndicateListener * listener, IndicateListenerServer * server, gc serverList_t * sltp = (serverList_t *)lookup->data; + remove_eclipses(sltp->menuitem); + while (sltp->imList) { imList_t * imitem = (imList_t *)sltp->imList->data; indicator_removed(listener, server, imitem->indicator, "message", data); @@ -514,6 +519,27 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, return; } +/* Check to see if a new desktop file causes + any of the launchers to be eclipsed by a running + process */ +static void +check_eclipses (AppMenuItem * ai) +{ + + + return; +} + +/* Remove any eclipses that might have been caused + by this app item that is now retiring */ +static void +remove_eclipses (AppMenuItem * ai) +{ + + + return; +} + gboolean build_launcher (gpointer data) { -- cgit v1.2.3 From de5f8b0273d835a96eccdcb2ecb744e41ec082db Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 21:53:09 -0500 Subject: Clean up, clean up, everybody everywhere --- src/messages-service.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/messages-service.c') diff --git a/src/messages-service.c b/src/messages-service.c index c3b3db9..c6bc5b8 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -48,6 +48,8 @@ static void resort_menu (DbusmenuMenuitem * menushell); static void indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data); static void check_eclipses (AppMenuItem * ai); static void remove_eclipses (AppMenuItem * ai); +static gboolean build_launcher (gpointer data); +static gboolean build_launchers (gpointer data); typedef struct _serverList_t serverList_t; struct _serverList_t { @@ -540,7 +542,9 @@ remove_eclipses (AppMenuItem * ai) return; } -gboolean +/* This function turns a specific file into a menu + item and registers it appropriately with everyone */ +static gboolean build_launcher (gpointer data) { /* Read the file get the data */ @@ -574,7 +578,11 @@ build_launcher (gpointer data) return FALSE; } -gboolean +/* This function goes through all the launchers that we're + supposed to be grabbing and decides to show turn them + into menu items or not. It doens't do the work, but it + makes the decision. */ +static gboolean build_launchers (gpointer data) { if (!g_file_test(SYSTEM_APPS_DIR, G_FILE_TEST_IS_DIR)) { -- cgit v1.2.3 From 17745461f669047872c12a6c7db7b05a9ccb0417 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 22:29:40 -0500 Subject: Big commit. Trying to check for eclipses, but first both objects needed to track their desktop file paths. So I had to add that little nugget in as well. --- src/messages-service.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/messages-service.c') diff --git a/src/messages-service.c b/src/messages-service.c index c6bc5b8..f8f1aaf 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -527,7 +527,18 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, static void check_eclipses (AppMenuItem * ai) { + const gchar * aidesktop = app_menu_item_get_desktop(ai); + if (aidesktop == NULL) return; + GList * llitem; + for (llitem = launcherList; llitem != NULL; llitem = llitem->next) { + const gchar * lidesktop = launcher_menu_item_get_desktop(LAUNCHER_MENU_ITEM(llitem->data)); + + if (!g_strcmp0(aidesktop, lidesktop)) { + launcher_menu_item_set_eclipsed(LAUNCHER_MENU_ITEM(llitem->data), TRUE); + break; + } + } return; } @@ -537,7 +548,18 @@ check_eclipses (AppMenuItem * ai) static void remove_eclipses (AppMenuItem * ai) { + const gchar * aidesktop = app_menu_item_get_desktop(ai); + if (aidesktop == NULL) return; + GList * llitem; + for (llitem = launcherList; llitem != NULL; llitem = llitem->next) { + const gchar * lidesktop = launcher_menu_item_get_desktop(LAUNCHER_MENU_ITEM(llitem->data)); + + if (!g_strcmp0(aidesktop, lidesktop)) { + launcher_menu_item_set_eclipsed(LAUNCHER_MENU_ITEM(llitem->data), FALSE); + break; + } + } return; } @@ -609,6 +631,8 @@ build_launchers (gpointer data) return FALSE; } +/* Oh, if you don't know what main() is for + we really shouldn't be talking. */ int main (int argc, char ** argv) { -- cgit v1.2.3 From db8ada09e2f254026f318b38cd45ae1cd765f584 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 22:42:15 -0500 Subject: Ah, where casting kills. You can cast anything to the right value even though it's not. Nice opaque errors you get for that. --- src/messages-service.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/messages-service.c') diff --git a/src/messages-service.c b/src/messages-service.c index f8f1aaf..395bf32 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -532,10 +532,11 @@ check_eclipses (AppMenuItem * ai) GList * llitem; for (llitem = launcherList; llitem != NULL; llitem = llitem->next) { - const gchar * lidesktop = launcher_menu_item_get_desktop(LAUNCHER_MENU_ITEM(llitem->data)); + launcherList_t * ll = (launcherList_t *)llitem->data; + const gchar * lidesktop = launcher_menu_item_get_desktop(ll->menuitem); if (!g_strcmp0(aidesktop, lidesktop)) { - launcher_menu_item_set_eclipsed(LAUNCHER_MENU_ITEM(llitem->data), TRUE); + launcher_menu_item_set_eclipsed(ll->menuitem, TRUE); break; } } @@ -553,10 +554,11 @@ remove_eclipses (AppMenuItem * ai) GList * llitem; for (llitem = launcherList; llitem != NULL; llitem = llitem->next) { - const gchar * lidesktop = launcher_menu_item_get_desktop(LAUNCHER_MENU_ITEM(llitem->data)); + launcherList_t * ll = (launcherList_t *)llitem->data; + const gchar * lidesktop = launcher_menu_item_get_desktop(ll->menuitem); if (!g_strcmp0(aidesktop, lidesktop)) { - launcher_menu_item_set_eclipsed(LAUNCHER_MENU_ITEM(llitem->data), FALSE); + launcher_menu_item_set_eclipsed(ll->menuitem, FALSE); break; } } -- cgit v1.2.3 From c49644e5e7a901c2113d6d0a88e54b4224f90de5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 22:54:33 -0500 Subject: Oh, some debug messages to see what's going on. --- src/messages-service.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/messages-service.c') diff --git a/src/messages-service.c b/src/messages-service.c index 395bf32..2020dd3 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -527,13 +527,16 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, static void check_eclipses (AppMenuItem * ai) { + g_debug("Checking eclipsing"); const gchar * aidesktop = app_menu_item_get_desktop(ai); if (aidesktop == NULL) return; + g_debug("\tApp desktop: %s", aidesktop); GList * llitem; for (llitem = launcherList; llitem != NULL; llitem = llitem->next) { launcherList_t * ll = (launcherList_t *)llitem->data; const gchar * lidesktop = launcher_menu_item_get_desktop(ll->menuitem); + g_debug("\tLauncher desktop: %s", lidesktop); if (!g_strcmp0(aidesktop, lidesktop)) { launcher_menu_item_set_eclipsed(ll->menuitem, TRUE); -- cgit v1.2.3