summary refs log tree commit diff
path: root/src/ui
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-05-13 08:52:02 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2021-05-13 08:53:56 +0200
commit22afa122c4697d25fd2f1eb4c7931bcf4ea43f31 (patch)
tree9025b1e8aa07821b65a92640289e8e6efaaeefef /src/ui
parentMake palette global in Qml (diff)
downloadnheko-22afa122c4697d25fd2f1eb4c7931bcf4ea43f31.tar.xz
Move openLink to Nheko globals
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/NhekoGlobalObject.cpp54
-rw-r--r--src/ui/NhekoGlobalObject.h3
2 files changed, 57 insertions, 0 deletions
diff --git a/src/ui/NhekoGlobalObject.cpp b/src/ui/NhekoGlobalObject.cpp

index 5a2b9788..e5e6825e 100644 --- a/src/ui/NhekoGlobalObject.cpp +++ b/src/ui/NhekoGlobalObject.cpp
@@ -4,6 +4,10 @@ #include "NhekoGlobalObject.h" +#include <QDesktopServices> +#include <QUrl> + +#include "ChatPage.h" #include "UserSettingsPage.h" Nheko::Nheko() @@ -25,3 +29,53 @@ Nheko::inactiveColors() const p.setCurrentColorGroup(QPalette::ColorGroup::Inactive); return p; } + +void +Nheko::openLink(QString link) const +{ + QUrl url(link); + if (url.scheme() == "https" && url.host() == "matrix.to") { + // handle matrix.to links internally + QString p = url.fragment(QUrl::FullyEncoded); + if (p.startsWith("/")) + p.remove(0, 1); + + auto temp = p.split("?"); + QString query; + if (temp.size() >= 2) + query = QUrl::fromPercentEncoding(temp.takeAt(1).toUtf8()); + + temp = temp.first().split("/"); + auto identifier = QUrl::fromPercentEncoding(temp.takeFirst().toUtf8()); + QString eventId = QUrl::fromPercentEncoding(temp.join('/').toUtf8()); + if (!identifier.isEmpty()) { + if (identifier.startsWith("@")) { + QByteArray uri = + "matrix:u/" + QUrl::toPercentEncoding(identifier.remove(0, 1)); + if (!query.isEmpty()) + uri.append("?" + query.toUtf8()); + ChatPage::instance()->handleMatrixUri(QUrl::fromEncoded(uri)); + } else if (identifier.startsWith("#")) { + QByteArray uri = + "matrix:r/" + QUrl::toPercentEncoding(identifier.remove(0, 1)); + if (!eventId.isEmpty()) + uri.append("/e/" + + QUrl::toPercentEncoding(eventId.remove(0, 1))); + if (!query.isEmpty()) + uri.append("?" + query.toUtf8()); + ChatPage::instance()->handleMatrixUri(QUrl::fromEncoded(uri)); + } else if (identifier.startsWith("!")) { + QByteArray uri = "matrix:roomid/" + + QUrl::toPercentEncoding(identifier.remove(0, 1)); + if (!eventId.isEmpty()) + uri.append("/e/" + + QUrl::toPercentEncoding(eventId.remove(0, 1))); + if (!query.isEmpty()) + uri.append("?" + query.toUtf8()); + ChatPage::instance()->handleMatrixUri(QUrl::fromEncoded(uri)); + } + } + } else { + QDesktopServices::openUrl(url); + } +} diff --git a/src/ui/NhekoGlobalObject.h b/src/ui/NhekoGlobalObject.h
index 76186828..05a0c050 100644 --- a/src/ui/NhekoGlobalObject.h +++ b/src/ui/NhekoGlobalObject.h
@@ -20,6 +20,9 @@ public: QPalette colors() const; QPalette inactiveColors() const; + Q_INVOKABLE void openLink(QString link) const; + signals: void colorsChanged(); }; +