mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Some fixes related to clipboard (#2405)
Also: - Fixed capitalization of one method in `LoginDialog.cpp` - Visually improved some strings in `LoginDialog.cpp` - Added utility function getting clipboard content to `Clipboard.cpp` - Made sure to use `crossPlatformCopy` in `UserInfoPopup.cpp`
This commit is contained in:
parent
369ffbfdc8
commit
3023a44a21
4 changed files with 31 additions and 26 deletions
|
@ -6,11 +6,18 @@ namespace chatterino {
|
||||||
void crossPlatformCopy(const QString &text)
|
void crossPlatformCopy(const QString &text)
|
||||||
{
|
{
|
||||||
auto clipboard = QApplication::clipboard();
|
auto clipboard = QApplication::clipboard();
|
||||||
|
|
||||||
clipboard->setText(text);
|
clipboard->setText(text);
|
||||||
|
|
||||||
if (clipboard->supportsSelection())
|
if (clipboard->supportsSelection())
|
||||||
{
|
{
|
||||||
clipboard->setText(text, QClipboard::Selection);
|
clipboard->setText(text, QClipboard::Selection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString getClipboardText()
|
||||||
|
{
|
||||||
|
return QApplication::clipboard()->text();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -6,4 +6,6 @@ namespace chatterino {
|
||||||
|
|
||||||
void crossPlatformCopy(const QString &text);
|
void crossPlatformCopy(const QString &text);
|
||||||
|
|
||||||
|
QString getClipboardText();
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "common/NetworkRequest.hpp"
|
#include "common/NetworkRequest.hpp"
|
||||||
#include "common/QLogging.hpp"
|
#include "common/QLogging.hpp"
|
||||||
#include "controllers/accounts/AccountController.hpp"
|
#include "controllers/accounts/AccountController.hpp"
|
||||||
|
#include "util/Clipboard.hpp"
|
||||||
#include "util/Helpers.hpp"
|
#include "util/Helpers.hpp"
|
||||||
|
|
||||||
#ifdef USEWINSDK
|
#ifdef USEWINSDK
|
||||||
|
@ -22,7 +23,7 @@ namespace chatterino {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void LogInWithCredentials(const QString &userID, const QString &username,
|
void logInWithCredentials(const QString &userID, const QString &username,
|
||||||
const QString &clientID,
|
const QString &clientID,
|
||||||
const QString &oauthToken)
|
const QString &oauthToken)
|
||||||
{
|
{
|
||||||
|
@ -57,16 +58,12 @@ namespace {
|
||||||
messageBox.setWindowTitle(
|
messageBox.setWindowTitle(
|
||||||
"Chatterino - invalid account credentials");
|
"Chatterino - invalid account credentials");
|
||||||
messageBox.setIcon(QMessageBox::Critical);
|
messageBox.setIcon(QMessageBox::Critical);
|
||||||
messageBox.setText(errors.join("<br />"));
|
messageBox.setText(errors.join("<br>"));
|
||||||
messageBox.setStandardButtons(QMessageBox::Ok);
|
messageBox.setStandardButtons(QMessageBox::Ok);
|
||||||
messageBox.exec();
|
messageBox.exec();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// QMessageBox messageBox;
|
|
||||||
// messageBox.setIcon(QMessageBox::Information);
|
|
||||||
// messageBox.setText("Successfully logged in with user <b>" +
|
|
||||||
// qS(username) + "</b>!");
|
|
||||||
std::string basePath = "/accounts/uid" + userID.toStdString();
|
std::string basePath = "/accounts/uid" + userID.toStdString();
|
||||||
pajlada::Settings::Setting<QString>::set(basePath + "/username",
|
pajlada::Settings::Setting<QString>::set(basePath + "/username",
|
||||||
username);
|
username);
|
||||||
|
@ -77,9 +74,6 @@ namespace {
|
||||||
oauthToken);
|
oauthToken);
|
||||||
|
|
||||||
getApp()->accounts->twitch.reloadUsers();
|
getApp()->accounts->twitch.reloadUsers();
|
||||||
|
|
||||||
// messageBox.exec();
|
|
||||||
|
|
||||||
getApp()->accounts->twitch.currentUsername = username;
|
getApp()->accounts->twitch.currentUsername = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,9 +91,10 @@ BasicLoginWidget::BasicLoginWidget()
|
||||||
this->ui_.unableToOpenBrowserHelper.setWordWrap(true);
|
this->ui_.unableToOpenBrowserHelper.setWordWrap(true);
|
||||||
this->ui_.unableToOpenBrowserHelper.hide();
|
this->ui_.unableToOpenBrowserHelper.hide();
|
||||||
this->ui_.unableToOpenBrowserHelper.setText(
|
this->ui_.unableToOpenBrowserHelper.setText(
|
||||||
"An error occurred while attempting to open <a href='" + logInLink +
|
QString("An error occurred while attempting to open <a href=\"%1\">the "
|
||||||
"'>the log in link (" + logInLink + ")</a> " +
|
"log in link (%1)</a> - open it manually in your browser and "
|
||||||
" - open it manually in your browser and proceed from there.");
|
"proceed from there.")
|
||||||
|
.arg(logInLink));
|
||||||
this->ui_.unableToOpenBrowserHelper.setOpenExternalLinks(true);
|
this->ui_.unableToOpenBrowserHelper.setOpenExternalLinks(true);
|
||||||
|
|
||||||
this->ui_.horizontalLayout.addWidget(&this->ui_.loginButton);
|
this->ui_.horizontalLayout.addWidget(&this->ui_.loginButton);
|
||||||
|
@ -110,8 +105,7 @@ BasicLoginWidget::BasicLoginWidget()
|
||||||
|
|
||||||
connect(&this->ui_.loginButton, &QPushButton::clicked, [this, logInLink]() {
|
connect(&this->ui_.loginButton, &QPushButton::clicked, [this, logInLink]() {
|
||||||
qCDebug(chatterinoWidget) << "open login in browser";
|
qCDebug(chatterinoWidget) << "open login in browser";
|
||||||
auto res = QDesktopServices::openUrl(QUrl(logInLink));
|
if (!QDesktopServices::openUrl(QUrl(logInLink)))
|
||||||
if (!res)
|
|
||||||
{
|
{
|
||||||
qCWarning(chatterinoWidget) << "open login in browser failed";
|
qCWarning(chatterinoWidget) << "open login in browser failed";
|
||||||
this->ui_.unableToOpenBrowserHelper.show();
|
this->ui_.unableToOpenBrowserHelper.show();
|
||||||
|
@ -119,10 +113,7 @@ BasicLoginWidget::BasicLoginWidget()
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(&this->ui_.pasteCodeButton, &QPushButton::clicked, [this]() {
|
connect(&this->ui_.pasteCodeButton, &QPushButton::clicked, [this]() {
|
||||||
QClipboard *clipboard = QGuiApplication::clipboard();
|
QStringList parameters = getClipboardText().split(";");
|
||||||
QString clipboardString = clipboard->text();
|
|
||||||
QStringList parameters = clipboardString.split(';');
|
|
||||||
|
|
||||||
QString oauthToken, clientID, username, userID;
|
QString oauthToken, clientID, username, userID;
|
||||||
|
|
||||||
for (const auto ¶m : parameters)
|
for (const auto ¶m : parameters)
|
||||||
|
@ -157,9 +148,10 @@ BasicLoginWidget::BasicLoginWidget()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LogInWithCredentials(userID, username, clientID, oauthToken);
|
logInWithCredentials(userID, username, clientID, oauthToken);
|
||||||
|
|
||||||
clipboard->clear();
|
// Removing clipboard content to prevent accidental paste of credentials into somewhere
|
||||||
|
crossPlatformCopy("");
|
||||||
this->window()->close();
|
this->window()->close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -169,9 +161,12 @@ AdvancedLoginWidget::AdvancedLoginWidget()
|
||||||
this->setLayout(&this->ui_.layout);
|
this->setLayout(&this->ui_.layout);
|
||||||
|
|
||||||
this->ui_.instructionsLabel.setText(
|
this->ui_.instructionsLabel.setText(
|
||||||
"1. Fill in your username\n2. Fill in your user ID or press "
|
"1. Fill in your username"
|
||||||
"the 'Get user ID from username' button\n3. Fill in your "
|
"\n2. Fill in your user ID or press the 'Get user ID from username' "
|
||||||
"Client ID\n4. Fill in your OAuth Token\n5. Press Add User");
|
"button"
|
||||||
|
"\n3. Fill in your Client ID"
|
||||||
|
"\n4. Fill in your OAuth Token"
|
||||||
|
"\n5. Press Add User");
|
||||||
this->ui_.instructionsLabel.setWordWrap(true);
|
this->ui_.instructionsLabel.setWordWrap(true);
|
||||||
|
|
||||||
this->ui_.layout.addWidget(&this->ui_.instructionsLabel);
|
this->ui_.layout.addWidget(&this->ui_.instructionsLabel);
|
||||||
|
@ -226,7 +221,7 @@ AdvancedLoginWidget::AdvancedLoginWidget()
|
||||||
QString clientID = this->ui_.clientIDInput.text();
|
QString clientID = this->ui_.clientIDInput.text();
|
||||||
QString oauthToken = this->ui_.oauthTokenInput.text();
|
QString oauthToken = this->ui_.oauthTokenInput.text();
|
||||||
|
|
||||||
LogInWithCredentials(userID, username, clientID, oauthToken);
|
logInWithCredentials(userID, username, clientID, oauthToken);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "providers/twitch/api/Kraken.hpp"
|
#include "providers/twitch/api/Kraken.hpp"
|
||||||
#include "singletons/Resources.hpp"
|
#include "singletons/Resources.hpp"
|
||||||
#include "singletons/Settings.hpp"
|
#include "singletons/Settings.hpp"
|
||||||
|
#include "util/Clipboard.hpp"
|
||||||
#include "util/LayoutCreator.hpp"
|
#include "util/LayoutCreator.hpp"
|
||||||
#include "util/PostToThread.hpp"
|
#include "util/PostToThread.hpp"
|
||||||
#include "util/Shortcut.hpp"
|
#include "util/Shortcut.hpp"
|
||||||
|
@ -47,8 +48,8 @@ namespace {
|
||||||
[label = label.getElement()] {
|
[label = label.getElement()] {
|
||||||
auto copyText = label->property("copy-text").toString();
|
auto copyText = label->property("copy-text").toString();
|
||||||
|
|
||||||
qApp->clipboard()->setText(copyText.isEmpty() ? label->getText()
|
crossPlatformCopy(copyText.isEmpty() ? label->getText()
|
||||||
: copyText);
|
: copyText);
|
||||||
});
|
});
|
||||||
|
|
||||||
return label.getElement();
|
return label.getElement();
|
||||||
|
|
Loading…
Reference in a new issue