Skip to content

Commit

Permalink
Merge branch 'main' into danirabbit/backlight-detect
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Feb 11, 2024
2 parents 3d1fab6 + eb635b8 commit 0ad7384
Show file tree
Hide file tree
Showing 11 changed files with 272 additions and 76 deletions.
2 changes: 2 additions & 0 deletions po/POTFILES
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
data/power.policy.in
cli/Server.vala
cli/main.vala
src/Device.vala
src/MainView.vala
src/Plug.vala
src/LogindHelper.vala
src/Interfaces.vala
src/Widgets/BatteryBox.vala
src/Widgets/TimeoutComboBox.vala
src/Widgets/LidCloseActionComboBox.vala
src/Widgets/ActionComboBox.vala
Expand Down
8 changes: 3 additions & 5 deletions po/he.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: maya\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-02-10 02:17+0000\n"
"PO-Revision-Date: 2024-02-10 02:17+0000\n"
"PO-Revision-Date: 2024-02-10 18:59+0000\n"
"Last-Translator: Yaron Shahrabani <sh.yaron@gmail.com>\n"
"Language-Team: Hebrew <https://l10n.elementary.io/projects/switchboard/power/"
"he/>\n"
Expand Down Expand Up @@ -69,14 +69,12 @@ msgid "Plugged In"
msgstr "מחובר"

#: src/MainView.vala:258 src/Plug.vala:79
#, fuzzy
#| msgid "Automatically adjust brightness:"
msgid "Automatically Save Power"
msgstr "התאמת בהירות התצוגה אוטומטית:"
msgstr "חיסכון אוטומטי בחשמל"

#: src/MainView.vala:260
msgid "Power Saver mode will be used when battery is low"
msgstr ""
msgstr "מצב חיסכון בחשמל יופעל כשהסוללה חלשה"

#: src/MainView.vala:266
msgid "On Battery"
Expand Down
12 changes: 4 additions & 8 deletions po/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-02-10 02:17+0000\n"
"PO-Revision-Date: 2024-02-02 22:42+0000\n"
"PO-Revision-Date: 2024-02-10 18:59+0000\n"
"Last-Translator: Ryo Nakano <ryonakaknock3@gmail.com>\n"
"Language-Team: Japanese <https://l10n.elementary.io/projects/switchboard/"
"power/ja/>\n"
Expand Down Expand Up @@ -64,14 +64,12 @@ msgid "Plugged In"
msgstr "電源接続時"

#: src/MainView.vala:258 src/Plug.vala:79
#, fuzzy
#| msgid "Automatically adjust brightness:"
msgid "Automatically Save Power"
msgstr "明るさを自動調整:"
msgstr "自動的に電力消費を抑える"

#: src/MainView.vala:260
msgid "Power Saver mode will be used when battery is low"
msgstr ""
msgstr "電力消費を抑えるモードは、バッテリー残量が低下した際に適用されます"

#: src/MainView.vala:266
msgid "On Battery"
Expand Down Expand Up @@ -192,10 +190,8 @@ msgid "Prompt to shutdown"
msgstr "シャットダウンの確認"

#: src/Widgets/PowerModeButton.vala:60
#, fuzzy
#| msgid "Power Saver"
msgid "Power Mode"
msgstr "省電力"
msgstr "電力モード"

#: src/Widgets/PowerModeButton.vala:68
msgid "Power Saver"
Expand Down
19 changes: 8 additions & 11 deletions po/nl.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ msgstr ""
"Project-Id-Version: maya\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-02-10 02:17+0000\n"
"PO-Revision-Date: 2022-05-23 00:21+0000\n"
"PO-Revision-Date: 2024-02-10 18:59+0000\n"
"Last-Translator: Dennis ten Hoove <dennistenhoove@protonmail.com>\n"
"Language-Team: Dutch <https://l10n.elementary.io/projects/switchboard/"
"switchboard-plug-power/nl/>\n"
"Language-Team: Dutch <https://l10n.elementary.io/projects/switchboard/power/"
"nl/>\n"
"Language: nl\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.4.2\n"
"X-Generator: Weblate 5.0.2\n"
"X-Launchpad-Export-Date: 2016-11-21 05:42+0000\n"

#: data/power.policy.in:10
Expand Down Expand Up @@ -70,14 +70,13 @@ msgid "Plugged In"
msgstr "Aangesloten"

