Commit c9c9f79f authored by Laurent Montel's avatar Laurent Montel 😁

Use LineEditPassword here

parent b849a8fd
......@@ -3,8 +3,9 @@ set(mailtransport_smtpplugin_SRCS
smtpconfigdialog.cpp
smtpjob.cpp
smtpconfigwidget.cpp
lineeditpassword.cpp
)
qt5_add_resources(mailtransport_smtpplugin_SRCS icons.qrc)
ki18n_wrap_ui(mailtransport_smtpplugin_SRCS
smtpsettings.ui
)
......
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>icons/visibility.svg</file>
<file>icons/hint.svg</file>
</qresource>
</RCC>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="16"
height="16"
id="svg3049"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="hint.svg"
inkscape:export-filename="/home/uri/.kde/share/icons/NITRUX-KDE/16x16/actions/view-right-new.png"
inkscape:export-xdpi="30"
inkscape:export-ydpi="30">
<defs
id="defs3051">
<linearGradient
gradientTransform="translate(0,-1.9999941)"
inkscape:collect="always"
xlink:href="#linearGradient4021-3"
id="linearGradient4123"
gradientUnits="userSpaceOnUse"
x1="3"
y1="1045.3622"
x2="15"
y2="1045.3622" />
<linearGradient
id="linearGradient4021-3">
<stop
id="stop4023-0"
offset="0"
style="stop-color:#b3b3b3;stop-opacity:1;" />
<stop
id="stop4025-2"
offset="1"
style="stop-color:#4d4d4d;stop-opacity:1;" />
</linearGradient>
<clipPath
id="clipPath4160"
clipPathUnits="userSpaceOnUse">
<rect
y="1023.3622"
x="7"
height="1"
width="1"
id="rect4162"
style="opacity:1;fill:#f2f2f2;fill-opacity:1;stroke:none;stroke-opacity:1" />
</clipPath>
<clipPath
id="clipPath4160-6"
clipPathUnits="userSpaceOnUse">
<rect
y="1023.3622"
x="7"
height="1"
width="1"
id="rect4162-4"
style="opacity:1;fill:#f2f2f2;fill-opacity:1;stroke:none;stroke-opacity:1" />
</clipPath>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="45.254834"
inkscape:cx="4.5612296"
inkscape:cy="8.1291941"
inkscape:document-units="px"
inkscape:current-layer="layer1-6"
showgrid="true"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="2560"
inkscape:window-height="1016"
inkscape:window-x="-4"
inkscape:window-y="35"
inkscape:window-maximized="1"
inkscape:showpageshadow="false"
borderlayer="true"
inkscape:snap-bbox="true"
inkscape:snap-global="true"
inkscape:object-nodes="true">
<inkscape:grid
type="xygrid"
id="grid4085" />
<sodipodi:guide
position="2.0000044,14.00003"
orientation="12,0"
id="guide4075" />
<sodipodi:guide
position="2.0000044,2.0000296"
orientation="0,12"
id="guide4077" />
<sodipodi:guide
position="14,9"
orientation="-12,0"
id="guide4079" />
<sodipodi:guide
position="14.000004,14.00003"
orientation="0,-12"
id="guide4081" />
</sodipodi:namedview>
<metadata
id="metadata3054">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Capa 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-421.71429,-531.79074)">
<g
transform="matrix(0.75,0,0,0.74999813,421.46429,-241.22897)"
id="layer1-0"
inkscape:label="Capa 1">
<g
transform="translate(6.2937501e-7,-2.041003e-4)"
id="layer1-6"
inkscape:label="Capa 1">
<path
style="opacity:1;fill:#4d4d4d;fill-opacity:1;stroke:none"
d="M 13.314453 2 L 2 13.294922 L 2.7148438 14 L 14 2.6972656 L 13.314453 2 z M 8 3 A 8.999992 9.0000024 0 0 0 0.12304688 7.6679688 C 0.25199189 8.0317035 0.48048562 8.3445563 0.77929688 8.5761719 A 7.999993 8.0000022 0 0 1 8 4 A 3.9999995 4.0000005 0 0 0 4 8 A 3.9999995 4.0000005 0 0 0 4.1054688 8.8945312 L 5 8 A 2.9999995 3.0000003 0 0 1 8 5 L 8.8925781 4.1074219 A 3.9999995 4.0000005 0 0 0 8.3496094 4.0175781 A 7.999993 8.0000022 0 0 1 8.9277344 4.0722656 L 9.8066406 3.1933594 A 8.999992 9.0000024 0 0 0 8 3 z M 13.835938 5.1640625 L 13.121094 5.8789062 A 7.999993 8.0000022 0 0 1 15.220703 8.5761719 C 15.522218 8.3424607 15.752612 8.0261216 15.880859 7.6582031 A 8.999992 9.0000024 0 0 0 13.835938 5.1640625 z M 11.894531 7.1054688 L 11 8 A 2.9999995 3.0000003 0 0 1 8 11 L 7.1074219 11.892578 A 3.9999995 4.0000005 0 0 0 8 12 A 3.9999995 4.0000005 0 0 0 12 8 A 3.9999995 4.0000005 0 0 0 11.894531 7.1054688 z "
transform="matrix(1.3333333,0,0,1.3333367,0.3333327,1030.6957)"
id="rect4170" />
</g>
</g>
</g>
</svg>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="16"
height="16"
id="svg3049"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="visibility.svg"
inkscape:export-filename="/home/uri/.kde/share/icons/NITRUX-KDE/16x16/actions/view-right-new.png"
inkscape:export-xdpi="30"
inkscape:export-ydpi="30">
<defs
id="defs3051">
<linearGradient
gradientTransform="translate(0,-1.9999941)"
inkscape:collect="always"
xlink:href="#linearGradient4021-3"
id="linearGradient4123"
gradientUnits="userSpaceOnUse"
x1="3"
y1="1045.3622"
x2="15"
y2="1045.3622" />
<linearGradient
id="linearGradient4021-3">
<stop
id="stop4023-0"
offset="0"
style="stop-color:#b3b3b3;stop-opacity:1;" />
<stop
id="stop4025-2"
offset="1"
style="stop-color:#4d4d4d;stop-opacity:1;" />
</linearGradient>
<clipPath
id="clipPath4160"
clipPathUnits="userSpaceOnUse">
<rect
y="1023.3622"
x="7"
height="1"
width="1"
id="rect4162"
style="opacity:1;fill:#f2f2f2;fill-opacity:1;stroke:none;stroke-opacity:1" />
</clipPath>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="45.254834"
inkscape:cx="10.140744"
inkscape:cy="6.8696601"
inkscape:document-units="px"
inkscape:current-layer="layer1-6"
showgrid="true"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="2560"
inkscape:window-height="1016"
inkscape:window-x="-4"
inkscape:window-y="35"
inkscape:window-maximized="1"
inkscape:showpageshadow="false"
borderlayer="true"
inkscape:snap-bbox="true"
inkscape:snap-global="true"
inkscape:object-nodes="true">
<inkscape:grid
type="xygrid"
id="grid4085" />
<sodipodi:guide
position="2.0000044,14.00003"
orientation="12,0"
id="guide4075" />
<sodipodi:guide
position="2.0000044,2.0000296"
orientation="0,12"
id="guide4077" />
<sodipodi:guide
position="14,9"
orientation="-12,0"
id="guide4079" />
<sodipodi:guide
position="14.000004,14.00003"
orientation="0,-12"
id="guide4081" />
</sodipodi:namedview>
<metadata
id="metadata3054">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Capa 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-421.71429,-531.79074)">
<g
transform="matrix(0.75,0,0,0.74999813,421.46429,-241.22897)"
id="layer1-0"
inkscape:label="Capa 1">
<g
transform="translate(6.2937501e-7,-2.041003e-4)"
id="layer1-6"
inkscape:label="Capa 1">
<path
style="opacity:1;fill:#4d4d4d;fill-opacity:1;stroke:none"
d="M 8 3 A 8.9999924 9.0000018 0 0 0 0.12304688 7.6679688 C 0.25199191 8.0317035 0.48048562 8.3445563 0.77929688 8.5761719 A 7.9999934 8.0000016 0 0 1 8 4 A 3.9999997 4.0000003 0 0 0 4 8 A 3.9999997 4.0000003 0 0 0 8 12 A 3.9999997 4.0000003 0 0 0 12 8 A 3.9999997 4.0000003 0 0 0 8.3496094 4.0175781 A 7.9999934 8.0000016 0 0 1 15.220703 8.5761719 C 15.522218 8.3424607 15.752612 8.0261216 15.880859 7.6582031 A 8.9999924 9.0000018 0 0 0 8 3 z M 8 5 A 2.9999997 3.0000001 0 0 1 11 8 A 2.9999997 3.0000001 0 0 1 8 11 A 2.9999997 3.0000001 0 0 1 5 8 A 2.9999997 3.0000001 0 0 1 8 5 z M 8 6 A 1.9999999 2.0000002 0 0 0 6 8 A 1.9999999 2.0000002 0 0 0 8 10 A 1.9999999 2.0000002 0 0 0 10 8 A 1.9999999 2.0000002 0 0 0 9.9101562 7.4121094 A 0.99999992 1 0 0 1 9 8 A 0.99999992 1 0 0 1 8 7 A 0.99999992 1 0 0 1 8.5898438 6.0898438 A 1.9999999 2.0000002 0 0 0 8 6 z "
transform="matrix(1.3333333,0,0,1.3333367,0.3333327,1030.6957)"
id="rect4170" />
</g>
</g>
</g>
</svg>
/*
Copyright (c) 2017 Montel Laurent <montel@kde.org>
based on lineedit in kpassworddialog.cpp
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "lineeditpassword.h"
#include <KLocalizedString>
#include <QIcon>
#include <QAction>
#include <QHBoxLayout>
#include <QLineEdit>
using namespace MailTransport;
LineEditPassword::LineEditPassword(QWidget *parent)
: QWidget(parent)
, mIsToggleEchoModeAvailable(true)
{
QHBoxLayout *mainLayout = new QHBoxLayout(this);
mainLayout->setObjectName(QStringLiteral("mainlayout"));
mainLayout->setMargin(0);
mPasswordLineEdit = new QLineEdit(this);
mPasswordLineEdit->setObjectName(QStringLiteral("passwordlineedit"));
mPasswordLineEdit->setEchoMode(QLineEdit::Password);
mainLayout->addWidget(mPasswordLineEdit);
initialize();
}
LineEditPassword::~LineEditPassword()
{
}
void LineEditPassword::initialize()
{
QIcon visibilityIcon = QIcon::fromTheme(QStringLiteral("visibility"), QIcon(QStringLiteral(":/icons/visibility.svg")));
mToggleEchoModeAction = mPasswordLineEdit->addAction(visibilityIcon, QLineEdit::TrailingPosition);
mToggleEchoModeAction->setObjectName(QStringLiteral("visibilityAction"));
mToggleEchoModeAction->setVisible(false);
mToggleEchoModeAction->setToolTip(i18n("Change the visibility of the password"));
connect(mToggleEchoModeAction, &QAction::triggered, this, &LineEditPassword::toggleEchoMode);
connect(mPasswordLineEdit, &QLineEdit::textChanged, this, &LineEditPassword::showToggleEchoModeAction);
}
void LineEditPassword::toggleEchoMode()
{
if (mPasswordLineEdit->echoMode() == QLineEdit::Password) {
mPasswordLineEdit->setEchoMode(QLineEdit::Normal);
mToggleEchoModeAction->setIcon(QIcon::fromTheme(QStringLiteral("hint"), QIcon(QStringLiteral(":/icons/hint.svg"))));
}
else if (mPasswordLineEdit->echoMode() == QLineEdit::Normal) {
mPasswordLineEdit->setEchoMode(QLineEdit::Password);
mToggleEchoModeAction->setIcon(QIcon::fromTheme(QStringLiteral("visibility"), QIcon(QStringLiteral(":/icons/visibility.svg"))));
}
}
void LineEditPassword::setPassword(const QString &p)
{
mIsToggleEchoModeAvailable = p.isEmpty();
mPasswordLineEdit->setText(p);
}
QString LineEditPassword::password() const
{
return mPasswordLineEdit->text();
}
void LineEditPassword::showToggleEchoModeAction(const QString &text)
{
mToggleEchoModeAction->setVisible(mIsToggleEchoModeAvailable && (mPasswordLineEdit->echoMode() == QLineEdit::Normal || !text.isEmpty()));
}
QAction *LineEditPassword::toggleEchoModeAction() const
{
return mToggleEchoModeAction;
}
/*
Copyright (c) 2017 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef LINEEDITPASSWORD_H
#define LINEEDITPASSWORD_H
#include <QWidget>
class QLineEdit;
class QAction;
namespace MailTransport
{
class LineEditPassword : public QWidget
{
public:
explicit LineEditPassword(QWidget *parent = nullptr);
~LineEditPassword();
void setPassword(const QString &p);
QString password() const;
QAction *toggleEchoModeAction() const;
private:
void initialize();
void toggleEchoMode();
void showToggleEchoModeAction(const QString &text);
QLineEdit *mPasswordLineEdit = nullptr;
QAction *mToggleEchoModeAction = nullptr;
bool mIsToggleEchoModeAvailable;
};
}
#endif // LINEEDITPASSWORD_H
......@@ -150,6 +150,9 @@ void SMTPConfigWidget::init()
d->manager->addWidget(this); // otherwise it doesn't find out about these widgets
d->manager->updateWidgets();
d->ui.password->setEnabled(false);
d->ui.password->setWhatsThis(i18n("The password to send to the server for authorization."));
d->encryptionGroup = new QButtonGroup(this);
d->encryptionGroup->addButton(d->ui.encryptionNone, Transport::EnumEncryption::None);
d->encryptionGroup->addButton(d->ui.encryptionSsl, Transport::EnumEncryption::SSL);
......@@ -180,7 +183,7 @@ void SMTPConfigWidget::init()
// load the password
d->transport->updatePasswordState();
if (d->transport->isComplete()) {
d->ui.password->setText(d->transport->password());
d->ui.password->setPassword(d->transport->password());
} else {
if (d->transport->requiresAuthentication()) {
TransportManager::self()->loadPasswordsAsync();
......@@ -224,7 +227,7 @@ void SMTPConfigWidget::apply()
Q_D(SMTPConfigWidget);
Q_ASSERT(d->manager);
d->manager->updateSettings();
d->transport->setPassword(d->ui.password->text());
d->transport->setPassword(d->ui.password->password());
KConfigGroup group(d->transport->config(), d->transport->currentGroup());
const int index = d->ui.authCombo->currentIndex();
......@@ -250,8 +253,8 @@ void SMTPConfigWidget::passwordsLoaded()
// Load the password from the original to our cloned copy
d->transport->updatePasswordState();
if (d->ui.password->text().isEmpty()) {
d->ui.password->setText(d->transport->password());
if (d->ui.password->password().isEmpty()) {
d->ui.password->setPassword(d->transport->password());
}
}
......
......@@ -103,19 +103,7 @@
</widget>
</item>
<item row="3" column="1">
<widget class="KLineEdit" name="password">
<property name="enabled">
<bool>false</bool>
</property>
<property name="whatsThis">
<string>The password to send to the server for authorization.</string>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="trapEnterKeyEvent" stdset="0">
<bool>true</bool>
</property>
<widget class="MailTransport::LineEditPassword" name="password">
</widget>
</item>
<item row="4" column="1">
......@@ -407,6 +395,11 @@
<extends>QLineEdit</extends>
<header>klineedit.h</header>
</customwidget>
<customwidget>
<class>MailTransport::LineEditPassword</class>
<extends>QLineEdit</extends>
<header>lineeditpassword.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>tabWidget</tabstop>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment