Merge lp:~didrocks/unity/theme-icon-load into lp:unity

Proposed by Didier Roche-Tolomelli
Status: Merged
Approved by: Neil J. Patel
Approved revision: no longer in the source branch.
Merged at revision: 1116
Proposed branch: lp:~didrocks/unity/theme-icon-load
Merge into: lp:unity
Diff against target: 224 lines (+102/-17)
3 files modified
src/LauncherIcon.cpp (+91/-15)
src/LauncherIcon.h (+8/-2)
src/SimpleLauncherIcon.cpp (+3/-0)
To merge this branch: bzr merge lp:~didrocks/unity/theme-icon-load
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+57314@code.launchpad.net

Description of the change

"Try to load from unity-icon-theme first for some dedicated icons (LP: #750471)"

You need latest unity-asset-pool to check that it's indeed loading trash and
workspace switcher icon from unity-asset-pool.

u-a-p now inherits from Humanity as well, but I restrict the lookup to
well-known icons to avoid further damage (like the home folder nautilus icon
being in the mono themes).
We should do that on a -unity postfix for icons names, see FIXME. Something for
O as it needs to be touched in multiple package and needs discussion with the
design team.

To post a comment you must log in.
Revision history for this message
Neil J. Patel (njpatel) wrote :

Approved!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/LauncherIcon.cpp'
2--- src/LauncherIcon.cpp 2011-04-10 17:52:26 +0000
3+++ src/LauncherIcon.cpp 2011-04-12 16:35:47 +0000
4@@ -44,12 +44,17 @@
5 #include "UBusMessages.h"
6
7 #define DEFAULT_ICON "application-default-icon"
8+#define MONO_TEST_ICON "gnome-home"
9+#define UNITY_THEME_NAME "unity-icon-theme"
10
11 NUX_IMPLEMENT_OBJECT_TYPE (LauncherIcon);
12
13 nux::Tooltip *LauncherIcon::_current_tooltip = 0;
14 QuicklistView *LauncherIcon::_current_quicklist = 0;
15
16+int LauncherIcon::_current_theme_is_mono = -1;
17+GtkIconTheme *LauncherIcon::_unity_theme = NULL;
18+
19 LauncherIcon::LauncherIcon(Launcher* launcher)
20 {
21 _folding_angle = 0;
22@@ -62,7 +67,7 @@
23 _quirk_times[i].tv_sec = 0;
24 _quirk_times[i].tv_nsec = 0;
25 }
26-
27+
28 _related_windows = 0;
29
30 _background_color = nux::Colors::White;
31@@ -87,6 +92,11 @@
32 _present_time_handle = 0;
33 _center_stabilize_handle = 0;
34 _time_delay_handle = 0;
35+
36+ if (!LauncherIcon::_unity_theme) {
37+ LauncherIcon::_unity_theme = gtk_icon_theme_new ();
38+ gtk_icon_theme_set_custom_theme (LauncherIcon::_unity_theme, UNITY_THEME_NAME);
39+ }
40
41 // FIXME: the abstraction is already broken, should be fixed for O
42 // right now, hooking the dynamic quicklist the less ugly possible way
43@@ -139,6 +149,12 @@
44
45 _quicklist->UnReference ();
46 _tooltip->UnReference ();
47+
48+ if (_unity_theme)
49+ {
50+ g_object_unref (_unity_theme);
51+ _unity_theme = NULL;
52+ }
53 }
54
55 bool
56@@ -257,19 +273,81 @@
57 glow = nux::Color (r, g, b);
58 }
59
60+/*
61+ * FIXME, all this code (and below), should be put in a facility for IconLoader
62+ * to share between launcher and places the same Icon loading logic and not look
63+ * having etoomanyimplementationofsamethings.
64+ */
65+/* static */
66+bool LauncherIcon::IsMonoDefaultTheme ()
67+{
68+
69+ if (_current_theme_is_mono != -1)
70+ return (bool)_current_theme_is_mono;
71+
72+ GtkIconTheme *default_theme;
73+ GtkIconInfo *info;
74+ int size = 48;
75+
76+ default_theme = gtk_icon_theme_get_default ();
77+
78+ _current_theme_is_mono = (int)false;
79+ info = gtk_icon_theme_lookup_icon (default_theme, MONO_TEST_ICON, size, (GtkIconLookupFlags)0);
80+
81+ if (!info)
82+ return (bool)_current_theme_is_mono;
83+
84+ // yeah, it's evil, but it's blessed upstream
85+ if (g_strrstr (gtk_icon_info_get_filename (info), "ubuntu-mono") != NULL)
86+ _current_theme_is_mono = (int)true;
87+
88+ gtk_icon_info_free (info);
89+ return (bool)_current_theme_is_mono;
90+
91+}
92+
93 nux::BaseTexture * LauncherIcon::TextureFromGtkTheme (const char *icon_name, int size, bool update_glow_colors)
94 {
95- GdkPixbuf *pbuf;
96- GtkIconTheme *theme;
97- GtkIconInfo *info;
98- nux::BaseTexture *result;
99- GError *error = NULL;
100- GIcon *icon;
101-
102+ GtkIconTheme *default_theme;
103+ nux::BaseTexture *result = NULL;
104+
105 if (!icon_name)
106 icon_name = g_strdup (DEFAULT_ICON);
107
108- theme = gtk_icon_theme_get_default ();
109+ default_theme = gtk_icon_theme_get_default ();
110+
111+ // FIXME: we need to create some kind of -unity postfix to see if we are looking to the unity-icon-theme
112+ // for dedicated unity icons, then remove the postfix and degrade to other icon themes if not found
113+ if (((g_strrstr (icon_name, "user-trash") != NULL) ||
114+ (g_strcmp0 (icon_name, "workspace-switcher") == 0)) &&
115+ IsMonoDefaultTheme ()) {
116+ result = TextureFromSpecificGtkTheme (_unity_theme, icon_name, size, update_glow_colors);
117+
118+ }
119+
120+ if (!result)
121+ result = TextureFromSpecificGtkTheme (default_theme, icon_name, size, update_glow_colors, true);
122+
123+ if (!result) {
124+ if (g_strcmp0 (icon_name, "folder") == 0)
125+ result = NULL;
126+ else
127+ result = TextureFromSpecificGtkTheme (default_theme, "folder", size, update_glow_colors);
128+ }
129+
130+ return result;
131+
132+}
133+
134+nux::BaseTexture * LauncherIcon::TextureFromSpecificGtkTheme (GtkIconTheme *theme, const char *icon_name, int size, bool update_glow_colors, bool is_default_theme)
135+{
136+
137+ GdkPixbuf *pbuf;
138+ GtkIconInfo *info;
139+ nux::BaseTexture *result = NULL;
140+ GError *error = NULL;
141+ GIcon *icon;
142+
143 icon = g_icon_new_for_string (icon_name, NULL);
144
145 if (G_IS_ICON (icon))
146@@ -284,6 +362,9 @@
147 size,
148 (GtkIconLookupFlags) 0);
149 }
150+
151+ if (!info && !is_default_theme)
152+ return NULL;
153
154 if (!info)
155 {
156@@ -292,7 +373,7 @@
157 size,
158 (GtkIconLookupFlags) 0);
159 }
160-
161+
162 if (gtk_icon_info_get_filename (info) == NULL)
163 {
164 gtk_icon_info_free (info);
165@@ -321,11 +402,6 @@
166 icon_name,
167 error ? error->message : "unknown");
168 g_error_free (error);
169-
170- if (g_strcmp0 (icon_name, "folder") == 0)
171- return NULL;
172- else
173- return TextureFromGtkTheme ("folder", size, update_glow_colors);
174 }
175
176 return result;
177
178=== modified file 'src/LauncherIcon.h'
179--- src/LauncherIcon.h 2011-04-10 03:39:11 +0000
180+++ src/LauncherIcon.h 2011-04-12 16:35:47 +0000
181@@ -204,8 +204,10 @@
182 virtual void ActivateLauncherIcon () {}
183 virtual void OpenInstanceLauncherIcon () {}
184
185- nux::BaseTexture * TextureFromGtkTheme (const char *name, int size, bool update_glow_colors = true);
186- nux::BaseTexture * TextureFromPath (const char *name, int size, bool update_glow_colors = true);
187+ nux::BaseTexture * TextureFromGtkTheme (const char *name, int size, bool update_glow_colors = true);
188+ nux::BaseTexture * TextureFromSpecificGtkTheme (GtkIconTheme *theme, const char *name, int size, bool update_glow_colors = true, bool is_default_theme=false);
189+ nux::BaseTexture * TextureFromPath (const char *name, int size, bool update_glow_colors = true);
190+ static bool IsMonoDefaultTheme ();
191
192 void OnRemoteEmblemChanged (LauncherEntryRemote *remote);
193 void OnRemoteCountChanged (LauncherEntryRemote *remote);
194@@ -232,6 +234,8 @@
195
196 static nux::Tooltip *_current_tooltip;
197 static QuicklistView *_current_quicklist;
198+
199+ static int _current_theme_is_mono;
200
201 DbusmenuClient *_menuclient_dynamic_quicklist;
202
203@@ -281,6 +285,8 @@
204 struct timespec _quirk_times[QUIRK_LAST];
205
206 std::list<LauncherEntryRemote *> _entry_list;
207+
208+ static GtkIconTheme *_unity_theme;
209 };
210
211 #endif // LAUNCHERICON_H
212
213=== modified file 'src/SimpleLauncherIcon.cpp'
214--- src/SimpleLauncherIcon.cpp 2011-03-31 20:38:49 +0000
215+++ src/SimpleLauncherIcon.cpp 2011-04-12 16:35:47 +0000
216@@ -130,6 +130,9 @@
217
218 if (!data)
219 return;
220+
221+ // invalidate the current cache
222+ LauncherIcon::_current_theme_is_mono = -1;
223
224 self = (SimpleLauncherIcon*) data;
225