summaryrefslogtreecommitdiff
path: root/src/gpm-tray-icon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpm-tray-icon.c')
-rw-r--r--src/gpm-tray-icon.c169
1 files changed, 121 insertions, 48 deletions
diff --git a/src/gpm-tray-icon.c b/src/gpm-tray-icon.c
index fa7f5da..3bcd09b 100644
--- a/src/gpm-tray-icon.c
+++ b/src/gpm-tray-icon.c
@@ -39,14 +39,13 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <libupower-glib/upower.h>
-#include <libmate-desktop/mate-aboutdialog.h>
#include "egg-debug.h"
#include "gpm-upower.h"
#include "gpm-engine.h"
#include "gpm-common.h"
-#include "gpm-stock-icons.h"
+#include "gpm-icon-names.h"
#include "gpm-tray-icon.h"
static void gpm_tray_icon_finalize (GObject *object);
@@ -111,20 +110,21 @@ gpm_tray_icon_get_status_icon (GpmTrayIcon *icon)
}
/**
- * gpm_tray_icon_set_image_from_stock:
- * @filename: The icon name, e.g. GPM_STOCK_APP_ICON, or NULL to remove.
+ * gpm_tray_icon_set_icon:
+ * @icon_name: The icon name, e.g. GPM_ICON_APP_ICON, or NULL to remove.
*
- * Loads a pixmap from disk, and sets as the tooltip icon
+ * Loads a pixmap from disk, and sets as the tooltip icon.
**/
gboolean
-gpm_tray_icon_set_icon (GpmTrayIcon *icon, const gchar *filename)
+gpm_tray_icon_set_icon (GpmTrayIcon *icon, const gchar *icon_name)
{
g_return_val_if_fail (icon != NULL, FALSE);
g_return_val_if_fail (GPM_IS_TRAY_ICON (icon), FALSE);
- if (filename != NULL) {
- egg_debug ("Setting icon to %s", filename);
- gtk_status_icon_set_from_icon_name (icon->priv->status_icon, filename);
+ if (icon_name != NULL) {
+ egg_debug ("Setting icon to %s", icon_name);
+ gtk_status_icon_set_from_icon_name (icon->priv->status_icon,
+ icon_name);
/* make sure that we are visible */
gpm_tray_icon_show (icon, TRUE);
@@ -182,35 +182,20 @@ gpm_tray_icon_show_about_cb (GtkMenuItem *item, gpointer data)
NULL
};
- mate_show_about_dialog (NULL,
- "program-name", _("Power Manager"),
- "version", VERSION,
- "comments", _("Power management daemon"),
- "copyright", _("Copyright \xC2\xA9 2011-2014 MATE developers"),
- "authors", authors,
- /* Translators should localize the following string
- * which will be displayed at the bottom of the about
- * box to give credit to the translator(s).
- */
- "translator-credits", _("translator-credits"),
- "logo-icon-name", "mate-power-manager",
- "website", "http://www.mate-desktop.org",
- NULL);
-}
-
-/**
- * gpm_tray_icon_popup_cleared_cd:
- * @widget: The popup Gtkwidget
- *
- * We have to re-enable the tooltip when the popup is removed
- **/
-static void
-gpm_tray_icon_popup_cleared_cd (GtkWidget *widget, GpmTrayIcon *icon)
-{
- g_return_if_fail (GPM_IS_TRAY_ICON (icon));
- egg_debug ("clear tray");
- g_object_ref_sink (widget);
- g_object_unref (widget);
+ gtk_show_about_dialog (NULL,
+ "program-name", _("Power Manager"),
+ "version", VERSION,
+ "comments", _("Power management daemon"),
+ "copyright", _("Copyright \xC2\xA9 2011-2016 MATE developers"),
+ "authors", authors,
+ /* Translators should localize the following string
+ * which will be displayed at the bottom of the about
+ * box to give credit to the translator(s).
+ */
+ "translator-credits", _("translator-credits"),
+ "logo-icon-name", "mate-power-manager",
+ "website", "http://www.mate-desktop.org",
+ NULL);
}
/**
@@ -234,11 +219,10 @@ gpm_tray_icon_add_device (GpmTrayIcon *icon, GtkMenu *menu, const GPtrArray *arr
guint i;
guint added = 0;
gchar *icon_name;
- gchar *label;
+ gchar *label, *vendor, *model;
GtkWidget *item;
GtkWidget *image;
const gchar *object_path;
- const gchar *desc;
UpDevice *device;
UpDeviceKind kind_tmp;
gdouble percentage;
@@ -251,6 +235,8 @@ gpm_tray_icon_add_device (GpmTrayIcon *icon, GtkMenu *menu, const GPtrArray *arr
g_object_get (device,
"kind", &kind_tmp,
"percentage", &percentage,
+ "vendor", &vendor,
+ "model", &model,
NULL);
if (kind != kind_tmp)
@@ -261,8 +247,12 @@ gpm_tray_icon_add_device (GpmTrayIcon *icon, GtkMenu *menu, const GPtrArray *arr
added++;
/* generate the label */
- desc = gpm_device_kind_to_localised_text (kind, 1);
- label = g_strdup_printf ("%s (%.1f%%)", desc, percentage);
+ if ((vendor != NULL && strlen(vendor) != 0) && (model != NULL && strlen(model) != 0)) {
+ label = g_strdup_printf ("%s %s (%.1f%%)", vendor, model, percentage);
+ }
+ else {
+ label = g_strdup_printf ("%s (%.1f%%)", gpm_device_kind_to_localised_string (kind, 1), percentage);
+ }
item = gtk_image_menu_item_new_with_label (label);
/* generate the image */
@@ -278,23 +268,61 @@ gpm_tray_icon_add_device (GpmTrayIcon *icon, GtkMenu *menu, const GPtrArray *arr
g_free (icon_name);
g_free (label);
+ g_free (vendor);
+ g_free (model);
}
return added;
}
/**
+ * gpm_tray_icon_add_primary_device:
+ **/
+static void
+gpm_tray_icon_add_primary_device (GpmTrayIcon *icon, GtkMenu *menu, UpDevice *device)
+{
+ GtkWidget *item;
+ gchar *time_str;
+ gchar *string;
+ gint64 time_to_empty = 0;
+
+ /* get details */
+ g_object_get (device,
+ "time-to-empty", &time_to_empty,
+ NULL);
+
+ /* convert time to string */
+ time_str = gpm_get_timestring (time_to_empty);
+
+ /* TRANSLATORS: % is a timestring, e.g. "6 hours 10 minutes" */
+ string = g_strdup_printf (_("%s remaining"), time_str);
+ item = gtk_image_menu_item_new_with_label (string);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ g_free (time_str);
+ g_free (string);
+}
+
+/**
* gpm_tray_icon_create_menu:
*
- * Display the popup menu.
+ * Create the popup menu.
**/
-static void
-gpm_tray_icon_create_menu (GpmTrayIcon *icon, guint32 timestamp)
+static GtkMenu *
+gpm_tray_icon_create_menu (GpmTrayIcon *icon)
{
GtkMenu *menu = (GtkMenu*) gtk_menu_new ();
GtkWidget *item;
GtkWidget *image;
guint dev_cnt = 0;
GPtrArray *array;
+ UpDevice *device = NULL;
+
+ /* show the primary device time remaining */
+ device = gpm_engine_get_primary_device (icon->priv->engine);
+ if (device != NULL) {
+ gpm_tray_icon_add_primary_device (icon, menu, device);
+ item = gtk_separator_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ }
/* add all device types to the drop down menu */
array = gpm_engine_get_devices (icon->priv->engine);
@@ -321,11 +349,23 @@ gpm_tray_icon_create_menu (GpmTrayIcon *icon, guint32 timestamp)
/* preferences */
item = gtk_image_menu_item_new_with_mnemonic (_("_Preferences"));
- image = gtk_image_new_from_icon_name (GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_MENU);
+ image = gtk_image_new_from_icon_name ("preferences-system", GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
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);
+
+ /*Set up custom panel menu theme support-gtk3 only */
+ GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menu));
+ /* Fix any failures of compiz/other wm's to communicate with gtk for transparency in menu theme */
+ GdkScreen *screen = gtk_widget_get_screen(GTK_WIDGET(toplevel));
+ GdkVisual *visual = gdk_screen_get_rgba_visual(screen);
+ gtk_widget_set_visual(GTK_WIDGET(toplevel), visual);
+ /* Set menu and it's toplevel window to follow panel theme */
+ GtkStyleContext *context;
+ context = gtk_widget_get_style_context (GTK_WIDGET(toplevel));
+ gtk_style_context_add_class(context,"gnome-panel-menu-bar");
+ gtk_style_context_add_class(context,"mate-panel-menu-bar");
/* about */
item = gtk_image_menu_item_new_from_stock (GTK_STOCK_ABOUT, NULL);
@@ -334,6 +374,38 @@ gpm_tray_icon_create_menu (GpmTrayIcon *icon, guint32 timestamp)
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
skip_prefs:
+ if (device != NULL)
+ g_object_unref (device);
+ return menu;
+}
+
+/**
+ * gpm_tray_icon_popup_cleared_cd:
+ * @widget: The popup Gtkwidget
+ *
+ * We have to re-enable the tooltip when the popup is removed
+ **/
+static void
+gpm_tray_icon_popup_cleared_cd (GtkWidget *widget, GpmTrayIcon *icon)
+{
+ g_return_if_fail (GPM_IS_TRAY_ICON (icon));
+ egg_debug ("clear tray");
+ g_object_ref_sink (widget);
+ g_object_unref (widget);
+}
+
+/**
+ * gpm_tray_icon_popup_menu:
+ *
+ * Display the popup menu.
+ **/
+static void
+gpm_tray_icon_popup_menu (GpmTrayIcon *icon, guint32 timestamp)
+{
+ GtkMenu *menu;
+
+ menu = gpm_tray_icon_create_menu (icon);
+
/* show the menu */
gtk_widget_show_all (GTK_WIDGET (menu));
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
@@ -353,7 +425,7 @@ static void
gpm_tray_icon_popup_menu_cb (GtkStatusIcon *status_icon, guint button, guint32 timestamp, GpmTrayIcon *icon)
{
egg_debug ("icon right clicked");
- gpm_tray_icon_create_menu (icon, timestamp);
+ gpm_tray_icon_popup_menu (icon, timestamp);
}
@@ -367,7 +439,7 @@ static void
gpm_tray_icon_activate_cb (GtkStatusIcon *status_icon, GpmTrayIcon *icon)
{
egg_debug ("icon left clicked");
- gpm_tray_icon_create_menu (icon, gtk_get_current_event_time());
+ gpm_tray_icon_popup_menu (icon, gtk_get_current_event_time());
}
/**
@@ -405,6 +477,7 @@ gpm_tray_icon_init (GpmTrayIcon *icon)
G_CALLBACK (gpm_tray_icon_settings_changed_cb), icon);
icon->priv->status_icon = gtk_status_icon_new ();
+ gpm_tray_icon_show (icon, FALSE);
g_signal_connect_object (G_OBJECT (icon->priv->status_icon),
"popup_menu",
G_CALLBACK (gpm_tray_icon_popup_menu_cb),