Merge pull request #953 from PhenomRetroShare/Fix_NewWindowForPassword

Fix Ask Password in new window if wrong in StartDialog.
This commit is contained in:
csoler 2017-07-30 21:29:14 +02:00 committed by GitHub
commit 2588068775
7 changed files with 71 additions and 29 deletions

View File

@ -267,6 +267,12 @@ bool p3Notify::clearPgpPassphrase()
return true ; 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) 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()) if(!prev_is_bad && !cached_pgp_passphrase.empty())
@ -278,8 +284,9 @@ bool p3Notify::askForPassword (const std::string& title , c
} }
FOR_ALL_NOTIFY_CLIENTS FOR_ALL_NOTIFY_CLIENTS
if( (*it)->askForPassword(title,key_details,prev_is_bad,password,*cancelled)) if (!_disableAskPassword)
return true ; if( (*it)->askForPassword(title,key_details,prev_is_bad,password,*cancelled) )
return true;
return false ; return false ;
} }

View File

@ -66,7 +66,7 @@ class p3Notify: public RsNotify
{ {
public: public:
p3Notify() : noteMtx("p3Notify") { return; } p3Notify() : noteMtx("p3Notify"), _disableAskPassword(false) { return; }
virtual ~p3Notify() { return; } virtual ~p3Notify() { return; }
virtual void registerNotifyClient(NotifyClient *nc) ; 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 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) ; 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 cachePgpPassphrase (const std::string& /* pgp_passphrase */) ;
virtual bool clearPgpPassphrase () ; virtual bool clearPgpPassphrase () ;
virtual bool setDisableAskPassword (const bool /*bValue*/) ;
private: private:
@ -139,7 +141,8 @@ class p3Notify: public RsNotify
std::list<NotifyClient*> notifyClients ; std::list<NotifyClient*> notifyClients ;
std::string cached_pgp_passphrase ; std::string cached_pgp_passphrase;
bool _disableAskPassword;
}; };

View File

@ -205,8 +205,10 @@ class RsNotify
virtual bool GetFeedItem(RsFeedItem &item) = 0; virtual bool GetFeedItem(RsFeedItem &item) = 0;
virtual bool cachePgpPassphrase (const std::string& /* pgp_passphrase */) { return false ; } virtual bool cachePgpPassphrase (const std::string& /* pgp_passphrase */) { return false ; }
virtual bool clearPgpPassphrase () { return false ; } virtual bool clearPgpPassphrase () { return false ; }
virtual bool setDisableAskPassword (const bool /*bValue*/) { return false ; }
}; };
class NotifyClient class NotifyClient

View File

@ -19,15 +19,18 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
****************************************************************/ ****************************************************************/
#include <QMessageBox>
#include "rshare.h"
#include "retroshare/rsinit.h"
#include "StartDialog.h" #include "StartDialog.h"
#include "LogoBar.h" #include "LogoBar.h"
#include "retroshare/rsnotify.h" #include "rshare.h"
#include "settings/rsharesettings.h" #include "settings/rsharesettings.h"
#include "retroshare/rsinit.h"
#include "retroshare/rsnotify.h"
#include <QLineEdit>
#include <QMessageBox>
#include <iostream> #include <iostream>
/** Default constructor */ /** Default constructor */
@ -74,7 +77,7 @@ StartDialog::StartDialog(QWidget *parent)
} }
QObject::connect(ui.loadName,SIGNAL(currentIndexChanged(int)),this,SLOT(updateSelectedProfile(int))) ; 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())); QObject::connect(ui.loadButton, SIGNAL(clicked()), this, SLOT(loadPerson()));
if (pidx > 0) if (pidx > 0)
@ -87,8 +90,9 @@ StartDialog::StartDialog(QWidget *parent)
void StartDialog::updateSelectedProfile(int) void StartDialog::updateSelectedProfile(int)
{ {
ui.password_input->clear(); ui.password_input->clear();
ui.password_input->setFocus(); ui.password_input->setPlaceholderText(tr("Password"));
ui.password_input->setFocus();
} }
void StartDialog::closeEvent (QCloseEvent * event) void StartDialog::closeEvent (QCloseEvent * event)
@ -111,14 +115,22 @@ void StartDialog::loadPerson()
QVariant data = ui.loadName->itemData(pgpidx); QVariant data = ui.loadName->itemData(pgpidx);
RsPeerId accountId = RsPeerId((data.toString()).toStdString()); 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->cachePgpPassphrase(ui.password_input->text().toUtf8().constData()) ;
rsNotify->setDisableAskPassword(true);
bool res = Rshare::loadCertificate(accountId, ui.autologin_checkbox->isChecked()) ; bool res = Rshare::loadCertificate(accountId, ui.autologin_checkbox->isChecked()) ;
if(res) rsNotify->setDisableAskPassword(false);
if(res)
accept(); accept();
else
{
ui.password_input->setPlaceholderText(tr("Wrong password"));
ui.password_input->setText("");
ui.password_input->setFocus();
}
} }
void StartDialog::on_labelProfile_linkActivated(QString /*link*/) void StartDialog::on_labelProfile_linkActivated(QString /*link*/)

