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

Proposed by Andrea Azzarone
Status: Merged
Approved by: Łukasz Zemczak
Approved revision: no longer in the source branch.
Merged at revision: 2372
Proposed branch: lp:~azzar1/unity/fix-994163-5.0
Merge into: lp:unity/5.0
Diff against target: 247 lines (+79/-64)
5 files modified
manual-tests/Launcher.txt (+16/-0)
plugins/unityshell/src/DeviceLauncherIcon.cpp (+52/-28)
plugins/unityshell/src/DeviceLauncherIcon.h (+11/-4)
plugins/unityshell/src/DeviceLauncherSection.cpp (+0/-30)
plugins/unityshell/src/DeviceLauncherSection.h (+0/-2)
To merge this branch: bzr merge lp:~azzar1/unity/fix-994163-5.0
Reviewer Review Type Date Requested Status
Łukasz Zemczak Approve
Review via email: mp+111651@code.launchpad.net

Commit message

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
Łukasz Zemczak (sil2100) wrote :

Works for me.

review: Approve

Preview Diff

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

Subscribers

People subscribed via source and target branches

to all changes: