Merge lp:~tigrangab/slingshot/bug_1072036 into lp:~elementary-pantheon/slingshot/trunk

Proposed by Tigran Gabrielyan
Status: Merged
Approved by: David Gomes
Approved revision: 381
Merged at revision: 377
Proposed branch: lp:~tigrangab/slingshot/bug_1072036
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 201 lines (+69/-51)
2 files modified
src/Backend/App.vala (+66/-30)
src/Widgets/SearchItem.vala (+3/-21)
To merge this branch: bzr merge lp:~tigrangab/slingshot/bug_1072036
Reviewer Review Type Date Requested Status
David Gomes (community) Approve
Sergey "Shnatsel" Davidoff (community) Approve
Review via email: mp+181209@code.launchpad.net

Commit message

Fix fallback methods of finding an apps icon to work in all views. Fixes bug #1072036.

To post a comment you must log in.
Revision history for this message
David Gomes (davidgomes) wrote :

my_function_call (tom, josh, peter
                  hello, new Game ());

That's how you align 2 lines (many editors do this automatically) when you split them. You have a lot to realign in your branch.

I can't test this bug cos I've never even experienced so I'll need a tester too. The code itself is well made, good job.

review: Needs Fixing
Revision history for this message
Tigran Gabrielyan (tigrangab) wrote :

If you need a test file: https://gist.github.com/tigrang/6312102/raw/09b075acc4e6f38e5eef35cf311b0664b8ce9573/test.desktop

Before patch:
In Grid view, the icon for "Testing Bug 1072036" will show. When you search "Test" it will not show.

After the patch:
It should work in both views.

lp:~tigrangab/slingshot/bug_1072036 updated
377. By Tigran Gabrielyan

Clean up code

378. By Tigran Gabrielyan

Add warning/error messages to fallback methods

Revision history for this message
David Gomes (davidgomes) wrote :

>}),

Add a newline after those on the array with the different methods.

Diff lines 48 and 54, remove both.

Also, why not?

foreach (IconLoadFallbackMethod fallback in fallbacks) {
 try {
    fallback.load_icon()
 } catch (Error ) {

 }
}

to avoid some code repetition?

review: Needs Fixing
Revision history for this message
Tigran Gabrielyan (tigrangab) wrote :

That's what I did initially, but it doesn't catch the error that way, not sure why.

lp:~tigrangab/slingshot/bug_1072036 updated
379. By Tigran Gabrielyan

Remove unneeded lines

380. By Tigran Gabrielyan

Add newlines between array items

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

I can confirm this fixes the bug for the test launcher and for Skype. Great job, thanks!

review: Approve
Revision history for this message
David Gomes (davidgomes) wrote :

