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)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock1(this->connectionMutex_);
|
||||
std::lock_guard<std::mutex> lock2(this->channelMutex);
|
||||
std::lock_guard<std::mutex> lock(this->connectionMutex_);
|
||||
|
||||
if (type == Write)
|
||||
{
|
||||
|
@ -98,13 +97,6 @@ void AbstractIrcServer::open(ConnectionType type)
|
|||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ namespace {
|
|||
row[3]->data(Qt::EditRole).toString(), // user
|
||||
row[4]->data(Qt::EditRole).toString(), // nick
|
||||
row[5]->data(Qt::EditRole).toString(), // real
|
||||
original.authType, // authType
|
||||
original.connectCommands, // connectCommands
|
||||
original.id, // id
|
||||
};
|
||||
|
@ -203,6 +204,8 @@ void Irc::save()
|
|||
obj.insert("connectCommands",
|
||||
QJsonArray::fromStringList(conn.connectCommands));
|
||||
obj.insert("id", conn.id);
|
||||
obj.insert("authType", int(conn.authType));
|
||||
|
||||
servers.append(obj);
|
||||
}
|
||||
|
||||
|
@ -242,6 +245,8 @@ void Irc::load()
|
|||
data.connectCommands =
|
||||
obj.value("connectCommands").toVariant().toStringList();
|
||||
data.id = obj.value("id").toInt(data.id);
|
||||
data.authType =
|
||||
IrcAuthType(obj.value("authType").toInt(int(data.authType)));
|
||||
|
||||
// duplicate id's are not allowed :(
|
||||
if (ids.find(data.id) == ids.end())
|
||||
|
|
|
@ -21,7 +21,7 @@ struct IrcServerData {
|
|||
QString nick;
|
||||
QString real;
|
||||
|
||||
// IrcAuthType authType = Anonymous;
|
||||
IrcAuthType authType = IrcAuthType::Anonymous;
|
||||
void getPassword(QObject *receiver,
|
||||
std::function<void(const QString &)> &&onLoaded) const;
|
||||
void setPassword(const QString &password);
|
||||
|
|
|
@ -63,17 +63,24 @@ void IrcServer::initializeConnection(IrcConnection *connection,
|
|||
connection->setRealName(this->data_->real.isEmpty() ? this->data_->user
|
||||
: this->data_->nick);
|
||||
|
||||
this->data_->getPassword(
|
||||
this, [conn = new QObjectRef(connection) /* can't copy */,
|
||||
this](const QString &password) mutable {
|
||||
if (*conn)
|
||||
{
|
||||
(*conn)->setPassword(password);
|
||||
this->open(Both);
|
||||
}
|
||||
if (this->data_->authType == IrcAuthType::Pass)
|
||||
{
|
||||
this->data_->getPassword(
|
||||
this, [conn = new QObjectRef(connection) /* can't copy */,
|
||||
this](const QString &password) mutable {
|
||||
if (*conn)
|
||||
{
|
||||
(*conn)->setPassword(password);
|
||||
this->open(Both);
|
||||
}
|
||||
|
||||
delete conn;
|
||||
});
|
||||
delete conn;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
this->open(Both);
|
||||
}
|
||||
}
|
||||
|
||||
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_->loginMethodComboBox->setCurrentIndex([&] {
|
||||
switch (data.authType)
|
||||
{
|
||||
case IrcAuthType::Custom:
|
||||
return 1;
|
||||
case IrcAuthType::Pass:
|
||||
return 2;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}());
|
||||
|
||||
QObject::connect(this->ui_->loginMethodComboBox,
|
||||
qOverload<int>(&QComboBox::currentIndexChanged), this,
|
||||
[this](int index) {
|
||||
IrcAuthType type;
|
||||
|
||||
switch (index)
|
||||
if (index == 1) // Custom
|
||||
{
|
||||
case 0: // anonymous
|
||||
type = IrcAuthType::Anonymous;
|
||||
break;
|
||||
case 1: // custom
|
||||
this->ui_->connectCommandsEditor->setFocus();
|
||||
type = IrcAuthType::Custom;
|
||||
break;
|
||||
case 2: // PASS
|
||||
type = IrcAuthType::Pass;
|
||||
break;
|
||||
this->ui_->connectCommandsEditor->setFocus();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -75,6 +76,17 @@ IrcServerData IrcConnectionEditor::data()
|
|||
data.connectCommands =
|
||||
this->ui_->connectCommandsEditor->toPlainText().split('\n');
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue