[gnome-calendar] manager: Move GOA to GcalContext
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] manager: Move GOA to GcalContext
- Date: Thu, 25 Apr 2019 19:57:38 +0000 (UTC)
commit 1b8a29e59b641a564a3ab09e25d59ddbbf5e2a35
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Apr 24 14:27:11 2019 -0300
manager: Move GOA to GcalContext
Another step into making GcalManager only be responsible
for handling backend interactions.
src/gcal-context.c | 30 ++++++++++++++++++++++++++
src/gcal-context.h | 3 +++
src/gcal-manager.c | 56 +-----------------------------------------------
src/gcal-manager.h | 5 -----
src/gcal-source-dialog.c | 56 ++++++++----------------------------------------
5 files changed, 43 insertions(+), 107 deletions(-)
---
diff --git a/src/gcal-context.c b/src/gcal-context.c
index 0d3d7ba6..2685d01b 100644
--- a/src/gcal-context.c
+++ b/src/gcal-context.c
@@ -27,6 +27,7 @@ struct _GcalContext
GObject parent;
GcalClock *clock;
+ GoaClient *goa_client;
GcalManager *manager;
GSettings *settings;
GcalWeatherService *weather_service;
@@ -38,6 +39,7 @@ enum
{
PROP_0,
PROP_CLOCK,
+ PROP_GOA_CLIENT,
PROP_MANAGER,
PROP_SETTINGS,
PROP_WEATHER_SERVICE,
@@ -57,6 +59,7 @@ gcal_context_finalize (GObject *object)
GcalContext *self = (GcalContext *)object;
g_clear_object (&self->clock);
+ g_clear_object (&self->goa_client);
g_clear_object (&self->manager);
g_clear_object (&self->weather_service);
@@ -77,6 +80,10 @@ gcal_context_get_property (GObject *object,
g_value_set_object (value, self->clock);
break;
+ case PROP_GOA_CLIENT:
+ g_value_set_object (value, self->goa_client);
+ break;
+
case PROP_MANAGER:
g_value_set_object (value, self->manager);
break;
@@ -103,6 +110,7 @@ gcal_context_set_property (GObject *object,
switch (prop_id)
{
case PROP_CLOCK:
+ case PROP_GOA_CLIENT:
case PROP_MANAGER:
case PROP_SETTINGS:
case PROP_WEATHER_SERVICE:
@@ -126,6 +134,12 @@ gcal_context_class_init (GcalContextClass *klass)
GCAL_TYPE_CLOCK,
G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS);
+ properties[PROP_GOA_CLIENT] = g_param_spec_object ("goa-client",
+ "Online Accounts client",
+ "Online Accounts client",
+ GOA_TYPE_CLIENT,
+ G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY |
G_PARAM_STATIC_STRINGS);
+
properties[PROP_MANAGER] = g_param_spec_object ("manager",
"Data manager",
"Data manager of the application",
@@ -151,6 +165,7 @@ static void
gcal_context_init (GcalContext *self)
{
self->clock = gcal_clock_new ();
+ self->goa_client = goa_client_new_sync (NULL, NULL);
self->manager = gcal_manager_new ();
self->settings = g_settings_new ("org.gnome.calendar");
self->weather_service = gcal_weather_service_new ();
@@ -185,6 +200,21 @@ gcal_context_get_clock (GcalContext *self)
return self->clock;
}
+/**
+ * gcal_context_get_goa_client:
+ *
+ * Retrieves the #GoaClient from @self.
+ *
+ * Returns: (transfer none): a #GoaClient
+ */
+GoaClient*
+gcal_context_get_goa_client (GcalContext *self)
+{
+ g_return_val_if_fail (GCAL_IS_CONTEXT (self), NULL);
+
+ return self->goa_client;
+}
+
/**
* gcal_context_get_manager:
*
diff --git a/src/gcal-context.h b/src/gcal-context.h
index 5d1478f8..d8f884fe 100644
--- a/src/gcal-context.h
+++ b/src/gcal-context.h
@@ -25,6 +25,7 @@
#include "weather/gcal-weather-service.h"
#include <glib-object.h>
+#include <goa/goa.h>
G_BEGIN_DECLS
@@ -35,6 +36,8 @@ GcalContext* gcal_context_new (void);
GcalClock* gcal_context_get_clock (GcalContext *self);
+GoaClient* gcal_context_get_goa_client (GcalContext *self);
+
GcalManager* gcal_context_get_manager (GcalContext *self);
GSettings* gcal_context_get_settings (GcalContext *self);
diff --git a/src/gcal-manager.c b/src/gcal-manager.c
index 2d71c2c0..8951c746 100644
--- a/src/gcal-manager.c
+++ b/src/gcal-manager.c
@@ -88,10 +88,7 @@ struct _GcalManager
GCancellable *async_ops;
- GoaClient *goa_client;
-
/* state flags */
- gboolean goa_client_ready;
gint sources_at_launch;
/* timezone */
@@ -735,33 +732,6 @@ source_get_last_credentials_required_arguments_cb (GObject *source_object,
GCAL_EXIT;
}
-static void
-gcal_manager_client_ready_cb (GObject *source,
- GAsyncResult *result,
- gpointer user_data)
-{
- GcalManager *self = GCAL_MANAGER (user_data);
- GError *error = NULL;
-
- GCAL_ENTRY;
-
- self->goa_client = goa_client_new_finish (result, &error);
- self->goa_client_ready = TRUE;
-
- if (error != NULL)
- {
- g_warning ("%s: Error retrieving GoaClient: %s",
- G_STRFUNC,
- error->message);
-
- g_error_free (error);
- }
-
- g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LOADING]);
-
- GCAL_EXIT;
-}
-
static void
gcal_manager_finalize (GObject *object)
{
@@ -769,7 +739,6 @@ gcal_manager_finalize (GObject *object)
GCAL_ENTRY;
- g_clear_object (&self->goa_client);
g_clear_object (&self->e_data_model);
g_clear_object (&self->search_data_model);
g_clear_object (&self->shell_search_data_model);
@@ -1800,7 +1769,7 @@ gcal_manager_get_loading (GcalManager *self)
{
g_return_val_if_fail (GCAL_IS_MANAGER (self), FALSE);
- return !self->goa_client_ready || self->sources_at_launch > 0;
+ return self->sources_at_launch > 0;
}
/**
@@ -1856,24 +1825,6 @@ gcal_manager_get_event_from_shell_search (GcalManager *self,
GCAL_RETURN (new_event);
}
-/**
- * gcal_manager_get_goa_client:
- * @self: a #GcalManager
- *
- * Retrieves the #GoaClient connected by @self.
- *
- * Returns: (transfer none): a #GoaClient
- */
-GoaClient*
-gcal_manager_get_goa_client (GcalManager *self)
-{
- GCAL_ENTRY;
-
- g_return_val_if_fail (GCAL_IS_MANAGER (self), NULL);
-
- GCAL_RETURN (self->goa_client);
-}
-
void
gcal_manager_startup (GcalManager *self)
{
@@ -1886,11 +1837,6 @@ gcal_manager_startup (GcalManager *self)
self->clients = g_hash_table_new_full ((GHashFunc) e_source_hash, (GEqualFunc) e_source_equal,
g_object_unref, (GDestroyNotify) free_unit_data);
- /* load GOA client */
- goa_client_new (NULL, /* we won't really cancel it */
- (GAsyncReadyCallback) gcal_manager_client_ready_cb,
- self);
-
/* reading sources and schedule its connecting */
self->source_registry = e_source_registry_new_sync (NULL, &error);
diff --git a/src/gcal-manager.h b/src/gcal-manager.h
index 837b9c18..d5dc6bbe 100644
--- a/src/gcal-manager.h
+++ b/src/gcal-manager.h
@@ -23,7 +23,6 @@
#include "gcal-event.h"
#include <libical/icaltime.h>
-#include <goa/goa.h>
G_BEGIN_DECLS
@@ -104,10 +103,6 @@ GList* gcal_manager_get_events (GcalManager
gboolean gcal_manager_get_loading (GcalManager *self);
-/* Online Accounts */
-GoaClient* gcal_manager_get_goa_client (GcalManager *self);
-
-
/* GNOME Shell-related functions */
GcalEvent* gcal_manager_get_event_from_shell_search (GcalManager *self,
const gchar *uuid);
diff --git a/src/gcal-source-dialog.c b/src/gcal-source-dialog.c
index 34454267..ce118297 100644
--- a/src/gcal-source-dialog.c
+++ b/src/gcal-source-dialog.c
@@ -2035,69 +2035,31 @@ goa_account_removed_cb (GoaClient *client,
}
static void
-loading_changed_cb (GcalSourceDialog *dialog)
+setup_context (GcalSourceDialog *self)
{
+ g_autolist (GoaAccount) accounts = NULL;
GcalManager *manager;
GoaClient *client;
- GList *accounts, *l;
+ GList *l;
GCAL_ENTRY;
- g_return_if_fail (GCAL_IS_SOURCE_DIALOG (dialog));
-
- manager = gcal_context_get_manager (dialog->context);
-
- if (gcal_manager_get_loading (manager))
- {
- GCAL_TRACE_MSG ("Not loaded yet");
- GCAL_EXIT;
- return;
- }
-
/* Add already fetched accounts */
- client = gcal_manager_get_goa_client (manager);
+ client = gcal_context_get_goa_client (self->context);
accounts = goa_client_get_accounts (client);
for (l = accounts; l != NULL; l = l->next)
- add_goa_account (dialog, goa_object_get_account (l->data));
+ add_goa_account (self, goa_object_get_account (l->data));
/* Be ready to other accounts */
- 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 (manager, loading_changed_cb, dialog);
-
- g_list_free (accounts);
-
- GCAL_EXIT;
-}
-
-static void
-setup_context (GcalSourceDialog *self)
-{
- GcalManager *manager = gcal_context_get_manager (self->context);
-
- if (!gcal_manager_get_loading (manager))
- {
- GList *sources, *l;
-
- sources = gcal_manager_get_sources_connected (manager);
-
- for (l = sources; l != NULL; l = l->next)
- add_source (manager, l->data, is_source_enabled (l->data), self);
- }
- else
- {
- g_signal_connect_swapped (manager,
- "notify::loading",
- G_CALLBACK (loading_changed_cb),
- self);
- }
+ g_signal_connect (client, "account-added", G_CALLBACK (goa_account_added_cb), self);
+ g_signal_connect (client, "account-removed", G_CALLBACK (goa_account_removed_cb), self);
+ manager = gcal_context_get_manager (self->context);
g_signal_connect (manager, "source-added", G_CALLBACK (add_source), self);
g_signal_connect (manager, "source-removed", G_CALLBACK (remove_source), self);
+ GCAL_EXIT;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]