[Goodies-commits] r1461 - in xfce4-battery-plugin/branches/XERVERIUS: . panel-plugin

Nick Schermer nick at xfce.org
Wed Jun 28 16:47:49 CEST 2006


Author: nick
Date: 2006-06-28 14:47:42 +0000 (Wed, 28 Jun 2006)
New Revision: 1461

Modified:
   xfce4-battery-plugin/branches/XERVERIUS/TODO
   xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery-actions.c
   xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery-actions.h
   xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery-dialogs.c
   xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery-hal.c
   xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery.c
   xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery.h
Log:
* Support for the lid and power button
* Fix problem with unsaved new commands in
  properties dialog


Modified: xfce4-battery-plugin/branches/XERVERIUS/TODO
===================================================================
--- xfce4-battery-plugin/branches/XERVERIUS/TODO	2006-06-27 11:32:10 UTC (rev 1460)
+++ xfce4-battery-plugin/branches/XERVERIUS/TODO	2006-06-28 14:47:42 UTC (rev 1461)
@@ -1,10 +1,2 @@
-- Create our own "remaining time" calculate function,
-  using some kind of argoritm
-  
-- Support for suspend and hibernate through HAL
-
-- Add support for power usage (Watts) to give the user
-  an idea of the power usage of his/her laptop
-
 - Add a 'averange' battery for multiple battery users, to
   show a global status of all batteries in the system.

Modified: xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery-actions.c
===================================================================
--- xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery-actions.c	2006-06-27 11:32:10 UTC (rev 1460)
+++ xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery-actions.c	2006-06-28 14:47:42 UTC (rev 1461)
@@ -381,8 +381,8 @@
 battery_actions_check (BatteryStatus *bat,
                        guint          id,
                        GtkWidget     *messages,
-               ActiveAction   action,
-               gchar         *command)
+                       BatteryAction  action,
+                       gchar         *command)
 {
     switch (action)
     {
@@ -415,3 +415,30 @@
     failed:
         g_warning (_("The battery monitor was unable to execute following command: %s"), command);
 }
+
+void
+button_actions_check (ButtonAction  action,
+                      gchar        *command)
+{
+    switch (action)
+    {
+        case COMMAND2:
+            if (!xfce_exec (command, FALSE, FALSE, NULL))
+                goto failed;
+            break;
+
+        case TERMINAL2:
+            if (!xfce_exec (command, TRUE, FALSE, NULL))
+                goto failed;
+            break;
+
+        default:
+            break;
+    }
+
+    return;
+
+    failed:
+        g_warning (_("The battery monitor was unable to execute following command: %s"), command);
+}
+

Modified: xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery-actions.h
===================================================================
--- xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery-actions.h	2006-06-27 11:32:10 UTC (rev 1460)
+++ xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery-actions.h	2006-06-28 14:47:42 UTC (rev 1461)
@@ -46,8 +46,11 @@
 battery_actions_set_len         (gint len);
 
 void
-battery_actions_check           (BatteryStatus *bat, guint id, GtkWidget *messages, ActiveAction action, gchar *command);
+battery_actions_check           (BatteryStatus *bat, guint id, GtkWidget *messages, BatteryAction action, gchar *command);
 
+void
+button_actions_check            (ButtonAction action, gchar *command);
+
 G_END_DECLS
 
 #endif /* _BATTERY_ACTIONS_H */

Modified: xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery-dialogs.c
===================================================================
--- xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery-dialogs.c	2006-06-27 11:32:10 UTC (rev 1460)
+++ xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery-dialogs.c	2006-06-28 14:47:42 UTC (rev 1461)
@@ -37,13 +37,17 @@
 
     GtkWidget *panel_frame, *panel_icon, *panel_progressbar, *panel_percentage, *panel_time;
 
-    GtkWidget *tooltip_time;
+    GtkWidget *tooltip_time, *tooltip_power;
     GtkWidget *main_battery;
 
-    GtkWidget *spin_critical,   *spin_low;
-    GtkWidget *combo_critical,  *combo_low,  *combo_full;
-    GtkWidget *entry_critical,  *entry_low,  *entry_full;
+    GtkWidget *spin_critical, *spin_low;
+    GtkWidget *combo_critical, *combo_low, *combo_full;
+    GtkWidget *entry_critical, *entry_low, *entry_full;
     GtkWidget *button_critical, *button_low, *button_full;
+    
+    GtkWidget *combo_power, *combo_lid;
+    GtkWidget *entry_power, *entry_lid;
+    GtkWidget *button_power, *button_lid;
 }
 BatteryOptions;
 
