Added button in menu to join to channel. (#724)

This commit is contained in:
23rd 2018-09-21 21:35:14 +03:00 committed by pajlada
parent a3a7317e62
commit 9a6650b56c
5 changed files with 29 additions and 2 deletions

View file

@ -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\/(?<username>[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();

View file

@ -61,6 +61,7 @@ public:
pajlada::Signals::NoArgSignal selectionChanged;
pajlada::Signals::Signal<HighlightState> tabHighlightRequested;
pajlada::Signals::Signal<const Link &> linkClicked;
pajlada::Signals::Signal<QString> joinToChannel;
protected:
void themeChangedEvent() override;

View file

@ -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;

View file

@ -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)

View file

@ -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);