From 8f6894d25077d82f01cbea310467e4d5eb56d311 Mon Sep 17 00:00:00 2001 From: Nick Johnson Date: Thu, 11 Mar 2021 15:43:01 -0600 Subject: LibGUI+Notification: Add mutable notifications This commit puts all of the remaining pieces in place. This adds a mechanism to update the text, title, and icon of an image. If an image is not provided, the default ladybug will be shown. --- Userland/Libraries/LibGUI/Notification.cpp | 46 ++++++++++++++++++++++++++++++ Userland/Libraries/LibGUI/Notification.h | 22 ++++++++++++-- 2 files changed, 65 insertions(+), 3 deletions(-) (limited to 'Userland/Libraries/LibGUI') diff --git a/Userland/Libraries/LibGUI/Notification.cpp b/Userland/Libraries/LibGUI/Notification.cpp index b4ea45882f..d863309300 100644 --- a/Userland/Libraries/LibGUI/Notification.cpp +++ b/Userland/Libraries/LibGUI/Notification.cpp @@ -85,6 +85,52 @@ void Notification::close() m_showing = false; m_disposed = true; } + +bool Notification::update() +{ + VERIFY(m_showing); + VERIFY(!m_disposed); + if (!m_connection->is_connected()) { + m_showing = false; + m_disposed = true; + return false; + } + + bool is_checked = false; + + if (m_text_dirty || m_title_dirty) { + auto response = m_connection->send_sync(m_text, m_title); + m_text_dirty = false; + m_title_dirty = false; + + is_checked = true; + if (!response->still_showing()) { + m_showing = false; + m_disposed = true; + return false; + } + } + + if (m_icon_dirty) { + auto response = m_connection->send_sync(m_icon ? m_icon->to_shareable_bitmap() : Gfx::ShareableBitmap()); + m_icon_dirty = false; + + is_checked = true; + if (!response->still_showing()) { + m_showing = false; + m_disposed = true; + return false; + } + } + + if (!is_checked) { + auto response = m_connection->send_sync(); + m_showing = response->still_showing(); + if (!m_showing) { + m_disposed = true; + } + } + return m_showing; } } diff --git a/Userland/Libraries/LibGUI/Notification.h b/Userland/Libraries/LibGUI/Notification.h index 445b856411..1dda17d757 100644 --- a/Userland/Libraries/LibGUI/Notification.h +++ b/Userland/Libraries/LibGUI/Notification.h @@ -40,23 +40,39 @@ public: virtual ~Notification() override; const String& text() const { return m_text; } - void set_text(const String& text) { m_text = text; } + void set_text(const String& text) + { + m_text_dirty = true; + m_text = text; + } const String& title() const { return m_title; } - void set_title(const String& title) { m_title = title; } + void set_title(const String& title) + { + m_title_dirty = true; + m_title = title; + } const Gfx::Bitmap* icon() const { return m_icon; } - void set_icon(const Gfx::Bitmap* icon) { m_icon = icon; } + void set_icon(const Gfx::Bitmap* icon) + { + m_icon_dirty = true; + m_icon = icon; + } void show(); + bool update(); void close(); private: Notification(); String m_title; + bool m_title_dirty; String m_text; + bool m_text_dirty; RefPtr m_icon; + bool m_icon_dirty; NonnullRefPtr m_connection; bool m_showing { false }; -- cgit v1.2.3