diff options
author | Michele Calgaro <[email protected]> | 2020-10-25 14:13:23 +0800 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2020-10-25 14:13:23 +0800 |
commit | 53f8622a6a4a47a49431bcbb4f63aa09220bb835 (patch) | |
tree | b5eac82f45f46fa4e76449780f4c33c9c418f688 | |
parent | 6b2d46a5486df6c4d15140c86bbe74e014d274ef (diff) | |
download | tdebase-53f8622a6a4a47a49431bcbb4f63aa09220bb835.tar.gz tdebase-53f8622a6a4a47a49431bcbb4f63aa09220bb835.zip |
tdehwmonitor: added Unlock/Lock buttons to LUKS disks.
Signed-off-by: Michele Calgaro <[email protected]>
-rw-r--r-- | kcontrol/hwmanager/CMakeLists.txt | 4 | ||||
-rw-r--r-- | kcontrol/hwmanager/devicepropsdlg.cpp | 97 | ||||
-rw-r--r-- | kcontrol/hwmanager/devicepropsdlg.h | 11 | ||||
-rw-r--r-- | kcontrol/hwmanager/devicepropsdlgbase.ui | 16 | ||||
-rw-r--r-- | kcontrol/hwmanager/passworddlg.cpp | 59 | ||||
-rw-r--r-- | kcontrol/hwmanager/passworddlg.h | 58 | ||||
-rw-r--r-- | kcontrol/hwmanager/unlockdialog.ui | 161 | ||||
-rw-r--r-- | tdeioslave/media/mounthelper/dialog.h | 2 | ||||
-rw-r--r-- | tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp | 9 | ||||
-rw-r--r-- | tdeioslave/media/mounthelper/tdeio_media_mounthelper.h | 6 |
10 files changed, 410 insertions, 13 deletions
diff --git a/kcontrol/hwmanager/CMakeLists.txt b/kcontrol/hwmanager/CMakeLists.txt index be8d3f2cb..bd06bd930 100644 --- a/kcontrol/hwmanager/CMakeLists.txt +++ b/kcontrol/hwmanager/CMakeLists.txt @@ -48,7 +48,7 @@ set_property( SOURCE hwmanager.cpp APPEND PROPERTY COMPILE_DEFINITIONS KDE_CONFD tde_add_kpart( kcm_hwmanager AUTOMOC SOURCES hwmanager.cpp deviceiconview.cpp devicepropsdlg.cpp devicepropsdlgbase.ui hwmanagerbase.ui - cryptpassworddlg.cpp cryptpassworddlgbase.ui hwmanager.skel + cryptpassworddlg.cpp unlockdialog.ui passworddlg.cpp cryptpassworddlgbase.ui hwmanager.skel LINK tdeio-shared DESTINATION ${PLUGIN_INSTALL_DIR} ) @@ -61,4 +61,4 @@ tde_add_executable( tdehwdevicetray AUTOMOC hwdevicetray_configdialog.cpp LINK tdeio-shared tdeutils-shared tdeui-shared DESTINATION ${BIN_INSTALL_DIR} -)
\ No newline at end of file +) diff --git a/kcontrol/hwmanager/devicepropsdlg.cpp b/kcontrol/hwmanager/devicepropsdlg.cpp index 05b5832fa..717a23942 100644 --- a/kcontrol/hwmanager/devicepropsdlg.cpp +++ b/kcontrol/hwmanager/devicepropsdlg.cpp @@ -29,6 +29,8 @@ #include <tqpainter.h> #include <tqstyle.h> #include <tqinternal_p.h> +#include <dcopclient.h> +#include <dcopref.h> #undef Unsorted // Required for --enable-final (tqdir.h) #include <tqfiledialog.h> @@ -45,6 +47,7 @@ #include <ksslcertificate.h> #include "cryptpassworddlg.h" +#include "passworddlg.h" #include "devicepropsdlg.h" @@ -250,7 +253,7 @@ void SensorDisplayWidget::updateDisplay() { } DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidget *parent) - : KDialogBase(Plain, TQString::null, Ok|Cancel, Ok, parent, 0L, true, true) + : KDialogBase(Plain, TQString::null, Ok|Cancel, Ok, parent, 0L, true, true), m_passDlg(NULL) { m_device = device; enableButtonOK( false ); @@ -301,6 +304,8 @@ DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidge 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())); 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())); @@ -345,6 +350,10 @@ DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidge DevicePropertiesDialog::~DevicePropertiesDialog() { + if (m_passDlg) + { + delete m_passDlg; + } } void DevicePropertiesDialog::processHardwareRemoved(TDEGenericDevice* dev) { @@ -450,16 +459,32 @@ void DevicePropertiesDialog::populateDeviceInformation() { status_text += "Hidden<br>"; } if (status_text == "<qt>") { - status_text += "<i>Unavailable</i>"; + status_text += "<i>Unknown</i>"; } status_text += "</qt>"; base->labelDiskStatus->setText(status_text); // Update mount/unmount button status + base->buttonDiskMount->setEnabled(false); + base->buttonDiskUnmount->setEnabled(false); + base->buttonDiskUnlock->setEnabled(false); + base->buttonDiskLock->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->buttonDiskMount->setEnabled((sdevice->mountPath() == "")); base->buttonDiskUnmount->setEnabled((sdevice->mountPath() != "")); + base->buttonDiskMount->setHidden(false); + base->buttonDiskUnmount->setHidden(false); + } + else if (sdevice->isDiskOfType(TDEDiskDeviceType::LUKS)) { + base->buttonDiskUnlock->setEnabled(!sdevice->isDiskOfType(TDEDiskDeviceType::UnlockedCrypt)); + base->buttonDiskLock->setEnabled(sdevice->isDiskOfType(TDEDiskDeviceType::UnlockedCrypt)); + base->buttonDiskUnlock->setHidden(false); + base->buttonDiskLock->setHidden(false); } else { base->groupDiskActions->hide(); @@ -928,6 +953,74 @@ void DevicePropertiesDialog::unmountDisk() { populateDeviceInformation(); } +void DevicePropertiesDialog::unlockDisk() { + TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); + + if (!m_passDlg) + { + m_passDlg = new PasswordDlg(sdevice->deviceNode(), "drive-harddisk-locked"); + connect(m_passDlg, TQT_SIGNAL(user1Clicked()), this, TQT_SLOT(doUnlockDisk())); + } + m_passDlg->show(); +} + +void DevicePropertiesDialog::doUnlockDisk() { + 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 + 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.install>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)); + } + qerror.append("</qt>"); + } + else { + m_passDlg->hide(); + qerror = ""; + } + + if (qerror != "") KMessageBox::error(this, qerror, i18n("Unlock Failed")); + + populateDeviceInformation(); +} + +void DevicePropertiesDialog::lockDisk() { + 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 + 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) { + // 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>"); + } + + if (qerror != "") KMessageBox::error(this, qerror, i18n("Lock Failed")); + + populateDeviceInformation(); +} + void DevicePropertiesDialog::cryptLUKSAddKey() { int retcode; diff --git a/kcontrol/hwmanager/devicepropsdlg.h b/kcontrol/hwmanager/devicepropsdlg.h index e958d39ba..50fd1cac1 100644 --- a/kcontrol/hwmanager/devicepropsdlg.h +++ b/kcontrol/hwmanager/devicepropsdlg.h @@ -20,13 +20,13 @@ #define __devicepropsdlg_h__ #include <tqprogressbar.h> - #include <kdialogbase.h> - #include <tdehardwaredevices.h> #include "devicepropsdlgbase.h" +class PasswordDlg; + /** * * Simple sensor name and text label value display widget @@ -190,6 +190,9 @@ private slots: void mountDisk(); void unmountDisk(); + void unlockDisk(); + void doUnlockDisk(); + void lockDisk(); void cryptLUKSAddKey(); void cryptLUKSDelKey(); @@ -204,9 +207,7 @@ private slots: private: TDEGenericDevice* m_device; DevicePropertiesDialogBase* base; - - class DevicePropertiesDialogPrivate; - DevicePropertiesDialogPrivate* d; + PasswordDlg *m_passDlg; TQGridLayout* m_sensorDataGrid; SensorDisplayWidgetList m_sensorDataGridWidgets; diff --git a/kcontrol/hwmanager/devicepropsdlgbase.ui b/kcontrol/hwmanager/devicepropsdlgbase.ui index b6c53c331..b5ffe362d 100644 --- a/kcontrol/hwmanager/devicepropsdlgbase.ui +++ b/kcontrol/hwmanager/devicepropsdlgbase.ui @@ -355,6 +355,22 @@ <string>Unmount</string> </property> </widget> + <widget class="KPushButton" row="0" column="0" colspan="1"> + <property name="name"> + <cstring>buttonDiskUnlock</cstring> + </property> + <property name="text"> + <string>Unlock</string> + </property> + </widget> + <widget class="KPushButton" row="0" column="1" colspan="1"> + <property name="name"> + <cstring>buttonDiskLock</cstring> + </property> + <property name="text"> + <string>Lock</string> + </property> + </widget> </grid> </widget> <spacer row="8" column="0"> diff --git a/kcontrol/hwmanager/passworddlg.cpp b/kcontrol/hwmanager/passworddlg.cpp new file mode 100644 index 000000000..d9f1f54a6 --- /dev/null +++ b/kcontrol/hwmanager/passworddlg.cpp @@ -0,0 +1,59 @@ +/* This file is part of the KDE project + * Copyright (C) 2007 Jan Klötzke <jan kloetzke at freenet de> + * + * Based on kryptomedia- Another KDE cryto media application. + * Copyright (C) 2006 Daniel Gollub <[email protected]> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#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" )) +{ + 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 ); + + connect(unlockDialog->passwordEdit, TQT_SIGNAL (textChanged(const TQString &)), this, TQT_SLOT (slotPasswordChanged(const TQString &))); + + setMainWidget(unlockDialog); +} + +PasswordDlg::~PasswordDlg() +{ + delete unlockDialog; +} + +TQString PasswordDlg::getPassword() +{ + return unlockDialog->passwordEdit->text(); +} + +void PasswordDlg::slotPasswordChanged(const TQString &text) +{ + enableButton( User1, !text.isEmpty() ); +} + +#include "passworddlg.moc" diff --git a/kcontrol/hwmanager/passworddlg.h b/kcontrol/hwmanager/passworddlg.h new file mode 100644 index 000000000..77ee06803 --- /dev/null +++ b/kcontrol/hwmanager/passworddlg.h @@ -0,0 +1,58 @@ +/* This file is part of the KDE project + * Copyright (C) 2007 Jan Klötzke <jan kloetzke at freenet de> + * + * Based on kryptomedia- Another KDE cryto media application. + * Copyright (C) 2006 Daniel Gollub <[email protected]> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef DIALOG_H_ +#define DIALOG_H_ + +#include <tdemessagebox.h> +#include <tdelocale.h> +#include <tdeconfig.h> +#include <kdebug.h> +#include <kdialogbase.h> +#include <kiconloader.h> + +#include <tqlineedit.h> +#include <tqlabel.h> +#include <tqgroupbox.h> + +#include "unlockdialog.h" + +class PasswordDlg : public KDialogBase +{ + + Q_OBJECT + +public: + PasswordDlg(TQString url, TQString iconName); + ~PasswordDlg(); + + TQString getPassword(); + +public slots: + void slotPasswordChanged(const TQString &text); + +private: + UnlockDialog *unlockDialog; +}; + +#endif // DIALOG_H_ + diff --git a/kcontrol/hwmanager/unlockdialog.ui b/kcontrol/hwmanager/unlockdialog.ui new file mode 100644 index 000000000..7b78cdb42 --- /dev/null +++ b/kcontrol/hwmanager/unlockdialog.ui @@ -0,0 +1,161 @@ +<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> +<class>UnlockDialog</class> +<widget class="TQWidget"> + <property name="name"> + <cstring>UnlockDialog</cstring> + </property> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>207</width> + <height>172</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>3</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="caption"> + <string>Decrypting Storage Device</string> + </property> + <grid> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQLayoutWidget" row="0" column="0"> + <property name="name"> + <cstring>layout5</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQLayoutWidget"> + <property name="name"> + <cstring>layout4</cstring> + </property> + <vbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQLabel"> + <property name="name"> + <cstring>encryptedIcon</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>0</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>48</width> + <height>48</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>32</width> + <height>32</height> + </size> + </property> + <property name="scaledContents"> + <bool>true</bool> + </property> + <property name="alignment"> + <set>AlignTop</set> + </property> + </widget> + <spacer> + <property name="name"> + <cstring>spacer2_2</cstring> + </property> + <property name="orientation"> + <enum>Vertical</enum> + </property> + <property name="sizeType"> + <enum>Expanding</enum> + </property> + <property name="sizeHint"> + <size> + <width>31</width> + <height>41</height> + </size> + </property> + </spacer> + </vbox> + </widget> + <widget class="TQLabel"> + <property name="name"> + <cstring>descLabel</cstring> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>3</hsizetype> + <vsizetype>3</vsizetype> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string><p><b>%1</b> is an encrypted storage device.</p> +<p>Please enter the password to unlock the storage device.</p></string> + </property> + <property name="alignment"> + <set>WordBreak|AlignTop</set> + </property> + </widget> + </hbox> + </widget> + <widget class="TQLayoutWidget" row="1" column="0"> + <property name="name"> + <cstring>layout4</cstring> + </property> + <hbox> + <property name="name"> + <cstring>unnamed</cstring> + </property> + <widget class="TQLabel"> + <property name="name"> + <cstring>textLabel1</cstring> + </property> + <property name="text"> + <string>&Password:</string> + </property> + <property name="buddy" stdset="0"> + <cstring>passwordEdit</cstring> + </property> + </widget> + <widget class="TQLineEdit"> + <property name="name"> + <cstring>passwordEdit</cstring> + </property> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="sizePolicy"> + <sizepolicy> + <hsizetype>5</hsizetype> + <vsizetype>0</vsizetype> + <horstretch>1</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="echoMode"> + <enum>Password</enum> + </property> + </widget> + </hbox> + </widget> + </grid> +</widget> +<layoutdefaults spacing="6" margin="11"/> +</UI> diff --git a/tdeioslave/media/mounthelper/dialog.h b/tdeioslave/media/mounthelper/dialog.h index e704e5777..a80a9c69a 100644 --- a/tdeioslave/media/mounthelper/dialog.h +++ b/tdeioslave/media/mounthelper/dialog.h @@ -36,8 +36,6 @@ #include "unlockdialog.h" -class KryptoMedia; - class Dialog : public KDialogBase { diff --git a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp index 70f49d9ac..9d3da6d08 100644 --- a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp +++ b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.cpp @@ -25,7 +25,6 @@ #include <kurl.h> #include <tdemessagebox.h> #include <dcopclient.h> -#include <dcopref.h> #include <tqtimer.h> #include <stdlib.h> #include <kdebug.h> @@ -345,6 +344,14 @@ MountHelper::MountHelper() : TDEApplication(), m_mediamanager("kded", "mediamana } } +MountHelper::~MountHelper() +{ + if (m_dialog) + { + delete m_dialog; + } +} + void MountHelper::ejectFinished(TDEProcess *proc) { //If eject failed, report the error stored in m_errorStr diff --git a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h index 916cf3d30..59dba6e5a 100644 --- a/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h +++ b/tdeioslave/media/mounthelper/tdeio_media_mounthelper.h @@ -25,16 +25,20 @@ #include <tdeapplication.h> #include <tqstring.h> #include <tdeio/job.h> +#include <dcopref.h> #include "medium.h" class Dialog; +class TDEProcess; class MountHelper : public TDEApplication { - Q_OBJECT + Q_OBJECT + public: MountHelper(); + ~MountHelper(); private: TQString m_errorStr; |