| 1 | /**************************************************************************/ |
| 2 | /* freedesktop_portal_desktop.h */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #ifndef FREEDESKTOP_PORTAL_DESKTOP_H |
| 32 | #define FREEDESKTOP_PORTAL_DESKTOP_H |
| 33 | |
| 34 | #ifdef DBUS_ENABLED |
| 35 | |
| 36 | #include "core/os/thread.h" |
| 37 | #include "servers/display_server.h" |
| 38 | |
| 39 | struct DBusMessage; |
| 40 | struct DBusConnection; |
| 41 | struct DBusMessageIter; |
| 42 | |
| 43 | class FreeDesktopPortalDesktop { |
| 44 | private: |
| 45 | bool unsupported = false; |
| 46 | |
| 47 | static bool try_parse_variant(DBusMessage *p_reply_message, int p_type, void *r_value); |
| 48 | // Read a setting from org.freekdesktop.portal.Settings |
| 49 | bool read_setting(const char *p_namespace, const char *p_key, int p_type, void *r_value); |
| 50 | |
| 51 | static void append_dbus_string(DBusMessageIter *p_iter, const String &p_string); |
| 52 | static void append_dbus_dict_filters(DBusMessageIter *p_iter, const Vector<String> &p_filters); |
| 53 | static void append_dbus_dict_string(DBusMessageIter *p_iter, const String &p_key, const String &p_value, bool p_as_byte_array = false); |
| 54 | static void append_dbus_dict_bool(DBusMessageIter *p_iter, const String &p_key, bool p_value); |
| 55 | static bool file_chooser_parse_response(DBusMessageIter *p_iter, bool &r_cancel, Vector<String> &r_urls); |
| 56 | |
| 57 | struct FileDialogData { |
| 58 | DBusConnection *connection = nullptr; |
| 59 | Callable callback; |
| 60 | String path; |
| 61 | }; |
| 62 | |
| 63 | Mutex file_dialog_mutex; |
| 64 | Vector<FileDialogData> file_dialogs; |
| 65 | Thread file_dialog_thread; |
| 66 | SafeFlag file_dialog_thread_abort; |
| 67 | |
| 68 | static void _thread_file_dialog_monitor(void *p_ud); |
| 69 | |
| 70 | public: |
| 71 | FreeDesktopPortalDesktop(); |
| 72 | ~FreeDesktopPortalDesktop(); |
| 73 | |
| 74 | bool is_supported() { return !unsupported; } |
| 75 | |
| 76 | Error file_dialog_show(const String &p_xid, const String &p_title, const String &p_current_directory, const String &p_filename, DisplayServer::FileDialogMode p_mode, const Vector<String> &p_filters, const Callable &p_callback); |
| 77 | |
| 78 | // Retrieve the system's preferred color scheme. |
| 79 | // 0: No preference or unknown. |
| 80 | // 1: Prefer dark appearance. |
| 81 | // 2: Prefer light appearance. |
| 82 | uint32_t get_appearance_color_scheme(); |
| 83 | }; |
| 84 | |
| 85 | #endif // DBUS_ENABLED |
| 86 | |
| 87 | #endif // FREEDESKTOP_PORTAL_DESKTOP_H |
| 88 | |