diff -uNr -x .pc gnome-power-manager-2.31.90.orig/configure.ac gnome-power-manager-2.31.90/configure.ac --- gnome-power-manager-2.31.90.orig/configure.ac 2010-08-24 09:56:25.245912000 +0100 +++ gnome-power-manager-2.31.90/configure.ac 2010-08-24 09:56:54.420492001 +0100 @@ -122,6 +122,7 @@ XRANDR_REQUIRED=1.2.0 CANBERRA_REQUIRED=0.10 UPOWER_REQUIRED=0.9.1 +APPINDICATOR_REQUIRED=0.0.10 dnl --------------------------------------------------------------------------- dnl - Check library dependencies @@ -162,6 +163,27 @@ PKG_CHECK_MODULES(UPOWER, upower-glib >= $UPOWER_REQUIRED) +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_DEFINE(HAVE_APP_INDICATOR, 1, [Have AppIndicator]) + PKG_CHECK_MODULES(APP_INDICATOR, [appindicator-0.1 >= $APPINDICATOR_REQUIRED])], + [AC_MSG_ERROR([appindicator-0.1 is not installed])]) +fi +AM_CONDITIONAL(HAVE_APP_INDICATOR, [test x$enable_appindicator = xyes]) +AC_SUBST(APP_INDICATOR_CFLAGS) +AC_SUBST(APP_INDICATOR_LIBS) + AC_PATH_PROG(GCONFTOOL, gconftool-2) AM_GCONF_SOURCE_2 @@ -362,6 +384,7 @@ Self test support: ${have_tests} GConf default support: ${have_gconfdefaults} Docbook support: ${enable_docbook_docs} + App indicator support: ${enable_appindicator} documentation dir: $DOCDIR dbus-1 services dir: $DBUS_SERVICES_DIR gconf-schema dir: $GCONF_SCHEMA_FILE_DIR diff -uNr -x .pc gnome-power-manager-2.31.90.orig/src/gpm-common.c gnome-power-manager-2.31.90/src/gpm-common.c --- gnome-power-manager-2.31.90.orig/src/gpm-common.c 2010-08-17 15:30:31.000000000 +0100 +++ gnome-power-manager-2.31.90/src/gpm-common.c 2010-08-25 15:09:23.921183080 +0100 @@ -55,15 +55,22 @@ } if (minutes < 60) { +#ifdef HAVE_APP_INDICATOR + timestring = g_strdup_printf ("00:%02d", minutes); +#else timestring = g_strdup_printf (ngettext ("%i minute", "%i minutes", minutes), minutes); +#endif return timestring; } hours = minutes / 60; minutes = minutes % 60; +#ifdef HAVE_APP_INDICATOR + timestring = g_strdup_printf ("%02d:%02d", hours, minutes); +#else if (minutes == 0) timestring = g_strdup_printf (ngettext ( "%i hour", @@ -75,6 +82,7 @@ timestring = g_strdup_printf (_("%i %s %i %s"), hours, ngettext ("hour", "hours", hours), minutes, ngettext ("minute", "minutes", minutes)); +#endif return timestring; } diff -uNr -x .pc gnome-power-manager-2.31.90.orig/src/gpm-manager.c gnome-power-manager-2.31.90/src/gpm-manager.c --- gnome-power-manager-2.31.90.orig/src/gpm-manager.c 2010-08-24 09:56:25.225902000 +0100 +++ gnome-power-manager-2.31.90/src/gpm-manager.c 2010-08-24 09:56:54.420492001 +0100 @@ -2086,7 +2086,8 @@ g_object_unref (manager->priv->backlight); g_object_unref (manager->priv->console); g_object_unref (manager->priv->client); - g_object_unref (manager->priv->status_icon); + if (manager->priv->status_icon) + g_object_unref (manager->priv->status_icon); G_OBJECT_CLASS (gpm_manager_parent_class)->finalize (object); } diff -uNr -x .pc gnome-power-manager-2.31.90.orig/src/gpm-tray-icon.c gnome-power-manager-2.31.90/src/gpm-tray-icon.c --- gnome-power-manager-2.31.90.orig/src/gpm-tray-icon.c 2010-08-24 09:56:25.185882000 +0100 +++ gnome-power-manager-2.31.90/src/gpm-tray-icon.c 2010-08-24 09:56:54.420492001 +0100 @@ -41,6 +41,10 @@ #include #include +#ifdef HAVE_APP_INDICATOR +#include +#endif + #include "egg-debug.h" #include "gpm-upower.h" @@ -57,7 +61,11 @@ { GConfClient *conf; GpmEngine *engine; +#ifdef HAVE_APP_INDICATOR + AppIndicator *app_indicator; +#else GtkStatusIcon *status_icon; +#endif gboolean show_actions; }; @@ -81,7 +89,16 @@ gpm_tray_icon_show (GpmTrayIcon *icon, gboolean enabled) { g_return_if_fail (GPM_IS_TRAY_ICON (icon)); +#ifdef HAVE_APP_INDICATOR + if (enabled) + app_indicator_set_status (icon->priv->app_indicator, + APP_INDICATOR_STATUS_ACTIVE); + else + app_indicator_set_status (icon->priv->app_indicator, + APP_INDICATOR_STATUS_PASSIVE); +#else gtk_status_icon_set_visible (icon->priv->status_icon, enabled); +#endif } /** @@ -95,11 +112,13 @@ g_return_val_if_fail (GPM_IS_TRAY_ICON (icon), FALSE); g_return_val_if_fail (tooltip != NULL, FALSE); +#ifndef HAVE_APP_INDICATOR #if GTK_CHECK_VERSION(2,15,0) gtk_status_icon_set_tooltip_text (icon->priv->status_icon, tooltip); #else gtk_status_icon_set_tooltip (icon->priv->status_icon, tooltip); #endif +#endif return TRUE; } @@ -110,7 +129,11 @@ gpm_tray_icon_get_status_icon (GpmTrayIcon *icon) { g_return_val_if_fail (GPM_IS_TRAY_ICON (icon), NULL); +#ifdef HAVE_APP_INDICATOR + return NULL; +#else return g_object_ref (icon->priv->status_icon); +#endif } /** @@ -127,7 +150,11 @@ if (filename != NULL) { egg_debug ("Setting icon to %s", filename); +#ifdef HAVE_APP_INDICATOR + app_indicator_set_icon (icon->priv->app_indicator, filename); +#else gtk_status_icon_set_from_icon_name (icon->priv->status_icon, filename); +#endif /* make sure that we are visible */ gpm_tray_icon_show (icon, TRUE); @@ -208,7 +235,9 @@ gchar *icon_name; gchar *label; GtkWidget *item; +#ifndef HAVE_APP_INDICATOR GtkWidget *image; +#endif const gchar *object_path; const gchar *desc; UpDevice *device; @@ -233,6 +262,11 @@ added++; /* generate the label */ +#ifdef HAVE_APP_INDICATOR + desc = gpm_upower_get_device_summary (device); + item = gtk_menu_item_new_with_label (desc); + label = NULL; +#else desc = gpm_device_kind_to_localised_text (kind, 1); label = g_strdup_printf ("%s (%.1f%%)", desc, percentage); item = gtk_image_menu_item_new_with_label (label); @@ -242,6 +276,7 @@ image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE); +#endif /* callback and add the the menu */ g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (gpm_tray_icon_show_info_cb), icon); @@ -264,7 +299,9 @@ { GtkMenu *menu = (GtkMenu*) gtk_menu_new (); GtkWidget *item; +#ifndef HAVE_APP_INDICATOR GtkWidget *image; +#endif guint dev_cnt = 0; GPtrArray *array; @@ -294,9 +331,13 @@ } /* preferences */ +#ifdef HAVE_APP_INDICATOR + item = gtk_menu_item_new_with_mnemonic (_("_Preferences")); +#else item = gtk_image_menu_item_new_with_mnemonic (_("_Preferences")); image = gtk_image_new_from_icon_name (GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); +#endif g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (gpm_tray_icon_show_preferences_cb), icon); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); @@ -304,14 +345,30 @@ skip_prefs: /* show the menu */ gtk_widget_show_all (GTK_WIDGET (menu)); +#ifdef HAVE_APP_INDICATOR + app_indicator_set_menu (icon->priv->app_indicator, menu); +#else gtk_menu_popup (GTK_MENU (menu), NULL, NULL, gtk_status_icon_position_menu, icon->priv->status_icon, 1, timestamp); +#endif g_signal_connect (GTK_WIDGET (menu), "hide", G_CALLBACK (gpm_tray_icon_popup_cleared_cd), icon); } +#ifdef HAVE_APP_INDICATOR +/** + * gpm_tray_icon_devices_changed_cb: + * + * Callback when devices are changed and menu has to be recreated + **/ +static void +gpm_tray_icon_devices_changed_cb (GpmEngine *engine, GpmTrayIcon *icon) +{ + gpm_tray_icon_create_menu (icon, gtk_get_current_event_time()); +} +#else /** * gpm_tray_icon_popup_menu_cb: * @@ -337,6 +394,7 @@ egg_debug ("icon left clicked"); gpm_tray_icon_create_menu (icon, gtk_get_current_event_time()); } +#endif /** * gpm_conf_gconf_key_changed_cb: @@ -381,6 +439,17 @@ (GConfClientNotifyFunc) gpm_conf_gconf_key_changed_cb, icon, NULL, NULL); +#ifdef HAVE_APP_INDICATOR + icon->priv->app_indicator = app_indicator_new_with_path ("gnome-power-manager", + "gnome-power-manager", + APP_INDICATOR_CATEGORY_HARDWARE, + GPM_DATA G_DIR_SEPARATOR_S "icons"); + + gpm_tray_icon_create_menu (icon, gtk_get_current_event_time()); + g_signal_connect_object (G_OBJECT (icon->priv->engine), "devices-changed", + G_CALLBACK (gpm_tray_icon_devices_changed_cb), + icon, 0); +#else icon->priv->status_icon = gtk_status_icon_new (); g_signal_connect_object (G_OBJECT (icon->priv->status_icon), "popup_menu", @@ -390,6 +459,7 @@ "activate", G_CALLBACK (gpm_tray_icon_activate_cb), icon, 0); +#endif allowed_in_menu = gconf_client_get_bool (icon->priv->conf, GPM_CONF_UI_SHOW_ACTIONS, NULL); gpm_tray_icon_enable_actions (icon, allowed_in_menu); @@ -409,7 +479,11 @@ tray_icon = GPM_TRAY_ICON (object); +#ifdef HAVE_APP_INDICATOR + g_object_unref (tray_icon->priv->app_indicator); +#else g_object_unref (tray_icon->priv->status_icon); +#endif g_object_unref (tray_icon->priv->engine); g_return_if_fail (tray_icon->priv != NULL); diff -uNr -x .pc gnome-power-manager-2.31.90.orig/src/gpm-upower.c gnome-power-manager-2.31.90/src/gpm-upower.c --- gnome-power-manager-2.31.90.orig/src/gpm-upower.c 2010-08-17 15:30:31.000000000 +0100 +++ gnome-power-manager-2.31.90/src/gpm-upower.c 2010-08-25 14:54:19.291183081 +0100 @@ -229,7 +229,10 @@ /* we always display "Laptop battery 16 minutes remaining" as we need to clarify what device we are refering to */ if (state == UP_DEVICE_STATE_FULLY_CHARGED) { - +#ifdef HAVE_APP_INDICATOR + /* TRANSLATORS: the device is fully charged */ + description = g_strdup_printf (_("%s is charged"), kind_desc); +#else if (kind == UP_DEVICE_KIND_BATTERY && time_to_empty_round > GPM_UP_TEXT_MIN_TIME) { time_to_empty_str = gpm_get_timestring (time_to_empty_round); /* TRANSLATORS: The laptop battery is fully charged, and we know a time */ @@ -240,9 +243,22 @@ /* TRANSLATORS: the device is fully charged */ description = g_strdup_printf (_("%s is fully charged"), kind_desc); } - +#endif } else if (state == UP_DEVICE_STATE_DISCHARGING) { - +#ifdef HAVE_APP_INDICATOR + if (time_to_empty_round <= GPM_UP_TEXT_MIN_TIME) { + /* TRANSLATORS: the device is discharging and we don't have a time remaining yet */ + description = g_strdup_printf (_("%s (estimating...)"), kind_desc); + } else if (time_to_empty_round <= 12*60*60) { + time_to_empty_str = gpm_get_timestring (time_to_empty_round); + /* TRANSLATORS: the device is discharging, and we have a time remaining */ + description = g_strdup_printf (_("%s %s left"), kind_desc, time_to_empty_str); + g_free (time_to_empty_str); + } else { /* larger than 12 hours remaining */ + /* TRANSLATORS: the device is discharging */ + description = g_strdup_printf (_("%s"), kind_desc); + } +#else if (time_to_empty_round > GPM_UP_TEXT_MIN_TIME) { time_to_empty_str = gpm_get_timestring (time_to_empty_round); /* TRANSLATORS: the device is discharging, and we have a time remaining */ @@ -254,9 +270,20 @@ description = g_strdup_printf (_("%s discharging (%.1f%%)"), kind_desc, percentage); } - +#endif } else if (state == UP_DEVICE_STATE_CHARGING) { - +#ifdef HAVE_APP_INDICATOR + if (time_to_full_round > GPM_UP_TEXT_MIN_TIME) { + time_to_full_str = gpm_get_timestring (time_to_full_round); + /* TRANSLATORS: the device is charging */ + description = g_strdup_printf (_("%s %s until charged"), kind_desc, time_to_full_str); + g_free (time_to_full_str); + } else { + /* TRANSLATORS: device is charging, but we only have a percentage */ + description = g_strdup_printf (_("%s (estimating...)"), + kind_desc, percentage); + } +#else if (time_to_full_round > GPM_UP_TEXT_MIN_TIME && time_to_empty_round > GPM_UP_TEXT_MIN_TIME) { @@ -285,18 +312,23 @@ description = g_strdup_printf (_("%s charging (%.1f%%)"), kind_desc, percentage); } - +#endif } else if (state == UP_DEVICE_STATE_PENDING_DISCHARGE) { - /* TRANSLATORS: this is only shown for laptops with multiple batteries */ +#ifdef HAVE_APP_INDICATOR + description = g_strdup_printf (_("%s waiting to discharge"), + kind_desc); +#else description = g_strdup_printf (_("%s waiting to discharge (%.1f%%)"), kind_desc, percentage); - +#endif } else if (state == UP_DEVICE_STATE_PENDING_CHARGE) { - /* TRANSLATORS: this is only shown for laptops with multiple batteries */ +#ifdef HAVE_APP_INDICATOR + description = g_strdup_printf (_("%s waiting to charge"), kind_desc); +#else description = g_strdup_printf (_("%s waiting to charge (%.1f%%)"), kind_desc, percentage); - +#endif } else { egg_warning ("in an undefined state we are not charging or " "discharging and the batteries are also not charged"); diff -uNr -x .pc gnome-power-manager-2.31.90.orig/src/Makefile.am gnome-power-manager-2.31.90/src/Makefile.am --- gnome-power-manager-2.31.90.orig/src/Makefile.am 2010-08-24 09:56:25.205892000 +0100 +++ gnome-power-manager-2.31.90/src/Makefile.am 2010-08-24 09:56:54.420492001 +0100 @@ -20,6 +20,7 @@ $(GSTREAMER_CFLAGS) \ -DI_KNOW_THE_DEVICEKIT_POWER_API_IS_SUBJECT_TO_CHANGE \ $(UPOWER_CFLAGS) \ + $(APP_INDICATOR_CFLAGS) \ -DBINDIR=\"$(bindir)\" \ -DSBINDIR=\"$(sbindir)\" \ -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ @@ -186,6 +187,7 @@ $(X11_LIBS) \ $(GSTREAMER_LIBS) \ $(GNOME_LIBS) \ + $(APP_INDICATOR_LIBS) \ $(DBUS_LIBS) \ $(X11_LIBS) \ $(CANBERRA_LIBS) \