public IconLoadFallbackMethod(IconLoadFallback fallback) {

public IconLoadFallbackMethod (IconLoadFallback fallback) {

That's the last bit, then it's a merge man, great job!

review: Needs Fixing
lp:~tigrangab/slingshot/bug_1072036 updated
381. By Tigran Gabrielyan

Fix yet another CS issue

Revision history for this message
Tigran Gabrielyan (tigrangab) wrote :

Sorry about that :) This coding style is really odd/different to me. I'll get used to it eventually.

Revision history for this message
David Gomes (davidgomes) wrote :

Great job.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Backend/App.vala'
2--- src/Backend/App.vala 2013-04-17 18:32:40 +0000
3+++ src/Backend/App.vala 2013-08-26 17:15:32 +0000
4@@ -38,7 +38,6 @@
5 public signal void launched (App app);
6
7 public App (GMenu.TreeEntry entry) {
8-
9 name = entry.get_display_name ();
10 description = entry.get_comment () ?? name;
11 exec = entry.get_exec ();
12@@ -47,10 +46,9 @@
13 desktop_path = entry.get_desktop_file_path ();
14 keywords = Unity.AppInfoManager.get_default ().get_keywords (desktop_id);
15 generic_name = entry.get_generic_name ();
16-
17+
18 update_icon ();
19 Slingshot.icon_theme.changed.connect (update_icon);
20-
21 }
22
23 public App.from_command (string command) {
24@@ -68,40 +66,79 @@
25 }
26
27 public void update_icon () {
28-
29- try {
30- icon = Slingshot.icon_theme.load_icon (icon_name, Slingshot.settings.icon_size,
31- Gtk.IconLookupFlags.FORCE_SIZE);
32- } catch (Error e) {
33- try {
34- if (icon_name.last_index_of (".") > 0)
35- icon = Slingshot.icon_theme.load_icon (icon_name[0:icon_name.last_index_of (".")],
36- Slingshot.settings.icon_size, Gtk.IconLookupFlags.FORCE_SIZE);
37- else
38- throw new IOError.NOT_FOUND ("Requested image could not be found.");
39-
40- } catch (Error e) {
41+ icon = load_icon (Slingshot.settings.icon_size);
42+ icon_changed ();
43+ }
44+
45+ private delegate void IconLoadFallback ();
46+
47+ private class IconLoadFallbackMethod {
48+ public unowned IconLoadFallback load_icon;
49+
50+ public IconLoadFallbackMethod (IconLoadFallback fallback) {
51+ load_icon = fallback;
52+ }
53+ }
54+
55+ public Gdk.Pixbuf load_icon (int size) {
56+ Gdk.Pixbuf icon = null;
57+ var flags = Gtk.IconLookupFlags.FORCE_SIZE;
58+
59+ IconLoadFallbackMethod[] fallbacks = {
60+ new IconLoadFallbackMethod (() => {
61 try {
62- icon = new Gdk.Pixbuf.from_file_at_scale (icon_name, Slingshot.settings.icon_size,
63- Slingshot.settings.icon_size, false);
64+ icon = Slingshot.icon_theme.load_icon (icon_name, size, flags);
65 } catch (Error e) {
66- try {
67- icon = Slingshot.icon_theme.load_icon ("application-default-icon", Slingshot.settings.icon_size,
68- Gtk.IconLookupFlags.FORCE_SIZE);
69- } catch (Error e) {
70- icon = Slingshot.icon_theme.load_icon ("gtk-missing-image", Slingshot.settings.icon_size,
71- Gtk.IconLookupFlags.FORCE_SIZE);
72+ warning ("Could not load icon. Falling back to method 2");
73+ }
74+ }),
75+
76+ new IconLoadFallbackMethod (() => {
77+ try {
78+ if (icon_name.last_index_of (".") > 0) {
79+ var name = icon_name[0:icon_name.last_index_of (".")];
80+ icon = Slingshot.icon_theme.load_icon (name, size, flags);
81 }
82- }
83- }
84+ } catch (Error e) {
85+ warning ("Could not load icon. Falling back to method 3");
86+ }
87+ }),
88+
89+ new IconLoadFallbackMethod (() => {
90+ try {
91+ icon = new Gdk.Pixbuf.from_file_at_scale (icon_name, size, size, false);
92+ } catch (Error e) {
93+ warning ("Could not load icon. Falling back to method 4");
94+ }
95+ }),
96+
97+ new IconLoadFallbackMethod (() => {
98+ try {
99+ icon = Slingshot.icon_theme.load_icon ("application-default-icon", size, flags);
100+ } catch (Error e) {
101+ warning ("Could not load icon. Falling back to method 5");
102+ }
103+ }),
104+
105+ new IconLoadFallbackMethod (() => {
106+ try {
107+ icon = Slingshot.icon_theme.load_icon ("gtk-missing-image", size, flags);
108+ } catch (Error e) {
109+ error ("Could not find a fallback icon to load");
110+ }
111+ })
112+ };
113+
114+ foreach (IconLoadFallbackMethod fallback in fallbacks) {
115+ fallback.load_icon ();
116+ if (icon != null)
117+ break;
118 }
119
120- icon_changed ();
121-
122+ return icon;
123 }
124
125 public void launch () {
126-
127 try {
128 if (is_command) {
129 debug (@"Launching command: $name");
130@@ -114,7 +151,6 @@
131 } catch (Error e) {
132 warning ("Failed to launch %s: %s", name, exec);
133 }
134-
135 }
136
137 }
138
139=== modified file 'src/Widgets/SearchItem.vala'
140--- src/Widgets/SearchItem.vala 2012-09-09 18:14:52 +0000
141+++ src/Widgets/SearchItem.vala 2013-08-26 17:15:32 +0000
142@@ -23,6 +23,7 @@
143
144 public class SearchItem : Button {
145
146+ private Backend.App app;
147 private Pixbuf icon;
148 private string icon_name;
149 private Label name_label;
150@@ -33,7 +34,7 @@
151 public signal void launch_app ();
152
153 public SearchItem (Backend.App app) {
154-
155+ this.app = app;
156 get_style_context ().add_class ("app");
157
158 icon = app.icon;
159@@ -56,33 +57,15 @@
160 add (Utils.set_padding (vbox, 5, 0, 0, 78));
161
162 this.launch_app.connect (app.launch);
163-
164 }
165
166 protected override bool draw (Cairo.Context cr) {
167-
168 Allocation size;
169 get_allocation (out size);
170
171 base.draw (cr);
172
173- Pixbuf scaled_icon = null;
174- try {
175- scaled_icon = Slingshot.icon_theme.load_icon (icon_name, icon_size,
176- Gtk.IconLookupFlags.FORCE_SIZE);
177- } catch (Error e) {
178- try {
179- scaled_icon = new Gdk.Pixbuf.from_file_at_scale (icon_name, icon_size, icon_size, false);
180- } catch (Error e) {
181- try {
182- scaled_icon = Slingshot.icon_theme.load_icon ("application-default-icon", icon_size,
183- Gtk.IconLookupFlags.FORCE_SIZE);
184- } catch (Error e) {
185- scaled_icon = Slingshot.icon_theme.load_icon ("gtk-missing-image", icon_size,
186- Gtk.IconLookupFlags.FORCE_SIZE);
187- }
188- }
189- }
190+ Pixbuf scaled_icon = app.load_icon (icon_size);
191
192 height_request = icon_size + 10;
193
194@@ -91,7 +74,6 @@
195 cr.paint ();
196
197 return true;
198-
199 }
200
201 private string fix (string text) {

Subscribers

People subscribed via source and target branches