Merge lp:~azzar1/unity/fix-994163 into lp:unity

Proposed by Andrea Azzarone
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 2429
Proposed branch: lp:~azzar1/unity/fix-994163
Merge into: lp:unity
Diff against target: 232 lines (+65/-64)
5 files modified
launcher/DeviceLauncherIcon.cpp (+40/-28)
launcher/DeviceLauncherIcon.h (+10/-4)
launcher/DeviceLauncherSection.cpp (+0/-30)
launcher/DeviceLauncherSection.h (+0/-2)
manual-tests/Launcher.txt (+15/-0)
To merge this branch: bzr merge lp:~azzar1/unity/fix-994163
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Review via email: mp+111092@code.launchpad.net

Commit message

Remove internal partitions after they have been unmounted.

Description of the change

== Problem ==
Unity launcher shows internal partitions after they have been unmounted

== Fix ==
Use "changed" signal instead of "mount-added"/"mount-removed".

== Test ==
Manual test

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

16 + typedef glib::Signal<void, GVolume*> VolumeSignal;
17 + sig_manager_.Add(new VolumeSignal(volume_, "changed", sigc::mem_fun(this, &DeviceLauncherIcon::OnVolumeChanged)));

Since DeviceLauncherIcon just uses one signal I think that you can avoid to use the SignalManager and save some overhead by just adding a glib::Signal class member and using its Connect method...

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

> 16 + typedef glib::Signal<void, GVolume*> VolumeSignal;
> 17 + sig_manager_.Add(new VolumeSignal(volume_, "changed",
> sigc::mem_fun(this, &DeviceLauncherIcon::OnVolumeChanged)));
>
> Since DeviceLauncherIcon just uses one signal I think that you can avoid to
> use the SignalManager and save some overhead by just adding a glib::Signal
> class member and using its Connect method...

Done.

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

