summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorNick Johnson <sylvyrfysh@gmail.com>2021-03-11 15:43:01 -0600
committerAndreas Kling <kling@serenityos.org>2021-03-22 12:46:16 +0100
commit8f6894d25077d82f01cbea310467e4d5eb56d311 (patch)
tree3906fb4adfb6f303fc567062717c6f2275130e5f /Userland/Libraries
parent147a2c4ca26e88c76557b59cb1e1dc6486d188fd (diff)
downloadserenity-8f6894d25077d82f01cbea310467e4d5eb56d311.zip
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.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGUI/Notification.cpp46
-rw-r--r--Userland/Libraries/LibGUI/Notification.h22
2 files changed, 65 insertions, 3 deletions
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<Messages::NotificationServer::UpdateNotificationText>(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<Messages::NotificationServer::UpdateNotificationIcon>(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<Messages::NotificationServer::IsShowing>();
+ 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<Gfx::Bitmap> m_icon;
+ bool m_icon_dirty;
NonnullRefPtr<NotificationServerConnection> m_connection;
bool m_showing { false };