From 5974438edfd13de6ff4e27575a19c918f4e50b0b Mon Sep 17 00:00:00 2001 From: fourtf Date: Mon, 9 Sep 2019 22:26:56 +0200 Subject: [PATCH] added irc tab in SelectChannelView --- src/widgets/dialogs/SelectChannelDialog.cpp | 50 ++++++++++++++++++++- src/widgets/dialogs/SelectChannelDialog.hpp | 5 +++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/widgets/dialogs/SelectChannelDialog.cpp b/src/widgets/dialogs/SelectChannelDialog.cpp index b5af90fe..be077919 100644 --- a/src/widgets/dialogs/SelectChannelDialog.cpp +++ b/src/widgets/dialogs/SelectChannelDialog.cpp @@ -21,6 +21,7 @@ #include "widgets/helper/EditableModelView.hpp" #define TAB_TWITCH 0 +#define TAB_IRC 1 namespace chatterino { @@ -134,7 +135,7 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent) // outerBox.emplace("Connection:"); { - auto view = new EditableModelView( + auto view = this->ui_.irc.servers = new EditableModelView( Irc::getInstance().newConnectionModel(this)); view->setTitles( @@ -170,7 +171,7 @@ SelectChannelDialog::SelectChannelDialog(QWidget *parent) { auto box = outerBox.emplace().withoutMargin(); box.emplace("Channel:"); - box.emplace(); + this->ui_.irc.channel = box.emplace().getElement(); } // auto vbox = obj.setLayoutType(); @@ -261,6 +262,30 @@ void SelectChannelDialog::setSelectedChannel(IndirectChannel _channel) this->ui_.twitch.whispers->setFocus(); } break; + case Channel::Type::Irc: + { + this->ui_.notebook->selectIndex(TAB_IRC); + this->ui_.irc.channel->setText(_channel.get()->getName()); + + if (auto ircChannel = + dynamic_cast(_channel.get().get())) + { + if (auto server = + Irc::getInstance().getServerOfChannel(ircChannel)) + { + int i = 0; + for (auto &&conn : Irc::getInstance().connections) + { + if (conn.id == server->getId()) + { + this->ui_.irc.servers->getTableView()->selectRow(i); + break; + } + } + } + } + } + break; default: { this->ui_.notebook->selectIndex(TAB_TWITCH); @@ -302,6 +327,27 @@ IndirectChannel SelectChannelDialog::getSelectedChannel() const return app->twitch.server->whispersChannel; } } + break; + case TAB_IRC: + { + int row = this->ui_.irc.servers->getTableView() + ->selectionModel() + ->currentIndex() + .row(); + + auto &&vector = Irc::getInstance().connections.getVector(); + + if (row >= 0 && row < int(vector.size())) + { + return Irc::getInstance().getOrAddChannel( + vector[row].id, this->ui_.irc.channel->text()); + } + else + { + return Channel::getEmpty(); + } + } + break; } return this->selectedChannel_; diff --git a/src/widgets/dialogs/SelectChannelDialog.hpp b/src/widgets/dialogs/SelectChannelDialog.hpp index 5d5890d9..51944ce7 100644 --- a/src/widgets/dialogs/SelectChannelDialog.hpp +++ b/src/widgets/dialogs/SelectChannelDialog.hpp @@ -12,6 +12,7 @@ namespace chatterino { class Notebook; +class EditableModelView; class SelectChannelDialog final : public BaseWindow { @@ -47,6 +48,10 @@ private: QRadioButton *mentions; QRadioButton *watching; } twitch; + struct { + QLineEdit *channel; + EditableModelView *servers; + } irc; } ui_; EventFilter tabFilter_;