@@ -51,64 +55,56 @@
 check_button_toggled (GtkWidget      *button,
                       BatteryOptions *options)
 {
+    gboolean active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+    
     if (button == options->panel_frame)
-        options->battery->show_frame = 
-            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+        options->battery->show_frame = active;
     
     else if (button == options->panel_icon)
-        options->battery->show_icon = 
-            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+        options->battery->show_icon = active;
     
     else if (button == options->panel_progressbar)
-        options->battery->show_progressbar = 
-            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+        options->battery->show_progressbar = active;
 
     else if (button == options->panel_percentage)
-        options->battery->show_percentage = 
-            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+        options->battery->show_percentage = active;
 
     else if (button == options->panel_time)
-        options->battery->show_time = 
-            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+        options->battery->show_time = active;
 
     else if (button == options->tooltip_time)
-        options->battery->tip_time = 
-            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+        options->battery->tip_time = active;
     
+    else if (button == options->tooltip_power)
+        options->battery->tip_power = active;
+    
     battery_widgets (options->battery);
     battery_update_plugin (options->battery);
 }
 
-static gboolean
-command_focus_out (GtkWidget      *entry,
-                   GdkEventFocus  *event,
-                   BatteryOptions *options)
+static void
+save_all_commands (BatteryOptions *options)
 {
-    gchar *command;
-
-    command = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
+    options->battery->command_critical = 
+        g_strdup (gtk_editable_get_chars(GTK_EDITABLE(options->entry_critical), 0, -1));
     
-    if (command == NULL)
-        return FALSE;
-
-    if (entry == options->entry_critical)
-        options->battery->command_critical = g_strdup (command);
+    options->battery->command_low = 
+        g_strdup (gtk_editable_get_chars(GTK_EDITABLE(options->entry_low), 0, -1));
     
-    else if (entry == options->entry_low)
-        options->battery->command_low = g_strdup (command);
+    options->battery->command_charged = 
+        g_strdup (gtk_editable_get_chars(GTK_EDITABLE(options->entry_full), 0, -1));
     
-    else if (entry == options->entry_full)
-        options->battery->command_charged = g_strdup (command);
-
-    g_free (command);
+    options->battery->command_power = 
+        g_strdup (gtk_editable_get_chars(GTK_EDITABLE(options->entry_power), 0, -1));
     
-    return FALSE;
+    options->battery->command_lid = 
+        g_strdup (gtk_editable_get_chars(GTK_EDITABLE(options->entry_lid), 0, -1));
 }
 
 static void
-combobox_changed_sensative (gint       active,
-                            GtkWidget *entry,
-                            GtkWidget *button)
+battery_action_set_sensative (gint       active,
+                              GtkWidget *entry,
+                              GtkWidget *button)
 {
 #ifdef HAVE_LIBNOTIFY
     if (active >= 3)
@@ -127,6 +123,23 @@
 }
 
 static void
