diff options
author | fiaxh <git@mx.ax.lt> | 2018-03-02 13:13:15 +0100 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2018-03-05 15:43:02 +0100 |
commit | a8ee61b34c4c6c73cda94ac5f60529e892b3666b (patch) | |
tree | 5f23d21dde98505eeca74490d3364be9d612e35a /main/src/ui | |
parent | 08c8b9c6d63784f3db1fa3423e629db3ca461b94 (diff) | |
download | dino-a8ee61b34c4c6c73cda94ac5f60529e892b3666b.tar.gz dino-a8ee61b34c4c6c73cda94ac5f60529e892b3666b.zip |
Move notification sounds (canberra dependency) into plugin, introduce libdino/NotificationEvents
Diffstat (limited to 'main/src/ui')
-rw-r--r-- | main/src/ui/notifications.vala | 63 | ||||
-rw-r--r-- | main/src/ui/settings_dialog.vala | 3 |
2 files changed, 19 insertions, 47 deletions
diff --git a/main/src/ui/notifications.vala b/main/src/ui/notifications.vala index 2eb144e4..f7540a4d 100644 --- a/main/src/ui/notifications.vala +++ b/main/src/ui/notifications.vala @@ -14,14 +14,11 @@ public class Notifications : Object { private HashMap<Conversation, Notification> notifications = new HashMap<Conversation, Notification>(Conversation.hash_func, Conversation.equals_func); private Set<string>? active_conversation_ids = null; private Set<string>? active_ids = new HashSet<string>(); - private Canberra.Context sound_context; public Notifications(StreamInteractor stream_interactor, Gtk.Window window) { this.stream_interactor = stream_interactor; this.window = window; - Canberra.Context.create(out sound_context); - stream_interactor.get_module(ChatInteraction.IDENTITY).focused_in.connect((focused_conversation) => { if (active_conversation_ids == null) { Gee.List<Conversation> conversations = stream_interactor.get_module(ConversationManager.IDENTITY).get_active_conversations(); @@ -44,48 +41,36 @@ public class Notifications : Object { } public void start() { - stream_interactor.get_module(MessageProcessor.IDENTITY).message_received.connect(on_message_received); - stream_interactor.get_module(PresenceManager.IDENTITY).received_subscription_request.connect(on_received_subscription_request); + stream_interactor.get_module(NotificationEvents.IDENTITY).notify_message.connect(notify_message); + stream_interactor.get_module(NotificationEvents.IDENTITY).notify_subscription_request.connect(notify_subscription_request); } - private void on_message_received(Entities.Message message, Conversation conversation) { - if (!should_notify_message(message, conversation)) return; - + private void notify_message(Entities.Message message, Conversation conversation) { if (!notifications.has_key(conversation)) { notifications[conversation] = new Notification(""); notifications[conversation].set_default_action_and_target_value("app.open-conversation", new Variant.int32(conversation.id)); } - if (!stream_interactor.get_module(ChatInteraction.IDENTITY).is_active_focus()) { - string display_name = Util.get_conversation_display_name(stream_interactor, conversation); - string text = message.body; - if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat(conversation.counterpart, conversation.account)) { - string muc_occupant = Util.get_display_name(stream_interactor, message.from, conversation.account); - text = @"$muc_occupant: $text"; - } - notifications[conversation].set_title(display_name); - notifications[conversation].set_body(text); - try { - notifications[conversation].set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_conversation(stream_interactor, conversation))); - } catch (Error e) { } - window.get_application().send_notification(conversation.id.to_string(), notifications[conversation]); - active_conversation_ids.add(conversation.id.to_string()); - window.urgency_hint = true; - } - if (conversation.get_sound_setting(stream_interactor)) { - sound_context.play (0, - Canberra.PROP_EVENT_ID, "message-new-instant", - Canberra.PROP_EVENT_DESCRIPTION, "New Dino message"); + string display_name = Util.get_conversation_display_name(stream_interactor, conversation); + string text = message.body; + if (stream_interactor.get_module(MucManager.IDENTITY).is_groupchat(conversation.counterpart, conversation.account)) { + string muc_occupant = Util.get_display_name(stream_interactor, message.from, conversation.account); + text = @"$muc_occupant: $text"; } + notifications[conversation].set_title(display_name); + notifications[conversation].set_body(text); + try { + notifications[conversation].set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_conversation(stream_interactor, conversation))); + } catch (Error e) { } + window.get_application().send_notification(conversation.id.to_string(), notifications[conversation]); + active_conversation_ids.add(conversation.id.to_string()); + window.urgency_hint = true; } - private void on_received_subscription_request(Jid jid, Account account) { - Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.CHAT); - if (stream_interactor.get_module(ChatInteraction.IDENTITY).is_active_focus(conversation)) return; - + private void notify_subscription_request(Conversation conversation) { Notification notification = new Notification(_("Subscription request")); - notification.set_body(jid.bare_jid.to_string()); + notification.set_body(conversation.counterpart.to_string()); try { - notification.set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_jid(stream_interactor, jid, account))); + notification.set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_jid(stream_interactor, conversation.counterpart, conversation.account))); } catch (Error e) { } notification.set_default_action_and_target_value("app.open-conversation", new Variant.int32(conversation.id)); notification.add_button_with_target_value(_("Accept"), "app.accept-subscription", conversation.id); @@ -94,16 +79,6 @@ public class Notifications : Object { active_ids.add(conversation.id.to_string() + "-subscription"); } - private bool should_notify_message(Entities.Message message, Conversation conversation) { - Conversation.NotifySetting notify = conversation.get_notification_setting(stream_interactor); - if (notify == Conversation.NotifySetting.OFF) return false; - Jid? nick = stream_interactor.get_module(MucManager.IDENTITY).get_own_jid(conversation.counterpart, conversation.account); - if (notify == Conversation.NotifySetting.HIGHLIGHT && nick != null) { - return Regex.match_simple("""\b""" + Regex.escape_string(nick.resourcepart) + """\b""", message.body, RegexCompileFlags.CASELESS); - } - return true; - } - private Icon get_pixbuf_icon(Cairo.ImageSurface surface) throws Error { Gdk.Pixbuf avatar = Gdk.pixbuf_get_from_surface(surface, 0, 0, surface.get_width(), surface.get_height()); uint8[] buffer; diff --git a/main/src/ui/settings_dialog.vala b/main/src/ui/settings_dialog.vala index 58c86bde..e40b2993 100644 --- a/main/src/ui/settings_dialog.vala +++ b/main/src/ui/settings_dialog.vala @@ -8,7 +8,6 @@ class SettingsDialog : Dialog { [GtkChild] private CheckButton typing_checkbutton; [GtkChild] private CheckButton marker_checkbutton; [GtkChild] private CheckButton notification_checkbutton; - [GtkChild] private CheckButton sound_checkbutton; [GtkChild] private CheckButton emoji_checkbutton; Dino.Entities.Settings settings = Dino.Application.get_default().settings; @@ -19,13 +18,11 @@ class SettingsDialog : Dialog { typing_checkbutton.active = settings.send_typing; marker_checkbutton.active = settings.send_marker; notification_checkbutton.active = settings.notifications; - sound_checkbutton.active = settings.sound; emoji_checkbutton.active = settings.convert_utf8_smileys; typing_checkbutton.toggled.connect(() => { settings.send_typing = typing_checkbutton.active; } ); marker_checkbutton.toggled.connect(() => { settings.send_marker = marker_checkbutton.active; } ); notification_checkbutton.toggled.connect(() => { settings.notifications = notification_checkbutton.active; } ); - sound_checkbutton.toggled.connect(() => { settings.sound = sound_checkbutton.active; } ); emoji_checkbutton.toggled.connect(() => { settings.convert_utf8_smileys = emoji_checkbutton.active; }); } } |