Qt5.5 compatiblity patch for login flow V2 + UI improvment
authorMichael Schuster <michael@schuster.ms>
Fri, 6 Sep 2019 12:40:54 +0000 (14:40 +0200)
committerMichael Schuster <michael@schuster.ms>
Fri, 6 Sep 2019 12:40:54 +0000 (14:40 +0200)
Removes the right-click function for the "Re-open browser" buttons because
they are not intuitive for the user.

Adds a dedicated "Copy link" button.

Implements Qt 5.5 fixes based on: https://github.com/nextcloud/desktop/pull/1392

Signed-off-by: Michael Schuster <michael@schuster.ms>
src/gui/wizard/flow2authcredspage.cpp
src/gui/wizard/flow2authcredspage.h
src/gui/wizard/flow2authcredspage.ui
src/gui/wizard/flow2authwidget.cpp
src/gui/wizard/flow2authwidget.h
src/gui/wizard/flow2authwidget.ui
src/gui/wizard/owncloudoauthcredspage.cpp
src/gui/wizard/owncloudoauthcredspage.h
src/gui/wizard/owncloudoauthcredspage.ui

index a368d604385a5229f12e71fe2db9a256116a3684..165752663e8d7b83d1609917d476c58193463585 100644 (file)
@@ -46,21 +46,8 @@ Flow2AuthCredsPage::Flow2AuthCredsPage()
     setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(Theme::instance()->appNameGUI())));
     setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Login in your browser (Login Flow v2)")));
 
-    connect(_ui.openLinkButton, &QCommandLinkButton::clicked, [this] {
-        _ui.errorLabel->hide();
-        if (_asyncAuth)
-            _asyncAuth->openBrowser();
-    });
-    _ui.openLinkButton->setContextMenuPolicy(Qt::CustomContextMenu);
-    QObject::connect(_ui.openLinkButton, &QWidget::customContextMenuRequested, [this](const QPoint &pos) {
-        auto menu = new QMenu(_ui.openLinkButton);
-        menu->addAction(tr("Copy link to clipboard"), this, [this] {
-            if (_asyncAuth)
-                QApplication::clipboard()->setText(_asyncAuth->authorisationLink().toString(QUrl::FullyEncoded));
-        });
-        menu->setAttribute(Qt::WA_DeleteOnClose);
-        menu->popup(_ui.openLinkButton->mapToGlobal(pos));
-    });
+    connect(_ui.openLinkButton, &QCommandLinkButton::clicked, this, &Flow2AuthCredsPage::slotOpenBrowser);
+    connect(_ui.copyLinkButton, &QCommandLinkButton::clicked, this, &Flow2AuthCredsPage::slotCopyLinkToClipboard);
 }
 
 void Flow2AuthCredsPage::initializePage()
@@ -146,4 +133,19 @@ bool Flow2AuthCredsPage::isComplete() const
     return false; /* We can never go forward manually */
 }
 
+void Flow2AuthCredsPage::slotOpenBrowser()
+{
+    if (_ui.errorLabel)
+        _ui.errorLabel->hide();
+
+    if (_asyncAuth)
+        _asyncAuth->openBrowser();
+}
+
+void Flow2AuthCredsPage::slotCopyLinkToClipboard()
+{
+    if (_asyncAuth)
+        QApplication::clipboard()->setText(_asyncAuth->authorisationLink().toString(QUrl::FullyEncoded));
+}
+
 } // namespace OCC
index bffcf68b3ff00b6fcdebcae40666ad58c0f4f800..f51d7d7f359c14f2a3654f3c3130996195bd5abc 100644 (file)
@@ -56,6 +56,10 @@ public:
     QString _appPassword;
     QScopedPointer<Flow2Auth> _asyncAuth;
     Ui_Flow2AuthCredsPage _ui;
+
+protected slots:
+    void slotOpenBrowser();
+    void slotCopyLinkToClipboard();
 };
 
 } // namespace OCC
index 04c1d72175df4fc32a5641fdfb2942a324f097d1..37d2b8f530bfa8fde065166de90b9d81cd0fe792 100644 (file)
    <item>
     <widget class="QCommandLinkButton" name="openLinkButton">
      <property name="text">
-      <string>Re-open Browser (or right-click to copy link)</string>
+      <string>Re-open Browser</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QCommandLinkButton" name="copyLinkButton">
+     <property name="font">
+      <font>
+       <weight>50</weight>
+       <bold>false</bold>
+      </font>
+     </property>
+     <property name="text">
+      <string>Copy link</string>
      </property>
     </widget>
    </item>
index 300b2e83d84e8f8f571733a556640f6a715761e1..c050a54d03a56ffc1ae25acd339cfb270674a94c 100644 (file)
@@ -50,21 +50,8 @@ Flow2AuthWidget::Flow2AuthWidget(Account *account, QWidget *parent)
 
     WizardCommon::initErrorLabel(_ui.errorLabel);
 
-    connect(_ui.openLinkButton, &QCommandLinkButton::clicked, [this] {
-        _ui.errorLabel->hide();
-        if (_asyncAuth)
-            _asyncAuth->openBrowser();
-    });
-    _ui.openLinkButton->setContextMenuPolicy(Qt::CustomContextMenu);
-    QObject::connect(_ui.openLinkButton, &QWidget::customContextMenuRequested, [this](const QPoint &pos) {
-        auto menu = new QMenu(_ui.openLinkButton);
-        menu->addAction(tr("Copy link to clipboard"), this, [this] {
-            if (_asyncAuth)
-                QApplication::clipboard()->setText(_asyncAuth->authorisationLink().toString(QUrl::FullyEncoded));
-        });
-        menu->setAttribute(Qt::WA_DeleteOnClose);
-        menu->popup(_ui.openLinkButton->mapToGlobal(pos));
-    });
+    connect(_ui.openLinkButton, &QCommandLinkButton::clicked, this, &Flow2AuthWidget::slotOpenBrowser);
+    connect(_ui.copyLinkButton, &QCommandLinkButton::clicked, this, &Flow2AuthWidget::slotCopyLinkToClipboard);
 
     _asyncAuth.reset(new Flow2Auth(_account, this));
     connect(_asyncAuth.data(), &Flow2Auth::result, this, &Flow2AuthWidget::asyncAuthResult, Qt::QueuedConnection);
