1) tdehwdevicetray: added support for unmount/unlock/lock operations.

2) minor changes and improvements to user messages.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/159/head
Michele Calgaro 3 years ago
parent 1b6c123de1
commit d39c407bf4
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -58,7 +58,7 @@ tde_add_kpart( kcm_hwmanager AUTOMOC
tde_add_executable( tdehwdevicetray AUTOMOC tde_add_executable( tdehwdevicetray AUTOMOC
SOURCES SOURCES
hwdevicetray_main.cpp hwdevicetray.cpp hwdevicetray_app.cpp hwdevicetray_main.cpp hwdevicetray.cpp hwdevicetray_app.cpp
hwdevicetray_configdialog.cpp hwdevicetray_configdialog.cpp unlockdialog.ui passworddlg.cpp
LINK tdeio-shared tdeutils-shared tdeui-shared LINK tdeio-shared tdeutils-shared tdeui-shared
DESTINATION ${BIN_INSTALL_DIR} DESTINATION ${BIN_INSTALL_DIR}
) )

@ -940,7 +940,7 @@ void DevicePropertiesDialog::unmountDisk() {
TQStringVariantMap unmountResult = sdevice->unmountDevice(); TQStringVariantMap unmountResult = sdevice->unmountDevice();
if (unmountResult["result"].toBool() == false) { if (unmountResult["result"].toBool() == false) {
// Unmount failed! // Unmount failed!
qerror = "<qt>" + i18n("Unfortunately, the device could not be unmounted."); qerror = "<qt>" + i18n("<b>The device could not be unmounted.</b>");
TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null; TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null;
if (!errStr.isEmpty()) { if (!errStr.isEmpty()) {
qerror.append(i18n("<p>Technical details:<br>").append(errStr)); qerror.append(i18n("<p>Technical details:<br>").append(errStr));
@ -958,9 +958,11 @@ void DevicePropertiesDialog::unlockDisk() {
if (!m_passDlg) if (!m_passDlg)
{ {
m_passDlg = new PasswordDlg(sdevice->deviceNode(), "drive-harddisk-locked"); m_passDlg = new PasswordDlg();
connect(m_passDlg, TQT_SIGNAL(user1Clicked()), this, TQT_SLOT(doUnlockDisk())); connect(m_passDlg, TQT_SIGNAL(user1Clicked()), this, TQT_SLOT(doUnlockDisk()));
} }
m_passDlg->setDevice(sdevice->deviceNode());
m_passDlg->clearPassword();
m_passDlg->show(); m_passDlg->show();
} }
@ -969,28 +971,27 @@ void DevicePropertiesDialog::doUnlockDisk() {
// Use DCOP call to unlock the disk to make sure the status and mime type of the underlying medium // Use DCOP call to unlock the disk to make sure the status and mime type of the underlying medium
// is correctly updated throughout TDE // is correctly updated throughout TDE
TQString qerror;
DCOPRef mediamanager("kded", "mediamanager"); DCOPRef mediamanager("kded", "mediamanager");
DCOPReply reply = mediamanager.call("unlockByNode", sdevice->deviceNode(), m_passDlg->getPassword()); DCOPReply reply = mediamanager.call("unlockByNode", sdevice->deviceNode(), m_passDlg->getPassword());
TQStringVariantMap unlockResult; TQStringVariantMap unlockResult;
if (reply.isValid()) { if (reply.isValid()) {
reply.get(unlockResult); reply.get(unlockResult);
} }
if (!unlockResult.contains("result") || !unlockResult["result"].toBool()) { if (!unlockResult.contains("result") || !unlockResult["result"].toBool())
qerror = 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."); {
TQString errStr = unlockResult.contains("errStr") ? unlockResult["errStr"].toString() : i18n("Unknown unlock error."); TQString errStr = unlockResult.contains("errStr") ? unlockResult["errStr"].toString() : TQString::null;
if (!errStr.isEmpty()) { if (errStr.isEmpty())
qerror.append(i18n("<p>Technical details:<br>").append(errStr)); {
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>");
} }
qerror.append("</qt>"); KMessageBox::error(this, errStr, i18n("Unlock Failed"));
m_passDlg->clearPassword();
} }
else { else {
m_passDlg->hide(); m_passDlg->hide();
qerror = "";
} }
if (qerror != "") KMessageBox::error(this, qerror, i18n("Unlock Failed"));
populateDeviceInformation(); populateDeviceInformation();
} }
@ -999,25 +1000,18 @@ void DevicePropertiesDialog::lockDisk() {
// Use DCOP call to lock the disk to make sure the status and mime type of the underlying medium // Use DCOP call to lock the disk to make sure the status and mime type of the underlying medium
// is correctly updated throughout TDE // is correctly updated throughout TDE
TQString qerror;
DCOPRef mediamanager("kded", "mediamanager"); DCOPRef mediamanager("kded", "mediamanager");
DCOPReply reply = mediamanager.call("lockByNode", sdevice->deviceNode()); DCOPReply reply = mediamanager.call("lockByNode", sdevice->deviceNode());
TQStringVariantMap lockResult; TQStringVariantMap lockResult;
if (reply.isValid()) { if (reply.isValid()) {
reply.get(lockResult); reply.get(lockResult);
} }
if (lockResult["result"].toBool() == false) { if (!lockResult.contains("result") || lockResult["result"].toBool() == false) {
// Lock failed! // Lock failed!
qerror = "<qt>" + i18n("Unfortunately, the device could not be locked."); TQString errStr = lockResult.contains("errStr") ? lockResult["errStr"].toString() : i18n("Unable to lock the device.");
TQString errStr = lockResult.contains("errStr") ? lockResult["errStr"].toString() : TQString::null; KMessageBox::error(this, "<qt>" + errStr + "</qt>", i18n("Lock Failed"));
if (!errStr.isEmpty()) {
qerror.append(i18n("<p>Technical details:<br>").append(errStr));
}
qerror.append("</qt>");
} }
if (qerror != "") KMessageBox::error(this, qerror, i18n("Lock Failed"));
populateDeviceInformation(); populateDeviceInformation();
} }

@ -37,6 +37,7 @@
#include <tdemessagebox.h> #include <tdemessagebox.h>
#include <kpassivepopup.h> #include <kpassivepopup.h>
#include <kstandarddirs.h> #include <kstandarddirs.h>
#include "passworddlg.h"
#include <dcopclient.h> #include <dcopclient.h>
@ -48,8 +49,8 @@
#include "hwdevicetray.h" #include "hwdevicetray.h"
HwDeviceSystemTray::HwDeviceSystemTray(TQWidget* parent, const char *name) HwDeviceSystemTray::HwDeviceSystemTray(TQWidget* parent, const char *name)
: KSystemTray(parent, name) { : KSystemTray(parent, name), m_passDlg(NULL)
{
// Create notifier // Create notifier
m_hardwareNotifierContainer = new TDEPassivePopupStackContainer(); m_hardwareNotifierContainer = new TDEPassivePopupStackContainer();
connect(m_hardwareNotifierContainer, TQT_SIGNAL(popupClicked(KPassivePopup*, TQPoint, TQString)), this, TQT_SLOT(devicePopupClicked(KPassivePopup*, TQPoint, TQString))); connect(m_hardwareNotifierContainer, TQT_SIGNAL(popupClicked(KPassivePopup*, TQPoint, TQString)), this, TQT_SLOT(devicePopupClicked(KPassivePopup*, TQPoint, TQString)));
@ -75,8 +76,11 @@ HwDeviceSystemTray::HwDeviceSystemTray(TQWidget* parent, const char *name)
connect(kapp, TQT_SIGNAL(settingsChanged(int)), TQT_SLOT(slotSettingsChanged(int))); connect(kapp, TQT_SIGNAL(settingsChanged(int)), TQT_SLOT(slotSettingsChanged(int)));
new TDEActionMenu(i18n("Open Device"), SmallIcon("connect_creating", TQIconSet::Automatic), actionCollection(), "mount_menu"); new TDEActionMenu(i18n("Mount"), SmallIcon("drive-harddisk-mounted", TQIconSet::Automatic), actionCollection(), "mount_menu");
new TDEActionMenu(i18n("Eject Device"), SmallIcon("connect_no", TQIconSet::Automatic), actionCollection(), "unmount_menu"); new TDEActionMenu(i18n("Unmount"), SmallIcon("drive-harddisk-unmounted", TQIconSet::Automatic), actionCollection(), "unmount_menu");
new TDEActionMenu(i18n("Unlock"), SmallIcon("decrypted", TQIconSet::Automatic), actionCollection(), "unlock_menu");
new TDEActionMenu(i18n("Lock"), SmallIcon("encrypted", TQIconSet::Automatic), actionCollection(), "lock_menu");
new TDEActionMenu(i18n("Eject"), SmallIcon("player_eject", TQIconSet::Automatic), actionCollection(), "eject_menu");
#ifdef __TDE_HAVE_TDEHWLIB #ifdef __TDE_HAVE_TDEHWLIB
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
@ -86,8 +90,13 @@ HwDeviceSystemTray::HwDeviceSystemTray(TQWidget* parent, const char *name)
#endif #endif
} }
HwDeviceSystemTray::~HwDeviceSystemTray() { HwDeviceSystemTray::~HwDeviceSystemTray()
{
delete m_hardwareNotifierContainer; delete m_hardwareNotifierContainer;
if (m_passDlg)
{
delete m_passDlg;
}
} }
/*! /*!
@ -143,43 +152,43 @@ void HwDeviceSystemTray::mousePressEvent(TQMouseEvent* e) {
bool HwDeviceSystemTray::isMonitoredDevice(TDEStorageDevice* sdevice) { bool HwDeviceSystemTray::isMonitoredDevice(TDEStorageDevice* sdevice) {
// Type selection logic largely duplicated from the media manager tdeioslave // Type selection logic largely duplicated from the media manager tdeioslave
if (((sdevice->isDiskOfType(TDEDiskDeviceType::LUKS) if ((sdevice->isDiskOfType(TDEDiskDeviceType::LUKS) ||
|| sdevice->checkDiskStatus(TDEDiskDeviceStatus::ContainsFilesystem) sdevice->checkDiskStatus(TDEDiskDeviceStatus::ContainsFilesystem) ||
|| sdevice->isDiskOfType(TDEDiskDeviceType::CDAudio) sdevice->isDiskOfType(TDEDiskDeviceType::CDAudio) ||
|| sdevice->checkDiskStatus(TDEDiskDeviceStatus::Blank)) sdevice->checkDiskStatus(TDEDiskDeviceStatus::Blank)) &&
&& !sdevice->checkDiskStatus(TDEDiskDeviceStatus::UsedByDevice) !sdevice->checkDiskStatus(TDEDiskDeviceStatus::Hidden) &&
&& !sdevice->checkDiskStatus(TDEDiskDeviceStatus::Hidden) (sdevice->isDiskOfType(TDEDiskDeviceType::HDD) ||
&& (sdevice->isDiskOfType(TDEDiskDeviceType::HDD) sdevice->isDiskOfType(TDEDiskDeviceType::CDROM) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::CDROM)) sdevice->isDiskOfType(TDEDiskDeviceType::CDR) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::CDR)) sdevice->isDiskOfType(TDEDiskDeviceType::CDRW) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::CDRW)) sdevice->isDiskOfType(TDEDiskDeviceType::CDMO) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::CDMO)) sdevice->isDiskOfType(TDEDiskDeviceType::CDMRRW) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::CDMRRW)) sdevice->isDiskOfType(TDEDiskDeviceType::CDMRRWW) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::CDMRRWW)) sdevice->isDiskOfType(TDEDiskDeviceType::DVDROM) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::DVDROM)) sdevice->isDiskOfType(TDEDiskDeviceType::DVDRAM) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::DVDRAM)) sdevice->isDiskOfType(TDEDiskDeviceType::DVDR) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::DVDR)) sdevice->isDiskOfType(TDEDiskDeviceType::DVDRW) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::DVDRW)) sdevice->isDiskOfType(TDEDiskDeviceType::DVDRDL) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::DVDRDL)) sdevice->isDiskOfType(TDEDiskDeviceType::DVDRWDL) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::DVDRWDL)) sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSR) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSR)) sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRW) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRW)) sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRDL) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRDL)) sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRWDL) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::DVDPLUSRWDL)) sdevice->isDiskOfType(TDEDiskDeviceType::BDROM) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::BDROM)) sdevice->isDiskOfType(TDEDiskDeviceType::BDR) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::BDR)) sdevice->isDiskOfType(TDEDiskDeviceType::BDRW) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::BDRW)) sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDROM) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDROM)) sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDR) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDR)) sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDRW) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::HDDVDRW)) sdevice->isDiskOfType(TDEDiskDeviceType::CDAudio) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::CDAudio)) sdevice->isDiskOfType(TDEDiskDeviceType::CDVideo) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::CDVideo)) sdevice->isDiskOfType(TDEDiskDeviceType::DVDVideo) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::DVDVideo)) sdevice->isDiskOfType(TDEDiskDeviceType::BDVideo) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::BDVideo)) sdevice->isDiskOfType(TDEDiskDeviceType::Floppy) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::Floppy)) sdevice->isDiskOfType(TDEDiskDeviceType::Zip) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::Zip)) sdevice->isDiskOfType(TDEDiskDeviceType::Jaz) ||
|| (sdevice->isDiskOfType(TDEDiskDeviceType::Jaz)))) sdevice->isDiskOfType(TDEDiskDeviceType::Camera)))
|| (sdevice->isDiskOfType(TDEDiskDeviceType::Camera))) { {
return true; return true;
} }
else { else {
@ -213,59 +222,133 @@ void HwDeviceSystemTray::configChanged() {
} }
void HwDeviceSystemTray::populateMenu(TDEPopupMenu* menu) { void HwDeviceSystemTray::populateMenu(TDEPopupMenu* menu) {
int lastMountIndex; menu->insertTitle(SmallIcon("drive-harddisk-unmounted"), i18n("Storage Devices"));
int lastUnmountIndex;
TDEGenericDevice *hwdevice;
TDEActionMenu* mountDiskActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("mount_menu")); TDEActionMenu* mountDiskActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("mount_menu"));
mountDiskActionMenu->popupMenu()->clear();
m_mountMenuIndexMap.clear();
TDEActionMenu* unmountDiskActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("unmount_menu")); TDEActionMenu* unmountDiskActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("unmount_menu"));
TDEActionMenu* unlockDiskActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("unlock_menu"));
TDEActionMenu* lockDiskActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("lock_menu"));
TDEActionMenu* ejectDiskActionMenu = static_cast<TDEActionMenu*>(actionCollection()->action("eject_menu"));
mountDiskActionMenu->popupMenu()->clear();
unmountDiskActionMenu->popupMenu()->clear(); unmountDiskActionMenu->popupMenu()->clear();
m_mountMenuIndexMap.clear(); unlockDiskActionMenu->popupMenu()->clear();
lockDiskActionMenu->popupMenu()->clear();
ejectDiskActionMenu->popupMenu()->clear();
menu->insertTitle(SmallIcon("drive-harddisk-unmounted"), i18n("Storage Devices")); m_mountMenuIndexMap.clear();
m_unmountMenuIndexMap.clear();
m_unlockMenuIndexMap.clear();
m_lockMenuIndexMap.clear();
m_ejectMenuIndexMap.clear();
// Find all storage devices and add them to the popup menus
int lastMountIndex = -1;
int lastUnmountIndex = -1;
int lastUnlockIndex = -1;
int lastLockIndex = -1;
int lastEjectIndex = -1;
// Find all storage devices and add them to the popup menu
lastMountIndex = 1;
lastUnmountIndex = 1;
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk); TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk);
for (hwdevice = diskDeviceList.first(); hwdevice; hwdevice = diskDeviceList.next()) { for (TDEGenericDevice *hwdevice = diskDeviceList.first(); hwdevice; hwdevice = diskDeviceList.next())
{
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice); TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if (isMonitoredDevice(sdevice)) { if (isMonitoredDevice(sdevice))
lastMountIndex = mountDiskActionMenu->popupMenu()->insertItem(hwdevice->icon(TDEIcon::SizeSmall), i18n("%1 (%2)").arg(sdevice->friendlyName(), sdevice->deviceNode())); {
mountDiskActionMenu->popupMenu()->connectItem(lastMountIndex, this, TQT_SLOT(slotMountDevice(int))); if (sdevice->isDiskOfType(TDEDiskDeviceType::LUKS) || sdevice->isDiskOfType(TDEDiskDeviceType::OtherCrypted))
m_mountMenuIndexMap[lastMountIndex] = sdevice->diskUUID(); {
if (m_mountMenuIndexMap[lastMountIndex] == "") { if (sdevice->isDiskOfType(TDEDiskDeviceType::UnlockedCrypt))
m_mountMenuIndexMap[lastMountIndex] = sdevice->systemPath(); {
lastLockIndex = lockDiskActionMenu->popupMenu()->insertItem(hwdevice->icon(TDEIcon::SizeSmall),
i18n("%1 (%2)").arg(sdevice->friendlyName(), sdevice->deviceNode()));
lockDiskActionMenu->popupMenu()->connectItem(lastLockIndex, this, TQT_SLOT(slotLockDevice(int)));
m_lockMenuIndexMap[lastLockIndex] = sdevice->diskUUID();
if (m_lockMenuIndexMap[lastLockIndex] == "")
{
m_lockMenuIndexMap[lastLockIndex] = sdevice->systemPath();
}
}
else
{
lastUnlockIndex = unlockDiskActionMenu->popupMenu()->insertItem(hwdevice->icon(TDEIcon::SizeSmall),
i18n("%1 (%2)").arg(sdevice->friendlyName(), sdevice->deviceNode()));
unlockDiskActionMenu->popupMenu()->connectItem(lastUnlockIndex, this, TQT_SLOT(slotUnlockDevice(int)));
m_unlockMenuIndexMap[lastUnlockIndex] = sdevice->diskUUID();
if (m_unlockMenuIndexMap[lastUnlockIndex] == "")
{
m_unlockMenuIndexMap[lastUnlockIndex] = sdevice->systemPath();
}
}
} }
if (sdevice->mountPath() != TQString::null) {
lastUnmountIndex = unmountDiskActionMenu->popupMenu()->insertItem(hwdevice->icon(TDEIcon::SizeSmall), i18n("%1 (%2)").arg(sdevice->friendlyName(), sdevice->deviceNode())); if (sdevice->checkDiskStatus(TDEDiskDeviceStatus::Mountable))
unmountDiskActionMenu->popupMenu()->connectItem(lastUnmountIndex, this, TQT_SLOT(slotUnmountDevice(int))); {
m_unmountMenuIndexMap[lastUnmountIndex] = sdevice->diskUUID(); if (sdevice->mountPath().isEmpty())
if (m_unmountMenuIndexMap[lastMountIndex] == "") { {
m_unmountMenuIndexMap[lastMountIndex] = sdevice->systemPath(); lastMountIndex = mountDiskActionMenu->popupMenu()->insertItem(hwdevice->icon(TDEIcon::SizeSmall),
i18n("%1 (%2)").arg(sdevice->friendlyName(), sdevice->deviceNode()));
mountDiskActionMenu->popupMenu()->connectItem(lastMountIndex, this, TQT_SLOT(slotMountDevice(int)));
m_mountMenuIndexMap[lastMountIndex] = sdevice->diskUUID();
if (m_mountMenuIndexMap[lastMountIndex] == "")
{
m_mountMenuIndexMap[lastMountIndex] = sdevice->systemPath();
}
}
else
{
lastUnmountIndex = unmountDiskActionMenu->popupMenu()->insertItem(hwdevice->icon(TDEIcon::SizeSmall),
i18n("%1 (%2)").arg(sdevice->friendlyName(), sdevice->deviceNode()));
unmountDiskActionMenu->popupMenu()->connectItem(lastUnmountIndex, this, TQT_SLOT(slotUnmountDevice(int)));
m_unmountMenuIndexMap[lastUnmountIndex] = sdevice->diskUUID();
if (m_unmountMenuIndexMap[lastMountIndex] == "")
{
m_unmountMenuIndexMap[lastMountIndex] = sdevice->systemPath();
}
}
}
if (sdevice->checkDiskStatus(TDEDiskDeviceStatus::Removable) ||
sdevice->checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable))
{
lastEjectIndex = ejectDiskActionMenu->popupMenu()->insertItem(hwdevice->icon(TDEIcon::SizeSmall),
i18n("%1 (%2)").arg(sdevice->friendlyName(), sdevice->deviceNode()));
ejectDiskActionMenu->popupMenu()->connectItem(lastEjectIndex, this, TQT_SLOT(slotEjectDevice(int)));
m_ejectMenuIndexMap[lastEjectIndex] = sdevice->diskUUID();
if (m_ejectMenuIndexMap[lastEjectIndex] == "")
{
m_ejectMenuIndexMap[lastEjectIndex] = sdevice->systemPath();
} }
} }
} }
} }
if (lastMountIndex == 0) { mountDiskActionMenu->setEnabled(lastMountIndex != -1);
mountDiskActionMenu->setEnabled(false); unmountDiskActionMenu->setEnabled(lastUnmountIndex != -1);
unlockDiskActionMenu->setEnabled(lastUnlockIndex != -1);
lockDiskActionMenu->setEnabled(lastLockIndex != -1);
ejectDiskActionMenu->setEnabled(lastEjectIndex != -1);
if (lastMountIndex != -1)
{
mountDiskActionMenu->plug(menu);
} }
else { if (lastUnmountIndex != -1)
mountDiskActionMenu->setEnabled(true); {
unmountDiskActionMenu->plug(menu);
} }
if (lastUnmountIndex == 0) { if (lastUnlockIndex != -1)
unmountDiskActionMenu->setEnabled(false); {
unlockDiskActionMenu->plug(menu);
} }
else { if (lastLockIndex != -1)
unmountDiskActionMenu->setEnabled(true); {
lockDiskActionMenu->plug(menu);
}
if (lastEjectIndex != -1)
{
ejectDiskActionMenu->plug(menu);
} }
mountDiskActionMenu->plug(menu);
unmountDiskActionMenu->plug(menu);
} }
void HwDeviceSystemTray::slotMountDevice(int parameter) void HwDeviceSystemTray::slotMountDevice(int parameter)
@ -292,20 +375,26 @@ void HwDeviceSystemTray::slotMountDevice(int parameter)
void HwDeviceSystemTray::slotUnmountDevice(int parameter) void HwDeviceSystemTray::slotUnmountDevice(int parameter)
{ {
TDEGenericDevice *hwdevice;
TQString uuid = m_unmountMenuIndexMap[parameter]; TQString uuid = m_unmountMenuIndexMap[parameter];
if (uuid != "") { if (uuid != "")
{
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk); TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk);
for (hwdevice = diskDeviceList.first(); hwdevice; hwdevice = diskDeviceList.next()) { for (TDEGenericDevice *hwdevice = diskDeviceList.first(); hwdevice; hwdevice = diskDeviceList.next())
{
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 (!sdevice->mountPath().isEmpty()) { {
if (!sdevice->mountPath().isEmpty())
{
TQStringVariantMap unmountResult = sdevice->unmountDevice(); TQStringVariantMap unmountResult = sdevice->unmountDevice();
if (unmountResult["result"].toBool() == false) { if (unmountResult["result"].toBool() == false)
{
TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null; TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null;
TQString retcodeStr = unmountResult.contains("retCode") ? unmountResult["retCode"].toString() : "not available"; TQString retcodeStr = unmountResult.contains("retCode") ? unmountResult["retCode"].toString() : i18n("not available");
KMessageBox::error(0, i18n("<qt><b>Unable to eject device</b><p>Detailed error information:<br>%1 (error code %2)</qt>").arg(errStr).arg(retcodeStr), i18n("Eject Failed")); TQString qerror = i18n("<p>Technical details:<br>") + (!errStr.isEmpty() ? errStr : i18n("unknown"));
KMessageBox::error(0, i18n("<qt><b>Unable to unmount the device.</b>") + qerror + " (error code " +
retcodeStr + ").</qt>", i18n("Unmount failed"));
} }
return; return;
} }
@ -314,6 +403,119 @@ void HwDeviceSystemTray::slotUnmountDevice(int parameter)
} }
} }
void HwDeviceSystemTray::slotUnlockDevice(int parameter)
{
TQString uuid = m_unlockMenuIndexMap[parameter];
if (uuid != "")
{
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))
{
if (!m_passDlg)
{
m_passDlg = new PasswordDlg();
connect(m_passDlg, TQT_SIGNAL(user1Clicked()), this, TQT_SLOT(doUnlockDisk()));
}
m_passDlg->setDevice(sdevice->deviceNode());
m_passDlg->index = parameter;
m_passDlg->clearPassword();
m_passDlg->show();
}
}
}
}
void HwDeviceSystemTray::doUnlockDisk()
{
TQString uuid = m_unlockMenuIndexMap[m_passDlg->index];
if (uuid != "")
{
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))
{
TQStringVariantMap unlockResult = sdevice->unlockDevice(m_passDlg->getPassword());
if (unlockResult["result"].toBool() == false)
{
// Unlock failed!
TQString errStr = unlockResult.contains("errStr") ? unlockResult["errStr"].toString() : TQString::null;
TQString retcodeStr = unlockResult.contains("retCode") ? unlockResult["retCode"].toString() : i18n("not available");
TQString qerror = i18n("<p>Technical details:<br>") + (!errStr.isEmpty() ? errStr : i18n("unknown"));
KMessageBox::error(0, i18n("<qt><b>Unable to unlock the device.</b>") + qerror + " (error code " +
retcodeStr + ").</qt>", i18n("Unlock failed"));
m_passDlg->clearPassword();
}
else
{
m_passDlg->hide();
}
}
}
}
}
void HwDeviceSystemTray::slotLockDevice(int parameter)
{
TDEGenericDevice *hwdevice;
TQString uuid = m_lockMenuIndexMap[parameter];
if (uuid != "")
{
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
TDEGenericHardwareList diskDeviceList = hwdevices->listByDeviceClass(TDEGenericDeviceType::Disk);
for (hwdevice = diskDeviceList.first(); hwdevice; hwdevice = diskDeviceList.next()) {
TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(hwdevice);
if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid))
{
TQStringVariantMap lockResult = sdevice->lockDevice();
if (lockResult["result"].toBool() == false)
{
// Lock failed!
TQString errStr = lockResult.contains("errStr") ? lockResult["errStr"].toString() : TQString::null;
TQString retcodeStr = lockResult.contains("retCode") ? lockResult["retCode"].toString() : i18n("not available");
TQString qerror = i18n("<p>Technical details:<br>") + (!errStr.isEmpty() ? errStr : i18n("unknown"));
KMessageBox::error(0, i18n("<qt><b>Unable to lock the device.</b>") + qerror + " (error code " +
retcodeStr + ").</qt>", i18n("Lock failed"));
}
}
}
}
}
void HwDeviceSystemTray::slotEjectDevice(int parameter)
{
TQString uuid = m_ejectMenuIndexMap[parameter];
if (uuid != "")
{
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))
{
TQStringVariantMap ejectResult = sdevice->ejectDrive();
if (ejectResult["result"].toBool() == false)
{
// Eject failed!
TQString errStr = ejectResult.contains("errStr") ? ejectResult["errStr"].toString() : TQString::null;
TQString retcodeStr = ejectResult.contains("retCode") ? ejectResult["retCode"].toString() : i18n("not available");
TQString qerror = i18n("<p>Technical details:<br>") + (!errStr.isEmpty() ? errStr : i18n("unknown"));
KMessageBox::error(0, i18n("<qt><b>Unable to eject the device.</b>") + qerror + " (error code " +
retcodeStr + ").</qt>", i18n("Eject failed"));
}
return;
}
}
}
}
void HwDeviceSystemTray::slotHardwareConfig() { void HwDeviceSystemTray::slotHardwareConfig() {
KCMultiDialog *kcm = new KCMultiDialog(KDialogBase::Plain, i18n("Configure"), this); KCMultiDialog *kcm = new KCMultiDialog(KDialogBase::Plain, i18n("Configure"), this);
@ -429,4 +631,4 @@ void HwDeviceSystemTray::slotHelpContents() {
kapp->invokeHelp(TQString::null, "hwdevicetray"); kapp->invokeHelp(TQString::null, "hwdevicetray");
} }
#include "hwdevicetray.moc" #include "hwdevicetray.moc"

@ -34,6 +34,7 @@
#endif #endif
class KHelpMenu; class KHelpMenu;
class PasswordDlg;
class TDEPopupMenu; class TDEPopupMenu;
typedef TQMap<int, TQString> TQStringMap; typedef TQMap<int, TQString> TQStringMap;
@ -59,6 +60,9 @@ protected slots:
void slotMountDevice(int parameter); void slotMountDevice(int parameter);
void slotUnmountDevice(int parameter); void slotUnmountDevice(int parameter);
void slotUnlockDevice(int parameter);
void slotLockDevice(int parameter);
void slotEjectDevice(int parameter);
protected: protected:
void mousePressEvent(TQMouseEvent *e); void mousePressEvent(TQMouseEvent *e);
@ -70,8 +74,8 @@ private slots:
void deviceAdded(TDEGenericDevice*); void deviceAdded(TDEGenericDevice*);
void deviceRemoved(TDEGenericDevice*); void deviceRemoved(TDEGenericDevice*);
void deviceChanged(TDEGenericDevice*); void deviceChanged(TDEGenericDevice*);
void devicePopupClicked(KPassivePopup*, TQPoint, TQString); void devicePopupClicked(KPassivePopup*, TQPoint, TQString);
void doUnlockDisk();
private: private:
bool isMonitoredDevice(TDEStorageDevice* sdevice); bool isMonitoredDevice(TDEStorageDevice* sdevice);
@ -88,8 +92,12 @@ private:
TQStringMap m_mountMenuIndexMap; TQStringMap m_mountMenuIndexMap;
TQStringMap m_unmountMenuIndexMap; TQStringMap m_unmountMenuIndexMap;
TQStringMap m_unlockMenuIndexMap;
TQStringMap m_lockMenuIndexMap;
TQStringMap m_ejectMenuIndexMap;
TDEPopupMenu* m_menu; TDEPopupMenu* m_menu;
KSimpleConfig *r_config; KSimpleConfig *r_config;
PasswordDlg *m_passDlg;
}; };
#endif #endif

@ -22,20 +22,14 @@
#include "passworddlg.h" #include "passworddlg.h"
PasswordDlg::PasswordDlg(TQString url, TQString iconName) : PasswordDlg::PasswordDlg() :
KDialogBase(NULL, "PasswordDlg", true, i18n("Unlock Storage Device"), (Cancel|User1), User1, false, KGuiItem(i18n("Unlock"), "unlocked" )) KDialogBase(NULL, "PasswordDlg", true, i18n("Unlock Storage Device"), (Cancel|User1),
User1, false, KGuiItem(i18n("Unlock"), "unlocked" ))
{ {
unlockDialog = new UnlockDialog(this); unlockDialog = new UnlockDialog(this);
unlockDialog->descLabel->setText(unlockDialog->descLabel->text().arg(url));
unlockDialog->descLabel->adjustSize();
unlockDialog->adjustSize();
enableButton( User1, false ); enableButton( User1, false );
unlockDialog->encryptedIcon->setPixmap(TDEGlobal::iconLoader()->loadIcon("drive-harddisk-locked",
TQPixmap pixmap = TDEGlobal::iconLoader()->loadIcon(iconName, TDEIcon::NoGroup, TDEIcon::SizeLarge); TDEIcon::NoGroup, TDEIcon::SizeLarge));
unlockDialog->encryptedIcon->setPixmap( pixmap );
connect(unlockDialog->passwordEdit, TQT_SIGNAL (textChanged(const TQString &)), this, TQT_SLOT (slotPasswordChanged(const TQString &))); connect(unlockDialog->passwordEdit, TQT_SIGNAL (textChanged(const TQString &)), this, TQT_SLOT (slotPasswordChanged(const TQString &)));
setMainWidget(unlockDialog); setMainWidget(unlockDialog);
@ -46,6 +40,19 @@ PasswordDlg::~PasswordDlg()
delete unlockDialog; delete unlockDialog;
} }
void PasswordDlg::setDevice(TQString deviceName)
{
unlockDialog->descLabel->setText("<p><b>" + deviceName + "</b> is an encrypted storage device.</p>"
"<p>Please enter the password to unlock the storage device.</p>");
unlockDialog->descLabel->adjustSize();
unlockDialog->adjustSize();
}
void PasswordDlg::clearPassword()
{
unlockDialog->passwordEdit->setText(TQString::null);
}
TQString PasswordDlg::getPassword() TQString PasswordDlg::getPassword()
{ {
return unlockDialog->passwordEdit->text(); return unlockDialog->passwordEdit->text();

@ -42,11 +42,15 @@ class PasswordDlg : public KDialogBase
Q_OBJECT Q_OBJECT
public: public:
PasswordDlg(TQString url, TQString iconName); PasswordDlg();
~PasswordDlg(); ~PasswordDlg();
void setDevice(TQString deviceName);
void clearPassword();
TQString getPassword(); TQString getPassword();
int index;
public slots: public slots:
void slotPasswordChanged(const TQString &text); void slotPasswordChanged(const TQString &text);

@ -106,8 +106,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>&lt;p&gt;&lt;b&gt;%1&lt;/b&gt; is an encrypted storage device.&lt;/p&gt; <string>Dummy placeholder</string>
&lt;p&gt;Please enter the password to unlock the storage device.&lt;/p&gt;</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>WordBreak|AlignTop</set> <set>WordBreak|AlignTop</set>

@ -1279,7 +1279,7 @@ TQStringVariantMap TDEBackend::mount(const Medium *medium)
TQStringVariantMap mountResult = sdevice->mountDevice(diskLabel, valids); TQStringVariantMap mountResult = sdevice->mountDevice(diskLabel, valids);
TQString mountedPath = mountResult.contains("mountPath") ? mountResult["mountPath"].toString() : TQString::null; TQString mountedPath = mountResult.contains("mountPath") ? mountResult["mountPath"].toString() : TQString::null;
if (mountedPath.isEmpty()) { if (mountedPath.isEmpty()) {
qerror = i18n("Unable to mount this device."); qerror = i18n("<b>Unable to mount this device.</b>");
TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : TQString::null; TQString errStr = mountResult.contains("errStr") ? mountResult["errStr"].toString() : TQString::null;
if (!errStr.isEmpty()) { if (!errStr.isEmpty()) {
qerror.append(i18n("<p>Technical details:<br>").append(errStr)); qerror.append(i18n("<p>Technical details:<br>").append(errStr));
@ -1380,7 +1380,7 @@ TQStringVariantMap TDEBackend::unmount(const TQString &id)
TQStringVariantMap unmountResult = sdevice->unmountDevice(); TQStringVariantMap unmountResult = sdevice->unmountDevice();
if (unmountResult["result"].toBool() == false) { if (unmountResult["result"].toBool() == false) {
// Unmount failed! // Unmount failed!
qerror = i18n("Unfortunately, the device <b>%1</b> (%2) named <b>'%3'</b> and currently mounted at " qerror = i18n("The device <b>%1</b> (%2) named <b>'%3'</b> and currently mounted at "
"<b>%4</b> could not be unmounted. ").arg("system:/media/" + medium->name(), medium->deviceNode(), "<b>%4</b> could not be unmounted. ").arg("system:/media/" + medium->name(), medium->deviceNode(),
medium->prettyLabel(), medium->prettyBaseURL().pathOrURL()); medium->prettyLabel(), medium->prettyBaseURL().pathOrURL());
TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null; TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null;
@ -1402,7 +1402,7 @@ TQStringVariantMap TDEBackend::unmount(const TQString &id)
unmountResult = sdevice->unmountDevice(); unmountResult = sdevice->unmountDevice();
if (unmountResult["result"].toBool() == false) { if (unmountResult["result"].toBool() == false) {
// Unmount failed! // Unmount failed!
qerror = i18n("Unfortunately, the device <b>%1</b> (%2) named <b>'%3'</b> and currently mounted at " qerror = i18n("The device <b>%1</b> (%2) named <b>'%3'</b> and currently mounted at "
"<b>%4</b> could not be unmounted. ").arg("system:/media/" + medium->name(), medium->deviceNode(), "<b>%4</b> could not be unmounted. ").arg("system:/media/" + medium->name(), medium->deviceNode(),
medium->prettyLabel(), medium->prettyBaseURL().pathOrURL()); medium->prettyLabel(), medium->prettyBaseURL().pathOrURL());
TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null; TQString errStr = unmountResult.contains("errStr") ? unmountResult["errStr"].toString() : TQString::null;
@ -1464,7 +1464,7 @@ TQStringVariantMap TDEBackend::unlock(const TQString &id, const TQString &passwo
TQStringVariantMap unlockResult = sdevice->unlockDevice(password); TQStringVariantMap unlockResult = sdevice->unlockDevice(password);
if (unlockResult["result"].toBool() == false) { if (unlockResult["result"].toBool() == false) {
TQString qerror = i18n("Unable to unlock the device."); TQString qerror = i18n("<b>Unable to unlock the device.</b>");
TQString errStr = unlockResult.contains("errStr") ? unlockResult["errStr"].toString() : TQString::null; TQString errStr = unlockResult.contains("errStr") ? unlockResult["errStr"].toString() : TQString::null;
if (!errStr.isEmpty()) { if (!errStr.isEmpty()) {
qerror.append(i18n("<p>Technical details:<br>").append(errStr)); qerror.append(i18n("<p>Technical details:<br>").append(errStr));
@ -1513,7 +1513,7 @@ TQStringVariantMap TDEBackend::lock(const TQString &id)
TQStringVariantMap lockResult = sdevice->lockDevice(); TQStringVariantMap lockResult = sdevice->lockDevice();
if (lockResult["result"].toBool() == false) { if (lockResult["result"].toBool() == false) {
TQString qerror = i18n("Unable to lock the device."); TQString qerror = i18n("<b>Unable to lock the device.</b>");
TQString errStr = lockResult.contains("errStr") ? lockResult["errStr"].toString() : TQString::null; TQString errStr = lockResult.contains("errStr") ? lockResult["errStr"].toString() : TQString::null;
if (!errStr.isEmpty()) { if (!errStr.isEmpty()) {
qerror.append(i18n("<p>Technical details:<br>").append(errStr)); qerror.append(i18n("<p>Technical details:<br>").append(errStr));
@ -1538,7 +1538,7 @@ void TDEBackend::slotResult(TDEIO::Job *job)
if (job->error() == TDEIO::ERR_COULD_NOT_UNMOUNT) { if (job->error() == TDEIO::ERR_COULD_NOT_UNMOUNT) {
TQString proclist(listUsingProcesses(medium)); TQString proclist(listUsingProcesses(medium));
qerror += "<p>" + i18n("Unfortunately, the device <b>%1</b> (%2) named <b>'%3'</b> and " qerror += "<p>" + i18n("The device <b>%1</b> (%2) named <b>'%3'</b> and "
"currently mounted at <b>%4</b> could not be unmounted. ").arg( "currently mounted at <b>%4</b> could not be unmounted. ").arg(
"system:/media/" + medium->name(), "system:/media/" + medium->name(),
medium->deviceNode(), medium->deviceNode(),

Loading…
Cancel
Save