summaryrefslogtreecommitdiffstats
path: root/kcontrol
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2020-11-21 17:49:23 +0800
committerMichele Calgaro <michele.calgaro@yahoo.it>2020-11-21 17:49:23 +0800
commitd39c407bf49fab58fa53c20bb3d301ee6e709c32 (patch)
tree9bc93b5ecaf45943c3db3304f444a79eb1c780ed /kcontrol
parent1b6c123de102f0152d296fba8771d348329ba95c (diff)
downloadtdebase-d39c407bf49fab58fa53c20bb3d301ee6e709c32.tar.gz
tdebase-d39c407bf49fab58fa53c20bb3d301ee6e709c32.zip
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>
Diffstat (limited to 'kcontrol')
-rw-r--r--kcontrol/hwmanager/CMakeLists.txt2
-rw-r--r--kcontrol/hwmanager/devicepropsdlg.cpp38
-rw-r--r--kcontrol/hwmanager/hwdevicetray.cpp372
-rw-r--r--kcontrol/hwmanager/hwdevicetray.h10
-rw-r--r--kcontrol/hwmanager/passworddlg.cpp29
-rw-r--r--kcontrol/hwmanager/passworddlg.h6
-rw-r--r--kcontrol/hwmanager/unlockdialog.ui3
7 files changed, 337 insertions, 123 deletions
diff --git a/kcontrol/hwmanager/CMakeLists.txt b/kcontrol/hwmanager/CMakeLists.txt
index bd06bd930..3ac5dbc64 100644
--- a/kcontrol/hwmanager/CMakeLists.txt
+++ b/kcontrol/hwmanager/CMakeLists.txt
@@ -58,7 +58,7 @@ tde_add_kpart( kcm_hwmanager AUTOMOC
tde_add_executable( tdehwdevicetray AUTOMOC
SOURCES
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
DESTINATION ${BIN_INSTALL_DIR}
)
diff --git a/kcontrol/hwmanager/devicepropsdlg.cpp b/kcontrol/hwmanager/devicepropsdlg.cpp
index bb37695bd..bc50f11ac 100644
--- a/kcontrol/hwmanager/devicepropsdlg.cpp
+++ b/kcontrol/hwmanager/devicepropsdlg.cpp
@@ -940,7 +940,7 @@ void DevicePropertiesDialog::unmountDisk() {
TQStringVariantMap unmountResult = sdevice->unmountDevice();
if (unmountResult["result"].toBool() == false) {
// 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;
if (!errStr.isEmpty()) {
qerror.append(i18n("<p>Technical details:<br>").append(errStr));
@@ -958,9 +958,11 @@ void DevicePropertiesDialog::unlockDisk() {
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()));
}
+ m_passDlg->setDevice(sdevice->deviceNode());
+ m_passDlg->clearPassword();
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
// is correctly updated throughout TDE
- TQString qerror;
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()) {
- 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.");
- if (!errStr.isEmpty()) {
- qerror.append(i18n("<p>Technical details:<br>").append(errStr));
+ 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 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 {
m_passDlg->hide();
- qerror = "";
}
- if (qerror != "") KMessageBox::error(this, qerror, i18n("Unlock Failed"));
-
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
// is correctly updated throughout TDE
- TQString qerror;
DCOPRef mediamanager("kded", "mediamanager");
DCOPReply reply = mediamanager.call("lockByNode", sdevice->deviceNode());
TQStringVariantMap lockResult;
if (reply.isValid()) {
reply.get(lockResult);
}
- if (lockResult["result"].toBool() == false) {
+ if (!lockResult.contains("result") || lockResult["result"].toBool() == false) {
// Lock failed!
- qerror = "<qt>" + i18n("Unfortunately, the device could not be locked.");
- TQString errStr = lockResult.contains("errStr") ? lockResult["errStr"].toString() : TQString::null;
- if (!errStr.isEmpty()) {
- qerror.append(i18n("<p>Technical details:<br>").append(errStr));
- }
- qerror.append("</qt>");
+ TQString errStr = lockResult.contains("errStr") ? lockResult["errStr"].toString() : i18n("Unable to lock the device.");
+ KMessageBox::error(this, "<qt>" + errStr + "</qt>", i18n("Lock Failed"));
}
- if (qerror != "") KMessageBox::error(this, qerror, i18n("Lock Failed"));
-
populateDeviceInformation();
}
diff --git a/kcontrol/hwmanager/hwdevicetray.cpp b/kcontrol/hwmanager/hwdevicetray.cpp
index 18ef3d5e9..f4576f061 100644
--- a/kcontrol/hwmanager/hwdevicetray.cpp
+++ b/kcontrol/hwmanager/hwdevicetray.cpp
@@ -37,6 +37,7 @@
#include <tdemessagebox.h>
#include <kpassivepopup.h>
#include <kstandarddirs.h>
+#include "passworddlg.h"
#include <dcopclient.h>
@@ -48,8 +49,8 @@
#include "hwdevicetray.h"
HwDeviceSystemTray::HwDeviceSystemTray(TQWidget* parent, const char *name)
- : KSystemTray(parent, name) {
-
+ : KSystemTray(parent, name), m_passDlg(NULL)
+{
// Create notifier
m_hardwareNotifierContainer = new TDEPassivePopupStackContainer();
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)));
- new TDEActionMenu(i18n("Open Device"), SmallIcon("connect_creating", TQIconSet::Automatic), actionCollection(), "mount_menu");
- new TDEActionMenu(i18n("Eject Device"), SmallIcon("connect_no", TQIconSet::Automatic), actionCollection(), "unmount_menu");
+ new TDEActionMenu(i18n("Mount"), SmallIcon("drive-harddisk-mounted", TQIconSet::Automatic), actionCollection(), "mount_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
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
@@ -86,8 +90,13 @@ HwDeviceSystemTray::HwDeviceSystemTray(TQWidget* parent, const char *name)
#endif
}
-HwDeviceSystemTray::~HwDeviceSystemTray() {
+HwDeviceSystemTray::~HwDeviceSystemTray()
+{
delete m_hardwareNotifierContainer;
+ if (m_passDlg)
+ {
+ delete m_passDlg;
+ }
}
/*!
@@ -143,43 +152,43 @@ void HwDeviceSystemTray::mousePressEvent(TQMouseEvent* e) {
bool HwDeviceSystemTray::isMonitoredDevice(TDEStorageDevice* sdevice) {
// Type selection logic largely duplicated from the media manager tdeioslave
- if (((sdevice->isDiskOfType(TDEDiskDeviceType::LUKS)
- || sdevice->checkDiskStatus(TDEDiskDeviceStatus::ContainsFilesystem)
- || sdevice->isDiskOfType(TDEDiskDeviceType::CDAudio)
- || sdevice->checkDiskStatus(TDEDiskDeviceStatus::Blank))
- && !sdevice->checkDiskStatus(TDEDiskDeviceStatus::UsedByDevice)
- && !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))) {
+ if ((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)))
+ {
return true;
}
else {
@@ -213,59 +222,133 @@ void HwDeviceSystemTray::configChanged() {
}
void HwDeviceSystemTray::populateMenu(TDEPopupMenu* menu) {
- int lastMountIndex;
- int lastUnmountIndex;
- TDEGenericDevice *hwdevice;
+ menu->insertTitle(SmallIcon("drive-harddisk-unmounted"), i18n("Storage Devices"));
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* 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();
- 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();
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);
- 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)));
- m_mountMenuIndexMap[lastMountIndex] = sdevice->diskUUID();
- if (m_mountMenuIndexMap[lastMountIndex] == "") {
- m_mountMenuIndexMap[lastMountIndex] = sdevice->systemPath();
+ if (isMonitoredDevice(sdevice))
+ {
+ if (sdevice->isDiskOfType(TDEDiskDeviceType::LUKS) || sdevice->isDiskOfType(TDEDiskDeviceType::OtherCrypted))
+ {
+ if (sdevice->isDiskOfType(TDEDiskDeviceType::UnlockedCrypt))
+ {
+ 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()));
- 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::Mountable))
+ {
+ if (sdevice->mountPath().isEmpty())
+ {
+ 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(false);
+ mountDiskActionMenu->setEnabled(lastMountIndex != -1);
+ unmountDiskActionMenu->setEnabled(lastUnmountIndex != -1);
+ unlockDiskActionMenu->setEnabled(lastUnlockIndex != -1);
+ lockDiskActionMenu->setEnabled(lastLockIndex != -1);
+ ejectDiskActionMenu->setEnabled(lastEjectIndex != -1);
+
+ if (lastMountIndex != -1)
+ {
+ mountDiskActionMenu->plug(menu);
}
- else {
- mountDiskActionMenu->setEnabled(true);
+ if (lastUnmountIndex != -1)
+ {
+ unmountDiskActionMenu->plug(menu);
}
- if (lastUnmountIndex == 0) {
- unmountDiskActionMenu->setEnabled(false);
+ if (lastUnlockIndex != -1)
+ {
+ unlockDiskActionMenu->plug(menu);
}
- else {
- unmountDiskActionMenu->setEnabled(true);
+ if (lastLockIndex != -1)
+ {
+ lockDiskActionMenu->plug(menu);
+ }
+ if (lastEjectIndex != -1)
+ {
+ ejectDiskActionMenu->plug(menu);
}
-
- mountDiskActionMenu->plug(menu);
- unmountDiskActionMenu->plug(menu);
}
void HwDeviceSystemTray::slotMountDevice(int parameter)
@@ -292,20 +375,26 @@ void HwDeviceSystemTray::slotMountDevice(int parameter)
void HwDeviceSystemTray::slotUnmountDevice(int parameter)
{
- TDEGenericDevice *hwdevice;
TQString uuid = m_unmountMenuIndexMap[parameter];
- if (uuid != "") {
+ if (uuid != "")
+ {
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
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);
- if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid)) {
- if (!sdevice->mountPath().isEmpty()) {
+ if ((sdevice->diskUUID() == uuid) || (sdevice->systemPath() == uuid))
+ {
+ if (!sdevice->mountPath().isEmpty())
+ {
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 retcodeStr = unmountResult.contains("retCode") ? unmountResult["retCode"].toString() : "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 retcodeStr = unmountResult.contains("retCode") ? unmountResult["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 unmount the device.</b>") + qerror + " (error code " +
+ retcodeStr + ").</qt>", i18n("Unmount failed"));
}
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() {
KCMultiDialog *kcm = new KCMultiDialog(KDialogBase::Plain, i18n("Configure"), this);
@@ -429,4 +631,4 @@ void HwDeviceSystemTray::slotHelpContents() {
kapp->invokeHelp(TQString::null, "hwdevicetray");
}
-#include "hwdevicetray.moc" \ No newline at end of file
+#include "hwdevicetray.moc"
diff --git a/kcontrol/hwmanager/hwdevicetray.h b/kcontrol/hwmanager/hwdevicetray.h
index d49f5b4b3..d207b430c 100644
--- a/kcontrol/hwmanager/hwdevicetray.h
+++ b/kcontrol/hwmanager/hwdevicetray.h
@@ -34,6 +34,7 @@
#endif
class KHelpMenu;
+class PasswordDlg;
class TDEPopupMenu;
typedef TQMap<int, TQString> TQStringMap;
@@ -59,6 +60,9 @@ protected slots:
void slotMountDevice(int parameter);
void slotUnmountDevice(int parameter);
+ void slotUnlockDevice(int parameter);
+ void slotLockDevice(int parameter);
+ void slotEjectDevice(int parameter);
protected:
void mousePressEvent(TQMouseEvent *e);
@@ -70,8 +74,8 @@ private slots:
void deviceAdded(TDEGenericDevice*);
void deviceRemoved(TDEGenericDevice*);
void deviceChanged(TDEGenericDevice*);
-
void devicePopupClicked(KPassivePopup*, TQPoint, TQString);
+ void doUnlockDisk();
private:
bool isMonitoredDevice(TDEStorageDevice* sdevice);
@@ -88,8 +92,12 @@ private:
TQStringMap m_mountMenuIndexMap;
TQStringMap m_unmountMenuIndexMap;
+ TQStringMap m_unlockMenuIndexMap;
+ TQStringMap m_lockMenuIndexMap;
+ TQStringMap m_ejectMenuIndexMap;
TDEPopupMenu* m_menu;
KSimpleConfig *r_config;
+ PasswordDlg *m_passDlg;
};
#endif
diff --git a/kcontrol/hwmanager/passworddlg.cpp b/kcontrol/hwmanager/passworddlg.cpp
index d9f1f54a6..07b6027ae 100644
--- a/kcontrol/hwmanager/passworddlg.cpp
+++ b/kcontrol/hwmanager/passworddlg.cpp
@@ -22,20 +22,14 @@
#include "passworddlg.h"
-PasswordDlg::PasswordDlg(TQString url, TQString iconName) :
- KDialogBase(NULL, "PasswordDlg", true, i18n("Unlock Storage Device"), (Cancel|User1), User1, false, KGuiItem(i18n("Unlock"), "unlocked" ))
+PasswordDlg::PasswordDlg() :
+ KDialogBase(NULL, "PasswordDlg", true, i18n("Unlock Storage Device"), (Cancel|User1),
+ User1, false, KGuiItem(i18n("Unlock"), "unlocked" ))
{
unlockDialog = new UnlockDialog(this);
-
- unlockDialog->descLabel->setText(unlockDialog->descLabel->text().arg(url));
- unlockDialog->descLabel->adjustSize();
- unlockDialog->adjustSize();
-
enableButton( User1, false );
-
- TQPixmap pixmap = TDEGlobal::iconLoader()->loadIcon(iconName, TDEIcon::NoGroup, TDEIcon::SizeLarge);
- unlockDialog->encryptedIcon->setPixmap( pixmap );
-
+ unlockDialog->encryptedIcon->setPixmap(TDEGlobal::iconLoader()->loadIcon("drive-harddisk-locked",
+ TDEIcon::NoGroup, TDEIcon::SizeLarge));
connect(unlockDialog->passwordEdit, TQT_SIGNAL (textChanged(const TQString &)), this, TQT_SLOT (slotPasswordChanged(const TQString &)));
setMainWidget(unlockDialog);
@@ -46,6 +40,19 @@ PasswordDlg::~PasswordDlg()
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()
{
return unlockDialog->passwordEdit->text();
diff --git a/kcontrol/hwmanager/passworddlg.h b/kcontrol/hwmanager/passworddlg.h
index 77ee06803..bee1431cc 100644
--- a/kcontrol/hwmanager/passworddlg.h
+++ b/kcontrol/hwmanager/passworddlg.h
@@ -42,11 +42,15 @@ class PasswordDlg : public KDialogBase
Q_OBJECT
public:
- PasswordDlg(TQString url, TQString iconName);
+ PasswordDlg();
~PasswordDlg();
+ void setDevice(TQString deviceName);
+ void clearPassword();
TQString getPassword();
+ int index;
+
public slots:
void slotPasswordChanged(const TQString &text);
diff --git a/kcontrol/hwmanager/unlockdialog.ui b/kcontrol/hwmanager/unlockdialog.ui
index 7b78cdb42..576de07a4 100644
--- a/kcontrol/hwmanager/unlockdialog.ui
+++ b/kcontrol/hwmanager/unlockdialog.ui
@@ -106,8 +106,7 @@
</sizepolicy>
</property>
<property name="text">
- <string>&lt;p&gt;&lt;b&gt;%1&lt;/b&gt; is an encrypted storage device.&lt;/p&gt;
-&lt;p&gt;Please enter the password to unlock the storage device.&lt;/p&gt;</string>
+ <string>Dummy placeholder</string>
</property>
<property name="alignment">
<set>WordBreak|AlignTop</set>