From ba21dc6356e53dc5c8ab7aa190d3cd3cc0fdd8f3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 13:36:22 -0500 Subject: AM 1.11 silent rule --- configure.ac | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configure.ac b/configure.ac index 9093512..19a549c 100644 --- a/configure.ac +++ b/configure.ac @@ -17,6 +17,8 @@ AC_PROG_LIBTOOL AC_SUBST(VERSION) AC_CONFIG_MACRO_DIR([m4]) +m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) + ########################### # Dependencies ########################### -- cgit v1.2.3 From 1656fcc2e581fe4ba9bf8befbf6c94fe1f0a8f20 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 13:50:16 -0500 Subject: Adding directories. Let's put them in one file so that they'll be changable easy :) --- src/dirs.h | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 src/dirs.h diff --git a/src/dirs.h b/src/dirs.h new file mode 100644 index 0000000..a994ff5 --- /dev/null +++ b/src/dirs.h @@ -0,0 +1,3 @@ +#define SYSTEM_APPS_DIR "/etc/indicators/messages/applications" +#define USER_APPS_DIR "indicators/messages/applications" +#define USER_BLACKLIST_DIR "indicators/messages/applications-blacklist" -- cgit v1.2.3 From aed88cf243dc4862683acc886513ad970aafad60 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 15:22:58 -0500 Subject: Adding the basis for launchers --- src/indicator-service.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/indicator-service.c b/src/indicator-service.c index cb7e23a..93c926b 100644 --- a/src/indicator-service.c +++ b/src/indicator-service.c @@ -28,6 +28,7 @@ with this program. If not, see . #include "im-menu-item.h" #include "app-menu-item.h" +#include "launcher-menu-item.h" #include "dbus-data.h" static IndicateListener * listener; @@ -116,6 +117,25 @@ imList_sort (gconstpointer a, gconstpointer 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) { @@ -466,6 +486,15 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, return; } +gboolean +build_launchers (gpointer data) +{ + + + + return FALSE; +} + int main (int argc, char ** argv) { @@ -498,6 +527,8 @@ main (int argc, char ** argv) 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); -- cgit v1.2.3 From f0269893fd65671ee5022a7be43570572e118917 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 15:37:31 -0500 Subject: No reason that all these should be linked into the loadable module. Err, fail. --- src/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 74db2df..4944c45 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,7 +3,7 @@ bin_PROGRAMS = indicator-messages-service messaginglibdir = $(INDICATORDIR) messaginglib_LTLIBRARIES = libmessaging.la -libmessaging_la_SOURCES = indicator-messages.c im-menu-item.c im-menu-item.h app-menu-item.c app-menu-item.h +libmessaging_la_SOURCES = indicator-messages.c libmessaging_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Wl,-Bsymbolic-functions -Wl,-z,defs -Wl,--as-needed -Werror libmessaging_la_LIBADD = $(APPLET_LIBS) libmessaging_la_LDFLAGS = -module -avoid-version -- cgit v1.2.3 From 83836f587d5f4c11a9227c215a719a4ec4f2a71f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 15:38:15 -0500 Subject: Adding in a new menu-item type. One for launchers! Woo Hoo! --- src/Makefile.am | 2 +- src/launcher-menu-item.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++ src/launcher-menu-item.h | 62 ++++++++++++++++++++++ 3 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 src/launcher-menu-item.c create mode 100644 src/launcher-menu-item.h diff --git a/src/Makefile.am b/src/Makefile.am index 4944c45..fea03eb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,6 +8,6 @@ libmessaging_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Wl,-Bsymbolic-functions -Wl,-z, libmessaging_la_LIBADD = $(APPLET_LIBS) libmessaging_la_LDFLAGS = -module -avoid-version -indicator_messages_service_SOURCES = indicator-service.c im-menu-item.c im-menu-item.h app-menu-item.c app-menu-item.h +indicator_messages_service_SOURCES = indicator-service.c im-menu-item.c im-menu-item.h app-menu-item.c app-menu-item.h launcher-menu-item.c launcher-menu-item.h indicator_messages_service_CFLAGS = $(APPLET_CFLAGS) -Wall -Wl,-Bsymbolic-functions -Wl,-z,defs -Wl,--as-needed -Werror indicator_messages_service_LDADD = $(APPLET_LIBS) diff --git a/src/launcher-menu-item.c b/src/launcher-menu-item.c new file mode 100644 index 0000000..ce8fd5f --- /dev/null +++ b/src/launcher-menu-item.c @@ -0,0 +1,133 @@ +/* +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 . +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include "launcher-menu-item.h" + +enum { + NAME_CHANGED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + +typedef struct _LauncherMenuItemPrivate LauncherMenuItemPrivate; +struct _LauncherMenuItemPrivate +{ + GAppInfo * appinfo; +}; + +#define LAUNCHER_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LAUNCHER_MENU_ITEM_TYPE, LauncherMenuItemPrivate)) + +/* Prototypes */ +static void launcher_menu_item_class_init (LauncherMenuItemClass *klass); +static void launcher_menu_item_init (LauncherMenuItem *self); +static void launcher_menu_item_dispose (GObject *object); +static void launcher_menu_item_finalize (GObject *object); + + +G_DEFINE_TYPE (LauncherMenuItem, launcher_menu_item, DBUSMENU_TYPE_MENUITEM); + +static void +launcher_menu_item_class_init (LauncherMenuItemClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (LauncherMenuItemPrivate)); + + object_class->dispose = launcher_menu_item_dispose; + object_class->finalize = launcher_menu_item_finalize; + + signals[NAME_CHANGED] = g_signal_new(LAUNCHER_MENU_ITEM_SIGNAL_NAME_CHANGED, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (LauncherMenuItemClass, name_changed), + NULL, NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, G_TYPE_STRING); + + return; +} + +static void +launcher_menu_item_init (LauncherMenuItem *self) +{ + g_debug("Building new Launcher Menu Item"); + LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(self); + + priv->appinfo = NULL; + + return; +} + +static void +launcher_menu_item_dispose (GObject *object) +{ + // LauncherMenuItem * self = LAUNCHER_MENU_ITEM(object); + // LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(self); + + G_OBJECT_CLASS (launcher_menu_item_parent_class)->dispose (object); +} + +static void +launcher_menu_item_finalize (GObject *object) +{ + LauncherMenuItem * self = LAUNCHER_MENU_ITEM(object); + LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(self); + + if (priv->appinfo != NULL) { + g_object_unref(priv->appinfo); + } + + G_OBJECT_CLASS (launcher_menu_item_parent_class)->finalize (object); + + return; +} + +LauncherMenuItem * +launcher_menu_item_new (const gchar * desktop_file) +{ + LauncherMenuItem * self = g_object_new(LAUNCHER_MENU_ITEM_TYPE, NULL); + + LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(self); + + priv->appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(desktop_file)); + + return self; +} + +const gchar * +launcher_menu_item_get_name (LauncherMenuItem * appitem) +{ + LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(appitem); + + if (priv->appinfo == NULL) { + return NULL; + } else { + return g_app_info_get_name(priv->appinfo); + } +} diff --git a/src/launcher-menu-item.h b/src/launcher-menu-item.h new file mode 100644 index 0000000..c351dd9 --- /dev/null +++ b/src/launcher-menu-item.h @@ -0,0 +1,62 @@ +/* +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 . +*/ + +#ifndef __LAUNCHER_MENU_ITEM_H__ +#define __LAUNCHER_MENU_ITEM_H__ + +#include +#include + +#include + +G_BEGIN_DECLS + +#define LAUNCHER_MENU_ITEM_TYPE (launcher_menu_item_get_type ()) +#define LAUNCHER_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), LAUNCHER_MENU_ITEM_TYPE, LauncherMenuItem)) +#define LAUNCHER_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), LAUNCHER_MENU_ITEM_TYPE, LauncherMenuItemClass)) +#define IS_LAUNCHER_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), LAUNCHER_MENU_ITEM_TYPE)) +#define IS_LAUNCHER_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), LAUNCHER_MENU_ITEM_TYPE)) +#define LAUNCHER_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), LAUNCHER_MENU_ITEM_TYPE, LauncherMenuItemClass)) + +#define LAUNCHER_MENU_ITEM_SIGNAL_NAME_CHANGED "name-changed" + +typedef struct _LauncherMenuItem LauncherMenuItem; +typedef struct _LauncherMenuItemClass LauncherMenuItemClass; + +struct _LauncherMenuItemClass { + DbusmenuMenuitemClass parent_class; + + void (* name_changed) (gchar * name); +}; + +struct _LauncherMenuItem { + DbusmenuMenuitem parent; +}; + +GType launcher_menu_item_get_type (void); +LauncherMenuItem * launcher_menu_item_new (const gchar * desktop_file); +const gchar * launcher_menu_item_get_name (LauncherMenuItem * appitem); + +G_END_DECLS + +#endif /* __LAUNCHER_MENU_ITEM_H__ */ + -- cgit v1.2.3 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/Makefile.am | 2 +- src/indicator-service.c | 536 ------------------------------------------------ src/messages-service.c | 536 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 537 insertions(+), 537 deletions(-) delete mode 100644 src/indicator-service.c create mode 100644 src/messages-service.c diff --git a/src/Makefile.am b/src/Makefile.am index fea03eb..0428cbb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,6 +8,6 @@ libmessaging_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Wl,-Bsymbolic-functions -Wl,-z, libmessaging_la_LIBADD = $(APPLET_LIBS) libmessaging_la_LDFLAGS = -module -avoid-version -indicator_messages_service_SOURCES = indicator-service.c im-menu-item.c im-menu-item.h app-menu-item.c app-menu-item.h launcher-menu-item.c launcher-menu-item.h +indicator_messages_service_SOURCES = messages-service.c im-menu-item.c im-menu-item.h app-menu-item.c app-menu-item.h launcher-menu-item.c launcher-menu-item.h indicator_messages_service_CFLAGS = $(APPLET_CFLAGS) -Wall -Wl,-Bsymbolic-functions -Wl,-z,defs -Wl,--as-needed -Werror indicator_messages_service_LDADD = $(APPLET_LIBS) diff --git a/src/indicator-service.c b/src/indicator-service.c deleted file mode 100644 index 93c926b..0000000 --- a/src/indicator-service.c +++ /dev/null @@ -1,536 +0,0 @@ -/* -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; -} 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(-) 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(-) 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(-) 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/launcher-menu-item.c | 3 +++ src/messages-service.c | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/launcher-menu-item.c b/src/launcher-menu-item.c index ce8fd5f..915c81c 100644 --- a/src/launcher-menu-item.c +++ b/src/launcher-menu-item.c @@ -112,11 +112,14 @@ LauncherMenuItem * launcher_menu_item_new (const gchar * desktop_file) { LauncherMenuItem * self = g_object_new(LAUNCHER_MENU_ITEM_TYPE, NULL); + g_debug("\tDesktop file: %s", desktop_file); LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(self); priv->appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(desktop_file)); + g_debug("\tName: %s", launcher_menu_item_get_name(self)); + return self; } 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 69a569919e85cec838fce571be5fe319d17258e0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 20:38:33 -0500 Subject: Setting the label of the menu item. --- src/launcher-menu-item.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/launcher-menu-item.c b/src/launcher-menu-item.c index 915c81c..e8fc269 100644 --- a/src/launcher-menu-item.c +++ b/src/launcher-menu-item.c @@ -119,6 +119,7 @@ launcher_menu_item_new (const gchar * desktop_file) priv->appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(desktop_file)); g_debug("\tName: %s", launcher_menu_item_get_name(self)); + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "label", launcher_menu_item_get_name(self)); return self; } -- 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(-) 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 dbba757b9c5e2ff2b67221915264c8963982cb24 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 20:54:41 -0500 Subject: Missing a couple headers for distcheckness --- src/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 0428cbb..b4a6bdd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,11 +3,11 @@ bin_PROGRAMS = indicator-messages-service messaginglibdir = $(INDICATORDIR) messaginglib_LTLIBRARIES = libmessaging.la -libmessaging_la_SOURCES = indicator-messages.c +libmessaging_la_SOURCES = indicator-messages.c dbus-data.h libmessaging_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Wl,-Bsymbolic-functions -Wl,-z,defs -Wl,--as-needed -Werror libmessaging_la_LIBADD = $(APPLET_LIBS) libmessaging_la_LDFLAGS = -module -avoid-version -indicator_messages_service_SOURCES = messages-service.c im-menu-item.c im-menu-item.h app-menu-item.c app-menu-item.h launcher-menu-item.c launcher-menu-item.h +indicator_messages_service_SOURCES = messages-service.c im-menu-item.c im-menu-item.h app-menu-item.c app-menu-item.h launcher-menu-item.c launcher-menu-item.h dirs.h dbus-data.h indicator_messages_service_CFLAGS = $(APPLET_CFLAGS) -Wall -Wl,-Bsymbolic-functions -Wl,-z,defs -Wl,--as-needed -Werror indicator_messages_service_LDADD = $(APPLET_LIBS) -- cgit v1.2.3 From 72be94fdd1299c2bcec99e169f4800ff6e89c516 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 20:57:37 -0500 Subject: Making this file a little more readable. Eh, I guess you never plan on them getting this big when you start do you? I remember when he was just a little automake file. --- src/Makefile.am | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index b4a6bdd..0678537 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,13 +1,32 @@ bin_PROGRAMS = indicator-messages-service +###################################### +# Building the messages indicator +###################################### + messaginglibdir = $(INDICATORDIR) messaginglib_LTLIBRARIES = libmessaging.la -libmessaging_la_SOURCES = indicator-messages.c dbus-data.h +libmessaging_la_SOURCES = \ + indicator-messages.c\ + dbus-data.h libmessaging_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Wl,-Bsymbolic-functions -Wl,-z,defs -Wl,--as-needed -Werror libmessaging_la_LIBADD = $(APPLET_LIBS) libmessaging_la_LDFLAGS = -module -avoid-version -indicator_messages_service_SOURCES = messages-service.c im-menu-item.c im-menu-item.h app-menu-item.c app-menu-item.h launcher-menu-item.c launcher-menu-item.h dirs.h dbus-data.h +###################################### +# Building the messages service +###################################### + +indicator_messages_service_SOURCES = \ + messages-service.c \ + im-menu-item.c \ + im-menu-item.h \ + app-menu-item.c \ + app-menu-item.h \ + launcher-menu-item.c \ + launcher-menu-item.h \ + dirs.h \ + dbus-data.h indicator_messages_service_CFLAGS = $(APPLET_CFLAGS) -Wall -Wl,-Bsymbolic-functions -Wl,-z,defs -Wl,--as-needed -Werror indicator_messages_service_LDADD = $(APPLET_LIBS) -- 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(+) 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 cfb0854e7c6bfa7cc9ac5ffdcd6672ad812ecfa0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 21:30:02 -0500 Subject: Adding in the activate logic so that the menu items actually launch the application. --- src/launcher-menu-item.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/launcher-menu-item.c b/src/launcher-menu-item.c index e8fc269..7970288 100644 --- a/src/launcher-menu-item.c +++ b/src/launcher-menu-item.c @@ -48,6 +48,7 @@ static void launcher_menu_item_class_init (LauncherMenuItemClass *klass); static void launcher_menu_item_init (LauncherMenuItem *self); static void launcher_menu_item_dispose (GObject *object); static void launcher_menu_item_finalize (GObject *object); +void activate_cb (LauncherMenuItem * self, gpointer data); G_DEFINE_TYPE (LauncherMenuItem, launcher_menu_item, DBUSMENU_TYPE_MENUITEM); @@ -121,6 +122,8 @@ launcher_menu_item_new (const gchar * desktop_file) g_debug("\tName: %s", launcher_menu_item_get_name(self)); dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "label", launcher_menu_item_get_name(self)); + g_signal_connect(G_OBJECT(self), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), NULL); + return self; } @@ -135,3 +138,18 @@ launcher_menu_item_get_name (LauncherMenuItem * appitem) return g_app_info_get_name(priv->appinfo); } } + +void +activate_cb (LauncherMenuItem * self, gpointer data) +{ + LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(self); + g_return_if_fail(priv->appinfo != NULL); + + GError * error = NULL; + if (!g_app_info_launch(priv->appinfo, NULL, NULL, &error)) { + g_warning("Application failed to launch '%s' because: %s", launcher_menu_item_get_name(self), error->message); + g_error_free(error); + } + + 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(+) 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(-) 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 99744b30f0ebf4c7054b8274c30af063ec52b248 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Aug 2009 21:59:43 -0500 Subject: Adding an eclipsed function for the LMI --- src/launcher-menu-item.c | 16 ++++++++++++++-- src/launcher-menu-item.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/launcher-menu-item.c b/src/launcher-menu-item.c index 7970288..b869a40 100644 --- a/src/launcher-menu-item.c +++ b/src/launcher-menu-item.c @@ -48,7 +48,7 @@ static void launcher_menu_item_class_init (LauncherMenuItemClass *klass); static void launcher_menu_item_init (LauncherMenuItem *self); static void launcher_menu_item_dispose (GObject *object); static void launcher_menu_item_finalize (GObject *object); -void activate_cb (LauncherMenuItem * self, gpointer data); +static void activate_cb (LauncherMenuItem * self, gpointer data); G_DEFINE_TYPE (LauncherMenuItem, launcher_menu_item, DBUSMENU_TYPE_MENUITEM); @@ -139,7 +139,9 @@ launcher_menu_item_get_name (LauncherMenuItem * appitem) } } -void +/* When the menu item is clicked on it tries to launch + the application that is represented by the desktop file */ +static void activate_cb (LauncherMenuItem * self, gpointer data) { LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(self); @@ -153,3 +155,13 @@ activate_cb (LauncherMenuItem * self, gpointer data) return; } + +/* Hides the menu item based on whether it is eclipsed + or not. */ +void +launcher_menu_item_set_eclipsed (LauncherMenuItem * li, gboolean eclipsed) +{ + g_debug("Laucher '%s' is %s", launcher_menu_item_get_name(li), eclipsed ? "now eclipsed" : "shown again"); + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(li), "show", eclipsed ? "false" : "true"); + return; +} diff --git a/src/launcher-menu-item.h b/src/launcher-menu-item.h index c351dd9..f17fbad 100644 --- a/src/launcher-menu-item.h +++ b/src/launcher-menu-item.h @@ -55,6 +55,7 @@ struct _LauncherMenuItem { GType launcher_menu_item_get_type (void); LauncherMenuItem * launcher_menu_item_new (const gchar * desktop_file); const gchar * launcher_menu_item_get_name (LauncherMenuItem * appitem); +void launcher_menu_item_set_eclipsed (LauncherMenuItem * li, gboolean eclipsed); G_END_DECLS -- 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/app-menu-item.c | 27 ++++++++++++++++++++++++++- src/app-menu-item.h | 1 + src/launcher-menu-item.c | 17 +++++++++++++++++ src/launcher-menu-item.h | 1 + src/messages-service.c | 24 ++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 2212be5..3a2c795 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -45,6 +45,7 @@ struct _AppMenuItemPrivate gchar * type; GAppInfo * appinfo; + gchar * desktop; guint unreadcount; gboolean count_on_label; }; @@ -105,6 +106,7 @@ app_menu_item_init (AppMenuItem *self) priv->server = NULL; priv->type = NULL; priv->appinfo = NULL; + priv->desktop = NULL; priv->unreadcount = 0; priv->count_on_label = FALSE; @@ -136,6 +138,10 @@ app_menu_item_finalize (GObject *object) g_free(priv->type); } + if (priv->desktop != NULL) { + g_free(priv->desktop); + } + if (priv->appinfo != NULL) { g_object_unref(priv->appinfo); } @@ -229,15 +235,23 @@ desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar if (priv->appinfo != NULL) { g_object_unref(G_OBJECT(priv->appinfo)); + priv->appinfo = NULL; + } + + if (priv->desktop != NULL) { + g_free(priv->desktop); + priv->desktop = NULL; } if (value == NULL || value[0] == '\0') { return; } - + priv->appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(value)); g_return_if_fail(priv->appinfo != NULL); + priv->desktop = g_strdup(value); + update_label(self); g_signal_emit(G_OBJECT(self), signals[NAME_CHANGED], 0, app_menu_item_get_name(self), TRUE); @@ -297,6 +311,7 @@ indicator_removed_cb (IndicateListener * listener, IndicateListenerServer * serv guint app_menu_item_get_count (AppMenuItem * appitem) { + g_return_val_if_fail(IS_APP_MENU_ITEM(appitem), 0); AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(appitem); return priv->unreadcount; @@ -304,6 +319,7 @@ app_menu_item_get_count (AppMenuItem * appitem) IndicateListenerServer * app_menu_item_get_server (AppMenuItem * appitem) { + g_return_val_if_fail(IS_APP_MENU_ITEM(appitem), NULL); AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(appitem); return priv->server; @@ -312,6 +328,7 @@ app_menu_item_get_server (AppMenuItem * appitem) { const gchar * app_menu_item_get_name (AppMenuItem * appitem) { + g_return_val_if_fail(IS_APP_MENU_ITEM(appitem), NULL); AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(appitem); if (priv->appinfo == NULL) { @@ -320,3 +337,11 @@ app_menu_item_get_name (AppMenuItem * appitem) return g_app_info_get_name(priv->appinfo); } } + +const gchar * +app_menu_item_get_desktop (AppMenuItem * appitem) +{ + g_return_val_if_fail(IS_APP_MENU_ITEM(appitem), NULL); + AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(appitem); + return priv->desktop; +} diff --git a/src/app-menu-item.h b/src/app-menu-item.h index dda4765..583d50d 100644 --- a/src/app-menu-item.h +++ b/src/app-menu-item.h @@ -59,6 +59,7 @@ AppMenuItem * app_menu_item_new (IndicateListener * listener, IndicateListenerSe guint app_menu_item_get_count (AppMenuItem * appitem); IndicateListenerServer * app_menu_item_get_server (AppMenuItem * appitem); const gchar * app_menu_item_get_name (AppMenuItem * appitem); +const gchar * app_menu_item_get_desktop (AppMenuItem * appitem); G_END_DECLS diff --git a/src/launcher-menu-item.c b/src/launcher-menu-item.c index b869a40..4f05ae6 100644 --- a/src/launcher-menu-item.c +++ b/src/launcher-menu-item.c @@ -39,6 +39,7 @@ typedef struct _LauncherMenuItemPrivate LauncherMenuItemPrivate; struct _LauncherMenuItemPrivate { GAppInfo * appinfo; + gchar * desktop; }; #define LAUNCHER_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LAUNCHER_MENU_ITEM_TYPE, LauncherMenuItemPrivate)) @@ -81,6 +82,7 @@ launcher_menu_item_init (LauncherMenuItem *self) LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(self); priv->appinfo = NULL; + priv->desktop = NULL; return; } @@ -102,6 +104,12 @@ launcher_menu_item_finalize (GObject *object) if (priv->appinfo != NULL) { g_object_unref(priv->appinfo); + priv->appinfo = NULL; + } + + if (priv->desktop != NULL) { + g_free(priv->desktop); + priv->desktop = NULL; } G_OBJECT_CLASS (launcher_menu_item_parent_class)->finalize (object); @@ -118,6 +126,7 @@ launcher_menu_item_new (const gchar * desktop_file) LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(self); priv->appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(desktop_file)); + priv->desktop = g_strdup(desktop_file); g_debug("\tName: %s", launcher_menu_item_get_name(self)); dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "label", launcher_menu_item_get_name(self)); @@ -156,6 +165,14 @@ activate_cb (LauncherMenuItem * self, gpointer data) return; } +const gchar * +launcher_menu_item_get_desktop (LauncherMenuItem * launchitem) +{ + g_return_val_if_fail(IS_LAUNCHER_MENU_ITEM(launchitem), NULL); + LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(launchitem); + return priv->desktop; +} + /* Hides the menu item based on whether it is eclipsed or not. */ void diff --git a/src/launcher-menu-item.h b/src/launcher-menu-item.h index f17fbad..2b39073 100644 --- a/src/launcher-menu-item.h +++ b/src/launcher-menu-item.h @@ -55,6 +55,7 @@ struct _LauncherMenuItem { GType launcher_menu_item_get_type (void); LauncherMenuItem * launcher_menu_item_new (const gchar * desktop_file); const gchar * launcher_menu_item_get_name (LauncherMenuItem * appitem); +const gchar * launcher_menu_item_get_desktop (LauncherMenuItem * launchitem); void launcher_menu_item_set_eclipsed (LauncherMenuItem * li, gboolean eclipsed); G_END_DECLS 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(-) 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(+) 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 From 8483b2d92f9b86e6d00afc163b835a47e1bebdbe Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 10:25:07 -0500 Subject: Use a GDK app context. Not sure about the timestamp units though. --- src/launcher-menu-item.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/launcher-menu-item.c b/src/launcher-menu-item.c index 4f05ae6..653592c 100644 --- a/src/launcher-menu-item.c +++ b/src/launcher-menu-item.c @@ -24,6 +24,7 @@ with this program. If not, see . #include "config.h" #endif +#include #include #include #include "launcher-menu-item.h" @@ -156,12 +157,23 @@ activate_cb (LauncherMenuItem * self, gpointer data) LauncherMenuItemPrivate * priv = LAUNCHER_MENU_ITEM_GET_PRIVATE(self); g_return_if_fail(priv->appinfo != NULL); + /* This should manage the X stuff for us */ + GdkAppLaunchContext * context = gdk_app_launch_context_new(); + + /* Using the current time as we don't have the event + time as that's not sent across the bus */ + GTimeVal time; + g_get_current_time(&time); + gdk_app_launch_context_set_timestamp(context, time.tv_usec); + GError * error = NULL; - if (!g_app_info_launch(priv->appinfo, NULL, NULL, &error)) { + if (!g_app_info_launch(priv->appinfo, NULL, G_APP_LAUNCH_CONTEXT(context), &error)) { g_warning("Application failed to launch '%s' because: %s", launcher_menu_item_get_name(self), error->message); g_error_free(error); } + g_object_unref(G_OBJECT(context)); + return; } -- cgit v1.2.3 From da36b66e974c34b2024677396236a62e5973e9c9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 11:29:09 -0500 Subject: Should be in milliseconds not micro --- src/launcher-menu-item.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/launcher-menu-item.c b/src/launcher-menu-item.c index 653592c..6c79adb 100644 --- a/src/launcher-menu-item.c +++ b/src/launcher-menu-item.c @@ -164,7 +164,7 @@ activate_cb (LauncherMenuItem * self, gpointer data) time as that's not sent across the bus */ GTimeVal time; g_get_current_time(&time); - gdk_app_launch_context_set_timestamp(context, time.tv_usec); + gdk_app_launch_context_set_timestamp(context, time.tv_usec / 1000); GError * error = NULL; if (!g_app_info_launch(priv->appinfo, NULL, G_APP_LAUNCH_CONTEXT(context), &error)) { -- cgit v1.2.3 From b0f699b4d657330edfa56cd27c856db9941d3a0c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 14:04:58 -0500 Subject: Adding in a couple of blacklist check point. --- src/messages-service.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index 2020dd3..8743b62 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -143,6 +143,13 @@ launcherList_sort (gconstpointer a, gconstpointer b) return g_strcmp0(pan, pbn); } +static gboolean +blacklist_check (const gchar * desktop_file) +{ + + return FALSE; +} + static void server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) { @@ -555,6 +562,8 @@ remove_eclipses (AppMenuItem * ai) const gchar * aidesktop = app_menu_item_get_desktop(ai); if (aidesktop == NULL) return; + if (blacklist_check(aidesktop)) return; + GList * llitem; for (llitem = launcherList; llitem != NULL; llitem = llitem->next) { launcherList_t * ll = (launcherList_t *)llitem->data; @@ -602,6 +611,10 @@ build_launcher (gpointer data) dbusmenu_menuitem_child_append(root_menuitem, DBUSMENU_MENUITEM(ll->menuitem)); resort_menu(root_menuitem); + if (blacklist_check(trimdesktop)) { + launcher_menu_item_set_eclipsed(ll->menuitem, TRUE); + } + return FALSE; } -- cgit v1.2.3 From 754694356af4079753531d5a090c0d7ed9eee828 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 14:06:52 -0500 Subject: Adding in some seperators to make things more clear. --- src/messages-service.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index 8743b62..9879e3a 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -51,6 +51,11 @@ static void remove_eclipses (AppMenuItem * ai); static gboolean build_launcher (gpointer data); static gboolean build_launchers (gpointer data); + +/* + * Server List + */ + typedef struct _serverList_t serverList_t; struct _serverList_t { IndicateListenerServer * server; @@ -86,6 +91,10 @@ serverList_sort (gconstpointer a, gconstpointer b) return g_strcmp0(pan, pbn); } +/* + * Item List + */ + typedef struct _imList_t imList_t; struct _imList_t { IndicateListenerServer * server; @@ -124,6 +133,10 @@ imList_sort (gconstpointer a, gconstpointer b) return (gint)(im_menu_item_get_seconds(IM_MENU_ITEM(pb->menuitem)) - im_menu_item_get_seconds(IM_MENU_ITEM(pa->menuitem))); } +/* + * Launcher List + */ + typedef struct _launcherList_t launcherList_t; struct _launcherList_t { LauncherMenuItem * menuitem; @@ -143,6 +156,10 @@ launcherList_sort (gconstpointer a, gconstpointer b) return g_strcmp0(pan, pbn); } +/* + * Black List + */ + static gboolean blacklist_check (const gchar * desktop_file) { @@ -150,6 +167,10 @@ blacklist_check (const gchar * desktop_file) return FALSE; } +/* + * More code + */ + static void server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) { -- cgit v1.2.3 From ee713f22dd253cf6e757f3ffb4ec839dad91bf31 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 14:26:56 -0500 Subject: More of a basis for the black list stuff. Some functions and an interface. --- src/messages-service.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index 9879e3a..1ff97ca 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -160,9 +160,41 @@ launcherList_sort (gconstpointer a, gconstpointer b) * Black List */ +static GHashTable * blacklist = NULL; + +/* Initialize the black list and start to setup + handlers for it. */ +static void +blacklist_init (gpointer data) +{ + + return; +} + +/* Add a definition file into the black list and eclipse + and launchers that have the same file. */ +static void +blacklist_add (const gchar * definition_file) +{ + + return; +} + +/* Remove a black list item based on the definition file + and uneclipse those launchers blocked by it. */ +static void +blacklist_remove (const gchar * definition_file) +{ + + return; +} + +/* Check to see if a particular desktop file is + in the blacklist. */ static gboolean blacklist_check (const gchar * desktop_file) { + if (blacklist == NULL) return FALSE; return FALSE; } -- cgit v1.2.3 From 528c37375ce30f80c2ca0376d62fd41a3629b66e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 14:59:45 -0500 Subject: Fleshing out the add function. Just a little. --- src/messages-service.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/messages-service.c b/src/messages-service.c index 1ff97ca..e4290f4 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -167,6 +167,8 @@ static GHashTable * blacklist = NULL; static void blacklist_init (gpointer data) { + blacklist = g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, g_free); return; } @@ -174,8 +176,46 @@ blacklist_init (gpointer data) /* Add a definition file into the black list and eclipse and launchers that have the same file. */ static void -blacklist_add (const gchar * definition_file) +blacklist_add (gchar * definition_file) { + /* Dump the file */ + gchar * desktop; + g_file_get_contents(definition_file, &desktop, NULL, NULL); + if (desktop == NULL) { + g_warning("Couldn't get data out of: %s", definition_file); + return; + } + + /* Clean up the data */ + gchar * trimdesktop = pango_trim_string(desktop); + g_free(desktop); + + /* Check for conflicts */ + gpointer data = g_hash_table_lookup(blacklist, trimdesktop); + if (data != NULL) { + gchar * oldfile = (gchar *)data; + if (!g_strcmp0(oldfile, definition_file)) { + g_warning("Already added file '%s'", oldfile); + } else { + g_warning("Already have desktop file '%s' in blacklist file '%s' not adding from '%s'", trimdesktop, oldfile, definition_file); + } + + g_free(trimdesktop); + return; + } + + /* Actually blacklist this thing */ + g_hash_table_insert(blacklist, trimdesktop, definition_file); + g_debug("Adding Blacklist item '%s' for desktop '%s'", definition_file, trimdesktop); + + /* Go through and eclipse folks */ + GList * launcher; + for (launcher = launcherList; launcher != NULL; launcher = launcher->next) { + launcherList_t * item = (launcherList_t *)launcher->data; + if (!g_strcmp0(trimdesktop, launcher_menu_item_get_desktop(item->menuitem))) { + launcher_menu_item_set_eclipsed(item->menuitem, TRUE); + } + } return; } -- cgit v1.2.3 From cc75cbe10d562c29657f61deda56115362df6179 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 15:00:25 -0500 Subject: We're taking ownership of that variable as well --- src/messages-service.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/messages-service.c b/src/messages-service.c index e4290f4..61a4b1a 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -201,6 +201,7 @@ blacklist_add (gchar * definition_file) } g_free(trimdesktop); + g_free(definition_file); return; } -- cgit v1.2.3 From 333467a2e1736c372108c954a191e6206cb18849 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 15:05:38 -0500 Subject: Writing the fairly extensive and complex check function. But, if that's the way it needs to be, I guess it needs to be that way. --- src/messages-service.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index 61a4b1a..e238b78 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -237,6 +237,10 @@ blacklist_check (const gchar * desktop_file) { if (blacklist == NULL) return FALSE; + if (g_hash_table_lookup(blacklist, desktop_file)) { + return TRUE; + } + return FALSE; } -- cgit v1.2.3 From e5d4b846037b0397022f12b5355d6889e5b9adec Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 15:51:01 -0500 Subject: Now parsing the directory on start up. Getting this whole thing started up. --- src/messages-service.c | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/src/messages-service.c b/src/messages-service.c index e238b78..f2768cb 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -50,6 +50,9 @@ static void check_eclipses (AppMenuItem * ai); static void remove_eclipses (AppMenuItem * ai); static gboolean build_launcher (gpointer data); static gboolean build_launchers (gpointer data); +static gboolean blacklist_init (gpointer data); +static gboolean blacklist_add (gpointer data); +static void blacklist_remove (const gchar * definition_file); /* @@ -164,26 +167,53 @@ static GHashTable * blacklist = NULL; /* Initialize the black list and start to setup handlers for it. */ -static void +static gboolean blacklist_init (gpointer data) { blacklist = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); - return; + gchar * blacklistdir = g_build_filename(g_get_user_config_dir(), USER_BLACKLIST_DIR, NULL); + g_debug("Looking at blacklist: %s", blacklistdir); + if (!g_file_test(blacklistdir, G_FILE_TEST_IS_DIR)) { + g_free(blacklistdir); + return FALSE; + } + + GError * error = NULL; + GDir * dir = g_dir_open(blacklistdir, 0, &error); + if (dir == NULL) { + g_warning("Unable to open blacklist directory (%s): %s", blacklistdir, error->message); + g_error_free(error); + g_free(blacklistdir); + return FALSE; + } + + const gchar * filename = NULL; + while ((filename = g_dir_read_name(dir)) != NULL) { + g_debug("Found file: %s", filename); + gchar * path = g_build_filename(blacklistdir, filename, NULL); + g_idle_add(blacklist_add, path); + } + + g_dir_close(dir); + g_free(blacklistdir); + + return FALSE; } /* Add a definition file into the black list and eclipse and launchers that have the same file. */ -static void -blacklist_add (gchar * definition_file) +static gboolean +blacklist_add (gpointer udata) { + gchar * definition_file = (gchar *)udata; /* Dump the file */ gchar * desktop; g_file_get_contents(definition_file, &desktop, NULL, NULL); if (desktop == NULL) { g_warning("Couldn't get data out of: %s", definition_file); - return; + return FALSE; } /* Clean up the data */ @@ -202,7 +232,7 @@ blacklist_add (gchar * definition_file) g_free(trimdesktop); g_free(definition_file); - return; + return FALSE; } /* Actually blacklist this thing */ @@ -218,7 +248,8 @@ blacklist_add (gchar * definition_file) } } - return; + blacklist_remove(NULL); + return FALSE; } /* Remove a black list item based on the definition file @@ -781,6 +812,7 @@ main (int argc, char ** argv) 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(blacklist_init, NULL); g_idle_add(build_launchers, NULL); mainloop = g_main_loop_new(NULL, FALSE); -- cgit v1.2.3 From f41d2527cb53f8a5ca091e860b6fd5f25f6ce87a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 16:00:12 -0500 Subject: Some debug and fixing checking the desktop file. All good. --- src/messages-service.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/messages-service.c b/src/messages-service.c index f2768cb..a4e8870 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -266,9 +266,11 @@ blacklist_remove (const gchar * definition_file) static gboolean blacklist_check (const gchar * desktop_file) { + g_debug("Checking blacklist for: %s", desktop_file); if (blacklist == NULL) return FALSE; if (g_hash_table_lookup(blacklist, desktop_file)) { + g_debug("\tFound!"); return TRUE; } @@ -740,7 +742,7 @@ build_launcher (gpointer data) dbusmenu_menuitem_child_append(root_menuitem, DBUSMENU_MENUITEM(ll->menuitem)); resort_menu(root_menuitem); - if (blacklist_check(trimdesktop)) { + if (blacklist_check(launcher_menu_item_get_desktop(ll->menuitem))) { launcher_menu_item_set_eclipsed(ll->menuitem, TRUE); } -- cgit v1.2.3 From 33f40e13838d18687507145c98c1cae48c0bc033 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 20:48:52 -0500 Subject: Switching the build to take the directory as a parameter --- src/messages-service.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/messages-service.c b/src/messages-service.c index a4e8870..0e4c296 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -756,12 +756,14 @@ build_launcher (gpointer data) static gboolean build_launchers (gpointer data) { - if (!g_file_test(SYSTEM_APPS_DIR, G_FILE_TEST_IS_DIR)) { + gchar * directory = (gchar *)data; + + if (!g_file_test(directory, G_FILE_TEST_IS_DIR)) { return FALSE; } GError * error = NULL; - GDir * dir = g_dir_open(SYSTEM_APPS_DIR, 0, &error); + GDir * dir = g_dir_open(directory, 0, &error); if (dir == NULL) { g_warning("Unable to open system apps directory: %s", error->message); g_error_free(error); @@ -771,7 +773,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); + gchar * path = g_build_filename(directory, filename, NULL); g_idle_add(build_launcher, path); } @@ -815,7 +817,7 @@ main (int argc, char ** argv) g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_REMOVED, G_CALLBACK(server_removed), root_menuitem); g_idle_add(blacklist_init, NULL); - g_idle_add(build_launchers, NULL); + g_idle_add(build_launchers, SYSTEM_APPS_DIR); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); -- cgit v1.2.3 From ce045e0d41054c2ccf8c9e524a4997ea2ee38601 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Aug 2009 20:52:12 -0500 Subject: Adding the user APPS directory to the places where we can find applications --- src/messages-service.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index 0e4c296..8b9b5cb 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -818,9 +818,13 @@ main (int argc, char ** argv) g_idle_add(blacklist_init, NULL); g_idle_add(build_launchers, SYSTEM_APPS_DIR); + gchar * userdir = g_build_filename(g_get_user_config_dir(), USER_APPS_DIR, NULL); + g_idle_add(build_launchers, userdir); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); + g_free(userdir); + return 0; } -- cgit v1.2.3