Merge lp:~azzar1/unity/fix-875467-2 into lp:unity

Proposed by Andrea Azzarone
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 1793
Proposed branch: lp:~azzar1/unity/fix-875467-2
Merge into: lp:unity
Diff against target: 329 lines (+89/-43)
11 files modified
manual-tests/EjectNotificationIcon.txt (+27/-0)
plugins/unityshell/src/BFBLauncherIcon.cpp (+1/-1)
plugins/unityshell/src/BamfLauncherIcon.cpp (+2/-4)
plugins/unityshell/src/DesktopLauncherIcon.cpp (+1/-1)
plugins/unityshell/src/DeviceLauncherIcon.cpp (+27/-12)
plugins/unityshell/src/DeviceLauncherIcon.h (+1/-0)
plugins/unityshell/src/LauncherController.cpp (+1/-1)
plugins/unityshell/src/SimpleLauncherIcon.cpp (+13/-14)
plugins/unityshell/src/SimpleLauncherIcon.h (+8/-6)
plugins/unityshell/src/TrashLauncherIcon.cpp (+4/-4)
standalone-clients/CMakeLists.txt (+4/-0)
To merge this branch: bzr merge lp:~azzar1/unity/fix-875467-2
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Marco Trevisan (Treviño) Approve
Review via email: mp+82732@code.launchpad.net

Description of the change

Use unity::IconLoader to load device launcher icon that will be used to show an OSD notification. If it's not able to load an icon it shows a OSD notification without an icon.

