diff options
| author | Andrea Azzarone <azzaronea@gmail.com> | 2016-01-24 15:35:49 +0100 |
|---|---|---|
| committer | Andrea Azzarone <azzaronea@gmail.com> | 2016-01-24 15:35:49 +0100 |
| commit | 67f91ebd9e8b66c2690f2060b2f55a01d994f845 (patch) | |
| tree | 5e434c7ccc111584c37b98141e5ff2edac949c1e | |
| parent | 08db65d0d50bc583d30131d358de98c42b92d233 (diff) | |
Make sure a volume can be formatted.
(bzr r4067.3.3)
| -rw-r--r-- | launcher/Volume.h | 1 | ||||
| -rw-r--r-- | launcher/VolumeImp.cpp | 10 | ||||
| -rw-r--r-- | launcher/VolumeImp.h | 1 | ||||
| -rw-r--r-- | launcher/VolumeLauncherIcon.cpp | 3 | ||||
| -rw-r--r-- | tests/test_mock_devices.h | 1 | ||||
| -rw-r--r-- | tests/test_volume_launcher_icon.cpp | 1 |
6 files changed, 17 insertions, 0 deletions
diff --git a/launcher/Volume.h b/launcher/Volume.h index 59bbcf64b..b6c03ffb3 100644 --- a/launcher/Volume.h +++ b/launcher/Volume.h @@ -39,6 +39,7 @@ 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; diff --git a/launcher/VolumeImp.cpp b/launcher/VolumeImp.cpp index 5365c6750..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_)); @@ -206,6 +211,11 @@ bool VolumeImp::CanBeEjected() const return pimpl->CanBeEjected(); } +bool VolumeImp::CanBeFormatted() const +{ + return pimpl->CanBeFormatted(); +} + bool VolumeImp::CanBeRemoved() const { return pimpl->CanBeRemoved(); diff --git a/launcher/VolumeImp.h b/launcher/VolumeImp.h index d0b6ded42..47a9b0b47 100644 --- a/launcher/VolumeImp.h +++ b/launcher/VolumeImp.h @@ -41,6 +41,7 @@ public: virtual ~VolumeImp(); virtual bool CanBeEjected() const; + virtual bool CanBeFormatted() const; virtual bool CanBeRemoved() const; virtual bool CanBeStopped() const; virtual std::string GetName() const; diff --git a/launcher/VolumeLauncherIcon.cpp b/launcher/VolumeLauncherIcon.cpp index b2816a6d6..28c8659ea 100644 --- a/launcher/VolumeLauncherIcon.cpp +++ b/launcher/VolumeLauncherIcon.cpp @@ -298,6 +298,9 @@ public: 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...")); diff --git a/tests/test_mock_devices.h b/tests/test_mock_devices.h index e3bf66b4b..d429b569b 100644 --- a/tests/test_mock_devices.h +++ b/tests/test_mock_devices.h @@ -78,6 +78,7 @@ 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)); diff --git a/tests/test_volume_launcher_icon.cpp b/tests/test_volume_launcher_icon.cpp index 269b31025..1bd4f5a56 100644 --- a/tests/test_volume_launcher_icon.cpp +++ b/tests/test_volume_launcher_icon.cpp @@ -56,6 +56,7 @@ 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")); |
