File indexing completed on 2024-06-23 05:24:06
0001 // SPDX-FileCopyrightText: 2023 Arjen Hiemstra <ahiemstra@heimr.nl> 0002 // 0003 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0004 0005 #pragma once 0006 0007 #include <functional> 0008 #include <memory> 0009 #include <optional> 0010 #include <type_traits> 0011 0012 #include <QDBusPendingCallWatcher> 0013 #include <QObject> 0014 #include <QPoint> 0015 #include <QPointer> 0016 0017 #include "krdp_export.h" 0018 0019 namespace KRdp 0020 { 0021 0022 /** 0023 * Convenience class to help with making requests to the Desktop portal less cumbersome to work with. 0024 * 0025 * A request to the portal requires first calling a method on the portal, which 0026 * will return an object path that should be listened to for a signal. The 0027 * signal provides the actual proper data for the original method call. 0028 */ 0029 class PortalRequest : public QObject 0030 { 0031 Q_OBJECT 0032 public: 0033 template<typename ContextType, typename Callback> 0034 PortalRequest(const QDBusPendingCall &call, ContextType *context, Callback callback) 0035 { 0036 m_context = context; 0037 0038 if constexpr (std::is_member_function_pointer<Callback>::value) { 0039 m_callback = std::bind(callback, context, std::placeholders::_1, std::placeholders::_2); 0040 } else { 0041 m_callback = callback; 0042 } 0043 0044 auto watcher = new QDBusPendingCallWatcher(call); 0045 // We need to wait here because otherwise we risk the signal arriving 0046 // before we know what path to listen on. 0047 watcher->waitForFinished(); 0048 onStarted(watcher); 0049 } 0050 0051 private: 0052 void onStarted(QDBusPendingCallWatcher *watcher); 0053 Q_SLOT void onFinished(uint code, const QVariantMap &result); 0054 0055 QPointer<QObject> m_context; 0056 std::function<void(uint, const QVariantMap &)> m_callback; 0057 }; 0058 0059 struct PortalSessionStream { 0060 uint nodeId; 0061 QVariantMap map; 0062 }; 0063 0064 } 0065 0066 Q_DECLARE_METATYPE(KRdp::PortalSessionStream)