diff options
| author | Peter Penz <[email protected]> | 2012-05-11 23:00:26 +0200 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2012-05-11 23:02:14 +0200 |
| commit | 28daa45a44bc172747bad6d948de2a58c8586845 (patch) | |
| tree | 0bee0a91d45dcfe57597a0dba256b393e58431d0 /src/panels/places/placesitemmodel.cpp | |
| parent | b319c59b8d1e068cf621be852ced9c5396bd77f9 (diff) | |
Places Panel: Implement eject and teardown actions
Further fixes:
- Add/remove item when device has been added/removed
- Update emblem if the accessibility-state has been changed
Diffstat (limited to 'src/panels/places/placesitemmodel.cpp')
| -rw-r--r-- | src/panels/places/placesitemmodel.cpp | 110 |
1 files changed, 93 insertions, 17 deletions
diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp index 48f54b276..815338763 100644 --- a/src/panels/places/placesitemmodel.cpp +++ b/src/panels/places/placesitemmodel.cpp @@ -48,6 +48,10 @@ #include <Solid/Device> #include <Solid/DeviceNotifier> +#include <Solid/OpticalDisc> +#include <Solid/OpticalDrive> +#include <Solid/StorageAccess> +#include <Solid/StorageDrive> PlacesItemModel::PlacesItemModel(QObject* parent) : KStandardItemModel(parent), @@ -221,31 +225,82 @@ QAction* PlacesItemModel::ejectAction(int index) const return 0; } -QAction* PlacesItemModel::tearDownAction(int index) const +QAction* PlacesItemModel::teardownAction(int index) const { - // TODO: This is a dummy-implementation to have at least all - // translation-strings as part of the code before the freeze + const PlacesItem* item = placesItem(index); + if (!item) { + return 0; + } + + Solid::Device device = item->device(); + const bool providesTearDown = device.is<Solid::StorageAccess>() && + device.as<Solid::StorageAccess>()->isAccessible(); + if (!providesTearDown) { + return 0; + } + + Solid::StorageDrive* drive = device.as<Solid::StorageDrive>(); + if (!drive) { + drive = device.parent().as<Solid::StorageDrive>(); + } + + bool hotPluggable = false; + bool removable = false; + if (drive) { + hotPluggable = drive->isHotpluggable(); + removable = drive->isRemovable(); + } + QString iconName; QString text; - QString label; - switch (index) { - case 0: + const QString label = item->text(); + if (device.is<Solid::OpticalDisc>()) { text = i18nc("@item", "Release '%1'", label); - break; - case 1: + } else if (removable || hotPluggable) { text = i18nc("@item", "Safely Remove '%1'", label); iconName = "media-eject"; - break; - case 2: + } else { text = i18nc("@item", "Unmount '%1'", label); iconName = "media-eject"; - break; - default: - break; } - //return new QAction(KIcon(iconName), text, 0); - return 0; + if (iconName.isEmpty()) { + return new QAction(text, 0); + } + + return new QAction(KIcon(iconName), text, 0); +} + +void PlacesItemModel::requestEject(int index) +{ + const PlacesItem* item = placesItem(index); + if (item) { + Solid::OpticalDrive* drive = item->device().parent().as<Solid::OpticalDrive>(); + if (drive) { + connect(drive, SIGNAL(ejectDone(Solid::ErrorType,QVariant,QString)), + this, SLOT(slotStorageTeardownDone(Solid::ErrorType,QVariant))); + drive->eject(); + } else { + + } + } +} + +void PlacesItemModel::requestTeardown(int index) +{ + const PlacesItem* item = placesItem(index); + if (item) { + Solid::StorageAccess* access = item->device().as<Solid::StorageAccess>(); + if (access) { + connect(access, SIGNAL(teardownDone(Solid::ErrorType,QVariant,QString)), + this, SLOT(slotStorageTeardownDone(Solid::ErrorType,QVariant))); + access->teardown(); + } else { + const QString label = item->text(); + const QString message = i18nc("@info", "The device '%1' is not a disk and cannot be ejected.", label); + emit errorMessage(message); + } + } } void PlacesItemModel::onItemInserted(int index) @@ -283,12 +338,33 @@ void PlacesItemModel::onItemRemoved(int index) void PlacesItemModel::slotDeviceAdded(const QString& udi) { - Q_UNUSED(udi); + appendItem(new PlacesItem(udi)); } void PlacesItemModel::slotDeviceRemoved(const QString& udi) { - Q_UNUSED(udi); + for (int i = 0; i < m_hiddenItems.count(); ++i) { + PlacesItem* item = m_hiddenItems[i]; + if (item && item->udi() == udi) { + m_hiddenItems.removeAt(i); + delete item; + return; + } + } + + for (int i = 0; i < count(); ++i) { + if (placesItem(i)->udi() == udi) { + removeItem(i); + return; + } + } +} + +void PlacesItemModel::slotStorageTeardownDone(Solid::ErrorType error, const QVariant& errorData) +{ + if (error && errorData.isValid()) { + emit errorMessage(errorData.toString()); + } } void PlacesItemModel::loadBookmarks() |
