[gnome-shell/wip/fmuellner/dont-disturb: 417/417] calendar: Add "Do Not Disturb" switch



commit 0a73a101897337342ecf4364bdaf44ffc8a8659c
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri May 4 17:55:29 2018 +0200

    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

 data/theme/gnome-shell-sass/_common.scss |  6 ++++-
 js/ui/calendar.js                        | 44 +++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 2 deletions(-)
---
diff --git a/data/theme/gnome-shell-sass/_common.scss b/data/theme/gnome-shell-sass/_common.scss
index 7e0e9a634..f01e58475 100644
--- a/data/theme/gnome-shell-sass/_common.scss
+++ b/data/theme/gnome-shell-sass/_common.scss
@@ -1000,10 +1000,14 @@ StScrollBar {
         width: 31.5em;
       }
 
+        .message-list-controls {
+          margin: 1.5em 1.5em 0;
+          spacing: 0.8em;
+        }
+
         .message-list-clear-button.button {
           background-color: transparent;
           &:hover,&:focus { background-color: lighten($bg_color,5%); }
-          margin: 1.5em 1.5em 0;
           padding: 8px;
         }
 
diff --git a/js/ui/calendar.js b/js/ui/calendar.js
index 8dc04c8a1..fb3e532a0 100644
--- a/js/ui/calendar.js
+++ b/js/ui/calendar.js
@@ -7,10 +7,12 @@ const St = imports.gi.St;
 const Signals = imports.signals;
 const Shell = imports.gi.Shell;
 
+const GnomeSession = imports.misc.gnomeSession;
 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;
 
 var MSECS_IN_DAY = 24 * 60 * 60 * 1000;
@@ -1065,6 +1067,33 @@ var Placeholder = class Placeholder {
     }
 };
 
+var DoNotDisturbSwitch = class DoNotDisturbSwitch extends PopupMenu.Switch {
+    constructor() {
+        super(false);
+
+        this._presence = new GnomeSession.Presence((proxy, error) => {
+            this._onStatusChanged(proxy.status);
+        });
+        this._presence.connectSignal('StatusChanged', (proxy, sender, [status]) => {
+            this._onStatusChanged(status);
+        });
+    }
+
+    _onStatusChanged(status) {
+        this.setToggleState(status == GnomeSession.PresenceStatus.BUSY);
+    }
+
+    setToggleState(state) {
+        super.setToggleState(state);
+
+        if (!this._presence)
+            return;
+
+        this._presence.SetStatusRemote(state ? GnomeSession.PresenceStatus.BUSY
+                                             : GnomeSession.PresenceStatus.AVAILABLE);
+    }
+}
+
 var CalendarMessageList = class CalendarMessageList {
     constructor() {
         this.actor = new St.Widget({ style_class: 'message-list',
@@ -1085,7 +1114,20 @@ var CalendarMessageList = class CalendarMessageList {
         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_actor(hbox);
+
+        hbox.add_actor(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.actor });
+        this._dndButton.connect('clicked', () => { this._dndSwitch.toggle(); });
+        hbox.add_actor(this._dndButton);
+
         this._clearButton = new St.Button({ style_class: 'message-list-clear-button button',
+                                            x_expand: true,
                                             can_focus: true });
         this._clearButton.add_actor(new St.Icon({ icon_name: 'edit-clear-all-symbolic' }));
         this._clearButton.set_x_align(Clutter.ActorAlign.END);
@@ -1093,7 +1135,7 @@ var CalendarMessageList = class CalendarMessageList {
             let sections = [...this._sections.keys()];
             sections.forEach((s) => { s.clear(); });
         });
-        box.add_actor(this._clearButton);
+        hbox.add_actor(this._clearButton);
 
         this._sectionList = new St.BoxLayout({ style_class: 'message-list-sections',
                                                vertical: true,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]