summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorKarol Kosek <krkk@serenityos.org>2022-12-17 00:52:07 +0100
committerSam Atkins <atkinssj@gmail.com>2023-01-07 10:53:43 +0000
commit86f6586c6e7edb454bacd820ba37bd8b7d9e8e11 (patch)
treeff6da500f68c435fd2ee1bed0ad8118aad132051 /Userland/Libraries
parent2cbe2dd3c0cc9e783068419f4ba9a9798e87e1c7 (diff)
downloadserenity-86f6586c6e7edb454bacd820ba37bd8b7d9e8e11.zip
LibFileSystemAccessClient: Add functions returning FSAC::File
This patch reimplements the now deprecated try_open_file(), try_request_file() and try_request_file_read_only_approved() functions, with the difference that the new ones return a FSAC::File object (currently a wrapper with a Core::Stream and a filename) instead of a Core::File. Implemented in a similar manner to 6dd716adf2.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibFileSystemAccessClient/Client.cpp70
-rw-r--r--Userland/Libraries/LibFileSystemAccessClient/Client.h3
2 files changed, 73 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();
diff --git a/Userland/Libraries/LibFileSystemAccessClient/Client.h b/Userland/Libraries/LibFileSystemAccessClient/Client.h
index b0c0360f3b..32236bc0f0 100644
--- a/Userland/Libraries/LibFileSystemAccessClient/Client.h
+++ b/Userland/Libraries/LibFileSystemAccessClient/Client.h
@@ -51,6 +51,9 @@ public:
DeprecatedResult try_open_file_deprecated(GUI::Window* parent_window, DeprecatedString const& window_title = {}, StringView path = Core::StandardPaths::home_directory(), Core::OpenMode requested_access = Core::OpenMode::ReadOnly);
DeprecatedResult try_save_file_deprecated(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::OpenMode requested_access = Core::OpenMode::WriteOnly | Core::OpenMode::Truncate);
+ Result request_file_read_only_approved(GUI::Window* parent_window, DeprecatedString const& path);
+ Result request_file(GUI::Window* parent_window, DeprecatedString const& path, Core::Stream::OpenMode requested_access);
+ Result open_file(GUI::Window* parent_window, DeprecatedString const& window_title = {}, StringView path = Core::StandardPaths::home_directory(), Core::Stream::OpenMode requested_access = Core::Stream::OpenMode::Read);
Result save_file(GUI::Window* parent_window, DeprecatedString const& name, DeprecatedString const ext, Core::Stream::OpenMode requested_access = Core::Stream::OpenMode::Write | Core::Stream::OpenMode::Truncate);
static Client& the();