+button_action_set_sensative (gint       active,
+                             GtkWidget *entry,
+                             GtkWidget *button)
+{
+    if (active >= 1)
+    {
+        gtk_widget_set_sensitive (entry, TRUE);
+        gtk_widget_set_sensitive (button, TRUE);
+    }
+    else
+    {
+        gtk_widget_set_sensitive (entry, FALSE);
+        gtk_widget_set_sensitive (button, FALSE);
+    }
+}                       
+
+static void
 combobox_changed (GtkComboBox    *combobox,
                   BatteryOptions *options)
 {
@@ -134,19 +147,29 @@
 
     if (GTK_WIDGET(combobox) == options->combo_critical)
     {
-        combobox_changed_sensative (active, options->entry_critical, options->button_critical);
+        battery_action_set_sensative (active, options->entry_critical, options->button_critical);
         options->battery->action_critical = active;
     }
     else if (GTK_WIDGET(combobox) == options->combo_low)
     {
-        combobox_changed_sensative (active, options->entry_low, options->button_low);
+        battery_action_set_sensative (active, options->entry_low, options->button_low);
         options->battery->action_low = active;
     }
     else if (GTK_WIDGET(combobox) == options->combo_full)
     {
-        combobox_changed_sensative (active, options->entry_full, options->button_full);
+        battery_action_set_sensative (active, options->entry_full, options->button_full);
         options->battery->action_charged = active;
     }
+    else if (GTK_WIDGET(combobox) == options->combo_power)
+    {
+        button_action_set_sensative (active, options->entry_power, options->button_power);
+        options->battery->action_power = active;
+    }
+    else if (GTK_WIDGET(combobox) == options->combo_lid)
+    {
+        button_action_set_sensative (active, options->entry_lid, options->button_lid);
+        options->battery->action_lid = active;
+    }
     else if (GTK_WIDGET (combobox) == options->main_battery)
     {
         options->battery->show_battery = active;
@@ -193,6 +216,9 @@
     g_object_set_data (G_OBJECT (options->battery->plugin), "configure", NULL);
 
     xfce_panel_plugin_unblock_menu (options->battery->plugin);
+    
+    /* Save all commands */
+    save_all_commands (options);
 
     /* Destroy all widgets */
     gtk_widget_destroy (dialog);
@@ -204,13 +230,19 @@
 }
 
 static void
-battery_append_values (GtkComboBox *box)
+combobox_append_values (GtkComboBox *box,
+                        gboolean     is_battery)
 {
     gtk_combo_box_append_text (box, _("Do nothing"));
-    gtk_combo_box_append_text (box, _("Display warning message"));
+    
+    if (is_battery)
+    {
+        gtk_combo_box_append_text (box, _("Display warning message"));
 #ifdef HAVE_LIBNOTIFY
-    gtk_combo_box_append_text (box, _("Notification"));
+        gtk_combo_box_append_text (box, _("Show notification"));
 #endif
+    }
+    
     gtk_combo_box_append_text (box, _("Run Command"));
     gtk_combo_box_append_text (box, _("Run command in terminal"));
 }
@@ -457,7 +489,7 @@
 
     /* Tooltip appearance frame */
     frame = gtk_frame_new (NULL);
-    gtk_box_pack_start (GTK_BOX (notebook_vbox), frame, TRUE, TRUE, 0);
+    gtk_box_pack_start (GTK_BOX (notebook_vbox), frame, FALSE, FALSE, 0);
     gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
 
     alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
@@ -474,6 +506,13 @@
     
     g_signal_connect (button, "toggled",
         G_CALLBACK (check_button_toggled), options);
+	
+    button = options->tooltip_power = gtk_check_button_new_with_mnemonic (_("Show power usage"));
+    gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), battery->tip_power);
+    
+    g_signal_connect (button, "toggled",
+        G_CALLBACK (check_button_toggled), options);
 
     label = gtk_label_new (_("<b>Tooltip</b>"));
     gtk_frame_set_label_widget (GTK_FRAME (frame), label);
@@ -483,14 +522,14 @@
     label = gtk_label_new (_("Appearance"));
     gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 0), label);
     
-    /* Actions tab */
+    /* Battery actions tab */
     notebook_vbox = gtk_vbox_new (FALSE, BORDER);
     gtk_container_add (GTK_CONTAINER (notebook), notebook_vbox);
     gtk_container_set_border_width (GTK_CONTAINER (notebook_vbox), BORDER);
     
     /* Critical battery action frame */
     frame = gtk_frame_new (NULL);
-    gtk_box_pack_start (GTK_BOX (notebook_vbox), frame, TRUE, TRUE, 0);
+    gtk_box_pack_start (GTK_BOX (notebook_vbox), frame, FALSE, FALSE, 0);
     gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
 
     alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
