diff options
Diffstat (limited to 'kcontrol/hwmanager/devicepropsdlg.cpp')
-rw-r--r-- | kcontrol/hwmanager/devicepropsdlg.cpp | 238 |
1 files changed, 131 insertions, 107 deletions
diff --git a/kcontrol/hwmanager/devicepropsdlg.cpp b/kcontrol/hwmanager/devicepropsdlg.cpp index ffb19da1a..4baabe29a 100644 --- a/kcontrol/hwmanager/devicepropsdlg.cpp +++ b/kcontrol/hwmanager/devicepropsdlg.cpp @@ -29,6 +29,7 @@ #include <tqpainter.h> #include <tqstyle.h> #include <tqinternal_p.h> +#include <kprocess.h> #include <dcopclient.h> #include <dcopref.h> #undef Unsorted // Required for --enable-final (tqdir.h) @@ -253,7 +254,7 @@ void SensorDisplayWidget::updateDisplay() { } DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidget *parent) - : KDialogBase(Plain, TQString::null, Ok|Cancel, Ok, parent, 0L, true, true), m_passDlg(NULL) + : KDialogBase(Plain, TQString::null, Ok|Cancel, Ok, parent, 0L, true, true) { m_device = device; enableButtonOK( false ); @@ -298,18 +299,20 @@ DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidge } if (m_device->type() == TDEGenericDeviceType::CPU) { - connect(base->comboCPUGovernor, TQT_SIGNAL(activated(const TQString &)), this, TQT_SLOT(setCPUGovernor(const TQString &))); + connect(base->comboCPUGovernor, TQ_SIGNAL(activated(const TQString &)), this, TQ_SLOT(setCPUGovernor(const TQString &))); } if (m_device->type() == TDEGenericDeviceType::Disk) { TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); - connect(base->buttonDiskMount, TQT_SIGNAL(clicked()), this, TQT_SLOT(mountDisk())); - connect(base->buttonDiskUnmount, TQT_SIGNAL(clicked()), this, TQT_SLOT(unmountDisk())); - connect(base->buttonDiskUnlock, TQT_SIGNAL(clicked()), this, TQT_SLOT(unlockDisk())); - connect(base->buttonDiskLock, TQT_SIGNAL(clicked()), this, TQT_SLOT(lockDisk())); + connect(base->buttonDiskMount, TQ_SIGNAL(clicked()), this, TQ_SLOT(mountDisk())); + connect(base->buttonDiskUnmount, TQ_SIGNAL(clicked()), this, TQ_SLOT(unmountDisk())); + connect(base->buttonDiskUnlock, TQ_SIGNAL(clicked()), this, TQ_SLOT(unlockDisk())); + connect(base->buttonDiskLock, TQ_SIGNAL(clicked()), this, TQ_SLOT(lockDisk())); + connect(base->buttonDiskEject, TQ_SIGNAL(clicked()), this, TQ_SLOT(ejectDisk())); + connect(base->buttonDiskSafeRemove, TQ_SIGNAL(clicked()), this, TQ_SLOT(safeRemoveDisk())); if (sdevice->isDiskOfType(TDEDiskDeviceType::LUKS)) { - connect(base->cryptLUKSAddKey, TQT_SIGNAL(clicked()), this, TQT_SLOT(cryptLUKSAddKey())); - connect(base->cryptLUKSDelKey, TQT_SIGNAL(clicked()), this, TQT_SLOT(cryptLUKSDelKey())); - connect(base->cryptLUKSKeySlotList, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(processLockouts())); + connect(base->cryptLUKSAddKey, TQ_SIGNAL(clicked()), this, TQ_SLOT(cryptLUKSAddKey())); + connect(base->cryptLUKSDelKey, TQ_SIGNAL(clicked()), this, TQ_SLOT(cryptLUKSDelKey())); + connect(base->cryptLUKSKeySlotList, TQ_SIGNAL(selectionChanged()), this, TQ_SLOT(processLockouts())); base->cryptLUKSKeySlotList->setAllColumnsShowFocus(true); base->cryptLUKSKeySlotList->setFullWidth(true); cryptLUKSPopulateList(); @@ -329,10 +332,10 @@ DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidge m_sensorDataGridWidgets.setAutoDelete(true); } if (m_device->type() == TDEGenericDeviceType::Backlight) { - connect(base->sliderBacklightBrightness, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(setBacklightBrightness(int))); + connect(base->sliderBacklightBrightness, TQ_SIGNAL(valueChanged(int)), this, TQ_SLOT(setBacklightBrightness(int))); } if (m_device->type() == TDEGenericDeviceType::RootSystem) { - connect(base->comboSystemHibernationMethod, TQT_SIGNAL(activated(int)), this, TQT_SLOT(setHibernationMethod(int))); + connect(base->comboSystemHibernationMethod, TQ_SIGNAL(activated(int)), this, TQ_SLOT(setHibernationMethod(int))); } TQGridLayout *mainGrid = new TQGridLayout(plainPage(), 1, 1, 0, spacingHint()); @@ -342,18 +345,14 @@ DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidge TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); - connect(hwdevices, TQT_SIGNAL(hardwareRemoved(TDEGenericDevice*)), this, TQT_SLOT(processHardwareRemoved(TDEGenericDevice*))); - connect(hwdevices, TQT_SIGNAL(hardwareUpdated(TDEGenericDevice*)), this, TQT_SLOT(processHardwareUpdated(TDEGenericDevice*))); + connect(hwdevices, TQ_SIGNAL(hardwareRemoved(TDEGenericDevice*)), this, TQ_SLOT(processHardwareRemoved(TDEGenericDevice*))); + connect(hwdevices, TQ_SIGNAL(hardwareUpdated(TDEGenericDevice*)), this, TQ_SLOT(processHardwareUpdated(TDEGenericDevice*))); populateDeviceInformation(); } DevicePropertiesDialog::~DevicePropertiesDialog() { - if (m_passDlg) - { - delete m_passDlg; - } } void DevicePropertiesDialog::processHardwareRemoved(TDEGenericDevice* dev) { @@ -376,7 +375,49 @@ static TQString formatDisplayString(TQString input) { return TQStyleSheet::escape(input); } -void DevicePropertiesDialog::populateDeviceInformation() { +bool DevicePropertiesDialog::isMonitoredDevice(TDEStorageDevice *sdevice) +{ + // Type selection logic largely duplicated from the media manager tdeioslave + return ((sdevice->isDiskOfType(TDEDiskDeviceType::LUKS) || + sdevice->checkDiskStatus(TDEDiskDeviceStatus::ContainsFilesystem) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDAudio) || + sdevice->checkDiskStatus(TDEDiskDeviceStatus::Blank)) && + !sdevice->checkDiskStatus(TDEDiskDeviceStatus::Hidden) && + (sdevice->isDiskOfType(TDEDiskDeviceType::HDD) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDROM) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDR) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDMO) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDMRRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDMRRWW) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDROM) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDRAM) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDR) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDRDL) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDRWDL) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSR) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRDL) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRWDL) || + sdevice->isDiskOfType(TDEDiskDeviceType::BDROM) || + sdevice->isDiskOfType(TDEDiskDeviceType::BDR) || + sdevice->isDiskOfType(TDEDiskDeviceType::BDRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDROM) || + sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDR) || + sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDRW) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDAudio) || + sdevice->isDiskOfType(TDEDiskDeviceType::CDVideo) || + sdevice->isDiskOfType(TDEDiskDeviceType::DVDVideo) || + sdevice->isDiskOfType(TDEDiskDeviceType::BDVideo) || + sdevice->isDiskOfType(TDEDiskDeviceType::Floppy) || + sdevice->isDiskOfType(TDEDiskDeviceType::Zip) || + sdevice->isDiskOfType(TDEDiskDeviceType::Jaz) || + sdevice->isDiskOfType(TDEDiskDeviceType::Camera))); +} + +void DevicePropertiesDialog::populateDeviceInformation() +{ if (m_device) { base->labelDeviceType->setText(m_device->friendlyDeviceType()); base->iconDeviceType->setPixmap(m_device->icon(TDEIcon::SizeSmall)); @@ -452,9 +493,6 @@ void DevicePropertiesDialog::populateDeviceInformation() { if (sdevice->checkDiskStatus(TDEDiskDeviceStatus::ContainsFilesystem)) { status_text += i18n("Contains a filesystem") + "<br>"; } - if (sdevice->checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable)) { - status_text += i18n("Hotpluggable") + "<br>"; - } if (sdevice->checkDiskStatus(TDEDiskDeviceStatus::Hidden)) { status_text += i18n("Hidden") + "<br>"; } @@ -464,29 +502,52 @@ void DevicePropertiesDialog::populateDeviceInformation() { status_text += "</qt>"; base->labelDiskStatus->setText(status_text); - // Update mount/unmount button status + // Update action button status base->buttonDiskMount->setEnabled(false); base->buttonDiskUnmount->setEnabled(false); base->buttonDiskUnlock->setEnabled(false); base->buttonDiskLock->setEnabled(false); + base->buttonDiskEject->setEnabled(false); + base->buttonDiskSafeRemove->setEnabled(false); base->buttonDiskMount->setHidden(true); base->buttonDiskUnmount->setHidden(true); base->buttonDiskUnlock->setHidden(true); base->buttonDiskLock->setHidden(true); - if (sdevice->checkDiskStatus(TDEDiskDeviceStatus::Mountable)) { - base->groupDiskActions->show(); + base->buttonDiskEject->setHidden(true); + base->buttonDiskSafeRemove->setHidden(true); + bool showGroup = false; + if (sdevice->checkDiskStatus(TDEDiskDeviceStatus::Mountable)) + { base->buttonDiskMount->setEnabled((sdevice->mountPath() == "")); base->buttonDiskUnmount->setEnabled((sdevice->mountPath() != "")); base->buttonDiskMount->setHidden(false); base->buttonDiskUnmount->setHidden(false); + showGroup = true; } - else if (sdevice->isDiskOfType(TDEDiskDeviceType::LUKS)) { + else if (sdevice->isDiskOfType(TDEDiskDeviceType::LUKS) || + sdevice->isDiskOfType(TDEDiskDeviceType::OtherCrypted)) + { base->buttonDiskUnlock->setEnabled(!sdevice->isDiskOfType(TDEDiskDeviceType::UnlockedCrypt)); base->buttonDiskLock->setEnabled(sdevice->isDiskOfType(TDEDiskDeviceType::UnlockedCrypt)); base->buttonDiskUnlock->setHidden(false); base->buttonDiskLock->setHidden(false); + showGroup = true; } - else { + if (isMonitoredDevice(sdevice) && + sdevice->checkDiskStatus(TDEDiskDeviceStatus::Removable)) + { + base->buttonDiskEject->setEnabled(true); + base->buttonDiskSafeRemove->setEnabled(true); + base->buttonDiskEject->setHidden(false); + base->buttonDiskSafeRemove->setHidden(false); + showGroup = true; + } + if (showGroup) + { + base->groupDiskActions->show(); + } + else + { base->groupDiskActions->hide(); } } @@ -820,8 +881,8 @@ void DevicePropertiesDialog::populateDeviceInformation() { if (m_device->type() == TDEGenericDeviceType::CryptographicCard) { TDECryptographicCardDevice* cdevice = static_cast<TDECryptographicCardDevice*>(m_device); - connect(cdevice, TQT_SIGNAL(cardInserted(TDECryptographicCardDevice*)), this, TQT_SLOT(cryptographicCardInserted())); - connect(cdevice, TQT_SIGNAL(cardRemoved(TDECryptographicCardDevice*)), this, TQT_SLOT(cryptographicCardRemoved())); + connect(cdevice, TQ_SIGNAL(cardInserted(TDECryptographicCardDevice*)), this, TQ_SLOT(cryptographicCardInserted())); + connect(cdevice, TQ_SIGNAL(cardRemoved(TDECryptographicCardDevice*)), this, TQ_SLOT(cryptographicCardRemoved())); updateCryptographicCardStatusDisplay(); } @@ -908,111 +969,74 @@ void DevicePropertiesDialog::setHibernationMethod(int value) { void DevicePropertiesDialog::mountDisk() { TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); - TQString qerror; - TQString diskLabel = sdevice->diskLabel(); - if (diskLabel.isNull()) { - diskLabel = i18n("%1 Removable Device").arg(sdevice->deviceFriendlySize()); - } - TDEStorageMountOptions mountOptions; - TQStringVariantMap mountResult = sdevice->mountDevice(diskLabel, mountOptions); - TQString mountedPath = mountResult.contains("mountPath") ? mountResult["mountPath"].toString() : TQString::null; - if (mountedPath.isEmpty()) { - qerror = i18n("<qt>Unable to mount this device.<p>Potential reasons include:<br>Improper device and/or user privilege level<br>Corrupt data on storage device"); - TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : TQString::null; - if (!errStr.isEmpty()) { - qerror.append(i18n("<p>Technical details:<br>").append(errStr)); - } - qerror.append("</qt>"); - } - else { - qerror = ""; - } - - if (qerror != "") KMessageBox::error(this, qerror, i18n("Mount Failed")); - populateDeviceInformation(); + TDEProcess proc; + proc << "tdeio_media_mounthelper" << "-m" << sdevice->deviceNode(); + if (!proc.start(TDEProcess::DontCare)) + { + KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."), + i18n("Device monitor")); + } } void DevicePropertiesDialog::unmountDisk() { TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); - TQString qerror; - TQStringVariantMap unmountResult = sdevice->unmountDevice(); - if (unmountResult["result"].toBool() == false) { - // Unmount failed! - qerror = "<qt>" + i18n("<b>The device could not be unmounted.</b>"); - TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null; - if (!errStr.isEmpty()) { - qerror.append(i18n("<p>Technical details:<br>").append(errStr)); - } - qerror.append("</qt>"); + TDEProcess proc; + proc << "tdeio_media_mounthelper" << "-u" << sdevice->deviceNode(); + if (!proc.start(TDEProcess::DontCare)) + { + KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."), + i18n("Device monitor")); } - - if (qerror != "") KMessageBox::error(this, qerror, i18n("Unmount Failed")); - - populateDeviceInformation(); } void DevicePropertiesDialog::unlockDisk() { TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); - if (!m_passDlg) + TDEProcess proc; + proc << "tdeio_media_mounthelper" << "-k" << sdevice->deviceNode(); + if (!proc.start(TDEProcess::DontCare)) { - m_passDlg = new PasswordDlg(); - connect(m_passDlg, TQT_SIGNAL(user1Clicked()), this, TQT_SLOT(doUnlockDisk())); + KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."), + i18n("Device monitor")); } - m_passDlg->setDevice(sdevice->deviceNode()); - m_passDlg->clearPassword(); - m_passDlg->show(); } -void DevicePropertiesDialog::doUnlockDisk() { +void DevicePropertiesDialog::lockDisk() { TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); - // Use DCOP call to unlock the disk to make sure the status and mime type of the underlying medium - // is correctly updated throughout TDE - DCOPRef mediamanager("kded", "mediamanager"); - DCOPReply reply = mediamanager.call("unlockByNode", sdevice->deviceNode(), m_passDlg->getPassword()); - TQStringVariantMap unlockResult; - if (reply.isValid()) { - reply.get(unlockResult); - } - if (!unlockResult.contains("result") || !unlockResult["result"].toBool()) + TDEProcess proc; + proc << "tdeio_media_mounthelper" << "-l" << sdevice->deviceNode(); + if (!proc.start(TDEProcess::DontCare)) { - TQString errStr = unlockResult.contains("errStr") ? unlockResult["errStr"].toString() : TQString::null; - if (errStr.isEmpty()) - { - errStr = i18n("<qt>Unable to unlock this device.<p>Potential reasons include:<br>Wrong password " - "and/or user privilege level.<br>Corrupt data on storage device.</qt>"); - } - KMessageBox::error(this, errStr, i18n("Unlock Failed")); - m_passDlg->clearPassword(); + KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."), + i18n("Device monitor")); } - else { - m_passDlg->hide(); - } - - populateDeviceInformation(); } -void DevicePropertiesDialog::lockDisk() { +void DevicePropertiesDialog::ejectDisk() { TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); - // Use DCOP call to lock the disk to make sure the status and mime type of the underlying medium - // is correctly updated throughout TDE - DCOPRef mediamanager("kded", "mediamanager"); - DCOPReply reply = mediamanager.call("lockByNode", sdevice->deviceNode()); - TQStringVariantMap lockResult; - if (reply.isValid()) { - reply.get(lockResult); - } - if (!lockResult.contains("result") || lockResult["result"].toBool() == false) { - // Lock failed! - TQString errStr = lockResult.contains("errStr") ? lockResult["errStr"].toString() : i18n("Unable to lock the device."); - KMessageBox::error(this, "<qt>" + errStr + "</qt>", i18n("Lock Failed")); + TDEProcess proc; + proc << "tdeio_media_mounthelper" << "-e" << sdevice->deviceNode(); + if (!proc.start(TDEProcess::DontCare)) + { + KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."), + i18n("Device monitor")); } +} - populateDeviceInformation(); +void DevicePropertiesDialog::safeRemoveDisk() { + TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); + + TDEProcess proc; + proc << "tdeio_media_mounthelper" << "-s" << sdevice->deviceNode(); + if (!proc.start(TDEProcess::DontCare)) + { + KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."), + i18n("Device monitor")); + } } void DevicePropertiesDialog::cryptLUKSAddKey() { |