Commit 1845d1ed authored by Julian Sparber's avatar Julian Sparber

BatteryInfo: drop private data for gobject

Since the BatteryInfo is a final it can't be subclassed, therefore it
doesn't need private data.
parent f0a582d3
Pipeline #50279 passed with stages
in 8 minutes and 51 seconds
......@@ -21,39 +21,34 @@
* @Title: PhoshBatteryInfo
*/
typedef struct {
typedef struct _PhoshBatteryInfo {
GtkImage parent;
UpClient *upower;
UpDevice *device;
GtkImage *icon;
gint size;
guint update_icon_id;
} PhoshBatteryInfoPrivate;
typedef struct _PhoshBatteryInfo {
GtkImage parent;
} PhoshBatteryInfo;
G_DEFINE_TYPE_WITH_PRIVATE (PhoshBatteryInfo, phosh_battery_info, GTK_TYPE_IMAGE)
G_DEFINE_TYPE (PhoshBatteryInfo, phosh_battery_info, GTK_TYPE_IMAGE)
static void
update_icon (PhoshBatteryInfo *self, gpointer unused)
{
PhoshBatteryInfoPrivate *priv;
g_autofree gchar *icon_name = NULL;
g_debug ("Updating battery icon");
g_return_if_fail (PHOSH_IS_BATTERY_INFO (self));
priv = phosh_battery_info_get_instance_private (self);
g_return_if_fail (priv->device);
g_return_if_fail (self->device);
g_object_get (priv->device, "icon-name", &icon_name, NULL);
g_object_get (self->device, "icon-name", &icon_name, NULL);
if (icon_name)
gtk_image_set_from_icon_name (GTK_IMAGE (self), icon_name, priv->size);
gtk_image_set_from_icon_name (GTK_IMAGE (self), icon_name, self->size);
}
......@@ -61,23 +56,22 @@ static void
setup_display_device (PhoshBatteryInfo *self)
{
GError *err = NULL;
PhoshBatteryInfoPrivate *priv = phosh_battery_info_get_instance_private (self);
priv->upower = up_client_new_full (NULL, &err);
if (priv->upower == NULL) {
self->upower = up_client_new_full (NULL, &err);
if (self->upower == NULL) {
g_warning ("Failed to connect to upowerd: %s", err->message);
g_clear_error (&err);
return;
}
/* TODO: this is a oversimplified sync call */
priv->device = up_client_get_display_device (priv->upower);
if (priv->device == NULL) {
self->device = up_client_get_display_device (self->upower);
if (self->device == NULL) {
g_warning ("Failed to get upowerd display device");
return;
}
priv->update_icon_id = g_signal_connect_swapped (priv->device,
self->update_icon_id = g_signal_connect_swapped (self->device,
"notify::icon-name",
G_CALLBACK (update_icon),
self);
......@@ -88,12 +82,11 @@ static void
phosh_battery_info_constructed (GObject *object)
{
PhoshBatteryInfo *self = PHOSH_BATTERY_INFO (object);
PhoshBatteryInfoPrivate *priv = phosh_battery_info_get_instance_private (self);
G_OBJECT_CLASS (phosh_battery_info_parent_class)->constructed (object);
setup_display_device (self);
if (priv->device)
if (self->device)
update_icon (self, NULL);
}
......@@ -101,16 +94,16 @@ phosh_battery_info_constructed (GObject *object)
static void
phosh_battery_info_dispose (GObject *object)
{
PhoshBatteryInfoPrivate *priv = phosh_battery_info_get_instance_private (PHOSH_BATTERY_INFO(object));
PhoshBatteryInfo *self = PHOSH_BATTERY_INFO (object);
if (priv->device) {
g_signal_handler_disconnect (priv->device, priv->update_icon_id);
priv->update_icon_id = 0;
g_clear_object (&priv->device);
if (self->device) {
g_signal_handler_disconnect (self->device, self->update_icon_id);
self->update_icon_id = 0;
g_clear_object (&self->device);
}
if (priv->upower)
g_clear_object (&priv->upower);
if (self->upower)
g_clear_object (&self->upower);
G_OBJECT_CLASS (phosh_battery_info_parent_class)->dispose (object);
}
......@@ -129,10 +122,8 @@ phosh_battery_info_class_init (PhoshBatteryInfoClass *klass)
static void
phosh_battery_info_init (PhoshBatteryInfo *self)
{
PhoshBatteryInfoPrivate *priv = phosh_battery_info_get_instance_private (self);
/* TODO: make scalable? */
priv->size = BATTERY_INFO_DEFAULT_ICON_SIZE;
self->size = BATTERY_INFO_DEFAULT_ICON_SIZE;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment