Merge lp:~azzar1/unity/format-option into lp:unity

Proposed by Andrea Azzarone
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 4081
Proposed branch: lp:~azzar1/unity/format-option
Merge into: lp:unity
Prerequisite: lp:~3v1n0/unity/launcher-filemanager-integration
Diff against target: 208 lines (+77/-0)
7 files modified
debian/control (+1/-0)
launcher/Volume.h (+2/-0)
launcher/VolumeImp.cpp (+21/-0)
launcher/VolumeImp.h (+2/-0)
launcher/VolumeLauncherIcon.cpp (+47/-0)
tests/test_mock_devices.h (+2/-0)
tests/test_volume_launcher_icon.cpp (+2/-0)
To merge this branch: bzr merge lp:~azzar1/unity/format-option
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Marco Trevisan (Treviño) Approve
Review via email: mp+283741@code.launchpad.net

Commit message

Add a "Format..." option to volume icons.

Description of the change

Add a "Format..." option to volume icons. Initial branch: lp:~mcintire-evan/unity/add-format-option

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Some improvements to do in order to use the event timestamp and launch context, plus a way to detect gnome-disks properly.

I guess we can also now add "gnome-disks" package to debian/control's Recommends.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) :
Revision history for this message
Andrea Azzarone (azzar1) wrote :

