anotherim-desktop/main/src/ui/add_conversation/select_contact_dialog.vala

110 lines
3.8 KiB
Vala
Raw Normal View History

2017-03-02 14:37:32 +00:00
using Gee;
using Gdk;
using Gtk;
using Dino.Entities;
using Xmpp;
2017-03-02 14:37:32 +00:00
namespace Dino.Ui {
2017-03-02 14:37:32 +00:00
public class SelectContactDialog : Gtk.Dialog {
2017-03-02 14:37:32 +00:00
2017-06-11 11:59:24 +00:00
public signal void selected(Account account, Jid jid);
2017-03-02 14:37:32 +00:00
2017-06-11 11:59:24 +00:00
public Button ok_button;
2017-03-02 14:37:32 +00:00
private RosterList roster_list;
2022-02-14 13:55:59 +00:00
private ListBox roster_list_box;
2017-03-02 14:37:32 +00:00
private SelectJidFragment select_jid_fragment;
private StreamInteractor stream_interactor;
2017-06-11 11:59:24 +00:00
private Gee.List<Account> accounts;
2017-03-02 14:37:32 +00:00
public SelectContactDialog(StreamInteractor stream_interactor, Gee.List<Account> accounts) {
Object(use_header_bar : Util.use_csd() ? 1 : 0);
2017-06-11 11:59:24 +00:00
modal = true;
2017-03-02 14:37:32 +00:00
this.stream_interactor = stream_interactor;
2017-06-11 11:59:24 +00:00
this.accounts = accounts;
2017-03-02 14:37:32 +00:00
setup_view();
setup_headerbar();
2017-03-02 14:37:32 +00:00
}
2017-08-25 19:20:09 +00:00
public void set_filter(string str) {
select_jid_fragment.set_filter(str);
}
2017-03-02 14:37:32 +00:00
private void setup_headerbar() {
Button cancel_button = new Button();
2017-04-07 09:09:47 +00:00
cancel_button.set_label(_("Cancel"));
2017-03-02 14:37:32 +00:00
cancel_button.visible = true;
ok_button = new Button();
2022-05-14 12:45:59 +00:00
ok_button.add_css_class("suggested-action");
2017-03-02 14:37:32 +00:00
ok_button.sensitive = false;
ok_button.visible = true;
if (Util.use_csd()) {
HeaderBar header_bar = get_header_bar() as HeaderBar;
2022-02-14 13:55:59 +00:00
header_bar.show_title_buttons = false;
header_bar.pack_start(cancel_button);
header_bar.pack_end(ok_button);
} else {
2022-05-14 12:45:59 +00:00
Box box = new Box(Orientation.HORIZONTAL, 5) { halign=Align.END, margin_bottom=15, margin_start=80, margin_end=80 };
cancel_button.halign = Align.START;
ok_button.halign = Align.END;
2022-02-14 13:55:59 +00:00
box.append(cancel_button);
box.append(ok_button);
2022-02-14 13:55:59 +00:00
get_content_area().append(box);
}
2017-03-02 14:37:32 +00:00
cancel_button.clicked.connect(() => { close(); });
2017-06-11 11:59:24 +00:00
ok_button.clicked.connect(() => {
2022-02-14 13:55:59 +00:00
ListRow? selected_row = roster_list_box.get_selected_row() != null ? roster_list_box.get_selected_row().get_child() as ListRow : null;
2017-06-11 11:59:24 +00:00
if (selected_row != null) selected(selected_row.account, selected_row.jid);
close();
});
2017-03-02 14:37:32 +00:00
}
private void setup_view() {
2017-06-11 11:59:24 +00:00
roster_list = new RosterList(stream_interactor, accounts);
2022-02-14 13:55:59 +00:00
roster_list_box = roster_list.get_list_box();
roster_list_box.row_activated.connect(() => { ok_button.clicked(); });
select_jid_fragment = new SelectJidFragment(stream_interactor, roster_list_box, accounts);
2017-03-02 14:37:32 +00:00
select_jid_fragment.add_jid.connect((row) => {
AddContactDialog add_contact_dialog = new AddContactDialog(stream_interactor);
add_contact_dialog.set_transient_for(this);
2017-05-30 20:47:16 +00:00
add_contact_dialog.present();
2017-03-02 14:37:32 +00:00
});
select_jid_fragment.remove_jid.connect((row) => {
2022-02-14 13:55:59 +00:00
ListRow list_row = roster_list_box.get_selected_row() as ListRow;
stream_interactor.get_module(RosterManager.IDENTITY).remove_jid(list_row.account, list_row.jid);
2017-03-02 14:37:32 +00:00
});
select_jid_fragment.notify["done"].connect(() => {
ok_button.sensitive = select_jid_fragment.done;
});
2022-02-14 13:55:59 +00:00
get_content_area().append(select_jid_fragment);
2017-03-02 14:37:32 +00:00
}
}
2017-03-10 17:07:28 +00:00
public class AddChatDialog : SelectContactDialog {
public signal void added(Conversation conversation);
public AddChatDialog(StreamInteractor stream_interactor, Gee.List<Account> accounts) {
base(stream_interactor, accounts);
title = _("Start Conversation");
ok_button.label = _("Start");
selected.connect((account, jid) => {
Conversation conversation = stream_interactor.get_module(ConversationManager.IDENTITY).create_conversation(jid, account, Conversation.Type.CHAT);
stream_interactor.get_module(ConversationManager.IDENTITY).start_conversation(conversation);
added(conversation);
});
}
}
}