← Back to team overview

do-plugins team mailing list archive

[Merge] lp:~ballogy/do-plugins/systemd-support into lp:do-plugins

 

György Balló has proposed merging lp:~ballogy/do-plugins/systemd-support into lp:do-plugins.

Requested reviews:
  Do Plugins Team (do-plugins)

For more details, see:
https://code.launchpad.net/~ballogy/do-plugins/systemd-support/+merge/141505

This change adds the following improvements for the GNOME-Session plugin:

1. Add support for reboot and power off with systemd-logind[1]. ConsoleKit is deprecated now, and no longer available on Arch Linux.

2. Fix GNOME Session support. gnome-session-save has been renamed to gnome-session-quit, and the parameters are changed.

3 Fix missing icons on actions. "gnome-session-*" icons are not available in gnome-icon-theme 3.6, so the general fallback icon displayed instead.

[1] http://www.freedesktop.org/wiki/Software/systemd/logind
-- 
https://code.launchpad.net/~ballogy/do-plugins/systemd-support/+merge/141505
Your team Do Plugins Team is requested to review the proposed merge of lp:~ballogy/do-plugins/systemd-support into lp:do-plugins.
=== modified file 'GNOME-Session/src/PowerManagement.cs'
--- GNOME-Session/src/PowerManagement.cs	2011-08-06 11:38:07 +0000
+++ GNOME-Session/src/PowerManagement.cs	2012-12-31 05:33:20 +0000
@@ -134,7 +134,7 @@
 		public static void Logout ()
 		{
 			try {
-				Process.Start ("gnome-session-save", "--kill --silent");
+				Process.Start ("gnome-session-quit", "--logout --no-prompt");
 			} catch (Exception e) {
 				Log<PowerManagement>.Error ("Could not logout: {0}", e.Message);
 				Log<PowerManagement>.Debug (e.StackTrace);

=== modified file 'GNOME-Session/src/SessionCommandsItemSource.cs'
--- GNOME-Session/src/SessionCommandsItemSource.cs	2010-03-17 15:01:40 +0000
+++ GNOME-Session/src/SessionCommandsItemSource.cs	2012-12-31 05:33:20 +0000
@@ -53,31 +53,31 @@
 				yield return new SessionCommandItem (
 					AddinManager.CurrentLocalizer.GetString ("Log Out"),
 					AddinManager.CurrentLocalizer.GetString ("Close your session and return to the login screen."),
-					"gnome-session-logout",
+					"system-log-out",
 					PowerManagement.Logout);
 
 				yield return new SessionCommandItem (
 					AddinManager.CurrentLocalizer.GetString ("Shutdown"),
 					AddinManager.CurrentLocalizer.GetString ("Turn your computer off."),
-					"gnome-session-halt",
+					"system-shutdown",
 					SystemManagement.Shutdown);
 
 				yield return new SessionCommandItem (
 					AddinManager.CurrentLocalizer.GetString ("Hibernate"),
 					AddinManager.CurrentLocalizer.GetString ("Put your computer into hibernation mode."),
-					"gnome-session-hibernate",
+					"system-shutdown",
 					PowerManagement.Hibernate);
 
 				yield return new SessionCommandItem (
 					AddinManager.CurrentLocalizer.GetString ("Suspend"),
 					AddinManager.CurrentLocalizer.GetString ("Put your computer into suspend mode."),
-					"gnome-session-suspend",
+					"system-shutdown",
 					PowerManagement.Suspend);
 
 				yield return new SessionCommandItem (
 					AddinManager.CurrentLocalizer.GetString ("Restart"),
 					AddinManager.CurrentLocalizer.GetString ("Restart your computer."),
-					"gnome-session-reboot",
+					"system-shutdown",
 					SystemManagement.Restart);
 
 				yield return new SessionCommandItem (

=== modified file 'GNOME-Session/src/SystemManagement.cs'
--- GNOME-Session/src/SystemManagement.cs	2011-08-06 11:38:07 +0000
+++ GNOME-Session/src/SystemManagement.cs	2012-12-31 05:33:20 +0000
@@ -36,24 +36,48 @@
 	class SystemManagement
 	{
 		[Interface ("org.freedesktop.ConsoleKit.Manager")]
-		interface ISystemManagementProxy
+		interface IConsoleKit
 		{
 			void Stop ();
 			void Restart ();
 		}
 
-		const string BusName = "org.freedesktop.ConsoleKit";
-		const string ObjectPath = "/org/freedesktop/ConsoleKit/Manager";
-
-		static ISystemManagementProxy BusInstance
+		[Interface ("org.freedesktop.login1.Manager")]
+		interface ISystemd
+		{
+			void PowerOff (bool interactive);
+			void Reboot (bool interactive);
+		}
+
+		const string ConsoleKitName = "org.freedesktop.ConsoleKit";
+		const string ConsoleKitPath = "/org/freedesktop/ConsoleKit/Manager";
+		const string SystemdName = "org.freedesktop.login1";
+		const string SystemdPath = "/org/freedesktop/login1";
+
+		static SystemManagement ()
+		{
+			try {
+				BusG.Init ();
+			} catch (Exception e) {
+				Log<SystemManagement>.Error ("Could not initialize the bus: {0}", e.Message);
+				Log<SystemManagement>.Debug (e.StackTrace);
+			}
+		}
+
+		static object BusInstance
 		{
 			get {
 				try {
-					return Bus.System.GetObject<ISystemManagementProxy> (BusName, new ObjectPath (ObjectPath));
+					if (Bus.System.NameHasOwner (SystemdName)) {
+						return Bus.System.GetObject<ISystemd> (SystemdName, new ObjectPath (SystemdPath));
+					} else if (Bus.System.NameHasOwner (ConsoleKitName)) {
+						return Bus.System.GetObject<IConsoleKit> (ConsoleKitName, new ObjectPath (ConsoleKitPath));
+					}
 				} catch (Exception e) {
-					Log<SystemManagement>.Error ("Could not get ConsoleKit bus object: {0}", e.Message);
+					Log<SystemManagement>.Error ("Could not get SystemManagement bus object: {0}", e.Message);
 					Log<SystemManagement>.Debug (e.StackTrace);
 				}
+
 				return null;
 			}
 		}
@@ -61,7 +85,12 @@
 		public static void Shutdown ()
 		{
 			try {
-				BusInstance.Stop ();
+				object instance = BusInstance;
+				if (instance is ISystemd) {
+					(instance as ISystemd).PowerOff (true);
+				} else if (instance is IConsoleKit) {
+					(instance as IConsoleKit).Stop ();
+				}
 			} catch (Exception e) {
 				Log<SystemManagement>.Error ("Could not shutdown: {0}", e.Message);
 				Log<SystemManagement>.Debug (e.StackTrace);
@@ -71,7 +100,12 @@
 		public static void Restart ()
 		{
 			try {
-				BusInstance.Restart ();
+				object instance = BusInstance;
+				if (instance is ISystemd) {
+					(instance as ISystemd).Reboot (true);
+				} else if (instance is IConsoleKit) {
+					(instance as IConsoleKit).Restart ();
+				}
 			} catch (Exception e) {
 				Log<SystemManagement>.Error ("Could not reboot: {0}", e.Message);
 				Log<SystemManagement>.Debug (e.StackTrace);