# HG changeset patch # User Guido Berhoerster # Date 1530477491 -7200 # Node ID 63347002d746f4540498f01fbb5994daa3bd1f70 # Parent b2f6b6b25703df679d5923432436cba0c478e86e Simplify PkuiBackend Make the "check-interval" property construct-only since it is never changed at runtime and schedule the first check for updates in the "constructed" method. Remove unused property get methods. Destroy PkClient and remove periodic check in the "dispose" method. diff -r b2f6b6b25703 -r 63347002d746 pkui-backend.c --- a/pkui-backend.c Wed Apr 18 13:20:52 2018 +0200 +++ b/pkui-backend.c Sun Jul 01 22:38:11 2018 +0200 @@ -74,36 +74,8 @@ switch (property_id) { case PROP_STARTUP_DELAY: self->priv->startup_delay = g_value_get_uint(value); - - if (self->priv->periodic_check_id != 0) { - g_source_remove(self->priv->periodic_check_id); - } - self->priv->periodic_check_id = - g_timeout_add_seconds(self->priv->startup_delay, - (GSourceFunc)periodic_check, self); - break; case PROP_CHECK_INTERVAL: self->priv->check_interval = g_value_get_uint(value); - - /* - * reschedule only if the first run has been completed and - * checks are currently not inibited, otherwise the new - * interval will be picked up anyway - */ - if (!self->priv->inhibit_check && self->priv->last_check > 0) { - time_to_check = g_get_real_time() - - self->priv->last_check; - if (time_to_check <= 0) - pkui_backend_check_now(self); - else { - if (self->priv->periodic_check_id != 0) { - g_source_remove(self->priv->periodic_check_id); - } - self->priv->periodic_check_id = - g_timeout_add_seconds(time_to_check, - periodic_check, self); - } - } break; case PROP_INHIBIT_CHECK: inhibit_check = g_value_get_boolean(value); @@ -161,14 +133,30 @@ } static void -pkui_backend_finalize(GObject *gobject) +pkui_backend_constructed(GObject *gobject) { PkuiBackend *self = PKUI_BACKEND(gobject); - if (self->priv->pk_client != NULL) - g_object_unref(self->priv->pk_client); + self->priv->periodic_check_id = + g_timeout_add_seconds(self->priv->startup_delay, + (GSourceFunc)periodic_check, self); +} + +static void +pkui_backend_dispose(GObject *gobject) +{ + PkuiBackend *self = PKUI_BACKEND(gobject); - G_OBJECT_CLASS(pkui_backend_parent_class)->finalize(gobject); + if (self->priv->pk_client != NULL) { + g_clear_object(&self->priv->pk_client); + } + + if (self->priv->periodic_check_id != 0) { + g_source_remove(self->priv->periodic_check_id); + self->priv->periodic_check_id = 0; + } + + G_OBJECT_CLASS(pkui_backend_parent_class)->dispose(gobject); } static void @@ -179,7 +167,8 @@ gobject_class->set_property = pkui_backend_set_property; gobject_class->get_property = pkui_backend_get_property; - gobject_class->finalize = pkui_backend_finalize; + gobject_class->constructed = pkui_backend_constructed; + gobject_class->dispose = pkui_backend_dispose; pspec = g_param_spec_uint("updates-normal", "Normal updates", "Number of normal package updates", 0, G_MAXUINT, 0, @@ -202,7 +191,7 @@ pspec = g_param_spec_uint("check-interval", "Check interval", "Interval in seconds for checking for new package updates", 1, - G_MAXUINT, 86400, G_PARAM_READWRITE | G_PARAM_CONSTRUCT); + G_MAXUINT, 86400, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); g_object_class_install_property(gobject_class, PROP_CHECK_INTERVAL, pspec); @@ -226,12 +215,6 @@ self->priv = PKUI_BACKEND_GET_PRIVATE(self); self->priv->pk_client = pk_client_new(); - self->priv->updates_normal = 0; - self->priv->updates_important = 0; - self->priv->periodic_check_id = - g_timeout_add_seconds(self->priv->startup_delay, - (GSourceFunc)periodic_check, self); - self->priv->last_check = 0; } static gboolean @@ -378,39 +361,6 @@ return (inhibit_check); } -guint -pkui_backend_get_startup_interval(PkuiBackend *self) -{ - guint startup_interval; - - g_return_val_if_fail(PKUI_IS_BACKEND(self), 0); - - g_object_get(G_OBJECT(self), "startup-interval", &startup_interval, - NULL); - - return (startup_interval); -} - -void -pkui_backend_set_check_interval(PkuiBackend *self, guint check_interval) -{ - g_return_if_fail(PKUI_IS_BACKEND(self)); - - g_object_set(G_OBJECT(self), "check-interval", check_interval, NULL); -} - -guint -pkui_backend_get_check_interval(PkuiBackend *self) -{ - guint check_interval; - - g_return_val_if_fail(PKUI_IS_BACKEND(self), 0); - - g_object_get(G_OBJECT(self), "check-interval", &check_interval, NULL); - - return (check_interval); -} - void pkui_backend_check_now(PkuiBackend *self) { diff -r b2f6b6b25703 -r 63347002d746 pkui-backend.h --- a/pkui-backend.h Wed Apr 18 13:20:52 2018 +0200 +++ b/pkui-backend.h Sun Jul 01 22:38:11 2018 +0200 @@ -60,10 +60,6 @@ void pkui_backend_set_inhibit_check(PkuiBackend *self, gboolean inhibit_check); gboolean pkui_backend_get_inhibit_check(PkuiBackend *self); -void pkui_backend_set_check_interval(PkuiBackend *self, - guint check_interval); -guint pkui_backend_get_check_interval(PkuiBackend *self); -guint pkui_backend_get_startup_interval(PkuiBackend *self); void pkui_backend_check_now(PkuiBackend *self); G_END_DECLS