@@ -528,7 +567,7 @@
 
     combobox = options->combo_critical = gtk_combo_box_new_text ();
     gtk_box_pack_start (GTK_BOX (hbox), combobox, TRUE, TRUE, 0);
-    battery_append_values (GTK_COMBO_BOX (combobox));
+    combobox_append_values (GTK_COMBO_BOX (combobox), TRUE);
     
     g_signal_connect(G_OBJECT(combobox), "changed",
         G_CALLBACK(combobox_changed), options);
@@ -548,9 +587,6 @@
     if (battery->command_critical)
         gtk_entry_set_text (GTK_ENTRY (entry), battery->command_critical);
     
-    g_signal_connect (G_OBJECT(entry), "focus-out-event",
-        G_CALLBACK (command_focus_out), options);
-
     button = options->button_critical = gtk_button_new ();
     gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
     
@@ -568,7 +604,7 @@
     
     /* Low battery action frame */
     frame = gtk_frame_new (NULL);
-    gtk_box_pack_start (GTK_BOX (notebook_vbox), frame, TRUE, TRUE, 0);
+    gtk_box_pack_start (GTK_BOX (notebook_vbox), frame, FALSE, FALSE, 0);
     gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
 
     alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
@@ -606,7 +642,7 @@
 
     combobox = options->combo_low = gtk_combo_box_new_text ();
     gtk_box_pack_start (GTK_BOX (hbox), combobox, TRUE, TRUE, 0);
-    battery_append_values (GTK_COMBO_BOX (combobox));
+    combobox_append_values (GTK_COMBO_BOX (combobox), TRUE);
     
     g_signal_connect(G_OBJECT(combobox), "changed",
         G_CALLBACK(combobox_changed), options);
@@ -626,9 +662,6 @@
     if (battery->command_low)
         gtk_entry_set_text (GTK_ENTRY (entry), battery->command_low);
     
-    g_signal_connect (G_OBJECT(entry), "focus-out-event",
-        G_CALLBACK (command_focus_out), options);
-
     button = options->button_low = gtk_button_new ();
     gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
     
@@ -646,7 +679,7 @@
     
     /* Charged battery action frame */
     frame = gtk_frame_new (NULL);
-    gtk_box_pack_start (GTK_BOX (notebook_vbox), frame, TRUE, TRUE, 0);
+    gtk_box_pack_start (GTK_BOX (notebook_vbox), frame, FALSE, FALSE, 0);
     gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
 
     alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
@@ -668,7 +701,7 @@
 
     combobox = options->combo_full = gtk_combo_box_new_text ();
     gtk_box_pack_start (GTK_BOX (hbox), combobox, TRUE, TRUE, 0);
-    battery_append_values (GTK_COMBO_BOX (combobox));
+    combobox_append_values (GTK_COMBO_BOX (combobox), TRUE);
     
     g_signal_connect(G_OBJECT(combobox), "changed",
         G_CALLBACK(combobox_changed), options);
@@ -688,9 +721,6 @@
     if (battery->command_charged)
         gtk_entry_set_text (GTK_ENTRY (entry), battery->command_charged);
     
-    g_signal_connect (G_OBJECT(entry), "focus-out-event",
-        G_CALLBACK (command_focus_out), options);
-
     button = options->button_full = gtk_button_new ();
     gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
     
@@ -706,10 +736,137 @@
     gtk_frame_set_label_widget (GTK_FRAME (frame), label);
     gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
     
-    /* Actions tab label */
-    label = gtk_label_new (_("Actions"));
+    /* Battery actions tab label */
+    label = gtk_label_new (_("Battery Actions"));
     gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 1), label);
     
