109 lines
3.8 KiB
C++
109 lines
3.8 KiB
C++
#include "widgets/notification/notificationWindow.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <sys/types.h>
|
|
|
|
#include "components/button/textButton.hpp"
|
|
#include "helpers/string.hpp"
|
|
|
|
#include "gtkmm/box.h"
|
|
#include "gtkmm/image.h"
|
|
#include "gtkmm/label.h"
|
|
|
|
NotificationWindow::NotificationWindow(uint64_t notificationId, std::shared_ptr<Gdk::Monitor> monitor, NotifyMessage notify) : BaseNotification(notificationId, monitor) {
|
|
set_title(notify.summary);
|
|
|
|
// Main vertical box
|
|
auto vbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::VERTICAL, 8);
|
|
vbox->set_halign(Gtk::Align::FILL);
|
|
|
|
switch (notify.urgency) {
|
|
case NotificationUrgency::CRITICAL:
|
|
add_css_class("notification-critical");
|
|
break;
|
|
case NotificationUrgency::NORMAL:
|
|
add_css_class("notification-normal");
|
|
break;
|
|
case NotificationUrgency::LOW:
|
|
add_css_class("notification-low");
|
|
break;
|
|
}
|
|
|
|
auto header_box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL);
|
|
header_box->set_halign(Gtk::Align::START);
|
|
header_box->add_css_class("notification-header");
|
|
header_box->set_hexpand(true);
|
|
header_box->set_halign(Gtk::Align::FILL);
|
|
|
|
if (notify.imageData) {
|
|
auto img = Gtk::make_managed<Gtk::Image>(*(notify.imageData));
|
|
img->set_pixel_size(16);
|
|
img->set_halign(Gtk::Align::START);
|
|
img->set_valign(Gtk::Align::CENTER);
|
|
img->add_css_class("notification-app-icon");
|
|
header_box->append(*img);
|
|
}
|
|
|
|
auto app_label = Gtk::make_managed<Gtk::Label>(notify.app_name);
|
|
app_label->set_halign(Gtk::Align::START);
|
|
app_label->set_ellipsize(Pango::EllipsizeMode::END);
|
|
app_label->set_max_width_chars(24);
|
|
app_label->set_wrap(false);
|
|
app_label->add_css_class("notification-app-name");
|
|
header_box->append(*app_label);
|
|
vbox->append(*header_box);
|
|
|
|
// Summary label
|
|
auto summary_label = Gtk::make_managed<Gtk::Label>("<b>" + notify.summary + "</b>");
|
|
summary_label->set_use_markup(true);
|
|
summary_label->set_halign(Gtk::Align::START);
|
|
summary_label->set_ellipsize(Pango::EllipsizeMode::END);
|
|
summary_label->set_lines(1);
|
|
summary_label->set_wrap(true);
|
|
vbox->append(*summary_label);
|
|
|
|
auto body_label = Gtk::make_managed<Gtk::Label>(notify.body);
|
|
body_label->set_use_markup(true);
|
|
body_label->set_halign(Gtk::Align::START);
|
|
body_label->set_ellipsize(Pango::EllipsizeMode::END);
|
|
body_label->set_lines(3);
|
|
body_label->set_wrap(true);
|
|
vbox->append(*body_label);
|
|
|
|
// If actions exist, add buttons
|
|
if (!notify.actions.empty()) {
|
|
auto actions_box = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 6);
|
|
for (size_t i = 0; i + 1 < notify.actions.size(); i += 2) {
|
|
std::string action_id = notify.actions[i];
|
|
std::string action_label = notify.actions[i + 1];
|
|
|
|
auto btn = Gtk::make_managed<TextButton>(action_label);
|
|
|
|
btn->add_css_class("notification-button");
|
|
|
|
switch (notify.urgency) {
|
|
case NotificationUrgency::CRITICAL:
|
|
btn->add_css_class("notification-critical");
|
|
break;
|
|
case NotificationUrgency::NORMAL:
|
|
btn->add_css_class("notification-normal");
|
|
break;
|
|
case NotificationUrgency::LOW:
|
|
btn->add_css_class("notification-low");
|
|
break;
|
|
}
|
|
|
|
btn->signal_clicked().connect([this, action_id, cb = notify.on_action, guard = notify.actionInvoked]() {
|
|
if (cb && guard && !*guard) {
|
|
*guard = true;
|
|
cb(action_id);
|
|
this->getSignalClose().emit(this->getNotificationId());
|
|
}
|
|
});
|
|
actions_box->append(*btn);
|
|
}
|
|
vbox->append(*actions_box);
|
|
}
|
|
|
|
set_child(*vbox);
|
|
} |