mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:27:35 +00:00
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.
This commit is contained in:
parent
147a2c4ca2
commit
8f6894d250
7 changed files with 119 additions and 7 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue