2018-04-17 12:01:55 +00:00
|
|
|
using Gtk;
|
|
|
|
using Granite;
|
|
|
|
|
2019-03-11 14:14:37 +00:00
|
|
|
public class Tootle.Widgets.Notification : Grid {
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2019-03-11 14:14:37 +00:00
|
|
|
private API.Notification notification;
|
2018-04-17 12:01:55 +00:00
|
|
|
|
2018-06-06 14:19:11 +00:00
|
|
|
public Separator? separator;
|
|
|
|
private Image image;
|
2019-03-11 14:14:37 +00:00
|
|
|
private Widgets.RichLabel label;
|
|
|
|
private Widgets.Status? status_widget;
|
2018-06-06 14:19:11 +00:00
|
|
|
private Button dismiss;
|
2018-04-17 12:01:55 +00:00
|
|
|
|
|
|
|
construct {
|
|
|
|
margin = 6;
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2018-10-30 15:57:37 +00:00
|
|
|
image = new Image.from_icon_name ("notification-symbolic", IconSize.BUTTON);
|
2018-04-17 12:01:55 +00:00
|
|
|
image.margin_start = 32;
|
|
|
|
image.margin_end = 6;
|
2018-04-28 16:27:10 +00:00
|
|
|
label = new RichLabel (_("Unknown Notification"));
|
2018-04-17 12:01:55 +00:00
|
|
|
label.hexpand = true;
|
2018-10-30 15:57:37 +00:00
|
|
|
label.halign = Align.START;
|
2019-03-09 14:45:16 +00:00
|
|
|
dismiss = new Button.from_icon_name ("window-close-symbolic", IconSize.BUTTON);
|
2018-05-09 15:32:53 +00:00
|
|
|
dismiss.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
|
|
|
|
dismiss.tooltip_text = _("Dismiss");
|
|
|
|
dismiss.clicked.connect (() => {
|
|
|
|
notification.dismiss ();
|
2018-05-15 11:10:19 +00:00
|
|
|
destroy ();
|
2018-04-17 12:10:57 +00:00
|
|
|
});
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2018-10-30 15:57:37 +00:00
|
|
|
attach (image, 1, 2);
|
|
|
|
attach (label, 2, 2);
|
|
|
|
attach (dismiss, 3, 2);
|
|
|
|
show_all ();
|
2018-04-17 12:01:55 +00:00
|
|
|
}
|
|
|
|
|
2019-03-11 14:14:37 +00:00
|
|
|
public Notification (API.Notification _notification) {
|
2018-10-30 15:57:37 +00:00
|
|
|
notification = _notification;
|
2018-04-17 12:01:55 +00:00
|
|
|
image.icon_name = notification.type.get_icon ();
|
2018-06-06 14:19:11 +00:00
|
|
|
label.set_label (notification.type.get_desc (notification.account));
|
2018-04-17 12:01:55 +00:00
|
|
|
get_style_context ().add_class ("notification");
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2018-10-30 15:57:37 +00:00
|
|
|
if (notification.status != null)
|
|
|
|
network.status_removed.connect (on_status_removed);
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2018-05-09 15:32:53 +00:00
|
|
|
destroy.connect (() => {
|
2018-07-14 08:37:41 +00:00
|
|
|
if (separator != null)
|
|
|
|
separator.destroy ();
|
2018-06-22 17:44:46 +00:00
|
|
|
separator = null;
|
|
|
|
status_widget = null;
|
2018-05-09 15:32:53 +00:00
|
|
|
});
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2018-04-17 12:01:55 +00:00
|
|
|
if (notification.status != null){
|
2019-03-11 14:14:37 +00:00
|
|
|
status_widget = new Widgets.Status (notification.status, true);
|
2018-05-22 13:18:39 +00:00
|
|
|
status_widget.is_notification = true;
|
2018-10-30 15:57:37 +00:00
|
|
|
status_widget.button_press_event.connect (status_widget.open);
|
2019-03-11 12:28:51 +00:00
|
|
|
status_widget.avatar.button_press_event.connect (status_widget.on_avatar_clicked);
|
2018-10-30 15:57:37 +00:00
|
|
|
attach (status_widget, 1, 3, 3, 1);
|
2018-04-17 12:01:55 +00:00
|
|
|
}
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2019-03-11 14:14:37 +00:00
|
|
|
if (notification.type == API.NotificationType.FOLLOW_REQUEST) {
|
2018-10-30 15:57:37 +00:00
|
|
|
var box = new Box (Orientation.HORIZONTAL, 6);
|
2018-05-09 15:32:53 +00:00
|
|
|
box.margin_start = 32 + 16 + 8;
|
2018-10-30 15:57:37 +00:00
|
|
|
var accept = new Button.with_label (_("Accept"));
|
2018-05-09 15:32:53 +00:00
|
|
|
box.pack_start (accept, false, false, 0);
|
2018-10-30 15:57:37 +00:00
|
|
|
var reject = new Button.with_label (_("Reject"));
|
2018-05-09 15:32:53 +00:00
|
|
|
box.pack_start (reject, false, false, 0);
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2018-10-30 15:57:37 +00:00
|
|
|
attach (box, 1, 3, 3, 1);
|
2018-05-09 15:32:53 +00:00
|
|
|
box.show_all ();
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2018-05-09 15:32:53 +00:00
|
|
|
accept.clicked.connect (() => {
|
|
|
|
destroy ();
|
|
|
|
notification.accept_follow_request ();
|
|
|
|
});
|
|
|
|
reject.clicked.connect (() => {
|
|
|
|
destroy ();
|
|
|
|
notification.reject_follow_request ();
|
|
|
|
});
|
|
|
|
}
|
2018-04-17 12:10:57 +00:00
|
|
|
}
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2018-10-30 15:57:37 +00:00
|
|
|
private void on_status_removed (int64 id) {
|
|
|
|
if (id == notification.status.id) {
|
2019-03-11 14:14:37 +00:00
|
|
|
if (notification.type == API.NotificationType.WATCHLIST)
|
2018-10-30 15:57:37 +00:00
|
|
|
notification.dismiss ();
|
2019-03-07 16:16:52 +00:00
|
|
|
|
2018-10-30 15:57:37 +00:00
|
|
|
destroy ();
|
|
|
|
}
|
|
|
|
}
|
2018-04-17 12:01:55 +00:00
|
|
|
|
|
|
|
}
|