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);
|
|
|
|
|
|
|
|
public new string? title {
|
|
|
|
get {
|
|
|
|
return Util.use_csd() ? conversation_titlebar_csd.title : conversation_titlebar.title;
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
if (Util.use_csd()) {
|
|
|
|
conversation_titlebar_csd.title = value;
|
|
|
|
} else {
|
|
|
|
conversation_titlebar.title = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string? subtitle {
|
|
|
|
get {
|
|
|
|
return Util.use_csd() ? conversation_titlebar_csd.subtitle : conversation_titlebar.subtitle;
|
|
|
|
}
|
|
|
|
set {
|
2019-03-14 16:38:48 +00:00
|
|
|
string? new_subtitle = value == null ? null : (/\s+/).replace_literal(value, -1, 0, " ");
|
2019-01-27 14:24:58 +00:00
|
|
|
if (Util.use_csd()) {
|
2019-03-01 17:20:08 +00:00
|
|
|
conversation_titlebar_csd.subtitle = new_subtitle;
|
2019-01-27 14:24:58 +00:00
|
|
|
} else {
|
2019-03-01 17:20:08 +00:00
|
|
|
conversation_titlebar.subtitle = new_subtitle;
|
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;
|
|
|
|
public ConversationListTitlebar conversation_list_titlebar;
|
|
|
|
public ConversationListTitlebarCsd conversation_list_titlebar_csd;
|
|
|
|
public ConversationSelector.View filterable_conversation_list;
|
|
|
|
public ConversationSummary.ConversationView conversation_frame;
|
|
|
|
public ConversationTitlebar conversation_titlebar;
|
|
|
|
public ConversationTitlebarCsd conversation_titlebar_csd;
|
|
|
|
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();
|
|
|
|
setup_unified();
|
2017-03-20 21:12:20 +00:00
|
|
|
setup_stack();
|
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
|
|
|
paned.bind_property("position", headerbar_paned, "position", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
|
2017-03-02 14:37:32 +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);
|
2017-03-23 15:34:54 +00:00
|
|
|
|
|
|
|
|
2019-01-27 14:24:58 +00:00
|
|
|
}
|
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);
|
|
|
|
conversation_frame = ((ConversationSummary.ConversationView) builder.get_object("conversation_frame")).init(stream_interactor);
|
|
|
|
filterable_conversation_list = ((ConversationSelector.View) 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()) {
|
|
|
|
conversation_titlebar_csd = new ConversationTitlebarCsd(stream_interactor, this) { visible=true };
|
|
|
|
conversation_list_titlebar_csd = new ConversationListTitlebarCsd(stream_interactor, this) { visible=true };
|
|
|
|
headerbar_paned.pack1(conversation_list_titlebar_csd, false, false);
|
|
|
|
headerbar_paned.pack2(conversation_titlebar_csd, true, false);
|
|
|
|
|
|
|
|
// Distribute start/end decoration_layout buttons to left/right headerbar. Ensure app menu fallback.
|
|
|
|
Gtk.Settings? gtk_settings = Gtk.Settings.get_default();
|
|
|
|
if (gtk_settings != null) {
|
|
|
|
if (!gtk_settings.gtk_decoration_layout.contains("menu")) {
|
|
|
|
gtk_settings.gtk_decoration_layout = "menu:" + gtk_settings.gtk_decoration_layout;
|
|
|
|
}
|
|
|
|
string[] decoration_layout = gtk_settings.gtk_decoration_layout.split(":");
|
|
|
|
if (decoration_layout.length == 2) {
|
|
|
|
conversation_list_titlebar_csd.decoration_layout = decoration_layout[0] + ":";
|
|
|
|
conversation_titlebar_csd.decoration_layout = ":" + decoration_layout[1];
|
|
|
|
}
|
2017-04-04 17:55:24 +00:00
|
|
|
}
|
2019-01-27 14:24:58 +00:00
|
|
|
} else {
|
|
|
|
conversation_list_titlebar = new ConversationListTitlebar(stream_interactor, this) { visible=true };
|
|
|
|
conversation_titlebar = new ConversationTitlebar(stream_interactor) { visible=true };
|
|
|
|
headerbar_paned.pack1(conversation_list_titlebar, false, false);
|
|
|
|
headerbar_paned.pack2(conversation_titlebar, true, false);
|
|
|
|
|
|
|
|
box.add(headerbar_paned);
|
2017-04-04 17:55:24 +00:00
|
|
|
}
|
2017-03-17 22:21:23 +00:00
|
|
|
}
|
2017-03-02 14:37:32 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|