diff 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
line wrap: on
line diff
--- a/pui-application.c	Wed Jul 04 17:08:47 2018 +0200
+++ b/pui-application.c	Fri Jul 06 14:12:46 2018 +0200
@@ -63,6 +63,8 @@
     [PUI_STATE_UP_TO_DATE] = "system-software-update",
     [PUI_STATE_NORMAL_UPDATES_AVAILABLE] = "software-update-available",
     [PUI_STATE_IMPORTANT_UPDATES_AVAILABLE] = "software-update-urgent",
+    [PUI_STATE_SESSION_RESTART_REQUIRED] = "system-log-out",
+    [PUI_STATE_SYSTEM_RESTART_REQUIRED] = "system-reboot",
     [PUI_STATE_ERROR] = "dialog-warning"
 };
 
@@ -208,6 +210,8 @@
 	switch (self->state) {
 	case PUI_STATE_INITIAL:				/* FALLTHGROUGH */
 	case PUI_STATE_UP_TO_DATE:			/* FALLTHGROUGH */
+	case PUI_STATE_SESSION_RESTART_REQUIRED:	/* FALLTHGROUGH */
+	case PUI_STATE_SYSTEM_RESTART_REQUIRED:		/* FALLTHGROUGH */
 	case PUI_STATE_ERROR:
 		g_simple_action_set_enabled(install_updates_action, FALSE);
 		break;
@@ -262,6 +266,16 @@
 			    important_updates);
 		}
 		break;
+	case PUI_STATE_SESSION_RESTART_REQUIRED:
+		title = g_strdup(_("Logout Required"));
+		body = g_strdup(_("You need to log out and back in for the "
+		    "update to take effect."));
+		break;
+	case PUI_STATE_SYSTEM_RESTART_REQUIRED:
+		title = g_strdup(_("Restart Required"));
+		body = g_strdup(_("The computer has to be restarted for the "
+		    "updates to take effect."));
+		break;
 	case PUI_STATE_ERROR:
 		title = g_strdup(self->error_message);
 		break;
@@ -276,6 +290,8 @@
 	case PUI_STATE_UP_TO_DATE:			/* FALLTHGROUGH */
 	case PUI_STATE_NORMAL_UPDATES_AVAILABLE:	/* FALLTHGROUGH */
 	case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE:	/* FALLTHGROUGH */
+	case PUI_STATE_SESSION_RESTART_REQUIRED:	/* FALLTHGROUGH */
+	case PUI_STATE_SYSTEM_RESTART_REQUIRED:		/* FALLTHGROUGH */
 	case PUI_STATE_ERROR:
 		app_indicator_set_status(self->indicator,
 		    APP_INDICATOR_STATUS_ACTIVE);
@@ -291,10 +307,12 @@
 	case PUI_STATE_ERROR:
 		/* withdraw exisiting notification */
 		g_application_withdraw_notification(application,
-		    "package-updates");
+		    "package-updates-or-restart-required");
 		break;
 	case PUI_STATE_NORMAL_UPDATES_AVAILABLE:	/* FALLTHGROUGH */
-	case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE:
+	case PUI_STATE_IMPORTANT_UPDATES_AVAILABLE:	/* FALLTHGROUGH */
+	case PUI_STATE_SESSION_RESTART_REQUIRED:	/* FALLTHGROUGH */
+	case PUI_STATE_SYSTEM_RESTART_REQUIRED:
 		/* create notification */
 		notification = g_notification_new(title);
 		g_notification_set_body(notification, body);
@@ -306,8 +324,8 @@
 			    _("Install Updates"),
 			    "app.install-updates");
 		}
-		g_application_send_notification(application, "package-updates",
-		    notification);
+		g_application_send_notification(application,
+		    "package-updates-or-restart-required", notification);
 		break;
 	}
 
@@ -326,6 +344,7 @@
 transition_state(PuiApplication *self)
 {
 	PuiState	state = self->state;
+	PuiRestart	restart_type;
 	guint		important_updates;
 	guint		normal_updates;
 	gchar		*old_state;
@@ -341,10 +360,14 @@
 			break;
 		}
 
-		g_object_get(self->backend,
+		g_object_get(self->backend, "restart-type", &restart_type,
 		    "important-updates", &important_updates,
 		    "normal-updates", &normal_updates, NULL);
-		if (important_updates > 0) {
+		if (restart_type == PUI_RESTART_SESSION) {
+			state = PUI_STATE_SESSION_RESTART_REQUIRED;
+		} else if (restart_type == PUI_RESTART_SYSTEM) {
+			state = PUI_STATE_SYSTEM_RESTART_REQUIRED;
+		} else if (important_updates > 0) {
 			state = PUI_STATE_IMPORTANT_UPDATES_AVAILABLE;
 		} else if (normal_updates > 0) {
 			state = PUI_STATE_NORMAL_UPDATES_AVAILABLE;
@@ -352,6 +375,14 @@
 			state = PUI_STATE_UP_TO_DATE;
 		}
 		break;
+	case PUI_STATE_SESSION_RESTART_REQUIRED:
+		g_object_get(self->backend, "restart-type", &restart_type,
+		    NULL);
+		if (restart_type == PUI_RESTART_SYSTEM) {
+			state = PUI_STATE_SYSTEM_RESTART_REQUIRED;
+		}
+		break;
+	case PUI_STATE_SYSTEM_RESTART_REQUIRED:		/* FALLTHROUGH */
 	case PUI_STATE_ERROR:
 		break;
 	}