#: src/MainView.vala:258 src/Plug.vala:79
#, fuzzy
#| msgid "Automatically adjust brightness:"
msgid "Automatically Save Power"
msgstr "Pas de helderheid automatisch aan:"
msgstr "Automatisch stroom besparen"

#: src/MainView.vala:260
msgid "Power Saver mode will be used when battery is low"
msgstr ""
"Energiebesparende modus zal worden gebruikt als het batterijniveau laag is"

#: src/MainView.vala:266
msgid "On Battery"
Expand Down Expand Up @@ -200,14 +199,12 @@ msgid "Prompt to shutdown"
msgstr "Vragen om uit te schakelen"

#: src/Widgets/PowerModeButton.vala:60
#, fuzzy
#| msgid "Power Saver"
msgid "Power Mode"
msgstr "Energiebesparing"
msgstr "Energiemodus"

#: src/Widgets/PowerModeButton.vala:68
msgid "Power Saver"
msgstr "Energiebesparing"
msgstr "Energie besparen"

#: src/Widgets/PowerModeButton.vala:82
msgid "Balanced"
Expand Down
11 changes: 5 additions & 6 deletions po/ru.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ msgstr ""
"Project-Id-Version: maya\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-02-10 02:17+0000\n"
"PO-Revision-Date: 2024-02-10 02:17+0000\n"
"PO-Revision-Date: 2024-02-10 18:59+0000\n"
"Last-Translator: кубик круглый <megarainbow29@gmail.com>\n"
"Language-Team: Russian <https://l10n.elementary.io/projects/switchboard/"
"power/ru/>\n"
"Language: ru\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
"X-Generator: Weblate 5.0.2\n"
"X-Launchpad-Export-Date: 2016-12-02 05:21+0000\n"

Expand Down Expand Up @@ -70,14 +70,13 @@ msgid "Plugged In"
msgstr "На зарядке"

#: src/MainView.vala:258 src/Plug.vala:79
#, fuzzy
#| msgid "Automatically adjust brightness:"
msgid "Automatically Save Power"
msgstr "Автоматическая регулировка яркости:"
msgstr "Автоматическая экономия энергии"

#: src/MainView.vala:260
msgid "Power Saver mode will be used when battery is low"
msgstr ""
"Режим экономии энергии будет использоваться при низком уровне заряда батареи"

