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 ;
}
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 ;
}

View File

@ -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) ;
@ -128,6 +128,8 @@ class p3Notify: public RsNotify
virtual bool cachePgpPassphrase (const std::string& /* pgp_passphrase */) ;
virtual bool clearPgpPassphrase () ;
virtual bool setDisableAskPassword (const bool /*bValue*/) ;
private:
RsMutex noteMtx;
@ -139,7 +141,8 @@ class p3Notify: public RsNotify
std::list<NotifyClient*> notifyClients ;
std::string cached_pgp_passphrase ;
std::string cached_pgp_passphrase;
bool _disableAskPassword;
};

View File

@ -207,6 +207,8 @@ class RsNotify
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

View File

@ -19,15 +19,18 @@
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QMessageBox>
#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 <QLineEdit>
#include <QMessageBox>
#include <iostream>
/** 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)
@ -88,6 +91,7 @@ StartDialog::StartDialog(QWidget *parent)
void StartDialog::updateSelectedProfile(int)
{
ui.password_input->clear();
ui.password_input->setPlaceholderText(tr("Password"));
ui.password_input->setFocus();
}
@ -112,13 +116,21 @@ void StartDialog::loadPerson()
RsPeerId accountId = RsPeerId((data.toString()).toStdString());
// 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()) ;
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*/)

View File

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

View File

@ -25,7 +25,8 @@
#include <QToolButton>
#include <QStyle>
#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>
#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)

View File

@ -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<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;
#endif
};