1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:48:11 +00:00

Userland: Migrate to String in notification system

This commit is contained in:
kleines Filmröllchen 2023-08-31 18:50:32 +02:00 committed by Andrew Kaster
parent f46b393d2d
commit a7c770268f
10 changed files with 35 additions and 34 deletions

View file

@ -77,9 +77,9 @@ private:
if (!m_notifications) if (!m_notifications)
return; return;
auto notification = GUI::Notification::construct(); auto notification = GUI::Notification::construct();
notification->set_title("Network"); notification->set_title("Network"_string);
notification->set_icon(m_connected_icon); notification->set_icon(m_connected_icon);
notification->set_text("Network connected"); notification->set_text("Network connected"_string);
notification->show(); notification->show();
} }
@ -88,9 +88,9 @@ private:
if (!m_notifications) if (!m_notifications)
return; return;
auto notification = GUI::Notification::construct(); auto notification = GUI::Notification::construct();
notification->set_title("Network"); notification->set_title("Network"_string);
notification->set_icon(m_disconnected_icon); notification->set_icon(m_disconnected_icon);
notification->set_text("Network disconnected"); notification->set_text("Network disconnected"_string);
notification->show(); notification->show();
} }

View file

@ -212,16 +212,16 @@ void ConnectionToServerWrapper::show_frequent_crashes_notification() const
{ {
auto notification = GUI::Notification::construct(); 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_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_title("LanguageServer Crashes too much!"_string);
notification->set_text("LanguageServer aided features will not be available in this session"); notification->set_text("LanguageServer aided features will not be available in this session"_string);
notification->show(); notification->show();
} }
void ConnectionToServerWrapper::show_crash_notification() const void ConnectionToServerWrapper::show_crash_notification() const
{ {
auto notification = GUI::Notification::construct(); 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_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_title("Oops!"_string);
notification->set_text(DeprecatedString::formatted("LanguageServer has crashed")); notification->set_text("LanguageServer has crashed"_string);
notification->show(); notification->show();
} }

View file

@ -113,8 +113,8 @@ static ErrorOr<void> notify_make_not_available()
auto notification = GUI::Notification::construct(); auto notification = GUI::Notification::construct();
auto icon = TRY(Gfx::Bitmap::load_from_file("/res/icons/32x32/app-hack-studio.png"sv)); auto icon = TRY(Gfx::Bitmap::load_from_file("/res/icons/32x32/app-hack-studio.png"sv));
notification->set_icon(icon); notification->set_icon(icon);
notification->set_title("'make' Not Available"); 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"); notification->set_text("You probably want to install the binutils, gcc, and make ports from the root of the Serenity repository"_string);
notification->show(); notification->show();
return {}; return {};
} }

View file

