Merge lp:~docky-core/plank/launcher-uri into lp:plank

Proposed by Rico Tzschichholz
Status: Merged
Approved by: Rico Tzschichholz
Approved revision: 741
Merged at revision: 739
Proposed branch: lp:~docky-core/plank/launcher-uri
Merge into: lp:plank
Diff against target: 363 lines (+105/-46)
9 files modified
lib/DockItems.vala (+19/-7)
lib/DragManager.vala (+2/-2)
lib/Factories/ItemFactory.vala (+42/-26)
lib/Items/ApplicationDockItem.vala (+5/-5)
lib/Items/DockItem.vala (+1/-1)
lib/Items/DockItemPreferences.vala (+18/-1)
lib/Items/FileDockItem.vala (+8/-2)
lib/Services/Matcher.vala (+9/-1)
lib/libplank.symbols (+1/-1)
To merge this branch: bzr merge lp:~docky-core/plank/launcher-uri
Reviewer Review Type Date Requested Status
Sergey "Shnatsel" Davidoff (community) Approve
Robert Dyer (community) Needs Fixing
Review via email: mp+145318@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Robert Dyer (psybers) wrote :

diff lines 94-106 -> each individual to_uri call needs its own try/catch block

This is because the first one might be invalid, but the rest may be valid. With 1 try/catch, if the first throws then none will be added to the dock. Individual try/catches will only skip ones that threw individually.

review: Needs Fixing
Revision history for this message
Robert Dyer (psybers) wrote :

Have you extensively tested this?

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

> diff lines 94-106 -> each individual to_uri call needs its own try/catch block
>
> This is because the first one might be invalid, but the rest may be valid.
> With 1 try/catch, if the first throws then none will be added to the dock.
> Individual try/catches will only skip ones that threw individually.

Yeah I know I was lazy here :\

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

> Have you extensively tested this?

As far as I can. It will transition old dockitem's Launcher entries to the new uri scheme. Of course old plank versions can't handle them afterwards.

I was hoping you will give it a spin. Especially in regards to https://bugs.launchpad.net/plank/+bug/1058468

lp:~docky-core/plank/launcher-uri updated
735. By Rico Tzschichholz

items: No need for a SeparatorMenuItem if the associated folder is empty

736. By Rico Tzschichholz

main: Avoid calling Poxis.exit ()

Change the way we are passing the commandline-arguments through the
initalization methods and return EXIT_SUCCESS or EXIT_FAILURE to the
actual main function

737. By Rico Tzschichholz

items: Validate an item before adding it here too

739. By Rico Tzschichholz

Handle errors separately in make_default_gnome_items

740. By Rico Tzschichholz

Better use string.has_prefix ()

741. By Rico Tzschichholz

Handle get_desktop_file () == null

Revision history for this message
Sergey "Shnatsel" Davidoff (shnatsel) wrote :

