From 470fe5a58adf0d1cc77833ddb97c9f3460737887 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Sat, 26 Sep 2020 10:24:29 +0200 Subject: [PATCH] Add label that shows up if the log in link didn't open properly This basically takes the official advice from https://github.com/Chatterino/chatterino2/issues/1779#issuecomment-699235396 and tells the user what they can do as a workaround. Relevant issue: #1779 --- src/widgets/dialogs/LoginDialog.cpp | 20 +++++++++++++++++--- src/widgets/dialogs/LoginDialog.hpp | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/widgets/dialogs/LoginDialog.cpp b/src/widgets/dialogs/LoginDialog.cpp index 3666ea657..ecfdbaff7 100644 --- a/src/widgets/dialogs/LoginDialog.cpp +++ b/src/widgets/dialogs/LoginDialog.cpp @@ -84,19 +84,33 @@ namespace { BasicLoginWidget::BasicLoginWidget() { + const QString logInLink = "https://chatterino.com/client_login"; this->setLayout(&this->ui_.layout); this->ui_.loginButton.setText("Log in (Opens in browser)"); this->ui_.pasteCodeButton.setText("Paste login info"); + this->ui_.unableToOpenBrowserHelper.setWordWrap(true); + this->ui_.unableToOpenBrowserHelper.hide(); + this->ui_.unableToOpenBrowserHelper.setText( + "An error occured while attempting to open the log in link (" + logInLink + ") " + + " - open it manually in your browser and proceed from there."); + this->ui_.unableToOpenBrowserHelper.setOpenExternalLinks(true); this->ui_.horizontalLayout.addWidget(&this->ui_.loginButton); this->ui_.horizontalLayout.addWidget(&this->ui_.pasteCodeButton); this->ui_.layout.addLayout(&this->ui_.horizontalLayout); + this->ui_.layout.addWidget(&this->ui_.unableToOpenBrowserHelper); - connect(&this->ui_.loginButton, &QPushButton::clicked, []() { - printf("open login in browser\n"); - QDesktopServices::openUrl(QUrl("https://chatterino.com/client_login")); + connect(&this->ui_.loginButton, &QPushButton::clicked, [this, logInLink]() { + qDebug() << "open login in browser"; + auto res = QDesktopServices::openUrl(QUrl(logInLink)); + if (!res) + { + qDebug() << "open login in browser failed"; + this->ui_.unableToOpenBrowserHelper.show(); + } }); connect(&this->ui_.pasteCodeButton, &QPushButton::clicked, [this]() { diff --git a/src/widgets/dialogs/LoginDialog.hpp b/src/widgets/dialogs/LoginDialog.hpp index 796b98cac..4fa4b2803 100644 --- a/src/widgets/dialogs/LoginDialog.hpp +++ b/src/widgets/dialogs/LoginDialog.hpp @@ -29,6 +29,7 @@ public: QHBoxLayout horizontalLayout; QPushButton loginButton; QPushButton pasteCodeButton; + QLabel unableToOpenBrowserHelper; } ui_; };