comparison pui-application.c @ 10:adba37525ee5

Notify about required session or system restarts Follow all PackageKit transactions and indicate when a session or system restart is required. Generate enum types with glib-mkenums.
author Guido Berhoerster <guido+pui@berhoerster.name>
date Fri, 06 Jul 2018 14:12:46 +0200
parents 2477a6151087
children f783ba95ec4a
comparison
equal deleted inserted replaced
9:b571e7ade208 10:adba37525ee5
61 static const gchar *icon_names[PUI_STATE_LAST] = { 61 static const gchar *icon_names[PUI_STATE_LAST] = {
62 [PUI_STATE_INITIAL] = "system-software-update", 62 [PUI_STATE_INITIAL] = "system-software-update",
63 [PUI_STATE_UP_TO_DATE] = "system-software-update", 63 [PUI_STATE_UP_TO_DATE] = "system-software-update",
64 [PUI_STATE_NORMAL_UPDATES_AVAILABLE] = "software-update-available", 64 [PUI_STATE_NORMAL_UPDATES_AVAILABLE] = "software-update-available",
65 [PUI_STATE_IMPORTANT_UPDATES_AVAILABLE] = "software-update-urgent", 65 [PUI_STATE_IMPORTANT_UPDATES_AVAILABLE] = "software-update-urgent",
66 [PUI_STATE_SESSION_RESTART_REQUIRED] = "system-log-out",
67 [PUI_STATE_SYSTEM_RESTART_REQUIRED] = "system-reboot",
66 [PUI_STATE_ERROR] = "dialog-warning" 68 [PUI_STATE_ERROR] = "dialog-warning"
67 }; 69 };
68 70
69 static const GOptionEntry cmd_options[] = { 71 static const GOptionEntry cmd_options[] = {
70 { "debug", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL, 72 { "debug", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, NULL,
206 208
207 /* actions */ 209 /* actions */
208 switch (self->state) { 210 switch (self->state) {
209 case PUI_STATE_INITIAL: /* FALLTHGROUGH */ 211 case PUI_STATE_INITIAL: /* FALLTHGROUGH */
210 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */ 212 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */
213 case PUI_STATE_SESSION_RESTART_REQUIRED: /* FALLTHGROUGH */
214 case PUI_STATE_SYSTEM_RESTART_REQUIRED: /* FALLTHGROUGH */
211 case PUI_STATE_ERROR: 215 case PUI_STATE_ERROR:
212 g_simple_action_set_enabled(install_updates_action, FALSE); 216 g_simple_action_set_enabled(install_updates_action, FALSE);
213 break; 217 break;
214 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHROUGH */ 218 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHROUGH */
215 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE: 219 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE:
260 "%u of them are important."), 264 "%u of them are important."),
261 normal_updates + important_updates, 265 normal_updates + important_updates,
262 important_updates); 266 important_updates);
263 } 267 }
264 break; 268 break;
269 case PUI_STATE_SESSION_RESTART_REQUIRED:
270 title = g_strdup(_("Logout Required"));
271 body = g_strdup(_("You need to log out and back in for the "
272 "update to take effect."));
273 break;
274 case PUI_STATE_SYSTEM_RESTART_REQUIRED:
275 title = g_strdup(_("Restart Required"));
276 body = g_strdup(_("The computer has to be restarted for the "
277 "updates to take effect."));
278 break;
265 case PUI_STATE_ERROR: 279 case PUI_STATE_ERROR:
266 title = g_strdup(self->error_message); 280 title = g_strdup(self->error_message);
267 break; 281 break;
268 } 282 }
269 283
274 APP_INDICATOR_STATUS_PASSIVE); 288 APP_INDICATOR_STATUS_PASSIVE);
275 break; 289 break;
276 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */ 290 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */
277 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHGROUGH */ 291 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHGROUGH */
278 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE: /* FALLTHGROUGH */ 292 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE: /* FALLTHGROUGH */
293 case PUI_STATE_SESSION_RESTART_REQUIRED: /* FALLTHGROUGH */
294 case PUI_STATE_SYSTEM_RESTART_REQUIRED: /* FALLTHGROUGH */
279 case PUI_STATE_ERROR: 295 case PUI_STATE_ERROR:
280 app_indicator_set_status(self->indicator, 296 app_indicator_set_status(self->indicator,
281 APP_INDICATOR_STATUS_ACTIVE); 297 APP_INDICATOR_STATUS_ACTIVE);
282 break; 298 break;
283 } 299 }
289 case PUI_STATE_INITIAL: /* FALLTHGROUGH */ 305 case PUI_STATE_INITIAL: /* FALLTHGROUGH */
290 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */ 306 case PUI_STATE_UP_TO_DATE: /* FALLTHGROUGH */
291 case PUI_STATE_ERROR: 307 case PUI_STATE_ERROR:
292 /* withdraw exisiting notification */ 308 /* withdraw exisiting notification */
293 g_application_withdraw_notification(application, 309 g_application_withdraw_notification(application,
294 "package-updates"); 310 "package-updates-or-restart-required");
295 break; 311 break;
296 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHGROUGH */ 312 case PUI_STATE_NORMAL_UPDATES_AVAILABLE: /* FALLTHGROUGH */
297 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE: 313 case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE: /* FALLTHGROUGH */
314 case PUI_STATE_SESSION_RESTART_REQUIRED: /* FALLTHGROUGH */
315 case PUI_STATE_SYSTEM_RESTART_REQUIRED:
298 /* create notification */ 316 /* create notification */
299 notification = g_notification_new(title); 317 notification = g_notification_new(title);
300 g_notification_set_body(notification, body); 318 g_notification_set_body(notification, body);
301 g_notification_set_icon(notification, self->icons[self->state]); 319 g_notification_set_icon(notification, self->icons[self->state]);
302 g_notification_set_priority(notification, 320 g_notification_set_priority(notification,
304 if (g_action_get_enabled(G_ACTION(install_updates_action))) { 322 if (g_action_get_enabled(G_ACTION(install_updates_action))) {
305 g_notification_add_button(notification, 323 g_notification_add_button(notification,
306 _("Install Updates"), 324 _("Install Updates"),
307 "app.install-updates"); 325 "app.install-updates");
308 } 326 }
309 g_application_send_notification(application, "package-updates", 327 g_application_send_notification(application,
310 notification); 328 "package-updates-or-restart-required", notification);
311 break; 329 break;
312 } 330 }
313 331
314 if (notification != NULL) { 332 if (notification != NULL) {
315 g_object_unref(notification); 333 g_object_unref(notification);
324 342
325 static void 343 static void
326 transition_state(PuiApplication *self) 344 transition_state(PuiApplication *self)
327 { 345 {
328 PuiState state = self->state; 346 PuiState state = self->state;
347 PuiRestart restart_type;
329 guint important_updates; 348 guint important_updates;
330 guint normal_updates; 349 guint normal_updates;
331 gchar *old_state; 350 gchar *old_state;
332 gchar *new_state; 351 gchar *new_state;
333 352
339 if (self->error_message != NULL) { 358 if (self->error_message != NULL) {
340 state = PUI_STATE_ERROR; 359 state = PUI_STATE_ERROR;
341 break; 360 break;
342 } 361 }
343 362
344 g_object_get(self->backend, 363 g_object_get(self->backend, "restart-type", &restart_type,
345 "important-updates", &important_updates, 364 "important-updates", &important_updates,
346 "normal-updates", &normal_updates, NULL); 365 "normal-updates", &normal_updates, NULL);
347 if (important_updates > 0) { 366 if (restart_type == PUI_RESTART_SESSION) {
367 state = PUI_STATE_SESSION_RESTART_REQUIRED;
368 } else if (restart_type == PUI_RESTART_SYSTEM) {
369 state = PUI_STATE_SYSTEM_RESTART_REQUIRED;
370 } else if (important_updates > 0) {
348 state = PUI_STATE_IMPORTANT_UPDATES_AVAILABLE; 371 state = PUI_STATE_IMPORTANT_UPDATES_AVAILABLE;
349 } else if (normal_updates > 0) { 372 } else if (normal_updates > 0) {
350 state = PUI_STATE_NORMAL_UPDATES_AVAILABLE; 373 state = PUI_STATE_NORMAL_UPDATES_AVAILABLE;
351 } else { 374 } else {
352 state = PUI_STATE_UP_TO_DATE; 375 state = PUI_STATE_UP_TO_DATE;
353 } 376 }
354 break; 377 break;
378 case PUI_STATE_SESSION_RESTART_REQUIRED:
379 g_object_get(self->backend, "restart-type", &restart_type,
380 NULL);
381 if (restart_type == PUI_RESTART_SYSTEM) {
382 state = PUI_STATE_SYSTEM_RESTART_REQUIRED;
383 }
384 break;
385 case PUI_STATE_SYSTEM_RESTART_REQUIRED: /* FALLTHROUGH */
355 case PUI_STATE_ERROR: 386 case PUI_STATE_ERROR:
356 break; 387 break;
357 } 388 }
358 389
359 if (state != self->state) { 390 if (state != self->state) {