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

Use new kpasswordlineedit

parent 3acfb2ce
cmake_minimum_required(VERSION 3.0)
set(PIM_VERSION "5.6.40")
set(PIM_VERSION "5.6.41")
project(MailTransport VERSION ${PIM_VERSION})
......
......@@ -7,7 +7,6 @@ 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
......
/*
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
......@@ -103,7 +103,7 @@
</widget>
</item>
<item row="3" column="1">
<widget class="MailTransport::LineEditPassword" name="password">
<widget class="KPasswordLineEdit" name="password">
</widget>
</item>
<item row="4" column="1">
......@@ -396,9 +396,9 @@
<header>klineedit.h</header>
</customwidget>
<customwidget>
<class>MailTransport::LineEditPassword</class>
<extends>QLineEdit</extends>
<header>lineeditpassword.h</header>
<class>KPasswordLineEdit</class>
<extends>QWidget</extends>
<header>kpasswordlineedit.h</header>
</customwidget>
</customwidgets>
<tabstops>
......
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