#: src/MainView.vala:266
msgid "On Battery"
Expand Down
103 changes: 103 additions & 0 deletions src/Device.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* SPDX-License-Identifier: GPL-2.0-or-later
* SPDX-FileCopyrightText: 2024 elementary, Inc. (https://elementary.io)
*/

[DBus (name = "org.freedesktop.UPower.Device")]
public interface Power.UpowerDevice : DBusProxy {
public signal void changed ();
public abstract bool is_present { owned get; }
public abstract bool online { owned get; }
public abstract bool power_supply { owned get; }
public abstract double percentage { owned get; }
public abstract void refresh () throws Error;
public abstract Device.State state { owned get; }
[DBus (name = "Type")]
public abstract Device.Type device_type { owned get; }
}

public class Power.Device : Object {
private const string UPOWER_NAME = "org.freedesktop.UPower";

[CCode (type_signature = "u")]
public enum State {
UNKNOWN = 0,
CHARGING = 1,
DISCHARGING = 2,
EMPTY = 3,
FULLY_CHARGED = 4,
PENDING_CHARGE = 5,
PENDING_DISCHARGE = 6;

public string to_string () {
switch (this) {
case CHARGING:
return _("Charging");
case DISCHARGING:
return _("Using battery power");
case EMPTY:
return _("Empty");
case FULLY_CHARGED:
return _("Fully charged");
case PENDING_CHARGE:
return _("Waiting to charge");
case PENDING_DISCHARGE:
return _("Waiting to use battery power");
default:
return _("Unknown");
}
}
}

[CCode (type_signature = "u")]
public enum Type {
UNKNOWN = 0,
LINE_POWER = 1,
BATTERY = 2,
UPS = 3,
MONITOR = 4,
MOUSE = 5,
KEYBOARD = 6,
PDA = 7,
PHONE = 8,
MEDIA_PLAYER = 9,
TABLET = 10,
COMPUTER = 11,
GAMING_INPUT = 12,
PEN = 13
}

public string path { get; construct; }
public double percentage { get; private set; default = -1; }
public State state { get; private set; default = UNKNOWN; }
public Type device_type { get; private set; default = UNKNOWN; }

private UpowerDevice upower_device;

public Device (string path) {
Object (path: path);
}

construct {
try {
upower_device = Bus.get_proxy_sync (
SYSTEM,
UPOWER_NAME,
path,
GET_INVALIDATED_PROPERTIES
);

device_type = upower_device.device_type;

update_properties ();
upower_device.g_properties_changed.connect (update_properties);
} catch (IOError e) {
critical (e.message);
}
}

private void update_properties () {
percentage = upower_device.percentage;
state = upower_device.state;
}
}
12 changes: 0 additions & 12 deletions src/Interfaces.vala
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,6 @@ namespace Power {
public abstract int brightness {get; set; }
}

[DBus (name = "org.freedesktop.UPower.Device")]
interface UpowerDevice : Object {
public signal void changed ();
public abstract void refresh () throws Error;
public abstract bool online { owned get; }
public abstract bool power_supply { owned get; }
public abstract bool is_present { owned get; }
[DBus (name = "Type")]
public abstract uint device_type { owned get; }
}


[DBus (name = "org.freedesktop.UPower")]
interface Upower : Object {
public signal void changed ();
Expand Down
27 changes: 9 additions & 18 deletions src/MainView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,7 @@ public class Power.MainView : Switchboard.SettingsPage {
row_spacing = 12
};

if (power_manager.has_battery ()) {
var wingpanel_power_settings = new GLib.Settings ("io.elementary.desktop.wingpanel.power");

var show_percent_label = new Gtk.Label (_("Show battery percentage in Panel:")) {
halign = Gtk.Align.END,
xalign = 1
};

var show_percent_switch = new Gtk.Switch () {
halign = Gtk.Align.START
};
wingpanel_power_settings.bind ("show-percentage", show_percent_switch, "active", SettingsBindFlags.DEFAULT);

main_grid.attach (show_percent_label, 0, 0);
main_grid.attach (show_percent_switch, 1, 0);
}

if (screen.brightness != -1) {
if (bscreen.brightness != -1) {
var brightness_label = new Gtk.Label (_("Display brightness:")) {
halign = Gtk.Align.END,
xalign = 1
Expand Down Expand Up @@ -306,6 +289,14 @@ public class Power.MainView : Switchboard.SettingsPage {

var box = new Gtk.Box (VERTICAL, 12);
box.append (infobar);
if (power_manager.has_battery ()) {
var battery_box = new BatteryBox () {
margin_bottom = 12
};

box.append (battery_box);
}

box.append (main_grid);

child = box;
Expand Down
35 changes: 19 additions & 16 deletions src/PowerManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,24 @@ public class Power.PowerManager : Object {
return instance.once (() => { return new PowerManager (); });
}

public HashTable<string, Device> devices { get; private set; }

private Upower? upower;

construct {
devices = new HashTable<string, Device> (str_hash, str_equal);

try {
upower = Bus.get_proxy_sync (SYSTEM, UPOWER_NAME, UPOWER_PATH);

try {
foreach (unowned var path in upower.enumerate_devices ()) {
var device_path = path.to_string ();
devices[device_path] = new Device (device_path);
}
} catch (Error e) {
critical ("acpi couldn't get upower devices: %s", e.message);
}
} catch (Error e) {
critical ("Connecting to UPower bus failed: %s", e.message);
}
Expand All @@ -27,24 +40,14 @@ public class Power.PowerManager : Object {
return true;
};

try {
foreach (unowned var path in upower.enumerate_devices ()) {
UpowerDevice device = Bus.get_proxy_sync (
SYSTEM,
UPOWER_NAME,
path.to_string (),
GET_INVALIDATED_PROPERTIES
);

if (device != null && device.device_type == 2 && device.is_present) {
return true;
}
var has_battery = false;
devices.foreach ((path, device) => {
if (device.device_type == BATTERY) {
has_battery = true;
}
} catch (Error e) {
critical ("acpi couldn't get upower devices: %s", e.message);
}
});

return false;
return has_battery;
}

public bool on_battery () {
Expand Down
Loading

0 comments on commit 0ad7384

Please sign in to comment.