[gnome-contacts/wip/nielsdg/cleanup-app-code: 1/2] App: Cleanup the window creation code
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts/wip/nielsdg/cleanup-app-code: 1/2] App: Cleanup the window creation code
- Date: Fri, 5 Jun 2020 13:38:24 +0000 (UTC)
commit e99ece963e050488311bdde6aa3617c1fa87cca8
Author: Niels De Graef <nielsdegraef gmail com>
Date: Fri Jun 5 15:33:56 2020 +0200
App: Cleanup the window creation code
The current code that created a new window was a mess, and didn't really
say what or why we were doing things. This commit cleans up some of this
by renaming some variables and functions and making sure we always show
a window to the user, so that we can provide useful feedback.
src/contacts-app.vala | 117 ++++++++++++-----------------------------------
src/contacts-window.vala | 12 +++--
2 files changed, 39 insertions(+), 90 deletions(-)
---
diff --git a/src/contacts-app.vala b/src/contacts-app.vala
index 531d0e0..c08159b 100644
--- a/src/contacts-app.vala
+++ b/src/contacts-app.vala
@@ -24,9 +24,6 @@ public class Contacts.App : Gtk.Application {
private Window window;
- private bool is_prepare_scheluded = false;
- private bool is_quiescent_scheduled = false;
-
private const GLib.ActionEntry[] action_entries = {
{ "quit", quit },
{ "help", show_help },
@@ -198,69 +195,40 @@ public class Contacts.App : Gtk.Application {
window.show_search (query);
} else {
contacts_store.quiescent.connect_after (() => {
- window.show_search (query);
- });
+ window.show_search (query);
+ });
}
}
private void create_window () {
this.window = new Contacts.Window (this.settings, this, this.contacts_store);
- }
-
- private void schedule_window_creation () {
- /* window creation code is run after Store::prepare */
- hold ();
- ulong id = 0;
- uint id2 = 0;
- id = contacts_store.prepared.connect (() => {
- contacts_store.disconnect (id);
- Source.remove (id2);
- create_window ();
- window.show ();
-
- schedule_window_finish_ui ();
-
- release ();
- });
- // Wait at most 0.5 seconds to show the window
- id2 = Timeout.add (500, () => {
- contacts_store.disconnect (id);
-
- create_window ();
- window.show ();
-
- schedule_window_finish_ui ();
-
- release ();
- return false;
- });
-
- is_prepare_scheluded = true;
+ show_contact_list ();
}
- private void schedule_window_finish_ui () {
- /* make window swap spinner out and init Contacts.ListView */
- // We delay the initial show a tiny bit so most contacts are loaded when we show
- ulong id = 0;
- uint id2 = 0;
- id = contacts_store.quiescent.connect (() => {
- Source.remove (id2);
- contacts_store.disconnect (id);
-
- debug ("callign set_list_pane from quiescent.connect");
- window.set_list_pane ();
- });
- // Wait at most 0.5 seconds to show the window
- id2 = Timeout.add (500, () => {
- contacts_store.disconnect (id);
-
- debug ("callign set_list_pane from 500.timeout");
- window.set_list_pane ();
- return false;
- });
-
- is_quiescent_scheduled = true;
+ // We have to wait until our Store is quiescent before showing contacts.
+ // However, some backends can take quite a while to load (or even timeout),
+ // so make sure we also show something within a reasonable time frame.
+ private const int LOADING_TIMEOUT = 1; // in seconds
+
+ private void show_contact_list () {
+ uint timeout_id = 0;
+
+ // Happy flow callback
+ ulong quiescence_id = contacts_store.quiescent.connect (() => {
+ Source.remove (timeout_id);
+ debug ("Got quiescent in time. Showing contact list");
+ window.show_contact_list ();
+ });
+
+ // Timeout callback
+ timeout_id = Timeout.add_seconds (LOADING_TIMEOUT, () => {
+ contacts_store.disconnect (quiescence_id);
+
+ debug ("Didn't achieve quiescence in time! Showing contact list anyway");
+ window.show_contact_list ();
+ return false;
+ });
}
public override void startup () {
@@ -271,7 +239,7 @@ public class Contacts.App : Gtk.Application {
base.startup ();
load_styling ();
- create_actions ();
+ create_actions ();
}
private void create_actions () {
@@ -293,7 +261,7 @@ public class Contacts.App : Gtk.Application {
public override void activate () {
// Check if we've already done the setup process
if (this.settings.did_initial_setup)
- create_new_window ();
+ create_window ();
else
run_setup ();
}
@@ -312,38 +280,13 @@ public class Contacts.App : Gtk.Application {
this.settings.did_initial_setup = true;
change_book_action.set_enabled (true); // re-enable change-book action
- create_new_window ();
+ create_window ();
});
setup_window.show ();
}
- private void create_new_window () {
- /* window creation code */
- if (window == null) {
- if (!this.contacts_store.is_prepared) {
- if (!is_prepare_scheluded) {
- schedule_window_creation ();
- return;
- }
- }
-
- create_window ();
- window.show ();
- }
-
- if (this.contacts_store.is_quiescent) {
- debug ("callign set_list_pane cause store is already quiescent");
- window.set_list_pane ();
- } else if (!is_quiescent_scheduled) {
- schedule_window_finish_ui ();
- }
-
- if (window != null)
- window.present ();
- }
-
public void new_contact () {
- window.new_contact ();
+ this.window.new_contact ();
}
private void on_show_contact(SimpleAction action, Variant? param) {
diff --git a/src/contacts-window.vala b/src/contacts-window.vala
index ff980a6..aa73844 100644
--- a/src/contacts-window.vala
+++ b/src/contacts-window.vala
@@ -98,6 +98,7 @@ public class Contacts.Window : Gtk.ApplicationWindow {
Object (
application: app,
show_menubar: false,
+ visible: true,
store: contacts_store
);
@@ -187,9 +188,14 @@ public class Contacts.Window : Gtk.ApplicationWindow {
this.contact_pane_container.add (this.contact_pane);
}
- public void set_list_pane () {
- /* FIXME: if no contact is loaded per backend, I must place a sign
- * saying "import your contacts/add online account" */
+ /**
+ * This shows the contact list on the left. This needs to be called
+ * explicitly when contacts are loaded, as the original setup will
+ * only show a loading spinner.
+ */
+ public void show_contact_list () {
+ // FIXME: if no contact is loaded per backend, I must place a sign
+ // saying "import your contacts/add online account"
if (list_pane != null)
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]