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