hwmanager: use tdeio_media_mounthelper process to

mount/unmout/lock/unlock/ejct media devices.
This ensures a consistent media device status also with complex
partition structures and LUKS encryption.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/263/head
Michele Calgaro 2 years ago
parent 40ef766f02
commit 88d92af3c1
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -29,6 +29,7 @@
#include <tqpainter.h> #include <tqpainter.h>
#include <tqstyle.h> #include <tqstyle.h>
#include <tqinternal_p.h> #include <tqinternal_p.h>
#include <kprocess.h>
#include <dcopclient.h> #include <dcopclient.h>
#include <dcopref.h> #include <dcopref.h>
#undef Unsorted // Required for --enable-final (tqdir.h) #undef Unsorted // Required for --enable-final (tqdir.h)
@ -253,7 +254,7 @@ void SensorDisplayWidget::updateDisplay() {
} }
DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidget *parent) 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; m_device = device;
enableButtonOK( false ); enableButtonOK( false );
@ -350,10 +351,6 @@ DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidge
DevicePropertiesDialog::~DevicePropertiesDialog() DevicePropertiesDialog::~DevicePropertiesDialog()
{ {
if (m_passDlg)
{
delete m_passDlg;
}
} }
void DevicePropertiesDialog::processHardwareRemoved(TDEGenericDevice* dev) { void DevicePropertiesDialog::processHardwareRemoved(TDEGenericDevice* dev) {
@ -909,99 +906,49 @@ void DevicePropertiesDialog::setHibernationMethod(int value) {
void DevicePropertiesDialog::mountDisk() { void DevicePropertiesDialog::mountDisk() {
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device);
// Use DCOP call instead of a tdehw call for consistent behavior across TDE TDEProcess proc;
DCOPRef mediamanager("kded", "mediamanager"); proc << "tdeio_media_mounthelper" << "-m" << sdevice->deviceNode();
DCOPReply reply = mediamanager.call("mountByNode", sdevice->deviceNode()); if (!proc.start(TDEProcess::DontCare))
TQStringVariantMap mountResult; {
if (reply.isValid()) { KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."),
reply.get(mountResult); i18n("Device monitor"));
}
if (!mountResult.contains("result") || mountResult["result"].toBool() == false) {
// Mount failed!
TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : i18n("Unable to mount the device.");
KMessageBox::error(this, "<qt>" + errStr + "</qt>", i18n("Mount failed"));
} }
populateDeviceInformation();
} }
void DevicePropertiesDialog::unmountDisk() { void DevicePropertiesDialog::unmountDisk() {
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device);
// Use DCOP call instead of a tdehw call for consistent behavior across TDE TDEProcess proc;
DCOPRef mediamanager("kded", "mediamanager"); proc << "tdeio_media_mounthelper" << "-u" << sdevice->deviceNode();
DCOPReply reply = mediamanager.call("unmountByNode", sdevice->deviceNode()); if (!proc.start(TDEProcess::DontCare))
TQStringVariantMap unmountResult;
if (reply.isValid()) {
reply.get(unmountResult);
}
if (!unmountResult.contains("result") || unmountResult["result"].toBool() == false) {
// Unmount failed!
TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : i18n("Unable to unmount the device.");
KMessageBox::error(this, "<qt>" + errStr + "</qt>", i18n("Unmount failed"));
}
populateDeviceInformation();
}
void DevicePropertiesDialog::unlockDisk() {
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device);
if (!m_passDlg)
{ {
m_passDlg = new PasswordDlg(); KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."),
connect(m_passDlg, TQT_SIGNAL(user1Clicked()), this, TQT_SLOT(doUnlockDisk())); i18n("Device monitor"));
} }
m_passDlg->setDevice(sdevice->deviceNode());
m_passDlg->clearPassword();
m_passDlg->show();
} }
void DevicePropertiesDialog::doUnlockDisk() { void DevicePropertiesDialog::unlockDisk() {
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device);
// Use DCOP call instead of a tdehw call for consistent behavior across TDE TDEProcess proc;
DCOPRef mediamanager("kded", "mediamanager"); proc << "tdeio_media_mounthelper" << "-k" << sdevice->deviceNode();
DCOPReply reply = mediamanager.call("unlockByNode", sdevice->deviceNode(), m_passDlg->getPassword()); if (!proc.start(TDEProcess::DontCare))
TQStringVariantMap unlockResult;
if (reply.isValid()) {
reply.get(unlockResult);
}
if (!unlockResult.contains("result") || !unlockResult["result"].toBool())
{ {
TQString errStr = unlockResult.contains("errStr") ? unlockResult["errStr"].toString() : TQString::null; KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."),
if (errStr.isEmpty()) i18n("Device monitor"));
{
errStr = i18n("<qt>Unable to unlock the 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();
}
else {
m_passDlg->hide();
} }
populateDeviceInformation();
} }
void DevicePropertiesDialog::lockDisk() { void DevicePropertiesDialog::lockDisk() {
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device);
// Use DCOP call instead of a tdehw call for consistent behavior across TDE TDEProcess proc;
DCOPRef mediamanager("kded", "mediamanager"); proc << "tdeio_media_mounthelper" << "-l" << sdevice->deviceNode();
DCOPReply reply = mediamanager.call("lockByNode", sdevice->deviceNode(), true); if (!proc.start(TDEProcess::DontCare))
TQStringVariantMap lockResult; {
if (reply.isValid()) { KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."),
reply.get(lockResult); i18n("Device monitor"));
}
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"));
} }
populateDeviceInformation();
} }
void DevicePropertiesDialog::cryptLUKSAddKey() { void DevicePropertiesDialog::cryptLUKSAddKey() {

@ -191,7 +191,6 @@ private slots:
void mountDisk(); void mountDisk();
void unmountDisk(); void unmountDisk();
void unlockDisk(); void unlockDisk();
void doUnlockDisk();
void lockDisk(); void lockDisk();
void cryptLUKSAddKey(); void cryptLUKSAddKey();
@ -207,7 +206,6 @@ private slots:
private: private:
TDEGenericDevice* m_device; TDEGenericDevice* m_device;
DevicePropertiesDialogBase* base; DevicePropertiesDialogBase* base;
PasswordDlg *m_passDlg;
TQGridLayout* m_sensorDataGrid; TQGridLayout* m_sensorDataGrid;
SensorDisplayWidgetList m_sensorDataGridWidgets; SensorDisplayWidgetList m_sensorDataGridWidgets;

@ -33,6 +33,7 @@
#include <kdebug.h> #include <kdebug.h>
#include <khelpmenu.h> #include <khelpmenu.h>
#include <kiconloader.h> #include <kiconloader.h>
#include "kprocess.h"
#include <tdelocale.h> #include <tdelocale.h>
#include <tdepopupmenu.h> #include <tdepopupmenu.h>
#include <kstdaction.h> #include <kstdaction.h>
@ -54,7 +55,7 @@
#include "hwdevicetray.h" #include "hwdevicetray.h"
HwDeviceSystemTray::HwDeviceSystemTray(TQWidget* parent, const char *name) HwDeviceSystemTray::HwDeviceSystemTray(TQWidget* parent, const char *name)
: KSystemTray(parent, name), m_passDlg(NULL) : KSystemTray(parent, name)
{ {
// Create notifier // Create notifier
m_hardwareNotifierContainer = new TDEPassivePopupStackContainer(); m_hardwareNotifierContainer = new TDEPassivePopupStackContainer();
@ -99,10 +100,6 @@ HwDeviceSystemTray::HwDeviceSystemTray(TQWidget* parent, const char *name)
HwDeviceSystemTray::~HwDeviceSystemTray() HwDeviceSystemTray::~HwDeviceSystemTray()
{ {
delete m_hardwareNotifierContainer; delete m_hardwareNotifierContainer;
if (m_passDlg)
{
delete m_passDlg;
}
} }
/*! /*!
@ -440,21 +437,13 @@ void HwDeviceSystemTray::slotMountDevice(int parameter)
{ {
if (sdevice->mountPath().isEmpty()) if (sdevice->mountPath().isEmpty())
{ {
// Use DCOP call instead of a tdehw call for consistent behavior across TDE TDEProcess proc;
DCOPRef mediamanager("kded", "mediamanager"); proc << "tdeio_media_mounthelper" << "-m" << sdevice->deviceNode();
DCOPReply reply = mediamanager.call("mountByNode", sdevice->deviceNode()); if (!proc.start(TDEProcess::DontCare))
TQStringVariantMap mountResult;
if (reply.isValid())
{
reply.get(mountResult);
}
if (!mountResult.contains("result") || mountResult["result"].toBool() == false)
{ {
// Mount failed! KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."),
TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : i18n("Unable to mount the device."); i18n("Device monitor"));
KMessageBox::error(0, "<qt>" + errStr + "</qt>", i18n("Mount failed"));
} }
return;
} }
} }
} }
@ -475,21 +464,13 @@ void HwDeviceSystemTray::slotUnmountDevice(int parameter)
{ {
if (!sdevice->mountPath().isEmpty()) if (!sdevice->mountPath().isEmpty())
{ {
// Use DCOP call instead of a tdehw call for consistent behavior across TDE TDEProcess proc;
DCOPRef mediamanager("kded", "mediamanager"); proc << "tdeio_media_mounthelper" << "-u" << sdevice->deviceNode();
DCOPReply reply = mediamanager.call("unmountByNode", sdevice->deviceNode()); if (!proc.start(TDEProcess::DontCare))
TQStringVariantMap unmountResult;
if (reply.isValid())
{ {
reply.get(unmountResult); KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."),
i18n("Device monitor"));
} }
if (!unmountResult.contains("result") || unmountResult["result"].toBool() == false)
{
// Unmount failed!
TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : i18n("Unable to unmount the device.");
KMessageBox::error(0, "<qt>" + errStr + "</qt>", i18n("Unmount failed"));
}
return;
} }
} }
} }
@ -508,57 +489,13 @@ void HwDeviceSystemTray::slotUnlockDevice(int parameter)
TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice); TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid)) if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid))
{ {
if (!m_passDlg) TDEProcess proc;
proc << "tdeio_media_mounthelper" << "-k" << sdevice->deviceNode();
if (!proc.start(TDEProcess::DontCare))
{ {
m_passDlg = new PasswordDlg(); KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."),
connect(m_passDlg, TQT_SIGNAL(user1Clicked()), this, TQT_SLOT(doUnlockDisk())); i18n("Device monitor"));
} }
m_passDlg->setDevice(sdevice->deviceNode());
m_passDlg->index = parameter;
m_passDlg->clearPassword();
m_passDlg->show();
return;
}
}
}
}
void HwDeviceSystemTray::doUnlockDisk()
{
TQString uuid = m_unlockMenuIndexMap[m_passDlg->index];
if (!uuid.isEmpty())
{
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk);
for (TDEGenericDevice *hwdevice = diskDeviceList.first(); hwdevice; hwdevice = diskDeviceList.next())
{
TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid))
{
// Use DCOP call instead of a tdehw call for consistent behavior across 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())
{
TQString errStr = unlockResult.contains("errStr") ? unlockResult["errStr"].toString() : TQString::null;
if (errStr.isEmpty())
{
errStr = i18n("<qt>Unable to unlock the device.<p>Potential reasons include:<br>Wrong password "
"and/or user privilege level.<br>Corrupt data on storage device.</qt>");
}
KMessageBox::error(0, errStr, i18n("Unlock failed"));
m_passDlg->clearPassword();
}
else
{
m_passDlg->hide();
}
return;
} }
} }
} }
@ -576,22 +513,14 @@ void HwDeviceSystemTray::slotLockDevice(int parameter)
TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice); TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid)) if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid))
{ {
// Use DCOP call instead of a tdehw call for consistent behavior across TDE TDEProcess proc;
DCOPRef mediamanager("kded", "mediamanager"); proc << "tdeio_media_mounthelper" << "-l" << sdevice->deviceNode();
DCOPReply reply = mediamanager.call("lockByNode", sdevice->deviceNode(), true); if (!proc.start(TDEProcess::DontCare))
TQStringVariantMap lockResult;
if (reply.isValid())
{
reply.get(lockResult);
}
if (!lockResult.contains("result") || lockResult["result"].toBool() == false)
{ {
// Lock failed! KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."),
TQString errStr = lockResult.contains("errStr") ? lockResult["errStr"].toString() : i18n("Unable to lock the device."); i18n("Device monitor"));
KMessageBox::error(0, "<qt>" + errStr + "</qt>", i18n("Lock failed"));
} }
return; }
}
} }
} }
} }
@ -608,21 +537,13 @@ void HwDeviceSystemTray::slotEjectDevice(int parameter)
TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice); TDEStorageDevice *sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid)) if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid))
{ {
// Use DCOP call instead of a tdehw call for consistent behavior across TDE TDEProcess proc;
DCOPRef mediamanager("kded", "mediamanager"); proc << "tdeio_media_mounthelper" << "-e" << sdevice->deviceNode();
DCOPReply reply = mediamanager.call("ejectByNode", sdevice->deviceNode()); if (!proc.start(TDEProcess::DontCare))
TQStringVariantMap ejectResult;
if (reply.isValid())
{ {
reply.get(ejectResult); KMessageBox::error(this, i18n("Could not start tdeio_media_mounthelper process."),
i18n("Device monitor"));
} }
if (!ejectResult.contains("result") || ejectResult["result"].toBool() == false)
{
// Eject failed!
TQString errStr = ejectResult.contains("errStr") ? ejectResult["errStr"].toString() : i18n("Unable to eject the device.");
KMessageBox::error(0, "<qt>" + errStr + "</qt>", i18n("Eject failed"));
}
return;
} }
} }
} }

@ -74,7 +74,6 @@ private slots:
void deviceRemoved(TDEGenericDevice*); void deviceRemoved(TDEGenericDevice*);
void deviceChanged(TDEGenericDevice*); void deviceChanged(TDEGenericDevice*);
void devicePopupClicked(KPassivePopup*, TQPoint, TQString); void devicePopupClicked(KPassivePopup*, TQPoint, TQString);
void doUnlockDisk();
void doDiskNotifications(bool scanOnly); void doDiskNotifications(bool scanOnly);
private: private:
@ -99,7 +98,6 @@ private:
TQStringMap m_propertiesMenuIndexMap; TQStringMap m_propertiesMenuIndexMap;
TDEPopupMenu* m_menu; TDEPopupMenu* m_menu;
KSimpleConfig *r_config; KSimpleConfig *r_config;
PasswordDlg *m_passDlg;
struct KnownDiskDeviceInfo struct KnownDiskDeviceInfo
{ {

@ -1427,6 +1427,7 @@ TQStringVariantMap TDEBackend::unmount(const TQString &id)
m_mediaList.removeMedium(uid, true); m_mediaList.removeMedium(uid, true);
} }
ResetProperties(sdevice, false, true);
result["result"] = true; result["result"] = true;
return result; return result;
} }
@ -1528,6 +1529,7 @@ TQStringVariantMap TDEBackend::lock(const TQString &id, bool releaseHolders)
} }
} }
ResetProperties(sdevice, false, true);
result["result"] = true; result["result"] = true;
return result; return result;
} }

Loading…
Cancel
Save