This merge propose comes from this one (https://code.launchpad.net/~andyrock/unity/fix-875467/+merge/79638). In that merge proposal I've created a mini (very very mini) icon loader implementation. Reading unity code I noticed that we already use two icon loader implementations (the dash icon loader and the launcher ones) so...

Because unity::IconLoader has already been tested and in a unit test we should not test an external module (osd notification library), i don't know if we need a unit test for this change. In the case let me know.

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

I was wondering, shouldn't be the notification, this case, be shown as a priority one?
I mean, making it to be positioned where the volume or brightness bubbles are shown, to exceed the queue of the all other applications that are firing notifications. The hint "x-canonical-private-synchronous" or the urgency should do that.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Despite the comment above (about which I'd suggest to contact the design team), the code looks good to me and works as expected, so I approve.

I agree about the fact that testing should not be needed for this one, as we only change how the UI is rendering through an external lib, but the core you're using is already in.

review: Approve
Revision history for this message
Tim Penhey (thumper) wrote :

notify_notification_new is called without any corresponding clean up.

If it uses g_object_unref, prehaps you chould use a glib::Object wrapper.

GdkPixbuf* pixbuf = NULL // should be nullptr

line 168: there are multiple calls to icon_name(). This returns a new
temporary each time, we should use a local variable.

I _think_ that I added equality checks for a property (just checked, I did).

so you should be able to go:
  self->empty_ = (self->icon_name == "user-trash");
(just removed the () from icon_name).

review: Needs Fixing
Revision history for this message
Andrea Azzarone (azzar1) wrote :

> notify_notification_new is called without any corresponding clean up.
>
> If it uses g_object_unref, prehaps you chould use a glib::Object wrapper.

Done.

> GdkPixbuf* pixbuf = NULL // should be nullptr

Done.

>
> line 168: there are multiple calls to icon_name(). This returns a new
> temporary each time, we should use a local variable.

Done.

>
> I _think_ that I added equality checks for a property (just checked, I did).
>
> so you should be able to go:
> self->empty_ = (self->icon_name == "user-trash");
> (just removed the () from icon_name).

Done.

Revision history for this message
Tim Penhey (thumper) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'manual-tests/EjectNotificationIcon.txt'
2--- manual-tests/EjectNotificationIcon.txt 1970-01-01 00:00:00 +0000
3+++ manual-tests/EjectNotificationIcon.txt 2011-12-16 10:59:25 +0000
4@@ -0,0 +1,27 @@
5+Test Eject Notification Icon (USB)
6+-------------------
7+This test shows that the correct icon is shown in the OSD notification when a
8+USB pen drive is ejected using drag and drop into the trash.
9+
10+#. Plug in a USB pen drive
11+#. Wait for device icon to appear in the launcher
12+#. Drag and drop it into the trash icon
13+
14+Outcome
15+ The usb pen drive will be "ejected" and an OSD-notification will appear. The
16+ icon in the notification is the same icon used for the launcher icon.
17+
18+
19+
20+Test Eject Notification Icon (CD)
21+-------------------
22+This test shows that the correct icon is shown in the OSD notification when a
23+CD is ejected using drag and drop into the trash.
24+
25+#. Insert a CD
26+#. Wait for device icon to appear in the launcher
27+#. Drag and drop it into the trash icon
28+
29+Outcome
30+ The cd will be"ejected and an OSD-notification will appear. The
31+ icon in the notification is the same icon used for the launcher icon.
32
33=== modified file 'plugins/unityshell/src/BFBLauncherIcon.cpp'
34--- plugins/unityshell/src/BFBLauncherIcon.cpp 2011-12-09 14:40:35 +0000
35+++ plugins/unityshell/src/BFBLauncherIcon.cpp 2011-12-16 10:59:25 +0000
36@@ -36,7 +36,7 @@
37 : SimpleLauncherIcon(IconManager)
38 {
39 tooltip_text = _("Dash home");
40- SetIconName(PKGDATADIR"/launcher_bfb.png");
41+ icon_name = PKGDATADIR"/launcher_bfb.png";
42 SetQuirk(QUIRK_VISIBLE, true);
43 SetQuirk(QUIRK_RUNNING, false);
44 SetIconType(TYPE_HOME);
45
46=== modified file 'plugins/unityshell/src/BamfLauncherIcon.cpp'
47--- plugins/unityshell/src/BamfLauncherIcon.cpp 2011-12-13 08:58:59 +0000
48+++ plugins/unityshell/src/BamfLauncherIcon.cpp 2011-12-16 10:59:25 +0000
49@@ -175,10 +175,10 @@
50 _menu_desktop_shortcuts = NULL;
51 _on_desktop_file_changed_handler_id = 0;
52 _window_moved_id = 0;
53- char* icon_name = bamf_view_get_icon(BAMF_VIEW(m_App));
54+ glib::String icon(bamf_view_get_icon(BAMF_VIEW(m_App)));
55
56 tooltip_text = BamfName();
57- SetIconName(icon_name);
58+ icon_name = icon.Str();
59 SetIconType(TYPE_APPLICATION);
60
61 if (bamf_view_is_sticky(BAMF_VIEW(m_App)))
62@@ -189,8 +189,6 @@
63 SetQuirk(QUIRK_ACTIVE, bamf_view_is_active(BAMF_VIEW(m_App)));
64 SetQuirk(QUIRK_RUNNING, bamf_view_is_running(BAMF_VIEW(m_App)));
65
66- g_free(icon_name);
67-
68 g_signal_connect(app, "child-removed", (GCallback) &BamfLauncherIcon::OnChildRemoved, this);
69 g_signal_connect(app, "child-added", (GCallback) &BamfLauncherIcon::OnChildAdded, this);
70 g_signal_connect(app, "urgent-changed", (GCallback) &BamfLauncherIcon::OnUrgentChanged, this);
71
72=== modified file 'plugins/unityshell/src/DesktopLauncherIcon.cpp'
73--- plugins/unityshell/src/DesktopLauncherIcon.cpp 2011-11-30 03:06:44 +0000
74+++ plugins/unityshell/src/DesktopLauncherIcon.cpp 2011-12-16 10:59:25 +0000
75@@ -32,7 +32,7 @@
76 , show_in_switcher_(true)
77 {
78 tooltip_text = _("Show Desktop");
79- SetIconName("desktop");
80+ icon_name = "desktop";
81 SetQuirk(QUIRK_VISIBLE, true);
82 SetQuirk(QUIRK_RUNNING, true);
83 SetIconType(TYPE_BEGIN);
84
85=== modified file 'plugins/unityshell/src/DeviceLauncherIcon.cpp'
86--- plugins/unityshell/src/DeviceLauncherIcon.cpp 2011-12-13 08:31:21 +0000
87+++ plugins/unityshell/src/DeviceLauncherIcon.cpp 2011-12-16 10:59:25 +0000
88@@ -27,6 +27,7 @@
89 #include <NuxCore/Logger.h>
90
91 #include "DevicesSettings.h"
92+#include "IconLoader.h"
93 #include "ubus-server.h"
94 #include "UBusMessages.h"
95
96@@ -46,7 +47,7 @@
97 : SimpleLauncherIcon(launcher)
98 , volume_(volume)
99 , device_file_(g_volume_get_identifier(volume_, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE))
100- , gdu_device_(get_device_for_device_file(device_file_.Value()))
101+ , gdu_device_(get_device_for_device_file(device_file_))
102 {
103 DevicesSettings::GetDefault().changed.connect(sigc::mem_fun(this, &DeviceLauncherIcon::OnSettingsChanged));
104
105@@ -67,8 +68,8 @@
106 glib::Object<GIcon> icon(g_volume_get_icon(volume_));
107 glib::String icon_string(g_icon_to_string(icon));
108
109- tooltip_text = name.Value();
110- SetIconName(icon_string.Value());
111+ tooltip_text = name.Str();
112+ icon_name = icon_string.Str();
113
114 SetIconType(TYPE_DEVICE);
115 SetQuirk(QUIRK_RUNNING, false);
116@@ -291,18 +292,32 @@
117 DeviceLauncherIcon* self)
118 {
119 if (g_volume_eject_with_operation_finish(self->volume_, result, NULL))
120- {
121- NotifyNotification* notification;
122- glib::String name(g_volume_get_name(self->volume_));
123-
124- notification = notify_notification_new(name.Value(),
125- _("The drive has been successfully ejected"),
126- "drive-removable-media-usb");
127-
128- notify_notification_show(notification, NULL);
129+ {
130+ IconLoader::GetDefault().LoadFromGIconString(self->icon_name(), 48,
131+ sigc::mem_fun(self, &DeviceLauncherIcon::ShowNotification));
132 }
133 }
134
135+void DeviceLauncherIcon::ShowNotification(std::string const& icon_name,
136+ unsigned size,
137+ GdkPixbuf* pixbuf)
138+{
139+
140+ glib::String name(g_volume_get_name(volume_));
141+ glib::Object<NotifyNotification> notification(notify_notification_new(name,
142+ _("The drive has been successfully ejected"),
143+ NULL));
144+
145+ notify_notification_set_hint(notification,
146+ "x-canonical-private-synchronous",
147+ g_variant_new_boolean(TRUE));
148+
149+ if(GDK_IS_PIXBUF(pixbuf))
150+ notify_notification_set_image_from_pixbuf(notification, pixbuf);
151+
152+ notify_notification_show(notification, NULL);
153+}
154+
155 void DeviceLauncherIcon::Eject()
156 {
157 glib::Object<GMountOperation> mount_op(gtk_mount_operation_new(NULL));
158
159=== modified file 'plugins/unityshell/src/DeviceLauncherIcon.h'
160--- plugins/unityshell/src/DeviceLauncherIcon.h 2011-10-25 17:00:12 +0000
161+++ plugins/unityshell/src/DeviceLauncherIcon.h 2011-12-16 10:59:25 +0000
162@@ -65,6 +65,7 @@
163 static void OnUnmountReady(GObject* object, GAsyncResult* result, DeviceLauncherIcon* self);
164 static void OnDriveStop(DbusmenuMenuitem* item, int time, DeviceLauncherIcon* self);
165 void OnSettingsChanged();
166+ void ShowNotification(std::string const& icon_name, unsigned size, GdkPixbuf* pixbuf);
167
168 private:
169 GVolume* volume_;
170
171=== modified file 'plugins/unityshell/src/LauncherController.cpp'
172--- plugins/unityshell/src/LauncherController.cpp 2011-12-12 00:18:26 +0000
173+++ plugins/unityshell/src/LauncherController.cpp 2011-12-16 10:59:25 +0000
174@@ -343,7 +343,7 @@
175 expo_icon_ = new SimpleLauncherIcon(launcher_.GetPointer());
176
177 expo_icon_->tooltip_text = _("Workspace Switcher");
178- expo_icon_->SetIconName("workspace-switcher");
179+ expo_icon_->icon_name = "workspace-switcher";
180 expo_icon_->SetQuirk(LauncherIcon::QUIRK_VISIBLE, true);
181 expo_icon_->SetQuirk(LauncherIcon::QUIRK_RUNNING, false);
182 expo_icon_->SetIconType(LauncherIcon::TYPE_EXPO);
183
184=== modified file 'plugins/unityshell/src/SimpleLauncherIcon.cpp'
185--- plugins/unityshell/src/SimpleLauncherIcon.cpp 2011-10-06 04:18:36 +0000
186+++ plugins/unityshell/src/SimpleLauncherIcon.cpp 2011-12-16 10:59:25 +0000
187@@ -40,6 +40,7 @@
188
189 SimpleLauncherIcon::SimpleLauncherIcon(Launcher* IconManager)
190 : LauncherIcon(IconManager)
191+ , icon_name("", sigc::mem_fun(this, &SimpleLauncherIcon::SetIconName))
192 , theme_changed_id_(0)
193 {
194 LauncherIcon::mouse_down.connect(sigc::mem_fun(this, &SimpleLauncherIcon::OnMouseDown));
195@@ -97,29 +98,27 @@
196 if (texture_map[size] != 0)
197 return texture_map[size];
198
199- if (icon_name_.empty())
200+ std::string icon_string(icon_name());
201+
202+ if (icon_string.empty())
203 return 0;
204
205- if (icon_name_[0] == '/')
206- texture_map[size] = TextureFromPath(icon_name_.c_str(), size);
207+ if (icon_string[0] == '/')
208+ texture_map[size] = TextureFromPath(icon_string.c_str(), size);
209 else
210- texture_map[size] = TextureFromGtkTheme(icon_name_.c_str(), size);
211+ texture_map[size] = TextureFromGtkTheme(icon_string.c_str(), size);
212 return texture_map[size];
213 }
214
215-void SimpleLauncherIcon::SetIconName(const char* name)
216+bool SimpleLauncherIcon::SetIconName(std::string& target, std::string const& value)
217 {
218- if (name == NULL)
219- {
220- LOG_WARNING(logger) << "attempted to set NULL as IconName";
221- icon_name_.clear();
222- }
223- else
224- {
225- icon_name_ = name;
226- }
227+ if (target == value)
228+ return false;
229
230+ target = value;
231 ReloadIcon();
232+
233+ return true;
234 }
235
236 void SimpleLauncherIcon::ReloadIcon()
237
238=== modified file 'plugins/unityshell/src/SimpleLauncherIcon.h'
239--- plugins/unityshell/src/SimpleLauncherIcon.h 2011-10-06 04:18:36 +0000
240+++ plugins/unityshell/src/SimpleLauncherIcon.h 2011-12-16 10:59:25 +0000
241@@ -17,8 +17,8 @@
242 * Authored by: Jason Smith <jason.smith@canonical.com>
243 */
244
245-#ifndef SIMPLELAUNCHERICON_H
246-#define SIMPLELAUNCHERICON_H
247+#ifndef UNITYSHELL_SIMPLELAUNCHERICON_H
248+#define UNITYSHELL_SIMPLELAUNCHERICON_H
249
250 #include "LauncherIcon.h"
251
252@@ -35,11 +35,13 @@
253 SimpleLauncherIcon(Launcher* IconManager);
254 virtual ~SimpleLauncherIcon();
255
256- /* override */
257+ // override
258 nux::BaseTexture* GetTextureForSize(int size);
259
260- void SetIconName(const char* name);
261-
262+ // Properties
263+ nux::Property<std::string> icon_name;
264+
265+ // Signals
266 sigc::signal<void> activate;
267
268 protected:
269@@ -53,9 +55,9 @@
270 private:
271 void ReloadIcon();
272 static void OnIconThemeChanged(GtkIconTheme* icon_theme, gpointer data);
273+ bool SetIconName(std::string& target, std::string const& value);
274
275 private:
276- std::string icon_name_;
277 guint32 theme_changed_id_;
278
279 std::map<int, nux::BaseTexture*> texture_map;
280
281=== modified file 'plugins/unityshell/src/TrashLauncherIcon.cpp'
282--- plugins/unityshell/src/TrashLauncherIcon.cpp 2011-10-06 04:18:36 +0000
283+++ plugins/unityshell/src/TrashLauncherIcon.cpp 2011-12-16 10:59:25 +0000
284@@ -37,7 +37,7 @@
285 , proxy_("org.gnome.Nautilus", "/org/gnome/Nautilus", "org.gnome.Nautilus.FileOperations")
286 {
287 tooltip_text = _("Trash");
288- SetIconName("user-trash");
289+ icon_name = "user-trash";
290 SetQuirk(QUIRK_VISIBLE, true);
291 SetQuirk(QUIRK_RUNNING, false);
292 SetIconType(TYPE_TRASH);
293@@ -135,11 +135,11 @@
294 if (info)
295 {
296 glib::Object<GIcon> icon(g_file_info_get_icon(info));
297- glib::String icon_name(g_icon_to_string(icon));
298+ glib::String icon_string(g_icon_to_string(icon));
299
300- self->SetIconName(icon_name.Value());
301+ self->icon_name = icon_string.Str();
302
303- self->empty_ = g_strcmp0(icon_name.Value(), "user-trash") == 0;
304+ self->empty_ = (self->icon_name == "user-trash");
305 }
306 }
307
308
309=== modified file 'standalone-clients/CMakeLists.txt'
310--- standalone-clients/CMakeLists.txt 2011-12-02 14:40:16 +0000
311+++ standalone-clients/CMakeLists.txt 2011-12-16 10:59:25 +0000
312@@ -217,6 +217,8 @@
313 ${UNITY_SRC}/FavoriteStore.h
314 ${UNITY_SRC}/FavoriteStoreGSettings.cpp
315 ${UNITY_SRC}/FavoriteStoreGSettings.h
316+ ${UNITY_SRC}/IconLoader.cpp
317+ ${UNITY_SRC}/IconLoader.h
318 ${UNITY_SRC}/LauncherEntryRemoteModel.cpp
319 ${UNITY_SRC}/LauncherEntryRemoteModel.h
320 ${UNITY_SRC}/LauncherEntryRemote.cpp
321@@ -261,6 +263,8 @@
322 ${UNITY_SRC}/QuicklistView.h
323 ${UNITY_SRC}/QuicklistManager.cpp
324 ${UNITY_SRC}/QuicklistManager.h
325+ ${UNITY_SRC}/Timer.cpp
326+ ${UNITY_SRC}/Timer.h
327 ${UNITY_SRC}/UBusMessages.h
328 ${UNITY_SRC}/UBusWrapper.cpp
329 ${UNITY_SRC}/UBusWrapper.h