The transition from plain filenames worked fine for me in the latest revision; I have some dangling .dockitem files in launchers folder, they were properly ignored. I didn't notice any regressions. Loading URLs other than file:// doesn't seem to work, but I believe this is out of scope of this branch.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/DockItems.vala'
2--- lib/DockItems.vala 2013-01-30 18:16:04 +0000
3+++ lib/DockItems.vala 2013-01-30 18:21:19 +0000
4@@ -170,12 +170,25 @@
5
6 ApplicationDockItem? item_for_application (Bamf.Application app)
7 {
8+ var app_desktop_file = app.get_desktop_file ();
9+ if (app_desktop_file != null && app_desktop_file.has_prefix ("/"))
10+ try {
11+ app_desktop_file = Filename.to_uri (app_desktop_file);
12+ } catch (ConvertError e) {
13+ warning (e.message);
14+ }
15+
16 foreach (var item in internal_items) {
17 unowned ApplicationDockItem? appitem = (item as ApplicationDockItem);
18 if (appitem == null)
19 continue;
20- if ((appitem.App != null && appitem.App == app) || (appitem.Launcher != null
21- && appitem.Launcher != "" && appitem.Launcher == app.get_desktop_file ()))
22+
23+ var item_app = appitem.App;
24+ if (item_app != null && item_app == app)
25+ return appitem;
26+
27+ var launcher = appitem.Launcher;
28+ if (launcher != "" && app_desktop_file != null && launcher == app_desktop_file)
29 return appitem;
30 }
31
32@@ -184,23 +197,22 @@
33
34 public bool item_exists_for_uri (string uri)
35 {
36- var launcher = uri.replace ("file://", "");
37 foreach (var item in internal_items)
38- if (item.Launcher == launcher)
39+ if (item.Launcher == uri)
40 return true;
41
42 return false;
43 }
44
45- public void add_item_with_launcher (string launcher, DockItem? target = null)
46+ public void add_item_with_uri (string uri, DockItem? target = null)
47 {
48- if (launcher == null || launcher == "")
49+ if (uri == null || uri == "")
50 return;
51
52 // delay automatic add of new dockitems while creating this new one
53 delay_items_monitor ();
54
55- var dockitem_file = Factory.item_factory.make_dock_item (launcher);
56+ var dockitem_file = Factory.item_factory.make_dock_item (uri);
57 if (dockitem_file == null)
58 return;
59
60
61=== modified file 'lib/DragManager.vala'
62--- lib/DragManager.vala 2013-01-21 11:57:33 +0000
63+++ lib/DragManager.vala 2013-01-30 18:21:19 +0000
64@@ -221,7 +221,7 @@
65 if (DragIsDesktopFile) {
66 var uri = drag_data[0];
67 if (!controller.items.item_exists_for_uri (uri))
68- controller.items.add_item_with_launcher (uri.replace ("file://", ""), item);
69+ controller.items.add_item_with_uri (uri, item);
70
71 ExternalDragActive = false;
72 return true;
73@@ -232,7 +232,7 @@
74 } else {
75 foreach (var uri in drag_data) {
76 if (!controller.items.item_exists_for_uri (uri))
77- controller.items.add_item_with_launcher (uri.replace ("file://", ""), item);
78+ controller.items.add_item_with_uri (uri, item);
79 }
80 }
81
82
83=== modified file 'lib/Factories/ItemFactory.vala'
84--- lib/Factories/ItemFactory.vala 2013-01-21 11:57:33 +0000
85+++ lib/Factories/ItemFactory.vala 2013-01-30 18:21:19 +0000
86@@ -87,13 +87,29 @@
87 return false;
88
89 if (browser != null)
90- make_dock_item (new DesktopAppInfo (browser.get_id ()).get_filename ());
91+ try {
92+ make_dock_item (Filename.to_uri (new DesktopAppInfo (browser.get_id ()).get_filename ()));
93+ } catch (ConvertError e) {
94+ warning (e.message);
95+ }
96 if (terminal != null)
97- make_dock_item (new DesktopAppInfo (terminal.get_id ()).get_filename ());
98+ try {
99+ make_dock_item (Filename.to_uri (new DesktopAppInfo (terminal.get_id ()).get_filename ()));
100+ } catch (ConvertError e) {
101+ warning (e.message);
102+ }
103 if (calendar != null)
104- make_dock_item (new DesktopAppInfo (calendar.get_id ()).get_filename ());
105+ try {
106+ make_dock_item (Filename.to_uri (new DesktopAppInfo (calendar.get_id ()).get_filename ()));
107+ } catch (ConvertError e) {
108+ warning (e.message);
109+ }
110 if (media != null)
111- make_dock_item (new DesktopAppInfo (media.get_id ()).get_filename ());
112+ try {
113+ make_dock_item (Filename.to_uri (new DesktopAppInfo (media.get_id ()).get_filename ()));
114+ } catch (ConvertError e) {
115+ warning (e.message);
116+ }
117
118 return true;
119 }
120@@ -104,50 +120,50 @@
121 public void make_default_items ()
122 {
123 // add plank item!
124- make_dock_item ((Paths.DataFolder.get_parent ().get_path () ?? "") + "/applications/" + Factory.main.app_launcher);
125+ make_dock_item (Paths.DataFolder.get_parent ().get_child ("applications").get_child (Factory.main.app_launcher).get_uri ());
126
127 if (make_default_gnome_items ())
128 return;
129
130 // add browser
131- if (make_dock_item ("/usr/share/applications/chromium-browser.desktop") == null)
132- if (make_dock_item ("/usr/local/share/applications/google-chrome.desktop") == null)
133- if (make_dock_item ("/usr/share/applications/firefox.desktop") == null)
134- if (make_dock_item ("/usr/share/applications/epiphany.desktop") == null)
135- make_dock_item ("/usr/share/applications/kde4/konqbrowser.desktop");
136+ if (make_dock_item ("file:///usr/share/applications/chromium-browser.desktop") == null)
137+ if (make_dock_item ("file:///usr/local/share/applications/google-chrome.desktop") == null)
138+ if (make_dock_item ("file:///usr/share/applications/firefox.desktop") == null)
139+ if (make_dock_item ("file:///usr/share/applications/epiphany.desktop") == null)
140+ make_dock_item ("file:///usr/share/applications/kde4/konqbrowser.desktop");
141
142 // add terminal
143- if (make_dock_item ("/usr/share/applications/terminator.desktop") == null)
144- if (make_dock_item ("/usr/share/applications/gnome-terminal.desktop") == null)
145- make_dock_item ("/usr/share/applications/kde4/konsole.desktop");
146+ if (make_dock_item ("file:///usr/share/applications/terminator.desktop") == null)
147+ if (make_dock_item ("file:///usr/share/applications/gnome-terminal.desktop") == null)
148+ make_dock_item ("file:///usr/share/applications/kde4/konsole.desktop");
149
150 // add music player
151- if (make_dock_item ("/usr/share/applications/exaile.desktop") == null)
152- if (make_dock_item ("/usr/share/applications/songbird.desktop") == null)
153- if (make_dock_item ("/usr/share/applications/rhythmbox.desktop") == null)
154- if (make_dock_item ("/usr/share/applications/banshee-1.desktop") == null)
155- make_dock_item ("/usr/share/applications/kde4/amarok.desktop");
156+ if (make_dock_item ("file:///usr/share/applications/exaile.desktop") == null)
157+ if (make_dock_item ("file:///usr/share/applications/songbird.desktop") == null)
158+ if (make_dock_item ("file:///usr/share/applications/rhythmbox.desktop") == null)
159+ if (make_dock_item ("file:///usr/share/applications/banshee-1.desktop") == null)
160+ make_dock_item ("file:///usr/share/applications/kde4/amarok.desktop");
161
162 // add IM client
163- if (make_dock_item ("/usr/share/applications/pidgin.desktop") == null)
164- make_dock_item ("/usr/share/applications/empathy.desktop");
165+ if (make_dock_item ("file:///usr/share/applications/pidgin.desktop") == null)
166+ make_dock_item ("file:///usr/share/applications/empathy.desktop");
167 }
168
169 /**
170- * Creates a new .dockitem for a launcher.
171+ * Creates a new .dockitem for a uri.
172 *
173- * @param launcher the launcher to create a .dockitem for
174+ * @param uri the uri or path to create a .dockitem for
175 * @param sort the Sort value in the new .dockitem
176 * @return the new {@link GLib.File} of the new .dockitem created
177 */
178- public GLib.File? make_dock_item (string launcher)
179+ public GLib.File? make_dock_item (string uri)
180 {
181- var launcher_file = File.new_for_path (launcher);
182+ var launcher_file = File.new_for_uri (uri);
183
184 if (launcher_file.query_exists ()) {
185 var file = new KeyFile ();
186
187- file.set_string (typeof (Items.DockItemPreferences).name (), "Launcher", launcher);
188+ file.set_string (typeof (Items.DockItemPreferences).name (), "Launcher", uri);
189
190 try {
191 // find a unique file name, based on the name of the launcher
192@@ -166,7 +182,7 @@
193 stream.put_string (file.to_data ());
194 stream.close ();
195
196- debug ("Created dock item '%s' for launcher '%s'", dockitem_file.get_path (), launcher);
197+ debug ("Created dock item '%s' for launcher '%s'", dockitem_file.get_path (), uri);
198 return dockitem_file;
199 } catch { }
200 }
201
202=== modified file 'lib/Items/ApplicationDockItem.vala'
203--- lib/Items/ApplicationDockItem.vala 2012-12-15 20:36:01 +0000
204+++ lib/Items/ApplicationDockItem.vala 2013-01-30 18:21:19 +0000
205@@ -186,7 +186,7 @@
206
207 void handle_launcher_changed ()
208 {
209- App = Matcher.get_default ().app_for_launcher (Prefs.Launcher);
210+ App = Matcher.get_default ().app_for_uri (Prefs.Launcher);
211
212 launcher_changed ();
213 }
214@@ -284,7 +284,7 @@
215
216 void launch ()
217 {
218- Services.System.launch (File.new_for_path (Prefs.Launcher));
219+ Services.System.launch (File.new_for_uri (Prefs.Launcher));
220 }
221
222 /**
223@@ -459,7 +459,7 @@
224 foreach (var uri in uris)
225 files.add (File.new_for_uri (uri));
226
227- Services.System.launch_with_files (File.new_for_path (Prefs.Launcher), files.to_array ());
228+ Services.System.launch_with_files (File.new_for_uri (Prefs.Launcher), files.to_array ());
229
230 return true;
231 }
232@@ -504,7 +504,7 @@
233
234 try {
235 var file = new KeyFile ();
236- file.load_from_file (launcher, 0);
237+ file.load_from_file (Filename.from_uri (launcher), 0);
238
239 icon = file.get_string (KeyFileDesktop.GROUP, KeyFileDesktop.KEY_ICON);
240 text = file.get_locale_string (KeyFileDesktop.GROUP, KeyFileDesktop.KEY_NAME);
241@@ -607,7 +607,7 @@
242 return;
243
244 try {
245- monitor = File.new_for_path (Prefs.Launcher).monitor (0);
246+ monitor = File.new_for_uri (Prefs.Launcher).monitor (0);
247 monitor.changed.connect (monitor_changed);
248 } catch {
249 warning ("Unable to watch the launcher file '%s'", Prefs.Launcher);
250
251=== modified file 'lib/Items/DockItem.vala'
252--- lib/Items/DockItem.vala 2013-01-21 11:57:33 +0000
253+++ lib/Items/DockItem.vala 2013-01-30 18:21:19 +0000
254@@ -245,7 +245,7 @@
255 * Whether or not this item is valid for the .dockitem given.
256 */
257 public virtual bool ValidItem {
258- get { return File.new_for_path (Prefs.Launcher).query_exists (); }
259+ get { return File.new_for_uri (Prefs.Launcher).query_exists (); }
260 }
261
262 /**
263
264=== modified file 'lib/Items/DockItemPreferences.vala'
265--- lib/Items/DockItemPreferences.vala 2013-01-21 11:57:33 +0000
266+++ lib/Items/DockItemPreferences.vala 2013-01-30 18:21:19 +0000
267@@ -24,7 +24,7 @@
268 */
269 public class DockItemPreferences : Preferences
270 {
271- [Description(nick = "launcher", blurb = "The path to the launcher for this item.")]
272+ [Description(nick = "launcher", blurb = "The uri for this item.")]
273 public string Launcher { get; set; }
274
275 /**
276@@ -50,5 +50,22 @@
277 {
278 Launcher = "";
279 }
280+
281+ /**
282+ * {@inheritDoc}
283+ */
284+ protected override void verify (string prop)
285+ {
286+ switch (prop) {
287+ case "Launcher":
288+ if (Launcher.has_prefix ("/"))
289+ try {
290+ Launcher = Filename.to_uri (Launcher);
291+ } catch (ConvertError e) {
292+ warning (e.message);
293+ }
294+ break;
295+ }
296+ }
297 }
298 }
299
300=== modified file 'lib/Items/FileDockItem.vala'
301--- lib/Items/FileDockItem.vala 2013-01-29 08:32:24 +0000
302+++ lib/Items/FileDockItem.vala 2013-01-30 18:21:19 +0000
303@@ -59,9 +59,15 @@
304 if (!ValidItem)
305 return;
306
307- OwnedFile = File.new_for_path (Prefs.Launcher);
308+ OwnedFile = File.new_for_uri (Prefs.Launcher);
309
310 Icon = DrawingService.get_icon_from_file (OwnedFile) ?? DEFAULT_ICON;
311+
312+ if (!OwnedFile.is_native ()) {
313+ Text = OwnedFile.get_uri ();
314+ return;
315+ }
316+
317 Text = OwnedFile.get_basename () ?? "";
318
319 // pop up the dir contents on a left click too
320@@ -163,7 +169,7 @@
321
322 void handle_launcher_changed ()
323 {
324- OwnedFile = File.new_for_path (Prefs.Launcher);
325+ OwnedFile = File.new_for_uri (Prefs.Launcher);
326
327 launcher_changed ();
328 }
329
330=== modified file 'lib/Services/Matcher.vala'
331--- lib/Services/Matcher.vala 2012-08-14 14:48:47 +0000
332+++ lib/Services/Matcher.vala 2013-01-30 18:21:19 +0000
333@@ -122,8 +122,16 @@
334 return list;
335 }
336
337- public Bamf.Application? app_for_launcher (string launcher)
338+ public Bamf.Application? app_for_uri (string uri)
339 {
340+ string launcher;
341+ try {
342+ launcher = Filename.from_uri (uri);
343+ } catch (ConvertError e) {
344+ warning (e.message);
345+ return null;
346+ }
347+
348 unowned Bamf.Application app = bamf_matcher.get_application_for_desktop_file (launcher, false);
349
350 warn_if_fail (app != null);
351
352=== modified file 'lib/libplank.symbols'
353--- lib/libplank.symbols 2013-01-21 12:10:22 +0000
354+++ lib/libplank.symbols 2013-01-30 18:21:19 +0000
355@@ -2,7 +2,7 @@
356 plank_dock_controller_get_type
357 plank_dock_controller_new
358 plank_dock_items_add_item
359-plank_dock_items_add_item_with_launcher
360+plank_dock_items_add_item_with_uri
361 plank_dock_items_construct
362 plank_dock_items_get_Items
363 plank_dock_items_get_type

Subscribers

People subscribed via source and target branches

to status/vote changes: