diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/device-provider-upower.c | 14 | ||||
-rw-r--r-- | src/device.c | 62 | ||||
-rw-r--r-- | src/device.h | 7 | ||||
-rw-r--r-- | src/service.c | 12 | ||||
-rw-r--r-- | src/testing.c | 3 |
5 files changed, 84 insertions, 14 deletions
diff --git a/src/device-provider-upower.c b/src/device-provider-upower.c index f9b5e18..dbbe5f1 100644 --- a/src/device-provider-upower.c +++ b/src/device-provider-upower.c @@ -1,8 +1,10 @@ /* * Copyright 2013 Canonical Ltd. + * Copyright 2023 Robert Tari * * Authors: * Charles Kerr <charles.kerr@canonical.com> + * Robert Tari <robert@tari.in> * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published @@ -108,6 +110,7 @@ on_get_all_response (GObject * o, GAsyncResult * res, gpointer gdata) else { guint32 kind = 0; + gchar *model; guint32 state = 0; gdouble percentage = 0; gint64 time_to_empty = 0; @@ -119,6 +122,7 @@ on_get_all_response (GObject * o, GAsyncResult * res, gpointer gdata) GVariant * dict = g_variant_get_child_value (response, 0); g_variant_lookup (dict, "Type", "u", &kind); + g_variant_lookup (dict, "Model", "s", &model); g_variant_lookup (dict, "State", "u", &state); g_variant_lookup (dict, "Percentage", "d", &percentage); g_variant_lookup (dict, "TimeToEmpty", "x", &time_to_empty); @@ -129,6 +133,7 @@ on_get_all_response (GObject * o, GAsyncResult * res, gpointer gdata) if ((device = g_hash_table_lookup (p->devices, data->path))) { g_object_set (device, INDICATOR_POWER_DEVICE_KIND, (gint)kind, + INDICATOR_POWER_DEVICE_MODEL, model, INDICATOR_POWER_DEVICE_STATE, (gint)state, INDICATOR_POWER_DEVICE_OBJECT_PATH, data->path, INDICATOR_POWER_DEVICE_PERCENTAGE, percentage, @@ -140,6 +145,7 @@ on_get_all_response (GObject * o, GAsyncResult * res, gpointer gdata) { device = indicator_power_device_new (data->path, kind, + model, percentage, state, (time_t)time, @@ -344,6 +350,14 @@ on_device_properties_changed(GDBusConnection * connection G_GNUC_UNUSED, NULL); changed = TRUE; } + else if (!g_strcmp0(key, "Model")) + { + const gchar *s = g_variant_get_string(value, NULL); + g_object_set(device, + INDICATOR_POWER_DEVICE_MODEL, s, + NULL); + changed = TRUE; + } else if (!g_strcmp0(key, "State")) { const guint32 u = g_variant_get_uint32(value); diff --git a/src/device.c b/src/device.c index a1c4d14..a373981 100644 --- a/src/device.c +++ b/src/device.c @@ -35,6 +35,7 @@ License along with this library. If not, see struct _IndicatorPowerDevicePrivate { UpDeviceKind kind; + gchar *model; UpDeviceState state; gchar * object_path; gdouble percentage; @@ -52,6 +53,7 @@ struct _IndicatorPowerDevicePrivate enum { PROP_0, PROP_KIND, + PROP_MODEL, PROP_STATE, PROP_OBJECT_PATH, PROP_PERCENTAGE, @@ -91,6 +93,12 @@ indicator_power_device_class_init (IndicatorPowerDeviceClass *klass) UP_DEVICE_KIND_UNKNOWN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + properties[PROP_MODEL] = g_param_spec_string (INDICATOR_POWER_DEVICE_MODEL, + "model", + "The device's model", + NULL, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + properties[PROP_STATE] = g_param_spec_int (INDICATOR_POWER_DEVICE_STATE, "state", "The device's UpDeviceState", @@ -135,6 +143,7 @@ indicator_power_device_init (IndicatorPowerDevice *self) priv = indicator_power_device_get_instance_private(self); priv->kind = UP_DEVICE_KIND_UNKNOWN; + priv->model = NULL; priv->state = UP_DEVICE_STATE_UNKNOWN; priv->object_path = NULL; priv->percentage = 0.0; @@ -182,6 +191,10 @@ get_property (GObject * o, guint prop_id, GValue * value, GParamSpec * pspec) g_value_set_int (value, priv->kind); break; + case PROP_MODEL: + g_value_set_string (value, priv->model); + break; + case PROP_STATE: g_value_set_int (value, priv->state); break; @@ -220,6 +233,11 @@ set_property (GObject * o, guint prop_id, const GValue * value, GParamSpec * psp p->kind = (UpDeviceKind) g_value_get_int (value); break; + case PROP_MODEL: + g_free (p->model); + p->model = g_value_dup_string (value); + break; + case PROP_STATE: p->state = (UpDeviceState) g_value_get_int (value); break; @@ -280,6 +298,16 @@ indicator_power_device_get_kind (const IndicatorPowerDevice * device) return device->priv->kind; } +const gchar * +indicator_power_device_get_model (const IndicatorPowerDevice * device) +{ + /* LCOV_EXCL_START */ + g_return_val_if_fail (INDICATOR_IS_POWER_DEVICE(device), NULL); + /* LCOV_EXCL_STOP */ + + return device->priv->model; +} + UpDeviceState indicator_power_device_get_state (const IndicatorPowerDevice * device) { @@ -880,16 +908,25 @@ time_is_relevant (const IndicatorPowerDevice * device) */ static char * get_menuitem_text (const IndicatorPowerDevice * device, - gboolean accessible) + gboolean accessible, gboolean bModelName) { char * str = NULL; const IndicatorPowerDevicePrivate * p = device->priv; - const char * kind_str = device_kind_to_localised_string (p->kind); + const char * sLabel = NULL; + + if (bModelName) + { + sLabel = p->model; + } + else + { + sLabel = device_kind_to_localised_string (p->kind); + } if (p->state == UP_DEVICE_STATE_FULLY_CHARGED) { /* TRANSLATORS: example: "battery (charged)" */ - str = g_strdup_printf (_("%s (charged)"), kind_str); + str = g_strdup_printf (_("%s (charged)"), sLabel); } else { @@ -906,11 +943,11 @@ get_menuitem_text (const IndicatorPowerDevice * device, if (time_str && *time_str) { /* TRANSLATORS: example: "battery (time remaining)" */ - str = g_strdup_printf (_("%s (%s)"), kind_str, time_str); + str = g_strdup_printf (_("%s (%s)"), sLabel, time_str); } else { - str = g_strdup (kind_str); + str = g_strdup (sLabel); } g_free (time_str); @@ -920,11 +957,11 @@ get_menuitem_text (const IndicatorPowerDevice * device, } char * -indicator_power_device_get_readable_text (const IndicatorPowerDevice * device) +indicator_power_device_get_readable_text (const IndicatorPowerDevice * device, gboolean bModelName) { g_return_val_if_fail (INDICATOR_IS_POWER_DEVICE(device), NULL); - return get_menuitem_text (device, FALSE); + return get_menuitem_text (device, FALSE, bModelName); } char * @@ -932,7 +969,7 @@ indicator_power_device_get_accessible_text (const IndicatorPowerDevice * device) { g_return_val_if_fail (INDICATOR_IS_POWER_DEVICE(device), NULL); - return get_menuitem_text (device, TRUE); + return get_menuitem_text (device, TRUE, FALSE); } /** @@ -1020,6 +1057,7 @@ indicator_power_device_get_accessible_title (const IndicatorPowerDevice * device IndicatorPowerDevice * indicator_power_device_new (const gchar * object_path, UpDeviceKind kind, + const gchar * model, gdouble percentage, UpDeviceState state, time_t timestamp, @@ -1027,6 +1065,7 @@ indicator_power_device_new (const gchar * object_path, { GObject * o = g_object_new (INDICATOR_POWER_DEVICE_TYPE, INDICATOR_POWER_DEVICE_KIND, kind, + INDICATOR_POWER_DEVICE_MODEL, model, INDICATOR_POWER_DEVICE_STATE, state, INDICATOR_POWER_DEVICE_OBJECT_PATH, object_path, INDICATOR_POWER_DEVICE_PERCENTAGE, percentage, @@ -1039,9 +1078,10 @@ indicator_power_device_new (const gchar * object_path, IndicatorPowerDevice * indicator_power_device_new_from_variant (GVariant * v) { - g_return_val_if_fail (g_variant_is_of_type (v, G_VARIANT_TYPE("(susdutb)")), NULL); + g_return_val_if_fail (g_variant_is_of_type (v, G_VARIANT_TYPE("(sussdutb)")), NULL); UpDeviceKind kind = UP_DEVICE_KIND_UNKNOWN; + const gchar *model = NULL; UpDeviceState state = UP_DEVICE_STATE_UNKNOWN; const gchar * icon = NULL; const gchar * object_path = NULL; @@ -1049,9 +1089,10 @@ indicator_power_device_new_from_variant (GVariant * v) guint64 time = 0; gboolean power_supply = FALSE; - g_variant_get (v, "(&su&sdutb)", + g_variant_get (v, "(&sus&sdutb)", &object_path, &kind, + &model, &icon, &percentage, &state, @@ -1060,6 +1101,7 @@ indicator_power_device_new_from_variant (GVariant * v) return indicator_power_device_new (object_path, kind, + model, percentage, state, (time_t)time, diff --git a/src/device.h b/src/device.h index fa41fe0..d9e9264 100644 --- a/src/device.h +++ b/src/device.h @@ -42,6 +42,7 @@ typedef struct _IndicatorPowerDeviceClass IndicatorPowerDeviceClass; typedef struct _IndicatorPowerDevicePrivate IndicatorPowerDevicePrivate; #define INDICATOR_POWER_DEVICE_KIND "kind" +#define INDICATOR_POWER_DEVICE_MODEL "model" #define INDICATOR_POWER_DEVICE_STATE "state" #define INDICATOR_POWER_DEVICE_OBJECT_PATH "object-path" #define INDICATOR_POWER_DEVICE_PERCENTAGE "percentage" @@ -125,6 +126,7 @@ GType indicator_power_device_get_type (void); IndicatorPowerDevice* indicator_power_device_new (const gchar * object_path, UpDeviceKind kind, + const gchar * model, gdouble percentage, UpDeviceState state, time_t time, @@ -132,12 +134,13 @@ IndicatorPowerDevice* indicator_power_device_new (const gchar * object_path, /** * Convenience wrapper around indicator_power_device_new() - * @variant holds the same args as indicator_power_device_new() in "(susdut)" + * @variant holds the same args as indicator_power_device_new() in "(sussdut)" */ IndicatorPowerDevice* indicator_power_device_new_from_variant (GVariant * variant); UpDeviceKind indicator_power_device_get_kind (const IndicatorPowerDevice * device); +const gchar * indicator_power_device_get_model (const IndicatorPowerDevice * device); UpDeviceState indicator_power_device_get_state (const IndicatorPowerDevice * device); const gchar * indicator_power_device_get_object_path (const IndicatorPowerDevice * device); gdouble indicator_power_device_get_percentage (const IndicatorPowerDevice * device); @@ -148,7 +151,7 @@ GStrv indicator_power_device_get_icon_names (const IndicatorPower GIcon * indicator_power_device_get_gicon (const IndicatorPowerDevice * device, gboolean panel); -char * indicator_power_device_get_readable_text (const IndicatorPowerDevice * device); +char * indicator_power_device_get_readable_text (const IndicatorPowerDevice * device, gboolean bModelName); char * indicator_power_device_get_accessible_text (const IndicatorPowerDevice * device); diff --git a/src/service.c b/src/service.c index 32f8788..bdf4caa 100644 --- a/src/service.c +++ b/src/service.c @@ -517,11 +517,18 @@ create_devices_section (IndicatorPowerService * self, int profile) if (kind == UP_DEVICE_KIND_BATTERY) { - sLabel = g_strdup (_("Charge level")); + if (!ayatana_common_utils_is_lomiri()) + { + sLabel = indicator_power_device_get_readable_text (device, FALSE); + } + else + { + sLabel = g_strdup (_("Charge level")); + } } else { - sLabel = indicator_power_device_get_readable_text (device); + sLabel = indicator_power_device_get_readable_text (device, TRUE); } gchar *sIndicator = NULL; @@ -1418,6 +1425,7 @@ create_totalled_battery_device (const GList * devices) device = indicator_power_device_new (NULL, UP_DEVICE_KIND_BATTERY, + NULL, percent, state, time_left, diff --git a/src/testing.c b/src/testing.c index 0d002a1..3633cfe 100644 --- a/src/testing.c +++ b/src/testing.c @@ -1,5 +1,6 @@ /* * Copyright 2014 Canonical Ltd. + * Copyright 2023 Robert Tari * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License version 3, as published @@ -15,6 +16,7 @@ * * Authors: * Charles Kerr <charles.kerr@canonical.com> + * Robert Tari <robert@tari.in> */ #include "dbus-shared.h" @@ -299,6 +301,7 @@ indicator_power_testing_init (IndicatorPowerTesting * self) p->battery_mock = indicator_power_device_new("/some/path", UP_DEVICE_KIND_BATTERY, + "Some Model", 50.0, UP_DEVICE_STATE_DISCHARGING, 60*30, |