diff --git a/src/Widgets/DeviceList.vala b/src/Widgets/DeviceList.vala index cf3367b6..0c56f466 100644 --- a/src/Widgets/DeviceList.vala +++ b/src/Widgets/DeviceList.vala @@ -19,12 +19,14 @@ public class Power.Widgets.DeviceList : Gtk.ListBox { public Gee.HashMap entries; + public Gee.HashMap path_entries; construct { selection_mode = Gtk.SelectionMode.NONE; set_sort_func (sort_function); entries = new Gee.HashMap (); + path_entries = new Gee.HashMap (); var dm = Services.DeviceManager.get_default (); dm.battery_registered.connect (add_battery); @@ -32,12 +34,30 @@ public class Power.Widgets.DeviceList : Gtk.ListBox { // load all battery information. dm.read_devices (); + + this.row_activated.connect ((value) => { + string device_path = path_entries.@get (value); + try { + AppInfo statistics_app = AppInfo.create_from_commandline ( + "gnome-power-statistics --device " + device_path, + "", + AppInfoCreateFlags.NONE + ); + statistics_app.launch (null, null); + + Gtk.Popover popover = (Gtk.Popover) get_ancestor (typeof (Gtk.Popover)); + popover.popdown (); + } catch (Error e) { + print ("Error opening Gnome Power Statistics: %s\n", e.message); + } + }); } private void add_battery (string device_path, Services.Device battery) { var device_row = new Power.Widgets.DeviceRow (battery); entries.@set (device_path, device_row); + path_entries.@set (device_row, device_path); add (device_row); show_all (); diff --git a/src/Widgets/DeviceRow.vala b/src/Widgets/DeviceRow.vala index 08e0efb1..00e95485 100644 --- a/src/Widgets/DeviceRow.vala +++ b/src/Widgets/DeviceRow.vala @@ -28,39 +28,45 @@ public class Power.Widgets.DeviceRow : Gtk.ListBoxRow { } construct { - device_image = new Gtk.Image.from_icon_name ("battery", Gtk.IconSize.DIALOG); - device_image.pixel_size = 48; - device_image.margin_end = 3; + device_image = new Gtk.Image.from_icon_name ("battery", Gtk.IconSize.DIALOG) { + pixel_size = 48, + margin_end = 3 + }; - battery_image = new Gtk.Image (); - battery_image.pixel_size = 32; - battery_image.halign = Gtk.Align.END; - battery_image.valign = Gtk.Align.END; + battery_image = new Gtk.Image () { + pixel_size = 32, + halign = Gtk.Align.END, + valign = Gtk.Align.END + }; var overlay = new Gtk.Overlay (); overlay.add (device_image); overlay.add_overlay (battery_image); - var title_label = new Gtk.Label (get_title ()); - title_label.use_markup = true; - title_label.halign = Gtk.Align.START; - title_label.valign = Gtk.Align.END; + var title_label = new Gtk.Label (get_title ()) { + use_markup = true, + halign = Gtk.Align.START, + valign = Gtk.Align.END + }; - var info_label = new Gtk.Label (battery.get_info ()); - info_label.halign = Gtk.Align.START; - info_label.valign = Gtk.Align.START; - var grid = new Gtk.Grid (); - grid.column_spacing = 3; - grid.margin = 3; - grid.margin_start = 6; - grid.margin_end = 12; + var info_label = new Gtk.Label (battery.get_info ()) { + halign = Gtk.Align.START, + valign = Gtk.Align.START + }; + + var grid = new Gtk.Grid () { + column_spacing = 3, + margin = 3, + margin_start = 6, + margin_end = 12 + }; grid.attach (overlay, 0, 0, 1, 2); grid.attach (title_label, 1, 0); grid.attach (info_label, 1, 1); - add (grid); + add (grid); update_icons (); battery.properties_updated.connect (() => {