MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
DBusBackend.hpp
Go to the documentation of this file.
1#pragma once
2
3#ifdef MAYAFLUX_PLATFORM_LINUX
4
5#include "SystemBackend.hpp"
6
7struct DBusConnection;
8
9namespace MayaFlux::Core {
10
11/**
12 * @class DBusBackend
13 * @brief Linux SystemBackend via the XDG Desktop Portal over D-Bus.
14 *
15 * Uses org.freedesktop.portal.FileChooser for file open and save dialogs.
16 * The portal works correctly inside Flatpak sandboxes and across all
17 * desktop environments that ship a portal implementation (GNOME, KDE, etc.).
18 *
19 * A private session bus connection is opened during initialize() and held
20 * for the lifetime of the backend. Each dialog operation spawns a short-lived
21 * thread that blocks on dbus_connection_read_write() until the portal's
22 * Request object signals its Response, then fires the callback and exits.
23 */
24class MAYAFLUX_API DBusBackend final : public SystemBackend {
25public:
26 DBusBackend() = default;
27 ~DBusBackend() override;
28
29 DBusBackend(const DBusBackend&) = delete;
30 DBusBackend& operator=(const DBusBackend&) = delete;
31 DBusBackend(DBusBackend&&) noexcept = default;
32 DBusBackend& operator=(DBusBackend&&) noexcept = default;
33
34 [[nodiscard]] bool initialize() override;
35 void shutdown() override;
36 [[nodiscard]] bool is_initialized() const override { return m_initialized; }
37
38 void open_file(
39 FileDialogCallback callback,
40 std::vector<SystemFileFilter> filters,
41 std::filesystem::path start_dir) override;
42
43 void save_file(
44 FileDialogCallback callback,
45 std::string suggested_name,
46 std::vector<SystemFileFilter> filters,
47 std::filesystem::path start_dir) override;
48
49private:
50 DBusConnection* m_conn { nullptr };
51 bool m_initialized { false };
52
53 void invoke_portal(
54 const char* method,
55 FileDialogCallback callback,
56 const std::vector<SystemFileFilter>& filters,
57 const std::filesystem::path& start_dir,
58 const std::string& suggested) const;
59};
60
61} // namespace MayaFlux::Core
62
63#endif // MAYAFLUX_PLATFORM_LINUX
void initialize()
Definition main.cpp:11
void open_file(ChooserCallback callback, std::vector< ChooserFilter > filters, std::filesystem::path start_dir)
Present a native open-file dialog, delivering the result via callback.
Definition Chooser.cpp:8
void save_file(ChooserCallback callback, std::string suggested_name, std::vector< ChooserFilter > filters, std::filesystem::path start_dir)
Present a native save-file dialog, delivering the result via callback.
Definition Chooser.cpp:23