diff --git a/docklets/Battery/BatteryDockItem.vala b/docklets/Battery/BatteryDockItem.vala index a5e4652be..0eb12dd40 100644 --- a/docklets/Battery/BatteryDockItem.vala +++ b/docklets/Battery/BatteryDockItem.vala @@ -38,20 +38,27 @@ namespace Docky */ public BatteryDockItem.with_dockitem_file (GLib.File file) { - GLib.Object (Prefs: new DockItemPreferences.with_file (file)); + GLib.Object (Prefs: new BatteryPreferences.with_file (file)); } construct { Icon = "battery-missing"; Text = _("No battery"); - update (); + + unowned BatteryPreferences prefs = (BatteryPreferences) Prefs; + prefs.notify["BatteryName"].connect(handle_prefs_changed); + + handle_prefs_changed(); timer_id = Gdk.threads_add_timeout (60 * 1000, (SourceFunc) update); } ~BatteryDockItem () { + unowned BatteryPreferences prefs = (BatteryPreferences) Prefs; + prefs.notify["BatteryName"].disconnect(handle_prefs_changed); + if (timer_id > 0U) { GLib.Source.remove (timer_id); } @@ -120,7 +127,7 @@ namespace Docky } Icon = new_icon; - Text = "%i%%".printf (capacity); + Text = "%s - %i%%".printf (current_battery, capacity); } catch { Icon = "battery-missing"; Text = _("No battery"); @@ -128,5 +135,12 @@ namespace Docky return true; } + + void handle_prefs_changed () + { + unowned BatteryPreferences prefs = (BatteryPreferences) Prefs; + current_battery = (prefs.BatteryName); + update(); + } } } diff --git a/docklets/Battery/BatteryPreferences.vala b/docklets/Battery/BatteryPreferences.vala new file mode 100644 index 000000000..7eefa364c --- /dev/null +++ b/docklets/Battery/BatteryPreferences.vala @@ -0,0 +1,39 @@ +// +// Copyright (C) 2011 Robert Dyer +// +// This file is part of Plank. +// +// Plank is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Plank is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +using Plank; + +namespace Docky +{ + public class BatteryPreferences : DockItemPreferences + { + [Description(nick = "battery-name", blurb = "The name of the battery unit under /sys/class/powe_supply (default=BAT0)")] + public string BatteryName {get;set;} + + public BatteryPreferences.with_file (GLib.File file) + { + base.with_file (file); + } + + protected override void reset_properties () + { + BatteryName = "BAT0"; + } + } +} \ No newline at end of file diff --git a/docklets/Battery/Makefile.am b/docklets/Battery/Makefile.am index 357b0185c..2983db19d 100644 --- a/docklets/Battery/Makefile.am +++ b/docklets/Battery/Makefile.am @@ -12,6 +12,7 @@ libdocklet_battery_ladir = $(pkglibdir)/docklets libdocklet_battery_la_VALASOURCES = \ BatteryDockItem.vala \ BatteryDocklet.vala \ + BatteryPreferences.vala \ $(NULL) nodist_libdocklet_battery_la_SOURCES = \