mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 14:28:49 +00:00
The current implementation is a bit of a hack since we also want to keep around the previous variants for now, but will be cleaned up later once all applications have been ported to the new API.
61 lines
2.5 KiB
C++
61 lines
2.5 KiB
C++
/*
|
|
* Copyright (c) 2021, timmot <tiwwot@protonmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <FileSystemAccessServer/FileSystemAccessClientEndpoint.h>
|
|
#include <FileSystemAccessServer/FileSystemAccessServerEndpoint.h>
|
|
#include <LibCore/File.h>
|
|
#include <LibCore/Promise.h>
|
|
#include <LibCore/StandardPaths.h>
|
|
#include <LibGUI/Window.h>
|
|
#include <LibIPC/ServerConnection.h>
|
|
|
|
namespace FileSystemAccessClient {
|
|
|
|
struct Result {
|
|
i32 error;
|
|
Optional<i32> fd;
|
|
Optional<String> chosen_file;
|
|
};
|
|
|
|
using FileResult = ErrorOr<NonnullRefPtr<Core::File>>;
|
|
|
|
class Client final
|
|
: public IPC::ServerConnection<FileSystemAccessClientEndpoint, FileSystemAccessServerEndpoint>
|
|
, public FileSystemAccessClientEndpoint {
|
|
IPC_CLIENT_CONNECTION(Client, "/tmp/portal/filesystemaccess")
|
|
|
|
public:
|
|
Result request_file_read_only_approved(i32 parent_window_id, String const& path);
|
|
Result request_file(i32 parent_window_id, String const& path, Core::OpenMode mode);
|
|
Result open_file(i32 parent_window_id, String const& window_title = {}, StringView path = Core::StandardPaths::home_directory(), Core::OpenMode requested_access = Core::OpenMode::ReadOnly);
|
|
Result save_file(i32 parent_window_id, String const& name, String const ext, Core::OpenMode requested_access = Core::OpenMode::WriteOnly | Core::OpenMode::Truncate);
|
|
|
|
FileResult try_request_file_read_only_approved(GUI::Window* parent_window, String const& path);
|
|
FileResult try_request_file(GUI::Window* parent_window, String const& path, Core::OpenMode mode);
|
|
FileResult try_open_file(GUI::Window* parent_window, String const& window_title = {}, StringView path = Core::StandardPaths::home_directory(), Core::OpenMode requested_access = Core::OpenMode::ReadOnly);
|
|
FileResult try_save_file(GUI::Window* parent_window, String const& name, String const ext, Core::OpenMode requested_access = Core::OpenMode::WriteOnly | Core::OpenMode::Truncate);
|
|
|
|
static Client& the();
|
|
|
|
protected:
|
|
void die() override;
|
|
|
|
private:
|
|
explicit Client(NonnullOwnPtr<Core::Stream::LocalSocket> socket)
|
|
: IPC::ServerConnection<FileSystemAccessClientEndpoint, FileSystemAccessServerEndpoint>(*this, move(socket))
|
|
{
|
|
}
|
|
|
|
virtual void handle_prompt_end(i32 error, Optional<IPC::File> const& fd, Optional<String> const& chosen_file) override;
|
|
|
|
RefPtr<Core::Promise<Result>> m_promise;
|
|
RefPtr<Core::Promise<FileResult>> m_file_promise;
|
|
GUI::Window* m_parent_window { nullptr };
|
|
};
|
|
|
|
}
|