mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Implement stupid account manager
After logging in, you need to restart chatterino
This commit is contained in:
parent
1296aac245
commit
467ca90fd8
8 changed files with 176 additions and 7 deletions
|
@ -96,7 +96,8 @@ SOURCES += \
|
|||
src/messagefactory.cpp \
|
||||
src/widgets/basewidget.cpp \
|
||||
src/widgets/resizingtextedit.cpp \
|
||||
src/completionmanager.cpp
|
||||
src/completionmanager.cpp \
|
||||
src/widgets/logindialog.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/asyncexec.hpp \
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "accountmanager.hpp"
|
||||
#include "common.hpp"
|
||||
|
||||
#include <pajlada/settings/setting.hpp>
|
||||
|
||||
|
@ -32,6 +33,34 @@ AccountManager::AccountManager()
|
|||
"/accounts/current/roomID", "11148817", pajlada::Settings::SettingOption::DoNotWriteToJSON);
|
||||
}
|
||||
|
||||
void AccountManager::load()
|
||||
{
|
||||
auto keys = pajlada::Settings::SettingManager::getObjectKeys("/accounts");
|
||||
|
||||
for (const auto &uid : keys) {
|
||||
if (uid == "current") {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string username =
|
||||
pajlada::Settings::Setting<std::string>::get("/accounts/" + uid + "/username");
|
||||
std::string userID =
|
||||
pajlada::Settings::Setting<std::string>::get("/accounts/" + uid + "/userID");
|
||||
std::string clientID =
|
||||
pajlada::Settings::Setting<std::string>::get("/accounts/" + uid + "/clientID");
|
||||
std::string oauthToken =
|
||||
pajlada::Settings::Setting<std::string>::get("/accounts/" + uid + "/oauthToken");
|
||||
|
||||
if (username.empty() || userID.empty() || clientID.empty() || oauthToken.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
twitch::TwitchUser user(qS(username), qS(oauthToken), qS(clientID));
|
||||
|
||||
this->addTwitchUser(user);
|
||||
}
|
||||
}
|
||||
|
||||
twitch::TwitchUser &AccountManager::getTwitchAnon()
|
||||
{
|
||||
return this->twitchAnonymousUser;
|
||||
|
|
|
@ -16,6 +16,8 @@ public:
|
|||
return instance;
|
||||
}
|
||||
|
||||
void load();
|
||||
|
||||
twitch::TwitchUser &getTwitchAnon();
|
||||
|
||||
// Returns first user from twitchUsers, or twitchAnonymousUser if twitchUsers is empty
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "application.hpp"
|
||||
#include "accountmanager.hpp"
|
||||
#include "colorscheme.hpp"
|
||||
#include "logging/loggingmanager.hpp"
|
||||
#include "settingsmanager.hpp"
|
||||
|
@ -25,6 +26,10 @@ Application::Application()
|
|||
// Initialize everything we need
|
||||
this->emoteManager.loadGlobalEmotes();
|
||||
|
||||
AccountManager::getInstance().load();
|
||||
|
||||
this->ircManager.setUser(AccountManager::getInstance().getTwitchUser());
|
||||
|
||||
// XXX
|
||||
SettingsManager::getInstance().updateWordTypeMask();
|
||||
|
||||
|
|
|
@ -68,6 +68,9 @@ Communi::IrcConnection *IrcManager::createConnection(bool doRead)
|
|||
QString username = _account.getUserName();
|
||||
QString oauthClient = _account.getOAuthClient();
|
||||
QString oauthToken = _account.getOAuthToken();
|
||||
if (!oauthToken.startsWith("oauth:")) {
|
||||
oauthToken.prepend("oauth:");
|
||||
}
|
||||
|
||||
connection->setUserName(username);
|
||||
connection->setNickName(username);
|
||||
|
|
85
src/widgets/logindialog.cpp
Normal file
85
src/widgets/logindialog.cpp
Normal file
|
@ -0,0 +1,85 @@
|
|||
#include "widgets/logindialog.hpp"
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QDebug>
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
#include <pajlada/settings/setting.hpp>
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
LoginWidget::LoginWidget()
|
||||
{
|
||||
this->setLayout(&this->ui.mainLayout);
|
||||
|
||||
this->ui.loginButton.setText("Log in (Opens in browser)");
|
||||
this->ui.pasteCodeButton.setText("Paste code");
|
||||
|
||||
this->ui.horizontalLayout.addWidget(&this->ui.loginButton);
|
||||
this->ui.horizontalLayout.addWidget(&this->ui.pasteCodeButton);
|
||||
|
||||
this->ui.verticalLayout.addLayout(&this->ui.horizontalLayout);
|
||||
|
||||
this->ui.mainLayout.addLayout(&this->ui.verticalLayout);
|
||||
|
||||
this->ui.buttonBox.setStandardButtons(QDialogButtonBox::Close);
|
||||
|
||||
this->ui.mainLayout.addWidget(&this->ui.buttonBox);
|
||||
|
||||
connect(&this->ui.buttonBox, &QDialogButtonBox::rejected, [this]() {
|
||||
this->close(); //
|
||||
});
|
||||
|
||||
connect(&this->ui.loginButton, &QPushButton::clicked, [this]() {
|
||||
printf("open login in browser\n");
|
||||
QDesktopServices::openUrl(QUrl("https://pajlada.se/chatterino/#chatterino"));
|
||||
|
||||
});
|
||||
|
||||
connect(&this->ui.pasteCodeButton, &QPushButton::clicked, [this]() {
|
||||
QClipboard *clipboard = QGuiApplication::clipboard();
|
||||
QString clipboardString = clipboard->text();
|
||||
QStringList parameters = clipboardString.split(';');
|
||||
|
||||
std::string oauthToken, clientID, username, userID;
|
||||
|
||||
for (const auto ¶m : parameters) {
|
||||
QStringList kvParameters = param.split('=');
|
||||
if (kvParameters.size() != 2) {
|
||||
continue;
|
||||
}
|
||||
QString key = kvParameters[0];
|
||||
QString value = kvParameters[1];
|
||||
|
||||
if (key == "oauth_token") {
|
||||
oauthToken = value.toStdString();
|
||||
} else if (key == "client_id") {
|
||||
clientID = value.toStdString();
|
||||
} else if (key == "username") {
|
||||
username = value.toStdString();
|
||||
} else if (key == "user_id") {
|
||||
userID = value.toStdString();
|
||||
} else {
|
||||
qDebug() << "Unknown key in code: " << key;
|
||||
}
|
||||
}
|
||||
|
||||
if (oauthToken.empty() || clientID.empty() || username.empty() || userID.empty()) {
|
||||
qDebug() << "Missing variables!!!!!!!!!";
|
||||
} else {
|
||||
qDebug() << "Success! mr";
|
||||
pajlada::Settings::Setting<std::string>::set("/accounts/uid" + userID + "/username",
|
||||
username);
|
||||
pajlada::Settings::Setting<std::string>::set("/accounts/uid" + userID + "/userID",
|
||||
userID);
|
||||
pajlada::Settings::Setting<std::string>::set("/accounts/uid" + userID + "/clientID",
|
||||
clientID);
|
||||
pajlada::Settings::Setting<std::string>::set("/accounts/uid" + userID + "/oauthToken",
|
||||
oauthToken);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
37
src/widgets/logindialog.hpp
Normal file
37
src/widgets/logindialog.hpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
#pragma once
|
||||
|
||||
#include "widgets/basewidget.hpp"
|
||||
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtWidgets/QAction>
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QtWidgets/QButtonGroup>
|
||||
#include <QtWidgets/QDialog>
|
||||
#include <QtWidgets/QDialogButtonBox>
|
||||
#include <QtWidgets/QHBoxLayout>
|
||||
#include <QtWidgets/QHeaderView>
|
||||
#include <QtWidgets/QPushButton>
|
||||
#include <QtWidgets/QVBoxLayout>
|
||||
|
||||
namespace chatterino {
|
||||
namespace widgets {
|
||||
|
||||
class LoginWidget : public QDialog
|
||||
{
|
||||
public:
|
||||
LoginWidget();
|
||||
|
||||
private:
|
||||
struct {
|
||||
QVBoxLayout mainLayout;
|
||||
|
||||
QVBoxLayout verticalLayout;
|
||||
QHBoxLayout horizontalLayout;
|
||||
QPushButton loginButton;
|
||||
QPushButton pasteCodeButton;
|
||||
QDialogButtonBox buttonBox;
|
||||
} ui;
|
||||
};
|
||||
|
||||
} // namespace widgets
|
||||
} // namespace chatterino
|
|
@ -2,6 +2,7 @@
|
|||
#include "accountmanager.hpp"
|
||||
#include "twitch/twitchmessagebuilder.hpp"
|
||||
#include "twitch/twitchuser.hpp"
|
||||
#include "widgets/logindialog.hpp"
|
||||
#include "widgets/settingsdialogtab.hpp"
|
||||
#include "windowmanager.hpp"
|
||||
|
||||
|
@ -80,8 +81,18 @@ void SettingsDialog::addTabs()
|
|||
// add remove buttons
|
||||
auto buttonBox = new QDialogButtonBox(this);
|
||||
|
||||
auto addButton = new QPushButton("add", this);
|
||||
auto removeButton = new QPushButton("remove", this);
|
||||
auto addButton = new QPushButton("Add", this);
|
||||
auto removeButton = new QPushButton("Remove", this);
|
||||
|
||||
connect(addButton, &QPushButton::clicked, []() {
|
||||
// TODO: fix memory leak :bbaper:
|
||||
auto loginWidget = new LoginWidget();
|
||||
loginWidget->show();
|
||||
});
|
||||
|
||||
connect(removeButton, &QPushButton::clicked, []() {
|
||||
qDebug() << "TODO: Implement"; //
|
||||
});
|
||||
|
||||
buttonBox->addButton(addButton, QDialogButtonBox::YesRole);
|
||||
buttonBox->addButton(removeButton, QDialogButtonBox::NoRole);
|
||||
|
@ -91,10 +102,6 @@ void SettingsDialog::addTabs()
|
|||
// listview
|
||||
auto listWidget = new QListWidget(this);
|
||||
|
||||
listWidget->addItem("xD");
|
||||
listWidget->addItem("vi von");
|
||||
listWidget->addItem("monkaS");
|
||||
|
||||
for (auto &user : AccountManager::getInstance().getTwitchUsers()) {
|
||||
listWidget->addItem(user.getUserName());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue