projects/pk-update-icon

changeset 56:63347002d746

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.
author Guido Berhoerster <guido+pk-update-icon@berhoerster.name>
date Sun Jul 01 22:38:11 2018 +0200 (23 months ago)
parents b2f6b6b25703
children 75249ce94ca0
files pkui-backend.c pkui-backend.h
line diff
     1.1 --- a/pkui-backend.c	Wed Apr 18 13:20:52 2018 +0200
     1.2 +++ b/pkui-backend.c	Sun Jul 01 22:38:11 2018 +0200
     1.3 @@ -74,36 +74,8 @@
     1.4  	switch (property_id) {
     1.5  	case PROP_STARTUP_DELAY:
     1.6  		self->priv->startup_delay = g_value_get_uint(value);
     1.7 -
     1.8 -		if (self->priv->periodic_check_id != 0) {
     1.9 -			g_source_remove(self->priv->periodic_check_id);
    1.10 -		}
    1.11 -		self->priv->periodic_check_id =
    1.12 -		    g_timeout_add_seconds(self->priv->startup_delay,
    1.13 -		    (GSourceFunc)periodic_check, self);
    1.14 -		break;
    1.15  	case PROP_CHECK_INTERVAL:
    1.16  		self->priv->check_interval = g_value_get_uint(value);
    1.17 -
    1.18 -		/*
    1.19 -		 * reschedule only if the first run has been completed and
    1.20 -		 * checks are currently not inibited, otherwise the new
    1.21 -		 * interval will be picked up anyway
    1.22 -		 */
    1.23 -		if (!self->priv->inhibit_check && self->priv->last_check > 0) {
    1.24 -			time_to_check = g_get_real_time() -
    1.25 -			    self->priv->last_check;
    1.26 -			if (time_to_check <= 0)
    1.27 -				pkui_backend_check_now(self);
    1.28 -			else {
    1.29 -				if (self->priv->periodic_check_id != 0) {
    1.30 -					g_source_remove(self->priv->periodic_check_id);
    1.31 -				}
    1.32 -				self->priv->periodic_check_id =
    1.33 -				    g_timeout_add_seconds(time_to_check,
    1.34 -				    periodic_check, self);
    1.35 -			}
    1.36 -		}
    1.37  		break;
    1.38  	case PROP_INHIBIT_CHECK:
    1.39  		inhibit_check = g_value_get_boolean(value);
    1.40 @@ -161,14 +133,30 @@
    1.41  }
    1.42  
    1.43  static void
    1.44 -pkui_backend_finalize(GObject *gobject)
    1.45 +pkui_backend_constructed(GObject *gobject)
    1.46  {
    1.47  	PkuiBackend	*self = PKUI_BACKEND(gobject);
    1.48  
    1.49 -	if (self->priv->pk_client != NULL)
    1.50 -		g_object_unref(self->priv->pk_client);
    1.51 +	self->priv->periodic_check_id =
    1.52 +	    g_timeout_add_seconds(self->priv->startup_delay,
    1.53 +	    (GSourceFunc)periodic_check, self);
    1.54 +}
    1.55  
    1.56 -	G_OBJECT_CLASS(pkui_backend_parent_class)->finalize(gobject);
    1.57 +static void
    1.58 +pkui_backend_dispose(GObject *gobject)
    1.59 +{
    1.60 +	PkuiBackend	*self = PKUI_BACKEND(gobject);
    1.61 +
    1.62 +	if (self->priv->pk_client != NULL) {
    1.63 +		g_clear_object(&self->priv->pk_client);
    1.64 +	}
    1.65 +
    1.66 +	if (self->priv->periodic_check_id != 0) {
    1.67 +		g_source_remove(self->priv->periodic_check_id);
    1.68 +		self->priv->periodic_check_id = 0;
    1.69 +	}
    1.70 +
    1.71 +	G_OBJECT_CLASS(pkui_backend_parent_class)->dispose(gobject);
    1.72  }
    1.73  
    1.74  static void
    1.75 @@ -179,7 +167,8 @@
    1.76  
    1.77  	gobject_class->set_property = pkui_backend_set_property;
    1.78  	gobject_class->get_property = pkui_backend_get_property;
    1.79 -	gobject_class->finalize = pkui_backend_finalize;
    1.80 +	gobject_class->constructed = pkui_backend_constructed;
    1.81 +	gobject_class->dispose = pkui_backend_dispose;
    1.82  
    1.83  	pspec = g_param_spec_uint("updates-normal", "Normal updates",
    1.84  	    "Number of normal package updates", 0, G_MAXUINT, 0,
    1.85 @@ -202,7 +191,7 @@
    1.86  
    1.87  	pspec = g_param_spec_uint("check-interval", "Check interval",
    1.88  	    "Interval in seconds for checking for new package updates", 1,
    1.89 -	    G_MAXUINT, 86400, G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
    1.90 +	    G_MAXUINT, 86400, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
    1.91  	g_object_class_install_property(gobject_class, PROP_CHECK_INTERVAL,
    1.92  	    pspec);
    1.93  
    1.94 @@ -226,12 +215,6 @@
    1.95  	self->priv = PKUI_BACKEND_GET_PRIVATE(self);
    1.96  
    1.97  	self->priv->pk_client = pk_client_new();
    1.98 -	self->priv->updates_normal = 0;
    1.99 -	self->priv->updates_important = 0;
   1.100 -	self->priv->periodic_check_id =
   1.101 -	    g_timeout_add_seconds(self->priv->startup_delay,
   1.102 -	    (GSourceFunc)periodic_check, self);
   1.103 -	self->priv->last_check = 0;
   1.104  }
   1.105  
   1.106  static gboolean
   1.107 @@ -378,39 +361,6 @@
   1.108  	return (inhibit_check);
   1.109  }
   1.110  
   1.111 -guint
   1.112 -pkui_backend_get_startup_interval(PkuiBackend *self)
   1.113 -{
   1.114 -	guint	startup_interval;
   1.115 -
   1.116 -	g_return_val_if_fail(PKUI_IS_BACKEND(self), 0);
   1.117 -
   1.118 -	g_object_get(G_OBJECT(self), "startup-interval", &startup_interval,
   1.119 -	    NULL);
   1.120 -
   1.121 -	return (startup_interval);
   1.122 -}
   1.123 -
   1.124 -void
   1.125 -pkui_backend_set_check_interval(PkuiBackend *self, guint check_interval)
   1.126 -{
   1.127 -	g_return_if_fail(PKUI_IS_BACKEND(self));
   1.128 -
   1.129 -	g_object_set(G_OBJECT(self), "check-interval", check_interval, NULL);
   1.130 -}
   1.131 -
   1.132 -guint
   1.133 -pkui_backend_get_check_interval(PkuiBackend *self)
   1.134 -{
   1.135 -	guint	check_interval;
   1.136 -
   1.137 -	g_return_val_if_fail(PKUI_IS_BACKEND(self), 0);
   1.138 -
   1.139 -	g_object_get(G_OBJECT(self), "check-interval", &check_interval, NULL);
   1.140 -
   1.141 -	return (check_interval);
   1.142 -}
   1.143 -
   1.144  void
   1.145  pkui_backend_check_now(PkuiBackend *self)
   1.146  {
     2.1 --- a/pkui-backend.h	Wed Apr 18 13:20:52 2018 +0200
     2.2 +++ b/pkui-backend.h	Sun Jul 01 22:38:11 2018 +0200
     2.3 @@ -60,10 +60,6 @@
     2.4  void		pkui_backend_set_inhibit_check(PkuiBackend *self,
     2.5      gboolean inhibit_check);
     2.6  gboolean	pkui_backend_get_inhibit_check(PkuiBackend *self);
     2.7 -void		pkui_backend_set_check_interval(PkuiBackend *self,
     2.8 -    guint check_interval);
     2.9 -guint		pkui_backend_get_check_interval(PkuiBackend *self);
    2.10 -guint		pkui_backend_get_startup_interval(PkuiBackend *self);
    2.11  void		pkui_backend_check_now(PkuiBackend *self);
    2.12  
    2.13  G_END_DECLS