mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
added irc authentificate type
This commit is contained in:
parent
9bbc4f8a5e
commit
2a56cef848
5 changed files with 49 additions and 33 deletions
|
@ -89,8 +89,7 @@ void AbstractIrcServer::connect()
|
||||||
|
|
||||||
void AbstractIrcServer::open(ConnectionType type)
|
void AbstractIrcServer::open(ConnectionType type)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock1(this->connectionMutex_);
|
std::lock_guard<std::mutex> lock(this->connectionMutex_);
|
||||||
std::lock_guard<std::mutex> lock2(this->channelMutex);
|
|
||||||
|
|
||||||
if (type == Write)
|
if (type == Write)
|
||||||
{
|
{
|
||||||
|
@ -98,13 +97,6 @@ void AbstractIrcServer::open(ConnectionType type)
|
||||||
}
|
}
|
||||||
if (type & Read)
|
if (type & Read)
|
||||||
{
|
{
|
||||||
for (std::weak_ptr<Channel> &weak : this->channels.values())
|
|
||||||
{
|
|
||||||
if (auto channel = weak.lock())
|
|
||||||
{
|
|
||||||
this->readConnection_->sendRaw("JOIN #" + channel->getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this->readConnection_->open();
|
this->readConnection_->open();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ namespace {
|
||||||
row[3]->data(Qt::EditRole).toString(), // user
|
row[3]->data(Qt::EditRole).toString(), // user
|
||||||
row[4]->data(Qt::EditRole).toString(), // nick
|
row[4]->data(Qt::EditRole).toString(), // nick
|
||||||
row[5]->data(Qt::EditRole).toString(), // real
|
row[5]->data(Qt::EditRole).toString(), // real
|
||||||
|
original.authType, // authType
|
||||||
original.connectCommands, // connectCommands
|
original.connectCommands, // connectCommands
|
||||||
original.id, // id
|
original.id, // id
|
||||||
};
|
};
|
||||||
|
@ -203,6 +204,8 @@ void Irc::save()
|
||||||
obj.insert("connectCommands",
|
obj.insert("connectCommands",
|
||||||
QJsonArray::fromStringList(conn.connectCommands));
|
QJsonArray::fromStringList(conn.connectCommands));
|
||||||
obj.insert("id", conn.id);
|
obj.insert("id", conn.id);
|
||||||
|
obj.insert("authType", int(conn.authType));
|
||||||
|
|
||||||
servers.append(obj);
|
servers.append(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,6 +245,8 @@ void Irc::load()
|
||||||
data.connectCommands =
|
data.connectCommands =
|
||||||
obj.value("connectCommands").toVariant().toStringList();
|
obj.value("connectCommands").toVariant().toStringList();
|
||||||
data.id = obj.value("id").toInt(data.id);
|
data.id = obj.value("id").toInt(data.id);
|
||||||
|
data.authType =
|
||||||
|
IrcAuthType(obj.value("authType").toInt(int(data.authType)));
|
||||||
|
|
||||||
// duplicate id's are not allowed :(
|
// duplicate id's are not allowed :(
|
||||||
if (ids.find(data.id) == ids.end())
|
if (ids.find(data.id) == ids.end())
|
||||||
|
|
|
@ -21,7 +21,7 @@ struct IrcServerData {
|
||||||
QString nick;
|
QString nick;
|
||||||
QString real;
|
QString real;
|
||||||
|
|
||||||
// IrcAuthType authType = Anonymous;
|
IrcAuthType authType = IrcAuthType::Anonymous;
|
||||||
void getPassword(QObject *receiver,
|
void getPassword(QObject *receiver,
|
||||||
std::function<void(const QString &)> &&onLoaded) const;
|
std::function<void(const QString &)> &&onLoaded) const;
|
||||||
void setPassword(const QString &password);
|
void setPassword(const QString &password);
|
||||||
|
|
|
@ -63,17 +63,24 @@ void IrcServer::initializeConnection(IrcConnection *connection,
|
||||||
connection->setRealName(this->data_->real.isEmpty() ? this->data_->user
|
connection->setRealName(this->data_->real.isEmpty() ? this->data_->user
|
||||||
: this->data_->nick);
|
: this->data_->nick);
|
||||||
|
|
||||||
this->data_->getPassword(
|
if (this->data_->authType == IrcAuthType::Pass)
|
||||||
this, [conn = new QObjectRef(connection) /* can't copy */,
|
{
|
||||||
this](const QString &password) mutable {
|
this->data_->getPassword(
|
||||||
if (*conn)
|
this, [conn = new QObjectRef(connection) /* can't copy */,
|
||||||
{
|
this](const QString &password) mutable {
|
||||||
(*conn)->setPassword(password);
|
if (*conn)
|
||||||
this->open(Both);
|
{
|
||||||
}
|
(*conn)->setPassword(password);
|
||||||
|
this->open(Both);
|
||||||
|
}
|
||||||
|
|
||||||
delete conn;
|
delete conn;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->open(Both);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Channel> IrcServer::createChannel(const QString &channelName)
|
std::shared_ptr<Channel> IrcServer::createChannel(const QString &channelName)
|
||||||
|
|
|
@ -33,23 +33,24 @@ IrcConnectionEditor::IrcConnectionEditor(const IrcServerData &data, bool isAdd,
|
||||||
this->ui_->passwordLineEdit->setText(password);
|
this->ui_->passwordLineEdit->setText(password);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this->ui_->loginMethodComboBox->setCurrentIndex([&] {
|
||||||
|
switch (data.authType)
|
||||||
|
{
|
||||||
|
case IrcAuthType::Custom:
|
||||||
|
return 1;
|
||||||
|
case IrcAuthType::Pass:
|
||||||
|
return 2;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}());
|
||||||
|
|
||||||
QObject::connect(this->ui_->loginMethodComboBox,
|
QObject::connect(this->ui_->loginMethodComboBox,
|
||||||
qOverload<int>(&QComboBox::currentIndexChanged), this,
|
qOverload<int>(&QComboBox::currentIndexChanged), this,
|
||||||
[this](int index) {
|
[this](int index) {
|
||||||
IrcAuthType type;
|
if (index == 1) // Custom
|
||||||
|
|
||||||
switch (index)
|
|
||||||
{
|
{
|
||||||
case 0: // anonymous
|
this->ui_->connectCommandsEditor->setFocus();
|
||||||
type = IrcAuthType::Anonymous;
|
|
||||||
break;
|
|
||||||
case 1: // custom
|
|
||||||
this->ui_->connectCommandsEditor->setFocus();
|
|
||||||
type = IrcAuthType::Custom;
|
|
||||||
break;
|
|
||||||
case 2: // PASS
|
|
||||||
type = IrcAuthType::Pass;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -75,6 +76,17 @@ IrcServerData IrcConnectionEditor::data()
|
||||||
data.connectCommands =
|
data.connectCommands =
|
||||||
this->ui_->connectCommandsEditor->toPlainText().split('\n');
|
this->ui_->connectCommandsEditor->toPlainText().split('\n');
|
||||||
data.setPassword(this->ui_->passwordLineEdit->text());
|
data.setPassword(this->ui_->passwordLineEdit->text());
|
||||||
|
data.authType = [this] {
|
||||||
|
switch (this->ui_->loginMethodComboBox->currentIndex())
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
return IrcAuthType::Custom;
|
||||||
|
case 2:
|
||||||
|
return IrcAuthType::Pass;
|
||||||
|
default:
|
||||||
|
return IrcAuthType::Anonymous;
|
||||||
|
}
|
||||||
|
}();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue