Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions docklets/Battery/BatteryDockItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -120,13 +127,20 @@ namespace Docky
}

Icon = new_icon;
Text = "%i%%".printf (capacity);
Text = "%s - %i%%".printf (current_battery, capacity);
} catch {
Icon = "battery-missing";
Text = _("No battery");
}

return true;
}

void handle_prefs_changed ()
{
unowned BatteryPreferences prefs = (BatteryPreferences) Prefs;
current_battery = (prefs.BatteryName);
update();
}
}
}
39 changes: 39 additions & 0 deletions docklets/Battery/BatteryPreferences.vala
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
//

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)")]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be power_supply right?

public string BatteryName {get;set;}

public BatteryPreferences.with_file (GLib.File file)
{
base.with_file (file);
}

protected override void reset_properties ()
{
BatteryName = "BAT0";
}
}
}
1 change: 1 addition & 0 deletions docklets/Battery/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 = \
Expand Down