1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:57:44 +00:00

Welcome: Replace instances of DeprecatedString with String

This commit is contained in:
thankyouverycool 2023-01-29 08:59:36 -05:00 committed by Linus Groh
parent c216d71b6c
commit bfc08bc84b
2 changed files with 11 additions and 8 deletions

View file

@ -6,6 +6,7 @@
#include "WelcomeWidget.h" #include "WelcomeWidget.h"
#include <AK/Random.h> #include <AK/Random.h>
#include <AK/String.h>
#include <Applications/Welcome/WelcomeWindowGML.h> #include <Applications/Welcome/WelcomeWindowGML.h>
#include <LibConfig/Client.h> #include <LibConfig/Client.h>
#include <LibCore/StandardPaths.h> #include <LibCore/StandardPaths.h>
@ -33,7 +34,8 @@ ErrorOr<void> WelcomeWidget::create_widgets()
TRY(load_from_gml(welcome_window_gml)); TRY(load_from_gml(welcome_window_gml));
m_web_view = find_descendant_of_type_named<WebView::OutOfProcessWebView>("web_view"); m_web_view = find_descendant_of_type_named<WebView::OutOfProcessWebView>("web_view");
m_web_view->load(URL::create_with_file_scheme(DeprecatedString::formatted("{}/README.md", Core::StandardPaths::home_directory()))); auto path = TRY(String::formatted("{}/README.md", Core::StandardPaths::home_directory()));
m_web_view->load(URL::create_with_file_scheme(path.to_deprecated_string()));
m_tip_label = find_descendant_of_type_named<GUI::Label>("tip_label"); m_tip_label = find_descendant_of_type_named<GUI::Label>("tip_label");
m_tip_frame = find_descendant_of_type_named<GUI::Frame>("tip_frame"); m_tip_frame = find_descendant_of_type_named<GUI::Frame>("tip_frame");
@ -47,7 +49,7 @@ ErrorOr<void> WelcomeWidget::create_widgets()
m_initial_tip_index++; m_initial_tip_index++;
if (m_initial_tip_index >= m_tips.size()) if (m_initial_tip_index >= m_tips.size())
m_initial_tip_index = 0; m_initial_tip_index = 0;
m_tip_label->set_text(m_tips[m_initial_tip_index]); m_tip_label->set_text(m_tips[m_initial_tip_index].to_deprecated_string());
}; };
m_help_button = find_descendant_of_type_named<GUI::Button>("help_button"); m_help_button = find_descendant_of_type_named<GUI::Button>("help_button");
@ -77,8 +79,9 @@ ErrorOr<void> WelcomeWidget::create_widgets()
}; };
if (auto result = open_and_parse_tips_file(); result.is_error()) { if (auto result = open_and_parse_tips_file(); result.is_error()) {
auto error = DeprecatedString::formatted("Opening \"{}/tips.txt\" failed: {}", Core::StandardPaths::documents_directory(), result.error()); auto path = TRY(String::formatted("{}/tips.txt", Core::StandardPaths::documents_directory()));
m_tip_label->set_text(error); auto error = TRY(String::formatted("Opening \"{}\" failed: {}", path, result.error()));
m_tip_label->set_text(error.to_deprecated_string());
warnln(error); warnln(error);
} }
@ -89,7 +92,7 @@ ErrorOr<void> WelcomeWidget::create_widgets()
ErrorOr<void> WelcomeWidget::open_and_parse_tips_file() ErrorOr<void> WelcomeWidget::open_and_parse_tips_file()
{ {
auto path = DeprecatedString::formatted("{}/tips.txt", Core::StandardPaths::documents_directory()); auto path = TRY(String::formatted("{}/tips.txt", Core::StandardPaths::documents_directory()));
auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read)); auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
auto buffered_file = TRY(Core::Stream::BufferedFile::create(move(file))); auto buffered_file = TRY(Core::Stream::BufferedFile::create(move(file)));
Array<u8, PAGE_SIZE> buffer; Array<u8, PAGE_SIZE> buffer;
@ -98,7 +101,7 @@ ErrorOr<void> WelcomeWidget::open_and_parse_tips_file()
auto line = TRY(buffered_file->read_line(buffer)); auto line = TRY(buffered_file->read_line(buffer));
if (line.starts_with('#') || line.is_empty()) if (line.starts_with('#') || line.is_empty())
continue; continue;
m_tips.append(line); TRY(m_tips.try_append(TRY(String::from_utf8(line))));
} }
return {}; return {};
@ -110,7 +113,7 @@ void WelcomeWidget::set_random_tip()
return; return;
m_initial_tip_index = get_random_uniform(m_tips.size()); m_initial_tip_index = get_random_uniform(m_tips.size());
m_tip_label->set_text(m_tips[m_initial_tip_index]); m_tip_label->set_text(m_tips[m_initial_tip_index].to_deprecated_string());
} }
void WelcomeWidget::paint_event(GUI::PaintEvent& event) void WelcomeWidget::paint_event(GUI::PaintEvent& event)

View file

@ -35,5 +35,5 @@ private:
RefPtr<WebView::OutOfProcessWebView> m_web_view; RefPtr<WebView::OutOfProcessWebView> m_web_view;
size_t m_initial_tip_index { 0 }; size_t m_initial_tip_index { 0 };
Vector<DeprecatedString> m_tips; Vector<String> m_tips;
}; };