From 2a56cef84824a9810c49e9c39f13066d75c7085c Mon Sep 17 00:00:00 2001 From: fourtf Date: Sun, 15 Sep 2019 11:35:17 +0200 Subject: [PATCH] added irc authentificate type --- src/providers/irc/AbstractIrcServer.cpp | 10 +----- src/providers/irc/Irc2.cpp | 5 +++ src/providers/irc/Irc2.hpp | 2 +- src/providers/irc/IrcServer.cpp | 27 +++++++++------ src/widgets/dialogs/IrcConnectionEditor.cpp | 38 ++++++++++++++------- 5 files changed, 49 insertions(+), 33 deletions(-) diff --git a/src/providers/irc/AbstractIrcServer.cpp b/src/providers/irc/AbstractIrcServer.cpp index 31a7688f4..30952a6d3 100644 --- a/src/providers/irc/AbstractIrcServer.cpp +++ b/src/providers/irc/AbstractIrcServer.cpp @@ -89,8 +89,7 @@ void AbstractIrcServer::connect() void AbstractIrcServer::open(ConnectionType type) { - std::lock_guard lock1(this->connectionMutex_); - std::lock_guard lock2(this->channelMutex); + std::lock_guard lock(this->connectionMutex_); if (type == Write) { @@ -98,13 +97,6 @@ void AbstractIrcServer::open(ConnectionType type) } if (type & Read) { - for (std::weak_ptr &weak : this->channels.values()) - { - if (auto channel = weak.lock()) - { - this->readConnection_->sendRaw("JOIN #" + channel->getName()); - } - } this->readConnection_->open(); } } diff --git a/src/providers/irc/Irc2.cpp b/src/providers/irc/Irc2.cpp index 5a985803f..7409ac986 100644 --- a/src/providers/irc/Irc2.cpp +++ b/src/providers/irc/Irc2.cpp @@ -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()) diff --git a/src/providers/irc/Irc2.hpp b/src/providers/irc/Irc2.hpp index 6ca6b0c8b..a15a0fcb8 100644 --- a/src/providers/irc/Irc2.hpp +++ b/src/providers/irc/Irc2.hpp @@ -21,7 +21,7 @@ struct IrcServerData { QString nick; QString real; - // IrcAuthType authType = Anonymous; + IrcAuthType authType = IrcAuthType::Anonymous; void getPassword(QObject *receiver, std::function &&onLoaded) const; void setPassword(const QString &password); diff --git a/src/providers/irc/IrcServer.cpp b/src/providers/irc/IrcServer.cpp index 9692698c1..a0f5907fa 100644 --- a/src/providers/irc/IrcServer.cpp +++ b/src/providers/irc/IrcServer.cpp @@ -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 IrcServer::createChannel(const QString &channelName) diff --git a/src/widgets/dialogs/IrcConnectionEditor.cpp b/src/widgets/dialogs/IrcConnectionEditor.cpp index 0fbf46208..1adfdf295 100644 --- a/src/widgets/dialogs/IrcConnectionEditor.cpp +++ b/src/widgets/dialogs/IrcConnectionEditor.cpp @@ -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(&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; }