Commit 52ea204e authored by Méven Car's avatar Méven Car
Browse files

Replace the PasswordEdit field by a changePassword QPushButton, remove foreach uses

Summary:
BUG: 328664

The current behavior to change password is quite unfriendly to say the least.
Clicking in a line field to open a dialog is not logical.
Replace this with a much simpler button leading to the dialog.

Test Plan:
Compile
kcmshell5 user_manager
Tried changing your password
Tried adding a user

Before:
{F7269649}

After:

{F7269690}

Reviewers: #plasma, ngraham, davidedmundson, sitter, #vdg, GB_2

Reviewed By: #plasma, ngraham, davidedmundson, #vdg, GB_2

Subscribers: nicolasfella, GB_2, plasma-devel

Tags: #plasma, #vdg

Differential Revision: https://phabricator.kde.org/D23337
parent cc809e09
......@@ -6,7 +6,6 @@ set(user_manager_SRCS
accountinfo.cpp
createavatarjob.cpp
passworddialog.cpp
passwordedit.cpp
avatargallery.cpp
)
......
......@@ -210,21 +210,12 @@
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="passwordEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QPushButton" name="changePasswordButton">
<property name="text">
<string>MyPassword</string>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
<string>Change Password...</string>
</property>
<property name="placeholderText">
<string/>
<property name="icon">
<iconset theme="document-edit"/>
</property>
</widget>
</item>
......@@ -251,6 +242,7 @@
<tabstop>username</tabstop>
<tabstop>realName</tabstop>
<tabstop>email</tabstop>
<tabstop>changePasswordButton</tabstop>
<tabstop>administrator</tabstop>
<tabstop>automaticLogin</tabstop>
</tabstops>
......
......@@ -21,7 +21,6 @@
#include "createavatarjob.h"
#include "passworddialog.h"
#include "lib/accountmodel.h"
#include "passwordedit.h"
#include "avatargallery.h"
#include <pwd.h>
......@@ -39,25 +38,21 @@
#include <KIO/CopyJob>
#include <KIconLoader>
#include <KUser>
#include <KI18n/klocalizedstring.h>
AccountInfo::AccountInfo(AccountModel* model, QWidget* parent, Qt::WindowFlags f)
: QWidget(parent, f)
, m_info(new Ui::AccountInfo())
, m_model(model)
, m_passwordEdit(new PasswordEdit(this))
{
m_info->setupUi(this);
//If I remove this from the .ui file the layouting gets screwed...
m_info->formLayout->removeWidget(m_info->passwordEdit);
delete m_info->passwordEdit;
connect(m_info->username, &QLineEdit::textEdited, this, &AccountInfo::hasChanged);
connect(m_info->realName, &QLineEdit::textEdited, this, &AccountInfo::hasChanged);
connect(m_info->email, &QLineEdit::textEdited, this, &AccountInfo::hasChanged);
connect(m_info->administrator, &QAbstractButton::clicked, this, &AccountInfo::hasChanged);
connect(m_info->automaticLogin, &QAbstractButton::clicked, this, &AccountInfo::hasChanged);
connect(m_passwordEdit, &PasswordEdit::focused, this, &AccountInfo::changePassword);
connect(m_passwordEdit, &QLineEdit::textEdited, this, &AccountInfo::changePassword);
connect(m_info->changePasswordButton, &QPushButton::clicked, this, &AccountInfo::changePassword);
connect(m_model, &QAbstractItemModel::dataChanged, this, &AccountInfo::dataChanged);
m_info->face->setPopupMode(QToolButton::InstantPopup);
......@@ -90,18 +85,6 @@ AccountInfo::AccountInfo(AccountModel* model, QWidget* parent, Qt::WindowFlags f
m_info->realName->setMinimumWidth(size);
m_info->email->setMinimumWidth(size);
QWidget::setTabOrder(m_info->email, m_passwordEdit);
QWidget::setTabOrder(m_passwordEdit, m_info->administrator);
m_passwordEdit->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
m_passwordEdit->setMinimumWidth(size);
m_passwordEdit->setEchoMode(QLineEdit::Password);
int row;
QFormLayout::ItemRole role;
m_info->formLayout->getWidgetPosition(m_info->administrator, &row, &role);
m_info->formLayout->insertRow(row, m_info->label_3, m_passwordEdit);
int pixmapSize = m_info->username->sizeHint().height();
m_negative = QIcon::fromTheme(QStringLiteral("dialog-cancel")).pixmap(pixmapSize, pixmapSize);
}
......@@ -132,8 +115,10 @@ void AccountInfo::loadFromModel()
QString username = m_model->data(m_index, AccountModel::Username).toString();
if (!username.isEmpty()) {
m_info->username->setDisabled(true);//Do not allow to change the username
m_info->changePasswordButton->setText(i18nc("@label:button", "Change Password"));
} else {
m_info->username->setDisabled(false);
m_info->changePasswordButton->setText(i18nc("@label:button", "Set Password"));
}
m_info->username->setText(username);
......@@ -142,7 +127,6 @@ void AccountInfo::loadFromModel()
m_info->email->setText(m_model->data(m_index, AccountModel::Email).toString());
m_info->administrator->setChecked(m_model->data(m_index, AccountModel::Administrator).toBool());
m_info->automaticLogin->setChecked(m_model->data(m_index, AccountModel::AutomaticLogin).toBool());
m_passwordEdit->clear();
}
bool AccountInfo::save()
......@@ -312,7 +296,7 @@ bool AccountInfo::validateUsername(const QString &username) const
errorTooltip.append(QStringLiteral("\n"));
}
Q_FOREACH(const char c, userchar) {
for (const char c : userchar) {
valid = (
(c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
......@@ -414,7 +398,8 @@ void AccountInfo::openGallery()
QStringList AccountInfo::imageFormats() const
{
QStringList result;
for(const QByteArray &b: QImageReader::supportedMimeTypes()) {
const QList<QByteArray> supportedMimes = QImageReader::supportedMimeTypes();
for (const QByteArray &b: supportedMimes) {
if (! b.isEmpty())
result.append(QString::fromLatin1(b));
}
......@@ -480,6 +465,5 @@ void AccountInfo::changePassword()
}
m_infoToSave[AccountModel::Password] = dialog->password();
m_passwordEdit->setText(dialog->password());
Q_EMIT changed(true);
}
......@@ -23,6 +23,7 @@
#include <QWidget>
#include <QStringList>
#include <QPushButton>
#include "lib/accountmodel.h"
class KJob;
......@@ -70,7 +71,7 @@ class AccountInfo : public QWidget
QPixmap m_negative;
Ui::AccountInfo * m_info;
AccountModel* m_model;
PasswordEdit *m_passwordEdit;
QPushButton *m_changePasswordButton;
QModelIndex m_index;
QMap<AccountModel::Role, QVariant> m_infoToSave;
};
......
......@@ -52,9 +52,9 @@ AvatarGallery::AvatarGallery(QWidget *parent) : QDialog(parent)
}
const QString &systemFacesPath = locations.last() + QLatin1Char('/');
QDir avatarsDir(systemFacesPath);
const QDir avatarsDir(systemFacesPath);
foreach(const QString &avatarStyle, avatarsDir.entryList(QDir::Dirs | QDir::NoDotDot)) {
for (const QString &avatarStyle : avatarsDir.entryList(QDir::Dirs | QDir::NoDotDot)) {
QDir facesDir = (avatarsDir.filePath(avatarStyle));
const QStringList &avatarList = facesDir.entryList(QDir::Files);
for (auto it = avatarList.constBegin(), end = avatarList.constEnd(); it != end; ++it) {
......
......@@ -88,8 +88,8 @@ AccountModel::AccountModel(QObject* parent)
return;
}
QList<QDBusObjectPath> users = reply.value();
Q_FOREACH(const QDBusObjectPath& path, users) {
const QList<QDBusObjectPath> users = reply.value();
for (const QDBusObjectPath& path : users) {
addAccount(path.path());
}
......
......@@ -66,8 +66,8 @@ void UserSession::listUsersSlot(QDBusPendingCallWatcher *watcher)
if (reply.isError()) {
qCWarning(USER_MANAGER_LOG) << reply.error().name() << reply.error().message();
} else {
UserInfoList userList = reply.value();
Q_FOREACH(const UserInfo &userInfo, userList) {
const UserInfoList userList = reply.value();
for (const UserInfo &userInfo : userList) {
UserNew(userInfo.id);
}
}
......
/*************************************************************************************
* Copyright (C) 2013 by Alejandro Fiestas Olivares <afiestas@kde.org> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* 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 "passwordedit.h"
PasswordEdit::PasswordEdit(QWidget* parent) : QLineEdit(parent)
{
}
void PasswordEdit::focusInEvent(QFocusEvent* e)
{
QLineEdit::focusInEvent(e);
if (e->reason() != Qt::ActiveWindowFocusReason) {
Q_EMIT focused();
}
}
/*************************************************************************************
* Copyright (C) 2013 by Alejandro Fiestas Olivares <afiestas@kde.org> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* 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 PASSWORDEDIT_H
#define PASSWORDEDIT_H
#include <QLineEdit>
#include <QFocusEvent>
class PasswordEdit : public QLineEdit
{
Q_OBJECT
public:
explicit PasswordEdit(QWidget* parent = nullptr);
Q_SIGNALS:
void focused();
protected:
void focusInEvent(QFocusEvent* e) override;
};
#endif
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