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
66 changes: 4 additions & 62 deletions src/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class Notifications.Indicator : Wingpanel.Indicator {
private Gee.HashMap<string, Settings> app_settings_cache;
private GLib.Settings notify_settings;

private Gtk.Box? main_box = null;
private Wingpanel.PopoverMenuItem clear_all_btn;
private NotificationsIndicator.Symbol? dynamic_icon = null;
private NotificationsList nlist;
private NotificationsMonitor monitor;
Expand Down Expand Up @@ -87,58 +85,16 @@ public class Notifications.Indicator : Wingpanel.Indicator {
}

public override Gtk.Widget? get_widget () {
if (main_box == null) {
var not_disturb_switch = new Granite.SwitchModelButton (_("Do Not Disturb"));
not_disturb_switch.add_css_class (Granite.STYLE_CLASS_H4_LABEL);

var dnd_switch_separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL) {
margin_top = 3
};

var clear_all_btn_separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL) {
margin_bottom = 3
};

clear_all_btn = new Wingpanel.PopoverMenuItem () {
text = _("Clear All Notifications")
};

var settings_btn = new Wingpanel.PopoverMenuItem () {
text = _("Notifications Settings…")
};

main_box = new Gtk.Box (VERTICAL, 0) {
width_request = 360
};
main_box.append (not_disturb_switch);
main_box.append (dnd_switch_separator);
main_box.append (nlist);
main_box.append (clear_all_btn_separator);
main_box.append (clear_all_btn);
main_box.append (settings_btn);

notify_settings.bind ("do-not-disturb", not_disturb_switch, "active", GLib.SettingsBindFlags.DEFAULT);

if (nlist == null) {
nlist.close_popover.connect (() => close ());
nlist.items_changed.connect (update_clear_all_sensitivity);

clear_all_btn.clicked.connect (() => {
nlist.clear_all (); // This calls each appentry's clear method, which also clears session
});

settings_btn.clicked.connect (show_settings);
}

return main_box;
return nlist;
}

public override void opened () {
update_clear_all_sensitivity ();
}

public override void closed () {
public override void opened () { }

}
public override void closed () { }

private void on_notification_received (DBusMessage message, uint32 id) {
var notification = new Notification.from_message (message, id);
Expand All @@ -161,10 +117,6 @@ public class Notifications.Indicator : Wingpanel.Indicator {
set_display_icon_name ();
}

private void update_clear_all_sensitivity () {
clear_all_btn.sensitive = nlist.notification_items.get_n_items () > 0;
}

private void on_notification_closed (uint32 id, Notification.CloseReason reason) {
for (int i = 0; i < nlist.notification_items.get_n_items (); i++) {
var notification = (Notification) nlist.notification_items.get_item (i);
Expand All @@ -186,16 +138,6 @@ public class Notifications.Indicator : Wingpanel.Indicator {
update_tooltip ();
}

private void show_settings () {
close ();

try {
AppInfo.launch_default_for_uri ("settings://notifications", null);
} catch (Error e) {
warning ("Failed to open notifications settings: %s", e.message);
}
}

private void update_tooltip () {
var number_of_notifications = nlist.notification_items.get_n_items ();
string[] accels = {};
Expand Down
52 changes: 51 additions & 1 deletion src/Widgets/NotificationsList.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Notifications.NotificationsList : Granite.Bin {

private static GLib.HashTable<string, GLib.DateTime> app_datetime;

private Gtk.Button clear_all_btn;
private Gtk.SortListModel sort_list_model;
private Gtk.Stack stack;

Expand All @@ -27,6 +28,24 @@ public class Notifications.NotificationsList : Granite.Bin {
}

construct {
var not_disturb_switch = new Granite.SwitchModelButton (_("Do Not Disturb"));
Comment thread
zeebok marked this conversation as resolved.

var dnd_switch_separator = new Gtk.Separator (HORIZONTAL) {
margin_top = 3
};

var clear_all_btn_separator = new Gtk.Separator (HORIZONTAL) {
margin_bottom = 3
};

clear_all_btn = new Wingpanel.PopoverMenuItem () {
text = _("Clear All Notifications")
};

var settings_btn = new Wingpanel.PopoverMenuItem () {
text = _("Notifications Settings…")
};

var placeholder = new Gtk.Label (_("No Notifications")) {
margin_top = 24,
margin_bottom = 24,
Expand Down Expand Up @@ -71,7 +90,17 @@ public class Notifications.NotificationsList : Granite.Bin {
stack.add_named (placeholder, "placeholder");
stack.add_named (scrolled, "list");

child = stack;
var main_box = new Gtk.Box (VERTICAL, 0) {
width_request = 360
};
main_box.append (not_disturb_switch);
main_box.append (dnd_switch_separator);
main_box.append (stack);
main_box.append (clear_all_btn_separator);
main_box.append (clear_all_btn);
main_box.append (settings_btn);

child = main_box;

insert_action_group (ACTION_GROUP_PREFIX, new NotificationsMonitor ().notifications_action_group);

Expand All @@ -86,6 +115,12 @@ public class Notifications.NotificationsList : Granite.Bin {
add_entry (notification);
}
});

var settings = new GLib.Settings ("io.elementary.notifications");
settings.bind ("do-not-disturb", not_disturb_switch, "active", DEFAULT);

clear_all_btn.clicked.connect (clear_all);
settings_btn.clicked.connect (show_settings);
}

private static int section_compare (Notification a, Notification b) {
Expand Down Expand Up @@ -148,6 +183,19 @@ public class Notifications.NotificationsList : Granite.Bin {
close_popover ();
}

private void show_settings () {
close_popover ();

var uri_launcher = new Gtk.UriLauncher (Granite.SettingsUri.NOTIFICATIONS);
uri_launcher.launch.begin ((Gtk.Window) get_root (), null, (obj, res) => {
try {
uri_launcher.launch.end (res);
} catch (Error e) {
warning ("Failed to open notifications settings: %s", e.message);
}
});
}

public uint get_n_app_items () {
var app_list = new GenericSet<string> (str_hash, str_equal);
for (var i = 0; i < list_store.n_items; i++) {
Expand Down Expand Up @@ -180,6 +228,8 @@ public class Notifications.NotificationsList : Granite.Bin {
stack.visible_child_name = "list";
}

clear_all_btn.sensitive = list_store.n_items > 0;

items_changed ();
}

Expand Down
Loading