1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 18:20:43 +09:00

LibFileSystemAccessClient: Rename try_* functions to try_*_deprecated

These functions return the deprecated `Core::File` class, so let's mark
it as such to avoid possible confusion between future non try_*
functions which will use Core::Stream family classes and to possibly
grab someone's attention. :^)
This commit is contained in:
Karol Kosek 2022-12-17 00:58:13 +01:00 committed by Sam Atkins
parent e361025cfb
commit 247db3fdd0
Notes: sideshowbarker 2024-07-17 02:01:26 +09:00
22 changed files with 38 additions and 38 deletions

View file

@ -147,7 +147,7 @@ void GLContextWidget::drop_event(GUI::DropEvent& event)
if (url.scheme() != "file") if (url.scheme() != "file")
continue; continue;
auto response = FileSystemAccessClient::Client::the().try_request_file(window(), url.path(), Core::OpenMode::ReadOnly); auto response = FileSystemAccessClient::Client::the().try_request_file_deprecated(window(), url.path(), Core::OpenMode::ReadOnly);
if (response.is_error()) if (response.is_error())
return; return;
load_file(response.value()); load_file(response.value());
@ -339,7 +339,7 @@ bool GLContextWidget::load_file(Core::File& file)
if (!bitmap_or_error.is_error()) if (!bitmap_or_error.is_error())
texture_image = bitmap_or_error.release_value_but_fixme_should_propagate_errors(); texture_image = bitmap_or_error.release_value_but_fixme_should_propagate_errors();
} else { } else {
auto response = FileSystemAccessClient::Client::the().try_request_file(window(), builder.string_view(), Core::OpenMode::ReadOnly); auto response = FileSystemAccessClient::Client::the().try_request_file_deprecated(window(), builder.string_view(), Core::OpenMode::ReadOnly);
if (!response.is_error()) { if (!response.is_error()) {
auto texture_file = response.value(); auto texture_file = response.value();
auto bitmap_or_error = Gfx::Bitmap::try_load_from_fd_and_close(texture_file->leak_fd(), texture_file->filename()); auto bitmap_or_error = Gfx::Bitmap::try_load_from_fd_and_close(texture_file->leak_fd(), texture_file->filename());
@ -398,7 +398,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto& file_menu = window->add_menu("&File"); auto& file_menu = window->add_menu("&File");
file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) { file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
auto response = FileSystemAccessClient::Client::the().try_open_file(window); auto response = FileSystemAccessClient::Client::the().try_open_file_deprecated(window);
if (response.is_error()) if (response.is_error())
return; return;

View file

@ -121,7 +121,7 @@ HexEditorWidget::HexEditorWidget()
if (!request_close()) if (!request_close())
return; return;
auto response = FileSystemAccessClient::Client::the().try_open_file(window(), {}, Core::StandardPaths::home_directory(), Core::OpenMode::ReadWrite); auto response = FileSystemAccessClient::Client::the().try_open_file_deprecated(window(), {}, Core::StandardPaths::home_directory(), Core::OpenMode::ReadWrite);
if (response.is_error()) if (response.is_error())
return; return;
@ -586,7 +586,7 @@ void HexEditorWidget::drop_event(GUI::DropEvent& event)
return; return;
// TODO: A drop event should be considered user consent for opening a file // TODO: A drop event should be considered user consent for opening a file
auto response = FileSystemAccessClient::Client::the().try_request_file(window(), urls.first().path(), Core::OpenMode::ReadOnly); auto response = FileSystemAccessClient::Client::the().try_request_file_deprecated(window(), urls.first().path(), Core::OpenMode::ReadOnly);
if (response.is_error()) if (response.is_error())
return; return;
open_file(response.value()); open_file(response.value());

View file

@ -54,7 +54,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (arguments.argc > 1) { if (arguments.argc > 1) {
// FIXME: Using `try_request_file_read_only_approved` doesn't work here since the file stored in the editor is only readable. // FIXME: Using `try_request_file_read_only_approved` doesn't work here since the file stored in the editor is only readable.
auto response = FileSystemAccessClient::Client::the().try_request_file(window, arguments.strings[1], Core::OpenMode::ReadWrite); auto response = FileSystemAccessClient::Client::the().try_request_file_deprecated(window, arguments.strings[1], Core::OpenMode::ReadWrite);
if (response.is_error()) if (response.is_error())
return 1; return 1;
hex_editor_widget->open_file(response.value()); hex_editor_widget->open_file(response.value());

View file

@ -211,7 +211,7 @@ void PDFViewerWidget::initialize_menubar(GUI::Window& window)
{ {
auto& file_menu = window.add_menu("&File"); auto& file_menu = window.add_menu("&File");
file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) { file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
auto response = FileSystemAccessClient::Client::the().try_open_file(&window); auto response = FileSystemAccessClient::Client::the().try_open_file_deprecated(&window);
if (!response.is_error()) if (!response.is_error())
open_file(*response.value()); open_file(*response.value());
})); }));

View file

@ -47,7 +47,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->set_icon(app_icon.bitmap_for_size(16)); window->set_icon(app_icon.bitmap_for_size(16));
if (file_path) { if (file_path) {
auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window, file_path); auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved_deprecated(window, file_path);
if (response.is_error()) if (response.is_error())
return 1; return 1;
pdf_viewer_widget->open_file(*response.value()); pdf_viewer_widget->open_file(*response.value());

View file

@ -710,7 +710,7 @@ void ImageEditor::save_project()
save_project_as(); save_project_as();
return; return;
} }
auto response = FileSystemAccessClient::Client::the().try_request_file(window(), path(), Core::OpenMode::Truncate | Core::OpenMode::WriteOnly); auto response = FileSystemAccessClient::Client::the().try_request_file_deprecated(window(), path(), Core::OpenMode::Truncate | Core::OpenMode::WriteOnly);
if (response.is_error()) if (response.is_error())
return; return;
auto result = save_project_to_file(*response.value()); auto result = save_project_to_file(*response.value());

