diff --git applet/Makefile.am applet/Makefile.am index 3511c2b..3b5eede 100644 --- applet/Makefile.am +++ applet/Makefile.am @@ -17,6 +17,13 @@ AM_CFLAGS = $(APPLET_CFLAGS) $(WARN_CFLAGS) $(DISABLE_DEPRECATED) -DPKGDATADIR=" INCLUDES = -I$(top_srcdir)/lib +if HAVE_APP_INDICATOR +bluetooth_applet_LDADD += $(APP_INDICATOR_LIBS) +test_agentdialog_LDADD += $(APP_INDICATOR_LIBS) +test_icon_LDADD += $(APP_INDICATOR_LIBS) +INCLUDES += -DHAVE_APP_INDICATOR $(APP_INDICATOR_CFLAGS) +endif + man_MANS = bluetooth-applet.1 ui_DATA = popup-menu.ui authorisation-dialogue.ui confirm-dialogue.ui passkey-dialogue.ui diff --git applet/main.c applet/main.c index 3261d03..5cadbb4 100644 --- applet/main.c +++ applet/main.c @@ -32,6 +32,9 @@ #include #include +#ifdef HAVE_APP_INDICATOR +#include +#endif /* HAVE_APP_INDICATOR */ #include #include #include @@ -362,6 +365,9 @@ static GtkWidget *create_popupmenu(void) { GObject *object; GError *error = NULL; +#ifdef HAVE_APP_INDICATOR + GtkWidget *menuitem = NULL; +#endif /* HAVE_APP_INDICATOR */ xml = gtk_builder_new (); if (gtk_builder_add_from_file (xml, "popup-menu.ui", &error) == 0) { @@ -404,6 +410,22 @@ static GtkWidget *create_popupmenu(void) GTK_ACTION (gtk_builder_get_object (xml, "devices-label")), "/bluetooth-applet-popup/devices-label"); +#ifdef HAVE_APP_INDICATOR + menuitem = gtk_ui_manager_get_widget (GTK_UI_MANAGER (object), + "/bluetooth-applet-popup/preferences"); + + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), GTK_WIDGET (gtk_image_new ())); + + menuitem = gtk_ui_manager_get_widget (GTK_UI_MANAGER (object), + "/bluetooth-applet-popup/send-file"); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), GTK_WIDGET (gtk_image_new ())); + + /* This is normally hidden, but just in case, we'll remove the icon. */ + menuitem = gtk_ui_manager_get_widget (GTK_UI_MANAGER (object), + "/bluetooth-applet-popup/quit"); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), GTK_WIDGET (gtk_image_new ())); +#endif /* HAVE_APP_INDICATOR */ + return GTK_WIDGET (gtk_builder_get_object (xml, "bluetooth-applet-popup")); } @@ -1030,7 +1052,11 @@ static GOptionEntry options[] = { int main(int argc, char *argv[]) { UniqueApp *app; +#ifdef HAVE_APP_INDICATOR + AppIndicator *indicator; +#else GtkStatusIcon *statusicon; +#endif /* HAVE_APP_INDICATOR */ GtkWidget *menu; GConfValue *value; GOptionContext *context; @@ -1107,14 +1133,21 @@ int main(int argc, char *argv[]) gconf_client_notify_add(gconf, PREF_DIR, gconf_callback, NULL, NULL, NULL); +#ifdef HAVE_APP_INDICATOR + indicator = init_notification(); + app_indicator_set_menu(indicator, GTK_MENU(menu)); +#else statusicon = init_notification(); +#endif /* HAVE_APP_INDICATOR */ update_icon_visibility(); +#ifndef HAVE_APP_INDICATOR g_signal_connect(statusicon, "activate", G_CALLBACK(activate_callback), menu); g_signal_connect(statusicon, "popup-menu", G_CALLBACK(popup_callback), menu); +#endif /* HAVE_APP_INDICATOR */ setup_agents(); diff --git applet/notify.c applet/notify.c index e884f62..c0c5573 100644 --- applet/notify.c +++ applet/notify.c @@ -29,9 +29,16 @@ #include #include #include +#ifdef HAVE_APP_INDICATOR +#include +#endif /* HAVE_APP_INDICATOR */ #include "notify.h" +#ifdef HAVE_APP_INDICATOR +static AppIndicator *indicator = NULL; +#else static GtkStatusIcon *statusicon = NULL; +#endif /* HAVE_APP_INDICATOR */ static char *icon_name = NULL; static char *tooltip = NULL; static NotifyNotification *notify = NULL; @@ -75,6 +82,7 @@ void show_notification(const gchar *summary, const gchar *message, notify_notification_set_timeout(notify, timeout); +#ifndef HAVE_APP_INDICATOR if (gtk_status_icon_get_visible(statusicon) == TRUE) { gtk_status_icon_get_geometry(statusicon, &screen, &area, NULL); @@ -83,6 +91,7 @@ void show_notification(const gchar *summary, const gchar *message, notify_notification_set_hint_int32(notify, "y", area.y + area.height / 2); } +#endif /* HAVE_APP_INDICATOR */ notify_notification_set_urgency(notify, NOTIFY_URGENCY_NORMAL); @@ -106,6 +115,18 @@ void close_notification(void) } } +#ifdef HAVE_APP_INDICATOR +AppIndicator *init_notification(void) +{ + notify_init("bluetooth-manager"); + + indicator = app_indicator_new("bluetooth-manager", + icon_name, + APP_INDICATOR_CATEGORY_APPLICATION_STATUS); + + return indicator; +} +#else GtkStatusIcon *init_notification(void) { notify_init("bluetooth-manager"); @@ -115,12 +136,17 @@ GtkStatusIcon *init_notification(void) return statusicon; } +#endif /* HAVE_APP_INDICATOR */ void cleanup_notification(void) { close_notification(); +#ifdef HAVE_APP_INDICATOR + g_object_unref(indicator); +#else g_object_unref(statusicon); +#endif /* HAVE_APP_INDICATOR */ g_free (icon_name); icon_name = NULL; @@ -132,14 +158,24 @@ void cleanup_notification(void) void show_icon(void) { +#ifdef HAVE_APP_INDICATOR + if (indicator != NULL) + app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE); +#else if (statusicon != NULL) gtk_status_icon_set_visible(statusicon, TRUE); +#endif /* HAVE_APP_INDICATOR */ } void hide_icon(void) { +#ifdef HAVE_APP_INDICATOR + if (indicator != NULL) + app_indicator_set_status(indicator, APP_INDICATOR_STATUS_PASSIVE); +#else if (statusicon != NULL) gtk_status_icon_set_visible(statusicon, FALSE); +#endif /* HAVE_APP_INDICATOR */ } void set_icon(gboolean enabled) @@ -147,17 +183,41 @@ void set_icon(gboolean enabled) const char *name = (enabled ? "bluetooth-active" : "bluetooth-disabled"); const char *_tooltip = enabled ? _("Bluetooth: Enabled") : _("Bluetooth: Disabled"); +#ifdef HAVE_APP_INDICATOR + if (indicator == NULL) { +#else if (statusicon == NULL) { +#endif /* HAVE_APP_INDICATOR */ g_free (icon_name); g_free (tooltip); icon_name = g_strdup (name); tooltip = g_strdup (_tooltip); } else { +#ifdef HAVE_APP_INDICATOR + app_indicator_set_icon(indicator, name); + /* NOTE: I chose not to use the tooltip info because that information is already displayed in the menu. */ +#else gtk_status_icon_set_from_icon_name (statusicon, name); gtk_status_icon_set_tooltip_markup(statusicon, _tooltip); +#endif /* HAVE_APP_INDICATOR */ + } +} + +#ifdef HAVE_APP_INDICATOR +/* We avoid blinking, unless it is needed, in app indicators */ +void enable_blinking(void) +{ } + +void disable_blinking(void) +{ } +gboolean query_blinking(void) +{ + return FALSE; +} +#else void enable_blinking(void) { gtk_status_icon_set_blinking(statusicon, TRUE); @@ -172,3 +232,4 @@ gboolean query_blinking(void) { return gtk_status_icon_get_blinking(statusicon); } +#endif /* HAVE_APP_INDICATOR */ diff --git applet/notify.h applet/notify.h index 9ee5cb8..7f3ff39 100644 --- applet/notify.h +++ applet/notify.h @@ -22,7 +22,13 @@ * */ +#ifdef HAVE_APP_INDICATOR +#include + +AppIndicator *init_notification(void); +#else GtkStatusIcon *init_notification(void); +#endif /* HAVE_APP_INDICATOR */ void cleanup_notification(void); gboolean notification_supports_actions(void); diff --git applet/test-agentdialog.c applet/test-agentdialog.c index d2506d5..92a1a4b 100644 --- applet/test-agentdialog.c +++ applet/test-agentdialog.c @@ -31,7 +31,11 @@ static void activate_callback(GObject *widget, gpointer user_data) int main(int argc, char *argv[]) { +#ifdef HAVE_APP_INDICATOR + AppIndicator *indicator; +#else GtkStatusIcon *statusicon; +#endif /* HAVE_APP_INDICATOR */ DBusGConnection *conn; DBusGProxy *adapter, *device; GError *error = NULL; @@ -53,10 +57,14 @@ int main(int argc, char *argv[]) } set_icon (TRUE); +#ifdef HAVE_APP_INDICATOR + indicator = init_notification(); +#else statusicon = init_notification(); g_signal_connect(statusicon, "activate", G_CALLBACK(activate_callback), NULL); +#endif /* HAVE_APP_INDICATOR */ setup_agents(); diff --git configure.ac configure.ac index a4d6e5e..cfd9690 100644 --- configure.ac +++ configure.ac @@ -90,6 +90,31 @@ PKG_CHECK_MODULES(APPLET, libnotify >= $NOTIFY_REQUIRED unique-1.0) +dnl Requires for application indicators +APPINDICATOR_REQUIRED=0.0.7 + +AC_ARG_ENABLE(appindicator, + AS_HELP_STRING([--enable-appindicator[=@<:@no/auto/yes@:>@]],[Build support for application indicators ]), + [enable_appindicator=$enableval], + [enable_appindicator="auto"]) + +if test x$enable_appindicator = xauto ; then + PKG_CHECK_EXISTS([appindicator-0.1 >= $APPINDICATOR_REQUIRED], + enable_appindicator="yes", + enable_appindicator="no") +fi + +if test x$enable_appindicator = xyes ; then + PKG_CHECK_EXISTS([appindicator-0.1 >= $APPINDICATOR_REQUIRED],, + AC_MSG_ERROR([appindicator-0.1 is not installed])) + PKG_CHECK_MODULES(APP_INDICATOR, + appindicator-0.1 >= $APPINDICATOR_REQUIRED) + AC_SUBST(APP_INDICATOR_CFLAGS) + AC_SUBST(APP_INDICATOR_LIBS) + AC_DEFINE(HAVE_APP_INDICATOR, 1, [Have AppIndicator]) +fi +AM_CONDITIONAL(HAVE_APP_INDICATOR, test x"$enable_appindicator" = xyes) + dnl Requires for the sendto app PKG_CHECK_MODULES(SENDTO, dbus-glib-1 >= $DBUS_GLIB_REQUIRED