Flow2: Add poll status text, ProgressIndicator and countdown timer

Also enable / disable buttons during polling.

This aims to make the authentication status more transparent and should avoid the
impression that the client is perhaps doing nothing.

Signed-off-by: Michael Schuster <michael@schuster.ms>
This commit is contained in:
Michael Schuster 2019-12-21 04:21:41 +01:00 committed by Michael Schuster
parent 542590db7c
commit e81f972270
8 changed files with 175 additions and 2 deletions

View file

@ -99,8 +99,11 @@ void Flow2Auth::openBrowser()
ConfigFile cfg;
std::chrono::milliseconds polltime = cfg.remotePollInterval();
qCInfo(lcFlow2auth) << "setting remote poll timer interval to" << polltime.count() << "msec";
_pollTimer.setInterval(polltime.count());
_pollTimer.setInterval(1000);
QObject::connect(&_pollTimer, &QTimer::timeout, this, &Flow2Auth::slotPollTimerTimeout);
_secondsInterval = (polltime.count() / 1000);
_secondsLeft = _secondsInterval;
emit statusChanged(_secondsLeft);
_pollTimer.start();
@ -117,6 +120,14 @@ void Flow2Auth::slotPollTimerTimeout()
{
_pollTimer.stop();
_secondsLeft--;
emit statusChanged(_secondsLeft);
if(_secondsLeft > 0) {
_pollTimer.start();
return;
}
// Step 2: Poll
QNetworkRequest req;
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
@ -160,6 +171,7 @@ void Flow2Auth::slotPollTimerTimeout()
loginName.clear();
// Failed: poll again
_secondsLeft = _secondsInterval;
_pollTimer.start();
return;
}
@ -180,8 +192,10 @@ void Flow2Auth::slotPollTimerTimeout()
void Flow2Auth::slotPollNow()
{
// poll now if we're not already doing so
if(_pollTimer.isActive())
if(_pollTimer.isActive()) {
_secondsLeft = 1;
slotPollTimerTimeout();
}
}
} // namespace OCC

View file

@ -52,6 +52,8 @@ signals:
*/
void result(Flow2Auth::Result result, const QString &user = QString(), const QString &appPassword = QString());
void statusChanged(int secondsLeft);
public slots:
void slotPollNow();
@ -64,6 +66,8 @@ private:
QString _pollToken;
QString _pollEndpoint;
QTimer _pollTimer;
int _secondsLeft;
int _secondsInterval;
};

View file

