* Install dependencies
- apt-get install valac libglib2.0-dev libdbus-glib-1-dev libgee-dev libgtk2.0-dev libwnck-dev
+ # Build time
+ apt-get install valac libglib2.0-dev libdbus-glib-1-dev libgee-dev libgtk2.0-dev libwnck-dev libdevkit-power-gobject-dev
- Optional: apt-get install polygen polygen-data
+ # Runtime
+ apt-get install devicekit-power
+
+ # Optional runtime
+ apt-get install polygen polygen-data
* Compile
AC_SUBST(WNCK_CFLAGS)
AC_SUBST(WNCK_LIBS)
+PKG_CHECK_MODULES(DEVKITPOWER, devkit-power-gobject >= 010)
+AC_SUBST(DEVKITPOWER_CFLAGS)
+AC_SUBST(DEVKITPOWER_LIBS)
+
AC_CONFIG_FILES([Makefile
src/Makefile])
-VFLAGS=-g --pkg gee-1.0 --pkg dbus-glib-1 --pkg gtk+-2.0 --pkg posix --pkg libwnck-1.0 --vapidir=. --pkg linux-input --pkg dbus-extra
+VFLAGS=-g --pkg gee-1.0 --pkg dbus-glib-1 --pkg gtk+-2.0 --pkg posix --pkg libwnck-1.0 --vapidir=. --pkg linux-input --pkg dbus-extra --pkg devkit-power-gobject
#zavai: $(SOURCES)
# valac -o zavai $(VFLAGS) $^
$(GEE_CFLAGS) \
$(GTK_CFLAGS) \
$(WNCK_CFLAGS) \
- -DWNCK_I_KNOW_THIS_IS_UNSTABLE
+ $(DEVKITPOWER_CFLAGS) \
+ -DWNCK_I_KNOW_THIS_IS_UNSTABLE \
+ -DI_KNOW_THE_DEVICEKIT_POWER_API_IS_SUBJECT_TO_CHANGE
BUILT_SOURCES = zavai.vala.stamp $(zavai_VALASOURCES:.vala=.c)
$(DBUS_LIBS) \
$(GEE_LIBS) \
$(GTK_LIBS) \
- $(WNCK_LIBS)
+ $(WNCK_LIBS) \
+ $(DEVKITPOWER_LIBS)
#vapidir = $(datadir)/vala/vapi
public class BatteryIcon : Gtk.StatusIcon
{
- public dynamic DBus.Object battery;
- protected string last_status;
- protected int last_capacity;
+ //public dynamic DBus.Object battery;
+ public Dkp.Device battery;
- public BatteryIcon()
+ public BatteryIcon(Dkp.Device dev)
{
+ battery = dev;
+ battery.changed += on_changed;
+
+ stderr.printf("DEV %s online %s perc %f isrec %s tte %lld ttf %lld\n", dev.native_path, dev.online ? "yes" : "no", dev.percentage, dev.is_rechargeable ? "yes" : "no", dev.time_to_empty, dev.time_to_full);
+
+ /*
battery = zavai.registry.sbus.get_object(
"org.freesmartphone.odeviced",
"/org/freesmartphone/Device/PowerSupply/battery",
"org.freesmartphone.Device.PowerSupply");
+ */
// activate += on_activate;
+ /*
battery.PowerStatus += on_power_status;
battery.Capacity += on_capacity;
last_status = battery.GetPowerStatus();
last_capacity = battery.GetCapacity();
+ */
update_icon();
}
+ private void on_changed(void* obj)
+ {
+ update_icon();
+ }
+
+ /*
private void on_power_status(dynamic DBus.Object bat, string status)
{
zavai.log.info("New battery status: " + status);
last_capacity = val;
update_icon();
}
+ */
/*
private void on_activate()
protected void update_icon()
{
string name = zavai.config.icondir + "/battery/";
+ bool charging = false;
+ Dkp.DeviceState state = (Dkp.DeviceState)battery.state;
- if (last_status == "charging")
- name += "%02d0_charging_500.png".printf(last_capacity/10);
- else
- name += "%02d0.png".printf(last_capacity/10);
+stderr.printf("New battery status: %s\n", Dkp.Device.state_to_text(state));
+ int capacity = (int)Math.round(battery.percentage/10);
+ switch (state)
+ {
+ case Dkp.DeviceState.CHARGING:
+ name += "%02d0_charging_500.png".printf(capacity);
+ break;
+ case Dkp.DeviceState.FULLY_CHARGED:
+ name += "100_charging_500.png";
+ break;
+ case Dkp.DeviceState.UNKNOWN:
+ case Dkp.DeviceState.DISCHARGING:
+ case Dkp.DeviceState.EMPTY:
+ case Dkp.DeviceState.PENDING_CHARGE:
+ case Dkp.DeviceState.PENDING_DISCHARGE:
+ case Dkp.DeviceState.LAST:
+ name += "%02d0.png".printf(capacity);
+ break;
+ }
stderr.printf("Loading icon from %s\n", name);
Power power;
PowerMenu power_menu;
-BatteryIcon battery_icon;
+Gee.ArrayList<BatteryIcon> battery_icons;
Backlight backlight;
//TogglePowerMenu tpm;
power = new Power();
backlight = new Backlight();
zavai.registry.register_service(backlight);
-
- battery_icon = new BatteryIcon();
- battery_icon.set_visible(true);
+
+ battery_icons = new Gee.ArrayList<BatteryIcon>();
+ // Enumerate batteries
+ var c = new Dkp.Client();
+ unowned GLib.PtrArray devs = c.enumerate_devices();
+ for (int i = 0; i < devs.len; ++i)
+ {
+ Dkp.Device dev = (Dkp.Device)devs.pdata[i];
+ if (!dev.is_rechargeable) continue;
+ var bi = new BatteryIcon(dev);
+ bi.set_visible(true);
+ battery_icons.add(bi);
+ }
power_menu = new PowerMenu();
zavai.registry.register_resource("powermenu", power_menu);
[CCode (cprefix = "Dkp", lower_case_cprefix = "dkp_")]
namespace Dkp {
- [CCode (cheader_filename = "devkit-power-gobject.h")]
+ [CCode (cheader_filename = "devkit-power-gobject/devicekit-power.h")]
public class Client : GLib.Object {
[CCode (has_construct_function = false)]
public Client ();
public virtual signal void device_changed (void* device);
public virtual signal void device_removed (void* device);
}
- [CCode (cheader_filename = "devkit-power-gobject.h")]
+ [CCode (cheader_filename = "devkit-power-gobject/devicekit-power.h")]
public class Device : GLib.Object {
[CCode (has_construct_function = false)]
public Device ();
public virtual signal void changed (void* obj);
}
[Compact]
- [CCode (copy_function = "dkp_history_obj_copy", cheader_filename = "devkit-power-gobject.h")]
+ [CCode (copy_function = "dkp_history_obj_copy", cheader_filename = "devkit-power-gobject/devicekit-power.h")]
public class HistoryObj {
public Dkp.DeviceState state;
public uint time;
public unowned string to_string ();
}
[Compact]
- [CCode (copy_function = "dkp_qos_obj_copy", cheader_filename = "devkit-power-gobject.h")]
+ [CCode (copy_function = "dkp_qos_obj_copy", cheader_filename = "devkit-power-gobject/devicekit-power.h")]
public class QosObj {
public weak string cmdline;
public uint cookie;
public bool print ();
}
[Compact]
- [CCode (copy_function = "dkp_stats_obj_copy", cheader_filename = "devkit-power-gobject.h")]
+ [CCode (copy_function = "dkp_stats_obj_copy", cheader_filename = "devkit-power-gobject/devicekit-power.h")]
public class StatsObj {
public double accuracy;
public double value;
public static unowned Dkp.StatsObj from_string (string text);
public unowned string to_string ();
}
- [CCode (cheader_filename = "devkit-power-gobject.h")]
+ [CCode (cheader_filename = "devkit-power-gobject/devicekit-power.h")]
public class Wakeups : GLib.Object {
[CCode (has_construct_function = false)]
public Wakeups ();
public virtual signal void total_changed (uint value);
}
[Compact]
- [CCode (copy_function = "dkp_wakeups_obj_copy", cheader_filename = "devkit-power-gobject.h")]
+ [CCode (copy_function = "dkp_wakeups_obj_copy", cheader_filename = "devkit-power-gobject/devicekit-power.h")]
public class WakeupsObj {
public weak string cmdline;
public weak string details;
public bool equal (Dkp.WakeupsObj obj2);
public bool print ();
}
- [CCode (cprefix = "DKP_DEVICE_STATE_", has_type_id = "0", cheader_filename = "devkit-power-gobject.h")]
+ [CCode (cprefix = "DKP_DEVICE_STATE_", has_type_id = "0", cheader_filename = "devkit-power-gobject/devicekit-power.h")]
public enum DeviceState {
UNKNOWN,
CHARGING,
PENDING_DISCHARGE,
LAST
}
- [CCode (cprefix = "DKP_DEVICE_TECHNOLOGY_", has_type_id = "0", cheader_filename = "devkit-power-gobject.h")]
+ [CCode (cprefix = "DKP_DEVICE_TECHNOLOGY_", has_type_id = "0", cheader_filename = "devkit-power-gobject/devicekit-power.h")]
public enum DeviceTechnology {
UNKNOWN,
LITHIUM_ION,
NICKEL_METAL_HYDRIDE,
LAST
}
- [CCode (cprefix = "DKP_DEVICE_TYPE_", has_type_id = "0", cheader_filename = "devkit-power-gobject.h")]
+ [CCode (cprefix = "DKP_DEVICE_TYPE_", has_type_id = "0", cheader_filename = "devkit-power-gobject/devicekit-power.h")]
public enum DeviceType {
UNKNOWN,
LINE_POWER,
PHONE,
LAST
}
- [CCode (cprefix = "DKP_QOS_TYPE_", has_type_id = "0", cheader_filename = "devkit-power-gobject.h")]
+ [CCode (cprefix = "DKP_QOS_TYPE_", has_type_id = "0", cheader_filename = "devkit-power-gobject/devicekit-power.h")]
public enum QosType {
UNKNOWN,
NETWORK,
CPU_DMA,
LAST
}
- [CCode (cheader_filename = "devkit-power-gobject.h")]
+ [CCode (cheader_filename = "devkit-power-gobject/devicekit-power.h")]
public const int COMPILE_VERSION;
- [CCode (cheader_filename = "devkit-power-gobject.h")]
+ [CCode (cheader_filename = "devkit-power-gobject/devicekit-power.h")]
public static Dkp.QosType qos_type_from_text (string type);
- [CCode (cheader_filename = "devkit-power-gobject.h")]
+ [CCode (cheader_filename = "devkit-power-gobject/devicekit-power.h")]
public static unowned string qos_type_to_text (Dkp.QosType type);
}