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

Proposed by Andrea Azzarone on 2016-01-24
Status: Merged
Approved by: Marco Trevisan (Treviño) on 2016-02-25
Approved revision: 4078
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 continuous-integration Approve on 2016-02-25
Marco Trevisan (Treviño) 2016-01-24 Approve on 2016-02-25
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.
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
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.

lp:~azzar1/unity/format-option updated on 2016-02-09
4068. By Matthias Klose on 2016-02-08

debian: Multiarchify the library packages.

Manual sync with debian packaging

4069. By Marco Trevisan (Treviño) on 2016-02-09

Launcher: add FileManager, Trash and Volume icons integration

Now the launcher will link each nautilus window to the related volume or trash
icon, while the Nautilus launcher icon will only be active if the file manager is
browsing other locations.
It's now possible to manage sub-windows from the parent icon like it happens for
every other application (so even spreading them or select from QL)

The windows management logic has been moved to WindowedLauncherIcon which is a
base class of ApplicationLauncherIcon, and StorageLauncherIcon.
VolumeLauncherIcon and TrashLauncherIcon are now based on StorageLauncherIcon
which connects to the FileManager to get the windows for a given location.

FileManagerLauncherIcon is now special and is both an ApplicationLauncherIcon
and a StorageLauncherIcon, and uses the parent application only for some tasks.

Lots of random code cleanup included too. Fixes: #1063823, #1063838, #1161323, #1524721
Approved by: PS Jenkins bot, Andrea Azzarone

4070. By Marco Trevisan (Treviño) on 2016-02-09

SwitcherModel: avoid to access to invalid selection or to divide by zero Fixes: #1537524
Approved by: PS Jenkins bot, Andrea Azzarone

4071. By Didier Roche on 2016-02-09

debian: Recommends session-shortcuts, prodiving easy way to shutdown, reboot and logout from dash
Approved by: Marco Trevisan (Treviño)

4072. By Marco Trevisan (Treviño) on 2016-02-09

CMake: use GNUInstallDirs with native multi-arch support

We can now use CMAKE_INSTALL_*DIR instead of defining them manually.
Also disable networkarea region plugin build by default. Fixes: #1485668, #1508635
Approved by: Andrea Azzarone

4073. By handsome_feng on 2016-02-09

Extend the lockscreen theme for kylin.
Approved by: PS Jenkins bot, Marco Trevisan (Treviño)

4074. By CI Train Bot Account on 2016-02-09

Releasing 7.4.0+16.04.20160209.3-0ubuntu1

lp:~azzar1/unity/format-option updated on 2016-02-25
4075. By Andrea Azzarone on 2016-02-24

Merge with trunk.

4076. By Andrea Azzarone on 2016-02-24

Use proper unicode char for triple dots.

4077. By Andrea Azzarone on 2016-02-24

Avoid the useless std::string.

4078. By Andrea Azzarone on 2016-02-25

Properly launch gnome-disk.

Andrea Azzarone (azzar1) wrote :

Done.

Marco Trevisan (Treviño) (3v1n0) wrote :

Looks good now, thanks!

review: Approve
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));