From 582cc78edd35d7d3a9ab6ddc579919306a2325f5 Mon Sep 17 00:00:00 2001 From: fiaxh Date: Fri, 17 Mar 2017 23:21:23 +0100 Subject: [PATCH] "No accounts active, add?" stack in main view --- libdino/src/service/stream_interactor.vala | 2 + main/CMakeLists.txt | 2 +- main/data/unified_window.ui | 177 --------------------- main/data/unified_window_placeholder.ui | 50 ++++++ main/src/ui/application.vala | 17 +- main/src/ui/unified_window.vala | 102 ++++++++---- 6 files changed, 129 insertions(+), 221 deletions(-) delete mode 100644 main/data/unified_window.ui create mode 100644 main/data/unified_window_placeholder.ui diff --git a/libdino/src/service/stream_interactor.vala b/libdino/src/service/stream_interactor.vala index c085401a..f42eb41b 100644 --- a/libdino/src/service/stream_interactor.vala +++ b/libdino/src/service/stream_interactor.vala @@ -8,6 +8,7 @@ namespace Dino { public class StreamInteractor { public signal void account_added(Account account); + public signal void account_removed(Account account); public signal void stream_negotiated(Account account); public ModuleManager module_manager; @@ -29,6 +30,7 @@ public class StreamInteractor { public void disconnect(Account account) { connection_manager.disconnect(account); + account_removed(account); } public ArrayList get_accounts() { diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 79f4d205..db3e05cd 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -46,7 +46,7 @@ set(RESOURCE_LIST occupant_list.ui occupant_list_item.ui settings_dialog.ui - unified_window.ui + unified_window_placeholder.ui ) compile_gresources( diff --git a/main/data/unified_window.ui b/main/data/unified_window.ui deleted file mode 100644 index 5ae01493..00000000 --- a/main/data/unified_window.ui +++ /dev/null @@ -1,177 +0,0 @@ - - - - diff --git a/main/data/unified_window_placeholder.ui b/main/data/unified_window_placeholder.ui new file mode 100644 index 00000000..b22d6a11 --- /dev/null +++ b/main/data/unified_window_placeholder.ui @@ -0,0 +1,50 @@ + + + + \ No newline at end of file diff --git a/main/src/ui/application.vala b/main/src/ui/application.vala index 66fc0fd0..e6f01822 100644 --- a/main/src/ui/application.vala +++ b/main/src/ui/application.vala @@ -5,11 +5,7 @@ using Dino.Ui; public class Dino.Ui.Application : Dino.Application { private Notifications notifications; - private UnifiedWindow? window; - private ConversationSelector.View? filterable_conversation_list; - private ConversationSelector.List? conversation_list; - private ConversationSummary.View? conversation_frame; - private ChatInput? chat_input; + private UnifiedWindow window; public Application() throws Error { Notify.init("dino"); @@ -21,20 +17,11 @@ public class Dino.Ui.Application : Dino.Application { public override void activate() { create_set_app_menu(); - create_window(); + window = new UnifiedWindow(this, stream_interaction); window.show_all(); restore(); } - private void create_window() { - window = new UnifiedWindow(this, stream_interaction); - - filterable_conversation_list = window.filterable_conversation_list; - conversation_list = window.filterable_conversation_list.conversation_list; - conversation_frame = window.conversation_frame; - chat_input = window.chat_input; - } - private void show_accounts_window() { ManageAccounts.Dialog dialog = new ManageAccounts.Dialog(stream_interaction, db); dialog.set_transient_for(window); diff --git a/main/src/ui/unified_window.vala b/main/src/ui/unified_window.vala index 0f33450d..27240a58 100644 --- a/main/src/ui/unified_window.vala +++ b/main/src/ui/unified_window.vala @@ -1,3 +1,4 @@ +using Gee; using Gtk; using Dino.Entities; @@ -5,55 +6,95 @@ using Dino.Entities; namespace Dino.Ui { public class UnifiedWindow : Window { - public ChatInput chat_input; - public ConversationListTitlebar conversation_list_titlebar; - public ConversationSelector.View filterable_conversation_list; - public ConversationSummary.View conversation_frame; - public ConversationTitlebar conversation_titlebar; - public Paned paned; + + private UnifiedWindowPlaceholder main_placeholder = new UnifiedWindowPlaceholder(); + private ChatInput chat_input; + private ConversationListTitlebar conversation_list_titlebar; + private ConversationSelector.View filterable_conversation_list; + private ConversationSummary.View conversation_frame; + private ConversationTitlebar conversation_titlebar; + private Paned headerbar_paned = new Paned(Orientation.HORIZONTAL); + private Paned paned = new Paned(Orientation.HORIZONTAL); + private Stack headerbar_stack = new Stack(); + private Stack stack = new Stack(); private StreamInteractor stream_interactor; private Conversation? conversation; public UnifiedWindow(Application application, StreamInteractor stream_interactor) { - Object(application : application); + Object(application : application, default_width : 1200, default_height : 700); this.stream_interactor = stream_interactor; + + setup_headerbar(); + setup_unified(); + setup_stacks(); + + 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); + focus_in_event.connect(on_focus_in_event); focus_out_event.connect(on_focus_out_event); - default_width = 1200; - default_height = 700; + stream_interactor.account_added.connect((account) => { check_stack(true); }); + stream_interactor.account_removed.connect((account) => { check_stack(); }); + main_placeholder.no_accounts_add.clicked.connect(() => { get_application().activate_action("accounts", null); }); + filterable_conversation_list.conversation_list.conversation_selected.connect(on_conversation_selected); + conversation_list_titlebar.conversation_opened.connect(on_conversation_selected); + check_stack(); + } + + private void setup_unified() { chat_input = new ChatInput(stream_interactor); conversation_frame = new ConversationSummary.View(stream_interactor); - conversation_titlebar = new ConversationTitlebar(stream_interactor); - paned = new Paned(Orientation.HORIZONTAL); - paned.set_position(300); filterable_conversation_list = new ConversationSelector.View(stream_interactor); - conversation_list_titlebar = new ConversationListTitlebar(this, stream_interactor); - conversation_list_titlebar.search_button.bind_property("active", filterable_conversation_list.search_bar, "search-mode-enabled", - BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); - Grid grid = new Grid(); - grid.orientation = Orientation.VERTICAL; - Paned toolbar_paned = new Paned(Orientation.HORIZONTAL); - - add(paned); - paned.add1(filterable_conversation_list); - paned.add2(grid); + Grid grid = new Grid() { orientation=Orientation.VERTICAL }; grid.add(conversation_frame); grid.add(new Separator(Orientation.HORIZONTAL)); grid.add(chat_input); + paned.set_position(300); + paned.add1(filterable_conversation_list); + paned.add2(grid); + conversation_frame.show_all(); + } - toolbar_paned.add1(conversation_list_titlebar); - toolbar_paned.add2(conversation_titlebar); - paned.bind_property("position", toolbar_paned, "position", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL); - set_titlebar(toolbar_paned); + private void setup_headerbar() { + conversation_titlebar = new ConversationTitlebar(stream_interactor); + conversation_list_titlebar = new ConversationListTitlebar(this, stream_interactor); + headerbar_paned.add1(conversation_list_titlebar); + headerbar_paned.add2(conversation_titlebar); + } - filterable_conversation_list.conversation_list.conversation_selected.connect(on_conversation_selected); - conversation_list_titlebar.conversation_opened.connect(on_conversation_selected); + private void setup_stacks() { + stack.add_named(paned, "main"); + stack.add_named(main_placeholder, "placeholder"); + add(stack); + + headerbar_stack.add_named(headerbar_paned, "main"); + headerbar_stack.add_named(new HeaderBar() { title="Dino", show_close_button=true, visible=true}, "placeholder"); + set_titlebar(headerbar_stack); + } + + private void check_stack(bool know_exists = false) { + ArrayList accounts = stream_interactor.get_accounts(); + bool exists_active = know_exists; + foreach (Account account in accounts) { + if (account.enabled) { + exists_active = true; + break; + } + } + if (exists_active) { + stack.set_visible_child_name("main"); + headerbar_stack.set_visible_child_name("main"); + } else { + stack.set_visible_child_name("placeholder"); + headerbar_stack.set_visible_child_name("placeholder"); + } } private void on_conversation_selected(Conversation conversation) { @@ -78,4 +119,9 @@ public class UnifiedWindow : Window { } } +[GtkTemplate (ui = "/org/dino-im/unified_window_placeholder.ui")] +public class UnifiedWindowPlaceholder : Box { + [GtkChild] public Button no_accounts_add; +} + } \ No newline at end of file