[gnome-calendar] manager: unify completion flags
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] manager: unify completion flags
- Date: Fri, 17 Mar 2017 15:48:27 +0000 (UTC)
commit be137fca02585acb9ea288176111038820e28783
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Fri Mar 17 12:45:40 2017 -0300
manager: unify completion flags
Instead of having a completion flag for GOA and calendars,
unify both of them and simplify some code.
src/gcal-manager.c | 97 +++++++++++++++++++-------------------
src/gcal-manager.h | 4 +-
src/gcal-shell-search-provider.c | 4 +-
src/gcal-source-dialog.c | 46 +++++++++++-------
src/gcal-window.c | 2 +-
5 files changed, 79 insertions(+), 74 deletions(-)
---
diff --git a/src/gcal-manager.c b/src/gcal-manager.c
index 892e14c..0b570f4 100644
--- a/src/gcal-manager.c
+++ b/src/gcal-manager.c
@@ -100,7 +100,9 @@ enum
{
PROP_0,
PROP_DEFAULT_CALENDAR,
+ PROP_LOADING,
PROP_SETTINGS,
+ NUM_PROPS
};
enum
@@ -109,13 +111,12 @@ enum
SOURCE_CHANGED,
SOURCE_REMOVED,
SOURCE_ENABLED,
- LOAD_COMPLETED,
QUERY_COMPLETED,
- GOA_CLIENT_READY,
NUM_SIGNALS
};
-static guint signals[NUM_SIGNALS] = { 0, };
+static guint signals[NUM_SIGNALS] = { 0, };
+static GParamSpec *properties[NUM_PROPS] = { NULL, };
/* -- start: threading related code provided by Milan Crha */
typedef struct {
@@ -346,8 +347,9 @@ on_client_connected (GObject *source_object,
source = e_client_get_source (E_CLIENT (source_object));
manager->sources_at_launch--;
+
if (manager->sources_at_launch == 0)
- g_signal_emit (user_data, signals[LOAD_COMPLETED], 0);
+ g_object_notify_by_pspec (G_OBJECT (manager), properties[PROP_LOADING]);
error = NULL;
client = E_CAL_CLIENT (e_cal_client_connect_finish (result, &error));
@@ -746,8 +748,6 @@ gcal_manager_client_ready_cb (GObject *source,
manager->goa_client = goa_client_new_finish (result, &error);
manager->goa_client_ready = TRUE;
- g_signal_emit (user_data, signals[GOA_CLIENT_READY], 0, manager->goa_client);
-
if (error != NULL)
{
g_warning ("%s: Error retrieving GoaClient: %s",
@@ -757,6 +757,8 @@ gcal_manager_client_ready_cb (GObject *source,
g_error_free (error);
}
+ g_object_notify_by_pspec (G_OBJECT (manager), properties[PROP_LOADING]);
+
GCAL_EXIT;
}
@@ -972,6 +974,10 @@ gcal_manager_get_property (GObject *object,
g_value_take_object (value, e_source_registry_ref_default_calendar (self->source_registry));
break;
+ case PROP_LOADING:
+ g_value_set_boolean (value, gcal_manager_get_loading (self));
+ break;
+
case PROP_SETTINGS:
g_value_set_object (value, self->settings);
return;
@@ -995,22 +1001,40 @@ gcal_manager_class_init (GcalManagerClass *klass)
object_class->set_property = gcal_manager_set_property;
object_class->get_property = gcal_manager_get_property;
- /* properties */
- g_object_class_install_property (object_class,
- PROP_DEFAULT_CALENDAR,
- g_param_spec_object ("default-calendar",
- "Default calendar",
- "The default calendar",
- E_TYPE_SOURCE,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (object_class,
- PROP_SETTINGS,
- g_param_spec_object ("settings",
- "Application settings",
- "The settings of the application passed down from
GcalApplication",
- G_TYPE_SETTINGS,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
+ /**
+ * GcalManager:default-calendar:
+ *
+ * The default calendar.
+ */
+ properties[PROP_DEFAULT_CALENDAR] = g_param_spec_object ("default-calendar",
+ "Default calendar",
+ "The default calendar",
+ E_TYPE_SOURCE,
+ G_PARAM_READWRITE);
+
+ /**
+ * GcalManager:loading:
+ *
+ * Whether the manager is loading or not.
+ */
+ properties[PROP_LOADING] = g_param_spec_boolean ("loading",
+ "Loading",
+ "Whether it's still loading or not",
+ TRUE,
+ G_PARAM_READABLE);
+
+ /**
+ * GcalManager:settings:
+ *
+ * The settings.
+ */
+ properties[PROP_SETTINGS] = g_param_spec_object ("settings",
+ "Application settings",
+ "The settings of the application passed down from
GcalApplication",
+ G_TYPE_SETTINGS,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+
+ g_object_class_install_properties (object_class, NUM_PROPS, properties);
/* signals */
signals[SOURCE_ADDED] = g_signal_new ("source-added",
@@ -1047,13 +1071,6 @@ gcal_manager_class_init (GcalManagerClass *klass)
E_TYPE_SOURCE,
G_TYPE_BOOLEAN);
- signals[LOAD_COMPLETED] = g_signal_new ("load-completed",
- GCAL_TYPE_MANAGER,
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, NULL,
- G_TYPE_NONE,
- 0);
-
signals[QUERY_COMPLETED] = g_signal_new ("query-completed",
GCAL_TYPE_MANAGER,
G_SIGNAL_RUN_LAST,
@@ -1061,14 +1078,6 @@ gcal_manager_class_init (GcalManagerClass *klass)
NULL, NULL, NULL,
G_TYPE_NONE,
0);
-
- signals[GOA_CLIENT_READY] = g_signal_new ("goa-client-ready",
- GCAL_TYPE_MANAGER,
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, NULL,
- G_TYPE_NONE,
- 1,
- GOA_TYPE_CLIENT);
}
static void
@@ -1805,11 +1814,11 @@ gcal_manager_get_events (GcalManager *manager,
}
gboolean
-gcal_manager_load_completed (GcalManager *self)
+gcal_manager_get_loading (GcalManager *self)
{
g_return_val_if_fail (GCAL_IS_MANAGER (self), FALSE);
- return self->sources_at_launch == 0;
+ return !self->goa_client_ready || self->sources_at_launch > 0;
}
GcalEvent*
@@ -1847,16 +1856,6 @@ gcal_manager_get_event_from_shell_search (GcalManager *manager,
GCAL_RETURN (new_event);
}
-gboolean
-gcal_manager_is_goa_client_ready (GcalManager *manager)
-{
- g_return_val_if_fail (GCAL_IS_MANAGER (manager), FALSE);
-
- GCAL_ENTRY;
-
- GCAL_RETURN (manager->goa_client_ready);
-}
-
GoaClient*
gcal_manager_get_goa_client (GcalManager *manager)
{
diff --git a/src/gcal-manager.h b/src/gcal-manager.h
index 507b2c3..a368546 100644
--- a/src/gcal-manager.h
+++ b/src/gcal-manager.h
@@ -104,11 +104,9 @@ GList* gcal_manager_get_events (GcalManager
icaltimetype *range_start,
icaltimetype *range_end);
-gboolean gcal_manager_load_completed (GcalManager *self);
+gboolean gcal_manager_get_loading (GcalManager *self);
/* Online Accounts */
-gboolean gcal_manager_is_goa_client_ready (GcalManager *manager);
-
GoaClient* gcal_manager_get_goa_client (GcalManager *manager);
diff --git a/src/gcal-shell-search-provider.c b/src/gcal-shell-search-provider.c
index 9e08a94..1fd0302 100644
--- a/src/gcal-shell-search-provider.c
+++ b/src/gcal-shell-search-provider.c
@@ -78,7 +78,7 @@ execute_search (GcalShellSearchProvider *search_provider)
priv = search_provider->priv;
- if (!gcal_manager_load_completed (priv->manager))
+ if (gcal_manager_get_loading (priv->manager))
return TRUE;
zone = gcal_manager_get_system_timezone (priv->manager);
@@ -151,7 +151,7 @@ schedule_search (GcalShellSearchProvider *search_provider,
priv->pending_search->invocation = g_object_ref (invocation);
priv->pending_search->terms = g_strdupv (terms);
- if (!gcal_manager_load_completed (priv->manager))
+ if (gcal_manager_get_loading (priv->manager))
{
priv->scheduled_search_id = g_timeout_add_seconds (1, (GSourceFunc) execute_search, search_provider);
return;
diff --git a/src/gcal-source-dialog.c b/src/gcal-source-dialog.c
index 67f1144..b92f098 100644
--- a/src/gcal-source-dialog.c
+++ b/src/gcal-source-dialog.c
@@ -16,8 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#define G_LOG_DOMAIN "GcaçSourceDialog"
+#define G_LOG_DOMAIN "GcalSourceDialog"
+#include "gcal-debug.h"
#include "gcal-source-dialog.h"
#include "gcal-utils.h"
@@ -2143,16 +2144,24 @@ goa_account_removed_cb (GoaClient *client,
}
static void
-goa_client_ready_cb (GcalSourceDialog *dialog,
- GoaClient *client,
- gpointer user_data)
+loading_changed_cb (GcalSourceDialog *dialog)
{
+ GoaClient *client;
GList *accounts, *l;
+ GCAL_ENTRY;
+
g_return_if_fail (GCAL_IS_SOURCE_DIALOG (dialog));
- g_return_if_fail (GOA_IS_CLIENT (client));
+
+ if (gcal_manager_get_loading (dialog->manager))
+ {
+ GCAL_TRACE_MSG ("Not loaded yet");
+ GCAL_EXIT;
+ return;
+ }
/* Add already fetched accounts */
+ client = gcal_manager_get_goa_client (dialog->manager);
accounts = goa_client_get_accounts (client);
for (l = accounts; l != NULL; l = l->next)
@@ -2162,7 +2171,12 @@ goa_client_ready_cb (GcalSourceDialog *dialog,
g_signal_connect (client, "account-added", G_CALLBACK (goa_account_added_cb), dialog);
g_signal_connect (client, "account-removed", G_CALLBACK (goa_account_removed_cb), dialog);
+ /* Once we loaded, no need to track it down again */
+ g_signal_handlers_disconnect_by_func (dialog->manager, loading_changed_cb, dialog);
+
g_list_free (accounts);
+
+ GCAL_EXIT;
}
/**
@@ -2179,20 +2193,7 @@ gcal_source_dialog_set_manager (GcalSourceDialog *dialog,
{
dialog->manager = manager;
- /*
- * If the GoaClient is already loaded, fetch the online accounts
- * directly. Otherwise, wait for it to be ready.
- */
- if (gcal_manager_is_goa_client_ready (manager))
- {
- goa_client_ready_cb (dialog, gcal_manager_get_goa_client (manager), NULL);
- }
- else
- {
- g_signal_connect_swapped (manager, "goa-client-ready", G_CALLBACK (goa_client_ready_cb), dialog);
- }
-
- if (gcal_manager_load_completed (dialog->manager))
+ if (!gcal_manager_get_loading (dialog->manager))
{
GList *sources, *l;
@@ -2201,6 +2202,13 @@ gcal_source_dialog_set_manager (GcalSourceDialog *dialog,
for (l = sources; l != NULL; l = l->next)
add_source (dialog->manager, l->data, gcal_manager_source_enabled (dialog->manager, l->data),
dialog);
}
+ else
+ {
+ g_signal_connect_swapped (manager,
+ "notify::loading",
+ G_CALLBACK (loading_changed_cb),
+ dialog);
+ }
g_signal_connect (dialog->manager, "source-added", G_CALLBACK (add_source), dialog);
g_signal_connect (dialog->manager, "source-removed", G_CALLBACK (remove_source), dialog);
diff --git a/src/gcal-window.c b/src/gcal-window.c
index 3e802d4..b2a03c4 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -1242,7 +1242,7 @@ gcal_window_constructed (GObject *object)
gtk_list_box_set_sort_func (GTK_LIST_BOX (window->calendar_listbox), (GtkListBoxSortFunc)
calendar_listbox_sort_func,
object, NULL);
- if (gcal_manager_load_completed (window->manager))
+ if (!gcal_manager_get_loading (window->manager))
{
GList *sources, *l;
sources = gcal_manager_get_sources_connected (window->manager);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]