Skip to content
Merged
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
15 changes: 10 additions & 5 deletions data/io.github.v81d.Wattage.gschema.xml
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<schemalist gettext-domain="wattage">
<schema id="io.github.v81d.Wattage" path="/io/github/v81d/Wattage/">
<key name="trivial-devices" type="b">
<default>false</default>
<summary>Show trivial devices</summary>
<description>Show or hide devices that do not report much information.</description>
</key>
<key name="auto-refresh" type="b">
<default>true</default>
<summary>Enable auto-refresh</summary>
<description>Whether the app automatically refreshes data.</description>
<description>Whether or not the data should refresh automatically.</description>
</key>
<key name="auto-refresh-cooldown" type="u">
<default>20</default>
<range min="10" max="3600"/>
<summary>Auto-refresh cooldown</summary>
<description>Interval, in seconds, between auto-refresh operations.</description>
<description>The time, in seconds, between each data refresh.</description>
</key>
<key name="energy-unit" type="s">
<default>'Wh'</default>
<summary>Energy unit</summary>
<description>The unit used to display energy measurements.</description>
<description>The unit for energy measurements.</description>
</key>
<key name="power-unit" type="s">
<default>'W'</default>
<summary>Power unit</summary>
<description>The unit used to display power measurements.</description>
<description>The unit for power measurements.</description>
</key>
<key name="voltage-unit" type="s">
<default>'V'</default>
<summary>Voltage unit</summary>
<description>The unit used to display voltage measurements.</description>
<description>The unit for voltage measurements.</description>
</key>
<key name="history-type" type="s">
<default>'rate'</default>
Expand Down
9 changes: 9 additions & 0 deletions src/ui/preferences-dialog.blp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ Adw.PreferencesDialog preferences_dialog {
Adw.PreferencesPage {
title: _("General");

Adw.PreferencesGroup {
title: _("Devices");

Adw.SwitchRow trivial_devices_switch {
title: _("Show Trivial Devices");
subtitle: _("Show or hide devices that do not report much information.");
}
}

Adw.PreferencesGroup {
title: _("Automation");

Expand Down
6 changes: 3 additions & 3 deletions src/ui/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ template $WattageWindow: Adw.ApplicationWindow {
[overlay]
Adw.StatusPage device_list_empty_status {
title: _("No Devices Found");
description: _("Please check your UPower connection.");
description: _("Check your UPower connection");
icon-name: "battery-missing-symbolic";
visible: false;
}
Expand Down Expand Up @@ -102,8 +102,8 @@ template $WattageWindow: Adw.ApplicationWindow {
Adw.StatusPage device_info_empty_status {
hexpand: true;
vexpand: true;
title: _("No Device Information");
description: _("Load a valid device to view its information.");
title: _("No Device Details");
description: _("Load a device to view its information");
icon-name: "info-outline-symbolic";
visible: false;
}
Expand Down
32 changes: 27 additions & 5 deletions src/utils/device-manager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ namespace DeviceManager {
public string? health_description { get; set; }

public DeviceObject () {}

public bool is_trivial () {
return vendor == null &&
model == null &&
serial == null &&
technology == null &&
state == null &&
energy == null &&
energy_full == null &&
energy_full_design == null &&
energy_rate == null &&
voltage == null &&
voltage_min_design == null &&
charge_cycles == null &&
charge_start_threshold == null &&
charge_end_threshold == null &&
time_to_empty == null &&
time_to_full == null &&
temperature == null &&
capacity == null &&
health_description == null;
}
}

// This is the publicly accessible class used to probe, enumerate, and inspect power devices
Expand Down Expand Up @@ -107,12 +129,12 @@ namespace DeviceManager {
if (device_technology == null)return null;

switch (device_technology) {
case 1: return _("Lithium ion");
case 2: return _("Lithium polymer");
case 1: return _("Lithium-ion");
case 2: return _("Lithium-ion polymer");
case 3: return _("Lithium iron phosphate");
case 4: return _("Lead acid");
case 5: return _("Nickel cadmium");
case 6: return _("Nickel metal hydride");
case 4: return _("Lead-acid");
case 5: return _("Nickel-cadmium");
case 6: return _("Nickel-metal hydride");
default: return null;
}
}
Expand Down
18 changes: 17 additions & 1 deletion src/window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public class Wattage.Window : Adw.ApplicationWindow {
private ArrayList<DeviceInfoSection> device_info_sections = new ArrayList<DeviceInfoSection> ();

// Preferences and user settings
private bool trivial_devices;
private bool auto_refresh;
private uint auto_refresh_cooldown;
private uint auto_refresh_source_id = 0;
Expand Down Expand Up @@ -241,6 +242,9 @@ public class Wattage.Window : Adw.ApplicationWindow {
private void initialize_gsettings () {
this.settings = new Settings ("io.github.v81d.Wattage");

// Devices
this.trivial_devices = this.settings.get_boolean ("trivial-devices");

// Automation
this.auto_refresh = this.settings.get_boolean ("auto-refresh");
this.auto_refresh_cooldown = this.settings.get_uint ("auto-refresh-cooldown");
Expand All @@ -264,6 +268,16 @@ public class Wattage.Window : Adw.ApplicationWindow {
stderr.printf ("Could not open preferences dialog: %s\n", e.message);
}

// Trivial devices switch
Adw.SwitchRow trivial_devices_switch = this.preferences_dialog_builder.get_object ("trivial_devices_switch") as Adw.SwitchRow;
trivial_devices_switch.set_active (this.trivial_devices);
trivial_devices_switch.notify["active"].connect (() => {
bool is_active = trivial_devices_switch.get_active ();
this.settings.set_boolean ("trivial-devices", is_active);
this.trivial_devices = is_active;
load_device_list ();
});

// Auto-refresh switch
Adw.SwitchRow auto_refresh_switch = this.preferences_dialog_builder.get_object ("auto_refresh_switch") as Adw.SwitchRow;
auto_refresh_switch.set_active (this.auto_refresh);
Expand Down Expand Up @@ -472,8 +486,10 @@ public class Wattage.Window : Adw.ApplicationWindow {
Idle.add (() => {
if (generation != this.load_device_list_generation)return false;

foreach (DeviceObject device in devices)
foreach (DeviceObject device in devices) {
if (!this.trivial_devices && device.is_trivial ())continue;
this.append_device (device);
}

if (this.device_list.get_row_at_index (this.selected_device_index) != null)
this.device_list.select_row (this.device_list.get_row_at_index (this.selected_device_index));
Expand Down