Client.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2021, timmot <tiwwot@protonmail.com>
  3. * Copyright (c) 2022, Mustafa Quraish <mustafa@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <FileSystemAccessServer/FileSystemAccessClientEndpoint.h>
  9. #include <FileSystemAccessServer/FileSystemAccessServerEndpoint.h>
  10. #include <LibCore/File.h>
  11. #include <LibCore/Promise.h>
  12. #include <LibCore/StandardPaths.h>
  13. #include <LibGUI/Window.h>
  14. #include <LibIPC/ServerConnection.h>
  15. namespace FileSystemAccessClient {
  16. using Result = ErrorOr<NonnullRefPtr<Core::File>>;
  17. class Client final
  18. : public IPC::ServerConnection<FileSystemAccessClientEndpoint, FileSystemAccessServerEndpoint>
  19. , public FileSystemAccessClientEndpoint {
  20. IPC_CLIENT_CONNECTION(Client, "/tmp/portal/filesystemaccess")
  21. public:
  22. Result try_request_file_read_only_approved(GUI::Window* parent_window, String const& path);
  23. Result try_request_file(GUI::Window* parent_window, String const& path, Core::OpenMode mode);
  24. Result try_open_file(GUI::Window* parent_window, String const& window_title = {}, StringView path = Core::StandardPaths::home_directory(), Core::OpenMode requested_access = Core::OpenMode::ReadOnly);
  25. Result try_save_file(GUI::Window* parent_window, String const& name, String const ext, Core::OpenMode requested_access = Core::OpenMode::WriteOnly | Core::OpenMode::Truncate);
  26. static Client& the();
  27. protected:
  28. void die() override;
  29. private:
  30. explicit Client(NonnullOwnPtr<Core::Stream::LocalSocket> socket)
  31. : IPC::ServerConnection<FileSystemAccessClientEndpoint, FileSystemAccessServerEndpoint>(*this, move(socket))
  32. {
  33. }
  34. virtual void handle_prompt_end(i32 error, Optional<IPC::File> const& fd, Optional<String> const& chosen_file) override;
  35. RefPtr<Core::Promise<Result>> m_promise;
  36. GUI::Window* m_parent_window { nullptr };
  37. };
  38. }