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

Proposed by Andrea Azzarone
Status: Merged
Approved by: Neil J. Patel
Approved revision: no longer in the source branch.
Merge reported by: Neil J. Patel
Merged at revision: not available
Proposed branch: lp:~azzar1/unity/fix-814610
Merge into: lp:unity
Diff against target: 142 lines (+69/-3)
3 files modified
CMakeLists.txt (+1/-1)
plugins/unityshell/src/DeviceLauncherIcon.cpp (+62/-1)
plugins/unityshell/src/DeviceLauncherIcon.h (+6/-1)
To merge this branch: bzr merge lp:~azzar1/unity/fix-814610
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+76857@code.launchpad.net

Description of the change

Adds a "Format..." quicklist item to device icons (optical devices and mp4 should not have this quicklist item).

Following nautilus example, it uses gnome disk utility format tool. Here's how it appears: http://people.ubuntu.com/~andyrock/Format.png

Didier told me that this require an FFe.

To post a comment you must log in.
Revision history for this message
Didier Roche-Tolomelli (didrocks) wrote :

See the comment on the attached bug report. Maybe pending it for P?

Revision history for this message
Neil J. Patel (njpatel) wrote :

I'm approving this but let's wait until we branch for P to merge as it adds new strings.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2011-09-22 15:30:45 +0000
3+++ CMakeLists.txt 2011-09-24 14:45:28 +0000
4@@ -121,7 +121,7 @@
5 #
6 # Compiz Plugins
7 #
8-set (UNITY_PLUGIN_DEPS "compiz;nux-1.0 >= 1.2.2;libbamf3;dee-1.0;gio-2.0;gio-unix-2.0;dbusmenu-glib-0.4;x11;libstartup-notification-1.0;gthread-2.0;indicator3-0.4;atk;unity-misc >= 0.4.0;gconf-2.0;libutouch-geis;gtk+-3.0 >= 3.1;sigc++-2.0;json-glib-1.0;libnotify;gnome-desktop-3.0")
9+set (UNITY_PLUGIN_DEPS "compiz;nux-1.0 >= 1.2.2;libbamf3;dee-1.0;gio-2.0;gio-unix-2.0;dbusmenu-glib-0.4;x11;libstartup-notification-1.0;gthread-2.0;indicator3-0.4;atk;unity-misc >= 0.4.0;gconf-2.0;libutouch-geis;gtk+-3.0 >= 3.1;sigc++-2.0;json-glib-1.0;libnotify;gnome-desktop-3.0;gdu")
10
11
12 find_package (Compiz REQUIRED)
13
14=== modified file 'plugins/unityshell/src/DeviceLauncherIcon.cpp'
15--- plugins/unityshell/src/DeviceLauncherIcon.cpp 2011-09-08 04:49:34 +0000
16+++ plugins/unityshell/src/DeviceLauncherIcon.cpp 2011-09-24 14:45:28 +0000
17@@ -35,12 +35,17 @@
18 namespace
19 {
20 nux::logging::Logger logger("unity.launcher");
21+
22+GduDevice* get_device_for_device_file (const gchar *device_file);
23+
24 }
25
26 DeviceLauncherIcon::DeviceLauncherIcon(Launcher* launcher, GVolume* volume)
27 : SimpleLauncherIcon(launcher)
28 , volume_(volume)
29-{
30+ , device_file_(g_volume_get_identifier(volume_, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE))
31+ , gdu_device_(get_device_for_device_file(device_file_.Value()))
32+{
33 DevicesSettings::GetDefault().changed.connect(sigc::mem_fun(this, &DeviceLauncherIcon::OnSettingsChanged));
34
35 // Checks if in favourites!
36@@ -118,6 +123,21 @@
37 G_CALLBACK(&DeviceLauncherIcon::OnOpen), this);
38
39 result.push_back(menu_item);
40+
41+ // "Format" item
42+ if (gdu_device_ && !gdu_device_is_optical_disc(gdu_device_))
43+ {
44+ menu_item = dbusmenu_menuitem_new();
45+
46+ dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Format..."));
47+ dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
48+ dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
49+
50+ g_signal_connect(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
51+ G_CALLBACK(&DeviceLauncherIcon::OnFormat), this);
52+
53+ result.push_back(menu_item);
54+ }
55
56 // "Eject" item
57 if (drive && g_drive_can_eject(drive))
58@@ -329,6 +349,32 @@
59 self->ActivateLauncherIcon(ActionArg(ActionArg::OTHER, 0));
60 }
61
62+void DeviceLauncherIcon::OnFormat(DbusmenuMenuitem* item,
63+ int time,
64+ DeviceLauncherIcon* self)
65+{
66+ glib::Error error;
67+
68+ gchar const* args[] = { "/usr/lib/gnome-disk-utility/gdu-format-tool",
69+ "--device-file",
70+ self->device_file_.Value(),
71+ NULL};
72+
73+ g_spawn_async(NULL, // working dir
74+ const_cast<gchar **>(args),
75+ NULL, // envp
76+ (GSpawnFlags) 0, // flags
77+ NULL, // child_setup
78+ NULL, // user_data
79+ NULL, // GPid *child_pid
80+ &error);
81+
82+ if (error)
83+ {
84+ LOG_WARNING(logger) << "Error launching " << args[0] << ": " << error;
85+ }
86+}
87+
88 void DeviceLauncherIcon::OnEject(DbusmenuMenuitem* item,
89 int time,
90 DeviceLauncherIcon* self)
91@@ -433,4 +479,19 @@
92 UpdateVisibility();
93 }
94
95+namespace {
96+
97+GduDevice* get_device_for_device_file(const gchar *device_file)
98+{
99+ if (device_file == NULL || strlen(device_file) <= 1)
100+ return NULL;
101+
102+ glib::Object<GduPool> pool(gdu_pool_new());
103+ GduDevice *device = gdu_pool_get_by_device_file(pool, device_file);
104+
105+ return device;
106+}
107+
108+} // anonymouse namespace
109+
110 } // namespace unity
111
112=== modified file 'plugins/unityshell/src/DeviceLauncherIcon.h'
113--- plugins/unityshell/src/DeviceLauncherIcon.h 2011-08-25 10:33:02 +0000
114+++ plugins/unityshell/src/DeviceLauncherIcon.h 2011-09-24 14:45:28 +0000
115@@ -21,8 +21,10 @@
116 #define _DEVICE_LAUNCHER_ICON_H__H
117
118 #include <gio/gio.h>
119+#define GDU_API_IS_SUBJECT_TO_CHANGE
120+G_BEGIN_DECLS
121+#include <gdu/gdu.h>
122 #include <UnityCore/GLibWrapper.h>
123-
124 #include "SimpleLauncherIcon.h"
125
126 namespace unity {
127@@ -51,6 +53,7 @@
128 void StopDrive();
129 static void OnTogglePin(DbusmenuMenuitem* item, int time, DeviceLauncherIcon* self);
130 static void OnOpen(DbusmenuMenuitem* item, int time, DeviceLauncherIcon* self);
131+ static void OnFormat(DbusmenuMenuitem* item, int time, DeviceLauncherIcon* self);
132 static void OnEject(DbusmenuMenuitem* item, int time, DeviceLauncherIcon* self);
133 static void OnUnmount(DbusmenuMenuitem* item, int time, DeviceLauncherIcon* self);
134 static void OnChanged(GVolume* volume, DeviceLauncherIcon* self);
135@@ -62,6 +65,8 @@
136
137 private:
138 GVolume* volume_;
139+ glib::String device_file_;
140+ glib::Object<GduDevice> gdu_device_;
141 bool keep_in_launcher_;
142 };
143