From 9a6650b56ce6ce49e5c6536443daa341cbc81045 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 21 Sep 2018 21:35:14 +0300 Subject: [PATCH] Added button in menu to join to channel. (#724) --- src/widgets/helper/ChannelView.cpp | 19 +++++++++++++++++++ src/widgets/helper/ChannelView.hpp | 1 + src/widgets/splits/Split.cpp | 5 +++++ src/widgets/splits/SplitContainer.cpp | 4 +++- src/widgets/splits/SplitContainer.hpp | 2 +- 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index 6ba65b311..05462a59e 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -1126,6 +1126,25 @@ void ChannelView::addContextMenuItems( QGuiApplication::clipboard()->setText(copyString); }); + // Join to channel + if (hoveredElement->getLink().type == Link::Url) { + static QRegularExpression twitchChannelRegex( + R"(^(?:https?:\/\/)?(?:www\.|go\.)?twitch\.tv\/(?[a-z0-9_]+))", + QRegularExpression::CaseInsensitiveOption); + + auto twitchMatch = twitchChannelRegex.match( + hoveredElement->getLink().value); + auto twitchUsername = twitchMatch.captured("username"); + if (!twitchUsername.isEmpty() && + twitchUsername != "settings" && + twitchUsername != "videos") { + menu->addSeparator(); + menu->addAction("Join to channel", [twitchUsername, this] { + this->joinToChannel.invoke(twitchUsername); + }); + } + } + menu->popup(QCursor::pos()); menu->raise(); diff --git a/src/widgets/helper/ChannelView.hpp b/src/widgets/helper/ChannelView.hpp index 46e51bebe..e34c0dc85 100644 --- a/src/widgets/helper/ChannelView.hpp +++ b/src/widgets/helper/ChannelView.hpp @@ -61,6 +61,7 @@ public: pajlada::Signals::NoArgSignal selectionChanged; pajlada::Signals::Signal tabHighlightRequested; pajlada::Signals::Signal linkClicked; + pajlada::Signals::Signal joinToChannel; protected: void themeChangedEvent() override; diff --git a/src/widgets/splits/Split.cpp b/src/widgets/splits/Split.cpp index 276cd87d9..c5cd73cc1 100644 --- a/src/widgets/splits/Split.cpp +++ b/src/widgets/splits/Split.cpp @@ -105,6 +105,11 @@ Split::Split(QWidget *parent) } }); + this->view_->joinToChannel.connect([this](QString twitchChannel) { + this->container_->appendNewSplit(false)->setChannel( + getApp()->twitch.server->getOrAddChannel(twitchChannel)); + }); + this->input_->textChanged.connect([=](const QString &newText) { if (getSettings()->showEmptyInput) { return; diff --git a/src/widgets/splits/SplitContainer.cpp b/src/widgets/splits/SplitContainer.cpp index 58e2eb953..bc79317bf 100644 --- a/src/widgets/splits/SplitContainer.cpp +++ b/src/widgets/splits/SplitContainer.cpp @@ -101,7 +101,7 @@ void SplitContainer::resetMouseStatus() this->update(); } -void SplitContainer::appendNewSplit(bool openChannelNameDialog) +Split* SplitContainer::appendNewSplit(bool openChannelNameDialog) { assertInGuiThread(); @@ -115,6 +115,8 @@ void SplitContainer::appendNewSplit(bool openChannelNameDialog) } }); } + + return split; } void SplitContainer::appendSplit(Split *split) diff --git a/src/widgets/splits/SplitContainer.hpp b/src/widgets/splits/SplitContainer.hpp index 1f90e99aa..33604ba7a 100644 --- a/src/widgets/splits/SplitContainer.hpp +++ b/src/widgets/splits/SplitContainer.hpp @@ -171,7 +171,7 @@ private: public: SplitContainer(Notebook *parent); - void appendNewSplit(bool openChannelNameDialog); + Split* appendNewSplit(bool openChannelNameDialog); void appendSplit(Split *split); void insertSplit(Split *split, const Position &position); void insertSplit(Split *split, Direction direction, Split *relativeTo);