+    /* Button Actions */
+    notebook_vbox = gtk_vbox_new (FALSE, BORDER);
+    gtk_container_add (GTK_CONTAINER (notebook), notebook_vbox);
+    gtk_container_set_border_width (GTK_CONTAINER (notebook_vbox), BORDER);
+    
+    /* Power Button frame */
+    frame = gtk_frame_new (NULL);
+    gtk_box_pack_start (GTK_BOX (notebook_vbox), frame, FALSE, FALSE, 0);
+    gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
+
+    alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
+    gtk_container_add (GTK_CONTAINER (frame), alignment);
+    gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, BORDER*3, 0);
+
+    vbox = gtk_vbox_new (FALSE, 2);
+    gtk_container_add (GTK_CONTAINER (alignment), vbox);
+    gtk_container_set_border_width (GTK_CONTAINER (vbox), BORDER);
+
+    hbox = gtk_hbox_new (FALSE, BORDER);
+    gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
+
+    label = gtk_label_new (_("Action:"));
+    gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+    gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+    
+    gtk_size_group_add_widget (sg_labels, label);
+
+    combobox = options->combo_power = gtk_combo_box_new_text ();
+    gtk_box_pack_start (GTK_BOX (hbox), combobox, TRUE, TRUE, 0);
+    combobox_append_values (GTK_COMBO_BOX (combobox), FALSE);
+    
+    g_signal_connect(G_OBJECT(combobox), "changed",
+        G_CALLBACK(combobox_changed), options);
+
+    hbox = gtk_hbox_new (FALSE, BORDER);
+    gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
+
+    label = gtk_label_new (_("Command:"));
+    gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+    gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+    
+    gtk_size_group_add_widget (sg_labels, label);
+
+    entry = options->entry_power = gtk_entry_new ();
+    gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
+    
+    if (battery->command_power)
+        gtk_entry_set_text (GTK_ENTRY (entry), battery->command_power);
+    
+    button = options->button_power = gtk_button_new ();
+    gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+    
+    g_signal_connect(button, "button_press_event",
+            G_CALLBACK(battery_command_clicked), entry);
+
+    icon = gtk_image_new_from_stock ("gtk-open", GTK_ICON_SIZE_MENU);
+    gtk_container_add (GTK_CONTAINER (button), icon);
+    
+    gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), battery->action_power);
+
+    label = gtk_label_new (_("<b>Power Button</b>"));
+    gtk_frame_set_label_widget (GTK_FRAME (frame), label);
+    gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+    
+    /* LID Button frame */
+    frame = gtk_frame_new (NULL);
+    gtk_box_pack_start (GTK_BOX (notebook_vbox), frame, FALSE, FALSE, 0);
+    gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
+
+    alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
+    gtk_container_add (GTK_CONTAINER (frame), alignment);
+    gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, BORDER*3, 0);
+
+    vbox = gtk_vbox_new (FALSE, 2);
+    gtk_container_add (GTK_CONTAINER (alignment), vbox);
+    gtk_container_set_border_width (GTK_CONTAINER (vbox), BORDER);
+
+    hbox = gtk_hbox_new (FALSE, BORDER);
+    gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
+
+    label = gtk_label_new (_("Action:"));
+    gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+    gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+    
+    gtk_size_group_add_widget (sg_labels, label);
+
+    combobox = options->combo_lid = gtk_combo_box_new_text ();
+    gtk_box_pack_start (GTK_BOX (hbox), combobox, TRUE, TRUE, 0);
+    combobox_append_values (GTK_COMBO_BOX (combobox), FALSE);
+    
+    g_signal_connect(G_OBJECT(combobox), "changed",
+        G_CALLBACK(combobox_changed), options);
+
+    hbox = gtk_hbox_new (FALSE, BORDER);
+    gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
+
+    label = gtk_label_new (_("Command:"));
+    gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+    gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+    
+    gtk_size_group_add_widget (sg_labels, label);
+
+    entry = options->entry_lid = gtk_entry_new ();
+    gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
+    
+    if (battery->command_lid)
+        gtk_entry_set_text (GTK_ENTRY (entry), battery->command_lid);
+    
+    button = options->button_lid = gtk_button_new ();
+    gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+    
+    g_signal_connect(button, "button_press_event",
+            G_CALLBACK(battery_command_clicked), entry);
+
+    icon = gtk_image_new_from_stock ("gtk-open", GTK_ICON_SIZE_MENU);
+    gtk_container_add (GTK_CONTAINER (button), icon);
+    
+    gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), battery->action_lid);
+
+    label = gtk_label_new (_("<b>Lid Button</b>"));
+    gtk_frame_set_label_widget (GTK_FRAME (frame), label);
+    gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
+    
+    /* Button actions tab label */
+    label = gtk_label_new (_("Button Actions"));
+    gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 2), label);
+    
     g_signal_connect(dialog, "response",
         G_CALLBACK(battery_configure_response), options);
         

