From 2cabef97b6bc55ca2ced8700d55e23a2fad78f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Fri, 4 May 2018 17:55:29 +0200 Subject: [PATCH] calendar: Add "Do Not Disturb" switch We've had the ability to temporarily disable notification banners all the way back to 3.0, but we stopped exposing it in the UI with the 3.16 notification redesign. With the message list being more concise nowadays and the "Clear" button reduced to a single icon, we now have space for a "Do Not Disturb" switch again. https://gitlab.gnome.org/GNOME/gnome-shell/issues/239 --- .../widgets/_message-list.scss | 7 ++-- js/ui/calendar.js | 40 ++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/data/theme/gnome-shell-sass/widgets/_message-list.scss b/data/theme/gnome-shell-sass/widgets/_message-list.scss index 1b570c8ca..bc80c3f2e 100644 --- a/data/theme/gnome-shell-sass/widgets/_message-list.scss +++ b/data/theme/gnome-shell-sass/widgets/_message-list.scss @@ -24,9 +24,10 @@ &:rtl {padding:0;} } -// clear button -.message-list-clear-button.button { - margin:$base_margin $base_margin*2; +// do-not-disturb + clear button +.message-list-controls { + margin: $base_margin $base_margin*2; + spacing: $base_spacing; } // message bubbles diff --git a/js/ui/calendar.js b/js/ui/calendar.js index d0866ddf8..a5a763d59 100644 --- a/js/ui/calendar.js +++ b/js/ui/calendar.js @@ -7,6 +7,7 @@ const Main = imports.ui.main; const MessageList = imports.ui.messageList; const MessageTray = imports.ui.messageTray; const Mpris = imports.ui.mpris; +const PopupMenu = imports.ui.popupMenu; const Util = imports.misc.util; const { loadInterfaceXML } = imports.misc.fileUtils; @@ -1100,6 +1101,26 @@ class Placeholder extends St.BoxLayout { } }); +const DoNotDisturbSwitch = GObject.registerClass( +class DoNotDisturbSwitch extends PopupMenu.Switch { + _init() { + this._settings = new Gio.Settings({ + schema_id: 'org.gnome.desktop.notifications', + }); + + super._init(this._settings.get_boolean('show-banners')); + + this._settings.bind('show-banners', + this, 'state', + Gio.SettingsBindFlags.INVERT_BOOLEAN); + + this.connect('destroy', () => { + this._settings.run_dispose(); + this._settings = null; + }); + } +}); + var CalendarMessageList = GObject.registerClass( class CalendarMessageList extends St.Widget { _init() { @@ -1125,16 +1146,33 @@ class CalendarMessageList extends St.Widget { this._scrollView.set_policy(St.PolicyType.NEVER, St.PolicyType.AUTOMATIC); box.add_actor(this._scrollView); + let hbox = new St.BoxLayout({ style_class: 'message-list-controls' }); + box.add_child(hbox); + + hbox.add_child(new St.Label({ + text: _('Do Not Disturb'), + y_align: Clutter.ActorAlign.CENTER, + })); + + this._dndSwitch = new DoNotDisturbSwitch(); + this._dndButton = new St.Button({ + can_focus: true, + child: this._dndSwitch, + }); + this._dndButton.connect('clicked', () => this._dndSwitch.toggle()); + hbox.add_child(this._dndButton); + this._clearButton = new St.Button({ style_class: 'message-list-clear-button button', label: _('Clear'), can_focus: true, + x_expand: true, x_align: Clutter.ActorAlign.END, }); this._clearButton.connect('clicked', () => { this._sectionList.get_children().forEach(s => s.clear()); }); - box.add_actor(this._clearButton); + hbox.add_actor(this._clearButton); this._placeholder.bind_property('visible', this._clearButton, 'visible',