From dea9f645871b32775f72c0609faa2023660c88b4 Mon Sep 17 00:00:00 2001 From: Cranken Date: Tue, 25 Jul 2017 23:34:24 +0200 Subject: [PATCH] Made links open in the standard browser. --- src/messages/messagebuilder.cpp | 6 ++++-- src/messages/messagebuilder.hpp | 2 ++ src/widgets/chatwidgetview.cpp | 8 +++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/messages/messagebuilder.cpp b/src/messages/messagebuilder.cpp index 091e947a6..aec581b8b 100644 --- a/src/messages/messagebuilder.cpp +++ b/src/messages/messagebuilder.cpp @@ -10,6 +10,8 @@ MessageBuilder::MessageBuilder() : _words() { _parseTime = std::chrono::system_clock::now(); + regex.setPattern("\\bhttps?:\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[A-Z0-9+&@#\/%=~_|]"); + regex.setPatternOptions(QRegularExpression::CaseInsensitiveOption); } SharedMessage MessageBuilder::build() @@ -52,8 +54,8 @@ void MessageBuilder::appendTimestamp(time_t time) QString MessageBuilder::matchLink(const QString &string) { - // TODO: Implement this xD - return QString(); + QRegularExpressionMatch match = regex.match(string); + return match.captured(); } } // namespace messages diff --git a/src/messages/messagebuilder.hpp b/src/messages/messagebuilder.hpp index 8063d6a0c..fddd63169 100644 --- a/src/messages/messagebuilder.hpp +++ b/src/messages/messagebuilder.hpp @@ -3,6 +3,7 @@ #include "messages/message.hpp" #include +#include namespace chatterino { namespace messages { @@ -19,6 +20,7 @@ public: void appendTimestamp(std::time_t time); QString matchLink(const QString &string); + QRegularExpression regex; QString originalMessage; diff --git a/src/widgets/chatwidgetview.cpp b/src/widgets/chatwidgetview.cpp index 1a518163c..b360b4415 100644 --- a/src/widgets/chatwidgetview.cpp +++ b/src/widgets/chatwidgetview.cpp @@ -9,6 +9,7 @@ #include "widgets/chatwidget.hpp" #include +#include #include #include @@ -380,7 +381,7 @@ void ChatWidgetView::mouseReleaseEvent(QMouseEvent *event) auto &link = hoverWord.getLink(); switch (link.getType()) { - case messages::Link::UserInfo: + case messages::Link::UserInfo:{ auto user = message->getMessage()->getUserName(); this->userPopupWidget.setName(user); this->userPopupWidget.move(event->screenPos().toPoint()); @@ -389,6 +390,11 @@ void ChatWidgetView::mouseReleaseEvent(QMouseEvent *event) qDebug() << "Clicked " << user << "s message"; break; + } + case messages::Link::Url:{ + QDesktopServices::openUrl(QUrl(link.getValue())); + break; + } } }