@@ -110,4 +97,19 @@ Flow2AuthWidget::~Flow2AuthWidget() {
     _user.clear();
 }
 
+void Flow2AuthWidget::slotOpenBrowser()
+{
+    if (_ui.errorLabel)
+        _ui.errorLabel->hide();
+
+    if (_asyncAuth)
+        _asyncAuth->openBrowser();
+}
+
+void Flow2AuthWidget::slotCopyLinkToClipboard()
+{
+    if (_asyncAuth)
+        QApplication::clipboard()->setText(_asyncAuth->authorisationLink().toString(QUrl::FullyEncoded));
 }
+
+} // namespace OCC
index cf04d9193568ff1aaabfe3221e0c3fe70cd0f11c..7fe1844c1744298af4eae52746b1f8eae10e2793 100644 (file)
@@ -45,6 +45,10 @@ private:
     QString _appPassword;
     QScopedPointer<Flow2Auth> _asyncAuth;
     Ui_Flow2AuthWidget _ui;
+
+protected slots:
+    void slotOpenBrowser();
+    void slotCopyLinkToClipboard();
 };
 
 }
index e73ae6a1d68a8094be9815637e6a6b3ef734d089..7de44675f7b55e8bc1815b58e36efe4fbcb880d2 100644 (file)
    <item>
     <widget class="QCommandLinkButton" name="openLinkButton">
      <property name="text">
-      <string>Re-open Browser (or right-click to copy link)</string>
+      <string>Re-open Browser</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QCommandLinkButton" name="copyLinkButton">
+     <property name="font">
+      <font>
+       <weight>50</weight>
+       <bold>false</bold>
+      </font>
+     </property>
+     <property name="text">
+      <string>Copy link</string>
      </property>
     </widget>
    </item>
index 174aa05c47fa135ec249bf4bdec1c6124d6e5536..0d4c40ea7ea4426f12ebf984c7940b1d1acc7b22 100644 (file)
@@ -45,21 +45,8 @@ OwncloudOAuthCredsPage::OwncloudOAuthCredsPage()
     setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(Theme::instance()->appNameGUI())));
     setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Login in your browser")));
 
-    connect(_ui.openLinkButton, &QCommandLinkButton::clicked, [this] {
-        _ui.errorLabel->hide();
-        if (_asyncAuth)
-            _asyncAuth->openBrowser();
-    });
-    _ui.openLinkButton->setContextMenuPolicy(Qt::CustomContextMenu);
-    QObject::connect(_ui.openLinkButton, &QWidget::customContextMenuRequested, [this](const QPoint &pos) {
-        auto menu = new QMenu(_ui.openLinkButton);
-        menu->addAction(tr("Copy link to clipboard"), this, [this] {
-            if (_asyncAuth)
-                QApplication::clipboard()->setText(_asyncAuth->authorisationLink().toString(QUrl::FullyEncoded));
-        });
-        menu->setAttribute(Qt::WA_DeleteOnClose);
-        menu->popup(_ui.openLinkButton->mapToGlobal(pos));
-    });
+    connect(_ui.openLinkButton, &QCommandLinkButton::clicked, this, &OwncloudOAuthCredsPage::slotOpenBrowser);
+    connect(_ui.copyLinkButton, &QCommandLinkButton::clicked, this, &OwncloudOAuthCredsPage::slotCopyLinkToClipboard);
 }
 
 void OwncloudOAuthCredsPage::initializePage()
@@ -133,4 +120,19 @@ bool OwncloudOAuthCredsPage::isComplete() const
     return false; /* We can never go forward manually */
 }
 
+void OwncloudOAuthCredsPage::slotOpenBrowser()
+{
+    if (_ui.errorLabel)
+        _ui.errorLabel->hide();
+
+    if (_asyncAuth)
+        _asyncAuth->openBrowser();
+}
+
+void OwncloudOAuthCredsPage::slotCopyLinkToClipboard()
+{
+    if (_asyncAuth)
+        QApplication::clipboard()->setText(_asyncAuth->authorisationLink().toString(QUrl::FullyEncoded));
+}
+
 } // namespace OCC
index 32341eb1cdef8fe0f6a4d57bc37e7b4400394e51..efbc9a69b3b22647fc3f19c9ae891d5b89a8a4e7 100644 (file)
@@ -57,6 +57,10 @@ public:
     QString _refreshToken;
     QScopedPointer<OAuth> _asyncAuth;
     Ui_OwncloudOAuthCredsPage _ui;
+
+protected slots:
+    void slotOpenBrowser();
+    void slotCopyLinkToClipboard();
 };
 
 } // namespace OCC
index 2c3a79ed22167e91184cc2d10fad0562873eb9fa..03682cae10d40771fdb26eb6827624f014c4516f 100644 (file)
      </property>
     </widget>
    </item>
+   <item>
+    <widget class="QCommandLinkButton" name="copyLinkButton">
+     <property name="font">
+      <font>
+       <weight>50</weight>
+       <bold>false</bold>
+      </font>
+     </property>
+     <property name="text">
+      <string>Copy link</string>
+     </property>
+    </widget>
+   </item>
    <item>
     <spacer name="verticalSpacer">
      <property name="orientation">