From 398e3d3b15b30b64d96e34ff0d50c23377f06601 Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Tue, 24 Aug 2021 22:04:06 +0200 Subject: [PATCH 1/3] Bypass Do Not Disturb as SettingsOption prototype --- src/Widgets/AppSettingsView.vala | 24 ++++++++++++++++++++++++ src/Widgets/MainView.vala | 20 ++++++-------------- src/Widgets/Sidebar.vala | 4 ++-- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/src/Widgets/AppSettingsView.vala b/src/Widgets/AppSettingsView.vala index afe70203..ef5e23fa 100644 --- a/src/Widgets/AppSettingsView.vala +++ b/src/Widgets/AppSettingsView.vala @@ -24,6 +24,7 @@ public class Widgets.AppSettingsView : Gtk.Grid { private SettingsOption bubbles_option; private SettingsOption sound_option; private SettingsOption remember_option; + private SettingsOption bypass_do_not_disturb_option; construct { app_image = new Gtk.Image () { @@ -64,12 +65,20 @@ public class Widgets.AppSettingsView : Gtk.Grid { new Gtk.Switch () ); + bypass_do_not_disturb_option = new SettingsOption ( + "/io/elementary/switchboard/notify-center.svg", + _("Bypass Do Not Disturb"), + _("Notify despite Do Not Disturb is enabled."), + new Gtk.Switch () + ); + margin = 12; row_spacing = 32; attach (header, 0, 0); attach (bubbles_option, 0, 1); attach (sound_option, 0, 2); attach (remember_option, 0, 3); + attach (bypass_do_not_disturb_option, 0, 4); update_selected_app (); @@ -77,12 +86,16 @@ public class Widgets.AppSettingsView : Gtk.Grid { remove_bindings (); update_selected_app (); }); + + bypass_do_not_disturb_option.widget.notify["state"].connect (update_view); + NotificationsPlug.notify_settings.changed["do-not-disturb"].connect (update_view); } private void remove_bindings () { Settings.unbind (bubbles_option.widget, "state"); Settings.unbind (sound_option.widget, "state"); Settings.unbind (remember_option.widget, "state"); + //Settings.unbind (bypass_do_not_disturb_option.widget, "state"); } private void update_selected_app () { @@ -93,8 +106,19 @@ public class Widgets.AppSettingsView : Gtk.Grid { selected_app.settings.bind ("bubbles", bubbles_option.widget, "state", GLib.SettingsBindFlags.DEFAULT); selected_app.settings.bind ("sounds", sound_option.widget, "state", GLib.SettingsBindFlags.DEFAULT); selected_app.settings.bind ("remember", remember_option.widget, "state", GLib.SettingsBindFlags.DEFAULT); + //selected_app.settings.bind ("bypass_do_not_disturb", bypass_do_not_disturb_option.widget, "state", GLib.SettingsBindFlags.DEFAULT); app_label.label = selected_app.app_info.get_display_name (); app_image.gicon = selected_app.app_info.get_icon (); + + update_view (); + } + + private void update_view () { + if (NotificationsPlug.notify_settings.get_boolean ("do-not-disturb") && !((Gtk.Switch) bypass_do_not_disturb_option.widget).state) { + bubbles_option.sensitive = sound_option.sensitive = remember_option.sensitive = false; + } else { + bubbles_option.sensitive = sound_option.sensitive = remember_option.sensitive = true; + } } } diff --git a/src/Widgets/MainView.vala b/src/Widgets/MainView.vala index eb2085f5..5807b30a 100644 --- a/src/Widgets/MainView.vala +++ b/src/Widgets/MainView.vala @@ -18,7 +18,7 @@ */ public class Widgets.MainView : Gtk.Paned { - private Gtk.Stack stack; + //private Gtk.Stack stack; construct { var sidebar = new Sidebar (); @@ -26,7 +26,7 @@ public class Widgets.MainView : Gtk.Paned { var app_settings_view = new AppSettingsView (); app_settings_view.show_all (); - var description = _("While in Do Not Disturb mode, notifications and alerts will be hidden and notification sounds will be silenced."); + /*var description = _("While in Do Not Disturb mode, notifications and alerts will be hidden and notification sounds will be silenced."); description += "\n\n"; description += _("System notifications, such as volume and display brightness, will be unaffected."); @@ -39,22 +39,14 @@ public class Widgets.MainView : Gtk.Paned { stack = new Gtk.Stack (); stack.add_named (app_settings_view, "app-settings-view"); - stack.add_named (alert_view, "alert-view"); + stack.add_named (alert_view, "alert-view");*/ pack1 (sidebar, true, false); - pack2 (stack, true, false); + pack2 (app_settings_view, true, false); set_position (240); - update_view (); + //update_view (); - NotificationsPlug.notify_settings.changed["do-not-disturb"].connect (update_view); - } - - private void update_view () { - if (NotificationsPlug.notify_settings.get_boolean ("do-not-disturb")) { - stack.visible_child_name = "alert-view"; - } else { - stack.visible_child_name = "app-settings-view"; - } + //NotificationsPlug.notify_settings.changed["do-not-disturb"].connect (update_view); } } diff --git a/src/Widgets/Sidebar.vala b/src/Widgets/Sidebar.vala index 6c67daa3..15468507 100644 --- a/src/Widgets/Sidebar.vala +++ b/src/Widgets/Sidebar.vala @@ -50,12 +50,12 @@ public class Widgets.Sidebar : Gtk.Grid { app_list.row_selected.connect (show_row); - NotificationsPlug.notify_settings.bind ( + /*NotificationsPlug.notify_settings.bind ( "do-not-disturb", app_list, "sensitive", SettingsBindFlags.INVERT_BOOLEAN - ); + );*/ NotificationsPlug.notify_settings.bind ( "do-not-disturb", From 6db539bd33e3864ec07c6de3037b04f5e0b260d8 Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Wed, 25 Aug 2021 10:04:46 +0200 Subject: [PATCH 2/3] Placed bypass dnd switch at the top --- src/Widgets/AppSettingsView.vala | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Widgets/AppSettingsView.vala b/src/Widgets/AppSettingsView.vala index ef5e23fa..57592760 100644 --- a/src/Widgets/AppSettingsView.vala +++ b/src/Widgets/AppSettingsView.vala @@ -24,7 +24,7 @@ public class Widgets.AppSettingsView : Gtk.Grid { private SettingsOption bubbles_option; private SettingsOption sound_option; private SettingsOption remember_option; - private SettingsOption bypass_do_not_disturb_option; + private Gtk.Switch bypass_do_not_disturb_switch; construct { app_image = new Gtk.Image () { @@ -38,11 +38,27 @@ public class Widgets.AppSettingsView : Gtk.Grid { }; app_label.get_style_context ().add_class (Granite.STYLE_CLASS_H2_LABEL); + var bypass_do_not_disturb_label = new Granite.HeaderLabel (_("Bypass Do Not Disturb")) { + margin_start = 3 + }; + + bypass_do_not_disturb_switch = new Gtk.Switch () { + margin = 6, + margin_end = 3 + }; + + var bypass_do_not_disturb_grid = new Gtk.Grid () { + margin_top = 6 + }; + bypass_do_not_disturb_grid.attach (bypass_do_not_disturb_label, 0, 0); + bypass_do_not_disturb_grid.attach (bypass_do_not_disturb_switch, 1, 0); + var header = new Gtk.Grid () { column_spacing = 12 }; header.attach (app_image, 0, 0); header.attach (app_label, 1, 0); + header.attach (bypass_do_not_disturb_grid, 2, 0); bubbles_option = new SettingsOption ( "/io/elementary/switchboard/bubbles.svg", @@ -65,20 +81,12 @@ public class Widgets.AppSettingsView : Gtk.Grid { new Gtk.Switch () ); - bypass_do_not_disturb_option = new SettingsOption ( - "/io/elementary/switchboard/notify-center.svg", - _("Bypass Do Not Disturb"), - _("Notify despite Do Not Disturb is enabled."), - new Gtk.Switch () - ); - margin = 12; row_spacing = 32; attach (header, 0, 0); attach (bubbles_option, 0, 1); attach (sound_option, 0, 2); attach (remember_option, 0, 3); - attach (bypass_do_not_disturb_option, 0, 4); update_selected_app (); @@ -87,7 +95,7 @@ public class Widgets.AppSettingsView : Gtk.Grid { update_selected_app (); }); - bypass_do_not_disturb_option.widget.notify["state"].connect (update_view); + bypass_do_not_disturb_switch.notify["state"].connect (update_view); NotificationsPlug.notify_settings.changed["do-not-disturb"].connect (update_view); } @@ -115,7 +123,7 @@ public class Widgets.AppSettingsView : Gtk.Grid { } private void update_view () { - if (NotificationsPlug.notify_settings.get_boolean ("do-not-disturb") && !((Gtk.Switch) bypass_do_not_disturb_option.widget).state) { + if (NotificationsPlug.notify_settings.get_boolean ("do-not-disturb") && !bypass_do_not_disturb_switch.state) { bubbles_option.sensitive = sound_option.sensitive = remember_option.sensitive = false; } else { bubbles_option.sensitive = sound_option.sensitive = remember_option.sensitive = true; From 1603fa37a43b5e9af90b3f533ba2ff8bf9c1334b Mon Sep 17 00:00:00 2001 From: Marco Betschart Date: Wed, 25 Aug 2021 19:23:06 +0200 Subject: [PATCH 3/3] Save bypass dnd setting and code cleanup --- src/Widgets/AppSettingsView.vala | 4 ++-- src/Widgets/MainView.vala | 19 ------------------- src/Widgets/Sidebar.vala | 7 ------- 3 files changed, 2 insertions(+), 28 deletions(-) diff --git a/src/Widgets/AppSettingsView.vala b/src/Widgets/AppSettingsView.vala index 57592760..0df5e6b4 100644 --- a/src/Widgets/AppSettingsView.vala +++ b/src/Widgets/AppSettingsView.vala @@ -103,7 +103,7 @@ public class Widgets.AppSettingsView : Gtk.Grid { Settings.unbind (bubbles_option.widget, "state"); Settings.unbind (sound_option.widget, "state"); Settings.unbind (remember_option.widget, "state"); - //Settings.unbind (bypass_do_not_disturb_option.widget, "state"); + Settings.unbind (bypass_do_not_disturb_switch, "state"); } private void update_selected_app () { @@ -114,7 +114,7 @@ public class Widgets.AppSettingsView : Gtk.Grid { selected_app.settings.bind ("bubbles", bubbles_option.widget, "state", GLib.SettingsBindFlags.DEFAULT); selected_app.settings.bind ("sounds", sound_option.widget, "state", GLib.SettingsBindFlags.DEFAULT); selected_app.settings.bind ("remember", remember_option.widget, "state", GLib.SettingsBindFlags.DEFAULT); - //selected_app.settings.bind ("bypass_do_not_disturb", bypass_do_not_disturb_option.widget, "state", GLib.SettingsBindFlags.DEFAULT); + selected_app.settings.bind ("bypass-do-not-disturb", bypass_do_not_disturb_switch, "state", GLib.SettingsBindFlags.DEFAULT); app_label.label = selected_app.app_info.get_display_name (); app_image.gicon = selected_app.app_info.get_icon (); diff --git a/src/Widgets/MainView.vala b/src/Widgets/MainView.vala index 5807b30a..ef77a437 100644 --- a/src/Widgets/MainView.vala +++ b/src/Widgets/MainView.vala @@ -26,27 +26,8 @@ public class Widgets.MainView : Gtk.Paned { var app_settings_view = new AppSettingsView (); app_settings_view.show_all (); - /*var description = _("While in Do Not Disturb mode, notifications and alerts will be hidden and notification sounds will be silenced."); - description += "\n\n"; - description += _("System notifications, such as volume and display brightness, will be unaffected."); - - var alert_view = new Granite.Widgets.AlertView ( - _("elementary OS is in Do Not Disturb mode"), - description, - "notification-disabled" - ); - alert_view.show_all (); - - stack = new Gtk.Stack (); - stack.add_named (app_settings_view, "app-settings-view"); - stack.add_named (alert_view, "alert-view");*/ - pack1 (sidebar, true, false); pack2 (app_settings_view, true, false); set_position (240); - - //update_view (); - - //NotificationsPlug.notify_settings.changed["do-not-disturb"].connect (update_view); } } diff --git a/src/Widgets/Sidebar.vala b/src/Widgets/Sidebar.vala index 15468507..f7b6979b 100644 --- a/src/Widgets/Sidebar.vala +++ b/src/Widgets/Sidebar.vala @@ -50,13 +50,6 @@ public class Widgets.Sidebar : Gtk.Grid { app_list.row_selected.connect (show_row); - /*NotificationsPlug.notify_settings.bind ( - "do-not-disturb", - app_list, - "sensitive", - SettingsBindFlags.INVERT_BOOLEAN - );*/ - NotificationsPlug.notify_settings.bind ( "do-not-disturb", do_not_disturb_switch,