2017-03-17 22:21:23 +00:00
|
|
|
using Gee;
|
2017-03-02 14:37:32 +00:00
|
|
|
using Gtk;
|
|
|
|
|
|
|
|
using Dino.Entities;
|
|
|
|
|
2017-03-10 17:07:28 +00:00
|
|
|
namespace Dino.Ui {
|
|
|
|
|
|
|
|
public class UnifiedWindow : Window {
|
2017-03-17 22:21:23 +00:00
|
|
|
|
2017-03-20 21:12:20 +00:00
|
|
|
private NoAccountsPlaceholder accounts_placeholder = new NoAccountsPlaceholder() { visible=true };
|
|
|
|
private NoConversationsPlaceholder conversations_placeholder = new NoConversationsPlaceholder() { visible=true };
|
2017-03-17 22:21:23 +00:00
|
|
|
private ChatInput chat_input;
|
|
|
|
private ConversationListTitlebar conversation_list_titlebar;
|
|
|
|
private ConversationSelector.View filterable_conversation_list;
|
|
|
|
private ConversationSummary.View conversation_frame;
|
|
|
|
private ConversationTitlebar conversation_titlebar;
|
2017-03-20 21:12:20 +00:00
|
|
|
private Paned headerbar_paned = new Paned(Orientation.HORIZONTAL) { visible=true };
|
|
|
|
private Paned paned = new Paned(Orientation.HORIZONTAL) { visible=true };
|
|
|
|
private Stack headerbar_stack = new Stack() { visible=true };
|
|
|
|
private Stack stack = new Stack() { visible=true };
|
2017-03-02 14:37:32 +00:00
|
|
|
|
|
|
|
private StreamInteractor stream_interactor;
|
|
|
|
private Conversation? conversation;
|
|
|
|
|
|
|
|
public UnifiedWindow(Application application, StreamInteractor stream_interactor) {
|
2017-03-17 22:21:23 +00:00
|
|
|
Object(application : application, default_width : 1200, default_height : 700);
|
2017-03-02 14:37:32 +00:00
|
|
|
this.stream_interactor = stream_interactor;
|
2017-03-17 22:21:23 +00:00
|
|
|
|
|
|
|
setup_headerbar();
|
|
|
|
setup_unified();
|
2017-03-20 21:12:20 +00:00
|
|
|
setup_stack();
|
2017-03-17 22:21:23 +00:00
|
|
|
|
|
|
|
conversation_list_titlebar.search_button.bind_property("active", filterable_conversation_list.search_bar, "search-mode-enabled",
|
|
|
|
BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
|
|
|
|
paned.bind_property("position", headerbar_paned, "position", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
|
|
|
|
|
2017-03-02 14:37:32 +00:00
|
|
|
focus_in_event.connect(on_focus_in_event);
|
|
|
|
focus_out_event.connect(on_focus_out_event);
|
|
|
|
|
2017-03-17 22:21:23 +00:00
|
|
|
stream_interactor.account_added.connect((account) => { check_stack(true); });
|
|
|
|
stream_interactor.account_removed.connect((account) => { check_stack(); });
|
2017-03-20 21:12:20 +00:00
|
|
|
stream_interactor.get_module(ConversationManager.IDENTITY).conversation_activated.connect((conversation) => { check_stack(); });
|
|
|
|
stream_interactor.get_module(ConversationManager.IDENTITY).conversation_deactivated.connect((conversation) => { check_stack(); });
|
|
|
|
accounts_placeholder.primary_button.clicked.connect(() => { get_application().activate_action("accounts", null); });
|
|
|
|
conversations_placeholder.primary_button.clicked.connect(() => { get_application().activate_action("add_chat", null); });
|
|
|
|
conversations_placeholder.secondary_button.clicked.connect(() => { get_application().activate_action("add_conference", null); });
|
2017-03-17 22:21:23 +00:00
|
|
|
filterable_conversation_list.conversation_list.conversation_selected.connect(on_conversation_selected);
|
|
|
|
conversation_list_titlebar.conversation_opened.connect(on_conversation_selected);
|
|
|
|
|
|
|
|
check_stack();
|
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2017-03-17 22:21:23 +00:00
|
|
|
private void setup_unified() {
|
2017-03-20 21:12:20 +00:00
|
|
|
chat_input = new ChatInput(stream_interactor) { visible=true };
|
|
|
|
conversation_frame = new ConversationSummary.View(stream_interactor) { visible=true };
|
|
|
|
filterable_conversation_list = new ConversationSelector.View(stream_interactor) { visible=true };
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2017-03-20 21:12:20 +00:00
|
|
|
Grid grid = new Grid() { orientation=Orientation.VERTICAL, visible=true };
|
2017-03-02 14:37:32 +00:00
|
|
|
grid.add(conversation_frame);
|
2017-03-20 21:12:20 +00:00
|
|
|
grid.add(new Separator(Orientation.HORIZONTAL) { visible=true });
|
2017-03-02 14:37:32 +00:00
|
|
|
grid.add(chat_input);
|
|
|
|
|
2017-03-17 22:21:23 +00:00
|
|
|
paned.set_position(300);
|
|
|
|
paned.add1(filterable_conversation_list);
|
|
|
|
paned.add2(grid);
|
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2017-03-17 22:21:23 +00:00
|
|
|
private void setup_headerbar() {
|
2017-03-20 21:12:20 +00:00
|
|
|
conversation_titlebar = new ConversationTitlebar(stream_interactor) { visible=true };
|
|
|
|
conversation_list_titlebar = new ConversationListTitlebar(this, stream_interactor) { visible=true };
|
2017-03-17 22:21:23 +00:00
|
|
|
headerbar_paned.add1(conversation_list_titlebar);
|
|
|
|
headerbar_paned.add2(conversation_titlebar);
|
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2017-03-20 21:12:20 +00:00
|
|
|
private void setup_stack() {
|
2017-03-17 22:21:23 +00:00
|
|
|
stack.add_named(paned, "main");
|
2017-03-20 21:12:20 +00:00
|
|
|
stack.add_named(accounts_placeholder, "accounts_placeholder");
|
|
|
|
stack.add_named(conversations_placeholder, "conversations_placeholder");
|
2017-03-17 22:21:23 +00:00
|
|
|
add(stack);
|
|
|
|
|
|
|
|
headerbar_stack.add_named(headerbar_paned, "main");
|
2017-03-20 21:12:20 +00:00
|
|
|
headerbar_stack.add_named(new HeaderBar() { title="Dino", show_close_button=true, visible=true }, "placeholder");
|
2017-03-17 22:21:23 +00:00
|
|
|
set_titlebar(headerbar_stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void check_stack(bool know_exists = false) {
|
|
|
|
ArrayList<Account> accounts = stream_interactor.get_accounts();
|
2017-03-20 21:12:20 +00:00
|
|
|
if (!know_exists && accounts.size == 0) {
|
|
|
|
stack.set_visible_child_name("accounts_placeholder");
|
|
|
|
headerbar_stack.set_visible_child_name("placeholder");
|
|
|
|
} else if (stream_interactor.get_module(ConversationManager.IDENTITY).get_active_conversations().size == 0) {
|
|
|
|
stack.set_visible_child_name("conversations_placeholder");
|
|
|
|
headerbar_stack.set_visible_child_name("placeholder");
|
|
|
|
} else {
|
2017-03-17 22:21:23 +00:00
|
|
|
stack.set_visible_child_name("main");
|
|
|
|
headerbar_stack.set_visible_child_name("main");
|
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void on_conversation_selected(Conversation conversation) {
|
|
|
|
this.conversation = conversation;
|
2017-03-19 11:55:36 +00:00
|
|
|
stream_interactor.get_module(ChatInteraction.IDENTITY).on_conversation_selected(conversation);
|
2017-03-02 14:37:32 +00:00
|
|
|
conversation.active = true; // only for conversation_selected
|
|
|
|
filterable_conversation_list.conversation_list.on_conversation_selected(conversation); // only for conversation_opened
|
|
|
|
|
|
|
|
chat_input.initialize_for_conversation(conversation);
|
|
|
|
conversation_frame.initialize_for_conversation(conversation);
|
|
|
|
conversation_titlebar.initialize_for_conversation(conversation);
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool on_focus_in_event() {
|
2017-03-19 11:55:36 +00:00
|
|
|
stream_interactor.get_module(ChatInteraction.IDENTITY).on_window_focus_in(conversation);
|
2017-03-02 14:37:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private bool on_focus_out_event() {
|
2017-03-19 11:55:36 +00:00
|
|
|
stream_interactor.get_module(ChatInteraction.IDENTITY).on_window_focus_out(conversation);
|
2017-03-02 14:37:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-20 21:12:20 +00:00
|
|
|
public class NoAccountsPlaceholder : UnifiedWindowPlaceholder {
|
|
|
|
public NoAccountsPlaceholder() {
|
|
|
|
label.label = "No accounts active";
|
|
|
|
primary_button.label = "Manage accounts";
|
|
|
|
secondary_button.visible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class NoConversationsPlaceholder : UnifiedWindowPlaceholder {
|
|
|
|
public NoConversationsPlaceholder() {
|
|
|
|
label.label = "No conversation active";
|
|
|
|
primary_button.label = "Add Chat";
|
|
|
|
secondary_button.label = "Join Conference";
|
|
|
|
secondary_button.visible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-17 22:21:23 +00:00
|
|
|
[GtkTemplate (ui = "/org/dino-im/unified_window_placeholder.ui")]
|
|
|
|
public class UnifiedWindowPlaceholder : Box {
|
2017-03-20 21:12:20 +00:00
|
|
|
[GtkChild] public Label label;
|
|
|
|
[GtkChild] public Button primary_button;
|
|
|
|
[GtkChild] public Button secondary_button;
|
2017-03-17 22:21:23 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 17:07:28 +00:00
|
|
|
}
|