@ -6,6 +6,7 @@
#pragma once #pragma once
#include <AK/String.h>
#include <LibCore/EventReceiver.h> #include <LibCore/EventReceiver.h>
#include <LibGfx/Bitmap.h> #include <LibGfx/Bitmap.h>
@ -21,15 +22,15 @@ class Notification : public Core::EventReceiver {
public: public:
virtual ~Notification() override; virtual ~Notification() override;
DeprecatedString const& text() const { return m_text; } String const& text() const { return m_text; }
void set_text(DeprecatedString const& text) void set_text(String const& text)
{ {
m_text_dirty = true; m_text_dirty = true;
m_text = text; m_text = text;
} }
DeprecatedString const& title() const { return m_title; } String const& title() const { return m_title; }
void set_title(DeprecatedString const& title) void set_title(String const& title)
{ {
m_title_dirty = true; m_title_dirty = true;
m_title = title; m_title = title;
@ -53,9 +54,9 @@ private:
void connection_closed(); void connection_closed();
DeprecatedString m_title; String m_title;
bool m_title_dirty; bool m_title_dirty;
DeprecatedString m_text; String m_text;
bool m_text_dirty; bool m_text_dirty;
RefPtr<Gfx::Bitmap const> m_icon; RefPtr<Gfx::Bitmap const> m_icon;
bool m_icon_dirty; bool m_icon_dirty;

View file

@ -24,7 +24,7 @@ void ConnectionFromClient::die()
s_connections.remove(client_id()); 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); auto window = NotificationWindow::construct(client_id(), text, title, icon);
window->show(); window->show();
@ -47,7 +47,7 @@ Messages::NotificationServer::UpdateNotificationIconResponse ConnectionFromClien
return !!window; 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()); auto window = NotificationWindow::get_window_by_id(client_id());
if (window) { if (window) {

View file

@ -23,10 +23,10 @@ public:
private: private:
explicit ConnectionFromClient(NonnullOwnPtr<Core::LocalSocket>, int client_id); explicit ConnectionFromClient(NonnullOwnPtr<Core::LocalSocket>, 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 void close_notification() override;
virtual Messages::NotificationServer::UpdateNotificationIconResponse update_notification_icon(Gfx::ShareableBitmap const&) 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; virtual Messages::NotificationServer::IsShowingResponse is_showing() override;
}; };

View file

@ -2,9 +2,9 @@
endpoint NotificationServer 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) update_notification_icon(Gfx::ShareableBitmap icon) => (bool still_showing)

View file

@ -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; m_id = client_id;
@ -82,10 +82,10 @@ NotificationWindow::NotificationWindow(i32 client_id, DeprecatedString const& te
auto& left_container = widget->add<GUI::Widget>(); auto& left_container = widget->add<GUI::Widget>();
left_container.set_layout<GUI::VerticalBoxLayout>(); left_container.set_layout<GUI::VerticalBoxLayout>();
m_title_label = &left_container.add<GUI::Label>(String::from_deprecated_string(title).release_value_but_fixme_should_propagate_errors()); m_title_label = &left_container.add<GUI::Label>(title);
m_title_label->set_font(Gfx::FontDatabase::default_font().bold_variant()); m_title_label->set_font(Gfx::FontDatabase::default_font().bold_variant());
m_title_label->set_text_alignment(Gfx::TextAlignment::CenterLeft); m_title_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
m_text_label = &left_container.add<GUI::Label>(String::from_deprecated_string(text).release_value_but_fixme_should_propagate_errors()); m_text_label = &left_container.add<GUI::Label>(text);
m_text_label->set_text_alignment(Gfx::TextAlignment::CenterLeft); m_text_label->set_text_alignment(Gfx::TextAlignment::CenterLeft);
// FIXME: There used to be code for setting the tooltip here, but since we // 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()); 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) if (m_hovering)
resize_to_fit_text(); 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) void NotificationWindow::set_image(Gfx::ShareableBitmap const& image)

View file

@ -18,8 +18,8 @@ public:
virtual ~NotificationWindow() override = default; virtual ~NotificationWindow() override = default;
void set_original_rect(Gfx::IntRect original_rect) { m_original_rect = original_rect; } void set_original_rect(Gfx::IntRect original_rect) { m_original_rect = original_rect; }
void set_text(DeprecatedString const&); void set_text(String const&);
void set_title(DeprecatedString const&); void set_title(String const&);
void set_image(Gfx::ShareableBitmap const&); void set_image(Gfx::ShareableBitmap const&);
static RefPtr<NotificationWindow> get_window_by_id(i32 id); static RefPtr<NotificationWindow> get_window_by_id(i32 id);
@ -29,7 +29,7 @@ protected:
virtual void leave_event(Core::Event&) override; virtual void leave_event(Core::Event&) override;
private: 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; virtual void screen_rects_change_event(GUI::ScreenRectsChangeEvent&) override;

View file

@ -15,8 +15,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto app = TRY(GUI::Application::create(arguments)); auto app = TRY(GUI::Application::create(arguments));
Core::ArgsParser args_parser; Core::ArgsParser args_parser;
StringView title {}; String title {};
StringView message {}; String message {};
StringView icon_path {}; StringView icon_path {};
args_parser.add_positional_argument(title, "Title of the notification", "title"); args_parser.add_positional_argument(title, "Title of the notification", "title");
args_parser.add_positional_argument(message, "Message to display in the notification", "message"); args_parser.add_positional_argument(message, "Message to display in the notification", "message");