Merge lp:~didrocks/unity-lens-applications/aboutconfig into lp:unity-lens-applications

Proposed by Didier Roche-Tolomelli
Status: Merged
Merged at revision: 178
Proposed branch: lp:~didrocks/unity-lens-applications/aboutconfig
Merge into: lp:unity-lens-applications
Diff against target: 173 lines (+69/-15)
1 file modified
src/runner.vala (+69/-15)
To merge this branch: bzr merge lp:~didrocks/unity-lens-applications/aboutconfig
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+53793@code.launchpad.net

Description of the change

about:config will launch and store in history ccsm -p unityshell (LP: #736765)

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

I agree that it could be nice with an about: namespace that can trigger certain built in actions.

However, before I merge this i'd rather see a more generic implementation where we can easily add/remove stuff under about:. Having a specific hack only for about:config seems well... a hack :-)

Fx. like adding a

private class AboutEntry {
  public string name;
  public string exec;
  public Icon icon;
}

Store them in a list or map and then in get_icon_uri_and_mimetype() check all registered AboutEntries or something...

review: Needs Fixing
180. By Didier Roche-Tolomelli

enable later extension creating a map of AboutEntry

Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

repropose with a map and some extensions :)

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) :
review: Approve
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Merged with a pedantic nullity-fix:

