aboutsummaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorfiaxh <git@lightrise.org>2020-02-21 03:04:15 +0100
committerfiaxh <git@lightrise.org>2020-02-22 02:58:36 +0100
commitd550fc905c79dccd51adb2d296140810ddc694fb (patch)
tree3676758f141d7a7ffabbf7ebb0562c259b4ad2ea /main
parent4ed6204fc2879c52fe88caa5711dea37cd4ae201 (diff)
downloaddino-d550fc905c79dccd51adb2d296140810ddc694fb.tar.gz
dino-d550fc905c79dccd51adb2d296140810ddc694fb.zip
Move UnifiedWindow stack state update logic into controller
Diffstat (limited to 'main')
-rw-r--r--main/src/ui/unified_window.vala41
-rw-r--r--main/src/ui/unified_window_controller.vala21
2 files changed, 41 insertions, 21 deletions
diff --git a/main/src/ui/unified_window.vala b/main/src/ui/unified_window.vala
index 1c57e7b7..50f57228 100644
--- a/main/src/ui/unified_window.vala
+++ b/main/src/ui/unified_window.vala
@@ -52,13 +52,6 @@ public class UnifiedWindow : Gtk.Window {
setup_stack();
paned.bind_property("position", headerbar_paned, "position", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
-
- stream_interactor.account_added.connect((account) => { check_stack(true); });
- stream_interactor.account_removed.connect((account) => { check_stack(); });
- stream_interactor.get_module(ConversationManager.IDENTITY).conversation_activated.connect(() => check_stack());
- stream_interactor.get_module(ConversationManager.IDENTITY).conversation_deactivated.connect(() => check_stack());
-
- check_stack();
}
private void setup_unified() {
@@ -113,32 +106,38 @@ public class UnifiedWindow : Gtk.Window {
add(stack);
}
- private void check_stack(bool know_exists = false) {
- ArrayList<Account> accounts = stream_interactor.get_accounts();
- if (!know_exists && accounts.size == 0) {
- if (db.get_accounts().size == 0) {
+ 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 {
+ } 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 (stream_interactor.get_module(ConversationManager.IDENTITY).get_active_conversations().size == 0) {
+ } 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);
}
- } else {
- 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);
- }
}
}
diff --git a/main/src/ui/unified_window_controller.vala b/main/src/ui/unified_window_controller.vala
index d580f8cc..ca958bf1 100644
--- a/main/src/ui/unified_window_controller.vala
+++ b/main/src/ui/unified_window_controller.vala
@@ -84,6 +84,12 @@ public class UnifiedWindowController : Object {
});
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) {
@@ -119,6 +125,21 @@ public class UnifiedWindowController : Object {
}
}
+ private void update_stack_state(bool know_exists = false) {
+ ArrayList<Account> 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_) {