comparison pkui-backend.c @ 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, 01 Jul 2018 22:38:11 +0200
parents 7de92a24e86c
children
comparison
equal deleted inserted replaced
55:b2f6b6b25703 56:63347002d746
72 gint64 time_to_check; 72 gint64 time_to_check;
73 73
74 switch (property_id) { 74 switch (property_id) {
75 case PROP_STARTUP_DELAY: 75 case PROP_STARTUP_DELAY:
76 self->priv->startup_delay = g_value_get_uint(value); 76 self->priv->startup_delay = g_value_get_uint(value);
77
78 if (self->priv->periodic_check_id != 0) {
79 g_source_remove(self->priv->periodic_check_id);
80 }
81 self->priv->periodic_check_id =
82 g_timeout_add_seconds(self->priv->startup_delay,
83 (GSourceFunc)periodic_check, self);
84 break;
85 case PROP_CHECK_INTERVAL: 77 case PROP_CHECK_INTERVAL:
86 self->priv->check_interval = g_value_get_uint(value); 78 self->priv->check_interval = g_value_get_uint(value);
87
88 /*
89 * reschedule only if the first run has been completed and
90 * checks are currently not inibited, otherwise the new
91 * interval will be picked up anyway
92 */
93 if (!self->priv->inhibit_check && self->priv->last_check > 0) {
94 time_to_check = g_get_real_time() -
95 self->priv->last_check;
96 if (time_to_check <= 0)
97 pkui_backend_check_now(self);
98 else {
99 if (self->priv->periodic_check_id != 0) {
100 g_source_remove(self->priv->periodic_check_id);
101 }
102 self->priv->periodic_check_id =
103 g_timeout_add_seconds(time_to_check,
104 periodic_check, self);
105 }
106 }
107 break; 79 break;
108 case PROP_INHIBIT_CHECK: 80 case PROP_INHIBIT_CHECK:
109 inhibit_check = g_value_get_boolean(value); 81 inhibit_check = g_value_get_boolean(value);
110 82
111 /* 83 /*
159 break; 131 break;
160 } 132 }
161 } 133 }
162 134
163 static void 135 static void
164 pkui_backend_finalize(GObject *gobject) 136 pkui_backend_constructed(GObject *gobject)
165 { 137 {
166 PkuiBackend *self = PKUI_BACKEND(gobject); 138 PkuiBackend *self = PKUI_BACKEND(gobject);
167 139
168 if (self->priv->pk_client != NULL) 140 self->priv->periodic_check_id =
169 g_object_unref(self->priv->pk_client); 141 g_timeout_add_seconds(self->priv->startup_delay,
170 142 (GSourceFunc)periodic_check, self);
171 G_OBJECT_CLASS(pkui_backend_parent_class)->finalize(gobject); 143 }
144
145 static void
146 pkui_backend_dispose(GObject *gobject)
147 {
148 PkuiBackend *self = PKUI_BACKEND(gobject);
149
150 if (self->priv->pk_client != NULL) {
151 g_clear_object(&self->priv->pk_client);
152 }
153
154 if (self->priv->periodic_check_id != 0) {
155 g_source_remove(self->priv->periodic_check_id);
156 self->priv->periodic_check_id = 0;
157 }
158
159 G_OBJECT_CLASS(pkui_backend_parent_class)->dispose(gobject);
172 } 160 }
173 161
174 static void 162 static void
175 pkui_backend_class_init(PkuiBackendClass *klass) 163 pkui_backend_class_init(PkuiBackendClass *klass)
176 { 164 {
177 GObjectClass *gobject_class = G_OBJECT_CLASS(klass); 165 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
178 GParamSpec *pspec; 166 GParamSpec *pspec;
179 167
180 gobject_class->set_property = pkui_backend_set_property; 168 gobject_class->set_property = pkui_backend_set_property;
181 gobject_class->get_property = pkui_backend_get_property; 169 gobject_class->get_property = pkui_backend_get_property;
182 gobject_class->finalize = pkui_backend_finalize; 170 gobject_class->constructed = pkui_backend_constructed;
171 gobject_class->dispose = pkui_backend_dispose;
183 172
184 pspec = g_param_spec_uint("updates-normal", "Normal updates", 173 pspec = g_param_spec_uint("updates-normal", "Normal updates",
185 "Number of normal package updates", 0, G_MAXUINT, 0, 174 "Number of normal package updates", 0, G_MAXUINT, 0,
186 G_PARAM_READABLE); 175 G_PARAM_READABLE);
187 g_object_class_install_property(gobject_class, PROP_UPDATES_NORMAL, 176 g_object_class_install_property(gobject_class, PROP_UPDATES_NORMAL,
200 g_object_class_install_property(gobject_class, PROP_STARTUP_DELAY, 189 g_object_class_install_property(gobject_class, PROP_STARTUP_DELAY,
201 pspec); 190 pspec);
202 191
203 pspec = g_param_spec_uint("check-interval", "Check interval", 192 pspec = g_param_spec_uint("check-interval", "Check interval",
204 "Interval in seconds for checking for new package updates", 1, 193 "Interval in seconds for checking for new package updates", 1,
205 G_MAXUINT, 86400, G_PARAM_READWRITE | G_PARAM_CONSTRUCT); 194 G_MAXUINT, 86400, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
206 g_object_class_install_property(gobject_class, PROP_CHECK_INTERVAL, 195 g_object_class_install_property(gobject_class, PROP_CHECK_INTERVAL,
207 pspec); 196 pspec);
208 197
209 pspec = g_param_spec_boolean("inhibit-check", "Inhibit check", 198 pspec = g_param_spec_boolean("inhibit-check", "Inhibit check",
210 "Whether to inhibit checks for new package updates", FALSE, 199 "Whether to inhibit checks for new package updates", FALSE,
224 pkui_backend_init(PkuiBackend *self) 213 pkui_backend_init(PkuiBackend *self)
225 { 214 {
226 self->priv = PKUI_BACKEND_GET_PRIVATE(self); 215 self->priv = PKUI_BACKEND_GET_PRIVATE(self);
227 216
228 self->priv->pk_client = pk_client_new(); 217 self->priv->pk_client = pk_client_new();
229 self->priv->updates_normal = 0;
230 self->priv->updates_important = 0;
231 self->priv->periodic_check_id =
232 g_timeout_add_seconds(self->priv->startup_delay,
233 (GSourceFunc)periodic_check, self);
234 self->priv->last_check = 0;
235 } 218 }
236 219
237 static gboolean 220 static gboolean
238 periodic_check(gpointer data) 221 periodic_check(gpointer data)
239 { 222 {
376 g_object_get(G_OBJECT(self), "inhibit-check", &inhibit_check, NULL); 359 g_object_get(G_OBJECT(self), "inhibit-check", &inhibit_check, NULL);
377 360
378 return (inhibit_check); 361 return (inhibit_check);
379 } 362 }
380 363
381 guint
382 pkui_backend_get_startup_interval(PkuiBackend *self)
383 {
384 guint startup_interval;
385
386 g_return_val_if_fail(PKUI_IS_BACKEND(self), 0);
387
388 g_object_get(G_OBJECT(self), "startup-interval", &startup_interval,
389 NULL);
390
391 return (startup_interval);
392 }
393
394 void
395 pkui_backend_set_check_interval(PkuiBackend *self, guint check_interval)
396 {
397 g_return_if_fail(PKUI_IS_BACKEND(self));
398
399 g_object_set(G_OBJECT(self), "check-interval", check_interval, NULL);
400 }
401
402 guint
403 pkui_backend_get_check_interval(PkuiBackend *self)
404 {
405 guint check_interval;
406
407 g_return_val_if_fail(PKUI_IS_BACKEND(self), 0);
408
409 g_object_get(G_OBJECT(self), "check-interval", &check_interval, NULL);
410
411 return (check_interval);
412 }
413
414 void 364 void
415 pkui_backend_check_now(PkuiBackend *self) 365 pkui_backend_check_now(PkuiBackend *self)
416 { 366 {
417 g_return_if_fail(PKUI_IS_BACKEND(self)); 367 g_return_if_fail(PKUI_IS_BACKEND(self));
418 368