Merge lp:~unity-team/unity/more-places into lp:unity

Proposed by Neil J. Patel
Status: Merged
Merged at revision: 348
Proposed branch: lp:~unity-team/unity/more-places
Merge into: lp:unity
Diff against target: 241 lines (+134/-29)
3 files modified
unity-private/places/places-default-renderer-group.vala (+123/-26)
unity-private/places/places-default-renderer.vala (+9/-1)
unity-private/places/places-place.vala (+2/-2)
To merge this branch: bzr merge lp:~unity-team/unity/more-places
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+28404@code.launchpad.net

Description of the change

- Fixes some spacing
- Cleans up group-render implementation by moving the logic to the Tile class
- Adds support for loading icons
- Adds support for loading application icons
- Adds support for launching desktop files

This is mostly some polish for this release. I need to clean this up and separate out some of the pieces for next weeks release, including the new expanding group view and a pixbuf cache

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

Approved!

It seems to be a bit heavy on the IO since you create all those GDesktopAppInfo's (which parses the keyfile each time I believe) but it works fine. I think we should address that later with some caching magic.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'unity-private/places/places-default-renderer-group.vala'
2--- unity-private/places/places-default-renderer-group.vala 2010-06-22 12:37:45 +0000
3+++ unity-private/places/places-default-renderer-group.vala 2010-06-24 14:39:27 +0000
4@@ -84,6 +84,15 @@
5 pack (renderer, true, true);
6 renderer.show ();
7
8+ unowned Dee.ModelIter iter = results.get_first_iter ();
9+ while (!results.is_last (iter))
10+ {
11+ if (interesting (iter))
12+ on_result_added (iter);
13+
14+ iter = results.next (iter);
15+ }
16+
17 results.row_added.connect (on_result_added);
18 results.row_removed.connect (on_result_removed);
19 }
20@@ -114,29 +123,15 @@
21 if (!interesting (iter))
22 return;
23
24- var button = new Tile ();
25- button.set_label (results.get_string (iter, 4));
26- unowned Ctk.Text text = button.get_text ();
27- text.ellipsize = Pango.EllipsizeMode.END;
28- button.get_image ().set_from_stock ("text-x-preview");
29+ var button = new Tile (iter,
30+ results.get_string (iter, 0),
31+ results.get_string (iter, 1),
32+ results.get_string (iter, 3),
33+ results.get_string (iter, 4),
34+ results.get_string (iter, 5));
35 renderer.add_actor (button);
36 button.show ();
37
38- button.set_data<unowned Dee.ModelIter> ("model-iter", iter);
39- button.set_data<string> ("uri", "%s".printf (results.get_string (iter, 0)));
40- button.clicked.connect ((b) => {
41- unowned string uri = b.get_data<unowned string> ("uri");
42-
43- print (@"Launching $uri\n");
44- try {
45- Gtk.show_uri (Gdk.Screen.get_default (),
46- uri,
47- 0);
48- } catch (GLib.Error e) {
49- warning ("Unable to launch: %s", e.message);
50- }
51- });
52-
53 show ();
54 }
55
56@@ -148,10 +143,9 @@
57 var children = renderer.get_children ();
58 foreach (Clutter.Actor actor in children)
59 {
60- unowned Dee.ModelIter i;
61+ Tile tile = actor as Tile;
62
63- i = actor.get_data<unowned Dee.ModelIter> ("model-iter");
64- if (i == iter)
65+ if (tile.iter == iter)
66 {
67 actor.destroy ();
68 break;
69@@ -170,9 +164,40 @@
70
71 public class Tile : Ctk.Button
72 {
73- public Tile ()
74- {
75- Object (orientation:Ctk.Orientation.VERTICAL);
76+ public unowned Dee.ModelIter iter { get; construct; }
77+
78+ public string display_name { get; construct; }
79+ public string? icon_hint { get; construct; }
80+ public string uri { get; construct; }
81+ public string? mimetype { get; construct; }
82+ public string? comment { get; construct; }
83+
84+ public Tile (Dee.ModelIter iter,
85+ string uri,
86+ string? icon_hint,
87+ string? mimetype,
88+ string display_name,
89+ string? comment)
90+ {
91+ Object (orientation:Ctk.Orientation.VERTICAL,
92+ iter:iter,
93+ display_name:display_name,
94+ icon_hint:icon_hint,
95+ uri:uri,
96+ mimetype:mimetype,
97+ comment:comment);
98+ }
99+
100+ construct
101+ {
102+ set_label (display_name);
103+
104+ unowned Ctk.Text text = get_text ();
105+ text.ellipsize = Pango.EllipsizeMode.END;
106+
107+ get_image ().set_from_stock ("text-x-preview");
108+
109+ Idle.add (load_icon);
110 }
111
112 private override void get_preferred_width (float for_height,
113@@ -182,6 +207,78 @@
114 mwidth = 160.0f;
115 nwidth = 160.0f;
116 }
117+
118+ private override void clicked ()
119+ {
120+ debug (@"Launching $uri");
121+
122+ if (uri.has_prefix ("application://"))
123+ {
124+ var id = uri.offset ("application://".length);
125+
126+ var info = new GLib.DesktopAppInfo (id);
127+ if (info is GLib.DesktopAppInfo)
128+ {
129+ try {
130+ info.launch (null,null);
131+
132+ } catch (Error e) {
133+ warning ("Unable to launch desktop file %s: %s\n",
134+ id,
135+ e.message);
136+ }
137+ }
138+ else
139+ {
140+ warning ("%s is an invalid DesktopAppInfo id\n", id);
141+ }
142+ return;
143+ }
144+
145+ try {
146+ Gtk.show_uri (Gdk.Screen.get_default (),
147+ uri,
148+ 0);
149+ } catch (GLib.Error e) {
150+ warning ("Unable to launch: %s\n", e.message);
151+ }
152+ }
153+
154+ private bool load_icon ()
155+ {
156+ if (uri.has_prefix ("application://"))
157+ {
158+ var id = uri.offset ("application://".length);
159+ var info = new GLib.DesktopAppInfo (id);
160+
161+ if (info is GLib.DesktopAppInfo)
162+ {
163+ var icon = info.get_icon ();
164+ if (icon is GLib.ThemedIcon)
165+ get_image ().set_from_gicon (icon);
166+ else if (icon is GLib.FileIcon)
167+ {
168+ var file = (icon as GLib.FileIcon).get_file ();
169+ get_image ().set_from_filename (file.get_path ());
170+ }
171+ }
172+ }
173+ else if (mimetype != null)
174+ {
175+ var icon = GLib.g_content_type_get_icon (mimetype) as ThemedIcon;
176+ if (icon is GLib.ThemedIcon)
177+ {
178+ get_image ().set_from_gicon (icon);
179+ }
180+ else if (icon is GLib.FileIcon)
181+ {
182+ var file = (icon as GLib.FileIcon).get_file ();
183+ get_image ().set_from_filename (file.get_path ());
184+ }
185+ }
186+
187+ return false;
188+ }
189 }
190 }
191
192
193=== modified file 'unity-private/places/places-default-renderer.vala'
194--- unity-private/places/places-default-renderer.vala 2010-06-22 12:37:45 +0000
195+++ unity-private/places/places-default-renderer.vala 2010-06-24 14:39:27 +0000
196@@ -37,7 +37,7 @@
197 {
198 padding = { 0.0f, 0.0f, PADDING, 0.0f };
199 box = new Ctk.VBox (SPACING);
200- box.padding = { PADDING, PADDING, PADDING , PADDING};
201+ box.padding = { 0.0f, PADDING, PADDING , PADDING};
202 box.homogeneous = false;
203 add_actor (box);
204 box.show ();
205@@ -53,6 +53,14 @@
206 groups_model = groups;
207 results_model = results;
208
209+ unowned Dee.ModelIter iter = groups.get_first_iter ();
210+ while (!groups.is_last (iter))
211+ {
212+ on_group_added (groups, iter);
213+
214+ iter = groups.next (iter);
215+ }
216+
217 groups_model.row_added.connect (on_group_added);
218 groups_model.row_removed.connect (on_group_removed);
219 }
220
221=== modified file 'unity-private/places/places-place.vala'
222--- unity-private/places/places-place.vala 2010-06-19 15:00:43 +0000
223+++ unity-private/places/places-place.vala 2010-06-24 14:39:27 +0000
224@@ -174,7 +174,7 @@
225 private void on_service_entry_added (dynamic DBus.Object dbus_object,
226 ValueArray info)
227 {
228- debug (@"EntryAdded %s", info.get_nth (0).get_string ());
229+ debug ("EntryAdded %s", info.get_nth (0).get_string ());
230 /* This is a new entry */
231 var entry = new PlaceEntry (dbus_name,
232 info.get_nth (0).get_string ());
233@@ -213,7 +213,7 @@
234 var groups = file.get_groups ();
235 foreach (string group in groups)
236 {
237- if (group.has_prefix (ENTRY_PREFIX))
238+ if (true == false) //group.has_prefix (ENTRY_PREFIX))
239 {
240 PlaceEntry? entry = load_entry_from_keyfile (file, group);
241 if (entry is PlaceEntry)