Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ public class Notifications.Indicator : Wingpanel.Indicator {
var clear_all_action = new SimpleAction ("clear-all", null);
clear_all_action.activate.connect (clear_all);

var clear_app_action = new SimpleAction ("clear-app", VariantType.STRING);
clear_app_action.activate.connect (clear_app);

action_group = new SimpleActionGroup ();
action_group.add_action (clear_all_action);
action_group.add_action (clear_app_action);
}

public override Gtk.Widget get_display_widget () {
Expand Down Expand Up @@ -154,14 +158,14 @@ public class Notifications.Indicator : Wingpanel.Indicator {
}

private void remove_notification (Notification notification) {
var app_id = notification.desktop_id;
Session.get_instance ().remove_notification (notification);

uint pos = -1;
if (list_store.find (notification, out pos)) {
list_store.remove (pos);
Session.get_instance ().remove_notification (notification);
}

var app_id = notification.desktop_id;
var items_for_appid = new Gtk.FilterListModel (
list_store, new Gtk.CustomFilter ((item) => {
return ((Notification) item).desktop_id == app_id;
Expand Down Expand Up @@ -197,6 +201,19 @@ public class Notifications.Indicator : Wingpanel.Indicator {
close ();
}

private void clear_app (SimpleAction action, Variant? parameter) {
var app_id = parameter.get_string ();
for (int i = 0; i < list_store.n_items; i++) {
var notification = (Notification) list_store.get_item (i);
if (notification.desktop_id == app_id) {
// Wait so that the header won't be removed before its animation finishes
Timeout.add_once (600, () => {
remove_notification (notification);
});
}
}
}

private void set_display_icon_name () {
if (notify_settings.get_boolean ("do-not-disturb")) {
dynamic_icon.state = NotificationsIndicator.SymbolState.DISABLED;
Expand Down
26 changes: 14 additions & 12 deletions src/Widgets/ListHeader.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*/

public class Notifications.ListHeader : Granite.Bin {
public signal void clear ();

private string _app_id = "";
public string app_id {
get {
Expand All @@ -14,6 +12,11 @@ public class Notifications.ListHeader : Granite.Bin {
set {
_app_id = value;

if (value != null) {
clear_btn_entry.action_target = new Variant.string (value);
}


if (value in headers) {
expander.active = headers[value];
}
Expand All @@ -26,6 +29,7 @@ public class Notifications.ListHeader : Granite.Bin {
private static Settings settings;
private static HashTable<string, bool> headers;

private Gtk.Button clear_btn_entry;
private Gtk.ToggleButton expander;

static construct {
Expand Down Expand Up @@ -64,7 +68,8 @@ public class Notifications.ListHeader : Granite.Bin {
var clear_btn_image = new Gtk.Image.from_icon_name ("edit-clear-all-symbolic");
clear_btn_image.add_css_class ("sweep-animation");

var clear_btn_entry = new Gtk.Button () {
clear_btn_entry = new Gtk.Button () {
action_name = Wingpanel.Indicator.MESSAGES + ".clear-app",
tooltip_text = _("Clear all %s notifications").printf (app_name),
child = clear_btn_image,
has_frame = false
Expand All @@ -80,11 +85,12 @@ public class Notifications.ListHeader : Granite.Bin {

bind_property ("app-name", label, "label");
bind_property ("app-name", clear_btn_entry, "tooltip-text", DEFAULT,
(binding, _app_name, ref _tooltip_text) => {
_tooltip_text = _("Clear all %s notifications").printf ((string) _app_name);
return true;
},
() => { return false; });
(binding, _app_name, ref _tooltip_text) => {
_tooltip_text = _("Clear all %s notifications").printf ((string) _app_name);
return true;
},
() => { return false; }
);

expander.toggled.connect (() => {
headers[app_id] = expander.active;
Expand All @@ -93,10 +99,6 @@ public class Notifications.ListHeader : Granite.Bin {

clear_btn_entry.clicked.connect (() => {
clear_btn_image.add_css_class ("active");
GLib.Timeout.add (600, () => {
clear (); // Causes notification list to destroy this app entry after clearing its notification entries
return GLib.Source.REMOVE;
});
});

expander.bind_property ("active", image, "tooltip-text", SYNC_CREATE, (binding, srcval, ref targetval) => {
Expand Down
20 changes: 1 addition & 19 deletions src/Widgets/NotificationsList.vala
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ public class Notifications.NotificationsList : Granite.Bin {
}

private void setup_header_factory (Object item) {
var app_entry = new ListHeader ();
app_entry.clear.connect (clear_app_entry);

((Gtk.ListHeader) item).child = app_entry;
((Gtk.ListHeader) item).child = new ListHeader ();
}

private void bind_header_factory (Object item) {
Expand All @@ -152,21 +149,6 @@ public class Notifications.NotificationsList : Granite.Bin {
});
}

private void clear_app_entry (ListHeader app_entry) {
app_entry.clear.disconnect (clear_app_entry);

Notification[] to_remove = {};
for (int i = 0; i < list_model.get_n_items (); i++) {
var notification = (Notification) list_model.get_item (i);
if (notification.desktop_id == app_entry.app_id) {
notification.server_id = 0;
to_remove += notification;
}
}

Session.get_instance ().remove_notifications (to_remove);
}

private void on_items_changed () {
if (list_model.get_n_items () == 0) {
stack.visible_child_name = "placeholder";
Expand Down
Loading