From f282ef68a44d6b1924869160b4ddcb88d8d8e715 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Fri, 21 Feb 2020 03:06:27 +0100 Subject: Rename UnifiedWindow -> MainWindow --- main/src/ui/application.vala | 8 +- main/src/ui/main_window.vala | 237 +++++++++++++++++++++++++++++ main/src/ui/main_window_controller.vala | 163 ++++++++++++++++++++ main/src/ui/unified_window.vala | 237 ----------------------------- main/src/ui/unified_window_controller.vala | 163 -------------------- 5 files changed, 404 insertions(+), 404 deletions(-) create mode 100644 main/src/ui/main_window.vala create mode 100644 main/src/ui/main_window_controller.vala delete mode 100644 main/src/ui/unified_window.vala delete mode 100644 main/src/ui/unified_window_controller.vala (limited to 'main/src') diff --git a/main/src/ui/application.vala b/main/src/ui/application.vala index 2b4b2d3e..9b6763fa 100644 --- a/main/src/ui/application.vala +++ b/main/src/ui/application.vala @@ -6,8 +6,8 @@ using Xmpp; public class Dino.Ui.Application : Gtk.Application, Dino.Application { private Notifications notifications; - private UnifiedWindow window; - public UnifiedWindowController controller; + private MainWindow window; + public MainWindowController controller; public Database db { get; set; } public Dino.Entities.Settings settings { get; set; } @@ -35,9 +35,9 @@ public class Dino.Ui.Application : Gtk.Application, Dino.Application { activate.connect(() => { if (window == null) { - controller = new UnifiedWindowController(this, stream_interactor, db); + controller = new MainWindowController(this, stream_interactor, db); config = new Config(db); - window = new UnifiedWindow(this, stream_interactor, db, config); + window = new MainWindow(this, stream_interactor, db, config); controller.set_window(window); if ((get_flags() & ApplicationFlags.IS_SERVICE) == ApplicationFlags.IS_SERVICE) window.delete_event.connect(window.hide_on_delete); diff --git a/main/src/ui/main_window.vala b/main/src/ui/main_window.vala new file mode 100644 index 00000000..afa16645 --- /dev/null +++ b/main/src/ui/main_window.vala @@ -0,0 +1,237 @@ +using Gee; +using Gdk; +using Gtk; + +using Dino.Entities; + +namespace Dino.Ui { + +public class MainWindow : Gtk.Window { + + public signal void conversation_selected(Conversation conversation); + + public new string? title { get; set; } + public string? subtitle { get; set; } + + 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 ConversationView conversation_view; + public ConversationSelector conversation_selector; + public ConversationTitlebar conversation_titlebar; + public ConversationTitlebarCsd conversation_titlebar_csd; + public ConversationListTitlebarCsd conversation_list_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 search_revealer; + public SearchEntry search_entry; + public GlobalSearch search_box; + private Stack stack = new Stack() { visible=true }; + private Stack left_stack; + private Stack right_stack; + + private StreamInteractor stream_interactor; + private Database db; + private Config config; + + public MainWindow(Application application, StreamInteractor stream_interactor, Database db, Config config) { + Object(application : application); + this.stream_interactor = stream_interactor; + this.db = db; + this.config = config; + + restore_window_size(); + + this.get_style_context().add_class("dino-main"); + setup_headerbar(); + Gtk.Settings.get_default().notify["gtk-decoration-layout"].connect(set_window_buttons); + this.realize.connect(set_window_buttons); + setup_unified(); + setup_stack(); + + paned.bind_property("position", headerbar_paned, "position", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); + } + + private void setup_unified() { + Builder builder = new Builder.from_resource("/im/dino/Dino/unified_main_content.ui"); + paned = (Paned) builder.get_object("paned"); + box.add(paned); + left_stack = (Stack) builder.get_object("left_stack"); + right_stack = (Stack) builder.get_object("right_stack"); + conversation_view = (ConversationView) builder.get_object("conversation_view"); + conversation_selector = ((ConversationSelector) builder.get_object("conversation_list")).init(stream_interactor); + search_box = ((GlobalSearch) builder.get_object("search_box")).init(stream_interactor); + search_revealer = (Revealer) builder.get_object("search_revealer"); + search_entry = (SearchEntry) builder.get_object("search_entry"); + Image conversation_list_placeholder_image = (Image) builder.get_object("conversation_list_placeholder_image"); + conversation_list_placeholder_image.set_from_pixbuf(new Pixbuf.from_resource("/im/dino/Dino/icons/dino-conversation-list-placeholder-arrow.svg")); + } + + private void setup_headerbar() { + if (Util.use_csd()) { + conversation_list_titlebar_csd = new ConversationListTitlebarCsd() { visible=true }; + headerbar_paned.pack1(conversation_list_titlebar_csd, false, false); + + conversation_titlebar_csd = new ConversationTitlebarCsd() { visible=true }; + conversation_titlebar = conversation_titlebar_csd; + headerbar_paned.pack2(conversation_titlebar_csd, true, false); + } else { + ConversationListTitlebar conversation_list_titlebar = new ConversationListTitlebar() { visible=true }; + headerbar_paned.pack1(conversation_list_titlebar, false, false); + + conversation_titlebar = new ConversationTitlebarNoCsd() { visible=true }; + headerbar_paned.pack2(conversation_titlebar, true, false); + + box.add(headerbar_paned); + } + } + + 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] : ""); + } + + private void setup_stack() { + stack.add_named(box, "main"); + stack.add_named(welcome_placeholder, "welcome_placeholder"); + stack.add_named(accounts_placeholder, "accounts_placeholder"); + stack.add_named(conversations_placeholder, "conversations_placeholder"); + add(stack); + } + + public enum StackState { + CLEAN_START, + NO_ACTIVE_ACCOUNTS, + NO_ACTIVE_CONVERSATIONS, + CONVERSATION + } + + public void set_stack_state(StackState stack_state) { + if (stack_state == StackState.CONVERSATION) { + left_stack.set_visible_child_name("content"); + right_stack.set_visible_child_name("content"); + + stack.set_visible_child_name("main"); + if (Util.use_csd()) { + set_titlebar(headerbar_paned); + } + } else if (stack_state == StackState.CLEAN_START || stack_state == StackState.NO_ACTIVE_ACCOUNTS) { + if (stack_state == StackState.CLEAN_START) { + stack.set_visible_child_name("welcome_placeholder"); + } else if (stack_state == StackState.NO_ACTIVE_ACCOUNTS) { + stack.set_visible_child_name("accounts_placeholder"); + } + if (Util.use_csd()) { + set_titlebar(placeholder_headerbar); + } + } else if (stack_state == StackState.NO_ACTIVE_CONVERSATIONS) { + stack.set_visible_child_name("main"); + left_stack.set_visible_child_name("placeholder"); + right_stack.set_visible_child_name("placeholder"); + if (Util.use_csd()) { + set_titlebar(headerbar_paned); + } + } + } + + public void loop_conversations(bool backwards) { + conversation_selector.loop_conversations(backwards); + } + + public void restore_window_size() { + Gdk.Display? display = Gdk.Display.get_default(); + if (display != null) { + Gdk.Monitor? monitor = display.get_primary_monitor(); + if (monitor == null) { + monitor = display.get_monitor_at_point(1, 1); + } + + if (monitor != null && + config.window_width <= monitor.geometry.width && + config.window_height <= monitor.geometry.height) { + set_default_size(config.window_width, config.window_height); + } + } + this.window_position = Gtk.WindowPosition.CENTER; + if (config.window_maximize) { + maximize(); + } + + this.delete_event.connect(() => { + save_window_size(); + config.window_maximize = this.is_maximized; + return false; + }); + } + + public void save_window_size() { + if (this.is_maximized) return; + + Gdk.Display? display = get_display(); + Gdk.Window? window = get_window(); + if (display != null && window != null) { + Gdk.Monitor monitor = display.get_monitor_at_window(window); + + int width = 0; + int height = 0; + get_size(out width, out height); + + + // Only store if the values have changed and are reasonable-looking. + if (config.window_width != width && width > 0 && width <= monitor.geometry.width) { + config.window_width = width; + } + if (config.window_height != height && height > 0 && height <= monitor.geometry.height) { + config.window_height = height; + } + } + } +} + +public class WelcomePlceholder : MainWindowPlaceholder { + public WelcomePlceholder() { + title_label.label = _("Welcome to Dino!"); + label.label = _("Sign in or create an account to get started."); + primary_button.label = _("Set up account"); + title_label.visible = true; + secondary_button.visible = false; + } +} + +public class NoAccountsPlaceholder : MainWindowPlaceholder { + public NoAccountsPlaceholder() { + title_label.label = _("No active accounts"); + primary_button.label = _("Manage accounts"); + title_label.visible = true; + label.visible = false; + secondary_button.visible = false; + } +} + +public class NoConversationsPlaceholder : MainWindowPlaceholder { + public NoConversationsPlaceholder() { + title_label.label = _("No active conversations"); + primary_button.label = _("Start Conversation"); + secondary_button.label = _("Join Channel"); + title_label.visible = true; + label.visible = false; + secondary_button.visible = true; + } +} + +[GtkTemplate (ui = "/im/dino/Dino/unified_window_placeholder.ui")] +public class MainWindowPlaceholder : Box { + [GtkChild] public Label title_label; + [GtkChild] public Label label; + [GtkChild] public Button primary_button; + [GtkChild] public Button secondary_button; +} + +} diff --git a/main/src/ui/main_window_controller.vala b/main/src/ui/main_window_controller.vala new file mode 100644 index 00000000..3107527d --- /dev/null +++ b/main/src/ui/main_window_controller.vala @@ -0,0 +1,163 @@ +using Gee; +using Gdk; +using Gtk; + +using Dino.Entities; + +namespace Dino.Ui { + +public class MainWindowController : Object { + + private StreamInteractor stream_interactor; + private Conversation? conversation; + private Application app; + private Database db; + private MainWindow window; + + private ConversationViewController conversation_view_controller; + + public MainWindowController(Application application, StreamInteractor stream_interactor, Database db) { + this.app = application; + this.stream_interactor = stream_interactor; + this.db = db; + + stream_interactor.get_module(ConversationManager.IDENTITY).conversation_deactivated.connect(check_unset_conversation); + stream_interactor.account_removed.connect(check_unset_conversation); + } + + public void set_window(MainWindow window) { + this.window = window; + + this.conversation_view_controller = new ConversationViewController(window.conversation_view, window.conversation_titlebar, stream_interactor); + + conversation_view_controller.search_menu_entry.search_button.bind_property("active", window.search_revealer, "reveal_child"); + + window.search_revealer.notify["child-revealed"].connect(() => { + if (window.search_revealer.child_revealed) { + if (window.conversation_view.conversation_frame.conversation != null && window.search_box.search_entry.text == "") { + reset_search_entry(); + } + window.search_box.search_entry.grab_focus_without_selecting(); + window.search_box.search_entry.set_position((int)window.search_box.search_entry.text_length); + } + }); + window.search_box.selected_item.connect((item) => { + select_conversation(item.conversation, false, false); + window.conversation_view.conversation_frame.initialize_around_message(item.conversation, item); + close_search(); + }); + + window.welcome_placeholder.primary_button.clicked.connect(() => { + ManageAccounts.AddAccountDialog dialog = new ManageAccounts.AddAccountDialog(stream_interactor, db); + dialog.set_transient_for(app.get_active_window()); + dialog.present(); + }); + window.accounts_placeholder.primary_button.clicked.connect(() => { app.activate_action("accounts", null); }); + window.conversations_placeholder.primary_button.clicked.connect(() => { app.activate_action("add_chat", null); }); + window.conversations_placeholder.secondary_button.clicked.connect(() => { app.activate_action("add_conference", null); }); + window.conversation_selector.conversation_selected.connect((conversation) => select_conversation(conversation)); + + window.event.connect((event) => { + if (event.type == EventType.BUTTON_PRESS) { + int dest_x, dest_y; + bool ret = window.search_box.translate_coordinates(window, 0, 0, out dest_x, out dest_y); + int geometry_x, geometry_y, geometry_width, geometry_height; + window.get_window().get_geometry(out geometry_x, out geometry_y, out geometry_width, out geometry_height); + if (ret && event.button.x_root - geometry_x < dest_x || event.button.y_root - geometry_y < dest_y) { + close_search(); + } + } else if (event.type == EventType.KEY_RELEASE) { + if (event.key.keyval == Gdk.Key.Escape) { + close_search(); + } + } + return false; + }); + window.focus_in_event.connect(() => { + stream_interactor.get_module(ChatInteraction.IDENTITY).on_window_focus_in(conversation); + window.urgency_hint = false; + return false; + }); + window.focus_out_event.connect(() => { + stream_interactor.get_module(ChatInteraction.IDENTITY).on_window_focus_out(conversation); + return false; + }); + + window.conversation_selected.connect(conversation => select_conversation(conversation)); + + stream_interactor.account_added.connect((account) => { update_stack_state(true); }); + stream_interactor.account_removed.connect((account) => { update_stack_state(); }); + stream_interactor.get_module(ConversationManager.IDENTITY).conversation_activated.connect(() => update_stack_state()); + stream_interactor.get_module(ConversationManager.IDENTITY).conversation_deactivated.connect(() => update_stack_state()); + update_stack_state(); + } + + public void select_conversation(Conversation? conversation, bool do_reset_search = true, bool default_initialize_conversation = true) { + this.conversation = conversation; + + conversation_view_controller.select_conversation(conversation, default_initialize_conversation); + + stream_interactor.get_module(ChatInteraction.IDENTITY).on_conversation_selected(conversation); + conversation.active = true; // only for conversation_selected + window.conversation_selector.on_conversation_selected(conversation); // In case selection was not via ConversationSelector + + if (do_reset_search) { + reset_search_entry(); + } + } + + private void check_unset_conversation() { + if (stream_interactor.get_module(ConversationManager.IDENTITY).get_active_conversations().size == 0) { + unset_conversation(); + } + } + + private void unset_conversation() { + this.conversation = null; + + conversation_view_controller.unset_conversation(); + + foreach(var e in this.app.plugin_registry.conversation_titlebar_entries) { + Plugins.ConversationTitlebarWidget widget = e.get_widget(Plugins.WidgetType.GTK); + if (widget != null) { + widget.unset_conversation(); + } + } + } + + private void update_stack_state(bool know_exists = false) { + ArrayList accounts = stream_interactor.get_accounts(); + if (!know_exists && accounts.size == 0) { + if (db.get_accounts().size == 0) { + window.set_stack_state(MainWindow.StackState.CLEAN_START); + } else { + window.set_stack_state(MainWindow.StackState.NO_ACTIVE_ACCOUNTS); + } + } else if (stream_interactor.get_module(ConversationManager.IDENTITY).get_active_conversations().size == 0) { + window.set_stack_state(MainWindow.StackState.NO_ACTIVE_CONVERSATIONS); + } else { + window.set_stack_state(MainWindow.StackState.CONVERSATION); + } + } + + private void reset_search_entry() { + if (window.conversation_view.conversation_frame.conversation != null) { + switch (conversation.type_) { + case Conversation.Type.CHAT: + case Conversation.Type.GROUPCHAT_PM: + window.search_box.search_entry.text = @"with:$(conversation.counterpart) "; + break; + case Conversation.Type.GROUPCHAT: + window.search_box.search_entry.text = @"in:$(conversation.counterpart) "; + break; + } + } + } + + private void close_search() { + conversation_view_controller.search_menu_entry.search_button.active = false; + window.search_revealer.reveal_child = false; + } +} + +} diff --git a/main/src/ui/unified_window.vala b/main/src/ui/unified_window.vala deleted file mode 100644 index 50f57228..00000000 --- a/main/src/ui/unified_window.vala +++ /dev/null @@ -1,237 +0,0 @@ -using Gee; -using Gdk; -using Gtk; - -using Dino.Entities; - -namespace Dino.Ui { - -public class UnifiedWindow : Gtk.Window { - - public signal void conversation_selected(Conversation conversation); - - public new string? title { get; set; } - public string? subtitle { get; set; } - - 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 ConversationView conversation_view; - public ConversationSelector conversation_selector; - public ConversationTitlebar conversation_titlebar; - public ConversationTitlebarCsd conversation_titlebar_csd; - public ConversationListTitlebarCsd conversation_list_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 search_revealer; - public SearchEntry search_entry; - public GlobalSearch search_box; - private Stack stack = new Stack() { visible=true }; - private Stack left_stack; - private Stack right_stack; - - private StreamInteractor stream_interactor; - private Database db; - private Config config; - - public UnifiedWindow(Application application, StreamInteractor stream_interactor, Database db, Config config) { - Object(application : application); - this.stream_interactor = stream_interactor; - this.db = db; - this.config = config; - - restore_window_size(); - - this.get_style_context().add_class("dino-main"); - setup_headerbar(); - Gtk.Settings.get_default().notify["gtk-decoration-layout"].connect(set_window_buttons); - this.realize.connect(set_window_buttons); - setup_unified(); - setup_stack(); - - paned.bind_property("position", headerbar_paned, "position", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); - } - - private void setup_unified() { - Builder builder = new Builder.from_resource("/im/dino/Dino/unified_main_content.ui"); - paned = (Paned) builder.get_object("paned"); - box.add(paned); - left_stack = (Stack) builder.get_object("left_stack"); - right_stack = (Stack) builder.get_object("right_stack"); - conversation_view = (ConversationView) builder.get_object("conversation_view"); - conversation_selector = ((ConversationSelector) builder.get_object("conversation_list")).init(stream_interactor); - search_box = ((GlobalSearch) builder.get_object("search_box")).init(stream_interactor); - search_revealer = (Revealer) builder.get_object("search_revealer"); - search_entry = (SearchEntry) builder.get_object("search_entry"); - Image conversation_list_placeholder_image = (Image) builder.get_object("conversation_list_placeholder_image"); - conversation_list_placeholder_image.set_from_pixbuf(new Pixbuf.from_resource("/im/dino/Dino/icons/dino-conversation-list-placeholder-arrow.svg")); - } - - private void setup_headerbar() { - if (Util.use_csd()) { - conversation_list_titlebar_csd = new ConversationListTitlebarCsd() { visible=true }; - headerbar_paned.pack1(conversation_list_titlebar_csd, false, false); - - conversation_titlebar_csd = new ConversationTitlebarCsd() { visible=true }; - conversation_titlebar = conversation_titlebar_csd; - headerbar_paned.pack2(conversation_titlebar_csd, true, false); - } else { - ConversationListTitlebar conversation_list_titlebar = new ConversationListTitlebar() { visible=true }; - headerbar_paned.pack1(conversation_list_titlebar, false, false); - - conversation_titlebar = new ConversationTitlebarNoCsd() { visible=true }; - headerbar_paned.pack2(conversation_titlebar, true, false); - - box.add(headerbar_paned); - } - } - - 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] : ""); - } - - private void setup_stack() { - stack.add_named(box, "main"); - stack.add_named(welcome_placeholder, "welcome_placeholder"); - stack.add_named(accounts_placeholder, "accounts_placeholder"); - stack.add_named(conversations_placeholder, "conversations_placeholder"); - add(stack); - } - - public enum StackState { - CLEAN_START, - NO_ACTIVE_ACCOUNTS, - NO_ACTIVE_CONVERSATIONS, - CONVERSATION - } - - public void set_stack_state(StackState stack_state) { - if (stack_state == StackState.CONVERSATION) { - left_stack.set_visible_child_name("content"); - right_stack.set_visible_child_name("content"); - - stack.set_visible_child_name("main"); - if (Util.use_csd()) { - set_titlebar(headerbar_paned); - } - } else if (stack_state == StackState.CLEAN_START || stack_state == StackState.NO_ACTIVE_ACCOUNTS) { - if (stack_state == StackState.CLEAN_START) { - stack.set_visible_child_name("welcome_placeholder"); - } else if (stack_state == StackState.NO_ACTIVE_ACCOUNTS) { - stack.set_visible_child_name("accounts_placeholder"); - } - if (Util.use_csd()) { - set_titlebar(placeholder_headerbar); - } - } else if (stack_state == StackState.NO_ACTIVE_CONVERSATIONS) { - stack.set_visible_child_name("main"); - left_stack.set_visible_child_name("placeholder"); - right_stack.set_visible_child_name("placeholder"); - if (Util.use_csd()) { - set_titlebar(headerbar_paned); - } - } - } - - public void loop_conversations(bool backwards) { - conversation_selector.loop_conversations(backwards); - } - - public void restore_window_size() { - Gdk.Display? display = Gdk.Display.get_default(); - if (display != null) { - Gdk.Monitor? monitor = display.get_primary_monitor(); - if (monitor == null) { - monitor = display.get_monitor_at_point(1, 1); - } - - if (monitor != null && - config.window_width <= monitor.geometry.width && - config.window_height <= monitor.geometry.height) { - set_default_size(config.window_width, config.window_height); - } - } - this.window_position = Gtk.WindowPosition.CENTER; - if (config.window_maximize) { - maximize(); - } - - this.delete_event.connect(() => { - save_window_size(); - config.window_maximize = this.is_maximized; - return false; - }); - } - - public void save_window_size() { - if (this.is_maximized) return; - - Gdk.Display? display = get_display(); - Gdk.Window? window = get_window(); - if (display != null && window != null) { - Gdk.Monitor monitor = display.get_monitor_at_window(window); - - int width = 0; - int height = 0; - get_size(out width, out height); - - - // Only store if the values have changed and are reasonable-looking. - if (config.window_width != width && width > 0 && width <= monitor.geometry.width) { - config.window_width = width; - } - if (config.window_height != height && height > 0 && height <= monitor.geometry.height) { - config.window_height = height; - } - } - } -} - -public class WelcomePlceholder : UnifiedWindowPlaceholder { - public WelcomePlceholder() { - title_label.label = _("Welcome to Dino!"); - label.label = _("Sign in or create an account to get started."); - primary_button.label = _("Set up account"); - title_label.visible = true; - secondary_button.visible = false; - } -} - -public class NoAccountsPlaceholder : UnifiedWindowPlaceholder { - public NoAccountsPlaceholder() { - title_label.label = _("No active accounts"); - primary_button.label = _("Manage accounts"); - title_label.visible = true; - label.visible = false; - secondary_button.visible = false; - } -} - -public class NoConversationsPlaceholder : UnifiedWindowPlaceholder { - public NoConversationsPlaceholder() { - title_label.label = _("No active conversations"); - primary_button.label = _("Start Conversation"); - secondary_button.label = _("Join Channel"); - title_label.visible = true; - label.visible = false; - secondary_button.visible = true; - } -} - -[GtkTemplate (ui = "/im/dino/Dino/unified_window_placeholder.ui")] -public class UnifiedWindowPlaceholder : Box { - [GtkChild] public Label title_label; - [GtkChild] public Label label; - [GtkChild] public Button primary_button; - [GtkChild] public Button secondary_button; -} - -} diff --git a/main/src/ui/unified_window_controller.vala b/main/src/ui/unified_window_controller.vala deleted file mode 100644 index ca958bf1..00000000 --- a/main/src/ui/unified_window_controller.vala +++ /dev/null @@ -1,163 +0,0 @@ -using Gee; -using Gdk; -using Gtk; - -using Dino.Entities; - -namespace Dino.Ui { - -public class UnifiedWindowController : Object { - - private StreamInteractor stream_interactor; - private Conversation? conversation; - private Application app; - private Database db; - private UnifiedWindow window; - - private ConversationViewController conversation_view_controller; - - public UnifiedWindowController(Application application, StreamInteractor stream_interactor, Database db) { - this.app = application; - this.stream_interactor = stream_interactor; - this.db = db; - - stream_interactor.get_module(ConversationManager.IDENTITY).conversation_deactivated.connect(check_unset_conversation); - stream_interactor.account_removed.connect(check_unset_conversation); - } - - public void set_window(UnifiedWindow window) { - this.window = window; - - this.conversation_view_controller = new ConversationViewController(window.conversation_view, window.conversation_titlebar, stream_interactor); - - conversation_view_controller.search_menu_entry.search_button.bind_property("active", window.search_revealer, "reveal_child"); - - window.search_revealer.notify["child-revealed"].connect(() => { - if (window.search_revealer.child_revealed) { - if (window.conversation_view.conversation_frame.conversation != null && window.search_box.search_entry.text == "") { - reset_search_entry(); - } - window.search_box.search_entry.grab_focus_without_selecting(); - window.search_box.search_entry.set_position((int)window.search_box.search_entry.text_length); - } - }); - window.search_box.selected_item.connect((item) => { - select_conversation(item.conversation, false, false); - window.conversation_view.conversation_frame.initialize_around_message(item.conversation, item); - close_search(); - }); - - window.welcome_placeholder.primary_button.clicked.connect(() => { - ManageAccounts.AddAccountDialog dialog = new ManageAccounts.AddAccountDialog(stream_interactor, db); - dialog.set_transient_for(app.get_active_window()); - dialog.present(); - }); - window.accounts_placeholder.primary_button.clicked.connect(() => { app.activate_action("accounts", null); }); - window.conversations_placeholder.primary_button.clicked.connect(() => { app.activate_action("add_chat", null); }); - window.conversations_placeholder.secondary_button.clicked.connect(() => { app.activate_action("add_conference", null); }); - window.conversation_selector.conversation_selected.connect((conversation) => select_conversation(conversation)); - - window.event.connect((event) => { - if (event.type == EventType.BUTTON_PRESS) { - int dest_x, dest_y; - bool ret = window.search_box.translate_coordinates(window, 0, 0, out dest_x, out dest_y); - int geometry_x, geometry_y, geometry_width, geometry_height; - window.get_window().get_geometry(out geometry_x, out geometry_y, out geometry_width, out geometry_height); - if (ret && event.button.x_root - geometry_x < dest_x || event.button.y_root - geometry_y < dest_y) { - close_search(); - } - } else if (event.type == EventType.KEY_RELEASE) { - if (event.key.keyval == Gdk.Key.Escape) { - close_search(); - } - } - return false; - }); - window.focus_in_event.connect(() => { - stream_interactor.get_module(ChatInteraction.IDENTITY).on_window_focus_in(conversation); - window.urgency_hint = false; - return false; - }); - window.focus_out_event.connect(() => { - stream_interactor.get_module(ChatInteraction.IDENTITY).on_window_focus_out(conversation); - return false; - }); - - window.conversation_selected.connect(conversation => select_conversation(conversation)); - - stream_interactor.account_added.connect((account) => { update_stack_state(true); }); - stream_interactor.account_removed.connect((account) => { update_stack_state(); }); - stream_interactor.get_module(ConversationManager.IDENTITY).conversation_activated.connect(() => update_stack_state()); - stream_interactor.get_module(ConversationManager.IDENTITY).conversation_deactivated.connect(() => update_stack_state()); - update_stack_state(); - } - - public void select_conversation(Conversation? conversation, bool do_reset_search = true, bool default_initialize_conversation = true) { - this.conversation = conversation; - - conversation_view_controller.select_conversation(conversation, default_initialize_conversation); - - stream_interactor.get_module(ChatInteraction.IDENTITY).on_conversation_selected(conversation); - conversation.active = true; // only for conversation_selected - window.conversation_selector.on_conversation_selected(conversation); // In case selection was not via ConversationSelector - - if (do_reset_search) { - reset_search_entry(); - } - } - - private void check_unset_conversation() { - if (stream_interactor.get_module(ConversationManager.IDENTITY).get_active_conversations().size == 0) { - unset_conversation(); - } - } - - private void unset_conversation() { - this.conversation = null; - - conversation_view_controller.unset_conversation(); - - foreach(var e in this.app.plugin_registry.conversation_titlebar_entries) { - Plugins.ConversationTitlebarWidget widget = e.get_widget(Plugins.WidgetType.GTK); - if (widget != null) { - widget.unset_conversation(); - } - } - } - - private void update_stack_state(bool know_exists = false) { - ArrayList accounts = stream_interactor.get_accounts(); - if (!know_exists && accounts.size == 0) { - if (db.get_accounts().size == 0) { - window.set_stack_state(UnifiedWindow.StackState.CLEAN_START); - } else { - window.set_stack_state(UnifiedWindow.StackState.NO_ACTIVE_ACCOUNTS); - } - } else if (stream_interactor.get_module(ConversationManager.IDENTITY).get_active_conversations().size == 0) { - window.set_stack_state(UnifiedWindow.StackState.NO_ACTIVE_CONVERSATIONS); - } else { - window.set_stack_state(UnifiedWindow.StackState.CONVERSATION); - } - } - - private void reset_search_entry() { - if (window.conversation_view.conversation_frame.conversation != null) { - switch (conversation.type_) { - case Conversation.Type.CHAT: - case Conversation.Type.GROUPCHAT_PM: - window.search_box.search_entry.text = @"with:$(conversation.counterpart) "; - break; - case Conversation.Type.GROUPCHAT: - window.search_box.search_entry.text = @"in:$(conversation.counterpart) "; - break; - } - } - } - - private void close_search() { - conversation_view_controller.search_menu_entry.search_button.active = false; - window.search_revealer.reveal_child = false; - } -} - -} -- cgit v1.2.3-54-g00ecf