diff options
| author | Andrea Azzarone <azzaronea@gmail.com> | 2016-02-24 13:05:30 +0100 |
|---|---|---|
| committer | Andrea Azzarone <azzaronea@gmail.com> | 2016-02-24 13:05:30 +0100 |
| commit | 7875e1af55be73ea1cdb67130d61e11012a5e345 (patch) | |
| tree | 50880dd1a7e37b83a4308754921ee9e56cfb4a8e | |
| parent | 825b78974ef8ad629f5dc0c55b586700ec610d3c (diff) | |
| parent | 33ede65b00a901ac1cd33e2176bc95f70ba1210a (diff) | |
Merge with trunk.
(bzr r4074.3.1)
| -rw-r--r-- | launcher/Volume.h | 2 | ||||
| -rw-r--r-- | launcher/VolumeImp.cpp | 21 | ||||
| -rw-r--r-- | launcher/VolumeImp.h | 2 | ||||
| -rw-r--r-- | launcher/VolumeLauncherIcon.cpp | 29 | ||||
| -rw-r--r-- | tests/test_mock_devices.h | 2 | ||||
| -rw-r--r-- | tests/test_volume_launcher_icon.cpp | 2 |
6 files changed, 58 insertions, 0 deletions
diff --git a/launcher/Volume.h b/launcher/Volume.h index 7df1eb7d7..b6c03ffb3 100644 --- a/launcher/Volume.h +++ b/launcher/Volume.h @@ -39,11 +39,13 @@ public: virtual ~Volume() = default; virtual bool CanBeEjected() const = 0; + virtual bool CanBeFormatted() const = 0; virtual bool CanBeRemoved() const = 0; virtual bool CanBeStopped() const = 0; virtual std::string GetName() const = 0; virtual std::string GetIconName() const = 0; virtual std::string GetIdentifier() const = 0; + virtual std::string GetUnixDevicePath() const = 0; virtual std::string GetUri() const = 0; virtual bool HasSiblings() const = 0; virtual bool IsMounted() const = 0; diff --git a/launcher/VolumeImp.cpp b/launcher/VolumeImp.cpp index dd8a574dd..f9696823a 100644 --- a/launcher/VolumeImp.cpp +++ b/launcher/VolumeImp.cpp @@ -53,6 +53,11 @@ public: return g_volume_can_eject(volume_) != FALSE; } + bool CanBeFormatted() const + { + return !GetUnixDevicePath().empty(); + } + bool CanBeRemoved() const { glib::Object<GDrive> drive(g_volume_get_drive(volume_)); @@ -84,6 +89,12 @@ public: return uuid.Str() + "-" + label.Str(); } + std::string GetUnixDevicePath() const + { + glib::String ret(g_volume_get_identifier(volume_, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE)); + return ret.Str(); + } + bool HasSiblings() const { glib::Object<GDrive> drive(g_volume_get_drive(volume_)); @@ -200,6 +211,11 @@ bool VolumeImp::CanBeEjected() const return pimpl->CanBeEjected(); } +bool VolumeImp::CanBeFormatted() const +{ + return pimpl->CanBeFormatted(); +} + bool VolumeImp::CanBeRemoved() const { return pimpl->CanBeRemoved(); @@ -225,6 +241,11 @@ std::string VolumeImp::GetIdentifier() const return pimpl->GetIdentifier(); } +std::string VolumeImp::GetUnixDevicePath() const +{ + return pimpl->GetUnixDevicePath(); +} + std::string VolumeImp::GetUri() const { return pimpl->GetUri(); diff --git a/launcher/VolumeImp.h b/launcher/VolumeImp.h index 005221c86..47a9b0b47 100644 --- a/launcher/VolumeImp.h +++ b/launcher/VolumeImp.h @@ -41,11 +41,13 @@ public: virtual ~VolumeImp(); virtual bool CanBeEjected() const; + virtual bool CanBeFormatted() const; virtual bool CanBeRemoved() const; virtual bool CanBeStopped() const; virtual std::string GetName() const; virtual std::string GetIconName() const; virtual std::string GetIdentifier() const; + virtual std::string GetUnixDevicePath() const; virtual std::string GetUri() const; virtual bool HasSiblings() const; virtual bool IsMounted() const; diff --git a/launcher/VolumeLauncherIcon.cpp b/launcher/VolumeLauncherIcon.cpp index 85eee27fc..a1a7d68dc 100644 --- a/launcher/VolumeLauncherIcon.cpp +++ b/launcher/VolumeLauncherIcon.cpp @@ -161,6 +161,7 @@ public: MenuItemsVector result; AppendOpenItem(result); + AppendFormatItem(result); AppendSeparatorItem(result); AppendNameItem(result); AppendSeparatorItem(result); @@ -295,6 +296,34 @@ public: menu.push_back(menu_item); } + void AppendFormatItem(MenuItemsVector& menu) + { + if (!volume_->CanBeFormatted()) + return; + + glib::Object<DbusmenuMenuitem> menu_item(dbusmenu_menuitem_new()); + + dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_LABEL, _("Format...")); + dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true); + dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true); + + parent_->glib_signals_.Add(new ItemSignal(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, [this] (DbusmenuMenuitem*, unsigned timestamp) { + OpenFormatPrompt(); + })); + + menu.push_back(menu_item); + } + + void OpenFormatPrompt() + { + std::string cmdline = std::string("gnome-disks") + + std::string(" --block-device ") + volume_->GetUnixDevicePath() + + std::string(" --format-device"); + + glib::Object<GAppInfo> app_info(g_app_info_create_from_commandline(cmdline.c_str(), nullptr, G_APP_INFO_CREATE_NONE, nullptr)); + g_app_info_launch(app_info, nullptr, nullptr, nullptr); + } + void AppendUnmountItem(MenuItemsVector& menu) { if (!volume_->IsMounted() || volume_->CanBeEjected() || volume_->CanBeStopped()) diff --git a/tests/test_mock_devices.h b/tests/test_mock_devices.h index 2f4218fc5..d429b569b 100644 --- a/tests/test_mock_devices.h +++ b/tests/test_mock_devices.h @@ -78,11 +78,13 @@ struct MockVolume : Volume typedef std::shared_ptr<MockVolume> Ptr; typedef testing::NiceMock<MockVolume> Nice; + MOCK_CONST_METHOD0(CanBeFormatted, bool(void)); MOCK_CONST_METHOD0(CanBeRemoved, bool(void)); MOCK_CONST_METHOD0(CanBeStopped, bool(void)); MOCK_CONST_METHOD0(GetName, std::string(void)); MOCK_CONST_METHOD0(GetIconName, std::string(void)); MOCK_CONST_METHOD0(GetIdentifier, std::string(void)); + MOCK_CONST_METHOD0(GetUnixDevicePath, std::string(void)); MOCK_CONST_METHOD0(GetUri, std::string(void)); MOCK_CONST_METHOD0(HasSiblings, bool(void)); MOCK_CONST_METHOD0(CanBeEjected, bool(void)); diff --git a/tests/test_volume_launcher_icon.cpp b/tests/test_volume_launcher_icon.cpp index 41b794bae..1bd4f5a56 100644 --- a/tests/test_volume_launcher_icon.cpp +++ b/tests/test_volume_launcher_icon.cpp @@ -56,11 +56,13 @@ struct TestVolumeLauncherIcon : public Test void SetupVolumeDefaultBehavior() { + ON_CALL(*volume_, CanBeFormatted()).WillByDefault(Return(false)); ON_CALL(*volume_, CanBeRemoved()).WillByDefault(Return(false)); ON_CALL(*volume_, CanBeStopped()).WillByDefault(Return(false)); ON_CALL(*volume_, GetName()).WillByDefault(Return("Test Name")); ON_CALL(*volume_, GetIconName()).WillByDefault(Return("Test Icon Name")); ON_CALL(*volume_, GetIdentifier()).WillByDefault(Return("Test Identifier")); + ON_CALL(*volume_, GetUnixDevicePath()).WillByDefault(Return("/dev/sda1")); ON_CALL(*volume_, GetUri()).WillByDefault(Return("file:///media/user/device_uri")); ON_CALL(*volume_, HasSiblings()).WillByDefault(Return(false)); ON_CALL(*volume_, CanBeEjected()).WillByDefault(Return(false)); |
