2020-04-06 11:09:01 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
2022-02-26 10:50:04 -07:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-04-06 11:09:01 +02:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-04-06 11:09:01 +02:00
|
|
|
*/
|
|
|
|
|
|
2020-02-16 19:28:08 +01:00
|
|
|
#include <LibGUI/Notification.h>
|
2022-02-25 12:27:37 +02:00
|
|
|
#include <LibIPC/ConnectionToServer.h>
|
2020-02-16 19:28:08 +01:00
|
|
|
#include <NotificationServer/NotificationClientEndpoint.h>
|
|
|
|
|
#include <NotificationServer/NotificationServerEndpoint.h>
|
|
|
|
|
|
|
|
|
|
namespace GUI {
|
|
|
|
|
|
2022-02-25 13:09:27 +02:00
|
|
|
class ConnectionToNotificationServer final
|
2022-02-25 12:27:37 +02:00
|
|
|
: public IPC::ConnectionToServer<NotificationClientEndpoint, NotificationServerEndpoint>
|
2020-02-16 19:28:08 +01:00
|
|
|
, public NotificationClientEndpoint {
|
2022-07-24 15:30:48 +02:00
|
|
|
IPC_CLIENT_CONNECTION(ConnectionToNotificationServer, "/tmp/user/%uid/portal/notify"sv)
|
2021-03-13 15:51:33 -06:00
|
|
|
|
|
|
|
|
friend class Notification;
|
|
|
|
|
|
2020-02-16 19:28:08 +01:00
|
|
|
public:
|
2021-03-13 15:51:33 -06:00
|
|
|
virtual void die() override
|
|
|
|
|
{
|
|
|
|
|
m_notification->connection_closed();
|
|
|
|
|
}
|
2021-03-11 15:33:37 -06:00
|
|
|
|
2020-02-16 19:28:08 +01:00
|
|
|
private:
|
2022-02-25 13:09:27 +02:00
|
|
|
explicit ConnectionToNotificationServer(NonnullOwnPtr<Core::Stream::LocalSocket> socket, Notification* notification)
|
2022-02-25 12:27:37 +02:00
|
|
|
: IPC::ConnectionToServer<NotificationClientEndpoint, NotificationServerEndpoint>(*this, move(socket))
|
2021-03-13 15:51:33 -06:00
|
|
|
, m_notification(notification)
|
2020-02-16 19:28:08 +01:00
|
|
|
{
|
|
|
|
|
}
|
2021-03-13 15:51:33 -06:00
|
|
|
Notification* m_notification;
|
2020-02-16 19:28:08 +01:00
|
|
|
};
|
|
|
|
|
|
2022-02-26 10:50:04 -07:00
|
|
|
Notification::Notification() = default;
|
|
|
|
|
Notification::~Notification() = default;
|
2020-02-16 19:28:08 +01:00
|
|
|
|
|
|
|
|
void Notification::show()
|
|
|
|
|
{
|
2021-03-13 15:51:33 -06:00
|
|
|
VERIFY(!m_shown && !m_destroyed);
|
2021-01-15 22:36:36 +01:00
|
|
|
auto icon = m_icon ? m_icon->to_shareable_bitmap() : Gfx::ShareableBitmap();
|
2022-02-25 13:09:27 +02:00
|
|
|
m_connection = ConnectionToNotificationServer::try_create(this).release_value_but_fixme_should_propagate_errors();
|
2021-05-03 13:33:59 +02:00
|
|
|
m_connection->show_notification(m_text, m_title, icon);
|
2021-03-13 15:51:33 -06:00
|
|
|
m_shown = true;
|
2021-03-11 14:21:06 -06:00
|
|
|
}
|
2021-03-11 15:33:37 -06:00
|
|
|
|
2021-03-11 14:21:06 -06:00
|
|
|
void Notification::close()
|
|
|
|
|
{
|
2021-03-13 15:51:33 -06:00
|
|
|
VERIFY(m_shown);
|
|
|
|
|
if (!m_destroyed) {
|
2021-05-03 13:33:59 +02:00
|
|
|
m_connection->close_notification();
|
2021-03-13 15:51:33 -06:00
|
|
|
connection_closed();
|
2021-03-12 11:53:51 -06:00
|
|
|
return;
|
2021-03-11 15:33:37 -06:00
|
|
|
}
|
|
|
|
|
}
|
2021-03-11 15:43:01 -06:00
|
|
|
|
|
|
|
|
bool Notification::update()
|
|
|
|
|
{
|
2021-03-13 15:51:33 -06:00
|
|
|
VERIFY(m_shown);
|
|
|
|
|
if (m_destroyed) {
|
2021-03-11 15:43:01 -06:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_text_dirty || m_title_dirty) {
|
2021-05-03 13:33:59 +02:00
|
|
|
m_connection->update_notification_text(m_text, m_title);
|
2021-03-11 15:43:01 -06:00
|
|
|
m_text_dirty = false;
|
|
|
|
|
m_title_dirty = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_icon_dirty) {
|
2021-05-03 13:33:59 +02:00
|
|
|
m_connection->update_notification_icon(m_icon ? m_icon->to_shareable_bitmap() : Gfx::ShareableBitmap());
|
2021-03-11 15:43:01 -06:00
|
|
|
m_icon_dirty = false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 11:53:51 -06:00
|
|
|
return true;
|
2020-02-16 19:28:08 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-13 15:51:33 -06:00
|
|
|
void Notification::connection_closed()
|
|
|
|
|
{
|
|
|
|
|
m_connection.clear();
|
|
|
|
|
m_destroyed = true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-16 19:28:08 +01:00
|
|
|
}
|