From 02c65476eac230ea90c70caff71afa8c09970ecf Mon Sep 17 00:00:00 2001 From: Adam Dingle Date: Sun, 19 Jan 2020 15:26:21 +0100 Subject: [PATCH] Allow brief notifications This change allows certain notifications to be displayed only briefly. The new DConf key brief-notification-duration is the number of seconds for which brief notifications should be displayed. At the moment the only brief notifications are "Message sent", "Conversation archived" and "Message archived". Closes #602 --- desktop/org.gnome.Geary.gschema.xml | 7 +++++++ src/client/accounts/accounts-editor-list-pane.vala | 6 +++++- src/client/application/application-command.vala | 8 ++++++++ src/client/application/application-configuration.vala | 5 +++++ src/client/application/application-controller.vala | 5 ++++- src/client/application/application-main-window.vala | 5 ++++- src/client/components/components-in-app-notification.vala | 4 +++- 7 files changed, 36 insertions(+), 4 deletions(-) diff --git a/desktop/org.gnome.Geary.gschema.xml b/desktop/org.gnome.Geary.gschema.xml index f0068798..df7f31be 100644 --- a/desktop/org.gnome.Geary.gschema.xml +++ b/desktop/org.gnome.Geary.gschema.xml @@ -128,6 +128,13 @@ email. Set to zero or less to disable. + + 5 + Brief notification display time + The length of time in seconds for which brief notifications should + be displayed. + + false Whether we migrated the old settings diff --git a/src/client/accounts/accounts-editor-list-pane.vala b/src/client/accounts/accounts-editor-list-pane.vala index 9bb42c1a..fc16da49 100644 --- a/src/client/accounts/accounts-editor-list-pane.vala +++ b/src/client/accounts/accounts-editor-list-pane.vala @@ -243,8 +243,12 @@ internal class Accounts.EditorListPane : Gtk.Grid, EditorPane, CommandPane { private void on_execute(Application.Command command) { if (command.executed_label != null) { + int notification_time = + command.executed_notification_brief ? + editor.application.config.brief_notification_duration : 0; Components.InAppNotification ian = - new Components.InAppNotification(command.executed_label); + new Components.InAppNotification( + command.executed_label, notification_time); ian.set_button(_("Undo"), Action.Edit.prefix(Action.Edit.UNDO)); this.editor.add_notification(ian); } diff --git a/src/client/application/application-command.vala b/src/client/application/application-command.vala index 24ee9f3b..446d6741 100644 --- a/src/client/application/application-command.vala +++ b/src/client/application/application-command.vala @@ -71,6 +71,14 @@ public abstract class Application.Command : GLib.Object { */ public string? executed_label { get; protected set; default = null; } + /** + * True if executed_label should be displayed only briefly to the user. + * Set this to true for very frequent notifications. + */ + public bool executed_notification_brief { + get; protected set; default = false; + } + /** * A human-readable label describing the result of calling {@link undo}. * diff --git a/src/client/application/application-configuration.vala b/src/client/application/application-configuration.vala index e2cc8f7b..c00bb564 100644 --- a/src/client/application/application-configuration.vala +++ b/src/client/application/application-configuration.vala @@ -14,6 +14,7 @@ public class Application.Configuration : Geary.BaseObject { public const string ASK_OPEN_ATTACHMENT_KEY = "ask-open-attachment"; public const string AUTOSELECT_KEY = "autoselect"; + public const string BRIEF_NOTIFICATION_DURATION = "brief-notification-duration"; public const string COMPOSER_WINDOW_SIZE_KEY = "composer-window-size"; public const string COMPOSE_AS_HTML_KEY = "compose-as-html"; public const string CONVERSATION_VIEWER_ZOOM_KEY = "conversation-viewer-zoom"; @@ -154,6 +155,10 @@ public class Application.Configuration : Geary.BaseObject { get { return settings.get_int(UNDO_SEND_DELAY); } } + /** The number of seconds for which brief notifications should be displayed. */ + public int brief_notification_duration { + get { return settings.get_int(BRIEF_NOTIFICATION_DURATION); } + } // Creates a configuration object. public Configuration(string schema_id) { diff --git a/src/client/application/application-controller.vala b/src/client/application/application-controller.vala index 87f70a44..48e902ee 100644 --- a/src/client/application/application-controller.vala +++ b/src/client/application/application-controller.vala @@ -1558,7 +1558,9 @@ internal class Application.Controller : Geary.BaseObject { "Email sent to %s" ).printf(Util.Email.to_short_recipient_display(sent)); Components.InAppNotification notification = - new Components.InAppNotification(message); + new Components.InAppNotification( + message, application.config.brief_notification_duration + ); foreach (MainWindow window in this.application.get_main_windows()) { window.add_notification(notification); } @@ -2324,6 +2326,7 @@ private class Application.ArchiveEmailCommand : RevokableCommand { base(source, conversations, messages); this.source = source; this.executed_label = executed_label; + this.executed_notification_brief = true; this.undone_label = undone_label; } diff --git a/src/client/application/application-main-window.vala b/src/client/application/application-main-window.vala index d605e027..6f337a10 100644 --- a/src/client/application/application-main-window.vala +++ b/src/client/application/application-main-window.vala @@ -2032,8 +2032,11 @@ public class Application.MainWindow : private void on_command_redo(Command command) { update_command_actions(); if (command.executed_label != null) { + int notification_time = + command.executed_notification_brief ? + application.config.brief_notification_duration : 0; Components.InAppNotification ian = - new Components.InAppNotification(command.executed_label); + new Components.InAppNotification(command.executed_label, notification_time); ian.set_button(_("Undo"), Action.Edit.prefix(Action.Edit.UNDO)); add_notification(ian); } diff --git a/src/client/components/components-in-app-notification.vala b/src/client/components/components-in-app-notification.vala index 79ec67c7..565e3974 100644 --- a/src/client/components/components-in-app-notification.vala +++ b/src/client/components/components-in-app-notification.vala @@ -26,7 +26,9 @@ public class Components.InAppNotification : Gtk.Revealer { * @param message The message that should be displayed. * @param keepalive The amount of seconds that the notification should stay visible. */ - public InAppNotification(string message, uint keepalive = DEFAULT_KEEPALIVE) { + public InAppNotification(string message, uint keepalive = 0) { + if (keepalive == 0) + keepalive = DEFAULT_KEEPALIVE; this.transition_type = Gtk.RevealerTransitionType.SLIDE_DOWN; this.message_label.label = message;