Merge lp:~marcobiscaro2112/unity/fixes-660010 into lp:unity

Proposed by Marco Biscaro
Status: Merged
Merged at revision: 927
Proposed branch: lp:~marcobiscaro2112/unity/fixes-660010
Merge into: lp:unity
Diff against target: 91 lines (+54/-0)
2 files modified
src/DeviceLauncherIcon.cpp (+51/-0)
src/DeviceLauncherIcon.h (+3/-0)
To merge this branch: bzr merge lp:~marcobiscaro2112/unity/fixes-660010
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+52315@code.launchpad.net

Description of the change

When a volume is added to launcher, it is verified if it has a drive.

If it does, and if this Drive can be stopped, an entry "Safely remove" is added to the launcher entry's menu.

When the "Safely remove" entry is clicked, the method g_drive_stop is called for the volume's drive.

This change fixes LP: #660010

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

Nice work, approved & merged! I removed the g_debug's.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/DeviceLauncherIcon.cpp'
2--- src/DeviceLauncherIcon.cpp 2011-02-24 14:17:13 +0000
3+++ src/DeviceLauncherIcon.cpp 2011-03-06 01:32:55 +0000
4@@ -104,6 +104,7 @@
5 {
6 std::list<DbusmenuMenuitem *> result;
7 DbusmenuMenuitem *menu_item;
8+ GDrive *drive;
9
10 menu_item = dbusmenu_menuitem_new ();
11 dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Open"));
12@@ -124,6 +125,19 @@
13 result.push_back (menu_item);
14 }
15
16+ drive = g_volume_get_drive (_volume);
17+ if (drive && g_drive_can_stop (drive))
18+ {
19+ menu_item = dbusmenu_menuitem_new ();
20+ dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Safely remove"));
21+ dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
22+ dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
23+ g_signal_connect (menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
24+ G_CALLBACK (&DeviceLauncherIcon::OnDriveStop), this);
25+ result.push_back (menu_item);
26+ g_object_unref (drive);
27+ }
28+
29 return result;
30 }
31
32@@ -262,3 +276,40 @@
33 {
34 self->Remove ();
35 }
36+
37+void
38+DeviceLauncherIcon::OnDriveStop (DbusmenuMenuitem *item, int time, DeviceLauncherIcon *self)
39+{
40+ g_debug ("%s", G_STRLOC);
41+ self->StopDrive ();
42+ g_debug ("%s", G_STRLOC);
43+}
44+
45+void
46+DeviceLauncherIcon::StopDrive ()
47+{
48+ GDrive *drive;
49+
50+ drive = g_volume_get_drive (_volume);
51+ g_debug ("%s", G_STRLOC);
52+ g_drive_stop (drive,
53+ (GMountUnmountFlags)0,
54+ NULL,
55+ NULL,
56+ (GAsyncReadyCallback)OnStopDriveReady,
57+ this);
58+ g_object_unref (drive);
59+ g_debug ("%s", G_STRLOC);
60+}
61+
62+void
63+DeviceLauncherIcon::OnStopDriveReady (GObject *object,
64+ GAsyncResult *result,
65+ DeviceLauncherIcon *self)
66+{
67+ GDrive *drive;
68+
69+ drive = g_volume_get_drive (self->_volume);
70+ g_drive_stop_finish (drive, result, NULL);
71+ g_object_unref (drive);
72+}
73
74=== modified file 'src/DeviceLauncherIcon.h'
75--- src/DeviceLauncherIcon.h 2011-02-22 13:46:36 +0000
76+++ src/DeviceLauncherIcon.h 2011-03-06 01:32:55 +0000
77@@ -43,11 +43,14 @@
78 void ActivateLauncherIcon ();
79 void ShowMount (GMount *mount);
80 void Eject ();
81+ void StopDrive ();
82 static void OnOpen (DbusmenuMenuitem *item, int time, DeviceLauncherIcon *self);
83 static void OnEject (DbusmenuMenuitem *item, int time, DeviceLauncherIcon *self);
84 static void OnRemoved (GVolume *volume, DeviceLauncherIcon *self);
85 static void OnMountReady (GObject *object, GAsyncResult *result, DeviceLauncherIcon *self);
86 static void OnEjectReady (GObject *object, GAsyncResult *result, DeviceLauncherIcon *self);
87+ static void OnDriveStop (DbusmenuMenuitem *item, int time, DeviceLauncherIcon *self);
88+ static void OnStopDriveReady (GObject *object, GAsyncResult *result, DeviceLauncherIcon *self);
89
90 private:
91 GVolume *_volume;