- AboutEntry entry = null;
+ AboutEntry? entry = null;

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/runner.vala'
--- src/runner.vala 2011-03-11 18:03:48 +0000
+++ src/runner.vala 2011-03-17 12:43:32 +0000
@@ -23,6 +23,19 @@
2323
24namespace Unity.ApplicationsPlace {24namespace Unity.ApplicationsPlace {
2525
26 private class AboutEntry {
27 public string name;
28 public string exec;
29 public Icon icon;
30
31 public AboutEntry (string name, string exec, Icon icon)
32 {
33 this.name = name;
34 this.exec = exec;
35 this.icon = icon;
36 }
37 }
38
26 public class Runner: GLib.Object39 public class Runner: GLib.Object
27 { 40 {
28 41
@@ -41,6 +54,7 @@
41 * incremental filtering of the result models */54 * incremental filtering of the result models */
42 private PlaceSearch? previous_search; 55 private PlaceSearch? previous_search;
43 56
57 private Gee.HashMap<string,AboutEntry> about_entries;
44 private Gee.List<string> executables;58 private Gee.List<string> executables;
45 private Gee.List<string> history;59 private Gee.List<string> history;
4660
@@ -64,6 +78,10 @@
6478
65 previous_search = null;79 previous_search = null;
66 80
81 /* create the private about entries */
82 about_entries = new Gee.HashMap<string,AboutEntry> ();
83 load_about_entries ();
84
67 executables = new Gee.ArrayList<string> ();85 executables = new Gee.ArrayList<string> ();
68 find_system_executables.begin ();86 find_system_executables.begin ();
69 87
@@ -111,15 +129,15 @@
111 string uri; 129 string uri;
112 Icon icon;130 Icon icon;
113 string mimetype;131 string mimetype;
132 string display_name;
114 var group_id = RunnerGroup.HISTORY;133 var group_id = RunnerGroup.HISTORY;
115134
116 foreach (var command in this.history)135 foreach (var command in this.history)
117 { 136 {
118 uri = @"unity-runner://$(command)"; 137 display_name = get_icon_uri_and_mimetype (command, out icon, out uri, out mimetype);
119 get_icon_and_mimetype (command, out icon, out mimetype);
120 model.append (uri, icon.to_string (),138 model.append (uri, icon.to_string (),
121 group_id, mimetype,139 group_id, mimetype,
122 command,140 display_name,
123 null);141 null);
124 }142 }
125 143
@@ -231,11 +249,10 @@
231249
232 // populate results250 // populate results
233 // 1. enable launching the exact search string251 // 1. enable launching the exact search string
234 uri = @"unity-runner://$(search_string)"; 252 display_name = get_icon_uri_and_mimetype (search_string, out icon, out uri, out mimetype);
235 get_icon_and_mimetype (search_string, out icon, out mimetype);
236 model.append (uri, icon.to_string (),253 model.append (uri, icon.to_string (),
237 group_id, mimetype,254 group_id, mimetype,
238 search_string,255 display_name,
239 null);256 null);
240 257
241 // 2. add possible directories (we don't store them)258 // 2. add possible directories (we don't store them)
@@ -255,11 +272,11 @@
255 {272 {
256 // TODO: try to match to a desktop file for the icon273 // TODO: try to match to a desktop file for the icon
257 uri = @"unity-runner://$(final_exec)";274 uri = @"unity-runner://$(final_exec)";
258 get_icon_and_mimetype (final_exec, out icon, out mimetype); 275 display_name = get_icon_uri_and_mimetype (final_exec, out icon, out uri, out mimetype);
259 276
260 model.append (uri, icon.to_string (),277 model.append (uri, icon.to_string (),
261 group_id, mimetype,278 group_id, mimetype,
262 final_exec,279 display_name,
263 null);280 null);
264 }281 }
265 282
@@ -316,19 +333,30 @@
316 }333 }
317 }334 }
318 335
319 private void get_icon_and_mimetype (string exec_string, out Icon? icon, out string? mimetype)336 private string get_icon_uri_and_mimetype (string exec_string, out Icon? icon, out string? uri, out string? mimetype)
320 {337 {
321 338
339 AboutEntry entry = null;
340
341 mimetype = "application/x-unity-run";
342 entry = about_entries[exec_string];
343 if (entry != null)
344 {
345 uri = @"unity-runner://$(entry.exec)";
346 icon = entry.icon;
347 return entry.name;
348 }
349
350 uri = @"unity-runner://$(exec_string)";
351
352
322 // if it's a folder, show… a folder icone! + right exec353 // if it's a folder, show… a folder icone! + right exec
323 if (FileUtils.test (exec_string, FileTest.IS_DIR))354 if (FileUtils.test (exec_string, FileTest.IS_DIR))
324 {355 {
325 mimetype = "inode/directory";356 mimetype = "inode/directory";
326 icon = ContentType.get_icon (mimetype);357 icon = ContentType.get_icon (mimetype);
327 return;358 return exec_string;
328 }359 }
329
330 mimetype = "application/x-unity-run";
331
332 360
333 var s = exec_string.delimit ("-", '_').split (" ", 0)[0]; 361 var s = exec_string.delimit ("-", '_').split (" ", 0)[0];
334 var appresults = this.daemon.appsearcher.search (@"type:Application AND exec:$s", 0,362 var appresults = this.daemon.appsearcher.search (@"type:Application AND exec:$s", 0,
@@ -342,12 +370,13 @@
342 370
343 // pick the first one371 // pick the first one
344 icon = this.daemon.find_pkg_icon (pkginfo);372 icon = this.daemon.find_pkg_icon (pkginfo);
345 return;373 return exec_string;
346 374
347 }375 }
348 376
349 // if no result, default icon377 // if no result, default icon
350 icon = new ThemedIcon ("gtk-execute");378 icon = new ThemedIcon ("gtk-execute");
379 return exec_string;
351 380
352 }381 }
353382
@@ -451,6 +480,31 @@
451 warning ("Can't access to the history: %s", e.message);480 warning ("Can't access to the history: %s", e.message);
452 }481 }
453 }482 }
483
484 private void load_about_entries ()
485 {
486 AboutEntry entry;
487 string name;
488 string exec;
489 Icon icon;
490
491 // first about:config
492 name = "about:config";
493 exec = "ccsm -p unityshell";
494 try {
495 icon = Icon.new_for_string (@"$(Config.PREFIX)/share/ccsm/icons/hicolor/64x64/apps/plugin-unityshell.png");
496 }
497 catch (Error err) {
498 warning ("Can't find unityshell icon: %s", err.message);
499 icon = new ThemedIcon ("gtk-execute");
500 }
501 entry = new AboutEntry (name, exec, icon);
502
503 about_entries[name] = entry;
504 about_entries[exec] = entry;
505
506 }
507
454 }508 }
455 509
456}510}

Subscribers

People subscribed via source and target branches