diff options
Diffstat (limited to 'main/src/ui')
-rw-r--r-- | main/src/ui/conversation_list_titlebar.vala | 35 | ||||
-rw-r--r-- | main/src/ui/conversation_list_titlebar_csd.vala | 35 | ||||
-rw-r--r-- | main/src/ui/conversation_summary/conversation_view.vala | 8 | ||||
-rw-r--r-- | main/src/ui/conversation_titlebar/conversation_titlebar.vala | 2 | ||||
-rw-r--r-- | main/src/ui/conversation_view_controller.vala | 109 | ||||
-rw-r--r-- | main/src/ui/unified_window.vala | 7 | ||||
-rw-r--r-- | main/src/ui/unified_window_controller.vala | 66 |
7 files changed, 119 insertions, 143 deletions
diff --git a/main/src/ui/conversation_list_titlebar.vala b/main/src/ui/conversation_list_titlebar.vala index ee9ff6bf..901902db 100644 --- a/main/src/ui/conversation_list_titlebar.vala +++ b/main/src/ui/conversation_list_titlebar.vala @@ -10,22 +10,33 @@ public class ConversationListTitlebar : Gtk.Box { [GtkChild] private MenuButton add_button; [GtkChild] private MenuButton menu_button; - private StreamInteractor stream_interactor; - - public ConversationListTitlebar(StreamInteractor stream_interactor, Window window) { - this.stream_interactor = stream_interactor; - create_add_menu(window); + public ConversationListTitlebar() { + create_add_menu(add_button, menu_button); } +} + +[GtkTemplate (ui = "/im/dino/Dino/conversation_list_titlebar_csd.ui")] +public class ConversationListTitlebarCsd : Gtk.HeaderBar { - private void create_add_menu(Window window) { - Builder add_builder = new Builder.from_resource("/im/dino/Dino/menu_add.ui"); - MenuModel add_menu_model = add_builder.get_object("menu_add") as MenuModel; - add_button.set_menu_model(add_menu_model); + [GtkChild] private MenuButton add_button; + [GtkChild] private MenuButton menu_button; - Builder menu_builder = new Builder.from_resource("/im/dino/Dino/menu_app.ui"); - MenuModel menu_menu_model = menu_builder.get_object("menu_app") as MenuModel; - menu_button.set_menu_model(menu_menu_model); + public ConversationListTitlebarCsd() { + custom_title = new Label("Dino") { visible = true, hexpand = true, xalign = 0 }; + custom_title.get_style_context().add_class("title"); + + create_add_menu(add_button, menu_button); } } +private static void create_add_menu(MenuButton add_button, MenuButton menu_button) { + Builder add_builder = new Builder.from_resource("/im/dino/Dino/menu_add.ui"); + MenuModel add_menu_model = add_builder.get_object("menu_add") as MenuModel; + add_button.set_menu_model(add_menu_model); + + Builder menu_builder = new Builder.from_resource("/im/dino/Dino/menu_app.ui"); + MenuModel menu_menu_model = menu_builder.get_object("menu_app") as MenuModel; + menu_button.set_menu_model(menu_menu_model); +} + } diff --git a/main/src/ui/conversation_list_titlebar_csd.vala b/main/src/ui/conversation_list_titlebar_csd.vala deleted file mode 100644 index 33ff6d43..00000000 --- a/main/src/ui/conversation_list_titlebar_csd.vala +++ /dev/null @@ -1,35 +0,0 @@ -using Gtk; - -using Dino.Entities; - -namespace Dino.Ui { - -[GtkTemplate (ui = "/im/dino/Dino/conversation_list_titlebar_csd.ui")] -public class ConversationListTitlebarCsd : Gtk.HeaderBar { - - [GtkChild] private MenuButton add_button; - [GtkChild] private MenuButton menu_button; - - private StreamInteractor stream_interactor; - - public ConversationListTitlebarCsd(StreamInteractor stream_interactor, Window window) { - this.stream_interactor = stream_interactor; - - custom_title = new Label("Dino") { visible = true, hexpand = true, xalign = 0 }; - custom_title.get_style_context().add_class("title"); - - create_add_menu(window); - } - - private void create_add_menu(Window window) { - Builder add_builder = new Builder.from_resource("/im/dino/Dino/menu_add.ui"); - MenuModel add_menu_model = add_builder.get_object("menu_add") as MenuModel; - add_button.set_menu_model(add_menu_model); - - Builder menu_builder = new Builder.from_resource("/im/dino/Dino/menu_app.ui"); - MenuModel menu_menu_model = menu_builder.get_object("menu_app") as MenuModel; - menu_button.set_menu_model(menu_menu_model); - } -} - -} diff --git a/main/src/ui/conversation_summary/conversation_view.vala b/main/src/ui/conversation_summary/conversation_view.vala index 92d94cd7..6b3f0f8a 100644 --- a/main/src/ui/conversation_summary/conversation_view.vala +++ b/main/src/ui/conversation_summary/conversation_view.vala @@ -57,14 +57,6 @@ public class ConversationView : Box, Plugins.ConversationItemCollection, Plugins } return true; }); - - const TargetEntry[] target_list = { - { "text/uri-list", 0, Target.URI_LIST } - }; -// drag_dest_unset(main); -// drag_dest_set(scrolled, DestDefaults.ALL, target_list, Gdk.DragAction.COPY); -// scrolled.drag_data_received.connect(() => print("a\n")); - return this; } diff --git a/main/src/ui/conversation_titlebar/conversation_titlebar.vala b/main/src/ui/conversation_titlebar/conversation_titlebar.vala index 9836f208..c3990e09 100644 --- a/main/src/ui/conversation_titlebar/conversation_titlebar.vala +++ b/main/src/ui/conversation_titlebar/conversation_titlebar.vala @@ -6,7 +6,7 @@ using Dino.Entities; namespace Dino.Ui { -public interface ConversationTitlebar: Widget { +public interface ConversationTitlebar : Widget { public abstract string? subtitle { get; set; } public abstract string? title { get; set; } } diff --git a/main/src/ui/conversation_view_controller.vala b/main/src/ui/conversation_view_controller.vala index 1a0b2b07..149a1f76 100644 --- a/main/src/ui/conversation_view_controller.vala +++ b/main/src/ui/conversation_view_controller.vala @@ -15,39 +15,74 @@ const TargetEntry[] target_list = { { "text/uri-list", 0, Target.URI_LIST } }; -public class ConversationViewController { +public class ConversationViewController : Object { - private ConversationView widget; + public new string? conversation_display_name { get; set; } + public string? conversation_topic { get; set; } + + private Application app; + private ConversationView view; + private ConversationTitlebar titlebar; + public SearchMenuEntry search_menu_entry = new SearchMenuEntry(); private ChatInputController chat_input_controller; private StreamInteractor stream_interactor; private Conversation? conversation; - public ConversationViewController(ConversationView widget, StreamInteractor stream_interactor) { - this.widget = widget; + public ConversationViewController(ConversationView view, ConversationTitlebar titlebar, StreamInteractor stream_interactor) { + this.view = view; + this.titlebar = titlebar; this.stream_interactor = stream_interactor; + this.app = GLib.Application.get_default() as Application; - this.chat_input_controller = new ChatInputController(widget.chat_input, stream_interactor); + this.chat_input_controller = new ChatInputController(view.chat_input, stream_interactor); - widget.conversation_frame.init(stream_interactor); + view.conversation_frame.init(stream_interactor); // drag 'n drop file upload - Gtk.drag_dest_unset(widget.chat_input.text_input); - Gtk.drag_dest_set(widget, DestDefaults.ALL, target_list, Gdk.DragAction.COPY); - widget.drag_data_received.connect(this.on_drag_data_received); + Gtk.drag_dest_unset(view.chat_input.text_input); + Gtk.drag_dest_set(view, DestDefaults.ALL, target_list, Gdk.DragAction.COPY); + view.drag_data_received.connect(this.on_drag_data_received); // forward key presses - widget.chat_input.key_press_event.connect(forward_key_press_to_chat_input); - widget.conversation_frame.key_press_event.connect(forward_key_press_to_chat_input); + view.chat_input.key_press_event.connect(forward_key_press_to_chat_input); + view.conversation_frame.key_press_event.connect(forward_key_press_to_chat_input); + titlebar.key_press_event.connect(forward_key_press_to_chat_input); // goto-end floating button - var vadjustment = widget.conversation_frame.scrolled.vadjustment; + var vadjustment = view.conversation_frame.scrolled.vadjustment; vadjustment.notify["value"].connect(() => { - widget.goto_end_revealer.reveal_child = vadjustment.value < vadjustment.upper - vadjustment.page_size; + view.goto_end_revealer.reveal_child = vadjustment.value < vadjustment.upper - vadjustment.page_size; + }); + view.goto_end_button.clicked.connect(() => { + view.conversation_frame.initialize_for_conversation(conversation); + }); + + // Update conversation display name & topic + this.bind_property("conversation-display-name", titlebar, "title"); + this.bind_property("conversation-topic", titlebar, "subtitle"); + stream_interactor.get_module(MucManager.IDENTITY).room_name_set.connect((account, jid, room_name) => { + if (conversation != null && conversation.counterpart.equals_bare(jid) && conversation.account.equals(account)) { + update_conversation_display_name(); + } + }); + stream_interactor.get_module(MucManager.IDENTITY).private_room_occupant_updated.connect((account, room, occupant) => { + if (conversation != null && conversation.counterpart.equals_bare(room.bare_jid) && conversation.account.equals(account)) { + update_conversation_display_name(); + } }); - widget.goto_end_button.clicked.connect(() => { - widget.conversation_frame.initialize_for_conversation(conversation); + stream_interactor.get_module(MucManager.IDENTITY).subject_set.connect((account, jid, subject) => { + if (conversation != null && conversation.counterpart.equals_bare(jid) && conversation.account.equals(account)) { + update_conversation_topic(subject); + } }); + + // Register headerbar plugins + app.plugin_registry.register_contact_titlebar_entry(new MenuEntry(stream_interactor)); + app.plugin_registry.register_contact_titlebar_entry(search_menu_entry); + app.plugin_registry.register_contact_titlebar_entry(new OccupantsEntry(stream_interactor)); + + } public void select_conversation(Conversation? conversation, bool default_initialize_conversation) { @@ -55,12 +90,46 @@ public class ConversationViewController { chat_input_controller.set_conversation(conversation); + update_conversation_display_name(); + update_conversation_topic(); + + foreach(var e in this.app.plugin_registry.conversation_titlebar_entries) { + Plugins.ConversationTitlebarWidget view = e.get_widget(Plugins.WidgetType.GTK); + if (view != null) { + view.set_conversation(conversation); + } + } + if (default_initialize_conversation) { - widget.conversation_frame.initialize_for_conversation(conversation); + view.conversation_frame.initialize_for_conversation(conversation); + } + } + + public void unset_conversation() { + conversation_display_name = null; + conversation_topic = null; + } + + private void update_conversation_display_name() { + conversation_display_name = Util.get_conversation_display_name(stream_interactor, conversation); + } + + private void update_conversation_topic(string? subtitle = null) { + if (subtitle != null) { + conversation_topic = Util.summarize_whitespaces_to_space(subtitle); + } else if (conversation.type_ == Conversation.Type.GROUPCHAT) { + string? subject = stream_interactor.get_module(MucManager.IDENTITY).get_groupchat_subject(conversation.counterpart, conversation.account); + if (subject != null) { + conversation_topic = Util.summarize_whitespaces_to_space(subject); + } else { + conversation_topic = null; + } + } else { + conversation_topic = null; } } - public void on_drag_data_received(Widget widget, Gdk.DragContext context, int x, int y, SelectionData selection_data, uint target_type, uint time) { + private void on_drag_data_received(Widget widget, Gdk.DragContext context, int x, int y, SelectionData selection_data, uint target_type, uint time) { if ((selection_data != null) && (selection_data.get_length() >= 0)) { switch (target_type) { case Target.URI_LIST: @@ -78,7 +147,7 @@ public class ConversationViewController { } } - public bool forward_key_press_to_chat_input(EventKey event) { + private bool forward_key_press_to_chat_input(EventKey event) { // Don't forward / change focus on Control / Alt if (event.keyval == Gdk.Key.Control_L || event.keyval == Gdk.Key.Control_R || event.keyval == Gdk.Key.Alt_L || event.keyval == Gdk.Key.Alt_R) { @@ -88,8 +157,8 @@ public class ConversationViewController { if ((event.state & ModifierType.CONTROL_MASK) > 0) { return false; } - widget.chat_input.text_input.key_press_event(event); - widget.chat_input.text_input.grab_focus(); + view.chat_input.text_input.key_press_event(event); + view.chat_input.text_input.grab_focus(); return true; } } diff --git a/main/src/ui/unified_window.vala b/main/src/ui/unified_window.vala index 9d9a870c..1c57e7b7 100644 --- a/main/src/ui/unified_window.vala +++ b/main/src/ui/unified_window.vala @@ -51,8 +51,6 @@ public class UnifiedWindow : Gtk.Window { setup_unified(); setup_stack(); - this.bind_property("title", conversation_titlebar, "title"); - this.bind_property("subtitle", conversation_titlebar, "subtitle"); paned.bind_property("position", headerbar_paned, "position", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); stream_interactor.account_added.connect((account) => { check_stack(true); }); @@ -80,14 +78,14 @@ public class UnifiedWindow : Gtk.Window { private void setup_headerbar() { if (Util.use_csd()) { - conversation_list_titlebar_csd = new ConversationListTitlebarCsd(stream_interactor, this) { visible=true }; + conversation_list_titlebar_csd = new ConversationListTitlebarCsd() { visible=true }; headerbar_paned.pack1(conversation_list_titlebar_csd, false, false); conversation_titlebar_csd = new ConversationTitlebarCsd() { visible=true }; conversation_titlebar = conversation_titlebar_csd; headerbar_paned.pack2(conversation_titlebar_csd, true, false); } else { - ConversationListTitlebar conversation_list_titlebar = new ConversationListTitlebar(stream_interactor, this) { visible=true }; + ConversationListTitlebar conversation_list_titlebar = new ConversationListTitlebar() { visible=true }; headerbar_paned.pack1(conversation_list_titlebar, false, false); conversation_titlebar = new ConversationTitlebarNoCsd() { visible=true }; @@ -95,7 +93,6 @@ public class UnifiedWindow : Gtk.Window { box.add(headerbar_paned); } -// headerbar_paned.key_press_event.connect(forward_key_press_to_chat_input); TODO } private void set_window_buttons() { diff --git a/main/src/ui/unified_window_controller.vala b/main/src/ui/unified_window_controller.vala index 2ee1c452..d580f8cc 100644 --- a/main/src/ui/unified_window_controller.vala +++ b/main/src/ui/unified_window_controller.vala @@ -8,17 +8,12 @@ namespace Dino.Ui { public class UnifiedWindowController : Object { - public new string? conversation_display_name { get; set; } - public string? conversation_topic { get; set; } - private StreamInteractor stream_interactor; private Conversation? conversation; private Application app; private Database db; private UnifiedWindow window; - private SearchMenuEntry search_menu_entry = new SearchMenuEntry(); - private ConversationViewController conversation_view_controller; public UnifiedWindowController(Application application, StreamInteractor stream_interactor, Database db) { @@ -26,39 +21,16 @@ public class UnifiedWindowController : Object { this.stream_interactor = stream_interactor; this.db = db; - stream_interactor.get_module(MucManager.IDENTITY).room_name_set.connect((account, jid, room_name) => { - if (conversation != null && conversation.counterpart.equals_bare(jid) && conversation.account.equals(account)) { - update_conversation_display_name(); - } - }); - - stream_interactor.get_module(MucManager.IDENTITY).private_room_occupant_updated.connect((account, room, occupant) => { - if (conversation != null && conversation.counterpart.equals_bare(room.bare_jid) && conversation.account.equals(account)) { - update_conversation_display_name(); - } - }); - - stream_interactor.get_module(MucManager.IDENTITY).subject_set.connect((account, jid, subject) => { - if (conversation != null && conversation.counterpart.equals_bare(jid) && conversation.account.equals(account)) { - update_conversation_topic(subject); - } - }); stream_interactor.get_module(ConversationManager.IDENTITY).conversation_deactivated.connect(check_unset_conversation); stream_interactor.account_removed.connect(check_unset_conversation); - - app.plugin_registry.register_contact_titlebar_entry(new MenuEntry(stream_interactor)); - app.plugin_registry.register_contact_titlebar_entry(search_menu_entry); - app.plugin_registry.register_contact_titlebar_entry(new OccupantsEntry(stream_interactor)); } public void set_window(UnifiedWindow window) { this.window = window; - this.conversation_view_controller = new ConversationViewController(window.conversation_view, stream_interactor); + this.conversation_view_controller = new ConversationViewController(window.conversation_view, window.conversation_titlebar, stream_interactor); - this.bind_property("conversation-display-name", window, "title"); - this.bind_property("conversation-topic", window, "subtitle"); - search_menu_entry.search_button.bind_property("active", window.search_revealer, "reveal_child"); + conversation_view_controller.search_menu_entry.search_button.bind_property("active", window.search_revealer, "reveal_child"); window.search_revealer.notify["child-revealed"].connect(() => { if (window.search_revealer.child_revealed) { @@ -119,16 +91,6 @@ public class UnifiedWindowController : Object { conversation_view_controller.select_conversation(conversation, default_initialize_conversation); - update_conversation_display_name(); - update_conversation_topic(); - - foreach(var e in this.app.plugin_registry.conversation_titlebar_entries) { - Plugins.ConversationTitlebarWidget widget = e.get_widget(Plugins.WidgetType.GTK); - if (widget != null) { - widget.set_conversation(conversation); - } - } - stream_interactor.get_module(ChatInteraction.IDENTITY).on_conversation_selected(conversation); conversation.active = true; // only for conversation_selected window.conversation_selector.on_conversation_selected(conversation); // In case selection was not via ConversationSelector @@ -147,8 +109,7 @@ public class UnifiedWindowController : Object { private void unset_conversation() { this.conversation = null; - conversation_display_name = null; - conversation_topic = null; + conversation_view_controller.unset_conversation(); foreach(var e in this.app.plugin_registry.conversation_titlebar_entries) { Plugins.ConversationTitlebarWidget widget = e.get_widget(Plugins.WidgetType.GTK); @@ -158,25 +119,6 @@ public class UnifiedWindowController : Object { } } - private void update_conversation_display_name() { - conversation_display_name = Util.get_conversation_display_name(stream_interactor, conversation); - } - - private void update_conversation_topic(string? subtitle = null) { - if (subtitle != null) { - conversation_topic = Util.summarize_whitespaces_to_space(subtitle); - } else if (conversation.type_ == Conversation.Type.GROUPCHAT) { - string? subject = stream_interactor.get_module(MucManager.IDENTITY).get_groupchat_subject(conversation.counterpart, conversation.account); - if (subject != null) { - conversation_topic = Util.summarize_whitespaces_to_space(subject); - } else { - conversation_topic = null; - } - } else { - conversation_topic = null; - } - } - private void reset_search_entry() { if (window.conversation_view.conversation_frame.conversation != null) { switch (conversation.type_) { @@ -192,7 +134,7 @@ public class UnifiedWindowController : Object { } private void close_search() { - search_menu_entry.search_button.active = false; + conversation_view_controller.search_menu_entry.search_button.active = false; window.search_revealer.reveal_child = false; } } |