diff options
Diffstat (limited to 'src/messages-service.c')
-rw-r--r-- | src/messages-service.c | 82 |
1 files changed, 70 insertions, 12 deletions
diff --git a/src/messages-service.c b/src/messages-service.c index e3352e8..e8fe576 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -28,10 +28,10 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include <libindicate/listener.h> #include <libindicator/indicator-service.h> #include <gio/gio.h> +#include <glib/gi18n.h> #include <libdbusmenu-glib/client.h> #include <libdbusmenu-glib/server.h> -#include <libdbusmenu-glib/menuitem-proxy.h> #include "im-menu-item.h" #include "app-menu-item.h" @@ -40,6 +40,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include "dirs.h" #include "messages-service-dbus.h" #include "seen-db.h" +#include "status-items.h" static IndicatorService * service = NULL; static IndicateListener * listener = NULL; @@ -47,6 +48,8 @@ static GList * serverList = NULL; static GList * launcherList = NULL; static DbusmenuMenuitem * root_menuitem = NULL; +static DbusmenuMenuitem * status_separator = NULL; +static DbusmenuMenuitem * clear_attention = NULL; static GMainLoop * mainloop = NULL; static MessageServiceDbus * dbus_interface = NULL; @@ -797,6 +800,8 @@ menushell_foreach_cb (DbusmenuMenuitem * data_mi, gpointer data_ms) { 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 a position at the end of our shortcuts */ + msl->position += g_list_length(app_menu_item_get_items(appmenu)); } else { msl->position++; } @@ -833,9 +838,13 @@ resort_menu (DbusmenuMenuitem * menushell) guint position = 0; GList * serverentry; GList * launcherentry = launcherList; - DbusmenuMenuitem * last_separator = NULL; g_debug("Reordering Menu:"); + + if (DBUSMENU_IS_MENUITEM(status_separator)) { + position = dbusmenu_menuitem_get_position(status_separator, root_menuitem) + 1; + g_debug("\tPriming with location of status separator: %d", position); + } for (serverentry = serverList; serverentry != NULL; serverentry = serverentry->next) { serverList_t * si = (serverList_t *)serverentry->data; @@ -865,7 +874,6 @@ resort_menu (DbusmenuMenuitem * menushell) if (!launcher_menu_item_get_eclipsed(li->menuitem)) { /* Only clear the visiblity if we're not eclipsed */ dbusmenu_menuitem_property_set_bool(li->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - last_separator = li->separator; } position++; @@ -921,7 +929,6 @@ resort_menu (DbusmenuMenuitem * menushell) /* Note, this isn't the last if we can't see it */ } else { dbusmenu_menuitem_property_set_bool(si->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - last_separator = si->separator; } dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(si->separator), position); @@ -953,17 +960,15 @@ resort_menu (DbusmenuMenuitem * menushell) if (!launcher_menu_item_get_eclipsed(li->menuitem)) { /* Only clear the visiblity if we're not eclipsed */ dbusmenu_menuitem_property_set_bool(li->separator, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - last_separator = li->separator; } position++; launcherentry = launcherentry->next; } - if (last_separator != NULL) { - dbusmenu_menuitem_property_set_bool(last_separator, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); - } else { - g_warning("No last separator on resort"); + if (clear_attention != NULL) { + dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), clear_attention, position); + position++; /* Not needed, but reduce bugs on code tacked on here, compiler will remove */ } return; @@ -1432,13 +1437,40 @@ service_shutdown (IndicatorService * service, gpointer user_data) return; } +/* Respond to changing status by updating the icon that + is on the panel */ +static void +status_update_callback (void) +{ + return; +} + +/* The clear attention item has been clicked on, what to do? */ +static void +clear_attention_activate (DbusmenuMenuitem * mi, guint timestamp, MessageServiceDbus * dbus) +{ + message_service_dbus_set_attention(dbus, FALSE); + return; +} + +/* Handle an update of the active state to ensure that we're + only enabled when we could do something. */ +static void +clear_attention_handler (MessageServiceDbus * msd, gboolean attention, DbusmenuMenuitem * clearitem) +{ + dbusmenu_menuitem_property_set_bool(clearitem, DBUSMENU_MENUITEM_PROP_ENABLED, attention); + return; +} + /* Oh, if you don't know what main() is for we really shouldn't be talking. */ int main (int argc, char ** argv) { + /* Glib init */ g_type_init(); + /* Create the Indicator Service interface */ service = indicator_service_new_version(INDICATOR_MESSAGES_DBUS_NAME, 1); g_signal_connect(service, INDICATOR_SERVICE_SIGNAL_SHUTDOWN, G_CALLBACK(service_shutdown), NULL); @@ -1448,31 +1480,57 @@ main (int argc, char ** argv) bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); textdomain (GETTEXT_PACKAGE); + /* Create the Seen DB */ seen_db_init(); + /* Bring up the service DBus interface */ dbus_interface = message_service_dbus_new(); - listener = indicate_listener_ref_default(); - serverList = NULL; - + /* Build the base menu */ root_menuitem = dbusmenu_menuitem_new(); DbusmenuServer * server = dbusmenu_server_new(INDICATOR_MESSAGES_DBUS_OBJECT); dbusmenu_server_set_root(server, root_menuitem); + /* Add status items */ + GList * statusitems = status_items_build(&status_update_callback); + while (statusitems != NULL) { + dbusmenu_menuitem_child_append(root_menuitem, DBUSMENU_MENUITEM(statusitems->data)); + statusitems = g_list_next(statusitems); + } + status_separator = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(status_separator, DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_append(root_menuitem, status_separator); + + /* Add in the clear attention item */ + clear_attention = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(clear_attention, DBUSMENU_MENUITEM_PROP_LABEL, _("Clear")); + dbusmenu_menuitem_child_append(root_menuitem, clear_attention); + g_signal_connect(G_OBJECT(dbus_interface), MESSAGE_SERVICE_DBUS_SIGNAL_ATTENTION_CHANGED, G_CALLBACK(clear_attention_handler), clear_attention); + g_signal_connect(G_OBJECT(clear_attention), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(clear_attention_activate), dbus_interface); + + /* Start up the libindicate listener */ + listener = indicate_listener_ref_default(); + serverList = NULL; + 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); + /* Find launchers by looking through the config directories + in the idle loop */ g_idle_add(blacklist_init, NULL); g_idle_add(build_launchers, SYSTEM_APPS_DIR); g_idle_add(build_launchers, SYSTEM_APPS_DIR_OLD); gchar * userdir = g_build_filename(g_get_user_config_dir(), USER_APPS_DIR, NULL); g_idle_add(build_launchers, userdir); + /* Let's run a mainloop */ mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); + /* Clean up */ + status_items_cleanup(); g_free(userdir); return 0; |