View file

@ -192,7 +192,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
}); });
m_open_image_action = GUI::CommonActions::make_open_action([&](auto&) { m_open_image_action = GUI::CommonActions::make_open_action([&](auto&) {
auto response = FileSystemAccessClient::Client::the().try_open_file(&window); auto response = FileSystemAccessClient::Client::the().try_open_file_deprecated(&window);
if (response.is_error()) if (response.is_error())
return; return;
open_image(response.value()); open_image(response.value());
@ -415,7 +415,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
})); }));
m_edit_menu->add_action(GUI::Action::create( m_edit_menu->add_action(GUI::Action::create(
"&Load Color Palette", g_icon_bag.load_color_palette, [&](auto&) { "&Load Color Palette", g_icon_bag.load_color_palette, [&](auto&) {
auto response = FileSystemAccessClient::Client::the().try_open_file(&window, "Load Color Palette"); auto response = FileSystemAccessClient::Client::the().try_open_file_deprecated(&window, "Load Color Palette");
if (response.is_error()) if (response.is_error())
return; return;
@ -1264,7 +1264,7 @@ void MainWidget::drop_event(GUI::DropEvent& event)
if (url.scheme() != "file") if (url.scheme() != "file")
continue; continue;
auto response = FileSystemAccessClient::Client::the().try_request_file(window(), url.path(), Core::OpenMode::ReadOnly); auto response = FileSystemAccessClient::Client::the().try_request_file_deprecated(window(), url.path(), Core::OpenMode::ReadOnly);
if (response.is_error()) if (response.is_error())
return; return;
open_image(response.value()); open_image(response.value());

View file

@ -74,7 +74,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->show(); window->show();
if (image_file) { if (image_file) {
auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window, image_file); auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved_deprecated(window, image_file);
if (response.is_error()) if (response.is_error())
return 1; return 1;
main_widget->open_image(response.value()); main_widget->open_image(response.value());

View file

@ -30,7 +30,7 @@ ErrorOr<void> PresenterWidget::initialize_menubar()
// Set up the menu bar. // Set up the menu bar.
auto& file_menu = window->add_menu("&File"); auto& file_menu = window->add_menu("&File");
auto open_action = GUI::CommonActions::make_open_action([this](auto&) { auto open_action = GUI::CommonActions::make_open_action([this](auto&) {
auto response = FileSystemAccessClient::Client::the().try_open_file(this->window()); auto response = FileSystemAccessClient::Client::the().try_open_file_deprecated(this->window());
if (response.is_error()) if (response.is_error())
return; return;
this->set_file(response.value()->filename()); this->set_file(response.value()->filename());

View file

@ -127,14 +127,14 @@ SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, NonnullRefPtrVe
if (!request_close()) if (!request_close())
return; return;
auto response = FileSystemAccessClient::Client::the().try_open_file(window()); auto response = FileSystemAccessClient::Client::the().try_open_file_deprecated(window());
if (response.is_error()) if (response.is_error())
return; return;
load_file(*response.value()); load_file(*response.value());
}); });
m_import_action = GUI::Action::create("Import sheets...", [&](auto&) { m_import_action = GUI::Action::create("Import sheets...", [&](auto&) {
auto response = FileSystemAccessClient::Client::the().try_open_file(window()); auto response = FileSystemAccessClient::Client::the().try_open_file_deprecated(window());
if (response.is_error()) if (response.is_error())
return; return;
@ -147,7 +147,7 @@ SpreadsheetWidget::SpreadsheetWidget(GUI::Window& parent_window, NonnullRefPtrVe
return; return;
} }
auto response = FileSystemAccessClient::Client::the().try_request_file(window(), current_filename(), Core::OpenMode::WriteOnly); auto response = FileSystemAccessClient::Client::the().try_request_file_deprecated(window(), current_filename(), Core::OpenMode::WriteOnly);
if (response.is_error()) if (response.is_error())
return; return;
save(*response.value()); save(*response.value());

View file

@ -70,7 +70,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->show(); window->show();
if (filename) { if (filename) {
auto file = TRY(FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window, filename)); auto file = TRY(FileSystemAccessClient::Client::the().try_request_file_read_only_approved_deprecated(window, filename));
spreadsheet_widget->load_file(file); spreadsheet_widget->load_file(file);
} }

View file

@ -272,7 +272,7 @@ MainWidget::MainWidget()
return; return;
} }
auto response = FileSystemAccessClient::Client::the().try_open_file(window()); auto response = FileSystemAccessClient::Client::the().try_open_file_deprecated(window());
if (response.is_error()) if (response.is_error())
return; return;
@ -303,7 +303,7 @@ MainWidget::MainWidget()
m_save_as_action->activate(); m_save_as_action->activate();
return; return;
} }
auto response = FileSystemAccessClient::Client::the().try_request_file(window(), m_path, Core::OpenMode::Truncate | Core::OpenMode::WriteOnly); auto response = FileSystemAccessClient::Client::the().try_request_file_deprecated(window(), m_path, Core::OpenMode::Truncate | Core::OpenMode::WriteOnly);
if (response.is_error()) if (response.is_error())
return; return;
@ -804,7 +804,7 @@ void MainWidget::drop_event(GUI::DropEvent& event)
return; return;
// TODO: A drop event should be considered user consent for opening a file // TODO: A drop event should be considered user consent for opening a file
auto response = FileSystemAccessClient::Client::the().try_request_file(window(), urls.first().path(), Core::OpenMode::ReadOnly); auto response = FileSystemAccessClient::Client::the().try_request_file_deprecated(window(), urls.first().path(), Core::OpenMode::ReadOnly);
if (response.is_error()) if (response.is_error())
return; return;
read_file(*response.value()); read_file(*response.value());

View file

@ -74,7 +74,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
if (file_to_edit) { if (file_to_edit) {
FileArgument parsed_argument(file_to_edit); FileArgument parsed_argument(file_to_edit);
auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window, parsed_argument.filename()); auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved_deprecated(window, parsed_argument.filename());
if (response.is_error()) { if (response.is_error()) {
if (response.error().code() == ENOENT) if (response.error().code() == ENOENT)

View file

@ -238,7 +238,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
TRY(file_menu->try_add_action(GUI::CommonActions::make_open_action([&](auto&) { TRY(file_menu->try_add_action(GUI::CommonActions::make_open_action([&](auto&) {
if (request_close() == GUI::Window::CloseRequestDecision::StayOpen) if (request_close() == GUI::Window::CloseRequestDecision::StayOpen)
return; return;
auto response = FileSystemAccessClient::Client::the().try_open_file(&window, "Select theme file", "/res/themes"sv); auto response = FileSystemAccessClient::Client::the().try_open_file_deprecated(&window, "Select theme file", "/res/themes"sv);
if (response.is_error()) if (response.is_error())
return; return;
auto load_from_file_result = load_from_file(*response.value()); auto load_from_file_result = load_from_file(*response.value());
@ -250,7 +250,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
m_save_action = GUI::CommonActions::make_save_action([&](auto&) { m_save_action = GUI::CommonActions::make_save_action([&](auto&) {
if (m_path.has_value()) { if (m_path.has_value()) {
auto result = FileSystemAccessClient::Client::the().try_request_file(&window, *m_path, Core::OpenMode::ReadWrite | Core::OpenMode::Truncate); auto result = FileSystemAccessClient::Client::the().try_request_file_deprecated(&window, *m_path, Core::OpenMode::ReadWrite | Core::OpenMode::Truncate);
if (result.is_error()) if (result.is_error())
return; return;
save_to_file(result.value()); save_to_file(result.value());

View file

@ -170,7 +170,7 @@ void PreviewWidget::drop_event(GUI::DropEvent& event)
return; return;
} }
auto response = FileSystemAccessClient::Client::the().try_request_file(window(), urls.first().path(), Core::OpenMode::ReadOnly); auto response = FileSystemAccessClient::Client::the().try_request_file_deprecated(window(), urls.first().path(), Core::OpenMode::ReadOnly);
if (response.is_error()) if (response.is_error())
return; return;

View file

@ -53,7 +53,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
// Note: This is deferred to ensure that the window has already popped and thus proper window stealing can be performed. // Note: This is deferred to ensure that the window has already popped and thus proper window stealing can be performed.
app->event_loop().deferred_invoke( app->event_loop().deferred_invoke(
[&window, &path, &main_widget]() { [&window, &path, &main_widget]() {
auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window, path.value()); auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved_deprecated(window, path.value());
if (response.is_error()) if (response.is_error())
GUI::MessageBox::show_error(window, DeprecatedString::formatted("Opening \"{}\" failed: {}", path.value(), response.error())); GUI::MessageBox::show_error(window, DeprecatedString::formatted("Opening \"{}\" failed: {}", path.value(), response.error()));
else { else {

View file

@ -108,7 +108,7 @@ GalleryWidget::GalleryWidget()
m_file_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png"sv).release_value_but_fixme_should_propagate_errors()); m_file_button->set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/open.png"sv).release_value_but_fixme_should_propagate_errors());
m_file_button->on_click = [&](auto) { m_file_button->on_click = [&](auto) {
auto response = FileSystemAccessClient::Client::the().try_open_file(window()); auto response = FileSystemAccessClient::Client::the().try_open_file_deprecated(window());
if (response.is_error()) if (response.is_error())
return; return;
m_text_editor->set_text(response.release_value()->filename()); m_text_editor->set_text(response.release_value()->filename());

View file

@ -150,7 +150,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
save_as_action->activate(); save_as_action->activate();
return; return;
} }
auto response = FileSystemAccessClient::Client::the().try_request_file(window, file_path, Core::OpenMode::Truncate | Core::OpenMode::WriteOnly); auto response = FileSystemAccessClient::Client::the().try_request_file_deprecated(window, file_path, Core::OpenMode::Truncate | Core::OpenMode::WriteOnly);
if (response.is_error()) if (response.is_error())
return; return;
@ -171,7 +171,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
return; return;
} }
auto response = FileSystemAccessClient::Client::the().try_open_file(window); auto response = FileSystemAccessClient::Client::the().try_open_file_deprecated(window);
if (response.is_error()) if (response.is_error())
return; return;
@ -295,7 +295,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
editor->set_cursor(4, 28); // after "...widgets!" editor->set_cursor(4, 28); // after "...widgets!"
update_title(); update_title();
} else { } else {
auto file = TRY(FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window, path)); auto file = TRY(FileSystemAccessClient::Client::the().try_request_file_read_only_approved_deprecated(window, path));
file_path = path; file_path = path;
editor->set_text(file->read_all()); editor->set_text(file->read_all());
update_title(); update_title();

View file

@ -67,7 +67,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(game_menu->try_add_separator()); TRY(game_menu->try_add_separator());
TRY(game_menu->try_add_action(GUI::Action::create("&Import PGN...", { Mod_Ctrl, Key_O }, [&](auto&) { TRY(game_menu->try_add_action(GUI::Action::create("&Import PGN...", { Mod_Ctrl, Key_O }, [&](auto&) {
auto result = FileSystemAccessClient::Client::the().try_open_file(window); auto result = FileSystemAccessClient::Client::the().try_open_file_deprecated(window);
if (result.is_error()) if (result.is_error())
return; return;

View file

@ -23,7 +23,7 @@ Client& Client::the()
return *s_the; return *s_the;
} }
DeprecatedResult Client::try_request_file_read_only_approved(GUI::Window* parent_window, DeprecatedString const& path) DeprecatedResult Client::try_request_file_read_only_approved_deprecated(GUI::Window* parent_window, DeprecatedString const& path)
{ {
auto const id = get_new_id(); auto const id = get_new_id();
m_promises.set(id, PromiseAndWindow { { Core::Promise<DeprecatedResult>::construct() }, parent_window }); m_promises.set(id, PromiseAndWindow { { Core::Promise<DeprecatedResult>::construct() }, parent_window });
@ -69,7 +69,7 @@ static Core::Stream::OpenMode to_stream_open_mode(Core::OpenMode open_mode)
return result; return result;
} }
DeprecatedResult Client::try_request_file(GUI::Window* parent_window, DeprecatedString const& path, Core::OpenMode deprecated_mode) DeprecatedResult Client::try_request_file_deprecated(GUI::Window* parent_window, DeprecatedString const& path, Core::OpenMode deprecated_mode)
{ {
auto const id = get_new_id(); auto const id = get_new_id();
m_promises.set(id, PromiseAndWindow { { Core::Promise<DeprecatedResult>::construct() }, parent_window }); m_promises.set(id, PromiseAndWindow { { Core::Promise<DeprecatedResult>::construct() }, parent_window });
@ -96,7 +96,7 @@ DeprecatedResult Client::try_request_file(GUI::Window* parent_window, Deprecated
return handle_promise<DeprecatedResult>(id); return handle_promise<DeprecatedResult>(id);
} }
DeprecatedResult Client::try_open_file(GUI::Window* parent_window, DeprecatedString const& window_title, StringView path, Core::OpenMode deprecated_requested_access) 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(); auto const id = get_new_id();
m_promises.set(id, PromiseAndWindow { { Core::Promise<DeprecatedResult>::construct() }, parent_window }); m_promises.set(id, PromiseAndWindow { { Core::Promise<DeprecatedResult>::construct() }, parent_window });

View file

@ -27,9 +27,9 @@ class Client final
IPC_CLIENT_CONNECTION(Client, "/tmp/session/%sid/portal/filesystemaccess"sv) IPC_CLIENT_CONNECTION(Client, "/tmp/session/%sid/portal/filesystemaccess"sv)
public: public:
DeprecatedResult try_request_file_read_only_approved(GUI::Window* parent_window, DeprecatedString const& path); DeprecatedResult try_request_file_read_only_approved_deprecated(GUI::Window* parent_window, DeprecatedString const& path);
DeprecatedResult try_request_file(GUI::Window* parent_window, DeprecatedString const& path, Core::OpenMode mode); DeprecatedResult try_request_file_deprecated(GUI::Window* parent_window, DeprecatedString const& path, Core::OpenMode mode);
DeprecatedResult try_open_file(GUI::Window* parent_window, DeprecatedString const& window_title = {}, StringView path = Core::StandardPaths::home_directory(), Core::OpenMode requested_access = Core::OpenMode::ReadOnly); 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); 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 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); 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);

View file

@ -522,7 +522,7 @@ Gfx::IntRect OutOfProcessWebView::notify_server_did_request_fullscreen_window()
void OutOfProcessWebView::notify_server_did_request_file(Badge<WebContentClient>, DeprecatedString const& path, i32 request_id) void OutOfProcessWebView::notify_server_did_request_file(Badge<WebContentClient>, DeprecatedString const& path, i32 request_id)
{ {
auto file = FileSystemAccessClient::Client::the().try_request_file_read_only_approved(window(), path); auto file = FileSystemAccessClient::Client::the().try_request_file_read_only_approved_deprecated(window(), path);
if (file.is_error()) if (file.is_error())
client().async_handle_file_return(file.error().code(), {}, request_id); client().async_handle_file_return(file.error().code(), {}, request_id);
else else