summaryrefslogtreecommitdiffstats
path: root/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tdeioslave/media/mediamanager/tdehardwarebackend.cpp')
-rw-r--r--tdeioslave/media/mediamanager/tdehardwarebackend.cpp153
1 files changed, 136 insertions, 17 deletions
diff --git a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
index ae9038a02..a5900c883 100644
--- a/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
+++ b/tdeioslave/media/mediamanager/tdehardwarebackend.cpp
@@ -55,9 +55,9 @@ TDEBackend::TDEBackend(MediaList &list, TQObject* parent)
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
// Connect device monitoring signals/slots
- connect(hwdevices, TQT_SIGNAL(hardwareAdded(TDEGenericDevice*)), this, TQT_SLOT(AddDeviceHandler(TDEGenericDevice*)));
- connect(hwdevices, TQT_SIGNAL(hardwareRemoved(TDEGenericDevice*)), this, TQT_SLOT(RemoveDeviceHandler(TDEGenericDevice*)));
- connect(hwdevices, TQT_SIGNAL(hardwareUpdated(TDEGenericDevice*)), this, TQT_SLOT(ModifyDeviceHandler(TDEGenericDevice*)));
+ connect(hwdevices, TQ_SIGNAL(hardwareAdded(TDEGenericDevice*)), this, TQ_SLOT(AddDeviceHandler(TDEGenericDevice*)));
+ connect(hwdevices, TQ_SIGNAL(hardwareRemoved(TDEGenericDevice*)), this, TQ_SLOT(RemoveDeviceHandler(TDEGenericDevice*)));
+ connect(hwdevices, TQ_SIGNAL(hardwareUpdated(TDEGenericDevice*)), this, TQ_SLOT(ModifyDeviceHandler(TDEGenericDevice*)));
// List devices at startup
ListDevices();
@@ -320,8 +320,7 @@ void TDEBackend::ModifyDevice(TDEStorageDevice * sdevice)
{
kdDebug(1219) << "TDEBackend::ModifyDevice for " << sdevice->uniqueID() << endl;
- bool allowNotification = false;
- ResetProperties(sdevice, allowNotification);
+ ResetProperties(sdevice, false);
}
void TDEBackend::ResetProperties(TDEStorageDevice * sdevice, bool allowNotification, bool overrideIgnoreList)
@@ -485,6 +484,7 @@ void TDEBackend::setVolumeProperties(Medium* medium)
if (useDefaultLabel) {
diskLabel = i18n("%1 Removable Device").arg(sdevice->deviceFriendlySize());
}
+ diskLabel += " (" + sdevice->deviceNode() + ")";
TQString mimeType;
@@ -520,7 +520,7 @@ void TDEBackend::setVolumeProperties(Medium* medium)
// Default
mimeType = "media/cdrom" + MOUNT_MEDIA_SUFFIX;
if (useDefaultLabel) {
- diskLabel = i18n("%1 Removable Device").arg(sdevice->deviceFriendlySize());
+ diskLabel = i18n("%1 Removable Disk (%2)").arg(sdevice->deviceFriendlySize(), sdevice->deviceNode());
}
if (sdevice->isDiskOfType(TDEDiskDeviceType::CDROM)) {
@@ -771,12 +771,11 @@ void TDEBackend::setVolumeProperties(Medium* medium)
diskLabel = i18n("%1 Fixed Disk (%2)").arg(sdevice->deviceFriendlySize(), sdevice->deviceNode());
}
- if (sdevice->isDiskOfType(TDEDiskDeviceType::USB)
- || sdevice->checkDiskStatus(TDEDiskDeviceStatus::Removable)
- || sdevice->checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable)) {
+ if (sdevice->isDiskOfType(TDEDiskDeviceType::USB) ||
+ sdevice->checkDiskStatus(TDEDiskDeviceStatus::Removable)) {
mimeType = "media/removable" + MOUNT_MEDIA_SUFFIX;
if (useDefaultLabel) {
- diskLabel = i18n("%1 Removable Device").arg(sdevice->deviceFriendlySize());
+ diskLabel = i18n("%1 Removable Disk (%2)").arg(sdevice->deviceFriendlySize(), sdevice->deviceNode());
}
}
@@ -883,7 +882,7 @@ bool TDEBackend::setFloppyProperties(Medium* medium)
// Set label
TQString diskLabel = sdevice->diskLabel();
if (diskLabel.isNull()) {
- diskLabel = i18n("%1 Zip Disk").arg(sdevice->deviceFriendlySize());
+ diskLabel = i18n("%1 Zip Disk (%2)").arg(sdevice->deviceFriendlySize(), sdevice->deviceNode());
}
medium->setLabel(diskLabel);
}
@@ -1035,7 +1034,7 @@ TQStringList TDEBackend::mountoptions(const TQString &name)
bool removable = false;
if (!drive_udi.isNull()) {
- removable = ((sdevice->checkDiskStatus(TDEDiskDeviceStatus::Removable)) || (sdevice->checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable)));
+ removable = sdevice->checkDiskStatus(TDEDiskDeviceStatus::Removable);
}
TQString tmp;
@@ -1235,7 +1234,7 @@ TQStringVariantMap TDEBackend::mount(const Medium *medium)
data.medium = medium;
TDEIO::Job *job = TDEIO::mount(false, 0, medium->deviceNode(), mountPoint);
- connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotResult(TDEIO::Job*)));
+ connect(job, TQ_SIGNAL(result(TDEIO::Job*)), TQ_SLOT(slotResult(TDEIO::Job*)));
mount_jobs[job] = &data;
// The caller expects the device to be mounted when the function
// completes. Thus block until the job completes.
@@ -1346,7 +1345,7 @@ TQStringVariantMap TDEBackend::unmount(const TQString &id)
data.medium = medium;
TDEIO::Job *job = TDEIO::unmount( medium->mountPoint(), false );
- connect(job, TQT_SIGNAL(result(TDEIO::Job*)), TQT_SLOT(slotResult(TDEIO::Job*)));
+ connect(job, TQ_SIGNAL(result(TDEIO::Job*)), TQ_SLOT(slotResult(TDEIO::Job*)));
mount_jobs[job] = &data;
// The caller expects the device to be unmounted when the function
// completes. Thus block until the job completes.
@@ -1428,6 +1427,7 @@ TQStringVariantMap TDEBackend::unmount(const TQString &id)
m_mediaList.removeMedium(uid, true);
}
+ ResetProperties(sdevice, false, true);
result["result"] = true;
return result;
}
@@ -1475,14 +1475,14 @@ TQStringVariantMap TDEBackend::unlock(const TQString &id, const TQString &passwo
}
ResetProperties(sdevice, false, true);
- result["result"] = unlockResult["unlockedDevice"];
result["result"] = true;
return result;
}
-TQStringVariantMap TDEBackend::lock(const TQString &id)
+TQStringVariantMap TDEBackend::lock(const TQString &id, bool releaseHolders)
{
- kdDebug(1219) << "TDEBackend::lock for id " << id << endl;
+ kdDebug(1219) << "TDEBackend::lock for id " << id << ", release holders "
+ << releaseHolders << endl;
TQStringVariantMap result;
@@ -1511,6 +1511,12 @@ TQStringVariantMap TDEBackend::lock(const TQString &id)
return result;
}
+ // Release device holders if requested
+ if (releaseHolders)
+ {
+ releaseHolderDevices(medium->deviceNode(), false);
+ }
+
TQStringVariantMap lockResult = sdevice->lockDevice();
if (lockResult["result"].toBool() == false) {
TQString qerror = i18n("<b>Unable to lock the device.</b>");
@@ -1523,10 +1529,123 @@ TQStringVariantMap TDEBackend::lock(const TQString &id)
}
}
+ ResetProperties(sdevice, false, true);
+ result["result"] = true;
+ return result;
+}
+
+TQStringVariantMap TDEBackend::eject(const TQString &id)
+{
+ kdDebug(1219) << "TDEBackend::eject for id " << id << endl;
+
+ TQStringVariantMap result;
+
+ const Medium *medium = m_mediaList.findById(id);
+ if (!medium)
+ {
+ result["errStr"] = i18n("No such medium: %1").arg(id);
+ result["result"] = false;
+ return result;
+ }
+
+ TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
+ TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id());
+ if (!sdevice)
+ {
+ result["errStr"] = i18n("Internal error. Couldn't find medium id %1.").arg(medium->id());
+ result["result"] = false;
+ return result;
+ }
+
+ TQStringVariantMap ejectResult = sdevice->ejectDrive();
+ if (ejectResult["result"].toBool() == false)
+ {
+ TQString qerror = i18n("<b>Unable to eject the device.</b>");
+ TQString errStr = ejectResult.contains("errStr") ? ejectResult["errStr"].toString() : TQString::null;
+ if (!errStr.isEmpty())
+ {
+ qerror.append(i18n("<p>Technical details:<br>").append(errStr));
+ result["errStr"] = qerror;
+ result["result"] = false;
+ return result;
+ }
+ }
+
result["result"] = true;
return result;
}
+TQStringVariantMap TDEBackend::safeRemove(const TQString &id)
+{
+ kdDebug(1219) << "TDEBackend::safeRemove for id " << id << endl;
+
+ TQStringVariantMap result;
+
+ const Medium *medium = m_mediaList.findById(id);
+ if (!medium)
+ {
+ result["errStr"] = i18n("No such medium: %1").arg(id);
+ result["result"] = false;
+ return result;
+ }
+
+ releaseHolderDevices(medium->deviceNode(), true);
+ return eject(id);
+}
+
+void TDEBackend::releaseHolderDevices(const TQString &deviceNode, bool handleThis)
+{
+ kdDebug(1219) << "TDEBackend::releaseHolderDevices for node " << deviceNode
+ << ", handle this " << (handleThis ? "yes" : "no") << endl;
+
+ const Medium *medium = m_mediaList.findByNode(deviceNode);
+ if (!medium)
+ {
+ return;
+ }
+
+ // Scan the holding devices and unmount/lock them if possible
+ TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
+ TDEStorageDevice *sdevice = hwdevices->findDiskByUID(medium->id());
+ if (sdevice)
+ {
+ TQStringList holdingDeviceList = sdevice->holdingDevices();
+ for (TQStringList::Iterator holdingDevIt = holdingDeviceList.begin(); holdingDevIt != holdingDeviceList.end(); ++holdingDevIt)
+ {
+ TDEGenericDevice *hwHolderDevice = hwdevices->findBySystemPath(*holdingDevIt);
+ if (hwHolderDevice->type() == TDEGenericDeviceType::Disk)
+ {
+ TDEStorageDevice *holderSDevice = static_cast<TDEStorageDevice*>(hwHolderDevice);
+ const Medium *holderMedium = m_mediaList.findByNode(holderSDevice->deviceNode());
+ if (holderMedium && !holderMedium->id().isEmpty())
+ {
+ releaseHolderDevices(holderMedium->deviceNode(), true);
+ }
+ }
+ }
+ }
+
+ if (handleThis)
+ {
+ // Unmount if necessary
+ if (medium->isMountable() && medium->isMounted())
+ {
+ unmount(medium->id());
+ // Must process udev events before continuing, to make sure all
+ // affected devices are properly updated
+ tqApp->processEvents();
+ }
+ // Lock if necessary.
+ if (medium->isEncrypted() && !medium->isLocked())
+ {
+ lock(medium->id(), false);
+ // Must process udev events before continuing, to make sure all
+ // affected devices are properly updated
+ tqApp->processEvents();
+ }
+ }
+}
+
void TDEBackend::slotResult(TDEIO::Job *job)
{
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();