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>
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();
{
_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");
loginName.clear();
// Failed: poll again
+ _secondsLeft = _secondsInterval;
_pollTimer.start();
return;
}
void Flow2Auth::slotPollNow()
{
// poll now if we're not already doing so
- if(_pollTimer.isActive())
+ if(_pollTimer.isActive()) {
+ _secondsLeft = 1;
slotPollTimerTimeout();
+ }
}
} // namespace OCC
*/
void result(Flow2Auth::Result result, const QString &user = QString(), const QString &appPassword = QString());
+ void statusChanged(int secondsLeft);
+
public slots:
void slotPollNow();
QString _pollToken;
QString _pollEndpoint;
QTimer _pollTimer;
+ int _secondsLeft;
+ int _secondsInterval;
};
#include "creds/credentialsfactory.h"
#include "creds/webflowcredentials.h"
+#include "QProgressIndicator.h"
+
namespace OCC {
Flow2AuthCredsPage::Flow2AuthCredsPage()
: AbstractCredentialsWizardPage()
, _ui()
+ , _progressIndi(new QProgressIndicator(this))
{
_ui.setupUi(this);
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()
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();
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) */
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
#include "ui_flow2authcredspage.h"
+class QProgressIndicator;
namespace OCC {
public Q_SLOTS:
void asyncAuthResult(Flow2Auth::Result, const QString &user, const QString &appPassword);
void slotPollNow();
+ void slotStatusChanged(int secondsLeft);
signals:
void connectToOCUrl(const QString &);
protected slots:
void slotOpenBrowser();
void slotCopyLinkToClipboard();
+
+private:
+ void startSpinner();
+ void stopSpinner(bool showStatusLabel);
+
+ QProgressIndicator *_progressIndi;
};
} // namespace OCC
</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">
#include "theme.h"
#include "wizard/owncloudwizardcommon.h"
+#include "QProgressIndicator.h"
+
namespace OCC {
Q_LOGGING_CATEGORY(lcFlow2AuthWidget, "gui.wizard.flow2authwidget", QtInfoMsg)
: QWidget(parent)
, _account(account)
, _ui()
+ , _progressIndi(new QProgressIndicator(this))
{
_ui.setupUi(this);
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();
}
void Flow2AuthWidget::asyncAuthResult(Flow2Auth::Result r, const QString &user,
const QString &appPassword)
{
+ stopSpinner(false);
+
switch (r) {
case Flow2Auth::NotSupported:
/* Flow2Auth can't open browser */
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
#include "ui_flow2authwidget.h"
+class QProgressIndicator;
+
namespace OCC {
class Flow2AuthWidget : public QWidget
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);
protected slots:
void slotOpenBrowser();
void slotCopyLinkToClipboard();
+
+private:
+ void startSpinner();
+ void stopSpinner(bool showStatusLabel);
+
+ QProgressIndicator *_progressIndi;
};
} // namespace OCC
</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">