Merge lp:~voldyman/slingshot/fix-install-exp into lp:~elementary-pantheon/slingshot/trunk

Proposed by Akshay Shekher on 2014-07-07
Status: Merged
Approved by: David Gomes on 2014-07-07
Approved revision: 426
Merged at revision: 426
Proposed branch: lp:~voldyman/slingshot/fix-install-exp
Merge into: lp:~elementary-pantheon/slingshot/trunk
Diff against target: 176 lines (+55/-13)
5 files modified
AUTHORS (+1/-0)
src/Backend/App.vala (+46/-11)
src/SlingshotView.vala (+1/-1)
src/Widgets/AppEntry.vala (+4/-1)
src/Widgets/Switcher.vala (+3/-0)
To merge this branch: bzr merge lp:~voldyman/slingshot/fix-install-exp
Reviewer Review Type Date Requested Status
David Gomes 2014-07-07 Approve on 2014-07-07
Review via email: mp+225866@code.launchpad.net

Commit message

Fixes buggy rendering of app icons right after installing them.

Description of the change

This branch fixes the buggy rendering of the app icons when installing

To post a comment you must log in.
David Gomes (davidgomes) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'AUTHORS'
2--- AUTHORS 2012-06-20 22:40:16 +0000
3+++ AUTHORS 2014-07-07 17:05:07 +0000
4@@ -4,3 +4,4 @@
5 * Giulio Collura <random.cpp@gmail.com>
6 * Maxwell Barvian
7 * Andrea Basso <andrea@elementaryos.org>
8+ * Akshay Shekher <akshay@elementaryos.org>
9
10=== modified file 'src/Backend/App.vala'
11--- src/Backend/App.vala 2014-06-12 09:36:00 +0000
12+++ src/Backend/App.vala 2014-07-07 17:05:07 +0000
13@@ -1,6 +1,7 @@
14 // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
15 //
16 // Copyright (C) 2011-2012 Giulio Collura
17+// 2013-2014 Akshay Shekher
18 //
19 // This program is free software: you can redistribute it and/or modify
20 // it under the terms of the GNU General Public License as published by
21@@ -50,6 +51,12 @@
22 public signal void icon_changed ();
23 public signal void launched (App app);
24
25+ // seconds to wait before retrying icon check
26+ private const int RECHECK_TIMEOUT = 2;
27+ private bool check_icon_again = true;
28+
29+ private LoadableIcon loadable_icon = null;
30+
31 public App (GMenu.TreeEntry entry) {
32 app_type = AppType.APP;
33
34@@ -68,21 +75,16 @@
35 if (info.get_icon () is ThemedIcon) {
36 icon_name = (info.get_icon () as ThemedIcon).get_names ()[0].dup ();
37 } else if (info.get_icon () is LoadableIcon) {
38- try {
39- var ios = (info.get_icon () as LoadableIcon).load (0, null, null);
40- icon = new Gdk.Pixbuf.from_stream_at_scale (ios, Slingshot.settings.icon_size,
41- Slingshot.settings.icon_size, true, null);
42- } catch {
43- icon_name = "application-default-icon";
44- }
45+ loadable_icon = info.get_icon () as LoadableIcon;
46+ icon = get_loadable_icon ();
47 } else {
48 icon_name = "application-default-icon";
49 }
50-
51- if (icon == null)
52+ if (icon == null) {
53 update_icon ();
54
55- Slingshot.icon_theme.changed.connect (update_icon);
56+ Slingshot.icon_theme.changed.connect (update_icon);
57+ }
58 }
59
60 public App.from_command (string command) {
61@@ -113,8 +115,13 @@
62
63 }
64
65+ ~App () {
66+ Slingshot.icon_theme.changed.disconnect (update_icon);
67+ }
68+
69 public void update_icon () {
70 icon = load_icon (Slingshot.settings.icon_size);
71+
72 icon_changed ();
73 }
74
75@@ -156,6 +163,9 @@
76 Gdk.Pixbuf icon = null;
77 var flags = Gtk.IconLookupFlags.FORCE_SIZE;
78
79+ if (loadable_icon != null)
80+ return get_loadable_icon ();
81+
82 IconLoadFallbackMethod[] fallbacks = {
83 new IconLoadFallbackMethod (() => {
84 try {
85@@ -166,6 +176,20 @@
86 }),
87
88 new IconLoadFallbackMethod (() => {
89+ // Since the best method didn't work retry after some time
90+ if (check_icon_again) {
91+ // only recheck once
92+ check_icon_again = false;
93+
94+ Timeout.add_seconds (RECHECK_TIMEOUT, () => {
95+ Slingshot.icon_theme.rescan_if_needed ();
96+ update_icon ();
97+ return false;
98+ });
99+ }
100+ }),
101+
102+ new IconLoadFallbackMethod (() => {
103 try {
104 if (icon_name.last_index_of (".") > 0) {
105 var name = icon_name[0:icon_name.last_index_of (".")];
106@@ -200,7 +224,6 @@
107 }
108 })
109 };
110-
111 foreach (IconLoadFallbackMethod fallback in fallbacks) {
112 fallback.load_icon ();
113 if (icon != null)
114@@ -210,6 +233,18 @@
115 return icon;
116 }
117
118+ public Gdk.Pixbuf? get_loadable_icon () {
119+ Gdk.Pixbuf? tmp_loadable_icon;
120+ try {
121+ var icon_stream = loadable_icon.load (0, null, null);
122+ tmp_loadable_icon = new Gdk.Pixbuf.from_stream_at_scale (icon_stream, Slingshot.settings.icon_size,
123+ Slingshot.settings.icon_size, true, null);
124+ } catch (Error e) {
125+ tmp_loadable_icon = null;
126+ }
127+ return tmp_loadable_icon;
128+ }
129+
130 public bool launch () {
131 try {
132 switch (app_type) {
133
134=== modified file 'src/SlingshotView.vala'
135--- src/SlingshotView.vala 2014-06-12 09:14:57 +0000
136+++ src/SlingshotView.vala 2014-07-07 17:05:07 +0000
137@@ -812,8 +812,8 @@
138 app_entry.show_all ();
139 }
140
141+
142 stack.set_visible_child_name ("normal");
143-
144 }
145
146 private void read_settings (bool first_start = false, bool check_columns = true, bool check_rows = true) {
147
148=== modified file 'src/Widgets/AppEntry.vala'
149--- src/Widgets/AppEntry.vala 2014-02-24 20:43:38 +0000
150+++ src/Widgets/AppEntry.vala 2014-07-07 17:05:07 +0000
151@@ -84,7 +84,10 @@
152 sel.set_uris ({File.new_for_path (desktop_path).get_uri ()});
153 });
154
155- app.icon_changed.connect (queue_draw);
156+ app.icon_changed.connect (() => {
157+ icon = app.icon;
158+ queue_draw ();
159+ });
160
161 }
162
163
164=== modified file 'src/Widgets/Switcher.vala'
165--- src/Widgets/Switcher.vala 2014-02-24 20:43:38 +0000
166+++ src/Widgets/Switcher.vala 2014-07-07 17:05:07 +0000
167@@ -66,6 +66,9 @@
168 buttons.set (widget, button);
169 if (buttons.size == 1)
170 button.active = true;
171+
172+ // show all children after update
173+ show_all ();
174 }
175
176 public override void show () {

Subscribers

People subscribed via source and target branches