@ -26,11 +26,14 @@
#include "creds/credentialsfactory.h"
#include "creds/webflowcredentials.h"
#include "QProgressIndicator.h"
namespace OCC {
Flow2AuthCredsPage::Flow2AuthCredsPage()
: AbstractCredentialsWizardPage()
, _ui()
, _progressIndi(new QProgressIndicator(this))
{
_ui.setupUi(this);
@ -49,6 +52,9 @@ Flow2AuthCredsPage::Flow2AuthCredsPage()
connect(_ui.openLinkButton, &QCommandLinkButton::clicked, this, &Flow2AuthCredsPage::slotOpenBrowser);
connect(_ui.copyLinkButton, &QCommandLinkButton::clicked, this, &Flow2AuthCredsPage::slotCopyLinkToClipboard);
_ui.horizontalLayout->addWidget(_progressIndi);
stopSpinner(false);
}
void Flow2AuthCredsPage::initializePage()
@ -58,6 +64,7 @@ void Flow2AuthCredsPage::initializePage()
ocWizard->account()->setCredentials(CredentialsFactory::create("http"));
_asyncAuth.reset(new Flow2Auth(ocWizard->account().data(), this));
connect(_asyncAuth.data(), &Flow2Auth::result, this, &Flow2AuthCredsPage::asyncAuthResult, Qt::QueuedConnection);
connect(_asyncAuth.data(), &Flow2Auth::statusChanged, this, &Flow2AuthCredsPage::slotStatusChanged);
connect(this, &Flow2AuthCredsPage::pollNow, _asyncAuth.data(), &Flow2Auth::slotPollNow);
_asyncAuth->start();
@ -79,6 +86,8 @@ void OCC::Flow2AuthCredsPage::cleanupPage()
void Flow2AuthCredsPage::asyncAuthResult(Flow2Auth::Result r, const QString &user,
const QString &appPassword)
{
stopSpinner(false);
switch (r) {
case Flow2Auth::NotSupported: {
/* Flow2Auth not supported (can't open browser) */
@ -160,4 +169,38 @@ void Flow2AuthCredsPage::slotPollNow()
emit pollNow();
}
void Flow2AuthCredsPage::slotStatusChanged(int secondsLeft)
{
const bool pollingNow = (secondsLeft == 0);
_ui.statusLabel->setText(tr("Polling for authorization") + (pollingNow ? "" : QString(" " + tr("in %1 seconds").arg(secondsLeft))) + "...");
if(pollingNow)
startSpinner();
else
stopSpinner(true);
}
void Flow2AuthCredsPage::startSpinner()
{
_ui.horizontalLayout->setEnabled(true);
_ui.statusLabel->setVisible(true);
_progressIndi->setVisible(true);
_progressIndi->startAnimation();
_ui.openLinkButton->setEnabled(false);
_ui.copyLinkButton->setEnabled(false);
}
void Flow2AuthCredsPage::stopSpinner(bool showStatusLabel)
{
_ui.horizontalLayout->setEnabled(false);
_ui.statusLabel->setVisible(showStatusLabel);
_progressIndi->setVisible(false);
_progressIndi->stopAnimation();
_ui.openLinkButton->setEnabled(true);
_ui.copyLinkButton->setEnabled(true);
}
} // namespace OCC

View file

@ -27,6 +27,7 @@
#include "ui_flow2authcredspage.h"
class QProgressIndicator;
namespace OCC {
@ -47,6 +48,7 @@ public:
public Q_SLOTS:
void asyncAuthResult(Flow2Auth::Result, const QString &user, const QString &appPassword);
void slotPollNow();
void slotStatusChanged(int secondsLeft);
signals:
void connectToOCUrl(const QString &);
@ -61,6 +63,12 @@ public:
protected slots:
void slotOpenBrowser();
void slotCopyLinkToClipboard();
private:
void startSpinner();
void stopSpinner(bool showStatusLabel);
QProgressIndicator *_progressIndi;
};
} // namespace OCC

View file

@ -70,6 +70,32 @@
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="statusLabel">
<property name="text">
<string notr="true">TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

View file

@ -28,6 +28,8 @@
#include "theme.h"
#include "wizard/owncloudwizardcommon.h"
#include "QProgressIndicator.h"
namespace OCC {
Q_LOGGING_CATEGORY(lcFlow2AuthWidget, "gui.wizard.flow2authwidget", QtInfoMsg)
@ -37,6 +39,7 @@ Flow2AuthWidget::Flow2AuthWidget(Account *account, QWidget *parent)
: QWidget(parent)
, _account(account)
, _ui()
, _progressIndi(new QProgressIndicator(this))
{
_ui.setupUi(this);
@ -53,8 +56,12 @@ Flow2AuthWidget::Flow2AuthWidget(Account *account, QWidget *parent)
connect(_ui.openLinkButton, &QCommandLinkButton::clicked, this, &Flow2AuthWidget::slotOpenBrowser);
connect(_ui.copyLinkButton, &QCommandLinkButton::clicked, this, &Flow2AuthWidget::slotCopyLinkToClipboard);
_ui.horizontalLayout->addWidget(_progressIndi);
stopSpinner(false);
_asyncAuth.reset(new Flow2Auth(_account, this));
connect(_asyncAuth.data(), &Flow2Auth::result, this, &Flow2AuthWidget::asyncAuthResult, Qt::QueuedConnection);
connect(_asyncAuth.data(), &Flow2Auth::statusChanged, this, &Flow2AuthWidget::slotStatusChanged);
connect(this, &Flow2AuthWidget::pollNow, _asyncAuth.data(), &Flow2Auth::slotPollNow);
_asyncAuth->start();
}
@ -62,6 +69,8 @@ Flow2AuthWidget::Flow2AuthWidget(Account *account, QWidget *parent)
void Flow2AuthWidget::asyncAuthResult(Flow2Auth::Result r, const QString &user,
const QString &appPassword)
{
stopSpinner(false);
switch (r) {
case Flow2Auth::NotSupported:
/* Flow2Auth can't open browser */
@ -118,4 +127,38 @@ void Flow2AuthWidget::slotPollNow()
emit pollNow();
}
void Flow2AuthWidget::slotStatusChanged(int secondsLeft)
{
const bool pollingNow = (secondsLeft == 0);
_ui.statusLabel->setText(tr("Polling for authorization") + (pollingNow ? "" : QString(" " + tr("in %1 seconds").arg(secondsLeft))) + "...");
if(pollingNow)
startSpinner();
else
stopSpinner(true);
}
void Flow2AuthWidget::startSpinner()
{
_ui.horizontalLayout->setEnabled(true);
_ui.statusLabel->setVisible(true);
_progressIndi->setVisible(true);
_progressIndi->startAnimation();
_ui.openLinkButton->setEnabled(false);
_ui.copyLinkButton->setEnabled(false);
}
void Flow2AuthWidget::stopSpinner(bool showStatusLabel)
{
_ui.horizontalLayout->setEnabled(false);
_ui.statusLabel->setVisible(showStatusLabel);
_progressIndi->setVisible(false);
_progressIndi->stopAnimation();
_ui.openLinkButton->setEnabled(true);
_ui.copyLinkButton->setEnabled(true);
}
} // namespace OCC

View file

@ -22,6 +22,8 @@
#include "ui_flow2authwidget.h"
class QProgressIndicator;
namespace OCC {
class Flow2AuthWidget : public QWidget
@ -36,6 +38,7 @@ public:
public Q_SLOTS:
void asyncAuthResult(Flow2Auth::Result, const QString &user, const QString &appPassword);
void slotPollNow();
void slotStatusChanged(int secondsLeft);
signals:
void urlCatched(const QString user, const QString pass, const QString host);
@ -51,6 +54,12 @@ private:
protected slots:
void slotOpenBrowser();
void slotCopyLinkToClipboard();
private:
void startSpinner();
void stopSpinner(bool showStatusLabel);
QProgressIndicator *_progressIndi;
};
} // namespace OCC

View file

@ -82,6 +82,32 @@
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="statusLabel">
<property name="text">
<string notr="true">TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">