Done.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Looks good now, thanks!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2016-02-23 22:39:12 +0000
3+++ debian/control 2016-02-25 13:43:24 +0000
4@@ -84,6 +84,7 @@
5 Recommends: unity-control-center,
6 ${unity-default-masterscopes}
7 nautilus,
8+ gnome-disk-utility,
9 indicator-appmenu (>= 15.02.0),
10 indicator-application,
11 indicator-sound,
12
13=== modified file 'launcher/Volume.h'
14--- launcher/Volume.h 2013-10-07 16:49:04 +0000
15+++ launcher/Volume.h 2016-02-25 13:43:24 +0000
16@@ -39,11 +39,13 @@
17 virtual ~Volume() = default;
18
19 virtual bool CanBeEjected() const = 0;
20+ virtual bool CanBeFormatted() const = 0;
21 virtual bool CanBeRemoved() const = 0;
22 virtual bool CanBeStopped() const = 0;
23 virtual std::string GetName() const = 0;
24 virtual std::string GetIconName() const = 0;
25 virtual std::string GetIdentifier() const = 0;
26+ virtual std::string GetUnixDevicePath() const = 0;
27 virtual std::string GetUri() const = 0;
28 virtual bool HasSiblings() const = 0;
29 virtual bool IsMounted() const = 0;
30
31=== modified file 'launcher/VolumeImp.cpp'
32--- launcher/VolumeImp.cpp 2013-10-07 16:49:04 +0000
33+++ launcher/VolumeImp.cpp 2016-02-25 13:43:24 +0000
34@@ -53,6 +53,11 @@
35 return g_volume_can_eject(volume_) != FALSE;
36 }
37
38+ bool CanBeFormatted() const
39+ {
40+ return !GetUnixDevicePath().empty();
41+ }
42+
43 bool CanBeRemoved() const
44 {
45 glib::Object<GDrive> drive(g_volume_get_drive(volume_));
46@@ -84,6 +89,12 @@
47 return uuid.Str() + "-" + label.Str();
48 }
49
50+ std::string GetUnixDevicePath() const
51+ {
52+ glib::String ret(g_volume_get_identifier(volume_, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE));
53+ return ret.Str();
54+ }
55+
56 bool HasSiblings() const
57 {
58 glib::Object<GDrive> drive(g_volume_get_drive(volume_));
59@@ -200,6 +211,11 @@
60 return pimpl->CanBeEjected();
61 }
62
63+bool VolumeImp::CanBeFormatted() const
64+{
65+ return pimpl->CanBeFormatted();
66+}
67+
68 bool VolumeImp::CanBeRemoved() const
69 {
70 return pimpl->CanBeRemoved();
71@@ -225,6 +241,11 @@
72 return pimpl->GetIdentifier();
73 }
74
75+std::string VolumeImp::GetUnixDevicePath() const
76+{
77+ return pimpl->GetUnixDevicePath();
78+}
79+
80 std::string VolumeImp::GetUri() const
81 {
82 return pimpl->GetUri();
83
84=== modified file 'launcher/VolumeImp.h'
85--- launcher/VolumeImp.h 2013-10-07 16:49:04 +0000
86+++ launcher/VolumeImp.h 2016-02-25 13:43:24 +0000
87@@ -41,11 +41,13 @@
88 virtual ~VolumeImp();
89
90 virtual bool CanBeEjected() const;
91+ virtual bool CanBeFormatted() const;
92 virtual bool CanBeRemoved() const;
93 virtual bool CanBeStopped() const;
94 virtual std::string GetName() const;
95 virtual std::string GetIconName() const;
96 virtual std::string GetIdentifier() const;
97+ virtual std::string GetUnixDevicePath() const;
98 virtual std::string GetUri() const;
99 virtual bool HasSiblings() const;
100 virtual bool IsMounted() const;
101
102=== modified file 'launcher/VolumeLauncherIcon.cpp'
103--- launcher/VolumeLauncherIcon.cpp 2015-12-09 12:02:05 +0000
104+++ launcher/VolumeLauncherIcon.cpp 2016-02-25 13:43:24 +0000
105@@ -20,6 +20,7 @@
106
107
108 #include "config.h"
109+#include <gio/gdesktopappinfo.h>
110 #include <glib/gi18n-lib.h>
111 #include <UnityCore/ConnectionManager.h>
112 #include <UnityCore/GLibSignal.h>
113@@ -161,6 +162,7 @@
114 MenuItemsVector result;
115
116 AppendOpenItem(result);
117+ AppendFormatItem(result);
118 AppendSeparatorItem(result);
119 AppendNameItem(result);
120 AppendSeparatorItem(result);
121@@ -295,6 +297,51 @@
122 menu.push_back(menu_item);
123 }
124
125+ void AppendFormatItem(MenuItemsVector& menu)
126+ {
127+ glib::Object<GDesktopAppInfo> gd(g_desktop_app_info_new("gnome-disks.desktop"));
128+
129+ if (!volume_->CanBeFormatted() || !gd)
130+ return;
131+
132+ glib::Object<DbusmenuMenuitem> menu_item(dbusmenu_menuitem_new());
133+
134+ dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Format…"));
135+ dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true);
136+ dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true);
137+
138+ parent_->glib_signals_.Add(new ItemSignal(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, [this] (DbusmenuMenuitem*, unsigned timestamp) {
139+ OpenFormatPrompt(timestamp);
140+ }));
141+
142+ menu.push_back(menu_item);
143+ }
144+
145+ void OpenFormatPrompt(Time timestamp)
146+ {
147+ glib::Object<GDesktopAppInfo> gd_desktop_app_info(g_desktop_app_info_new("gnome-disks.desktop"));
148+
149+ if (!gd_desktop_app_info)
150+ return;
151+
152+ auto gd_app_info = glib::object_cast<GAppInfo>(gd_desktop_app_info);
153+
154+ std::string command_line = glib::gchar_to_string(g_app_info_get_executable(gd_app_info)) +
155+ " --block-device " +
156+ volume_->GetUnixDevicePath() +
157+ " --format-device";
158+
159+ GdkDisplay* display = gdk_display_get_default();
160+ glib::Object<GdkAppLaunchContext> app_launch_context(gdk_display_get_app_launch_context(display));
161+ gdk_app_launch_context_set_timestamp(app_launch_context, timestamp);
162+
163+ glib::Object<GAppInfo> app_info(g_app_info_create_from_commandline(command_line.c_str(),
164+ nullptr,
165+ G_APP_INFO_CREATE_SUPPORTS_STARTUP_NOTIFICATION,
166+ nullptr));
167+ g_app_info_launch_uris(app_info, nullptr, glib::object_cast<GAppLaunchContext>(app_launch_context), nullptr);
168+ }
169+
170 void AppendUnmountItem(MenuItemsVector& menu)
171 {
172 if (!volume_->IsMounted() || volume_->CanBeEjected() || volume_->CanBeStopped())
173
174=== modified file 'tests/test_mock_devices.h'
175--- tests/test_mock_devices.h 2013-10-07 16:49:04 +0000
176+++ tests/test_mock_devices.h 2016-02-25 13:43:24 +0000
177@@ -78,11 +78,13 @@
178 typedef std::shared_ptr<MockVolume> Ptr;
179 typedef testing::NiceMock<MockVolume> Nice;
180
181+ MOCK_CONST_METHOD0(CanBeFormatted, bool(void));
182 MOCK_CONST_METHOD0(CanBeRemoved, bool(void));
183 MOCK_CONST_METHOD0(CanBeStopped, bool(void));
184 MOCK_CONST_METHOD0(GetName, std::string(void));
185 MOCK_CONST_METHOD0(GetIconName, std::string(void));
186 MOCK_CONST_METHOD0(GetIdentifier, std::string(void));
187+ MOCK_CONST_METHOD0(GetUnixDevicePath, std::string(void));
188 MOCK_CONST_METHOD0(GetUri, std::string(void));
189 MOCK_CONST_METHOD0(HasSiblings, bool(void));
190 MOCK_CONST_METHOD0(CanBeEjected, bool(void));
191
192=== modified file 'tests/test_volume_launcher_icon.cpp'
193--- tests/test_volume_launcher_icon.cpp 2015-12-08 14:34:55 +0000
194+++ tests/test_volume_launcher_icon.cpp 2016-02-25 13:43:24 +0000
195@@ -56,11 +56,13 @@
196
197 void SetupVolumeDefaultBehavior()
198 {
199+ ON_CALL(*volume_, CanBeFormatted()).WillByDefault(Return(false));
200 ON_CALL(*volume_, CanBeRemoved()).WillByDefault(Return(false));
201 ON_CALL(*volume_, CanBeStopped()).WillByDefault(Return(false));
202 ON_CALL(*volume_, GetName()).WillByDefault(Return("Test Name"));
203 ON_CALL(*volume_, GetIconName()).WillByDefault(Return("Test Icon Name"));
204 ON_CALL(*volume_, GetIdentifier()).WillByDefault(Return("Test Identifier"));
205+ ON_CALL(*volume_, GetUnixDevicePath()).WillByDefault(Return("/dev/sda1"));
206 ON_CALL(*volume_, GetUri()).WillByDefault(Return("file:///media/user/device_uri"));
207 ON_CALL(*volume_, HasSiblings()).WillByDefault(Return(false));
208 ON_CALL(*volume_, CanBeEjected()).WillByDefault(Return(false));