← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~ted/indicator-session/restart-required-menu into lp:indicator-session

 

Ted Gould has proposed merging lp:~ted/indicator-session/restart-required-menu into lp:indicator-session.

Requested reviews:
  Indicator Applet Developers (indicator-applet-developers)


Adds a directory watcher on /var/run so that we can look for the
reboot-required file existing and change the menu item to encourage
people to reboot their computers.

Though, it matches design currently, I kinda want to change "Switch Off"
to "Switch Off is acceptable too" ;)
-- 
https://code.launchpad.net/~ted/indicator-session/restart-required-menu/+merge/20619
Your team ayatana-commits is subscribed to branch lp:indicator-session.
=== modified file 'src/session-service.c'
--- src/session-service.c	2010-03-04 02:58:51 +0000
+++ src/session-service.c	2010-03-04 04:00:35 +0000
@@ -27,6 +27,7 @@
 #include <unistd.h>
 
 #include <glib/gi18n.h>
+#include <gio/gio.h>
 
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-bindings.h>
@@ -605,6 +606,47 @@
 	return;
 }
 
+/* When the directory changes we need to figure out how our menu
+   item should look. */
+static void
+restart_dir_changed (void)
+{
+	gboolean restart_required = g_file_test("/var/run/reboot-required", G_FILE_TEST_EXISTS);
+
+	if (restart_required) {
+		if (supress_confirmations()) {
+			dbusmenu_menuitem_property_set(restart_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Restart Required"));
+		} else {
+			dbusmenu_menuitem_property_set(restart_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Restart Required..."));
+		}
+		dbusmenu_menuitem_property_set(restart_mi, DBUSMENU_MENUITEM_PROP_ICON_NAME, "emblem-important");
+	} else {	
+		if (supress_confirmations()) {
+			dbusmenu_menuitem_property_set(restart_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Restart"));
+		} else {
+			dbusmenu_menuitem_property_set(restart_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Restart..."));
+		}
+		dbusmenu_menuitem_property_remove(restart_mi, DBUSMENU_MENUITEM_PROP_ICON_NAME);
+	}
+
+	return;
+}
+
+/* Buids a file watcher for the directory so that when it
+   changes we can check to see if our reboot-required is
+   there. */
+static void
+setup_restart_watch (void)
+{
+	GFile * filedir = g_file_new_for_path("/var/run");
+	GFileMonitor * filemon = g_file_monitor_directory(filedir, G_FILE_MONITOR_NONE, NULL, NULL);
+	if (filemon != NULL) {
+		g_signal_connect(G_OBJECT(filemon), "changed", G_CALLBACK(restart_dir_changed), NULL);
+	}
+	restart_dir_changed();
+	return;
+}
+
 /* Main, is well, main.  It brings everything up and throws
    us into the mainloop of no return. */
 int
@@ -642,6 +684,8 @@
                       G_CALLBACK (user_change),
                       root_menuitem);
 
+	setup_restart_watch();
+
 	setup_up();
 
     DbusmenuServer * server = dbusmenu_server_new(INDICATOR_SESSION_DBUS_OBJECT);


Follow ups