Code looks good, fix works.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/DeviceLauncherIcon.cpp'
2--- launcher/DeviceLauncherIcon.cpp 2012-06-15 02:03:31 +0000
3+++ launcher/DeviceLauncherIcon.cpp 2012-06-20 06:00:31 +0000
4@@ -40,12 +40,16 @@
5
6 nux::logging::Logger logger("unity.launcher");
7
8+const unsigned int volume_changed_timeout = 500;
9+
10 }
11
12 DeviceLauncherIcon::DeviceLauncherIcon(glib::Object<GVolume> const& volume)
13 : SimpleLauncherIcon()
14 , volume_(volume)
15 {
16+ signal_volume_changed_.Connect(volume, "changed", sigc::mem_fun(this, &DeviceLauncherIcon::OnVolumeChanged));
17+
18 DevicesSettings::GetDefault().changed.connect(sigc::mem_fun(this, &DeviceLauncherIcon::OnSettingsChanged));
19
20 // Checks if in favorites!
21@@ -59,6 +63,42 @@
22 UpdateVisibility();
23 }
24
25+void DeviceLauncherIcon::OnVolumeChanged(GVolume* volume)
26+{
27+ if (!G_IS_VOLUME(volume))
28+ return;
29+
30+ changed_timeout_.reset(new glib::Timeout(volume_changed_timeout, [this]() {
31+ UpdateDeviceIcon();
32+ UpdateVisibility();
33+ return false;
34+ }));
35+}
36+
37+void DeviceLauncherIcon::UpdateVisibility()
38+{
39+ switch (DevicesSettings::GetDefault().GetDevicesOption())
40+ {
41+ case DevicesSettings::NEVER:
42+ SetQuirk(QUIRK_VISIBLE, false);
43+ break;
44+ case DevicesSettings::ONLY_MOUNTED:
45+ if (keep_in_launcher_)
46+ {
47+ SetQuirk(QUIRK_VISIBLE, true);
48+ }
49+ else
50+ {
51+ glib::Object<GMount> mount(g_volume_get_mount(volume_));
52+ SetQuirk(QUIRK_VISIBLE, mount);
53+ }
54+ break;
55+ case DevicesSettings::ALWAYS:
56+ SetQuirk(QUIRK_VISIBLE, true);
57+ break;
58+ }
59+}
60+
61 void DeviceLauncherIcon::UpdateDeviceIcon()
62 {
63 name_ = glib::String(g_volume_get_name(volume_)).Str();
64@@ -395,34 +435,6 @@
65 NULL);
66 }
67
68-void DeviceLauncherIcon::UpdateVisibility(int visibility)
69-{
70- switch (DevicesSettings::GetDefault().GetDevicesOption())
71- {
72- case DevicesSettings::NEVER:
73- SetQuirk(QUIRK_VISIBLE, false);
74- break;
75- case DevicesSettings::ONLY_MOUNTED:
76- if (keep_in_launcher_)
77- {
78- SetQuirk(QUIRK_VISIBLE, true);
79- }
80- else if (visibility < 0)
81- {
82- glib::Object<GMount> mount(g_volume_get_mount(volume_));
83- SetQuirk(QUIRK_VISIBLE, mount.RawPtr() != NULL);
84- }
85- else
86- {
87- SetQuirk(QUIRK_VISIBLE, visibility);
88- }
89- break;
90- case DevicesSettings::ALWAYS:
91- SetQuirk(QUIRK_VISIBLE, true);
92- break;
93- }
94-}
95-
96 void DeviceLauncherIcon::OnSettingsChanged()
97 {
98 // Checks if in favourites!
99
100=== modified file 'launcher/DeviceLauncherIcon.h'
101--- launcher/DeviceLauncherIcon.h 2012-06-15 02:03:31 +0000
102+++ launcher/DeviceLauncherIcon.h 2012-06-20 06:00:31 +0000
103@@ -22,6 +22,8 @@
104
105 #include <gio/gio.h>
106 #include <UnityCore/GLibWrapper.h>
107+#include <UnityCore/GLibSignal.h>
108+
109 #include "SimpleLauncherIcon.h"
110
111 namespace unity
112@@ -35,17 +37,17 @@
113 public:
114 DeviceLauncherIcon(glib::Object<GVolume> const& volume);
115
116- void UpdateVisibility(int visibility = -1);
117 void OnRemoved();
118 bool CanEject();
119 void Eject();
120
121 protected:
122 std::list<DbusmenuMenuitem*> GetMenus();
123+ std::string GetName() const;
124+
125+private:
126+ void UpdateVisibility();
127 void UpdateDeviceIcon();
128- std::string GetName() const;
129-
130-private:
131 void ActivateLauncherIcon(ActionArg arg);
132 void ShowMount(GMount* mount);
133 void Unmount();
134@@ -59,11 +61,15 @@
135 static void OnEjectReady(GObject* object, GAsyncResult* result, DeviceLauncherIcon* self);
136 static void OnUnmountReady(GObject* object, GAsyncResult* result, DeviceLauncherIcon* self);
137 static void OnDriveStop(DbusmenuMenuitem* item, int time, DeviceLauncherIcon* self);
138+ void OnVolumeChanged(GVolume* volume);
139 void OnSettingsChanged();
140 void ShowNotification(std::string const&, unsigned, glib::Object<GdkPixbuf> const&, std::string const&);
141
142 private:
143+ glib::Signal<void, GVolume*> signal_volume_changed_;
144+ glib::Source::UniquePtr changed_timeout_;
145 glib::Object<GVolume> volume_;
146+
147 std::string name_;
148 bool keep_in_launcher_;
149 };
150
151=== modified file 'launcher/DeviceLauncherSection.cpp'
152--- launcher/DeviceLauncherSection.cpp 2012-06-12 06:32:09 +0000
153+++ launcher/DeviceLauncherSection.cpp 2012-06-20 06:00:31 +0000
154@@ -30,10 +30,6 @@
155 sig_manager_.Add(new VolumeSignal(monitor_, "volume-added", sigc::mem_fun(this, &DeviceLauncherSection::OnVolumeAdded)));
156 sig_manager_.Add(new VolumeSignal(monitor_, "volume-removed", sigc::mem_fun(this, &DeviceLauncherSection::OnVolumeRemoved)));
157
158- typedef glib::Signal<void, GVolumeMonitor*, GMount*> MountSignal;
159- sig_manager_.Add(new MountSignal(monitor_, "mount-added", sigc::mem_fun(this, &DeviceLauncherSection::OnMountAdded)));
160- sig_manager_.Add(new MountSignal(monitor_, "mount-pre-unmount", sigc::mem_fun(this, &DeviceLauncherSection::OnMountPreUnmount)));
161-
162 device_populate_idle_.Run([&] () {
163 PopulateEntries();
164 return false;
165@@ -88,31 +84,5 @@
166 }
167 }
168
169-/* Keep in mind: we could have a GMount without a related GVolume
170- * so check everything to avoid unwanted behaviors.
171- */
172-void DeviceLauncherSection::OnMountAdded(GVolumeMonitor* monitor, GMount* mount)
173-{
174- glib::Object<GVolume> volume(g_mount_get_volume(mount));
175-
176- auto volume_it = map_.find(volume);
177-
178- if (volume_it != map_.end())
179- volume_it->second->UpdateVisibility(1);
180-}
181-
182-/* We don't use "mount-removed" signal since it is received after "volume-removed"
183- * signal. You should read also the comment above.
184- */
185-void DeviceLauncherSection::OnMountPreUnmount(GVolumeMonitor* monitor, GMount* mount)
186-{
187- glib::Object<GVolume> volume(g_mount_get_volume(mount));
188-
189- auto volume_it = map_.find(volume);
190-
191- if (volume_it != map_.end())
192- volume_it->second->UpdateVisibility(0);
193-}
194-
195 } // namespace launcher
196 } // namespace unity
197
198=== modified file 'launcher/DeviceLauncherSection.h'
199--- launcher/DeviceLauncherSection.h 2012-06-12 06:32:09 +0000
200+++ launcher/DeviceLauncherSection.h 2012-06-20 06:00:31 +0000
201@@ -50,8 +50,6 @@
202
203 void OnVolumeAdded(GVolumeMonitor* monitor, GVolume* volume);
204 void OnVolumeRemoved(GVolumeMonitor* monitor, GVolume* volume);
205- void OnMountAdded(GVolumeMonitor* monitor, GMount* mount);
206- void OnMountPreUnmount(GVolumeMonitor* monitor, GMount* mount);
207
208 private:
209 std::map<GVolume*, DeviceLauncherIcon*> map_;
210
211=== modified file 'manual-tests/Launcher.txt'
212--- manual-tests/Launcher.txt 2012-06-15 02:03:31 +0000
213+++ manual-tests/Launcher.txt 2012-06-20 06:00:31 +0000
214@@ -562,3 +562,18 @@
215 Expected Results:
216 * There are no icons doubled up in the Launcher
217 * All icons are present in the Launcher
218+
219+
220+Test launcher removes device icons
221+------------------------------------------------------------
222+This test makes sure that Unity doesn't shows internal partitions after
223+they have been unmounted.
224+
225+Actions:
226+ * Open Nautilus
227+ * Mount an internal partition using the sidebar
228+ * Make sure the launcher has the launcher icon for the partition
229+ * Unmount that partition using Nautilus
230+
231+Expected Results:
232+ * The device launcher icon has been removed.