Modified: xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery-hal.c
===================================================================
--- xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery-hal.c	2006-06-27 11:32:10 UTC (rev 1460)
+++ xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery-hal.c	2006-06-28 14:47:42 UTC (rev 1461)
@@ -23,11 +23,13 @@
 #include <config.h>
 #endif
 
+#include <libxfcegui4/libxfcegui4.h>
 #include <dbus/dbus-glib-lowlevel.h>
 #include <hal/libhal.h>
 
 #include "battery.h"
 #include "battery-hal.h"
+#include "battery-actions.h"
 #include "battery-calc.h"
 
 /* Minimum time in seconds beween HAL events */
@@ -104,7 +106,7 @@
     BatteryStatus *bat;
     
     g_return_if_fail (ctx == context);
-
+    
     /* Only allow battery* keys */
     if (strncmp (key, "battery", 7) != 0)
         return;
@@ -142,6 +144,33 @@
     battery_update_plugin (battery);
 }
 
+static void
+hal_device_condition (LibHalContext *ctx,
+		      const char    *udi,
+		      const char    *name,
+		      const char    *details)
+{
+    BatteryPlugin *battery;
+    
+    g_return_if_fail (ctx == context);
+    
+    /* Only allow button press events */
+    if (strcmp (name, "ButtonPressed") != 0)
+        return;
+    
+    /* Get the plugin structure */
+    battery = libhal_ctx_get_user_data (ctx);
+    
+    if (strcmp (details, "power") == 0)
+    {
+	button_actions_check (battery->action_power, battery->command_power);
+    }
+    else if (strcmp (details, "lid") == 0)
+    {
+	button_actions_check (battery->action_lid, battery->command_lid);
+    }
+}
+    
 void
 battery_remove (BatteryStatus *bat)
 {
@@ -354,6 +383,7 @@
     
      /* Set callback to monitor the device changes */
     libhal_ctx_set_device_property_modified (context, hal_property_modified);
+    libhal_ctx_set_device_condition (context, hal_device_condition);
     
     if (G_UNLIKELY (battery_initilize_batteries(battery) == FALSE))
         goto nobatteries;

Modified: xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery.c
===================================================================
--- xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery.c	2006-06-27 11:32:10 UTC (rev 1460)
+++ xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery.c	2006-06-28 14:47:42 UTC (rev 1461)
@@ -93,6 +93,10 @@
         else
             g_string_append_printf (tooltip, "%s (%d%% %s)",
 	                            charging, percentage, completed);
+	
+	if (battery->tip_power)
+	    g_string_append_printf (tooltip, "\n%d mWh",
+	                            bat->chargeRate);
     }
     else if (G_LIKELY (bat->isPresent))/* Discharging */
     {
@@ -102,6 +106,10 @@
         else
             g_string_append_printf (tooltip, "%d%% %s",
 	                            percentage, remaining);
+	
+	if (battery->tip_power)
+	    g_string_append_printf (tooltip, "\n%d mWh",
+	                            bat->dischargeRate);
     }
     else /* Battery not present in system */
     {
@@ -548,11 +556,15 @@
     battery->show_time        = xfce_rc_read_bool_entry (rc, "show_time",        FALSE);
 
     battery->tip_time         = xfce_rc_read_bool_entry (rc, "tip_time",         TRUE);
+    battery->tip_power        = xfce_rc_read_bool_entry (rc, "tip_power",        TRUE);
 
     battery->action_critical  = xfce_rc_read_int_entry  (rc, "action_critical",  1);
     battery->action_low       = xfce_rc_read_int_entry  (rc, "action_low",       1);
     battery->action_charged   = xfce_rc_read_int_entry  (rc, "action_charged",   0);
 
+    battery->action_power     = xfce_rc_read_int_entry  (rc, "action_power",     0);
+    battery->action_lid       = xfce_rc_read_int_entry  (rc, "action_lid",       0);
+
     battery->perc_critical    = xfce_rc_read_int_entry  (rc, "perc_critical",    10);
     battery->perc_low         = xfce_rc_read_int_entry  (rc, "perc_low",         20);
 
@@ -565,6 +577,12 @@
     if ((s = xfce_rc_read_entry (rc, "command_charged", NULL)) != NULL)
         battery->command_charged = g_strdup (s);
     
+    if ((s = xfce_rc_read_entry (rc, "command_power", NULL)) != NULL)
+        battery->command_power = g_strdup (s);
+    
+    if ((s = xfce_rc_read_entry (rc, "command_lid", NULL)) != NULL)
+        battery->command_lid = g_strdup (s);
+    
     /* Load battery information */
     for (i = battery->batteries->len; i--;)
     {
@@ -610,10 +628,14 @@
     xfce_rc_write_bool_entry (rc, "show_time",        battery->show_time);
 
     xfce_rc_write_bool_entry (rc, "tip_time",         battery->tip_time);
+    xfce_rc_write_bool_entry (rc, "tip_power",        battery->tip_power);
 
     xfce_rc_write_int_entry  (rc, "action_critical",  battery->action_critical);
     xfce_rc_write_int_entry  (rc, "action_low",       battery->action_low);
     xfce_rc_write_int_entry  (rc, "action_charged",   battery->action_charged);
+    
+    xfce_rc_write_int_entry  (rc, "action_power",     battery->action_power);
+    xfce_rc_write_int_entry  (rc, "action_lid",       battery->action_lid);
 
     xfce_rc_write_int_entry  (rc, "perc_critical",    battery->perc_critical);
     xfce_rc_write_int_entry  (rc, "perc_low",         battery->perc_low);
@@ -622,6 +644,9 @@
     xfce_rc_write_entry (rc, "command_low",      battery->command_low      ? battery->command_low      : "");
     xfce_rc_write_entry (rc, "command_charged",  battery->command_charged  ? battery->command_charged  : "");
     
+    xfce_rc_write_entry (rc, "command_power", battery->command_power ? battery->command_power : "");
+    xfce_rc_write_entry (rc, "command_lid",   battery->command_lid   ? battery->command_lid   : "");
+    
     /* Save battery information */
     for (i = battery->batteries->len; i--;)
     {
@@ -685,6 +710,8 @@
     g_free (battery->command_critical);
     g_free (battery->command_low);
     g_free (battery->command_charged);
+    g_free (battery->command_power);
+    g_free (battery->command_lid);
 
     battery->plugin = NULL;
 

Modified: xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery.h
===================================================================
--- xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery.h	2006-06-27 11:32:10 UTC (rev 1460)
+++ xfce4-battery-plugin/branches/XERVERIUS/panel-plugin/battery.h	2006-06-28 14:47:42 UTC (rev 1461)
@@ -37,10 +37,19 @@
 #endif
     COMMAND,
     TERMINAL,
-} ActiveAction;
+}
+BatteryAction;
 
 typedef enum
 {
+    NOTHING2 = 0,
+    COMMAND2,
+    TERMINAL2,
+}
+ButtonAction;
+
+typedef enum
+{
     NONE = 0,
     CHARGED,
     LOW,
@@ -83,12 +92,16 @@
 
     /* Settings: Appearance */
     gboolean           show_frame, show_icon, show_progressbar, show_percentage, show_time;
-    gboolean           tip_time;
+    gboolean           tip_time, tip_power;
 
-    /* Settings: Actions */
+    /* Settings: Battery Actions */
     guint              perc_critical, perc_low;
-    ActiveAction       action_critical, action_low, action_charged;
+    BatteryAction      action_critical, action_low, action_charged;
     gchar             *command_critical, *command_low, *command_charged;
+    
+    /* Settings: Button Actions */
+    ButtonAction       action_power, action_lid;
+    gchar             *command_power, *command_lid;
 }
 BatteryPlugin;
 




More information about the Goodies-commits mailing list