diff options
author | fiaxh <git@mx.ax.lt> | 2017-12-14 02:01:55 +0100 |
---|---|---|
committer | fiaxh <git@mx.ax.lt> | 2017-12-30 13:10:06 +0100 |
commit | b4bb0912fc328bc44b13e190f59b347eb5d4310a (patch) | |
tree | a18f680f8349eb758dd54fd44321837bcd228545 /main | |
parent | f25fadde2d6c9492b9cafe2cddbcc7b966942e47 (diff) | |
download | dino-b4bb0912fc328bc44b13e190f59b347eb5d4310a.tar.gz dino-b4bb0912fc328bc44b13e190f59b347eb5d4310a.zip |
Show subscription request in conversation summary
Diffstat (limited to 'main')
-rw-r--r-- | main/CMakeLists.txt | 1 | ||||
-rw-r--r-- | main/data/add_conversation/add_contact_dialog.ui | 15 | ||||
-rw-r--r-- | main/data/contact_details_dialog.ui | 2 | ||||
-rw-r--r-- | main/data/conversation_summary/view.ui | 57 | ||||
-rw-r--r-- | main/src/ui/add_conversation/add_contact_dialog.vala | 5 | ||||
-rw-r--r-- | main/src/ui/application.vala | 24 | ||||
-rw-r--r-- | main/src/ui/conversation_summary/conversation_view.vala | 23 | ||||
-rw-r--r-- | main/src/ui/conversation_summary/subscription_notification.vala | 55 | ||||
-rw-r--r-- | main/src/ui/notifications.vala | 61 |
9 files changed, 168 insertions, 75 deletions
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 4a799758..b9b6fa29 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -109,6 +109,7 @@ SOURCES src/ui/conversation_summary/message_populator.vala src/ui/conversation_summary/message_textview.vala src/ui/conversation_summary/slashme_message_display.vala + src/ui/conversation_summary/subscription_notification.vala src/ui/conversation_titlebar/file_entry.vala src/ui/conversation_titlebar/menu_entry.vala src/ui/conversation_titlebar/occupants_entry.vala diff --git a/main/data/add_conversation/add_contact_dialog.ui b/main/data/add_conversation/add_contact_dialog.ui index abf9d892..6185c5ba 100644 --- a/main/data/add_conversation/add_contact_dialog.ui +++ b/main/data/add_conversation/add_contact_dialog.ui @@ -5,6 +5,7 @@ <property name="modal">True</property> <child type="titlebar"> <object class="GtkHeaderBar"> + <property name="title" translatable="yes">Add Contact</property> <property name="visible">True</property> <child> <object class="GtkButton" id="cancel_button"> @@ -123,20 +124,6 @@ <property name="height">1</property> </packing> </child> - <child> - <object class="GtkCheckButton" id="subscribe_checkbutton"> - <property name="active">True</property> - <property name="label" translatable="yes">Request presence updates</property> - <property name="xalign">0</property> - <property name="visible">True</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="top_attach">3</property> - <property name="width">1</property> - <property name="height">1</property> - </packing> - </child> </object> </child> </object> diff --git a/main/data/contact_details_dialog.ui b/main/data/contact_details_dialog.ui index 8fa62398..0903b260 100644 --- a/main/data/contact_details_dialog.ui +++ b/main/data/contact_details_dialog.ui @@ -4,7 +4,7 @@ <property name="modal">True</property> <child type="titlebar"> <object class="GtkHeaderBar"> - <property name="title">Conversation Details</property> + <property name="title" translatable="yes">Conversation Details</property> <property name="show_close_button">True</property> <property name="visible">True</property> </object> diff --git a/main/data/conversation_summary/view.ui b/main/data/conversation_summary/view.ui index 9139da56..2bc13752 100644 --- a/main/data/conversation_summary/view.ui +++ b/main/data/conversation_summary/view.ui @@ -10,26 +10,63 @@ <property name="transition_type">crossfade</property> <property name="visible">True</property> <child> - <object class="GtkScrolledWindow" id="scrolled"> - <property name="hscrollbar_policy">never</property> + <object class="GtkOverlay"> <property name="visible">True</property> <child> - <object class="GtkBox"> - <property name="margin">15</property> - <property name="orientation">vertical</property> + <object class="GtkScrolledWindow" id="scrolled"> + <property name="hscrollbar_policy">never</property> <property name="visible">True</property> <child> - <object class="GtkBox" id="main"> - <property name="expand">False</property> + <object class="GtkBox"> + <property name="margin">15</property> <property name="orientation">vertical</property> - <property name="spacing">15</property> <property name="visible">True</property> + <child> + <object class="GtkBox" id="main"> + <property name="expand">False</property> + <property name="orientation">vertical</property> + <property name="spacing">15</property> + <property name="visible">True</property> + </object> + </child> + <child> + <object class="GtkBox" id="filler"> + <property name="expand">True</property> + <property name="visible">True</property> + </object> + </child> </object> </child> + </object> + <packing> + <property name="index">-1</property> + </packing> + </child> + <child type="overlay"> + <object class="GtkRevealer" id="notification_revealer"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">center</property> + <property name="valign">start</property> <child> - <object class="GtkBox" id="filler"> - <property name="expand">True</property> + <object class="GtkFrame" id="frame2"> <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label_xalign">0</property> + <property name="shadow_type">none</property> + <style> + <class name="app-notification"/> + </style> + <child> + <object class="GtkBox" id="notifications"> + <property name="expand">False</property> + <property name="orientation">vertical</property> + <property name="visible">True</property> + </object> + </child> + <child type="label_item"> + <placeholder/> + </child> </object> </child> </object> diff --git a/main/src/ui/add_conversation/add_contact_dialog.vala b/main/src/ui/add_conversation/add_contact_dialog.vala index 2e7830a3..decc588d 100644 --- a/main/src/ui/add_conversation/add_contact_dialog.vala +++ b/main/src/ui/add_conversation/add_contact_dialog.vala @@ -23,7 +23,6 @@ protected class AddContactDialog : Gtk.Dialog { [GtkChild] private Button cancel_button; [GtkChild] private Entry jid_entry; [GtkChild] private Entry alias_entry; - [GtkChild] private CheckButton subscribe_checkbutton; private StreamInteractor stream_interactor; @@ -41,9 +40,7 @@ protected class AddContactDialog : Gtk.Dialog { string? alias = alias_entry.text == "" ? null : alias_entry.text; Jid jid = new Jid(jid_entry.text); stream_interactor.get_module(RosterManager.IDENTITY).add_jid(account, jid, alias); - if (subscribe_checkbutton.active) { - stream_interactor.get_module(PresenceManager.IDENTITY).request_subscription(account, jid); - } + stream_interactor.get_module(PresenceManager.IDENTITY).request_subscription(account, jid); close(); } diff --git a/main/src/ui/application.vala b/main/src/ui/application.vala index a506f511..3ebe3cff 100644 --- a/main/src/ui/application.vala +++ b/main/src/ui/application.vala @@ -23,6 +23,8 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application { provider.load_from_resource("/im/dino/Dino/theme.css"); StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), provider, STYLE_PROVIDER_PRIORITY_APPLICATION); + create_actions(); + activate.connect(() => { if (window == null) { create_set_app_menu(); @@ -76,9 +78,27 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application { } } + private void create_actions() { + SimpleAction open_conversation_action = new SimpleAction("open-conversation", VariantType.INT32); + open_conversation_action.activate.connect((variant) => { + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32()); + if (conversation != null) window.on_conversation_selected(conversation); + window.present(); + }); + add_action(open_conversation_action); + + SimpleAction deny_subscription_action = new SimpleAction("deny-subscription", VariantType.INT32); + deny_subscription_action.activate.connect((variant) => { + Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32()); + if (conversation == null) return; + stream_interactor.get_module(PresenceManager.IDENTITY).deny_subscription(conversation.account, conversation.counterpart); + }); + add_action(deny_subscription_action); + } + private void show_accounts_window() { ManageAccounts.Dialog dialog = new ManageAccounts.Dialog(stream_interactor, db); - dialog.set_transient_for(window); + dialog.set_transient_for(get_active_window()); dialog.account_enabled.connect(add_connection); dialog.account_disabled.connect(remove_connection); dialog.present(); @@ -86,7 +106,7 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application { private void show_settings_window() { SettingsDialog dialog = new SettingsDialog(); - dialog.set_transient_for(window); + dialog.set_transient_for(get_active_window()); dialog.present(); } diff --git a/main/src/ui/conversation_summary/conversation_view.vala b/main/src/ui/conversation_summary/conversation_view.vala index 7924da57..874605c8 100644 --- a/main/src/ui/conversation_summary/conversation_view.vala +++ b/main/src/ui/conversation_summary/conversation_view.vala @@ -12,6 +12,8 @@ public class ConversationView : Box, Plugins.ConversationItemCollection { public Conversation? conversation { get; private set; } [GtkChild] private ScrolledWindow scrolled; + [GtkChild] private Revealer notification_revealer; + [GtkChild] private Box notifications; [GtkChild] private Box main; [GtkChild] private Stack stack; @@ -22,6 +24,7 @@ public class ConversationView : Box, Plugins.ConversationItemCollection { private Gee.HashMap<Plugins.MetaConversationItem, Widget> widgets = new Gee.HashMap<Plugins.MetaConversationItem, Widget>(); private Gee.List<ConversationItemSkeleton> item_skeletons = new Gee.ArrayList<ConversationItemSkeleton>(); private MessagePopulator message_item_populator; + private SubscriptionNotitication subscription_notification; private double? was_value; private double? was_upper; @@ -36,6 +39,7 @@ public class ConversationView : Box, Plugins.ConversationItemCollection { scrolled.vadjustment.notify["value"].connect(on_value_notify); message_item_populator = new MessagePopulator(stream_interactor); + subscription_notification = new SubscriptionNotitication(stream_interactor); insert_item.connect(on_insert_item); remove_item.connect(on_remove_item); @@ -77,6 +81,8 @@ public class ConversationView : Box, Plugins.ConversationItemCollection { message_item_populator.populate_latest(conversation, 40); Idle.add(() => { on_value_notify(); return false; }); + subscription_notification.init(conversation, this); + stack.set_visible_child_name("main"); } @@ -104,6 +110,20 @@ public class ConversationView : Box, Plugins.ConversationItemCollection { } } + public void add_notification(Widget widget) { + notifications.add(widget); + Timeout.add(20, () => { + notification_revealer.transition_duration = 200; + notification_revealer.reveal_child = true; + return false; + }); + } + + public void remove_notification(Widget widget) { + notification_revealer.reveal_child = false; + widget.destroy(); + } + private bool merge_back(Plugins.MetaConversationItem item) { Plugins.MetaConversationItem? lower_item = meta_items.lower(item); if (lower_item != null) { @@ -246,6 +266,9 @@ public class ConversationView : Box, Plugins.ConversationItemCollection { item_item_skeletons.clear(); widgets.clear(); main.@foreach((widget) => { widget.destroy(); }); + notifications.@foreach((widget) => { widget.destroy(); }); + notification_revealer.transition_duration = 0; + notification_revealer.set_reveal_child(false); } } diff --git a/main/src/ui/conversation_summary/subscription_notification.vala b/main/src/ui/conversation_summary/subscription_notification.vala new file mode 100644 index 00000000..225e4b00 --- /dev/null +++ b/main/src/ui/conversation_summary/subscription_notification.vala @@ -0,0 +1,55 @@ +using Gee; +using Gtk; + +using Dino.Entities; + +namespace Dino.Ui.ConversationSummary { + +public class SubscriptionNotitication : Object { + + private StreamInteractor stream_interactor; + private Conversation conversation; + private ConversationView conversation_view; + + public SubscriptionNotitication(StreamInteractor stream_interactor) { + this.stream_interactor = stream_interactor; + + stream_interactor.get_module(PresenceManager.IDENTITY).received_subscription_request.connect((jid, account) => { + Conversation relevant_conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.CHAT); + stream_interactor.get_module(ConversationManager.IDENTITY).start_conversation(relevant_conversation, true); + if (conversation != null && account.equals(conversation.account) && jid.equals(conversation.counterpart)) { + show_notification(); + } + }); + } + + public void init(Conversation conversation, ConversationView conversation_view) { + this.conversation = conversation; + this.conversation_view = conversation_view; + + if (stream_interactor.get_module(PresenceManager.IDENTITY).exists_subscription_request(conversation.account, conversation.counterpart)) { + show_notification(); + } + } + + private void show_notification() { + Box box = new Box(Orientation.HORIZONTAL, 5) { visible=true }; + Button accept_button = new Button() { label=_("Accept"), visible=true }; + Button deny_button = new Button() { label=_("Deny"), visible=true }; + GLib.Application app = GLib.Application.get_default(); + accept_button.clicked.connect(() => { + app.activate_action("accept-subscription", conversation.id); + conversation_view.remove_notification(box); + }); + deny_button.clicked.connect(() => { + app.activate_action("deny-subscription", conversation.id); + conversation_view.remove_notification(box); + }); + box.add(new Label(_("This contact would like to add you to their contact list")) { margin_end=10, visible=true }); + box.add(accept_button); + box.add(deny_button); + conversation_view.add_notification(box); + } +} + +} diff --git a/main/src/ui/notifications.vala b/main/src/ui/notifications.vala index 464f5b0d..d9f70668 100644 --- a/main/src/ui/notifications.vala +++ b/main/src/ui/notifications.vala @@ -12,63 +12,32 @@ public class Notifications : Object { private StreamInteractor stream_interactor; private Gtk.Window window; private HashMap<Conversation, Notification> notifications = new HashMap<Conversation, Notification>(Conversation.hash_func, Conversation.equals_func); - private Set<string>? active_notification_ids = null; - - private enum ClosedReason { // org.freedesktop.Notifications.NotificationClosed - EXPIRED = 1, - USER_DISMISSED = 2, - CLOSE_NOTIFICATION = 3, - UNDEFINED = 4 - } + private Set<string>? active_conversation_ids = null; + private Set<string>? active_ids = new HashSet<string>(); public Notifications(StreamInteractor stream_interactor, Gtk.Window window) { this.stream_interactor = stream_interactor; this.window = window; - stream_interactor.get_module(ChatInteraction.IDENTITY).focused_in.connect(() => { - if (active_notification_ids == null) { + 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(); foreach (Conversation conversation in conversations) { GLib.Application.get_default().withdraw_notification(conversation.id.to_string()); } - active_notification_ids = new HashSet<string>(); + active_conversation_ids = new HashSet<string>(); } else { - foreach (string id in active_notification_ids) { + foreach (string id in active_conversation_ids) { GLib.Application.get_default().withdraw_notification(id); } - active_notification_ids.clear(); + active_conversation_ids.clear(); } - }); - SimpleAction open_conversation_action = new SimpleAction("open-conversation", VariantType.INT32); - open_conversation_action.activate.connect((variant) => { - Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32()); - if (conversation != null) conversation_selected(conversation); - window.present(); - }); - GLib.Application.get_default().add_action(open_conversation_action); - - SimpleAction accept_subscription_action = new SimpleAction("accept-subscription", VariantType.INT32); - accept_subscription_action.activate.connect((variant) => { - Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32()); - if (conversation == null) return; - stream_interactor.get_module(PresenceManager.IDENTITY).approve_subscription(conversation.account, conversation.counterpart); - if (stream_interactor.get_module(RosterManager.IDENTITY).get_roster_item(conversation.account, conversation.counterpart) == null) { - AddContactDialog dialog = new AddContactDialog(stream_interactor); - dialog.jid = conversation.counterpart.bare_jid.to_string(); - dialog.account = conversation.account; - dialog.present(); + string subscription_id = focused_conversation.id.to_string() + "-subscription"; + if (active_ids.contains(subscription_id)) { + GLib.Application.get_default().withdraw_notification(subscription_id); } }); - GLib.Application.get_default().add_action(accept_subscription_action); - - SimpleAction deny_subscription_action = new SimpleAction("deny-subscription", VariantType.INT32); - deny_subscription_action.activate.connect((variant) => { - Conversation? conversation = stream_interactor.get_module(ConversationManager.IDENTITY).get_conversation_by_id(variant.get_int32()); - if (conversation == null) return; - stream_interactor.get_module(PresenceManager.IDENTITY).deny_subscription(conversation.account, conversation.counterpart); - }); - GLib.Application.get_default().add_action(deny_subscription_action); } public void start() { @@ -96,21 +65,25 @@ public class Notifications : Object { 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_notification_ids.add(conversation.id.to_string()); + 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; + Notification notification = new Notification(_("Subscription request")); notification.set_body(jid.bare_jid.to_string()); try { notification.set_icon(get_pixbuf_icon((new AvatarGenerator(40, 40)).draw_jid(stream_interactor, jid, account))); } catch (Error e) { } - Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.CHAT); + 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); notification.add_button_with_target_value(_("Deny"), "app.deny-subscription", conversation.id); - window.get_application().send_notification(null, notification); + window.get_application().send_notification(conversation.id.to_string() + "-subscription", notification); + active_ids.add(conversation.id.to_string() + "-subscription"); } private bool should_notify_message(Entities.Message message, Conversation conversation) { |