[Xfce4-commits] [xfce/xfce4-power-manager] 25/64: Populate the device menu
noreply at xfce.org
noreply at xfce.org
Mon May 26 06:00:20 CEST 2014
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository xfce/xfce4-power-manager.
commit 2589da8e9a88d69f8b71d54fb95dac66ab946801
Author: Eric Koegel <eric.koegel at gmail.com>
Date: Sun May 4 05:56:56 2014 +0300
Populate the device menu
The left click menu now displays the devices and their status at
the time of the menu's creation.
---
panel-plugins/battery/battery-button.c | 71 +++++++++++++++++++++++++++++++-
panel-plugins/battery/battery-button.h | 6 +--
panel-plugins/battery/battery-plugin.c | 2 +-
3 files changed, 73 insertions(+), 6 deletions(-)
diff --git a/panel-plugins/battery/battery-button.c b/panel-plugins/battery/battery-button.c
index 93f5e6b..055b4be 100644
--- a/panel-plugins/battery/battery-button.c
+++ b/panel-plugins/battery/battery-button.c
@@ -1,5 +1,5 @@
/*
- * * Copyright (C) 2009-2011 Ali <aliov at xfce.org>
+ * * Copyright (C) 2014 Eric Koegel <eric at xfce.org>
*
* Licensed under the GNU General Public License Version 2
*
@@ -42,6 +42,8 @@ static void battery_button_finalize (GObject *object);
static gchar* get_device_description (UpClient *upower, UpDevice *device);
static GList* find_device_in_list (BatteryButton *button, const gchar *object_path);
static gboolean battery_button_set_icon (BatteryButton *button);
+static void battery_button_clicked (GtkButton *b);
+static void battery_button_show_menu (BatteryButton *button);
#define BATTERY_BUTTON_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), BATTERY_TYPE_BUTTON, BatteryButtonPrivate))
@@ -447,10 +449,13 @@ static void
battery_button_class_init (BatteryButtonClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
object_class->finalize = battery_button_finalize;
object_class->set_property = battery_button_set_property;
+ button_class->clicked = battery_button_clicked;
+
g_object_class_install_property (object_class,
PROP_PLUGIN,
g_param_spec_object ("plugin",
@@ -526,6 +531,14 @@ battery_button_set_icon (BatteryButton *button)
return FALSE;
}
+static void
+battery_button_clicked (GtkButton *b)
+{
+ BatteryButton *button = BATTERY_BUTTON (b);
+
+ battery_button_show_menu (button);
+}
+
static gboolean
battery_button_size_changed_cb (XfcePanelPlugin *plugin, gint size, BatteryButton *button)
{
@@ -550,7 +563,8 @@ help_cb (GtkMenuItem *menuitem, gpointer user_data)
xfce_dialog_show_help (NULL, "xfce4-power-manager", "start", NULL);
}
-void battery_button_show (BatteryButton *button)
+void
+battery_button_show (BatteryButton *button)
{
GtkWidget *mi;
@@ -581,3 +595,56 @@ void battery_button_show (BatteryButton *button)
/* Add all the devcies currently attached to the system */
battery_button_add_all_devices (button);
}
+
+static void
+battery_button_show_menu (BatteryButton *button)
+{
+ GtkWidget *menu, *mi, *label, *img;
+ GdkScreen *gscreen;
+ GList *item;
+
+ if(gtk_widget_has_screen(GTK_WIDGET(button)))
+ gscreen = gtk_widget_get_screen(GTK_WIDGET(button));
+ else
+ gscreen = gdk_display_get_default_screen(gdk_display_get_default());
+
+ menu = gtk_menu_new ();
+ gtk_menu_set_screen(GTK_MENU(menu), gscreen);
+
+ for (item = g_list_first (button->priv->devices); item != NULL; item = g_list_next (item))
+ {
+ BatteryDevice *battery_device = item->data;
+
+ mi = gtk_image_menu_item_new_with_label(battery_device->details);
+ /* Make the menu item be bold and multi-line */
+ label = gtk_bin_get_child(GTK_BIN(mi));
+ gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
+
+ /* add the image */
+ img = gtk_image_new_from_pixbuf(battery_device->pix);
+ gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(mi), img);
+
+ /* Add it to the menu */
+ gtk_widget_show(mi);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
+ }
+
+ /* separator */
+ mi = gtk_separator_menu_item_new();
+ gtk_widget_show(mi);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
+
+ /* Preferences option */
+ mi = gtk_menu_item_new_with_mnemonic ("_Preferences...");
+ gtk_widget_show(mi);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), mi);
+ g_signal_connect(G_OBJECT(mi), "activate", G_CALLBACK(xfpm_preferences), NULL);
+
+ gtk_menu_popup (GTK_MENU (menu),
+ NULL,
+ NULL,
+ xfce_panel_plugin_position_menu,
+ button->priv->plugin,
+ 0,
+ gtk_get_current_event_time ());
+}
diff --git a/panel-plugins/battery/battery-button.h b/panel-plugins/battery/battery-button.h
index ca0edce..e619cdb 100644
--- a/panel-plugins/battery/battery-button.h
+++ b/panel-plugins/battery/battery-button.h
@@ -1,5 +1,5 @@
/*
- * * Copyright (C) 2009-2011 Ali <aliov at xfce.org>
+ * * Copyright (C) 2014 Eric Koegel <eric at xfce.org>
*
* Licensed under the GNU General Public License Version 2
*
@@ -35,14 +35,14 @@ typedef struct BatteryButtonPrivate BatteryButtonPrivate;
typedef struct
{
- GtkButton parent;
+ GtkButton parent;
BatteryButtonPrivate *priv;
} BatteryButton;
typedef struct
{
- GtkButtonClass parent_class;
+ GtkButtonClass parent_class;
} BatteryButtonClass;
diff --git a/panel-plugins/battery/battery-plugin.c b/panel-plugins/battery/battery-plugin.c
index db446d5..1cec196 100644
--- a/panel-plugins/battery/battery-plugin.c
+++ b/panel-plugins/battery/battery-plugin.c
@@ -1,5 +1,5 @@
/*
- * * Copyright (C) 2009-2011 Ali <aliov at xfce.org>
+ * * Copyright (C) 2014 Eric Koegel <eric at xfce.org>
*
* Licensed under the GNU General Public License Version 2
*
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list