From ea5d3e50c6fd63ae3a151c883f691e76b9cb1018 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Mon, 3 Apr 2017 19:20:31 +0200 Subject: Start private conversation with MUC occupant via occupant menu --- main/src/ui/conversation_titlebar.vala | 7 +- main/src/ui/occupant_list.vala | 111 -------------------------------- main/src/ui/occupant_list_row.vala | 25 ------- main/src/ui/occupant_menu/list.vala | 111 ++++++++++++++++++++++++++++++++ main/src/ui/occupant_menu/list_row.vala | 30 +++++++++ main/src/ui/occupant_menu/view.vala | 79 +++++++++++++++++++++++ 6 files changed, 222 insertions(+), 141 deletions(-) delete mode 100644 main/src/ui/occupant_list.vala delete mode 100644 main/src/ui/occupant_list_row.vala create mode 100644 main/src/ui/occupant_menu/list.vala create mode 100644 main/src/ui/occupant_menu/list_row.vala create mode 100644 main/src/ui/occupant_menu/view.vala (limited to 'main/src') diff --git a/main/src/ui/conversation_titlebar.vala b/main/src/ui/conversation_titlebar.vala index 45c4c9c1..70a376f1 100644 --- a/main/src/ui/conversation_titlebar.vala +++ b/main/src/ui/conversation_titlebar.vala @@ -61,11 +61,8 @@ public class ConversationTitlebar : Gtk.HeaderBar { groupchat_button.visible = conversation.type_ == Conversation.Type.GROUPCHAT; if (conversation.type_ == Conversation.Type.GROUPCHAT) { groupchat_button.set_use_popover(true); - Popover popover = new Popover(null); - OccupantList occupant_list = new OccupantList(stream_interactor, conversation); - popover.add(occupant_list); - occupant_list.show_all(); - groupchat_button.set_popover(popover); + OccupantMenu.View menu = new OccupantMenu.View(stream_interactor, conversation); + groupchat_button.set_popover(menu); } } diff --git a/main/src/ui/occupant_list.vala b/main/src/ui/occupant_list.vala deleted file mode 100644 index 309289fc..00000000 --- a/main/src/ui/occupant_list.vala +++ /dev/null @@ -1,111 +0,0 @@ -using Gee; -using Gtk; - -using Dino.Entities; - -namespace Dino.Ui{ - -[GtkTemplate (ui = "/org/dino-im/occupant_list.ui")] -public class OccupantList : Box { - - public signal void conversation_selected(Conversation? conversation); - private StreamInteractor stream_interactor; - - [GtkChild] private ListBox list_box; - [GtkChild] private SearchEntry search_entry; - - private Conversation? conversation; - private string[]? filter_values; - private HashMap rows = new HashMap(Jid.hash_func, Jid.equals_func); - - public OccupantList(StreamInteractor stream_interactor, Conversation conversation) { - this.stream_interactor = stream_interactor; - list_box.set_header_func(header); - list_box.set_sort_func(sort); - list_box.set_filter_func(filter); - search_entry.search_changed.connect(search_changed); - - stream_interactor.get_module(PresenceManager.IDENTITY).show_received.connect((show, jid, account) => { - Idle.add(() => { on_show_received(show, jid, account); return false; }); - }); - stream_interactor.get_module(RosterManager.IDENTITY).updated_roster_item.connect(on_updated_roster_item); - - initialize_for_conversation(conversation); - } - - public void initialize_for_conversation(Conversation conversation) { - this.conversation = conversation; - ArrayList? occupants = stream_interactor.get_module(MucManager.IDENTITY).get_occupants(conversation.counterpart, conversation.account); - if (occupants != null) { - foreach (Jid occupant in occupants) { - add_occupant(occupant); - } - } - } - - private void refilter() { - string[]? values = null; - string str = search_entry.get_text (); - if (str != "") values = str.split(" "); - if (filter_values == values) return; - filter_values = values; - list_box.invalidate_filter(); - } - - private void search_changed(Editable editable) { - refilter(); - } - - public void add_occupant(Jid jid) { - rows[jid] = new OccupantListRow(stream_interactor, conversation.account, jid); - list_box.add(rows[jid]); - list_box.invalidate_filter(); - list_box.invalidate_sort(); - } - - public void remove_occupant(Jid jid) { - list_box.remove(rows[jid]); - rows.unset(jid); - } - - private void on_updated_roster_item(Account account, Jid jid, Xmpp.Roster.Item roster_item) { - - } - - private void on_show_received(Show show, Jid jid, Account account) { - if (conversation != null && conversation.counterpart.equals_bare(jid)) { - if (show.as == Show.OFFLINE && rows.has_key(jid)) { - remove_occupant(jid); - } else if (show.as != Show.OFFLINE && !rows.has_key(jid)) { - add_occupant(jid); - } - } - } - - private void header(ListBoxRow row, ListBoxRow? before_row) { - if (row.get_header() == null && before_row != null) { - row.set_header(new Separator(Orientation.HORIZONTAL)); - } - } - - private bool filter(ListBoxRow r) { - if (r.get_type().is_a(typeof(OccupantListRow))) { - OccupantListRow row = r as OccupantListRow; - foreach (string filter in filter_values) { - return row.name_label.label.down().contains(filter.down()); - } - } - return true; - } - - private int sort(ListBoxRow row1, ListBoxRow row2) { - if (row1.get_type().is_a(typeof(OccupantListRow)) && row2.get_type().is_a(typeof(OccupantListRow))) { - OccupantListRow c1 = row1 as OccupantListRow; - OccupantListRow c2 = row2 as OccupantListRow; - return c1.name_label.label.collate(c2.name_label.label); - } - return 0; - } -} - -} \ No newline at end of file diff --git a/main/src/ui/occupant_list_row.vala b/main/src/ui/occupant_list_row.vala deleted file mode 100644 index 4dc7c0c5..00000000 --- a/main/src/ui/occupant_list_row.vala +++ /dev/null @@ -1,25 +0,0 @@ -using Gtk; - -using Dino.Entities; -using Xmpp; - -namespace Dino.Ui { - -[GtkTemplate (ui = "/org/dino-im/occupant_list_item.ui")] -public class OccupantListRow : ListBoxRow { - - [GtkChild] private Image image; - [GtkChild] public Label name_label; - - public OccupantListRow(StreamInteractor stream_interactor, Account account, Jid jid) { - name_label.label = Util.get_display_name(stream_interactor, jid, account); - Util.image_set_from_scaled_pixbuf(image, (new AvatarGenerator(30, 30, image.scale_factor)).draw_jid(stream_interactor, jid, account)); - //has_tooltip = true; - } - - public void on_presence_received(Presence.Stanza presence) { - - } -} - -} \ No newline at end of file diff --git a/main/src/ui/occupant_menu/list.vala b/main/src/ui/occupant_menu/list.vala new file mode 100644 index 00000000..1e96ece4 --- /dev/null +++ b/main/src/ui/occupant_menu/list.vala @@ -0,0 +1,111 @@ +using Gee; +using Gtk; + +using Dino.Entities; + +namespace Dino.Ui.OccupantMenu{ + +[GtkTemplate (ui = "/org/dino-im/occupant_list.ui")] +public class List : Box { + + public signal void conversation_selected(Conversation? conversation); + private StreamInteractor stream_interactor; + + [GtkChild] public ListBox list_box; + [GtkChild] private SearchEntry search_entry; + + private Conversation? conversation; + private string[]? filter_values; + private HashMap rows = new HashMap(Jid.hash_func, Jid.equals_func); + + public List(StreamInteractor stream_interactor, Conversation conversation) { + this.stream_interactor = stream_interactor; + list_box.set_header_func(header); + list_box.set_sort_func(sort); + list_box.set_filter_func(filter); + search_entry.search_changed.connect(search_changed); + + stream_interactor.get_module(PresenceManager.IDENTITY).show_received.connect((show, jid, account) => { + Idle.add(() => { on_show_received(show, jid, account); return false; }); + }); + stream_interactor.get_module(RosterManager.IDENTITY).updated_roster_item.connect(on_updated_roster_item); + + initialize_for_conversation(conversation); + } + + public void initialize_for_conversation(Conversation conversation) { + this.conversation = conversation; + ArrayList? occupants = stream_interactor.get_module(MucManager.IDENTITY).get_occupants(conversation.counterpart, conversation.account); + if (occupants != null) { + foreach (Jid occupant in occupants) { + add_occupant(occupant); + } + } + } + + private void refilter() { + string[]? values = null; + string str = search_entry.get_text (); + if (str != "") values = str.split(" "); + if (filter_values == values) return; + filter_values = values; + list_box.invalidate_filter(); + } + + private void search_changed(Editable editable) { + refilter(); + } + + public void add_occupant(Jid jid) { + rows[jid] = new ListRow(stream_interactor, conversation.account, jid); + list_box.add(rows[jid]); + list_box.invalidate_filter(); + list_box.invalidate_sort(); + } + + public void remove_occupant(Jid jid) { + list_box.remove(rows[jid]); + rows.unset(jid); + } + + private void on_updated_roster_item(Account account, Jid jid, Xmpp.Roster.Item roster_item) { + + } + + private void on_show_received(Show show, Jid jid, Account account) { + if (conversation != null && conversation.counterpart.equals_bare(jid)) { + if (show.as == Show.OFFLINE && rows.has_key(jid)) { + remove_occupant(jid); + } else if (show.as != Show.OFFLINE && !rows.has_key(jid)) { + add_occupant(jid); + } + } + } + + private void header(ListBoxRow row, ListBoxRow? before_row) { + if (row.get_header() == null && before_row != null) { + row.set_header(new Separator(Orientation.HORIZONTAL)); + } + } + + private bool filter(ListBoxRow r) { + if (r.get_type().is_a(typeof(ListRow))) { + ListRow row = r as ListRow; + foreach (string filter in filter_values) { + return row.name_label.label.down().contains(filter.down()); + } + } + return true; + } + + private int sort(ListBoxRow row1, ListBoxRow row2) { + if (row1.get_type().is_a(typeof(ListRow)) && row2.get_type().is_a(typeof(ListRow))) { + ListRow c1 = row1 as ListRow; + ListRow c2 = row2 as ListRow; + return c1.name_label.label.collate(c2.name_label.label); + } + return 0; + } +} + +} \ No newline at end of file diff --git a/main/src/ui/occupant_menu/list_row.vala b/main/src/ui/occupant_menu/list_row.vala new file mode 100644 index 00000000..b8b95758 --- /dev/null +++ b/main/src/ui/occupant_menu/list_row.vala @@ -0,0 +1,30 @@ +using Gtk; + +using Dino.Entities; +using Xmpp; + +namespace Dino.Ui.OccupantMenu { + +[GtkTemplate (ui = "/org/dino-im/occupant_list_item.ui")] +public class ListRow : ListBoxRow { + + [GtkChild] private Image image; + [GtkChild] public Label name_label; + + public Account account; + public Jid jid; + + public ListRow(StreamInteractor stream_interactor, Account account, Jid jid) { + this.account = account; + this.jid = jid; + + name_label.label = Util.get_display_name(stream_interactor, jid, account); + Util.image_set_from_scaled_pixbuf(image, (new AvatarGenerator(30, 30, image.scale_factor)).draw_jid(stream_interactor, jid, account)); + } + + public void on_presence_received(Presence.Stanza presence) { + + } +} + +} \ No newline at end of file diff --git a/main/src/ui/occupant_menu/view.vala b/main/src/ui/occupant_menu/view.vala new file mode 100644 index 00000000..b7fe15ba --- /dev/null +++ b/main/src/ui/occupant_menu/view.vala @@ -0,0 +1,79 @@ +using Gtk; + +using Dino.Entities; + +namespace Dino.Ui.OccupantMenu { +public class View : Popover { + + private StreamInteractor stream_interactor; + private Conversation conversation; + + private Stack stack = new Stack() { vhomogeneous=false, visible=true }; + private List list; + private Label header_label = new Label("") { xalign=0.5f, hexpand=true, visible=true }; + + public View(StreamInteractor stream_interactor, Conversation conversation) { + this.stream_interactor = stream_interactor; + this.conversation = conversation; + + list = new List(stream_interactor, conversation) { visible=true }; + stack.add_named(list, "list"); + setup_menu(); + add(stack); + stack.visible_child_name = "list"; + + list.list_box.row_activated.connect((row) => { + ListRow list_row = row as ListRow; + header_label.label = list_row.name_label.label; + show_menu(); + }); + + hide.connect(reset); + } + + public void reset() { + stack.transition_type = StackTransitionType.NONE; + stack.visible_child_name = "list"; + list.list_box.unselect_all(); + } + + private void setup_menu() { + Box header_box = new Box(Orientation.HORIZONTAL, 5) { visible=true }; + header_box.add(new Image.from_icon_name("pan-start-symbolic", IconSize.SMALL_TOOLBAR) { visible=true }); + header_box.add(header_label); + + Button header_button = new Button() { relief=ReliefStyle.NONE, visible=true }; + header_button.add(header_box); + + ModelButton private_button = new ModelButton() { active=true, text="Start private conversation", visible=true }; + + Box outer_box = new Box(Orientation.VERTICAL, 5) { margin=10, visible=true }; + outer_box.add(header_button); + outer_box.add(private_button); + stack.add_named(outer_box, "menu"); + + header_button.clicked.connect(show_list); + private_button.clicked.connect(private_conversation_button_clicked); + } + + private void show_list() { + list.list_box.unselect_all(); + stack.transition_type = StackTransitionType.SLIDE_RIGHT; + stack.visible_child_name = "list"; + } + + private void show_menu() { + stack.transition_type = StackTransitionType.SLIDE_LEFT; + stack.visible_child_name = "menu"; + } + + private void private_conversation_button_clicked() { + ListRow? list_row = list.list_box.get_selected_row() as ListRow; + if (list_row == null) return; + + Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(list_row.jid, list_row.account, Conversation.Type.GROUPCHAT_PM); + stream_interactor.get_module(ConversationManager.IDENTITY).start_conversation(conversation, true); + } +} + +} \ No newline at end of file -- cgit v1.2.3-70-g09d2