Merge lp:~ricotz/plank/dbus into lp:plank

Proposed by Rico Tzschichholz
Status: Merged
Merged at revision: 1197
Proposed branch: lp:~ricotz/plank/dbus
Merge into: lp:plank
Diff against target: 906 lines (+747/-4)
12 files modified
.bzrignore (+4/-0)
Makefile.am (+1/-0)
configure.ac (+1/-0)
docs/Makefile.am (+3/-0)
examples/Makefile.am (+48/-0)
examples/RemoteClient.vala (+65/-0)
lib/DBus/Client.vala (+307/-0)
lib/DBus/Interfaces.vala (+73/-0)
lib/DBusManager.vala (+220/-0)
lib/DockController.vala (+10/-4)
lib/Makefile.am (+3/-0)
lib/libplank.symbols (+12/-0)
To merge this branch: bzr merge lp:~ricotz/plank/dbus
Reviewer Review Type Date Requested Status
Docky Core Pending
Review via email: mp+249177@code.launchpad.net

Description of the change

Provide Client class which discovers and connect to a running dock which provides certain inferfaces to control and manipulate it.

Provide a simple example using the Client class.

To post a comment you must log in.
lp:~ricotz/plank/dbus updated
1182. By Rico Tzschichholz

items: Add boolean return-value to public DockContainer/-Provider methods

This will indicate the success or failure of the corresponding operation.

1183. By Rico Tzschichholz

items: Avoid removal-delay when unpinning an application

Remove an AppDockItem if it doesn't represent a running application and
doesn't have visible remote-info coming via LauncherEntry.

1184. By Rico Tzschichholz

po: Update translations

1185. By Rico Tzschichholz

items: It is an ApplicationDockItem, no need to use "as"

1186. By Rico Tzschichholz

renderer: Draw final internal dock-buffer on window-context at (0,0)

1187. By Rico Tzschichholz

build: Make "distcheck" work independent from originally passed confflags

1188. By Rico Tzschichholz

dockwindow: Drop hack for menu-position with gtk+ 3.15+

Reverts r1158

1189. By Rico Tzschichholz

hidemanager: Add window-dodge hide-mode

1190. By Rico Tzschichholz

po: Update translations

1191. By Rico Tzschichholz

item: Rename protected arraylist-fields *_items to *_elements

1192. By Rico Tzschichholz

dockcontainer: Rename property Elements to VisibleElements

1193. By Rico Tzschichholz

controller: Rename property Items to VisibleItems

1194. By Rico Tzschichholz

controller: Add Items property

Which actually returns a list of all items regardless their visibility.

1195. By Rico Tzschichholz

controller: Call update_items while replacing default_provider

1196. By Rico Tzschichholz

Update symbols

1197. By Rico Tzschichholz

Add DBusManager to provide some useful remotely accessible actions