View File

@ -274,7 +274,7 @@
</widget> </widget>
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QLineEdit" name="password_input"> <widget class="LineEditClear" name="password_input">
<property name="echoMode"> <property name="echoMode">
<enum>QLineEdit::Password</enum> <enum>QLineEdit::Password</enum>
</property> </property>
@ -360,4 +360,11 @@ p, li { white-space: pre-wrap; }
<include location="icons.qrc"/> <include location="icons.qrc"/>
</resources> </resources>
<connections/> <connections/>
<customwidgets>
<customwidget>
<class>LineEditClear</class>
<extends>QLineEdit</extends>
<header>gui/common/LineEditClear.h</header>
</customwidget>
</customwidgets>
</ui> </ui>

View File

@ -25,7 +25,8 @@
#include <QToolButton> #include <QToolButton>
#include <QStyle> #include <QStyle>
#include <QMenu> #include <QMenu>
#if QT_VERSION < 0x040700 //#if QT_VERSION < 0x040700
#if QT_VERSION < 0x050000//PlaceHolder text only shown when not have focus in Qt4
#include <QLabel> #include <QLabel>
#endif #endif
@ -52,7 +53,8 @@ LineEditClear::LineEditClear(QWidget *parent)
connect(mClearButton, SIGNAL(clicked()), this, SLOT(clear())); connect(mClearButton, SIGNAL(clicked()), this, SLOT(clear()));
connect(this, SIGNAL(textChanged(const QString&)), this, SLOT(updateClearButton(const QString&))); 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 = new QLabel("", this);
mFilterLabel->setStyleSheet("QLabel { color: gray; }"); mFilterLabel->setStyleSheet("QLabel { color: gray; }");
#endif #endif
@ -72,15 +74,17 @@ void LineEditClear::resizeEvent(QResizeEvent *)
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth); int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
mClearButton->move(rect().right() - frameWidth - sz.width() + 2, (rect().bottom() - sz.height()) / 2 + 2); 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(); 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 #endif
} }
void LineEditClear::setPlaceholderText(const QString &text) 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); mFilterLabel->setText(text);
#else #else
QLineEdit::setPlaceholderText(text); QLineEdit::setPlaceholderText(text);
@ -89,7 +93,8 @@ void LineEditClear::setPlaceholderText(const QString &text)
setToolTip(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) void LineEditClear::focusInEvent(QFocusEvent *event)
{ {
mFilterLabel->setVisible(false); mFilterLabel->setVisible(false);
@ -137,6 +142,9 @@ void LineEditClear::showFilterIcon()
void LineEditClear::updateClearButton(const QString& text) void LineEditClear::updateClearButton(const QString& text)
{ {
mClearButton->setVisible(!text.isEmpty()); 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) void LineEditClear::addFilter(const QIcon &icon, const QString &text, int id, const QString &description)

View File

@ -28,7 +28,8 @@
class QToolButton; class QToolButton;
class QActionGroup; 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; class QLabel;
#endif #endif
@ -55,7 +56,8 @@ signals:
protected: protected:
void resizeEvent(QResizeEvent *); 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 focusInEvent(QFocusEvent *event);
void focusOutEvent(QFocusEvent *event); void focusOutEvent(QFocusEvent *event);
#endif #endif
@ -72,7 +74,8 @@ private:
QActionGroup *mActionGroup; QActionGroup *mActionGroup;
QMap<int, QString> mDescription; QMap<int, QString> 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; QLabel *mFilterLabel;
#endif #endif
}; };