From a7c770268f876b8dad6a858830f5edf95a0e728e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Thu, 31 Aug 2023 18:50:32 +0200 Subject: [PATCH] Userland: Migrate to String in notification system --- Userland/Applets/Network/main.cpp | 8 ++++---- Userland/DevTools/HackStudio/LanguageClient.cpp | 8 ++++---- Userland/DevTools/HackStudio/main.cpp | 4 ++-- Userland/Libraries/LibGUI/Notification.h | 13 +++++++------ .../NotificationServer/ConnectionFromClient.cpp | 4 ++-- .../NotificationServer/ConnectionFromClient.h | 4 ++-- .../NotificationServer/NotificationServer.ipc | 4 ++-- .../NotificationServer/NotificationWindow.cpp | 14 +++++++------- .../NotificationServer/NotificationWindow.h | 6 +++--- Userland/Utilities/notify.cpp | 4 ++-- 10 files changed, 35 insertions(+), 34 deletions(-) diff --git a/Userland/Applets/Network/main.cpp b/Userland/Applets/Network/main.cpp index 7975bcce19..e6f36e20be 100644 --- a/Userland/Applets/Network/main.cpp +++ b/Userland/Applets/Network/main.cpp @@ -77,9 +77,9 @@ private: if (!m_notifications) return; auto notification = GUI::Notification::construct(); - notification->set_title("Network"); + notification->set_title("Network"_string); notification->set_icon(m_connected_icon); - notification->set_text("Network connected"); + notification->set_text("Network connected"_string); notification->show(); } @@ -88,9 +88,9 @@ private: if (!m_notifications) return; auto notification = GUI::Notification::construct(); - notification->set_title("Network"); + notification->set_title("Network"_string); notification->set_icon(m_disconnected_icon); - notification->set_text("Network disconnected"); + notification->set_text("Network disconnected"_string); notification->show(); } diff --git a/Userland/DevTools/HackStudio/LanguageClient.cpp b/Userland/DevTools/HackStudio/LanguageClient.cpp index 9dfb6f7e62..a28eb13318 100644 --- a/Userland/DevTools/HackStudio/LanguageClient.cpp +++ b/Userland/DevTools/HackStudio/LanguageClient.cpp @@ -212,16 +212,16 @@ void ConnectionToServerWrapper::show_frequent_crashes_notification() const { auto notification = GUI::Notification::construct(); notification->set_icon(Gfx::Bitmap::load_from_file("/res/icons/32x32/app-hack-studio.png"sv).release_value_but_fixme_should_propagate_errors()); - notification->set_title("LanguageServer Crashes too much!"); - notification->set_text("LanguageServer aided features will not be available in this session"); + notification->set_title("LanguageServer Crashes too much!"_string); + notification->set_text("LanguageServer aided features will not be available in this session"_string); notification->show(); } void ConnectionToServerWrapper::show_crash_notification() const { auto notification = GUI::Notification::construct(); notification->set_icon(Gfx::Bitmap::load_from_file("/res/icons/32x32/app-hack-studio.png"sv).release_value_but_fixme_should_propagate_errors()); - notification->set_title("Oops!"); - notification->set_text(DeprecatedString::formatted("LanguageServer has crashed")); + notification->set_title("Oops!"_string); + notification->set_text("LanguageServer has crashed"_string); notification->show(); } diff --git a/Userland/DevTools/HackStudio/main.cpp b/Userland/DevTools/HackStudio/main.cpp index 3757a5dc7b..afd0920831 100644 --- a/Userland/DevTools/HackStudio/main.cpp +++ b/Userland/DevTools/HackStudio/main.cpp @@ -113,8 +113,8 @@ static ErrorOr notify_make_not_available() auto notification = GUI::Notification::construct(); auto icon = TRY(Gfx::Bitmap::load_from_file("/res/icons/32x32/app-hack-studio.png"sv)); notification->set_icon(icon); - notification->set_title("'make' Not Available"); - notification->set_text("You probably want to install the binutils, gcc, and make ports from the root of the Serenity repository"); + notification->set_title("'make' Not Available"_string); + notification->set_text("You probably want to install the binutils, gcc, and make ports from the root of the Serenity repository"_string); notification->show(); return {}; } diff --git a/Userland/Libraries/LibGUI/Notification.h b/Userland/Libraries/LibGUI/Notification.h index 7a4821a86c..33220c1aa2 100644 --- a/Userland/Libraries/LibGUI/Notification.h +++ b/Userland/Libraries/LibGUI/Notification.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include @@ -21,15 +22,15 @@ class Notification : public Core::EventReceiver { public: virtual ~Notification() override; - DeprecatedString const& text() const { return m_text; } - void set_text(DeprecatedString const& text) + String const& text() const { return m_text; } + void set_text(String const& text) { m_text_dirty = true; m_text = text; } - DeprecatedString const& title() const { return m_title; } - void set_title(DeprecatedString const& title) + String const& title() const { return m_title; } + void set_title(String const& title) { m_title_dirty = true; m_title = title; @@ -53,9 +54,9 @@ private: void connection_closed(); - DeprecatedString m_title; + String m_title; bool m_title_dirty; - DeprecatedString m_text; + String m_text; bool m_text_dirty; RefPtr m_icon; bool m_icon_dirty; diff --git a/Userland/Services/NotificationServer/ConnectionFromClient.cpp b/Userland/Services/NotificationServer/ConnectionFromClient.cpp index 1effb3ebae..7881d791fb 100644 --- a/Userland/Services/NotificationServer/ConnectionFromClient.cpp +++ b/Userland/Services/NotificationServer/ConnectionFromClient.cpp @@ -24,7 +24,7 @@ void ConnectionFromClient::die() s_connections.remove(client_id()); } -void ConnectionFromClient::show_notification(DeprecatedString const& text, DeprecatedString const& title, Gfx::ShareableBitmap const& icon) +void ConnectionFromClient::show_notification(String const& text, String const& title, Gfx::ShareableBitmap const& icon) { auto window = NotificationWindow::construct(client_id(), text, title, icon); window->show(); @@ -47,7 +47,7 @@ Messages::NotificationServer::UpdateNotificationIconResponse ConnectionFromClien return !!window; } -Messages::NotificationServer::UpdateNotificationTextResponse ConnectionFromClient::update_notification_text(DeprecatedString const& text, DeprecatedString const& title) +Messages::NotificationServer::UpdateNotificationTextResponse ConnectionFromClient::update_notification_text(String const& text, String const& title) { auto window = NotificationWindow::get_window_by_id(client_id()); if (window) { diff --git a/Userland/Services/NotificationServer/ConnectionFromClient.h b/Userland/Services/NotificationServer/ConnectionFromClient.h index 4e6875d1de..0db3c48b3e 100644 --- a/Userland/Services/NotificationServer/ConnectionFromClient.h +++ b/Userland/Services/NotificationServer/ConnectionFromClient.h @@ -23,10 +23,10 @@ public: private: explicit ConnectionFromClient(NonnullOwnPtr, int client_id); - virtual void show_notification(DeprecatedString const&, DeprecatedString const&, Gfx::ShareableBitmap const&) override; + virtual void show_notification(String const&, String const&, Gfx::ShareableBitmap const&) override; virtual void close_notification() override; virtual Messages::NotificationServer::UpdateNotificationIconResponse update_notification_icon(Gfx::ShareableBitmap const&) override; - virtual Messages::NotificationServer::UpdateNotificationTextResponse update_notification_text(DeprecatedString const&, DeprecatedString const&) override; + virtual Messages::NotificationServer::UpdateNotificationTextResponse update_notification_text(String const&, String const&) override; virtual Messages::NotificationServer::IsShowingResponse is_showing() override; }; diff --git a/Userland/Services/NotificationServer/NotificationServer.ipc b/Userland/Services/NotificationServer/NotificationServer.ipc index a907a63b78..9b1828e051 100644 --- a/Userland/Services/NotificationServer/NotificationServer.ipc +++ b/Userland/Services/NotificationServer/NotificationServer.ipc @@ -2,9 +2,9 @@ endpoint NotificationServer { - show_notification([UTF8] DeprecatedString text, [UTF8] DeprecatedString title, Gfx::ShareableBitmap icon) => () + show_notification(String text, String title, Gfx::ShareableBitmap icon) => () - update_notification_text([UTF8] DeprecatedString text, [UTF8] DeprecatedString title) => (bool still_showing) + update_notification_text(String text, String title) => (bool still_showing) update_notification_icon(Gfx::ShareableBitmap icon) => (bool still_showing) diff --git a/Userland/Services/NotificationServer/NotificationWindow.cpp b/Userland/Services/NotificationServer/NotificationWindow.cpp index b9ae0d9b6a..78ca448194 100644 --- a/Userland/Services/NotificationServer/NotificationWindow.cpp +++ b/Userland/Services/NotificationServer/NotificationWindow.cpp @@ -38,7 +38,7 @@ static void update_notification_window_locations(Gfx::IntRect const& screen_rect } } -NotificationWindow::NotificationWindow(i32 client_id, DeprecatedString const& text, DeprecatedString const& title, Gfx::ShareableBitmap const& icon) +NotificationWindow::NotificationWindow(i32 client_id, String const& text, String const& title, Gfx::ShareableBitmap const& icon) { m_id = client_id; @@ -82,10 +82,10 @@ NotificationWindow::NotificationWindow(i32 client_id, DeprecatedString const& te auto& left_container = widget->add(); left_container.set_layout(); - m_title_label = &left_container.add(String::from_deprecated_string(title).release_value_but_fixme_should_propagate_errors()); + m_title_label = &left_container.add(title); m_title_label->set_font(Gfx::FontDatabase::default_font().bold_variant()); m_title_label->set_text_alignment(Gfx::TextAlignment::CenterLeft); - m_text_label = &left_container.add(String::from_deprecated_string(text).release_value_but_fixme_should_propagate_errors()); + m_text_label = &left_container.add(text); m_text_label->set_text_alignment(Gfx::TextAlignment::CenterLeft); // FIXME: There used to be code for setting the tooltip here, but since we @@ -130,16 +130,16 @@ void NotificationWindow::leave_event(Core::Event&) update_notification_window_locations(GUI::Desktop::the().rect()); } -void NotificationWindow::set_text(DeprecatedString const& value) +void NotificationWindow::set_text(String const& value) { - m_text_label->set_text(String::from_deprecated_string(value).release_value_but_fixme_should_propagate_errors()); + m_text_label->set_text(value); if (m_hovering) resize_to_fit_text(); } -void NotificationWindow::set_title(DeprecatedString const& value) +void NotificationWindow::set_title(String const& value) { - m_title_label->set_text(String::from_deprecated_string(value).release_value_but_fixme_should_propagate_errors()); + m_title_label->set_text(value); } void NotificationWindow::set_image(Gfx::ShareableBitmap const& image) diff --git a/Userland/Services/NotificationServer/NotificationWindow.h b/Userland/Services/NotificationServer/NotificationWindow.h index a1e12a31f7..909f8087c9 100644 --- a/Userland/Services/NotificationServer/NotificationWindow.h +++ b/Userland/Services/NotificationServer/NotificationWindow.h @@ -18,8 +18,8 @@ public: virtual ~NotificationWindow() override = default; void set_original_rect(Gfx::IntRect original_rect) { m_original_rect = original_rect; } - void set_text(DeprecatedString const&); - void set_title(DeprecatedString const&); + void set_text(String const&); + void set_title(String const&); void set_image(Gfx::ShareableBitmap const&); static RefPtr get_window_by_id(i32 id); @@ -29,7 +29,7 @@ protected: virtual void leave_event(Core::Event&) override; private: - NotificationWindow(i32 client_id, DeprecatedString const& text, DeprecatedString const& title, Gfx::ShareableBitmap const&); + NotificationWindow(i32 client_id, String const& text, String const& title, Gfx::ShareableBitmap const&); virtual void screen_rects_change_event(GUI::ScreenRectsChangeEvent&) override; diff --git a/Userland/Utilities/notify.cpp b/Userland/Utilities/notify.cpp index 963a79f67e..5f8fb6a276 100644 --- a/Userland/Utilities/notify.cpp +++ b/Userland/Utilities/notify.cpp @@ -15,8 +15,8 @@ ErrorOr serenity_main(Main::Arguments arguments) auto app = TRY(GUI::Application::create(arguments)); Core::ArgsParser args_parser; - StringView title {}; - StringView message {}; + String title {}; + String message {}; StringView icon_path {}; args_parser.add_positional_argument(title, "Title of the notification", "title"); args_parser.add_positional_argument(message, "Message to display in the notification", "message");