Provide "net.launchpad.plank.Items" interface with "Add", "Remove",
"GetCount", "GetPersistentApplications" and "GetTransientApplications"
methods.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2014-06-02 14:18:48 +0000
+++ .bzrignore 2015-03-16 17:58:40 +0000
@@ -33,6 +33,9 @@
33docs/c-doc33docs/c-doc
34docs/vala-doc34docs/vala-doc
35docs/web-doc35docs/web-doc
36examples/remote-client
37examples/*.c
38examples/*.stamp
36lib/abi*39lib/abi*
37lib/*-abi40lib/*-abi
38lib/*.c41lib/*.c
@@ -41,6 +44,7 @@
41lib/*.vapi44lib/*.vapi
42lib/*.pc45lib/*.pc
43lib/*.stamp46lib/*.stamp
47lib/DBus/*.c
44lib/Drawing/*.c48lib/Drawing/*.c
45lib/Factories/*.c49lib/Factories/*.c
46lib/Services/*.c50lib/Services/*.c
4751
=== modified file 'Makefile.am'
--- Makefile.am 2015-03-11 16:25:25 +0000
+++ Makefile.am 2015-03-16 17:58:40 +0000
@@ -9,6 +9,7 @@
9 vapi \9 vapi \
10 src \10 src \
11 tests \11 tests \
12 examples \
12 $(NULL)13 $(NULL)
1314
14if HAVE_VALADOC15if HAVE_VALADOC
1516
=== modified file 'configure.ac'
--- configure.ac 2015-01-25 19:35:00 +0000
+++ configure.ac 2015-03-16 17:58:40 +0000
@@ -356,6 +356,7 @@
356docs/Makefile356docs/Makefile
357po/Makefile.in357po/Makefile.in
358tests/Makefile358tests/Makefile
359examples/Makefile
359vapi/Makefile360vapi/Makefile
360])361])
361362
362363
=== modified file 'docs/Makefile.am'
--- docs/Makefile.am 2015-03-11 16:25:25 +0000
+++ docs/Makefile.am 2015-03-16 17:58:40 +0000
@@ -17,6 +17,7 @@
17 $(NULL)17 $(NULL)
1818
19plank_doc_files = \19plank_doc_files = \
20 $(top_srcdir)/lib/DBusManager.vala \
20 $(top_srcdir)/lib/DockController.vala \21 $(top_srcdir)/lib/DockController.vala \
21 $(top_srcdir)/lib/DockPreferences.vala \22 $(top_srcdir)/lib/DockPreferences.vala \
22 $(top_srcdir)/lib/DockRenderer.vala \23 $(top_srcdir)/lib/DockRenderer.vala \
@@ -24,6 +25,8 @@
24 $(top_srcdir)/lib/HideManager.vala \25 $(top_srcdir)/lib/HideManager.vala \
25 $(top_srcdir)/lib/PositionManager.vala \26 $(top_srcdir)/lib/PositionManager.vala \
26 $(top_builddir)/lib/Version.vala \27 $(top_builddir)/lib/Version.vala \
28 $(top_srcdir)/lib/DBus/Client.vala \
29 $(top_srcdir)/lib/DBus/Interfaces.vala \
27 $(top_srcdir)/lib/Drawing/AnimatedRenderer.vala \30 $(top_srcdir)/lib/Drawing/AnimatedRenderer.vala \
28 $(top_srcdir)/lib/Drawing/Color.vala \31 $(top_srcdir)/lib/Drawing/Color.vala \
29 $(top_srcdir)/lib/Drawing/DrawingService.vala \32 $(top_srcdir)/lib/Drawing/DrawingService.vala \
3033
=== added directory 'examples'
=== added file 'examples/Makefile.am'
--- examples/Makefile.am 1970-01-01 00:00:00 +0000
+++ examples/Makefile.am 2015-03-16 17:58:40 +0000
@@ -0,0 +1,48 @@
1include $(top_srcdir)/Makefile.common
2
3remote_client_VALAFLAGS = \
4 $(PLANK_CORE_VALAFLAGS) \
5 $(top_builddir)/lib/plank.vapi \
6 --vapidir $(top_srcdir)/vapi \
7 -C \
8 $(NULL)
9
10BUILT_SOURCES = remote_client_vala.stamp
11
12noinst_PROGRAMS = remote-client
13
14remote_client_CFLAGS = \
15 $(PLANK_CORE_CFLAGS) \
16 -include config.h \
17 -w \
18 -I$(top_builddir)/lib \
19 $(NULL)
20
21remote_client_LDADD = \
22 $(PLANK_CORE_LIBS) \
23 $(top_builddir)/lib/libplank.la \
24 $(NULL)
25
26remote_client_VALASOURCES = \
27 RemoteClient.vala \
28 $(NULL)
29
30nodist_remote_client_SOURCES = \
31 remote_client_vala.stamp \
32 $(remote_client_VALASOURCES:.vala=.c) \
33 $(NULL)
34
35remote_client_vala.stamp: $(remote_client_VALASOURCES) $(top_builddir)/lib/plank.vapi Makefile
36 $(AM_V_VALA)$(VALAC) \
37 $(remote_client_VALAFLAGS) \
38 $(filter %.vala %.c,$^)
39 $(AM_V_at)touch $@
40
41CLEANFILES = \
42 $(nodist_remote_client_SOURCES) \
43 $(NULL)
44
45EXTRA_DIST = \
46 $(remote_client_VALASOURCES) \
47 $(NULL)
48
049
=== added file 'examples/RemoteClient.vala'
--- examples/RemoteClient.vala 1970-01-01 00:00:00 +0000
+++ examples/RemoteClient.vala 2015-03-16 17:58:40 +0000
@@ -0,0 +1,65 @@
1//
2// Copyright (C) 2015 Rico Tzschichholz
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//
17
18using Plank.DBus;
19using Plank.Services;
20
21namespace Plank.Examples
22{
23 public class RemoteClient : GLib.Application
24 {
25 construct
26 {
27 application_id = "net.launchpad.plank.remote-client";
28 flags = ApplicationFlags.FLAGS_NONE;
29
30 Logger.initialize ("remote-client");
31 Logger.DisplayLevel = LogLevel.DEBUG;
32 }
33
34 public override void activate ()
35 {
36 hold ();
37
38 var client = Client.get_instance ();
39 client.proxy_changed.connect (handle_proxy_changed);
40 }
41
42 void handle_proxy_changed (Client client)
43 {
44 if (!client.is_connected)
45 return;
46
47 print ("List all persistent applications:\n");
48 foreach (unowned string s in client.get_persistent_applications ())
49 print (" + %s\n", s);
50
51 print ("List all transient applications:\n");
52 foreach (unowned string s in client.get_transient_applications ())
53 print (" + %s\n", s);
54
55 print ("\n");
56 }
57
58 public static int main (string[] args)
59 {
60 var application = new RemoteClient ();
61 return application.run (args);
62 }
63
64 }
65}
066
=== added directory 'lib/DBus'
=== added file 'lib/DBus/Client.vala'
--- lib/DBus/Client.vala 1970-01-01 00:00:00 +0000
+++ lib/DBus/Client.vala 2015-03-16 17:58:40 +0000
@@ -0,0 +1,307 @@
1//
2// Copyright (C) 2015 Rico Tzschichholz
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//
17
18namespace Plank.DBus
19{
20 /**
21 * Connects to a running instance of plank via DBus and
22 * provides remote interface to a currently runnning dock.
23 */
24 public class Client : GLib.Object
25 {
26 static Client? instance;
27
28 /**
29 * Get the singleton instance of {@link Plank.DBus.Client}
30 */
31 public static unowned Client get_instance ()
32 {
33 if (instance == null)
34 instance = new Client ();
35
36 return instance;
37 }
38
39 /**
40 * If the proxy interfaces for the dock are ready to be used
41 * or were changed on runtime this signal will be emitted.
42 */
43 public signal void proxy_changed ();
44
45 /**
46 * Whether the client is in an operatable state and connected to
47 * a running dock
48 */
49 public bool is_connected {
50 get {
51 return (items_proxy != null);
52 }
53 }
54
55 DBusConnection? connection = null;
56 string? client_object_path;
57
58 string? dock_bus_owner;
59 string? dock_bus_name;
60 string? dock_object_path;
61
62 uint dbus_dock_ping_id = 0;
63 uint dbus_name_owner_changed_signal_id = 0;
64
65 ItemsIface? items_proxy = null;
66 int items_count = int.MIN;
67 string[]? persistent_apps_list = null;
68 string[]? transient_apps_list = null;
69
70 Client ()
71 {
72 Object ();
73 }
74
75 construct
76 {
77 unowned Application? application = GLib.Application.get_default ();
78 unowned string? object_path = null;
79
80 if (application != null) {
81 connection = application.get_dbus_connection ();
82 object_path = application.get_dbus_object_path ();
83 }
84
85 if (connection == null || object_path == null) {
86 critical ("Initializing client failed");
87 return;
88 }
89
90 try {
91 // Listen for "Ping" signals coming from docks
92 dbus_dock_ping_id = connection.signal_subscribe (null, Plank.DBus.DOCK_INTERFACE_NAME,
93 Plank.DBus.PING_NAME, null, null, DBusSignalFlags.NONE, handle_dock_ping);
94 } catch (IOError e) {
95 warning ("Could not subscribe for dock signal (%s)", e.message);
96 }
97
98 dbus_name_owner_changed_signal_id = connection.signal_subscribe ("org.freedesktop.DBus", "org.freedesktop.DBus",
99 "NameOwnerChanged", "/org/freedesktop/DBus", null, DBusSignalFlags.NONE, handle_name_owner_changed);
100
101 client_object_path = object_path;
102
103 try {
104 // Broadcast to inform running docks
105 connection.emit_signal (null, client_object_path, Plank.DBus.CLIENT_INTERFACE_NAME, Plank.DBus.PING_NAME, null);
106 } catch (Error e) {
107 warning ("Could not ping running docks (%s)", e.message);
108 }
109 }
110
111 ~Client ()
112 {
113 if (connection != null) {
114 if (dbus_dock_ping_id > 0)
115 connection.signal_unsubscribe (dbus_dock_ping_id);
116 if (dbus_name_owner_changed_signal_id > 0)
117 connection.signal_unsubscribe (dbus_name_owner_changed_signal_id);
118 }
119 }
120
121 void handle_dock_ping (DBusConnection connection, string sender_name, string object_path,
122 string interface_name, string signal_name, Variant parameters)
123 {
124 if (dock_bus_name == null && dock_bus_name != sender_name)
125 connect_proxies (connection, sender_name, object_path);
126 }
127
128 void handle_name_owner_changed (DBusConnection connection, string sender_name, string object_path,
129 string interface_name, string signal_name, Variant parameters)
130 {
131 string name, before, after;
132 parameters.get ("(sss)", out name, out before, out after);
133
134 if (dock_bus_owner != null && dock_bus_owner == after)
135 return;
136
137 if (name != null && name != "" && name != dock_bus_name)
138 return;
139
140 if (after == null || after == "") {
141 disconnect_proxies ();
142 return;
143 }
144
145 connect_proxies (connection, name, object_path);
146 }
147
148 void connect_proxies (DBusConnection connection, string sender_name, string object_path)
149 {
150 debug ("Connecting and create proxies for '%s' (%s)", sender_name, object_path);
151
152 try {
153 items_proxy = connection.get_proxy_sync<Plank.DBus.ItemsIface> (sender_name, object_path, DBusProxyFlags.NONE);
154 items_proxy.changed.connect (invalidate_items_cache);
155 dock_bus_owner = ((DBusProxy) items_proxy).get_name_owner ();
156 dock_bus_name = sender_name;
157 dock_object_path = object_path;
158 } catch (Error e) {
159 dock_bus_owner = null;
160 dock_bus_name = null;
161 dock_object_path = null;
162
163 items_proxy = null;
164 critical ("Failed to create items proxy for '%s' (%s)", sender_name, object_path);
165 }
166
167 proxy_changed ();
168 }
169
170 void disconnect_proxies ()
171 {
172 debug ("Disconnecting from '%s' (%s)", dock_bus_name, dock_object_path);
173
174 dock_bus_owner = null;
175 dock_bus_name = null;
176 dock_object_path = null;
177
178 items_proxy.changed.disconnect (invalidate_items_cache);
179 items_proxy = null;
180 }
181
182
183 void invalidate_items_cache ()
184 {
185 items_count = int.MIN;
186 persistent_apps_list = null;
187 transient_apps_list = null;
188 }
189
190 /**
191 * Add a new item for the given uri to the dock
192 *
193 * @param uri an URI
194 * @return whether it was successfully added
195 */
196 public bool add_item (string uri)
197 {
198 if (items_proxy == null) {
199 warning ("No proxy connected");
200 return false;
201 }
202
203 try {
204 return items_proxy.add (uri);
205 } catch (IOError e) {
206 warning (e.message);
207 return false;
208 }
209 }
210
211 /**
212 * Remove an existing item for the given uri from the dock
213 *
214 * @param uri an URI
215 * @return whether it was successfully removed
216 */
217 public bool remove_item (string uri)
218 {
219 if (items_proxy == null) {
220 warning ("No proxy connected");
221 return false;
222 }
223
224 try {
225 return items_proxy.remove (uri);
226 } catch (IOError e) {
227 warning (e.message);
228 return false;
229 }
230 }
231
232 /**
233 * Returns the number of currently visible items on the dock
234 *
235 * @return the item-count
236 */
237 public int get_items_count ()
238 {
239 if (items_proxy == null) {
240 warning ("No proxy connected");
241 return -1;
242 }
243
244 try {
245 if (items_count == int.MIN)
246 items_count = items_proxy.get_count ();
247 } catch (IOError e) {
248 warning (e.message);
249 return -1;
250 }
251
252 return items_count;
253 }
254
255 /**
256 * Returns an array of uris of the persistent applications on the dock
257 *
258 * @return the array of uris
259 */
260 public unowned string[]? get_persistent_applications ()
261 {
262 if (items_proxy == null) {
263 warning ("No proxy connected");
264 return null;
265 }
266
267 if (persistent_apps_list != null)
268 return persistent_apps_list;
269
270 try {
271 if (persistent_apps_list == null)
272 persistent_apps_list = items_proxy.get_persistent_applications ();
273 return persistent_apps_list;
274 } catch (IOError e) {
275 warning (e.message);
276 }
277
278 return null;
279 }
280
281 /**
282 * Returns an array of uris of the transient applications on the dock
283 *
284 * @return the array of uris
285 */
286 public unowned string[]? get_transient_applications ()
287 {
288 if (items_proxy == null) {
289 warning ("No proxy connected");
290 return null;
291 }
292
293 if (transient_apps_list != null)
294 return transient_apps_list;
295
296 try {
297 if (transient_apps_list == null)
298 transient_apps_list = items_proxy.get_transient_applications ();
299 return transient_apps_list;
300 } catch (IOError e) {
301 warning (e.message);
302 }
303
304 return null;
305 }
306 }
307}
0308
=== added file 'lib/DBus/Interfaces.vala'
--- lib/DBus/Interfaces.vala 1970-01-01 00:00:00 +0000
+++ lib/DBus/Interfaces.vala 2015-03-16 17:58:40 +0000
@@ -0,0 +1,73 @@
1//
2// Copyright (C) 2015 Rico Tzschichholz
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//
17
18namespace Plank.DBus
19{
20 const string PING_NAME = "Ping";
21
22 const string DOCK_INTERFACE_NAME = "net.launchpad.plank";
23 const string CLIENT_INTERFACE_NAME = "net.launchpad.plank.Client";
24
25 /**
26 * Provide an interface to manage items of the dock
27 */
28 [DBus (name = "net.launchpad.plank.Items")]
29 interface ItemsIface : GLib.Object
30 {
31 /**
32 * Emmited when items are changed
33 */
34 public signal void changed ();
35
36 /**
37 * Add a new item for the given uri to the dock
38 *
39 * @param uri an URI
40 * @return whether it was successfully added
41 */
42 public abstract bool add (string uri) throws GLib.IOError;
43
44 /**
45 * Remove an existing item for the given uri from the dock
46 *
47 * @param uri an URI
48 * @return whether it was successfully removed
49 */
50 public abstract bool remove (string uri) throws GLib.IOError;
51
52 /**
53 * Returns the number of currently visible items on the dock
54 *
55 * @return the item-count
56 */
57 public abstract int get_count () throws GLib.IOError;
58
59 /**
60 * Returns an array of uris of the persistent applications on the dock
61 *
62 * @return the array of uris
63 */
64 public abstract string[] get_persistent_applications () throws GLib.IOError;
65
66 /**
67 * Returns an array of uris of the transient applications on the dock
68 *
69 * @return the array of uris
70 */
71 public abstract string[] get_transient_applications () throws GLib.IOError;
72 }
73}
074
=== added file 'lib/DBusManager.vala'
--- lib/DBusManager.vala 1970-01-01 00:00:00 +0000
+++ lib/DBusManager.vala 2015-03-16 17:58:40 +0000
@@ -0,0 +1,220 @@
1//
2// Copyright (C) 2015 Rico Tzschichholz
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16//
17
18using Plank.Factories;
19using Plank.Items;
20using Plank.Services;
21
22namespace Plank
23{
24 /**
25 * Provide an interface to manage items of the dock
26 */
27 class DBusItems : GLib.Object, Plank.DBus.ItemsIface
28 {
29 DockController controller;
30 uint changed_timer = 0;
31
32 public DBusItems (DockController _controller)
33 {
34 controller = _controller;
35 controller.items_changed.connect (handle_items_changed);
36 }
37
38 ~DBusItems ()
39 {
40 controller.items_changed.disconnect (handle_items_changed);
41
42 if (changed_timer > 0) {
43 GLib.Source.remove (changed_timer);
44 changed_timer = 0;
45 }
46 }
47
48 void handle_items_changed ()
49 {
50 if (changed_timer > 0)
51 return;
52
53 // Fire updates with a reasonable rate
54 changed_timer = Timeout.add (500, () => {
55 changed_timer = 0;
56 changed ();
57 return false;
58 });
59 }
60
61 public bool add (string uri)
62 {
63 debug ("Try to remotely add '%s'", uri);
64
65 unowned ApplicationDockItemProvider? provider = controller.default_provider;
66 if (provider == null)
67 return false;
68
69 unowned DockItem? item = provider.item_for_uri (uri);
70 if (item != null && item is TransientDockItem) {
71 ((TransientDockItem) item).pin_launcher ();
72 return true;
73 }
74
75 return provider.add_item_with_uri (uri);
76 }
77
78 public bool remove (string uri)
79 {
80 debug ("Try to remotely remove '%s'", uri);
81
82 unowned ApplicationDockItemProvider? provider = controller.default_provider;
83 if (provider == null)
84 return false;
85
86 unowned DockItem? item = provider.item_for_uri (uri);
87 if (item == null)
88 return false;
89
90 if (item is ApplicationDockItem) {
91 if (!(item is TransientDockItem))
92 ((ApplicationDockItem) item).pin_launcher ();
93 return true;
94 }
95
96 return provider.remove_item (item);
97 }
98
99 public int get_count ()
100 {
101 return controller.VisibleItems.size;
102 }
103
104 public string[] get_persistent_applications ()
105 {
106 Logger.verbose ("Remotely list persistent items");
107
108 var items = controller.Items;
109
110 string[] result = {};
111 unowned string launcher;
112 foreach (unowned DockItem item in items) {
113 if (item is ApplicationDockItem && !(item is TransientDockItem)) {
114 launcher = item.Launcher;
115 if (launcher != null && launcher != "")
116 result += launcher;
117 }
118 }
119
120 return result;
121 }
122
123 public string[] get_transient_applications ()
124 {
125 Logger.verbose ("Remotely list transient items");
126
127 var items = controller.Items;
128
129 string[] result = {};
130 unowned string launcher;
131 foreach (unowned DockItem item in items) {
132 if (item is TransientDockItem) {
133 launcher = item.Launcher;
134 if (launcher != null && launcher != "")
135 result += launcher;
136 }
137 }
138
139 return result;
140 }
141 }
142
143 /**
144 * Handles all the exported DBus functions of the dock
145 */
146 public class DBusManager : GLib.Object
147 {
148 public DockController controller { private get; construct; }
149
150 string? dock_object_path;
151
152 uint dbus_items_id = 0;
153 uint dbus_client_ping_id = 0;
154
155 public DBusManager (DockController controller)
156 {
157 Object (controller: controller);
158 }
159
160 construct
161 {
162 unowned Application application = Application.get_default ();
163 unowned DBusConnection connection = application.get_dbus_connection ();
164 unowned string? object_path = application.get_dbus_object_path ();
165
166 if (connection == null || object_path == null) {
167 critical ("Not able to register our interfaces");
168 return;
169 }
170
171 // Listen for "Ping" signals coming from clients
172 try {
173 dbus_client_ping_id = connection.signal_subscribe (null, Plank.DBus.CLIENT_INTERFACE_NAME,
174 Plank.DBus.PING_NAME, null, null, DBusSignalFlags.NONE, handle_client_ping);
175 } catch (IOError e) {
176 warning ("Could not subscribe for client signal (%s)", e.message);
177 }
178
179 try {
180 var dbus_items = new DBusItems (controller);
181 dbus_items_id = connection.register_object<Plank.DBus.ItemsIface> (object_path, dbus_items);
182 } catch (IOError e) {
183 warning ("Could not register service (%s)", e.message);
184 }
185
186 dock_object_path = object_path;
187
188 try {
189 // Broadcast to inform running clients
190 connection.emit_signal (null, dock_object_path, Plank.DBus.DOCK_INTERFACE_NAME, Plank.DBus.PING_NAME, null);
191 } catch (Error e) {
192 warning ("Could not ping running clients (%s)", e.message);
193 }
194 }
195
196 ~DBusManager ()
197 {
198 unowned Application application = Application.get_default ();
199 unowned DBusConnection connection = application.get_dbus_connection ();
200
201 if (connection != null) {
202 if (dbus_items_id > 0)
203 connection.unregister_object (dbus_items_id);
204 if (dbus_client_ping_id > 0)
205 connection.signal_unsubscribe (dbus_client_ping_id);
206 }
207 }
208
209 void handle_client_ping (DBusConnection connection, string sender_name, string object_path,
210 string interface_name, string signal_name, Variant parameters)
211 {
212 try {
213 // Broadcast to inform running clients
214 connection.emit_signal (null, dock_object_path, Plank.DBus.DOCK_INTERFACE_NAME, Plank.DBus.PING_NAME, null);
215 } catch (Error e) {
216 warning ("Could not ping running clients (%s)", e.message);
217 }
218 }
219 }
220}
0221
=== modified file 'lib/DockController.vala'
--- lib/DockController.vala 2015-03-16 17:44:57 +0000
+++ lib/DockController.vala 2015-03-16 17:58:40 +0000
@@ -42,7 +42,9 @@
42 public DockRenderer renderer { get; protected set; }42 public DockRenderer renderer { get; protected set; }
43 public DockWindow window { get; protected set; }43 public DockWindow window { get; protected set; }
44 44
45 ApplicationDockItemProvider? default_provider;45 public ApplicationDockItemProvider? default_provider { get; private set; }
46
47 DBusManager dbus_manager;
46 Gee.ArrayList<unowned DockItem> visible_items;48 Gee.ArrayList<unowned DockItem> visible_items;
47 Gee.ArrayList<unowned DockItem> items;49 Gee.ArrayList<unowned DockItem> items;
48 50
@@ -90,6 +92,8 @@
90 92
91 prefs.notify["PinnedOnly"].connect (update_default_provider);93 prefs.notify["PinnedOnly"].connect (update_default_provider);
92 94
95 dbus_manager = new DBusManager (this);
96
93 position_manager = new PositionManager (this);97 position_manager = new PositionManager (this);
94 drag_manager = new DragManager (this);98 drag_manager = new DragManager (this);
95 hide_manager = new HideManager (this);99 hide_manager = new HideManager (this);
@@ -135,12 +139,12 @@
135 return;139 return;
136 140
137 Logger.verbose ("DockController.add_default_provider ()");141 Logger.verbose ("DockController.add_default_provider ()");
138 default_provider = get_default_provider ();142 default_provider = create_default_provider ();
139 143
140 add_item (default_provider);144 add_item (default_provider);
141 }145 }
142 146
143 ApplicationDockItemProvider get_default_provider ()147 ApplicationDockItemProvider create_default_provider ()
144 {148 {
145 ApplicationDockItemProvider provider;149 ApplicationDockItemProvider provider;
146 150
@@ -169,7 +173,7 @@
169 return;173 return;
170 174
171 var old_default_provider = default_provider;175 var old_default_provider = default_provider;
172 default_provider = get_default_provider ();176 default_provider = create_default_provider ();
173 default_provider.prepare ();177 default_provider.prepare ();
174 replace_item (default_provider, old_default_provider);178 replace_item (default_provider, old_default_provider);
175 179
@@ -275,6 +279,8 @@
275 position_manager.update_regions ();279 position_manager.update_regions ();
276 }280 }
277 window.update_icon_regions ();281 window.update_icon_regions ();
282
283 items_changed (added, removed);
278 }284 }
279 285
280 void handle_item_positions_changed (DockContainer provider, Gee.List<unowned DockElement> moved_items)286 void handle_item_positions_changed (DockContainer provider, Gee.List<unowned DockElement> moved_items)
281287
=== modified file 'lib/Makefile.am'
--- lib/Makefile.am 2015-01-22 10:24:51 +0000
+++ lib/Makefile.am 2015-03-16 17:58:40 +0000
@@ -61,12 +61,15 @@
61 $(NULL)61 $(NULL)
6262
63libplank_la_VALASOURCES = \63libplank_la_VALASOURCES = \
64 DBusManager.vala \
64 DockController.vala \65 DockController.vala \
65 DockPreferences.vala \66 DockPreferences.vala \
66 DockRenderer.vala \67 DockRenderer.vala \
67 DragManager.vala \68 DragManager.vala \
68 HideManager.vala \69 HideManager.vala \
69 PositionManager.vala \70 PositionManager.vala \
71 DBus/Client.vala \
72 DBus/Interfaces.vala \
70 Drawing/AnimatedRenderer.vala \73 Drawing/AnimatedRenderer.vala \
71 Drawing/Color.vala \74 Drawing/Color.vala \
72 Drawing/DrawingService.vala \75 Drawing/DrawingService.vala \
7376
=== modified file 'lib/libplank.symbols'
--- lib/libplank.symbols 2015-03-16 17:47:28 +0000
+++ lib/libplank.symbols 2015-03-16 17:58:40 +0000
@@ -1,6 +1,18 @@
1plank_dbus_client_add_item
2plank_dbus_client_get_instance
3plank_dbus_client_get_is_connected
4plank_dbus_client_get_items_count
5plank_dbus_client_get_persistent_applications
6plank_dbus_client_get_transient_applications
7plank_dbus_client_get_type
8plank_dbus_client_remove_item
9plank_dbus_manager_construct
10plank_dbus_manager_get_type
11plank_dbus_manager_new
1plank_dock_controller_add_default_provider12plank_dock_controller_add_default_provider
2plank_dock_controller_construct13plank_dock_controller_construct
3plank_dock_controller_get_config_folder14plank_dock_controller_get_config_folder
15plank_dock_controller_get_default_provider
4plank_dock_controller_get_drag_manager16plank_dock_controller_get_drag_manager
5plank_dock_controller_get_hide_manager17plank_dock_controller_get_hide_manager
6plank_dock_controller_get_Items18plank_dock_controller_get_Items

Subscribers

People subscribed via source and target branches

to status/vote changes: