Merge lp:~parnold-x/slingshot/slingshot-session-plugin into lp:~elementary-pantheon/slingshot/trunk
- slingshot-session-plugin
- Merge into trunk
Proposed by
Danielle Foré
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Cody Garver | ||||
Approved revision: | 534 | ||||
Merged at revision: | 539 | ||||
Proposed branch: | lp:~parnold-x/slingshot/slingshot-session-plugin | ||||
Merge into: | lp:~elementary-pantheon/slingshot/trunk | ||||
Diff against target: |
555 lines (+527/-1) 3 files modified
lib/synapse-plugins/CMakeLists.txt (+1/-0) lib/synapse-plugins/system-managment.vala (+524/-0) src/Backend/SynapseSearch.vala (+2/-1) |
||||
To merge this branch: | bzr merge lp:~parnold-x/slingshot/slingshot-session-plugin | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
elementary Pantheon team | Pending | ||
Review via email: mp+259656@code.launchpad.net |
Commit message
Add session actions plugin (lp:1380794)
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'lib/synapse-plugins/CMakeLists.txt' | |||
2 | --- lib/synapse-plugins/CMakeLists.txt 2014-06-29 14:50:36 +0000 | |||
3 | +++ lib/synapse-plugins/CMakeLists.txt 2015-05-20 17:20:28 +0000 | |||
4 | @@ -14,6 +14,7 @@ | |||
5 | 14 | calculator-plugin.vala | 14 | calculator-plugin.vala |
6 | 15 | command-plugin.vala | 15 | command-plugin.vala |
7 | 16 | desktop-file-plugin.vala | 16 | desktop-file-plugin.vala |
8 | 17 | system-managment.vala | ||
9 | 17 | ) | 18 | ) |
10 | 18 | 19 | ||
11 | 19 | set(LINK_MODE STATIC) | 20 | set(LINK_MODE STATIC) |
12 | 20 | 21 | ||
13 | === added file 'lib/synapse-plugins/system-managment.vala' | |||
14 | --- lib/synapse-plugins/system-managment.vala 1970-01-01 00:00:00 +0000 | |||
15 | +++ lib/synapse-plugins/system-managment.vala 2015-05-20 17:20:28 +0000 | |||
16 | @@ -0,0 +1,524 @@ | |||
17 | 1 | /* | ||
18 | 2 | * Copyright (C) 2010 Michal Hruby <michal.mhr@gmail.com> | ||
19 | 3 | * | ||
20 | 4 | * This program is free software; you can redistribute it and/or modify | ||
21 | 5 | * it under the terms of the GNU General Public License as published by | ||
22 | 6 | * the Free Software Foundation; either version 2 of the License, or | ||
23 | 7 | * (at your option) any later version. | ||
24 | 8 | * | ||
25 | 9 | * This program is distributed in the hope that it will be useful, | ||
26 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
27 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
28 | 12 | * GNU General Public License for more details. | ||
29 | 13 | * | ||
30 | 14 | * You should have received a copy of the GNU General Public License | ||
31 | 15 | * along with this program; if not, write to the Free Software | ||
32 | 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
33 | 17 | * | ||
34 | 18 | * Authored by Michal Hruby <michal.mhr@gmail.com> | ||
35 | 19 | * | ||
36 | 20 | */ | ||
37 | 21 | |||
38 | 22 | namespace Synapse | ||
39 | 23 | { | ||
40 | 24 | [DBus (name = "org.freedesktop.UPower")] | ||
41 | 25 | public interface UPowerObject : Object | ||
42 | 26 | { | ||
43 | 27 | public const string UNIQUE_NAME = "org.freedesktop.UPower"; | ||
44 | 28 | public const string OBJECT_PATH = "/org/freedesktop/UPower"; | ||
45 | 29 | |||
46 | 30 | public abstract async void hibernate () throws IOError; | ||
47 | 31 | public abstract async void suspend () throws IOError; | ||
48 | 32 | public abstract async bool hibernate_allowed () throws IOError; | ||
49 | 33 | public abstract async bool suspend_allowed () throws IOError; | ||
50 | 34 | |||
51 | 35 | public abstract async void about_to_sleep () throws IOError; | ||
52 | 36 | } | ||
53 | 37 | |||
54 | 38 | [DBus (name = "org.freedesktop.ConsoleKit.Manager")] | ||
55 | 39 | public interface ConsoleKitObject : Object | ||
56 | 40 | { | ||
57 | 41 | public const string UNIQUE_NAME = "org.freedesktop.ConsoleKit"; | ||
58 | 42 | public const string OBJECT_PATH = "/org/freedesktop/ConsoleKit/Manager"; | ||
59 | 43 | |||
60 | 44 | public abstract void restart () throws IOError; | ||
61 | 45 | public abstract void stop () throws IOError; | ||
62 | 46 | public abstract async bool can_restart () throws IOError; | ||
63 | 47 | public abstract async bool can_stop () throws IOError; | ||
64 | 48 | } | ||
65 | 49 | |||
66 | 50 | [DBus (name = "org.freedesktop.login1.Manager")] | ||
67 | 51 | public interface SystemdObject : Object | ||
68 | 52 | { | ||
69 | 53 | public const string UNIQUE_NAME = "org.freedesktop.login1"; | ||
70 | 54 | public const string OBJECT_PATH = "/org/freedesktop/login1"; | ||
71 | 55 | |||
72 | 56 | public abstract void reboot (bool interactive) throws IOError; | ||
73 | 57 | public abstract void suspend (bool interactive) throws IOError; | ||
74 | 58 | public abstract void hibernate (bool interactive) throws IOError; | ||
75 | 59 | public abstract void power_off (bool interactive) throws IOError; | ||
76 | 60 | public abstract string can_suspend () throws IOError; | ||
77 | 61 | public abstract string can_hibernate () throws IOError; | ||
78 | 62 | public abstract string can_reboot () throws IOError; | ||
79 | 63 | public abstract string can_power_off () throws IOError; | ||
80 | 64 | } | ||
81 | 65 | |||
82 | 66 | public class SystemManagementPlugin : Object, Activatable, ItemProvider | ||
83 | 67 | { | ||
84 | 68 | public bool enabled { get; set; default = true; } | ||
85 | 69 | |||
86 | 70 | public void activate () | ||
87 | 71 | { | ||
88 | 72 | |||
89 | 73 | } | ||
90 | 74 | |||
91 | 75 | public void deactivate () | ||
92 | 76 | { | ||
93 | 77 | |||
94 | 78 | } | ||
95 | 79 | |||
96 | 80 | private abstract class SystemAction : Object, Match | ||
97 | 81 | { | ||
98 | 82 | // for Match interface | ||
99 | 83 | public string title { get; construct set; } | ||
100 | 84 | public string description { get; set; default = ""; } | ||
101 | 85 | public string icon_name { get; construct set; default = ""; } | ||
102 | 86 | public bool has_thumbnail { get; construct set; default = false; } | ||
103 | 87 | public string thumbnail_path { get; construct set; } | ||
104 | 88 | public MatchType match_type { get; construct set; } | ||
105 | 89 | |||
106 | 90 | public abstract void do_action (); | ||
107 | 91 | |||
108 | 92 | public abstract bool action_allowed (); | ||
109 | 93 | |||
110 | 94 | public void execute (Match? match) { | ||
111 | 95 | do_action (); | ||
112 | 96 | } | ||
113 | 97 | } | ||
114 | 98 | |||
115 | 99 | private class SuspendAction : SystemAction | ||
116 | 100 | { | ||
117 | 101 | public SuspendAction () | ||
118 | 102 | { | ||
119 | 103 | Object (title: _("Suspend"), match_type: MatchType.ACTION, | ||
120 | 104 | description: _("Put your computer into suspend mode"), | ||
121 | 105 | icon_name: "system-suspend", has_thumbnail: false); | ||
122 | 106 | } | ||
123 | 107 | |||
124 | 108 | construct | ||
125 | 109 | { | ||
126 | 110 | check_allowed.begin (); | ||
127 | 111 | } | ||
128 | 112 | |||
129 | 113 | private async void check_allowed () | ||
130 | 114 | { | ||
131 | 115 | try | ||
132 | 116 | { | ||
133 | 117 | SystemdObject dbus_interface = Bus.get_proxy_sync (BusType.SYSTEM, | ||
134 | 118 | SystemdObject.UNIQUE_NAME, | ||
135 | 119 | SystemdObject.OBJECT_PATH); | ||
136 | 120 | |||
137 | 121 | allowed = (dbus_interface.can_suspend () == "yes"); | ||
138 | 122 | return; | ||
139 | 123 | } | ||
140 | 124 | catch (IOError err) | ||
141 | 125 | { | ||
142 | 126 | warning ("%s", err.message); | ||
143 | 127 | allowed = false; | ||
144 | 128 | } | ||
145 | 129 | |||
146 | 130 | try | ||
147 | 131 | { | ||
148 | 132 | UPowerObject dbus_interface = Bus.get_proxy_sync (BusType.SYSTEM, | ||
149 | 133 | UPowerObject.UNIQUE_NAME, | ||
150 | 134 | UPowerObject.OBJECT_PATH); | ||
151 | 135 | |||
152 | 136 | allowed = yield dbus_interface.suspend_allowed (); | ||
153 | 137 | } | ||
154 | 138 | catch (IOError err) | ||
155 | 139 | { | ||
156 | 140 | warning ("%s", err.message); | ||
157 | 141 | allowed = false; | ||
158 | 142 | } | ||
159 | 143 | } | ||
160 | 144 | |||
161 | 145 | private bool allowed = false; | ||
162 | 146 | |||
163 | 147 | public override bool action_allowed () | ||
164 | 148 | { | ||
165 | 149 | return allowed; | ||
166 | 150 | } | ||
167 | 151 | |||
168 | 152 | private async void do_suspend () | ||
169 | 153 | { | ||
170 | 154 | try | ||
171 | 155 | { | ||
172 | 156 | SystemdObject dbus_interface = Bus.get_proxy_sync (BusType.SYSTEM, | ||
173 | 157 | SystemdObject.UNIQUE_NAME, | ||
174 | 158 | SystemdObject.OBJECT_PATH); | ||
175 | 159 | |||
176 | 160 | dbus_interface.suspend (true); | ||
177 | 161 | return; | ||
178 | 162 | } | ||
179 | 163 | catch (IOError err) | ||
180 | 164 | { | ||
181 | 165 | warning ("%s", err.message); | ||
182 | 166 | } | ||
183 | 167 | |||
184 | 168 | try | ||
185 | 169 | { | ||
186 | 170 | UPowerObject dbus_interface = Bus.get_proxy_sync (BusType.SYSTEM, | ||
187 | 171 | UPowerObject.UNIQUE_NAME, | ||
188 | 172 | UPowerObject.OBJECT_PATH); | ||
189 | 173 | |||
190 | 174 | try | ||
191 | 175 | { | ||
192 | 176 | yield dbus_interface.about_to_sleep (); | ||
193 | 177 | } | ||
194 | 178 | catch (Error not_there_error) { } | ||
195 | 179 | // yea kinda nasty | ||
196 | 180 | //GnomeScreenSaverPlugin.lock_screen (); | ||
197 | 181 | // wait 2 seconds | ||
198 | 182 | Timeout.add (2000, do_suspend.callback); | ||
199 | 183 | yield; | ||
200 | 184 | |||
201 | 185 | yield dbus_interface.suspend (); | ||
202 | 186 | } | ||
203 | 187 | catch (IOError err) | ||
204 | 188 | { | ||
205 | 189 | warning ("%s", err.message); | ||
206 | 190 | } | ||
207 | 191 | } | ||
208 | 192 | |||
209 | 193 | public override void do_action () | ||
210 | 194 | { | ||
211 | 195 | do_suspend.begin (); | ||
212 | 196 | } | ||
213 | 197 | } | ||
214 | 198 | |||
215 | 199 | private class HibernateAction : SystemAction | ||
216 | 200 | { | ||
217 | 201 | public HibernateAction () | ||
218 | 202 | { | ||
219 | 203 | Object (title: _("Hibernate"), match_type: MatchType.ACTION, | ||
220 | 204 | description: _("Put your computer into hibernation mode"), | ||
221 | 205 | icon_name: "system-hibernate", has_thumbnail: false); | ||
222 | 206 | } | ||
223 | 207 | |||
224 | 208 | construct | ||
225 | 209 | { | ||
226 | 210 | check_allowed.begin (); | ||
227 | 211 | } | ||
228 | 212 | |||
229 | 213 | private async void check_allowed () | ||
230 | 214 | { | ||
231 | 215 | try | ||
232 | 216 | { | ||
233 | 217 | SystemdObject dbus_interface = Bus.get_proxy_sync (BusType.SYSTEM, | ||
234 | 218 | SystemdObject.UNIQUE_NAME, | ||
235 | 219 | SystemdObject.OBJECT_PATH); | ||
236 | 220 | |||
237 | 221 | allowed = (dbus_interface.can_hibernate () == "yes"); | ||
238 | 222 | return; | ||
239 | 223 | } | ||
240 | 224 | catch (IOError err) | ||
241 | 225 | { | ||
242 | 226 | warning ("%s", err.message); | ||
243 | 227 | allowed = false; | ||
244 | 228 | } | ||
245 | 229 | |||
246 | 230 | try | ||
247 | 231 | { | ||
248 | 232 | UPowerObject dbus_interface = Bus.get_proxy_sync (BusType.SYSTEM, | ||
249 | 233 | UPowerObject.UNIQUE_NAME, | ||
250 | 234 | UPowerObject.OBJECT_PATH); | ||
251 | 235 | |||
252 | 236 | allowed = yield dbus_interface.hibernate_allowed (); | ||
253 | 237 | } | ||
254 | 238 | catch (IOError err) | ||
255 | 239 | { | ||
256 | 240 | warning ("%s", err.message); | ||
257 | 241 | allowed = false; | ||
258 | 242 | } | ||
259 | 243 | } | ||
260 | 244 | |||
261 | 245 | private bool allowed = false; | ||
262 | 246 | |||
263 | 247 | public override bool action_allowed () | ||
264 | 248 | { | ||
265 | 249 | return allowed; | ||
266 | 250 | } | ||
267 | 251 | |||
268 | 252 | private async void do_hibernate () | ||
269 | 253 | { | ||
270 | 254 | try | ||
271 | 255 | { | ||
272 | 256 | SystemdObject dbus_interface = Bus.get_proxy_sync (BusType.SYSTEM, | ||
273 | 257 | SystemdObject.UNIQUE_NAME, | ||
274 | 258 | SystemdObject.OBJECT_PATH); | ||
275 | 259 | |||
276 | 260 | dbus_interface.hibernate (true); | ||
277 | 261 | return; | ||
278 | 262 | } | ||
279 | 263 | catch (IOError err) | ||
280 | 264 | { | ||
281 | 265 | warning ("%s", err.message); | ||
282 | 266 | } | ||
283 | 267 | |||
284 | 268 | try | ||
285 | 269 | { | ||
286 | 270 | UPowerObject dbus_interface = Bus.get_proxy_sync (BusType.SYSTEM, | ||
287 | 271 | UPowerObject.UNIQUE_NAME, | ||
288 | 272 | UPowerObject.OBJECT_PATH); | ||
289 | 273 | |||
290 | 274 | try | ||
291 | 275 | { | ||
292 | 276 | yield dbus_interface.about_to_sleep (); | ||
293 | 277 | } | ||
294 | 278 | catch (Error not_there_error) { } | ||
295 | 279 | // yea kinda nasty | ||
296 | 280 | //GnomeScreenSaverPlugin.lock_screen (); | ||
297 | 281 | // wait 2 seconds | ||
298 | 282 | Timeout.add (2000, do_hibernate.callback); | ||
299 | 283 | yield; | ||
300 | 284 | dbus_interface.hibernate.begin (); | ||
301 | 285 | } | ||
302 | 286 | catch (IOError err) | ||
303 | 287 | { | ||
304 | 288 | warning ("%s", err.message); | ||
305 | 289 | } | ||
306 | 290 | } | ||
307 | 291 | |||
308 | 292 | public override void do_action () | ||
309 | 293 | { | ||
310 | 294 | do_hibernate.begin (); | ||
311 | 295 | } | ||
312 | 296 | } | ||
313 | 297 | |||
314 | 298 | private class ShutdownAction : SystemAction | ||
315 | 299 | { | ||
316 | 300 | public ShutdownAction () | ||
317 | 301 | { | ||
318 | 302 | Object (title: _("Shut Down"), match_type: MatchType.ACTION, | ||
319 | 303 | description: _("Turn your computer off"), | ||
320 | 304 | icon_name: "system-shutdown", has_thumbnail: false); | ||
321 | 305 | } | ||
322 | 306 | |||
323 | 307 | construct | ||
324 | 308 | { | ||
325 | 309 | check_allowed.begin (); | ||
326 | 310 | } | ||
327 | 311 | |||
328 | 312 | private async void check_allowed () | ||
329 | 313 | { | ||
330 | 314 | try | ||
331 | 315 | { | ||
332 | 316 | SystemdObject dbus_interface = Bus.get_proxy_sync (BusType.SYSTEM, | ||
333 | 317 | SystemdObject.UNIQUE_NAME, | ||
334 | 318 | SystemdObject.OBJECT_PATH); | ||
335 | 319 | |||
336 | 320 | allowed = (dbus_interface.can_power_off () == "yes"); | ||
337 | 321 | return; | ||
338 | 322 | } | ||
339 | 323 | catch (IOError err) | ||
340 | 324 | { | ||
341 | 325 | warning ("%s", err.message); | ||
342 | 326 | allowed = false; | ||
343 | 327 | } | ||
344 | 328 | |||
345 | 329 | try | ||
346 | 330 | { | ||
347 | 331 | ConsoleKitObject dbus_interface = Bus.get_proxy_sync (BusType.SYSTEM, | ||
348 | 332 | ConsoleKitObject.UNIQUE_NAME, | ||
349 | 333 | ConsoleKitObject.OBJECT_PATH); | ||
350 | 334 | |||
351 | 335 | allowed = yield dbus_interface.can_stop (); | ||
352 | 336 | } | ||
353 | 337 | catch (IOError err) | ||
354 | 338 | { | ||
355 | 339 | warning ("%s", err.message); | ||
356 | 340 | allowed = false; | ||
357 | 341 | } | ||
358 | 342 | } | ||
359 | 343 | |||
360 | 344 | private bool allowed = false; | ||
361 | 345 | |||
362 | 346 | public override bool action_allowed () | ||
363 | 347 | { | ||
364 | 348 | return allowed; | ||
365 | 349 | } | ||
366 | 350 | |||
367 | 351 | public override void do_action () | ||
368 | 352 | { | ||
369 | 353 | try | ||
370 | 354 | { | ||
371 | 355 | SystemdObject dbus_interface = Bus.get_proxy_sync (BusType.SYSTEM, | ||
372 | 356 | SystemdObject.UNIQUE_NAME, | ||
373 | 357 | SystemdObject.OBJECT_PATH); | ||
374 | 358 | |||
375 | 359 | dbus_interface.power_off (true); | ||
376 | 360 | return; | ||
377 | 361 | } | ||
378 | 362 | catch (IOError err) | ||
379 | 363 | { | ||
380 | 364 | warning ("%s", err.message); | ||
381 | 365 | } | ||
382 | 366 | |||
383 | 367 | try | ||
384 | 368 | { | ||
385 | 369 | ConsoleKitObject dbus_interface = Bus.get_proxy_sync (BusType.SYSTEM, | ||
386 | 370 | ConsoleKitObject.UNIQUE_NAME, | ||
387 | 371 | ConsoleKitObject.OBJECT_PATH); | ||
388 | 372 | |||
389 | 373 | dbus_interface.stop (); | ||
390 | 374 | } | ||
391 | 375 | catch (IOError err) | ||
392 | 376 | { | ||
393 | 377 | warning ("%s", err.message); | ||
394 | 378 | } | ||
395 | 379 | } | ||
396 | 380 | } | ||
397 | 381 | |||
398 | 382 | private class RestartAction : SystemAction | ||
399 | 383 | { | ||
400 | 384 | public RestartAction () | ||
401 | 385 | { | ||
402 | 386 | Object (title: _("Restart"), match_type: MatchType.ACTION, | ||
403 | 387 | description: _("Restart your computer"), | ||
404 | 388 | icon_name: "system-restart", has_thumbnail: false); | ||
405 | 389 | } | ||
406 | 390 | |||
407 | 391 | construct | ||
408 | 392 | { | ||
409 | 393 | check_allowed.begin (); | ||
410 | 394 | } | ||
411 | 395 | |||
412 | 396 | private async void check_allowed () | ||
413 | 397 | { | ||
414 | 398 | try | ||
415 | 399 | { | ||
416 | 400 | SystemdObject dbus_interface = Bus.get_proxy_sync (BusType.SYSTEM, | ||
417 | 401 | SystemdObject.UNIQUE_NAME, | ||
418 | 402 | SystemdObject.OBJECT_PATH); | ||
419 | 403 | |||
420 | 404 | allowed = (dbus_interface.can_reboot () == "yes"); | ||
421 | 405 | return; | ||
422 | 406 | } | ||
423 | 407 | catch (IOError err) | ||
424 | 408 | { | ||
425 | 409 | warning ("%s", err.message); | ||
426 | 410 | allowed = false; | ||
427 | 411 | } | ||
428 | 412 | |||
429 | 413 | try | ||
430 | 414 | { | ||
431 | 415 | ConsoleKitObject dbus_interface = Bus.get_proxy_sync (BusType.SYSTEM, | ||
432 | 416 | ConsoleKitObject.UNIQUE_NAME, | ||
433 | 417 | ConsoleKitObject.OBJECT_PATH); | ||
434 | 418 | |||
435 | 419 | allowed = yield dbus_interface.can_restart (); | ||
436 | 420 | } | ||
437 | 421 | catch (IOError err) | ||
438 | 422 | { | ||
439 | 423 | warning ("%s", err.message); | ||
440 | 424 | allowed = false; | ||
441 | 425 | } | ||
442 | 426 | } | ||
443 | 427 | |||
444 | 428 | private bool allowed = false; | ||
445 | 429 | |||
446 | 430 | public override bool action_allowed () | ||
447 | 431 | { | ||
448 | 432 | return allowed; | ||
449 | 433 | } | ||
450 | 434 | |||
451 | 435 | public override void do_action () | ||
452 | 436 | { | ||
453 | 437 | try | ||
454 | 438 | { | ||
455 | 439 | SystemdObject dbus_interface = Bus.get_proxy_sync (BusType.SYSTEM, | ||
456 | 440 | SystemdObject.UNIQUE_NAME, | ||
457 | 441 | SystemdObject.OBJECT_PATH); | ||
458 | 442 | |||
459 | 443 | dbus_interface.reboot (true); | ||
460 | 444 | return; | ||
461 | 445 | } | ||
462 | 446 | catch (IOError err) | ||
463 | 447 | { | ||
464 | 448 | warning ("%s", err.message); | ||
465 | 449 | } | ||
466 | 450 | |||
467 | 451 | try | ||
468 | 452 | { | ||
469 | 453 | ConsoleKitObject dbus_interface = Bus.get_proxy_sync (BusType.SYSTEM, | ||
470 | 454 | ConsoleKitObject.UNIQUE_NAME, | ||
471 | 455 | ConsoleKitObject.OBJECT_PATH); | ||
472 | 456 | |||
473 | 457 | dbus_interface.restart (); | ||
474 | 458 | } | ||
475 | 459 | catch (IOError err) | ||
476 | 460 | { | ||
477 | 461 | warning ("%s", err.message); | ||
478 | 462 | } | ||
479 | 463 | } | ||
480 | 464 | } | ||
481 | 465 | |||
482 | 466 | static void register_plugin () | ||
483 | 467 | { | ||
484 | 468 | DataSink.PluginRegistry.get_default ().register_plugin ( | ||
485 | 469 | typeof (SystemManagementPlugin), | ||
486 | 470 | "System Management", | ||
487 | 471 | _("Suspend, hibernate, restart or shutdown your computer."), | ||
488 | 472 | "system-restart", | ||
489 | 473 | register_plugin, | ||
490 | 474 | DBusService.get_default ().service_is_available (SystemdObject.UNIQUE_NAME) || | ||
491 | 475 | DBusService.get_default ().service_is_available (ConsoleKitObject.UNIQUE_NAME), | ||
492 | 476 | _("ConsoleKit wasn't found") | ||
493 | 477 | ); | ||
494 | 478 | } | ||
495 | 479 | |||
496 | 480 | static construct | ||
497 | 481 | { | ||
498 | 482 | register_plugin (); | ||
499 | 483 | } | ||
500 | 484 | |||
501 | 485 | private Gee.List<SystemAction> actions; | ||
502 | 486 | |||
503 | 487 | construct | ||
504 | 488 | { | ||
505 | 489 | actions = new Gee.LinkedList<SystemAction> (); | ||
506 | 490 | actions.add (new SuspendAction ()); | ||
507 | 491 | actions.add (new HibernateAction ()); | ||
508 | 492 | actions.add (new ShutdownAction ()); | ||
509 | 493 | actions.add (new RestartAction ()); | ||
510 | 494 | } | ||
511 | 495 | |||
512 | 496 | public async ResultSet? search (Query q) throws SearchError | ||
513 | 497 | { | ||
514 | 498 | // we only search for actions | ||
515 | 499 | if (!(QueryFlags.ACTIONS in q.query_type)) return null; | ||
516 | 500 | |||
517 | 501 | var result = new ResultSet (); | ||
518 | 502 | |||
519 | 503 | var matchers = Query.get_matchers_for_query (q.query_string, 0, | ||
520 | 504 | RegexCompileFlags.OPTIMIZE | RegexCompileFlags.CASELESS); | ||
521 | 505 | |||
522 | 506 | foreach (var action in actions) | ||
523 | 507 | { | ||
524 | 508 | if (!action.action_allowed ()) continue; | ||
525 | 509 | foreach (var matcher in matchers) | ||
526 | 510 | { | ||
527 | 511 | if (matcher.key.match (action.title)) | ||
528 | 512 | { | ||
529 | 513 | result.add (action, matcher.value - Match.Score.INCREMENT_SMALL); | ||
530 | 514 | break; | ||
531 | 515 | } | ||
532 | 516 | } | ||
533 | 517 | } | ||
534 | 518 | |||
535 | 519 | q.check_cancellable (); | ||
536 | 520 | |||
537 | 521 | return result; | ||
538 | 522 | } | ||
539 | 523 | } | ||
540 | 524 | } | ||
541 | 0 | \ No newline at end of file | 525 | \ No newline at end of file |
542 | 1 | 526 | ||
543 | === modified file 'src/Backend/SynapseSearch.vala' | |||
544 | --- src/Backend/SynapseSearch.vala 2014-06-29 14:50:36 +0000 | |||
545 | +++ src/Backend/SynapseSearch.vala 2015-05-20 17:20:28 +0000 | |||
546 | @@ -23,7 +23,8 @@ | |||
547 | 23 | private static Type[] plugins = { | 23 | private static Type[] plugins = { |
548 | 24 | typeof (Synapse.CalculatorPlugin), | 24 | typeof (Synapse.CalculatorPlugin), |
549 | 25 | typeof (Synapse.CommandPlugin), | 25 | typeof (Synapse.CommandPlugin), |
551 | 26 | typeof (Synapse.DesktopFilePlugin) | 26 | typeof (Synapse.DesktopFilePlugin), |
552 | 27 | typeof (Synapse.SystemManagementPlugin) | ||
553 | 27 | }; | 28 | }; |
554 | 28 | 29 | ||
555 | 29 | private static Synapse.DataSink? sink = null; | 30 | private static Synapse.DataSink? sink = null; |