summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibFileSystemAccessClient/Client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Libraries/LibFileSystemAccessClient/Client.cpp')
-rw-r--r--Userland/Libraries/LibFileSystemAccessClient/Client.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/Userland/Libraries/LibFileSystemAccessClient/Client.cpp b/Userland/Libraries/LibFileSystemAccessClient/Client.cpp
index 49ade60a68..8ddfd71c50 100644
--- a/Userland/Libraries/LibFileSystemAccessClient/Client.cpp
+++ b/Userland/Libraries/LibFileSystemAccessClient/Client.cpp
@@ -48,6 +48,31 @@ DeprecatedResult Client::try_request_file_read_only_approved_deprecated(GUI::Win
return handle_promise<DeprecatedResult>(id);
}
+Result Client::request_file_read_only_approved(GUI::Window* parent_window, DeprecatedString const& path)
+{
+ auto const id = get_new_id();
+ m_promises.set(id, PromiseAndWindow { { Core::Promise<Result>::construct() }, parent_window });
+
+ auto parent_window_server_client_id = GUI::ConnectionToWindowServer::the().expose_client_id();
+ auto child_window_server_client_id = expose_window_server_client_id();
+ auto parent_window_id = parent_window->window_id();
+
+ GUI::ConnectionToWindowServer::the().add_window_stealing_for_client(child_window_server_client_id, parent_window_id);
+
+ ScopeGuard guard([parent_window_id, child_window_server_client_id] {
+ GUI::ConnectionToWindowServer::the().remove_window_stealing_for_client(child_window_server_client_id, parent_window_id);
+ });
+
+ if (path.starts_with('/')) {
+ async_request_file_read_only_approved(id, parent_window_server_client_id, parent_window_id, path);
+ } else {
+ auto full_path = LexicalPath::join(Core::File::current_working_directory(), path).string();
+ async_request_file_read_only_approved(id, parent_window_server_client_id, parent_window_id, full_path);
+ }
+
+ return handle_promise<Result>(id);
+}
+
static Core::Stream::OpenMode to_stream_open_mode(Core::OpenMode open_mode)
{
Core::Stream::OpenMode result {};
@@ -96,6 +121,31 @@ DeprecatedResult Client::try_request_file_deprecated(GUI::Window* parent_window,
return handle_promise<DeprecatedResult>(id);
}
+Result Client::request_file(GUI::Window* parent_window, DeprecatedString const& path, Core::Stream::OpenMode mode)
+{
+ auto const id = get_new_id();
+ m_promises.set(id, PromiseAndWindow { { Core::Promise<Result>::construct() }, parent_window });
+
+ auto parent_window_server_client_id = GUI::ConnectionToWindowServer::the().expose_client_id();
+ auto child_window_server_client_id = expose_window_server_client_id();
+ auto parent_window_id = parent_window->window_id();
+
+ GUI::ConnectionToWindowServer::the().add_window_stealing_for_client(child_window_server_client_id, parent_window_id);
+
+ ScopeGuard guard([parent_window_id, child_window_server_client_id] {
+ GUI::ConnectionToWindowServer::the().remove_window_stealing_for_client(child_window_server_client_id, parent_window_id);
+ });
+
+ if (path.starts_with('/')) {
+ async_request_file(id, parent_window_server_client_id, parent_window_id, path, mode);
+ } else {
+ auto full_path = LexicalPath::join(Core::File::current_working_directory(), path).string();
+ async_request_file(id, parent_window_server_client_id, parent_window_id, full_path, mode);
+ }
+
+ return handle_promise<Result>(id);
+}
+
DeprecatedResult Client::try_open_file_deprecated(GUI::Window* parent_window, DeprecatedString const& window_title, StringView path, Core::OpenMode deprecated_requested_access)
{
auto const id = get_new_id();
@@ -118,6 +168,26 @@ DeprecatedResult Client::try_open_file_deprecated(GUI::Window* parent_window, De
return handle_promise<DeprecatedResult>(id);
}
+Result Client::open_file(GUI::Window* parent_window, DeprecatedString const& window_title, StringView path, Core::Stream::OpenMode requested_access)
+{
+ auto const id = get_new_id();
+ m_promises.set(id, PromiseAndWindow { { Core::Promise<Result>::construct() }, parent_window });
+
+ auto parent_window_server_client_id = GUI::ConnectionToWindowServer::the().expose_client_id();
+ auto child_window_server_client_id = expose_window_server_client_id();
+ auto parent_window_id = parent_window->window_id();
+
+ GUI::ConnectionToWindowServer::the().add_window_stealing_for_client(child_window_server_client_id, parent_window_id);
+
+ ScopeGuard guard([parent_window_id, child_window_server_client_id] {
+ GUI::ConnectionToWindowServer::the().remove_window_stealing_for_client(child_window_server_client_id, parent_window_id);
+ });
+
+ async_prompt_open_file(id, parent_window_server_client_id, parent_window_id, window_title, path, requested_access);
+
+ return handle_promise<Result>(id);
+}
+
DeprecatedResult Client::try_save_file_deprecated(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::OpenMode deprecated_requested_access)
{
auto const id = get_new_id();