KeyboardMapper: Port to Core::Stream

Port KeyboardMapperWidget to use the new Core::Stream instead of the old
IODevice.

If you can't beat 'em, join 'em.
This commit is contained in:
RasmusNylander 2021-12-17 22:03:23 +01:00 committed by Andreas Kling
parent 9678ff15a8
commit c00014fa54
Notes: sideshowbarker 2024-07-17 21:32:59 +09:00
3 changed files with 12 additions and 9 deletions

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
* Copyright (c) 2021, Rasmus Nylander <RasmusNylander.SerenityOS@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/

View file

@ -1,12 +1,13 @@
/*
* Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
* Copyright (c) 2021, Rasmus Nylander <RasmusNylander.SerenityOS@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "KeyboardMapperWidget.h"
#include "KeyPositions.h"
#include <LibCore/File.h>
#include <LibCore/Stream.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/InputBox.h>
#include <LibGUI/MessageBox.h>
@ -178,11 +179,9 @@ ErrorOr<void> KeyboardMapperWidget::save_to_file(StringView filename)
// Write to file.
String file_content = map_json.to_string();
auto file = TRY(Core::File::open(filename, Core::OpenMode::WriteOnly));
bool result = file->write(file_content);
if (!result)
return Error::from_errno(file->error());
auto file = TRY(Core::Stream::File::open(filename, Core::Stream::OpenMode::Write));
TRY(file.write(file_content.bytes()));
file.close();
m_modified = false;
m_filename = filename;
@ -244,6 +243,7 @@ void KeyboardMapperWidget::update_window_title()
window()->set_title(sb.to_string());
}
void KeyboardMapperWidget::show_error_to_user(Error error){
void KeyboardMapperWidget::show_error_to_user(Error error)
{
GUI::MessageBox::show_error(window(), error.string_literal());
}
}

View file

@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
* Copyright (c) 2021, Rasmus Nylander <RasmusNylander.SerenityOS@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -48,7 +49,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto open_action = GUI::CommonActions::make_open_action(
[&](auto&) {
Optional<String> path = GUI::FilePicker::get_open_filepath(window, "Open", "/res/keymaps/");
if (!path.has_value()) return;
if (!path.has_value())
return;
ErrorOr<void> error_or = keyboard_mapper_widget->load_map_from_file(path.value());
if (error_or.is_error())