1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
diff -urN synapse-0.2.10.orig/src/plugins/Makefile.am synapse-0.2.10/src/plugins/Makefile.am
--- synapse-0.2.10.orig/src/plugins/Makefile.am 2013-08-18 18:33:35.710536590 +0200
+++ synapse-0.2.10/src/plugins/Makefile.am 2013-08-18 18:33:44.427203171 +0200
@@ -45,6 +45,7 @@
hybrid-search-plugin.vala \
launchpad-plugin.vala \
locate-plugin.vala \
+ mate-session-plugin.vala \
opensearch.vala \
pass-plugin.vala \
pastebin-plugin.vala \
diff -urN synapse-0.2.10.orig/src/plugins/mate-session-plugin.vala synapse-0.2.10/src/plugins/mate-session-plugin.vala
--- synapse-0.2.10.orig/src/plugins/mate-session-plugin.vala 1970-01-01 01:00:00.000000000 +0100
+++ synapse-0.2.10/src/plugins/mate-session-plugin.vala 2013-08-18 18:33:44.427203171 +0200
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) 2010 Michal Hruby <michal.mhr@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Authored by Michal Hruby <michal.mhr@gmail.com>
+ *
+ */
+
+namespace Synapse
+{
+ [DBus (name = "org.mate.SessionManager")]
+ public interface MateSessionManager: Object
+ {
+ public const string UNIQUE_NAME = "org.mate.SessionManager";
+ public const string OBJECT_PATH = "/org/mate/SessionManager";
+
+ public abstract bool can_shutdown () throws IOError;
+ public abstract void shutdown () throws IOError;
+ public abstract void request_reboot () throws IOError;
+ public abstract void logout (uint32 mode = 0) throws IOError;
+ }
+
+ public class MateSessionPlugin: Object, Activatable, ItemProvider
+ {
+ public bool enabled { get; set; default = true; }
+
+ public void activate ()
+ {
+
+ }
+
+ public void deactivate ()
+ {
+
+ }
+
+ private class ShutDownAction: ActionMatch
+ {
+ public ShutDownAction ()
+ {
+ Object (title: _("Shut Down"),
+ description: _("Turn your computer off"),
+ icon_name: "system-shutdown", has_thumbnail: false);
+ }
+
+ public override void do_action ()
+ {
+ try
+ {
+ MateSessionManager dbus_interface = Bus.get_proxy_sync (BusType.SESSION,
+ MateSessionManager.UNIQUE_NAME,
+ MateSessionManager.OBJECT_PATH);
+
+ dbus_interface.shutdown ();
+ }
+ catch (IOError err)
+ {
+ warning ("%s", err.message);
+ }
+ }
+ }
+
+ private class RebootAction: ActionMatch
+ {
+ public RebootAction ()
+ {
+ Object (title: _("Restart"),
+ description: _("Restart your computer"),
+ icon_name: "system-shutdown", has_thumbnail: false);
+ }
+
+ public override void do_action ()
+ {
+ try
+ {
+ MateSessionManager dbus_interface = Bus.get_proxy_sync (BusType.SESSION,
+ MateSessionManager.UNIQUE_NAME,
+ MateSessionManager.OBJECT_PATH);
+
+ dbus_interface.request_reboot ();
+ }
+ catch (IOError err)
+ {
+ warning ("%s", err.message);
+ }
+ }
+ }
+
+ private class LogOutAction: ActionMatch
+ {
+ public LogOutAction ()
+ {
+ Object (title: _("Log Out"),
+ description: _("Close your session and return to the login screen"),
+ icon_name: "gnome-logout", has_thumbnail: false);
+ }
+
+ public override void do_action ()
+ {
+ try
+ {
+ MateSessionManager dbus_interface = Bus.get_proxy_sync (BusType.SESSION,
+ MateSessionManager.UNIQUE_NAME,
+ MateSessionManager.OBJECT_PATH);
+
+ /*
+ * 0: Normal.
+ * 1: No confirmation inferface should be shown.
+ * 2: Forcefully logout. No confirmation will be shown and any inhibitors will be ignored.
+ */
+ dbus_interface.logout (1);
+ }
+ catch (IOError err)
+ {
+ warning ("%s", err.message);
+ }
+ }
+ }
+
+ static void register_plugin ()
+ {
+ PluginRegistry.get_default ().register_plugin (
+ typeof (MateSessionPlugin),
+ "MATE Session",
+ _ ("Log out from your session."),
+ "mate-session-logout",
+ register_plugin,
+ DBusService.get_default ().name_has_owner (MateSessionManager.UNIQUE_NAME),
+ _ ("MATE Session Manager wasn't found")
+ );
+ }
+
+ static construct
+ {
+ register_plugin ();
+ }
+
+ private bool session_manager_available = false;
+ private Gee.List<Match> actions;
+
+ construct
+ {
+ var cache = DBusService.get_default ();
+ session_manager_available = cache.name_has_owner (MateSessionManager.UNIQUE_NAME);
+ message ("%s %s available", MateSessionManager.UNIQUE_NAME,
+ session_manager_available ? "is" : "isn't");
+
+ actions = new Gee.LinkedList<Match> ();
+ actions.add (new LogOutAction ());
+ // TODO: add a config option to enable these actions (for example when ConsoleKit is not available)
+ //actions.add (new RebootAction ());
+ //actions.add (new ShutDownAction ());
+ }
+
+ public async ResultSet? search (Query q) throws SearchError
+ {
+ if (!session_manager_available) return null;
+ // we only search for actions
+ if (!(QueryFlags.ACTIONS in q.query_type)) return null;
+
+ var result = new ResultSet ();
+
+ var matchers = Query.get_matchers_for_query (q.query_string, 0,
+ RegexCompileFlags.OPTIMIZE | RegexCompileFlags.CASELESS);
+
+ foreach (var action in actions)
+ {
+ foreach (var matcher in matchers)
+ {
+ if (matcher.key.match (action.title))
+ {
+ result.add (action, matcher.value - MatchScore.INCREMENT_SMALL);
+ break;
+ }
+ }
+ }
+
+ q.check_cancellable ();
+
+ return result;
+ }
+ }
+}
diff -urN synapse-0.2.10.orig/src/ui/synapse-main.vala synapse-0.2.10/src/ui/synapse-main.vala
--- synapse-0.2.10.orig/src/ui/synapse-main.vala 2013-08-18 18:33:35.710536590 +0200
+++ synapse-0.2.10/src/ui/synapse-main.vala 2013-08-18 18:33:44.427203171 +0200
@@ -165,6 +165,7 @@
typeof (HybridSearchPlugin),
typeof (GnomeBookmarksPlugin),
typeof (GnomeSessionPlugin),
+ typeof (MateSessionPlugin),
typeof (ScreenSaverPlugin),
typeof (SystemManagementPlugin),
typeof (CommandPlugin),
|