2020-02-16 15:28:08 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-02-16 15:28:08 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ClientConnection.h"
|
|
|
|
|
#include "NotificationWindow.h"
|
|
|
|
|
#include <AK/HashMap.h>
|
2020-05-06 12:40:06 -03:00
|
|
|
#include <NotificationServer/NotificationClientEndpoint.h>
|
2020-02-16 15:28:08 -03:00
|
|
|
|
|
|
|
|
namespace NotificationServer {
|
|
|
|
|
|
|
|
|
|
static HashMap<int, RefPtr<ClientConnection>> s_connections;
|
|
|
|
|
|
2020-07-06 08:23:39 -03:00
|
|
|
ClientConnection::ClientConnection(NonnullRefPtr<Core::LocalSocket> client_socket, int client_id)
|
2020-09-12 06:44:00 -03:00
|
|
|
: IPC::ClientConnection<NotificationClientEndpoint, NotificationServerEndpoint>(*this, move(client_socket), client_id)
|
2020-02-16 15:28:08 -03:00
|
|
|
{
|
|
|
|
|
s_connections.set(client_id, *this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClientConnection::~ClientConnection()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClientConnection::die()
|
|
|
|
|
{
|
|
|
|
|
s_connections.remove(client_id());
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-02 14:54:34 -03:00
|
|
|
void ClientConnection::show_notification(String const& text, String const& title, Gfx::ShareableBitmap const& icon)
|
2020-02-16 15:28:08 -03:00
|
|
|
{
|
2021-05-02 14:54:34 -03:00
|
|
|
auto window = NotificationWindow::construct(client_id(), text, title, icon);
|
2020-02-16 15:28:08 -03:00
|
|
|
window->show();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-02 14:54:34 -03:00
|
|
|
void ClientConnection::close_notification()
|
2021-03-11 17:21:06 -03:00
|
|
|
{
|
|
|
|
|
auto window = NotificationWindow::get_window_by_id(client_id());
|
|
|
|
|
if (window) {
|
|
|
|
|
window->close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-02 14:54:34 -03:00
|
|
|
Messages::NotificationServer::UpdateNotificationIconResponse ClientConnection::update_notification_icon(Gfx::ShareableBitmap const& icon)
|
2021-03-11 18:43:01 -03:00
|
|
|
{
|
|
|
|
|
auto window = NotificationWindow::get_window_by_id(client_id());
|
|
|
|
|
if (window) {
|
2021-05-02 14:54:34 -03:00
|
|
|
window->set_image(icon);
|
2021-03-11 18:43:01 -03:00
|
|
|
}
|
2021-05-01 23:39:36 -03:00
|
|
|
return !!window;
|
2021-03-11 18:43:01 -03:00
|
|
|
}
|
|
|
|
|
|
2021-05-02 14:54:34 -03:00
|
|
|
Messages::NotificationServer::UpdateNotificationTextResponse ClientConnection::update_notification_text(String const& text, String const& title)
|
2021-03-11 18:43:01 -03:00
|
|
|
{
|
|
|
|
|
auto window = NotificationWindow::get_window_by_id(client_id());
|
|
|
|
|
if (window) {
|
2021-05-02 14:54:34 -03:00
|
|
|
window->set_text(text);
|
|
|
|
|
window->set_title(title);
|
2021-03-11 18:43:01 -03:00
|
|
|
}
|
2021-05-01 23:39:36 -03:00
|
|
|
return !!window;
|
2021-03-11 18:43:01 -03:00
|
|
|
}
|
|
|
|
|
|
2021-05-02 14:54:34 -03:00
|
|
|
Messages::NotificationServer::IsShowingResponse ClientConnection::is_showing()
|
2021-03-11 18:43:01 -03:00
|
|
|
{
|
|
|
|
|
auto window = NotificationWindow::get_window_by_id(client_id());
|
2021-05-01 23:39:36 -03:00
|
|
|
return !!window;
|
2021-03-11 18:43:01 -03:00
|
|
|
}
|
|
|
|
|
|
2020-02-16 15:28:08 -03:00
|
|
|
}
|