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
=== modified file 'unity-private/places/places-default-renderer-group.vala'
--- unity-private/places/places-default-renderer-group.vala 2010-06-22 12:37:45 +0000
+++ unity-private/places/places-default-renderer-group.vala 2010-06-24 14:39:27 +0000
@@ -84,6 +84,15 @@
84 pack (renderer, true, true);84 pack (renderer, true, true);
85 renderer.show ();85 renderer.show ();
8686
87 unowned Dee.ModelIter iter = results.get_first_iter ();
88 while (!results.is_last (iter))
89 {
90 if (interesting (iter))
91 on_result_added (iter);
92
93 iter = results.next (iter);
94 }
95
87 results.row_added.connect (on_result_added);96 results.row_added.connect (on_result_added);
88 results.row_removed.connect (on_result_removed);97 results.row_removed.connect (on_result_removed);
89 }98 }
@@ -114,29 +123,15 @@
114 if (!interesting (iter))123 if (!interesting (iter))
115 return;124 return;
116125
117 var button = new Tile ();126 var button = new Tile (iter,
118 button.set_label (results.get_string (iter, 4));127 results.get_string (iter, 0),
119 unowned Ctk.Text text = button.get_text ();128 results.get_string (iter, 1),
120 text.ellipsize = Pango.EllipsizeMode.END;129 results.get_string (iter, 3),
121 button.get_image ().set_from_stock ("text-x-preview");130 results.get_string (iter, 4),
131 results.get_string (iter, 5));
122 renderer.add_actor (button);132 renderer.add_actor (button);
123 button.show ();133 button.show ();
124134
125 button.set_data<unowned Dee.ModelIter> ("model-iter", iter);
126 button.set_data<string> ("uri", "%s".printf (results.get_string (iter, 0)));
127 button.clicked.connect ((b) => {
128 unowned string uri = b.get_data<unowned string> ("uri");
129
130 print (@"Launching $uri\n");
131 try {
132 Gtk.show_uri (Gdk.Screen.get_default (),
133 uri,
134 0);
135 } catch (GLib.Error e) {
136 warning ("Unable to launch: %s", e.message);
137 }
138 });
139
140 show ();135 show ();
141 }136 }
142137
@@ -148,10 +143,9 @@
148 var children = renderer.get_children ();143 var children = renderer.get_children ();
149 foreach (Clutter.Actor actor in children)144 foreach (Clutter.Actor actor in children)
150 {145 {
151 unowned Dee.ModelIter i;146 Tile tile = actor as Tile;
152147
153 i = actor.get_data<unowned Dee.ModelIter> ("model-iter");148 if (tile.iter == iter)
154 if (i == iter)
155 {149 {
156 actor.destroy ();150 actor.destroy ();
157 break;151 break;
@@ -170,9 +164,40 @@
170164
171 public class Tile : Ctk.Button165 public class Tile : Ctk.Button
172 {166 {
173 public Tile ()167 public unowned Dee.ModelIter iter { get; construct; }
174 {168
175 Object (orientation:Ctk.Orientation.VERTICAL);169 public string display_name { get; construct; }
170 public string? icon_hint { get; construct; }
171 public string uri { get; construct; }
172 public string? mimetype { get; construct; }
173 public string? comment { get; construct; }
174
175 public Tile (Dee.ModelIter iter,
176 string uri,
177 string? icon_hint,
178 string? mimetype,
179 string display_name,
180 string? comment)
181 {
182 Object (orientation:Ctk.Orientation.VERTICAL,
183 iter:iter,
184 display_name:display_name,
185 icon_hint:icon_hint,
186 uri:uri,
187 mimetype:mimetype,
188 comment:comment);
189 }
190
191 construct
192 {
193 set_label (display_name);
194
195 unowned Ctk.Text text = get_text ();
196 text.ellipsize = Pango.EllipsizeMode.END;
197
198 get_image ().set_from_stock ("text-x-preview");
199
200 Idle.add (load_icon);
176 }201 }
177202
178 private override void get_preferred_width (float for_height,203 private override void get_preferred_width (float for_height,
@@ -182,6 +207,78 @@
182 mwidth = 160.0f;207 mwidth = 160.0f;
183 nwidth = 160.0f;208 nwidth = 160.0f;
184 }209 }
210
211 private override void clicked ()
212 {
213 debug (@"Launching $uri");
214
215 if (uri.has_prefix ("application://"))
216 {
217 var id = uri.offset ("application://".length);
218
219 var info = new GLib.DesktopAppInfo (id);
220 if (info is GLib.DesktopAppInfo)
221 {
222 try {
223 info.launch (null,null);
224
225 } catch (Error e) {
226 warning ("Unable to launch desktop file %s: %s\n",
227 id,
228 e.message);
229 }
230 }
231 else
232 {
233 warning ("%s is an invalid DesktopAppInfo id\n", id);
234 }
235 return;
236 }
237
238 try {
239 Gtk.show_uri (Gdk.Screen.get_default (),
240 uri,
241 0);
242 } catch (GLib.Error e) {
243 warning ("Unable to launch: %s\n", e.message);
244 }
245 }
246
247 private bool load_icon ()
248 {
249 if (uri.has_prefix ("application://"))
250 {
251 var id = uri.offset ("application://".length);
252 var info = new GLib.DesktopAppInfo (id);
253
254 if (info is GLib.DesktopAppInfo)
255 {
256 var icon = info.get_icon ();
257 if (icon is GLib.ThemedIcon)
258 get_image ().set_from_gicon (icon);
259 else if (icon is GLib.FileIcon)
260 {
261 var file = (icon as GLib.FileIcon).get_file ();
262 get_image ().set_from_filename (file.get_path ());
263 }
264 }
265 }
266 else if (mimetype != null)
267 {
268 var icon = GLib.g_content_type_get_icon (mimetype) as ThemedIcon;
269 if (icon is GLib.ThemedIcon)
270 {
271 get_image ().set_from_gicon (icon);
272 }
273 else if (icon is GLib.FileIcon)
274 {
275 var file = (icon as GLib.FileIcon).get_file ();
276 get_image ().set_from_filename (file.get_path ());
277 }
278 }
279
280 return false;
281 }
185 }282 }
186}283}
187284
188285
=== modified file 'unity-private/places/places-default-renderer.vala'
--- unity-private/places/places-default-renderer.vala 2010-06-22 12:37:45 +0000
+++ unity-private/places/places-default-renderer.vala 2010-06-24 14:39:27 +0000
@@ -37,7 +37,7 @@
37 {37 {
38 padding = { 0.0f, 0.0f, PADDING, 0.0f };38 padding = { 0.0f, 0.0f, PADDING, 0.0f };
39 box = new Ctk.VBox (SPACING);39 box = new Ctk.VBox (SPACING);
40 box.padding = { PADDING, PADDING, PADDING , PADDING};40 box.padding = { 0.0f, PADDING, PADDING , PADDING};
41 box.homogeneous = false;41 box.homogeneous = false;
42 add_actor (box);42 add_actor (box);
43 box.show ();43 box.show ();
@@ -53,6 +53,14 @@
53 groups_model = groups;53 groups_model = groups;
54 results_model = results;54 results_model = results;
5555
56 unowned Dee.ModelIter iter = groups.get_first_iter ();
57 while (!groups.is_last (iter))
58 {
59 on_group_added (groups, iter);
60
61 iter = groups.next (iter);
62 }
63
56 groups_model.row_added.connect (on_group_added);64 groups_model.row_added.connect (on_group_added);
57 groups_model.row_removed.connect (on_group_removed);65 groups_model.row_removed.connect (on_group_removed);
58 }66 }
5967
=== modified file 'unity-private/places/places-place.vala'
--- unity-private/places/places-place.vala 2010-06-19 15:00:43 +0000
+++ unity-private/places/places-place.vala 2010-06-24 14:39:27 +0000
@@ -174,7 +174,7 @@
174 private void on_service_entry_added (dynamic DBus.Object dbus_object,174 private void on_service_entry_added (dynamic DBus.Object dbus_object,
175 ValueArray info)175 ValueArray info)
176 {176 {
177 debug (@"EntryAdded %s", info.get_nth (0).get_string ());177 debug ("EntryAdded %s", info.get_nth (0).get_string ());
178 /* This is a new entry */178 /* This is a new entry */
179 var entry = new PlaceEntry (dbus_name,179 var entry = new PlaceEntry (dbus_name,
180 info.get_nth (0).get_string ());180 info.get_nth (0).get_string ());
@@ -213,7 +213,7 @@
213 var groups = file.get_groups ();213 var groups = file.get_groups ();
214 foreach (string group in groups)214 foreach (string group in groups)
215 {215 {
216 if (group.has_prefix (ENTRY_PREFIX))216 if (true == false) //group.has_prefix (ENTRY_PREFIX))
217 {217 {
218 PlaceEntry? entry = load_entry_from_keyfile (file, group);218 PlaceEntry? entry = load_entry_from_keyfile (file, group);
219 if (entry is PlaceEntry)219 if (entry is PlaceEntry)