~ballogy/docky/systemd-support

« back to all changes in this revision

Viewing changes to StandardPlugins/SessionManager/src/SystemManager.cs

  • Committer: György Balló
  • Date: 2012-12-30 01:50:14 UTC
  • Revision ID: ballogy@freestart.hu-20121230015014-99yc9psyhb2x9ukc
Add systemd support for Session Manager plugin

And fix GNOME Session support, fix missing icon on the restart dialog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
                const string DeviceKitPowerPath = "/org/freedesktop/DeviceKit/Power";
42
42
                const string DeviceKitPowerIface = "org.freedesktop.DeviceKit.Power";
43
43
 
 
44
                const string SystemdName = "org.freedesktop.login1";
 
45
                const string SystemdPath = "/org/freedesktop/login1";
 
46
                const string SystemdIface = "org.freedesktop.login1.Manager";
 
47
 
44
48
                const string ConsoleKitName = "org.freedesktop.ConsoleKit";
45
49
                const string ConsoleKitPath = "/org/freedesktop/ConsoleKit/Manager";
46
50
                const string ConsoleKitIface = "org.freedesktop.ConsoleKit.Manager";
79
83
                        event Action Changed;
80
84
                }
81
85
 
 
86
                [Interface (SystemdIface)]
 
87
                interface ISystemd
 
88
                {
 
89
                        string CanPowerOff ();
 
90
                        string CanReboot ();
 
91
 
 
92
                        void PowerOff (bool interactive);
 
93
                        void Reboot (bool interactive);
 
94
                }
 
95
 
82
96
                [Interface (ConsoleKitIface)]
83
97
                interface IConsoleKit
84
98
                {
100
114
                
101
115
                IDeviceKitPower devicekit;
102
116
                IUPower upower;
 
117
                ISystemd systemd;
103
118
                IConsoleKit consolekit;
104
119
                
105
120
                private static SystemManager instance;
117
132
                                SystemBus = Bus.System.GetObject<IBus> ("org.freedesktop.DBus", new ObjectPath ("/org/freedesktop/DBus"));
118
133
                                
119
134
                                SystemBus.NameOwnerChanged += delegate(string name, string old_owner, string new_owner) {
120
 
                                        if (name != UPowerName && name != DeviceKitPowerName && name != ConsoleKitName)
 
135
                                        if (name != UPowerName && name != DeviceKitPowerName && name != SystemdName && name != ConsoleKitName)
121
136
                                                return;
122
137
 
123
138
                                        Log<SystemManager>.Debug ("DBus services changed, reconnecting now");
128
143
                                        if (devicekit != null)
129
144
                                                devicekit = null;
130
145
 
 
146
                                        if (systemd != null)
 
147
                                                systemd = null;
 
148
 
131
149
                                        if (consolekit != null)
132
150
                                                consolekit = null;
133
151
                                        
161
179
                                        Log<SystemManager>.Debug ("Using DeviceKit.Power dbus service");
162
180
                                }
163
181
                                
164
 
                                if (consolekit == null && Bus.System.NameHasOwner (ConsoleKitName)) {
 
182
                                if (systemd == null && Bus.System.NameHasOwner (SystemdName)) {
 
183
                                        systemd = Bus.System.GetObject<ISystemd> (SystemdName, new ObjectPath (SystemdPath));
 
184
                                        Log<SystemManager>.Debug ("Using login1.Manager dbus service");
 
185
                                } else if (consolekit == null && Bus.System.NameHasOwner (ConsoleKitName)) {
165
186
                                        consolekit = Bus.System.GetObject<IConsoleKit> (ConsoleKitName, new ObjectPath (ConsoleKitPath));
166
187
                                        Log<SystemManager>.Debug ("Using ConsoleKit.Manager dbus service");
167
188
                                }
261
282
                
262
283
                public bool CanRestart ()
263
284
                {
264
 
                        if (consolekit != null)
 
285
                        if (systemd != null)
 
286
                                return systemd.CanReboot () == "yes";
 
287
                        else if (consolekit != null)
265
288
                                return consolekit.CanRestart ();
266
289
                        
267
 
                        Log<SystemManager>.Debug ("No consolekit bus available");
 
290
                        Log<SystemManager>.Debug ("No session bus available");
268
291
                        return false;
269
292
                }
270
293
 
271
294
                public void Restart ()
272
295
                {
273
 
                        if (consolekit != null) {
 
296
                        if (systemd != null) {
 
297
                                if (systemd.CanReboot () == "yes")
 
298
                                        systemd.Reboot (true);
 
299
                        } else if (consolekit != null) {
274
300
                                if (consolekit.CanRestart ())
275
301
                                        consolekit.Restart ();
276
302
                        } else {
277
 
                                Log<SystemManager>.Debug ("No consolekit bus available");
 
303
                                Log<SystemManager>.Debug ("No session bus available");
278
304
                        }
279
305
                }
280
306
 
281
307
                public bool CanStop ()
282
308
                {
283
 
                        if (consolekit != null)
 
309
                        if (systemd != null)
 
310
                                return systemd.CanPowerOff () == "yes";
 
311
                        else if (consolekit != null)
284
312
                                return consolekit.CanStop ();
285
313
                        
286
 
                        Log<SystemManager>.Debug ("No consolekit bus available");
 
314
                        Log<SystemManager>.Debug ("No session bus available");
287
315
                        return false;
288
316
                }
289
317
 
290
318
                public void Stop ()
291
319
                {
292
 
                        if (consolekit != null) {
 
320
                        if (systemd != null) {
 
321
                                if (systemd.CanPowerOff () == "yes")
 
322
                                        systemd.PowerOff (true);
 
323
                        } else if (consolekit != null) {
293
324
                                if (consolekit.CanStop ())
294
325
                                        consolekit.Stop ();
295
326
                        } else {
296
 
                                Log<SystemManager>.Debug ("No consolekit bus available");
 
327
                                Log<SystemManager>.Debug ("No session bus available");
297
328
                        }
298
329
                }
299
330
                
309
340
                
310
341
                public bool CanLogOut ()
311
342
                {
312
 
                        return DockServices.System.IsValidExecutable ("gnome-session-save");
 
343
                        return DockServices.System.IsValidExecutable ("gnome-session-quit");
313
344
                }
314
345
                
315
346
                public void LogOut ()
316
347
                {
317
 
                        DockServices.System.Execute ("gnome-session-save --logout");
 
348
                        DockServices.System.Execute ("gnome-session-quit --logout --no-prompt");
318
349
                }
319
350
                
320
351
                public void Dispose ()