2017-03-17 22:21:23 +00:00
|
|
|
using Gee;
|
2018-07-29 21:24:53 +00:00
|
|
|
using Gdk;
|
2017-03-02 14:37:32 +00:00
|
|
|
using Gtk;
|
|
|
|
|
|
|
|
using Dino.Entities;
|
|
|
|
|
2017-03-10 17:07:28 +00:00
|
|
|
namespace Dino.Ui {
|
|
|
|
|
2018-07-29 21:24:53 +00:00
|
|
|
public class UnifiedWindow : Gtk.Window {
|
2017-03-17 22:21:23 +00:00
|
|
|
|
2019-01-27 14:24:58 +00:00
|
|
|
public signal void conversation_selected(Conversation conversation);
|
|
|
|
|
2019-04-12 15:43:47 +00:00
|
|
|
public new string? title { get; set; }
|
|
|
|
public string? subtitle { get; set; }
|
2019-01-27 14:24:58 +00:00
|
|
|
|
|
|
|
public WelcomePlceholder welcome_placeholder = new WelcomePlceholder() { visible=true };
|
|
|
|
public NoAccountsPlaceholder accounts_placeholder = new NoAccountsPlaceholder() { visible=true };
|
|
|
|
public NoConversationsPlaceholder conversations_placeholder = new NoConversationsPlaceholder() { visible=true };
|
|
|
|
public ChatInput.View chat_input;
|
2019-04-12 15:43:47 +00:00
|
|
|
public ConversationSelector conversation_selector;
|
2019-01-27 14:24:58 +00:00
|
|
|
public ConversationSummary.ConversationView conversation_frame;
|
|
|
|
public ConversationTitlebar conversation_titlebar;
|
2019-09-15 16:12:04 +00:00
|
|
|
public ConversationTitlebarCsd conversation_titlebar_csd;
|
|
|
|
public ConversationListTitlebarCsd conversation_list_titlebar_csd;
|
2019-01-27 14:24:58 +00:00
|
|
|
public HeaderBar placeholder_headerbar = new HeaderBar() { title="Dino", show_close_button=true, visible=true };
|
|
|
|
public Box box = new Box(Orientation.VERTICAL, 0) { orientation=Orientation.VERTICAL, visible=true };
|
|
|
|
public Paned headerbar_paned = new Paned(Orientation.HORIZONTAL) { visible=true };
|
|
|
|
public Paned paned;
|
|
|
|
public Revealer goto_end_revealer;
|
|
|
|
public Button goto_end_button;
|
|
|
|
public Revealer search_revealer;
|
|
|
|
public SearchEntry search_entry;
|
|
|
|
public GlobalSearch search_box;
|
2017-03-20 21:12:20 +00:00
|
|
|
private Stack stack = new Stack() { visible=true };
|
2017-03-02 14:37:32 +00:00
|
|
|
|
|
|
|
private StreamInteractor stream_interactor;
|
|
|
|
private Conversation? conversation;
|
2017-12-31 19:19:51 +00:00
|
|
|
private Application app;
|
2018-11-16 15:27:31 +00:00
|
|
|
private Database db;
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2018-11-16 15:27:31 +00:00
|
|
|
public UnifiedWindow(Application application, StreamInteractor stream_interactor, Database db) {
|
2017-12-31 19:19:51 +00:00
|
|
|
Object(application : application);
|
|
|
|
this.app = application;
|
2018-11-16 15:27:31 +00:00
|
|
|
this.stream_interactor = stream_interactor;
|
|
|
|
this.db = db;
|
2017-12-31 19:19:51 +00:00
|
|
|
|
2017-08-29 19:55:15 +00:00
|
|
|
this.get_style_context().add_class("dino-main");
|
2017-03-17 22:21:23 +00:00
|
|
|
setup_headerbar();
|
2019-09-15 16:12:04 +00:00
|
|
|
Gtk.Settings.get_default().notify["gtk-decoration-layout"].connect(set_window_buttons);
|
|
|
|
this.realize.connect(set_window_buttons);
|
2017-03-17 22:21:23 +00:00
|
|
|
setup_unified();
|
2017-03-20 21:12:20 +00:00
|
|
|
setup_stack();
|
2017-03-17 22:21:23 +00:00
|
|
|
|
2019-04-12 15:43:47 +00:00
|
|
|
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);
|
|
|
|
|
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-11-11 20:29:13 +00:00
|
|
|
stream_interactor.get_module(ConversationManager.IDENTITY).conversation_activated.connect(() => check_stack());
|
|
|
|
stream_interactor.get_module(ConversationManager.IDENTITY).conversation_deactivated.connect(() => check_stack());
|
2017-03-17 22:21:23 +00:00
|
|
|
|
2019-01-27 14:24:58 +00:00
|
|
|
check_stack();
|
2018-07-04 21:38:28 +00:00
|
|
|
}
|
|
|
|
|
2018-07-29 21:24:53 +00:00
|
|
|
public void on_conversation_selected(Conversation conversation, bool do_reset_search = true, bool default_initialize_conversation = true) {
|
2017-03-24 21:57:05 +00:00
|
|
|
if (this.conversation == null || !this.conversation.equals(conversation)) {
|
|
|
|
this.conversation = conversation;
|
2019-01-27 14:24:58 +00:00
|
|
|
conversation_selected(conversation);
|
|
|
|
}
|
2018-07-29 21:24:53 +00:00
|
|
|
}
|
|
|
|
|
2017-03-17 22:21:23 +00:00
|
|
|
private void setup_unified() {
|
2018-07-04 21:38:28 +00:00
|
|
|
Builder builder = new Builder.from_resource("/im/dino/Dino/unified_main_content.ui");
|
|
|
|
paned = (Paned) builder.get_object("paned");
|
2019-01-27 14:24:58 +00:00
|
|
|
box.add(paned);
|
2018-07-04 21:38:28 +00:00
|
|
|
chat_input = ((ChatInput.View) builder.get_object("chat_input")).init(stream_interactor);
|
2019-09-09 17:47:11 +00:00
|
|
|
chat_input.key_press_event.connect(forward_key_press_to_chat_input);
|
2018-07-04 21:38:28 +00:00
|
|
|
conversation_frame = ((ConversationSummary.ConversationView) builder.get_object("conversation_frame")).init(stream_interactor);
|
2019-09-09 17:47:11 +00:00
|
|
|
conversation_frame.key_press_event.connect(forward_key_press_to_chat_input);
|
2019-04-12 15:43:47 +00:00
|
|
|
conversation_selector = ((ConversationSelector) builder.get_object("conversation_list")).init(stream_interactor);
|
2018-08-07 14:03:00 +00:00
|
|
|
goto_end_revealer = (Revealer) builder.get_object("goto_end_revealer");
|
|
|
|
goto_end_button = (Button) builder.get_object("goto_end_button");
|
2018-07-09 22:31:39 +00:00
|
|
|
search_box = ((GlobalSearch) builder.get_object("search_box")).init(stream_interactor);
|
2018-07-04 21:38:28 +00:00
|
|
|
search_revealer = (Revealer) builder.get_object("search_revealer");
|
|
|
|
search_entry = (SearchEntry) builder.get_object("search_entry");
|
2017-03-17 22:21:23 +00:00
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2017-03-17 22:21:23 +00:00
|
|
|
private void setup_headerbar() {
|
2019-01-27 14:24:58 +00:00
|
|
|
if (Util.use_csd()) {
|
2019-09-15 16:12:04 +00:00
|
|
|
conversation_list_titlebar_csd = new ConversationListTitlebarCsd(stream_interactor, this) { visible=true };
|
2019-01-27 14:24:58 +00:00
|
|
|
headerbar_paned.pack1(conversation_list_titlebar_csd, false, false);
|
2019-04-12 15:43:47 +00:00
|
|
|
|
2019-09-15 16:12:04 +00:00
|
|
|
conversation_titlebar_csd = new ConversationTitlebarCsd() { visible=true };
|
2019-04-12 15:43:47 +00:00
|
|
|
conversation_titlebar = conversation_titlebar_csd;
|
2019-01-27 14:24:58 +00:00
|
|
|
headerbar_paned.pack2(conversation_titlebar_csd, true, false);
|
|
|
|
} else {
|
2019-04-12 15:43:47 +00:00
|
|
|
ConversationListTitlebar conversation_list_titlebar = new ConversationListTitlebar(stream_interactor, this) { visible=true };
|
2019-01-27 14:24:58 +00:00
|
|
|
headerbar_paned.pack1(conversation_list_titlebar, false, false);
|
2019-04-12 15:43:47 +00:00
|
|
|
|
|
|
|
conversation_titlebar = new ConversationTitlebarNoCsd() { visible=true };
|
2019-01-27 14:24:58 +00:00
|
|
|
headerbar_paned.pack2(conversation_titlebar, true, false);
|
|
|
|
|
|
|
|
box.add(headerbar_paned);
|
2017-04-04 17:55:24 +00:00
|
|
|
}
|
2019-09-09 17:47:11 +00:00
|
|
|
headerbar_paned.key_press_event.connect(forward_key_press_to_chat_input);
|
2017-03-17 22:21:23 +00:00
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
|
2019-09-15 16:12:04 +00:00
|
|
|
private void set_window_buttons() {
|
|
|
|
if (!Util.use_csd()) return;
|
|
|
|
Gtk.Settings? gtk_settings = Gtk.Settings.get_default();
|
|
|
|
if (gtk_settings == null) return;
|
|
|
|
|
|
|
|
string[] buttons = gtk_settings.gtk_decoration_layout.split(":");
|
|
|
|
this.conversation_list_titlebar_csd.decoration_layout = buttons[0] + ":";
|
|
|
|
this.conversation_titlebar_csd.decoration_layout = ((buttons.length == 2) ? ":" + buttons[1] : "");
|
|
|
|
}
|
|
|
|
|
2017-03-20 21:12:20 +00:00
|
|
|
private void setup_stack() {
|
2019-01-27 14:24:58 +00:00
|
|
|
stack.add_named(box, "main");
|
2018-11-16 15:27:31 +00:00
|
|
|
stack.add_named(welcome_placeholder, "welcome_placeholder");
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2018-11-16 15:27:31 +00:00
|
|
|
if (db.get_accounts().size == 0) {
|
|
|
|
stack.set_visible_child_name("welcome_placeholder");
|
|
|
|
} else {
|
|
|
|
stack.set_visible_child_name("accounts_placeholder");
|
2019-01-27 14:24:58 +00:00
|
|
|
}
|
|
|
|
if (Util.use_csd()) {
|
2018-11-16 15:27:31 +00:00
|
|
|
set_titlebar(placeholder_headerbar);
|
|
|
|
}
|
2017-03-20 21:12:20 +00:00
|
|
|
} else if (stream_interactor.get_module(ConversationManager.IDENTITY).get_active_conversations().size == 0) {
|
|
|
|
stack.set_visible_child_name("conversations_placeholder");
|
2019-01-27 14:24:58 +00:00
|
|
|
if (Util.use_csd()) {
|
|
|
|
set_titlebar(placeholder_headerbar);
|
|
|
|
}
|
2017-03-20 21:12:20 +00:00
|
|
|
} else {
|
2017-03-17 22:21:23 +00:00
|
|
|
stack.set_visible_child_name("main");
|
2019-01-27 14:24:58 +00:00
|
|
|
if (Util.use_csd()) {
|
|
|
|
set_titlebar(headerbar_paned);
|
|
|
|
}
|
2017-12-31 19:19:51 +00:00
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
2019-04-12 14:24:43 +00:00
|
|
|
|
2019-09-09 17:47:11 +00:00
|
|
|
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) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Don't forward / change focus on Control + ...
|
|
|
|
if ((event.state & ModifierType.CONTROL_MASK) > 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
chat_input.text_input.key_press_event(event);
|
|
|
|
chat_input.text_input.grab_focus();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-12 14:24:43 +00:00
|
|
|
public void loop_conversations(bool backwards) {
|
2019-04-12 15:43:47 +00:00
|
|
|
conversation_selector.loop_conversations(backwards);
|
2019-04-12 14:24:43 +00:00
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
}
|
|
|
|
|
2018-11-16 15:27:31 +00:00
|
|
|
public class WelcomePlceholder : UnifiedWindowPlaceholder {
|
|
|
|
public WelcomePlceholder() {
|
|
|
|
title_label.label = _("Welcome to Dino!");
|
2019-03-16 13:33:47 +00:00
|
|
|
label.label = "Communicating happiness.";
|
2019-01-06 17:31:40 +00:00
|
|
|
primary_button.label = _("Set up account");
|
2018-11-16 15:27:31 +00:00
|
|
|
title_label.visible = true;
|
|
|
|
secondary_button.visible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-20 21:12:20 +00:00
|
|
|
public class NoAccountsPlaceholder : UnifiedWindowPlaceholder {
|
|
|
|
public NoAccountsPlaceholder() {
|
2018-11-16 15:27:31 +00:00
|
|
|
title_label.label = _("No active accounts");
|
2017-04-07 09:09:47 +00:00
|
|
|
primary_button.label = _("Manage accounts");
|
2018-11-16 15:27:31 +00:00
|
|
|
title_label.visible = true;
|
|
|
|
label.visible = false;
|
2017-03-20 21:12:20 +00:00
|
|
|
secondary_button.visible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class NoConversationsPlaceholder : UnifiedWindowPlaceholder {
|
|
|
|
public NoConversationsPlaceholder() {
|
2018-11-16 15:27:31 +00:00
|
|
|
title_label.label = _("No active conversations");
|
2018-02-08 10:45:31 +00:00
|
|
|
primary_button.label = _("Start Conversation");
|
2018-04-30 21:11:58 +00:00
|
|
|
secondary_button.label = _("Join Channel");
|
2018-11-16 15:27:31 +00:00
|
|
|
title_label.visible = true;
|
|
|
|
label.visible = false;
|
2017-03-20 21:12:20 +00:00
|
|
|
secondary_button.visible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-03 18:42:15 +00:00
|
|
|
[GtkTemplate (ui = "/im/dino/Dino/unified_window_placeholder.ui")]
|
2017-03-17 22:21:23 +00:00
|
|
|
public class UnifiedWindowPlaceholder : Box {
|
2018-11-16 15:27:31 +00:00
|
|
|
[GtkChild] public Label title_label;
|
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-08-09 18:44:15 +00:00
|
|
|
}
|