diff --git a/src/Indicator.vala b/src/Indicator.vala index 0b70f837..ed1b1128 100644 --- a/src/Indicator.vala +++ b/src/Indicator.vala @@ -13,8 +13,6 @@ public class Notifications.Indicator : Wingpanel.Indicator { private Gee.HashMap 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; @@ -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); @@ -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); @@ -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 = {}; diff --git a/src/Widgets/NotificationsList.vala b/src/Widgets/NotificationsList.vala index e83e35a4..0f12f9e8 100644 --- a/src/Widgets/NotificationsList.vala +++ b/src/Widgets/NotificationsList.vala @@ -19,6 +19,7 @@ public class Notifications.NotificationsList : Granite.Bin { private static GLib.HashTable app_datetime; + private Gtk.Button clear_all_btn; private Gtk.SortListModel sort_list_model; private Gtk.Stack stack; @@ -27,6 +28,24 @@ public class Notifications.NotificationsList : Granite.Bin { } construct { + var not_disturb_switch = new Granite.SwitchModelButton (_("Do Not Disturb")); + + 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, @@ -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); @@ -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) { @@ -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 (str_hash, str_equal); for (var i = 0; i < list_store.n_items; i++) { @@ -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 (); }