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
=== modified file 'src/DeviceLauncherIcon.cpp'
--- src/DeviceLauncherIcon.cpp 2011-02-24 14:17:13 +0000
+++ src/DeviceLauncherIcon.cpp 2011-03-06 01:32:55 +0000
@@ -104,6 +104,7 @@
104{104{
105 std::list<DbusmenuMenuitem *> result;105 std::list<DbusmenuMenuitem *> result;
106 DbusmenuMenuitem *menu_item;106 DbusmenuMenuitem *menu_item;
107 GDrive *drive;
107108
108 menu_item = dbusmenu_menuitem_new ();109 menu_item = dbusmenu_menuitem_new ();
109 dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Open"));110 dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Open"));
@@ -124,6 +125,19 @@
124 result.push_back (menu_item);125 result.push_back (menu_item);
125 }126 }
126127
128 drive = g_volume_get_drive (_volume);
129 if (drive && g_drive_can_stop (drive))
130 {
131 menu_item = dbusmenu_menuitem_new ();
132 dbusmenu_menuitem_property_set (menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Safely remove"));
133 dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
134 dbusmenu_menuitem_property_set_bool (menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
135 g_signal_connect (menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
136 G_CALLBACK (&DeviceLauncherIcon::OnDriveStop), this);
137 result.push_back (menu_item);
138 g_object_unref (drive);
139 }
140
127 return result;141 return result;
128}142}
129143
@@ -262,3 +276,40 @@
262{276{
263 self->Remove ();277 self->Remove ();
264}278}
279
280void
281DeviceLauncherIcon::OnDriveStop (DbusmenuMenuitem *item, int time, DeviceLauncherIcon *self)
282{
283 g_debug ("%s", G_STRLOC);
284 self->StopDrive ();
285 g_debug ("%s", G_STRLOC);
286}
287
288void
289DeviceLauncherIcon::StopDrive ()
290{
291 GDrive *drive;
292
293 drive = g_volume_get_drive (_volume);
294 g_debug ("%s", G_STRLOC);
295 g_drive_stop (drive,
296 (GMountUnmountFlags)0,
297 NULL,
298 NULL,
299 (GAsyncReadyCallback)OnStopDriveReady,
300 this);
301 g_object_unref (drive);
302 g_debug ("%s", G_STRLOC);
303}
304
305void
306DeviceLauncherIcon::OnStopDriveReady (GObject *object,
307 GAsyncResult *result,
308 DeviceLauncherIcon *self)
309{
310 GDrive *drive;
311
312 drive = g_volume_get_drive (self->_volume);
313 g_drive_stop_finish (drive, result, NULL);
314 g_object_unref (drive);
315}
265316
=== modified file 'src/DeviceLauncherIcon.h'
--- src/DeviceLauncherIcon.h 2011-02-22 13:46:36 +0000
+++ src/DeviceLauncherIcon.h 2011-03-06 01:32:55 +0000
@@ -43,11 +43,14 @@
43 void ActivateLauncherIcon ();43 void ActivateLauncherIcon ();
44 void ShowMount (GMount *mount);44 void ShowMount (GMount *mount);
45 void Eject ();45 void Eject ();
46 void StopDrive ();
46 static void OnOpen (DbusmenuMenuitem *item, int time, DeviceLauncherIcon *self);47 static void OnOpen (DbusmenuMenuitem *item, int time, DeviceLauncherIcon *self);
47 static void OnEject (DbusmenuMenuitem *item, int time, DeviceLauncherIcon *self);48 static void OnEject (DbusmenuMenuitem *item, int time, DeviceLauncherIcon *self);
48 static void OnRemoved (GVolume *volume, DeviceLauncherIcon *self);49 static void OnRemoved (GVolume *volume, DeviceLauncherIcon *self);
49 static void OnMountReady (GObject *object, GAsyncResult *result, DeviceLauncherIcon *self);50 static void OnMountReady (GObject *object, GAsyncResult *result, DeviceLauncherIcon *self);
50 static void OnEjectReady (GObject *object, GAsyncResult *result, DeviceLauncherIcon *self);51 static void OnEjectReady (GObject *object, GAsyncResult *result, DeviceLauncherIcon *self);
52 static void OnDriveStop (DbusmenuMenuitem *item, int time, DeviceLauncherIcon *self);
53 static void OnStopDriveReady (GObject *object, GAsyncResult *result, DeviceLauncherIcon *self);
5154
52private:55private:
53 GVolume *_volume;56 GVolume *_volume;