summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorLucas CHOLLET <lucas.chollet@free.fr>2023-01-07 12:18:16 -0500
committerSam Atkins <atkinssj@gmail.com>2023-01-08 08:12:50 +0000
commit8377adfde008d6e86b67f1eea2ae4c13e0967262 (patch)
treea6964e068dceffc717f56c5bc4ba2ee071f47014 /Userland
parenta5d5b970ff475aa52730f3b01485dec395dc404d (diff)
downloadserenity-8377adfde008d6e86b67f1eea2ae4c13e0967262.zip
ThemeEditor: Port to `Core::Stream`
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/ThemeEditor/MainWidget.cpp30
-rw-r--r--Userland/Applications/ThemeEditor/MainWidget.h4
-rw-r--r--Userland/Applications/ThemeEditor/main.cpp4
3 files changed, 19 insertions, 19 deletions
diff --git a/Userland/Applications/ThemeEditor/MainWidget.cpp b/Userland/Applications/ThemeEditor/MainWidget.cpp
index a0fae4cd80..25092c7d3a 100644
--- a/Userland/Applications/ThemeEditor/MainWidget.cpp
+++ b/Userland/Applications/ThemeEditor/MainWidget.cpp
@@ -238,36 +238,36 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
TRY(file_menu->try_add_action(GUI::CommonActions::make_open_action([&](auto&) {
if (request_close() == GUI::Window::CloseRequestDecision::StayOpen)
return;
- auto response = FileSystemAccessClient::Client::the().try_open_file_deprecated(&window, "Select theme file", "/res/themes"sv);
+ auto response = FileSystemAccessClient::Client::the().open_file(&window, "Select theme file", "/res/themes"sv);
if (response.is_error())
return;
- auto load_from_file_result = load_from_file(*response.value());
+ auto load_from_file_result = load_from_file(response.value().filename(), response.value().release_stream());
if (load_from_file_result.is_error()) {
- GUI::MessageBox::show_error(&window, DeprecatedString::formatted("Can't open file named {}: {}", response.value()->filename(), load_from_file_result.error()));
+ GUI::MessageBox::show_error(&window, DeprecatedString::formatted("Can't open file named {}: {}", response.value().filename(), load_from_file_result.error()));
return;
}
})));
m_save_action = GUI::CommonActions::make_save_action([&](auto&) {
if (m_path.has_value()) {
- auto result = FileSystemAccessClient::Client::the().try_request_file_deprecated(&window, *m_path, Core::OpenMode::ReadWrite | Core::OpenMode::Truncate);
+ auto result = FileSystemAccessClient::Client::the().request_file(&window, *m_path, Core::Stream::OpenMode::ReadWrite | Core::Stream::OpenMode::Truncate);
if (result.is_error())
return;
- save_to_file(result.value());
+ save_to_file(result.value().filename(), result.value().release_stream());
} else {
- auto result = FileSystemAccessClient::Client::the().try_save_file_deprecated(&window, "Theme", "ini", Core::OpenMode::ReadWrite | Core::OpenMode::Truncate);
+ auto result = FileSystemAccessClient::Client::the().save_file(&window, "Theme", "ini", Core::Stream::OpenMode::ReadWrite | Core::Stream::OpenMode::Truncate);
if (result.is_error())
return;
- save_to_file(result.value());
+ save_to_file(result.value().filename(), result.value().release_stream());
}
});
TRY(file_menu->try_add_action(*m_save_action));
TRY(file_menu->try_add_action(GUI::CommonActions::make_save_as_action([&](auto&) {
- auto result = FileSystemAccessClient::Client::the().try_save_file_deprecated(&window, "Theme", "ini", Core::OpenMode::ReadWrite | Core::OpenMode::Truncate);
+ auto result = FileSystemAccessClient::Client::the().save_file(&window, "Theme", "ini", Core::Stream::OpenMode::ReadWrite | Core::Stream::OpenMode::Truncate);
if (result.is_error())
return;
- save_to_file(result.value());
+ save_to_file(result.value().filename(), result.value().release_stream());
})));
TRY(file_menu->try_add_separator());
@@ -315,9 +315,9 @@ void MainWidget::set_path(DeprecatedString path)
update_title();
}
-void MainWidget::save_to_file(Core::File& file)
+void MainWidget::save_to_file(String const& filename, NonnullOwnPtr<Core::Stream::File> file)
{
- auto theme = Core::ConfigFile::open(file.filename(), file.leak_fd()).release_value_but_fixme_should_propagate_errors();
+ auto theme = Core::ConfigFile::open(filename.to_deprecated_string(), move(file)).release_value_but_fixme_should_propagate_errors();
#define __ENUMERATE_ALIGNMENT_ROLE(role) theme->write_entry("Alignments", to_string(Gfx::AlignmentRole::role), to_string(m_current_palette.alignment(Gfx::AlignmentRole::role)));
ENUMERATE_ALIGNMENT_ROLES(__ENUMERATE_ALIGNMENT_ROLE)
@@ -344,7 +344,7 @@ void MainWidget::save_to_file(Core::File& file)
GUI::MessageBox::show_error(window(), DeprecatedString::formatted("Failed to save theme file: {}", sync_result.error()));
} else {
m_last_modified_time = Time::now_monotonic();
- set_path(file.filename());
+ set_path(filename.to_deprecated_string());
window()->set_modified(false);
}
}
@@ -601,15 +601,15 @@ void MainWidget::show_path_picker_dialog(StringView property_display_name, GUI::
path_input.set_text(*result);
}
-ErrorOr<void> MainWidget::load_from_file(Core::File& file)
+ErrorOr<void> MainWidget::load_from_file(String const& filename, NonnullOwnPtr<Core::Stream::File> file)
{
- auto config_file = TRY(Core::ConfigFile::open(file.filename(), file.leak_fd()));
+ auto config_file = TRY(Core::ConfigFile::open(filename.to_deprecated_string(), move(file)));
auto theme = TRY(Gfx::load_system_theme(config_file));
VERIFY(theme.is_valid());
auto new_palette = Gfx::Palette(Gfx::PaletteImpl::create_with_anonymous_buffer(theme));
set_palette(move(new_palette));
- set_path(file.filename());
+ set_path(filename.to_deprecated_string());
#define __ENUMERATE_ALIGNMENT_ROLE(role) \
if (auto alignment_input = m_alignment_inputs[to_underlying(Gfx::AlignmentRole::role)]) \
diff --git a/Userland/Applications/ThemeEditor/MainWidget.h b/Userland/Applications/ThemeEditor/MainWidget.h
index 786adb414d..07809ccfcc 100644
--- a/Userland/Applications/ThemeEditor/MainWidget.h
+++ b/Userland/Applications/ThemeEditor/MainWidget.h
@@ -86,12 +86,12 @@ public:
ErrorOr<void> initialize_menubar(GUI::Window&);
GUI::Window::CloseRequestDecision request_close();
void update_title();
- ErrorOr<void> load_from_file(Core::File&);
+ ErrorOr<void> load_from_file(String const& filename, NonnullOwnPtr<Core::Stream::File> file);
private:
explicit MainWidget(NonnullRefPtr<AlignmentModel>);
- void save_to_file(Core::File&);
+ void save_to_file(String const& filename, NonnullOwnPtr<Core::Stream::File> file);
ErrorOr<Core::AnonymousBuffer> encode();
void set_path(DeprecatedString);
diff --git a/Userland/Applications/ThemeEditor/main.cpp b/Userland/Applications/ThemeEditor/main.cpp
index 24df1bed84..7dc1a87bd5 100644
--- a/Userland/Applications/ThemeEditor/main.cpp
+++ b/Userland/Applications/ThemeEditor/main.cpp
@@ -53,11 +53,11 @@ 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.
app->event_loop().deferred_invoke(
[&window, &path, &main_widget]() {
- auto response = FileSystemAccessClient::Client::the().try_request_file_read_only_approved_deprecated(window, path.value());
+ auto response = FileSystemAccessClient::Client::the().request_file_read_only_approved(window, path.value());
if (response.is_error())
GUI::MessageBox::show_error(window, DeprecatedString::formatted("Opening \"{}\" failed: {}", path.value(), response.error()));
else {
- auto load_from_file_result = main_widget->load_from_file(response.release_value());
+ auto load_from_file_result = main_widget->load_from_file(response.value().filename(), response.value().release_stream());
if (load_from_file_result.is_error())
GUI::MessageBox::show_error(window, DeprecatedString::formatted("Loading theme from file has failed: {}", load_from_file_result.error()));
}