Skip to content

Commit

Permalink
Enhance: add option to reveal password temporarily on demand (Mudlet#…
Browse files Browse the repository at this point in the history
…3040)

This is an edited summary for a collection of 5 commits:
* Enhance: add option to reveal password temporarily on demand

This will show the password when the eye icon is clicked on until
a different profile is selected or it is clicked a second time.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>

Also rename the icon used when the password is hidden as it is a modified
version (of an oxygen theme one) so it is not wise to use the original
name.

Refactored to remove an unneeded new slot that can be done without;
by restructuring things I did not need to have a second slot just to hide
the password when the user changed selected profile - it was needed when
a Timer was used to automatically hide the password but in its absence
a direct call to the other new slot and a fixed argument - is sufficient.

Revised to switch to using icons from theme for show/hide password

And provide some `.png` icons if they are not in the current desktop theme
(on Linux/FreeBSD) or the OS does not provide such a system for them...

These icons were created by myself and I will licensing them under GPL 2.0
(or later terms).

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
  • Loading branch information
SlySven authored Sep 20, 2019
1 parent e633c31 commit 2af565e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/dlgConnectionProfiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ dlgConnectionProfiles::dlgConnectionProfiles(QWidget * parent)

welcome_message->setDocument(pWelcome_document);

mpAction_revealPassword = new QAction(this);
mpAction_revealPassword->setCheckable(true);
mpAction_revealPassword->setObjectName(QStringLiteral("mpAction_revealPassword"));
slot_togglePasswordVisibility(false);

character_password_entry->addAction(mpAction_revealPassword, QLineEdit::TrailingPosition);

connect(mpAction_revealPassword, &QAction::triggered, this, &dlgConnectionProfiles::slot_togglePasswordVisibility);
connect(offline_button, &QAbstractButton::clicked, this, &dlgConnectionProfiles::slot_load);
connect(connect_button, &QAbstractButton::clicked, this, &dlgConnectionProfiles::accept);
connect(abort, &QAbstractButton::clicked, this, &dlgConnectionProfiles::slot_cancel);
Expand Down Expand Up @@ -804,6 +812,7 @@ void dlgConnectionProfiles::slot_item_clicked(QListWidgetItem* pItem)
return;
}

slot_togglePasswordVisibility(false);

QString profile_name = pItem->text();

Expand Down Expand Up @@ -1219,7 +1228,8 @@ void dlgConnectionProfiles::updateDiscordStatus()
}

// (re-)creates the dialogs profile list
void dlgConnectionProfiles::fillout_form() {
void dlgConnectionProfiles::fillout_form()
{
profiles_tree_widget->clear();
profile_name_entry->clear();
host_name_entry->clear();
Expand Down Expand Up @@ -2384,3 +2394,28 @@ void dlgConnectionProfiles::copyFolder(const QString& sourceFolder, const QStrin
copyFolder(srcName, destName);
}
}

// As it is wired to the triggered() signal it is only called that way when
// the user clicks on the action, and not when setChecked() is used.
void dlgConnectionProfiles::slot_togglePasswordVisibility(const bool showPassword)
{
if (mpAction_revealPassword->isChecked() != showPassword) {
// This will only be reached and needed by a call NOT prompted by the
// user clicking on the icon - i.e. either when a different profile is
// selected or when called from the constructor:
mpAction_revealPassword->setChecked(showPassword);
}

if (mpAction_revealPassword->isChecked()) {
character_password_entry->setEchoMode(QLineEdit::Normal);
// In practice I could not get the icon to change based upon supplying
// different QPixmaps for the QIcon for different states - so lets do it
// directly:
mpAction_revealPassword->setIcon(QIcon::fromTheme(QStringLiteral("password-show-on"), QIcon(QStringLiteral(":/icons/password-show-on.png"))));
mpAction_revealPassword->setToolTip(tr("<p>Click to hide the password; it will also hide if another profile is selected.</p>"));
} else {
character_password_entry->setEchoMode(QLineEdit::Password);
mpAction_revealPassword->setIcon(QIcon::fromTheme(QStringLiteral("password-show-off"), QIcon(QStringLiteral(":/icons/password-show-off.png"))));
mpAction_revealPassword->setToolTip(tr("<p>Click to reveal the password for this profile.</p>"));
}
}
3 changes: 3 additions & 0 deletions src/dlgConnectionProfiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,14 @@ public slots:
QPushButton* delete_button;
QString mDiscordApplicationId;
const QStringList mDefaultGames;
QAction* mpAction_revealPassword;


private slots:
void slot_profile_menu(QPoint pos);
void slot_set_custom_icon();
void slot_reset_custom_icon();
void slot_togglePasswordVisibility(const bool);
void slot_password_saved(QKeychain::Job* job);
void slot_password_deleted(QKeychain::Job* job);
};
Expand Down
Binary file added src/icons/password-show-off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/icons/password-show-on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/mudlet.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@
<file>icons/offsettimer-on.png</file>
<file>icons/package-manager.png</file>
<file>icons/package-exporter.png</file>
<file>icons/password-show-off.png</file>
<file>icons/password-show-on.png</file>
<file>icons/Patreon_Mark_Primary.png</file>
<file>icons/place_of_interest.png</file>
<file>icons/preferences-desktop-keyboard.png</file>
Expand Down

0 comments on commit 2af565e

Please sign in to comment.