From 5dc25e37f7b4e1001b111c03a9ed0d7146c401c3 Mon Sep 17 00:00:00 2001 From: Phenom Date: Wed, 19 Jul 2017 19:39:21 +0200 Subject: [PATCH] Fix Ask Password in new window if wrong in StartDialog. And Fix LineEditClear to show placeholder test even if it has focus (Like Qt5). --- libretroshare/src/pqi/p3notify.cc | 11 ++++-- libretroshare/src/pqi/p3notify.h | 11 +++--- libretroshare/src/retroshare/rsnotify.h | 6 ++-- retroshare-gui/src/gui/StartDialog.cpp | 34 +++++++++++++------ retroshare-gui/src/gui/StartDialog.ui | 9 ++++- .../src/gui/common/LineEditClear.cpp | 20 +++++++---- retroshare-gui/src/gui/common/LineEditClear.h | 9 +++-- 7 files changed, 71 insertions(+), 29 deletions(-) diff --git a/libretroshare/src/pqi/p3notify.cc b/libretroshare/src/pqi/p3notify.cc index 9eb4b1bfd..43caf9758 100644 --- a/libretroshare/src/pqi/p3notify.cc +++ b/libretroshare/src/pqi/p3notify.cc @@ -267,6 +267,12 @@ bool p3Notify::clearPgpPassphrase() return true ; } +bool p3Notify::setDisableAskPassword(const bool bValue) +{ + _disableAskPassword = bValue; + return true; +} + bool p3Notify::askForPassword (const std::string& title , const std::string& key_details , bool prev_is_bad , std::string& password,bool *cancelled) { if(!prev_is_bad && !cached_pgp_passphrase.empty()) @@ -278,8 +284,9 @@ bool p3Notify::askForPassword (const std::string& title , c } FOR_ALL_NOTIFY_CLIENTS - if( (*it)->askForPassword(title,key_details,prev_is_bad,password,*cancelled)) - return true ; + if (!_disableAskPassword) + if( (*it)->askForPassword(title,key_details,prev_is_bad,password,*cancelled) ) + return true; return false ; } diff --git a/libretroshare/src/pqi/p3notify.h b/libretroshare/src/pqi/p3notify.h index c31a95eea..820c4a6bb 100644 --- a/libretroshare/src/pqi/p3notify.h +++ b/libretroshare/src/pqi/p3notify.h @@ -66,7 +66,7 @@ class p3Notify: public RsNotify { public: - p3Notify() : noteMtx("p3Notify") { return; } + p3Notify() : noteMtx("p3Notify"), _disableAskPassword(false) { return; } virtual ~p3Notify() { return; } virtual void registerNotifyClient(NotifyClient *nc) ; @@ -125,8 +125,10 @@ class p3Notify: public RsNotify bool askForPassword (const std::string& title, const std::string& /* key_details */, bool /* prev_is_bad */, std::string&, bool *cancelled /* password */ ) ; bool askForPluginConfirmation (const std::string& /* plugin_filename */, const std::string& /* plugin_file_hash */,bool first_time) ; - virtual bool cachePgpPassphrase (const std::string& /* pgp_passphrase */) ; - virtual bool clearPgpPassphrase () ; + virtual bool cachePgpPassphrase (const std::string& /* pgp_passphrase */) ; + virtual bool clearPgpPassphrase () ; + + virtual bool setDisableAskPassword (const bool /*bValue*/) ; private: @@ -139,7 +141,8 @@ class p3Notify: public RsNotify std::list notifyClients ; - std::string cached_pgp_passphrase ; + std::string cached_pgp_passphrase; + bool _disableAskPassword; }; diff --git a/libretroshare/src/retroshare/rsnotify.h b/libretroshare/src/retroshare/rsnotify.h index 8b636c77f..b73c577e9 100644 --- a/libretroshare/src/retroshare/rsnotify.h +++ b/libretroshare/src/retroshare/rsnotify.h @@ -205,8 +205,10 @@ class RsNotify virtual bool GetFeedItem(RsFeedItem &item) = 0; - virtual bool cachePgpPassphrase (const std::string& /* pgp_passphrase */) { return false ; } - virtual bool clearPgpPassphrase () { return false ; } + virtual bool cachePgpPassphrase (const std::string& /* pgp_passphrase */) { return false ; } + virtual bool clearPgpPassphrase () { return false ; } + + virtual bool setDisableAskPassword (const bool /*bValue*/) { return false ; } }; class NotifyClient diff --git a/retroshare-gui/src/gui/StartDialog.cpp b/retroshare-gui/src/gui/StartDialog.cpp index 27853c3e6..63b3df203 100644 --- a/retroshare-gui/src/gui/StartDialog.cpp +++ b/retroshare-gui/src/gui/StartDialog.cpp @@ -19,15 +19,18 @@ * Boston, MA 02110-1301, USA. ****************************************************************/ -#include - -#include "rshare.h" -#include "retroshare/rsinit.h" #include "StartDialog.h" + #include "LogoBar.h" -#include "retroshare/rsnotify.h" +#include "rshare.h" #include "settings/rsharesettings.h" +#include "retroshare/rsinit.h" +#include "retroshare/rsnotify.h" + +#include +#include + #include /** Default constructor */ @@ -74,7 +77,7 @@ StartDialog::StartDialog(QWidget *parent) } QObject::connect(ui.loadName,SIGNAL(currentIndexChanged(int)),this,SLOT(updateSelectedProfile(int))) ; - QObject::connect(ui.password_input,SIGNAL(returnPressed()),this,SLOT(loadPerson())) ; + //QObject::connect(ui.password_input,SIGNAL(returnPressed()),this,SLOT(loadPerson())) ;//Already called by StartDialog.returnPressed->loadButton.clicked QObject::connect(ui.loadButton, SIGNAL(clicked()), this, SLOT(loadPerson())); if (pidx > 0) @@ -87,8 +90,9 @@ StartDialog::StartDialog(QWidget *parent) void StartDialog::updateSelectedProfile(int) { - ui.password_input->clear(); - ui.password_input->setFocus(); + ui.password_input->clear(); + ui.password_input->setPlaceholderText(tr("Password")); + ui.password_input->setFocus(); } void StartDialog::closeEvent (QCloseEvent * event) @@ -111,14 +115,22 @@ void StartDialog::loadPerson() QVariant data = ui.loadName->itemData(pgpidx); RsPeerId accountId = RsPeerId((data.toString()).toStdString()); - // Cache the passphrase, so that it is not asked again. - + // Cache the passphrase, so that it is not asked again. rsNotify->cachePgpPassphrase(ui.password_input->text().toUtf8().constData()) ; + rsNotify->setDisableAskPassword(true); bool res = Rshare::loadCertificate(accountId, ui.autologin_checkbox->isChecked()) ; - if(res) + rsNotify->setDisableAskPassword(false); + + if(res) accept(); + else + { + ui.password_input->setPlaceholderText(tr("Wrong password")); + ui.password_input->setText(""); + ui.password_input->setFocus(); + } } void StartDialog::on_labelProfile_linkActivated(QString /*link*/) diff --git a/retroshare-gui/src/gui/StartDialog.ui b/retroshare-gui/src/gui/StartDialog.ui index 63356ac08..a49d51e9b 100644 --- a/retroshare-gui/src/gui/StartDialog.ui +++ b/retroshare-gui/src/gui/StartDialog.ui @@ -274,7 +274,7 @@ - + QLineEdit::Password @@ -360,4 +360,11 @@ p, li { white-space: pre-wrap; } + + + LineEditClear + QLineEdit +
gui/common/LineEditClear.h
+
+
diff --git a/retroshare-gui/src/gui/common/LineEditClear.cpp b/retroshare-gui/src/gui/common/LineEditClear.cpp index daf97d600..3871b17ea 100644 --- a/retroshare-gui/src/gui/common/LineEditClear.cpp +++ b/retroshare-gui/src/gui/common/LineEditClear.cpp @@ -25,7 +25,8 @@ #include #include #include -#if QT_VERSION < 0x040700 +//#if QT_VERSION < 0x040700 +#if QT_VERSION < 0x050000//PlaceHolder text only shown when not have focus in Qt4 #include #endif @@ -52,7 +53,8 @@ LineEditClear::LineEditClear(QWidget *parent) connect(mClearButton, SIGNAL(clicked()), this, SLOT(clear())); connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateClearButton(const QString&))); -#if QT_VERSION < 0x040700 +//#if QT_VERSION < 0x040700 +#if QT_VERSION < 0x050000//PlaceHolder text only shown when not have focus in Qt4 mFilterLabel = new QLabel("", this); mFilterLabel->setStyleSheet("QLabel { color: gray; }"); #endif @@ -72,15 +74,17 @@ void LineEditClear::resizeEvent(QResizeEvent *) int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); mClearButton->move(rect().right() - frameWidth - sz.width() + 2, (rect().bottom() - sz.height()) / 2 + 2); -#if QT_VERSION < 0x040700 +//#if QT_VERSION < 0x040700 +#if QT_VERSION < 0x050000//PlaceHolder text only shown when not have focus in Qt4 sz = mFilterLabel->sizeHint(); - mFilterLabel->move(frameWidth + (mFilterButton ? mFilterButton->sizeHint().width() + 5 : 0), (rect().bottom() + 1 - sz.height())/2); + mFilterLabel->move(frameWidth + (mFilterButton ? mFilterButton->sizeHint().width() + 5 : 5), (rect().bottom() + 1 - sz.height())/2); #endif } void LineEditClear::setPlaceholderText(const QString &text) { -#if QT_VERSION < 0x040700 +//#if QT_VERSION < 0x040700 +#if QT_VERSION < 0x050000//PlaceHolder text only shown when not have focus in Qt4 mFilterLabel->setText(text); #else QLineEdit::setPlaceholderText(text); @@ -89,7 +93,8 @@ void LineEditClear::setPlaceholderText(const QString &text) setToolTip(text); } -#if QT_VERSION < 0x040700 +//#if QT_VERSION < 0x040700 +#if 0//PlaceHolder text only shown when not have focus in Qt4 void LineEditClear::focusInEvent(QFocusEvent *event) { mFilterLabel->setVisible(false); @@ -137,6 +142,9 @@ void LineEditClear::showFilterIcon() void LineEditClear::updateClearButton(const QString& text) { mClearButton->setVisible(!text.isEmpty()); +#if QT_VERSION < 0x050000//PlaceHolder text only shown when not have focus in Qt4 + mFilterLabel->setVisible(text.isEmpty()); +#endif } void LineEditClear::addFilter(const QIcon &icon, const QString &text, int id, const QString &description) diff --git a/retroshare-gui/src/gui/common/LineEditClear.h b/retroshare-gui/src/gui/common/LineEditClear.h index 98b1b69e0..7e5a5db5c 100644 --- a/retroshare-gui/src/gui/common/LineEditClear.h +++ b/retroshare-gui/src/gui/common/LineEditClear.h @@ -28,7 +28,8 @@ class QToolButton; class QActionGroup; -#if QT_VERSION < 0x040700 +//#if QT_VERSION < 0x040700 +#if QT_VERSION < 0x050000//PlaceHolder text only shown when not have focus in Qt4 class QLabel; #endif @@ -55,7 +56,8 @@ signals: protected: void resizeEvent(QResizeEvent *); -#if QT_VERSION < 0x040700 +//#if QT_VERSION < 0x040700 +#if 0//PlaceHolder text only shown when not have focus in Qt4 void focusInEvent(QFocusEvent *event); void focusOutEvent(QFocusEvent *event); #endif @@ -72,7 +74,8 @@ private: QActionGroup *mActionGroup; QMap mDescription; -#if QT_VERSION < 0x040700 +//#if QT_VERSION < 0x040700 +#if QT_VERSION < 0x050000//PlaceHolder text only shown when not have focus in Qt4 QLabel *mFilterLabel; #endif };