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
=== modified file 'manual-tests/Launcher.txt'
--- manual-tests/Launcher.txt 2012-04-26 05:56:55 +0000
+++ manual-tests/Launcher.txt 2012-06-22 17:27:18 +0000
@@ -540,3 +540,19 @@
540540
541Expected Results:541Expected Results:
542 * Terminal window will be raised to the top of the stack (over the GIMP window)542 * Terminal window will be raised to the top of the stack (over the GIMP window)
543
544
545Test launcher removes device icons
546------------------------------------------------------------
547This test makes sure that Unity doesn't shows internal partitions after
548they have been unmounted.
549
550Actions:
551 * Open Nautilus
552 * Mount an internal partition using the sidebar
553 * Make sure the launcher has the launcher icon for the partition
554 * Unmount that partition using Nautilus
555
556Expected Results:
557 * The device launcher icon has been removed.
558
543559
=== modified file 'plugins/unityshell/src/DeviceLauncherIcon.cpp'
--- plugins/unityshell/src/DeviceLauncherIcon.cpp 2012-04-24 18:22:48 +0000
+++ plugins/unityshell/src/DeviceLauncherIcon.cpp 2012-06-22 17:27:18 +0000
@@ -40,6 +40,7 @@
40nux::logging::Logger logger("unity.launcher");40nux::logging::Logger logger("unity.launcher");
4141
42GduDevice* get_device_for_device_file (const gchar *device_file);42GduDevice* get_device_for_device_file (const gchar *device_file);
43const unsigned int volume_changed_timeout = 500;
4344
44}45}
4546
@@ -49,6 +50,8 @@
49 , device_file_(g_volume_get_identifier(volume_, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE))50 , device_file_(g_volume_get_identifier(volume_, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE))
50 , gdu_device_(get_device_for_device_file(device_file_))51 , gdu_device_(get_device_for_device_file(device_file_))
51{52{
53 signal_volume_changed_.Connect(volume, "changed", sigc::mem_fun(this, &DeviceLauncherIcon::OnVolumeChanged));
54
52 DevicesSettings::GetDefault().changed.connect(sigc::mem_fun(this, &DeviceLauncherIcon::OnSettingsChanged));55 DevicesSettings::GetDefault().changed.connect(sigc::mem_fun(this, &DeviceLauncherIcon::OnSettingsChanged));
5356
54 // Checks if in favourites!57 // Checks if in favourites!
@@ -62,6 +65,55 @@
62 UpdateVisibility();65 UpdateVisibility();
63}66}
6467
68DeviceLauncherIcon::~DeviceLauncherIcon()
69{
70 if (changed_timeout_ > 0)
71 g_source_remove(changed_timeout_);
72}
73
74void DeviceLauncherIcon::OnVolumeChanged(GVolume* volume)
75{
76 if (!G_IS_VOLUME(volume))
77 return;
78
79 if (changed_timeout_ > 0)
80 g_source_remove(changed_timeout_);
81 changed_timeout_ = g_timeout_add(volume_changed_timeout, &DeviceLauncherIcon::OnVolumeChangedTimeout, this);
82}
83
84gboolean DeviceLauncherIcon::OnVolumeChangedTimeout(gpointer data)
85{
86 DeviceLauncherIcon* self = static_cast<DeviceLauncherIcon*>(data);
87
88 self->UpdateDeviceIcon();
89 self->UpdateVisibility();
90 return FALSE;
91}
92
93void DeviceLauncherIcon::UpdateVisibility()
94{
95 switch (DevicesSettings::GetDefault().GetDevicesOption())
96 {
97 case DevicesSettings::NEVER:
98 SetQuirk(QUIRK_VISIBLE, false);
99 break;
100 case DevicesSettings::ONLY_MOUNTED:
101 if (keep_in_launcher_)
102 {
103 SetQuirk(QUIRK_VISIBLE, true);
104 }
105 else
106 {
107 glib::Object<GMount> mount(g_volume_get_mount(volume_));
108 SetQuirk(QUIRK_VISIBLE, mount);
109 }
110 break;
111 case DevicesSettings::ALWAYS:
112 SetQuirk(QUIRK_VISIBLE, true);
113 break;
114 }
115}
116
65void DeviceLauncherIcon::UpdateDeviceIcon()117void DeviceLauncherIcon::UpdateDeviceIcon()
66{118{
67 name_ = glib::String(g_volume_get_name(volume_)).Str();119 name_ = glib::String(g_volume_get_name(volume_)).Str();
@@ -440,34 +492,6 @@
440 NULL);492 NULL);
441}493}
442494
443void DeviceLauncherIcon::UpdateVisibility(int visibility)
444{
445 switch (DevicesSettings::GetDefault().GetDevicesOption())
446 {
447 case DevicesSettings::NEVER:
448 SetQuirk(QUIRK_VISIBLE, false);
449 break;
450 case DevicesSettings::ONLY_MOUNTED:
451 if (keep_in_launcher_)
452 {
453 SetQuirk(QUIRK_VISIBLE, true);
454 }
455 else if (visibility < 0)
456 {
457 glib::Object<GMount> mount(g_volume_get_mount(volume_));
458 SetQuirk(QUIRK_VISIBLE, mount.RawPtr() != NULL);
459 }
460 else
461 {
462 SetQuirk(QUIRK_VISIBLE, visibility);
463 }
464 break;
465 case DevicesSettings::ALWAYS:
466 SetQuirk(QUIRK_VISIBLE, true);
467 break;
468 }
469}
470
471void DeviceLauncherIcon::OnSettingsChanged()495void DeviceLauncherIcon::OnSettingsChanged()
472{496{
473 // Checks if in favourites!497 // Checks if in favourites!
474498
=== modified file 'plugins/unityshell/src/DeviceLauncherIcon.h'
--- plugins/unityshell/src/DeviceLauncherIcon.h 2012-04-24 18:22:48 +0000
+++ plugins/unityshell/src/DeviceLauncherIcon.h 2012-06-22 17:27:18 +0000
@@ -25,6 +25,8 @@
25G_BEGIN_DECLS25G_BEGIN_DECLS
26#include <gdu/gdu.h>26#include <gdu/gdu.h>
27#include <UnityCore/GLibWrapper.h>27#include <UnityCore/GLibWrapper.h>
28#include <UnityCore/GLibSignal.h>
29
28#include "SimpleLauncherIcon.h"30#include "SimpleLauncherIcon.h"
2931
30namespace unity32namespace unity
@@ -37,18 +39,19 @@
3739
38public:40public:
39 DeviceLauncherIcon(glib::Object<GVolume> const& volume);41 DeviceLauncherIcon(glib::Object<GVolume> const& volume);
42 ~DeviceLauncherIcon();
4043
41 void UpdateVisibility(int visibility = -1);
42 void OnRemoved();44 void OnRemoved();
43 bool CanEject();45 bool CanEject();
44 void Eject();46 void Eject();
4547
46protected:48protected:
47 std::list<DbusmenuMenuitem*> GetMenus();49 std::list<DbusmenuMenuitem*> GetMenus();
50 std::string GetName() const;
51
52private:
53 void UpdateVisibility();
48 void UpdateDeviceIcon();54 void UpdateDeviceIcon();
49 std::string GetName() const;
50
51private:
52 void ActivateLauncherIcon(ActionArg arg);55 void ActivateLauncherIcon(ActionArg arg);
53 void ShowMount(GMount* mount);56 void ShowMount(GMount* mount);
54 void Unmount();57 void Unmount();
@@ -63,10 +66,14 @@
63 static void OnEjectReady(GObject* object, GAsyncResult* result, DeviceLauncherIcon* self);66 static void OnEjectReady(GObject* object, GAsyncResult* result, DeviceLauncherIcon* self);
64 static void OnUnmountReady(GObject* object, GAsyncResult* result, DeviceLauncherIcon* self);67 static void OnUnmountReady(GObject* object, GAsyncResult* result, DeviceLauncherIcon* self);
65 static void OnDriveStop(DbusmenuMenuitem* item, int time, DeviceLauncherIcon* self);68 static void OnDriveStop(DbusmenuMenuitem* item, int time, DeviceLauncherIcon* self);
69 static gboolean OnVolumeChangedTimeout(gpointer data);
70 void OnVolumeChanged(GVolume* volume);
66 void OnSettingsChanged();71 void OnSettingsChanged();
67 void ShowNotification(std::string const&, unsigned, GdkPixbuf*, std::string const&);72 void ShowNotification(std::string const&, unsigned, GdkPixbuf*, std::string const&);
6873
69private:74private:
75 glib::Signal<void, GVolume*> signal_volume_changed_;
76 guint changed_timeout_;
70 glib::Object<GVolume> volume_;77 glib::Object<GVolume> volume_;
71 glib::String device_file_;78 glib::String device_file_;
72 std::string name_;79 std::string name_;
7380
=== modified file 'plugins/unityshell/src/DeviceLauncherSection.cpp'
--- plugins/unityshell/src/DeviceLauncherSection.cpp 2012-04-24 18:46:07 +0000
+++ plugins/unityshell/src/DeviceLauncherSection.cpp 2012-06-22 17:27:18 +0000
@@ -30,10 +30,6 @@
30 sig_manager_.Add(new VolumeSignal(monitor_, "volume-added", sigc::mem_fun(this, &DeviceLauncherSection::OnVolumeAdded)));30 sig_manager_.Add(new VolumeSignal(monitor_, "volume-added", sigc::mem_fun(this, &DeviceLauncherSection::OnVolumeAdded)));
31 sig_manager_.Add(new VolumeSignal(monitor_, "volume-removed", sigc::mem_fun(this, &DeviceLauncherSection::OnVolumeRemoved)));31 sig_manager_.Add(new VolumeSignal(monitor_, "volume-removed", sigc::mem_fun(this, &DeviceLauncherSection::OnVolumeRemoved)));
3232
33 typedef glib::Signal<void, GVolumeMonitor*, GMount*> MountSignal;
34 sig_manager_.Add(new MountSignal(monitor_, "mount-added", sigc::mem_fun(this, &DeviceLauncherSection::OnMountAdded)));
35 sig_manager_.Add(new MountSignal(monitor_, "mount-pre-unmount", sigc::mem_fun(this, &DeviceLauncherSection::OnMountPreUnmount)));
36
37 on_device_populate_entry_id_ = g_idle_add([] (gpointer data) {33 on_device_populate_entry_id_ = g_idle_add([] (gpointer data) {
38 auto self = static_cast<DeviceLauncherSection*>(data);34 auto self = static_cast<DeviceLauncherSection*>(data);
39 self->PopulateEntries();35 self->PopulateEntries();
@@ -96,31 +92,5 @@
96 }92 }
97}93}
9894
99/* Keep in mind: we could have a GMount without a related GVolume
100 * so check everything to avoid unwanted behaviors.
101 */
102void DeviceLauncherSection::OnMountAdded(GVolumeMonitor* monitor, GMount* mount)
103{
104 glib::Object<GVolume> volume(g_mount_get_volume(mount));
105
106 auto volume_it = map_.find(volume);
107
108 if (volume_it != map_.end())
109 volume_it->second->UpdateVisibility(1);
110}
111
112/* We don't use "mount-removed" signal since it is received after "volume-removed"
113 * signal. You should read also the comment above.
114 */
115void DeviceLauncherSection::OnMountPreUnmount(GVolumeMonitor* monitor, GMount* mount)
116{
117 glib::Object<GVolume> volume(g_mount_get_volume(mount));
118
119 auto volume_it = map_.find(volume);
120
121 if (volume_it != map_.end())
122 volume_it->second->UpdateVisibility(0);
123}
124
125} // namespace launcher95} // namespace launcher
126} // namespace unity96} // namespace unity
12797
=== modified file 'plugins/unityshell/src/DeviceLauncherSection.h'
--- plugins/unityshell/src/DeviceLauncherSection.h 2012-04-24 18:46:07 +0000
+++ plugins/unityshell/src/DeviceLauncherSection.h 2012-06-22 17:27:18 +0000
@@ -50,8 +50,6 @@
5050
51 void OnVolumeAdded(GVolumeMonitor* monitor, GVolume* volume);51 void OnVolumeAdded(GVolumeMonitor* monitor, GVolume* volume);
52 void OnVolumeRemoved(GVolumeMonitor* monitor, GVolume* volume);52 void OnVolumeRemoved(GVolumeMonitor* monitor, GVolume* volume);
53 void OnMountAdded(GVolumeMonitor* monitor, GMount* mount);
54 void OnMountPreUnmount(GVolumeMonitor* monitor, GMount* mount);
5553
56private:54private:
57 glib::SignalManager sig_manager_;55 glib::SignalManager sig_manager_;

Subscribers

People subscribed via source and target branches

to all changes: