From a8b4eaa43125391758f9a6a9f871abe973273ae8 Mon Sep 17 00:00:00 2001 From: kornes <28986062+kornes@users.noreply.github.com> Date: Sat, 12 Nov 2022 13:40:49 +0000 Subject: [PATCH] Fix login dialog causing main window to be non movable (#4121) Co-authored-by: pajlada fixes https://github.com/Chatterino/chatterino2/issues/2378 --- CHANGELOG.md | 1 + src/widgets/dialogs/LoginDialog.cpp | 59 ++++++++++------------ src/widgets/dialogs/LoginDialog.hpp | 4 +- src/widgets/settingspages/AccountsPage.cpp | 6 +-- 4 files changed, 32 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33366de6..f5d6df01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -79,6 +79,7 @@ - Minor: Migrated /mods to Helix API. (#4103) - Minor: Add settings tooltips. (#3437) - Minor: Improved look of tabs when using a layout other than top. (#3925) +- Bugfix: Fixed `Add new account` dialog causing main chatterino window to be non movable. (#4121) - Bugfix: Connection to Twitch PubSub now recovers more reliably. (#3643, #3716) - Bugfix: Fixed `Smooth scrolling on new messages` setting sometimes hiding messages. (#4028) - Bugfix: Fixed a crash that can occur when closing and quickly reopening a split, then running a command. (#3852) diff --git a/src/widgets/dialogs/LoginDialog.cpp b/src/widgets/dialogs/LoginDialog.cpp index b056f60c..f4b1fa15 100644 --- a/src/widgets/dialogs/LoginDialog.cpp +++ b/src/widgets/dialogs/LoginDialog.cpp @@ -23,8 +23,8 @@ namespace chatterino { namespace { - void logInWithCredentials(const QString &userID, const QString &username, - const QString &clientID, + bool logInWithCredentials(QWidget *parent, const QString &userID, + const QString &username, const QString &clientID, const QString &oauthToken) { QStringList errors; @@ -48,20 +48,12 @@ namespace { if (errors.length() > 0) { - QMessageBox messageBox; -// Set error window on top -#ifdef USEWINSDK - ::SetWindowPos(HWND(messageBox.winId()), HWND_TOPMOST, 0, 0, 0, 0, - SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); - -#endif - messageBox.setWindowTitle( - "Chatterino - invalid account credentials"); + QMessageBox messageBox(parent); + messageBox.setWindowTitle("Invalid account credentials"); messageBox.setIcon(QMessageBox::Critical); messageBox.setText(errors.join("
")); - messageBox.setStandardButtons(QMessageBox::Ok); messageBox.exec(); - return; + return false; } std::string basePath = "/accounts/uid" + userID.toStdString(); @@ -75,6 +67,7 @@ namespace { getApp()->accounts->twitch.reloadUsers(); getApp()->accounts->twitch.currentUsername = username; + return true; } } // namespace @@ -116,6 +109,9 @@ BasicLoginWidget::BasicLoginWidget() QStringList parameters = getClipboardText().split(";"); QString oauthToken, clientID, username, userID; + // Removing clipboard content to prevent accidental paste of credentials into somewhere + crossPlatformCopy(""); + for (const auto ¶m : parameters) { QStringList kvParameters = param.split('='); @@ -148,11 +144,10 @@ BasicLoginWidget::BasicLoginWidget() } } - logInWithCredentials(userID, username, clientID, oauthToken); - - // Removing clipboard content to prevent accidental paste of credentials into somewhere - crossPlatformCopy(""); - this->window()->close(); + if (logInWithCredentials(this, userID, username, clientID, oauthToken)) + { + this->window()->close(); + } }); } @@ -212,15 +207,15 @@ AdvancedLoginWidget::AdvancedLoginWidget() this->ui_.oauthTokenInput.clear(); }); - connect(&this->ui_.buttonUpperRow.addUserButton, &QPushButton::clicked, - [=]() { - QString userID = this->ui_.userIDInput.text(); - QString username = this->ui_.usernameInput.text(); - QString clientID = this->ui_.clientIDInput.text(); - QString oauthToken = this->ui_.oauthTokenInput.text(); + connect( + &this->ui_.buttonUpperRow.addUserButton, &QPushButton::clicked, [=]() { + QString userID = this->ui_.userIDInput.text(); + QString username = this->ui_.usernameInput.text(); + QString clientID = this->ui_.clientIDInput.text(); + QString oauthToken = this->ui_.oauthTokenInput.text(); - logInWithCredentials(userID, username, clientID, oauthToken); - }); + logInWithCredentials(this, userID, username, clientID, oauthToken); + }); } void AdvancedLoginWidget::refreshButtons() @@ -238,15 +233,15 @@ void AdvancedLoginWidget::refreshButtons() } } -LoginWidget::LoginWidget(QWidget *parent) +LoginDialog::LoginDialog(QWidget *parent) : QDialog(parent) { -#ifdef USEWINSDK - ::SetWindowPos(HWND(this->winId()), HWND_TOPMOST, 0, 0, 0, 0, - SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); -#endif + this->setMinimumWidth(300); + this->setWindowFlags( + (this->windowFlags() & ~(Qt::WindowContextHelpButtonHint)) | + Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint); - this->setWindowTitle("Chatterino - add new account"); + this->setWindowTitle("Add new account"); this->setLayout(&this->ui_.mainLayout); this->ui_.mainLayout.addWidget(&this->ui_.tabWidget); diff --git a/src/widgets/dialogs/LoginDialog.hpp b/src/widgets/dialogs/LoginDialog.hpp index 154e063c..fadd86fe 100644 --- a/src/widgets/dialogs/LoginDialog.hpp +++ b/src/widgets/dialogs/LoginDialog.hpp @@ -61,10 +61,10 @@ public: } ui_; }; -class LoginWidget : public QDialog +class LoginDialog : public QDialog { public: - LoginWidget(QWidget *parent); + LoginDialog(QWidget *parent); private: struct { diff --git a/src/widgets/settingspages/AccountsPage.cpp b/src/widgets/settingspages/AccountsPage.cpp index 1c53becb..e6991851 100644 --- a/src/widgets/settingspages/AccountsPage.cpp +++ b/src/widgets/settingspages/AccountsPage.cpp @@ -33,10 +33,8 @@ AccountsPage::AccountsPage() view->getTableView()->horizontalHeader()->setStretchLastSection(true); view->addButtonPressed.connect([this] { - static auto loginWidget = new LoginWidget(this); - - loginWidget->show(); - loginWidget->raise(); + LoginDialog d(this); + d.exec(); }); view->getTableView()->setStyleSheet("background: #333");