Fix activating browser windows on Wayland
QDesktopServices::openUrl does not have XDG activation support yet so it can't raise an existing browser window when opening URLs Instead use KIO::OpenUrlJob, which does support that
This commit is contained in:
@@ -20,7 +20,7 @@ LoginStep {
|
|||||||
Connections {
|
Connections {
|
||||||
target: LoginHelper
|
target: LoginHelper
|
||||||
function onSsoUrlChanged() {
|
function onSsoUrlChanged() {
|
||||||
Qt.openUrlExternally(LoginHelper.ssoUrl)
|
UrlHelper.openUrl(LoginHelper.ssoUrl)
|
||||||
}
|
}
|
||||||
function onConnected() {
|
function onConnected() {
|
||||||
processed("qrc:/imports/NeoChat/Component/Login/Loading.qml")
|
processed("qrc:/imports/NeoChat/Component/Login/Loading.qml")
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ TimelineContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function openSavedFile() {
|
function openSavedFile() {
|
||||||
if (Qt.openUrlExternally(progressInfo.localPath)) return;
|
if (UrlHelper.openUrl(progressInfo.localPath)) return;
|
||||||
if (Qt.openUrlExternally(progressInfo.localDir)) return;
|
if (UrlHelper.openUrl(progressInfo.localDir)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
innerObject: RowLayout {
|
innerObject: RowLayout {
|
||||||
|
|||||||
@@ -115,8 +115,8 @@ TimelineContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function openSavedFile() {
|
function openSavedFile() {
|
||||||
if (Qt.openUrlExternally(progressInfo.localPath)) return;
|
if (UrlHelper.openUrl(progressInfo.localPath)) return;
|
||||||
if (Qt.openUrlExternally(progressInfo.localDir)) return;
|
if (UrlHelper.openUrl(progressInfo.localDir)) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ Labs.MenuBar {
|
|||||||
|
|
||||||
Labs.MenuItem {
|
Labs.MenuItem {
|
||||||
text: i18nc("menu", "Matrix FAQ")
|
text: i18nc("menu", "Matrix FAQ")
|
||||||
onTriggered: Qt.openUrlExternally("https://matrix.org/faq/")
|
onTriggered: UrlHelper.openUrl("https://matrix.org/faq/")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,13 +24,13 @@ MessageDelegateContextMenu {
|
|||||||
icon.name: "document-open"
|
icon.name: "document-open"
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
if (file.downloaded) {
|
if (file.downloaded) {
|
||||||
if (!Qt.openUrlExternally(progressInfo.localPath)) {
|
if (!UrlHelper.openUrl(progressInfo.localPath)) {
|
||||||
Qt.openUrlExternally(progressInfo.localDir);
|
UrlHelper.openUrl(progressInfo.localDir);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
file.onDownloadedChanged.connect(function() {
|
file.onDownloadedChanged.connect(function() {
|
||||||
if (!Qt.openUrlExternally(progressInfo.localPath)) {
|
if (!UrlHelper.openUrl(progressInfo.localPath)) {
|
||||||
Qt.openUrlExternally(progressInfo.localDir);
|
UrlHelper.openUrl(progressInfo.localDir);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
currentRoom.downloadFile(eventId, StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(eventId))
|
currentRoom.downloadFile(eventId, StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(eventId))
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ Kirigami.OverlayDrawer {
|
|||||||
wrapMode: Text.WordWrap
|
wrapMode: Text.WordWrap
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
color: Kirigami.Theme.textColor
|
color: Kirigami.Theme.textColor
|
||||||
onLinkActivated: Qt.openUrlExternally(link)
|
onLinkActivated: UrlHelper.openUrl(link)
|
||||||
readOnly: true
|
readOnly: true
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|||||||
@@ -407,7 +407,7 @@ Kirigami.ApplicationWindow {
|
|||||||
}
|
}
|
||||||
footer: QQC2.Button {
|
footer: QQC2.Button {
|
||||||
text: i18n("Open")
|
text: i18n("Open")
|
||||||
onClicked: Qt.openUrlExternally(consentSheet.url)
|
onClicked: UrlHelper.openUrl(consentSheet.url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ add_executable(neochat
|
|||||||
blurhashimageprovider.cpp
|
blurhashimageprovider.cpp
|
||||||
joinrulesevent.cpp
|
joinrulesevent.cpp
|
||||||
collapsestateproxymodel.cpp
|
collapsestateproxymodel.cpp
|
||||||
|
urlhelper.cpp
|
||||||
../res.qrc
|
../res.qrc
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,7 @@
|
|||||||
#include "roomlistmodel.h"
|
#include "roomlistmodel.h"
|
||||||
#include "roommanager.h"
|
#include "roommanager.h"
|
||||||
#include "sortfilterroomlistmodel.h"
|
#include "sortfilterroomlistmodel.h"
|
||||||
|
#include "urlhelper.h"
|
||||||
#include "userdirectorylistmodel.h"
|
#include "userdirectorylistmodel.h"
|
||||||
#include "userlistmodel.h"
|
#include "userlistmodel.h"
|
||||||
#include "webshortcutmodel.h"
|
#include "webshortcutmodel.h"
|
||||||
@@ -175,6 +176,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
Login *login = new Login();
|
Login *login = new Login();
|
||||||
ChatBoxHelper chatBoxHelper;
|
ChatBoxHelper chatBoxHelper;
|
||||||
|
UrlHelper urlHelper;
|
||||||
|
|
||||||
#ifdef HAVE_COLORSCHEME
|
#ifdef HAVE_COLORSCHEME
|
||||||
ColorSchemer colorScheme;
|
ColorSchemer colorScheme;
|
||||||
@@ -191,6 +193,7 @@ int main(int argc, char *argv[])
|
|||||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "FileType", &fileTypeSingleton);
|
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "FileType", &fileTypeSingleton);
|
||||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "LoginHelper", login);
|
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "LoginHelper", login);
|
||||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "ChatBoxHelper", &chatBoxHelper);
|
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "ChatBoxHelper", &chatBoxHelper);
|
||||||
|
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "UrlHelper", &urlHelper);
|
||||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "EmojiModel", new EmojiModel(&app));
|
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "EmojiModel", new EmojiModel(&app));
|
||||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "CommandModel", new CommandModel(&app));
|
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "CommandModel", new CommandModel(&app));
|
||||||
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "AccountRegistry", &Quotient::AccountRegistry::instance());
|
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "AccountRegistry", &Quotient::AccountRegistry::instance());
|
||||||
|
|||||||
@@ -13,6 +13,10 @@
|
|||||||
#include <csapi/joining.h>
|
#include <csapi/joining.h>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#ifndef Q_OS_ANDROID
|
||||||
|
#include <KIO/OpenUrlJob>
|
||||||
|
#endif
|
||||||
|
|
||||||
RoomManager::RoomManager(QObject *parent)
|
RoomManager::RoomManager(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_currentRoom(nullptr)
|
, m_currentRoom(nullptr)
|
||||||
@@ -191,9 +195,19 @@ void RoomManager::joinRoom(Quotient::Connection *account, const QString &roomAli
|
|||||||
|
|
||||||
bool RoomManager::visitNonMatrix(const QUrl &url)
|
bool RoomManager::visitNonMatrix(const QUrl &url)
|
||||||
{
|
{
|
||||||
|
#ifdef Q_OS_ANDROID
|
||||||
if (!QDesktopServices::openUrl(url)) {
|
if (!QDesktopServices::openUrl(url)) {
|
||||||
Q_EMIT warning(i18n("No application for the link"), i18n("Your operating system could not find an application for the link."));
|
Q_EMIT warning(i18n("No application for the link"), i18n("Your operating system could not find an application for the link."));
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
auto *job = new KIO::OpenUrlJob(url);
|
||||||
|
connect(job, &KJob::finished, this, [this](KJob *job) {
|
||||||
|
if (job->error()) {
|
||||||
|
Q_EMIT warning(i18n("Could not open URL"), job->errorString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
job->start();
|
||||||
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
24
src/urlhelper.cpp
Normal file
24
src/urlhelper.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2022 Nicolas Fella <nicolas.fella@gmx.de>
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include "urlhelper.h"
|
||||||
|
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
#ifdef Q_OS_ANDROID
|
||||||
|
#include <QDesktopServices>
|
||||||
|
#else
|
||||||
|
#include <KIO/OpenUrlJob>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// QDesktopServices::openUrl doesn't support XDG activation yet, OpenUrlJob does
|
||||||
|
// On Android XDG activation is not relevant, so use QDesktopServices::openUrl to avoid the heavy KIO dependency
|
||||||
|
void UrlHelper::openUrl(const QUrl &url)
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_ANDROID
|
||||||
|
QDesktopServices::openUrl(url);
|
||||||
|
#else
|
||||||
|
auto *job = new KIO::OpenUrlJob(url);
|
||||||
|
job->start();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
13
src/urlhelper.h
Normal file
13
src/urlhelper.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2022 Nicolas Fella <nicolas.fella@gmx.de>
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class UrlHelper : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE void openUrl(const QUrl &url);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user