Get host path for selected application

This commit is contained in:
Patrick Nicolas
2025-05-13 09:34:24 +02:00
parent d666f16d98
commit ef90913426
3 changed files with 26 additions and 1 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ ColumnLayout {
Dialogs.FileDialog {
id: app_browse
onAccepted: {
app_text.text = new URL(selectedFile).pathname;
app_text.text = WivrnServer.host_path(new URL(selectedFile).pathname);
select_game.save();
}
}
+22
View File
@@ -19,6 +19,7 @@
#include "wivrn_server.h"
#include "gui_config.h"
#include "magic_enum.hpp"
#include "utils/flatpak.h"
#include "wivrn_server_dbus.h"
#include <QApplication>
#include <QClipboard>
@@ -554,6 +555,27 @@ QString wivrn_server::hostname()
return _hostname;
}
QString wivrn_server::host_path(QString path)
{
if (not wivrn::is_flatpak())
return path;
QDBusInterface docs("org.freedesktop.portal.Documents", "/org/freedesktop/portal/documents", "org.freedesktop.portal.Documents", QDBusConnection::sessionBus());
if (not docs.isValid())
return path;
QString id = QFileInfo(path).dir().dirName();
[[maybe_unused]] static auto r = qDBusRegisterMetaType<QMap<QString, QByteArray>>();
QDBusReply<QMap<QString, QByteArray>> res = docs.call("GetHostPaths", QStringList(id));
if ((not res.isValid()) or res.value().empty())
return path;
path = res.value().first();
if (path.endsWith('\0'))
path.chop(1);
return path;
}
void wivrn_server::disconnect_headset()
{
if (server_interface)
+3
View File
@@ -167,6 +167,9 @@ public:
// hostnamed
Q_PROPERTY(QString hostname READ hostname CONSTANT)
// flatpak API
Q_INVOKABLE QString host_path(QString path);
Status serverStatus() const
{
return m_serverStatus;