[gnome-panel] clock: port to ECalClient



commit b70a3515176d6075d24a8b5da6dce13b93ecff0b
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun May 26 18:50:22 2019 +0300

    clock: port to ECalClient

 configure.ac                     |   2 +-
 modules/clock/calendar-client.c  | 179 ++++++++++++++-------------------------
 modules/clock/calendar-sources.c |  56 ++++++------
 3 files changed, 94 insertions(+), 143 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 33410bcdc..f8c2615c9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -117,7 +117,7 @@ GLIB_REQUIRED=2.45.3
 GTK_REQUIRED=3.22.0
 LIBWNCK_REQUIRED=3.4.6
 LIBGNOME_MENU_REQUIRED=3.7.90
-LIBECAL_REQUIRED=3.5.3
+LIBECAL_REQUIRED=3.8.0
 LIBEDATASERVER_REQUIRED=3.5.3
 LIBSYSTEMD_REQUIRED=230
 CAIRO_REQUIRED=1.0.0
diff --git a/modules/clock/calendar-client.c b/modules/clock/calendar-client.c
index b88cffd44..1ce4a6547 100644
--- a/modules/clock/calendar-client.c
+++ b/modules/clock/calendar-client.c
@@ -48,14 +48,14 @@ typedef struct _CalendarClientSource CalendarClientSource;
 
 struct _CalendarClientQuery
 {
-  ECalView   *view;
-  GHashTable *events;
+  ECalClientView *view;
+  GHashTable     *events;
 };
 
 struct _CalendarClientSource
 {
   CalendarClient      *client;
-  ECal                *source;
+  ECalClient          *source;
 
   CalendarClientQuery  completed_query;
   CalendarClientQuery  in_progress_query;
@@ -227,9 +227,9 @@ calendar_client_set_timezone (CalendarClient *client)
   list = calendar_sources_get_appointment_clients (client->priv->calendar_sources);
   for (link = list; link != NULL; link = g_list_next (link))
     {
-      ECal *cal = E_CAL (link->data);
+      ECalClient *cal = E_CAL_CLIENT (link->data);
 
-      e_cal_set_default_timezone (cal, client->priv->zone, NULL);
+      e_cal_client_set_default_timezone (cal, client->priv->zone);
     }
   g_list_free (list);
 }
@@ -242,46 +242,6 @@ calendar_client_timezone_changed_cb (GSettings      *calendar_settings,
   calendar_client_set_timezone (client);
 }
 
-static void
-cal_opened_cb (ECal                 *ecal,
-               ECalendarStatus       status,
-               CalendarClientSource *cl_source)
-{
-  ECalSourceType  s_type;
-  CalendarClient *client = cl_source->client;
-
-  s_type = e_cal_get_source_type (ecal);
-
-  if (status == E_CALENDAR_STATUS_BUSY &&
-      e_cal_get_load_state (ecal) == E_CAL_LOAD_NOT_LOADED)
-    {
-      e_cal_open_async (ecal, FALSE);
-      return;
-    }
-  
-  g_signal_handlers_disconnect_by_func (ecal, cal_opened_cb, cl_source);
-
-  if (status != E_CALENDAR_STATUS_OK)
-    {
-      if (s_type == E_CAL_SOURCE_TYPE_EVENT)
-        client->priv->appointment_sources = g_slist_remove (client->priv->appointment_sources,
-                                                            cl_source);
-      else
-        client->priv->task_sources = g_slist_remove (client->priv->task_sources,
-                                                     cl_source);
-
-      calendar_client_source_finalize (cl_source);
-      g_free (cl_source);
-
-      return;
-    }
-
-  if (s_type == E_CAL_SOURCE_TYPE_EVENT)
-    calendar_client_update_appointments (client);
-  else
-    calendar_client_update_tasks (client);
-}
-
 static void
 load_calendars (CalendarClient    *client,
                 CalendarEventType  type) 
@@ -303,17 +263,10 @@ load_calendars (CalendarClient    *client,
 
   for (l = clients; l != NULL; l = l->next)
     {
-      ECal *ecal;      
-      CalendarClientSource *cl_source = l->data;
-
-      ecal = cl_source->source;
-
-      if (e_cal_get_load_state (ecal) == E_CAL_LOAD_LOADED)
-        continue;
-
-      g_signal_connect (G_OBJECT (ecal), "cal_opened",
-                        G_CALLBACK (cal_opened_cb), cl_source);
-      e_cal_open_async (ecal, TRUE);
+      if (type == CALENDAR_EVENT_APPOINTMENT)
+        calendar_client_update_appointments (client);
+      else if (type == CALENDAR_EVENT_TASK)
+        calendar_client_update_tasks (client);
     }
 }
 
@@ -688,28 +641,28 @@ get_ical_priority (icalcomponent *ical)
 }
 
 static char *
-get_source_color (ECal *esource)
+get_source_color (ECalClient *esource)
 {
   ESource *source;
-  ECalSourceType source_type;
+  ECalClientSourceType source_type;
   ESourceSelectable *extension;
   const gchar *extension_name;
 
-  g_return_val_if_fail (E_IS_CAL (esource), NULL);
+  g_return_val_if_fail (E_IS_CAL_CLIENT (esource), NULL);
 
-  source = e_cal_get_source (esource);
-  source_type = e_cal_get_source_type (esource);
+  source = e_client_get_source (E_CLIENT (esource));
+  source_type = e_cal_client_get_source_type (esource);
 
   switch (source_type)
     {
-      case E_CAL_SOURCE_TYPE_EVENT:
+      case E_CAL_CLIENT_SOURCE_TYPE_EVENTS:
         extension_name = E_SOURCE_EXTENSION_CALENDAR;
         break;
-      case E_CAL_SOURCE_TYPE_TODO:
+      case E_CAL_CLIENT_SOURCE_TYPE_TASKS:
         extension_name = E_SOURCE_EXTENSION_TASK_LIST;
         break;
-      case E_CAL_SOURCE_TYPE_JOURNAL:
-      case E_CAL_SOURCE_TYPE_LAST:
+      case E_CAL_CLIENT_SOURCE_TYPE_MEMOS:
+      case E_CAL_CLIENT_SOURCE_TYPE_LAST:
       default:
         g_return_val_if_reached (NULL);
     }
@@ -720,28 +673,28 @@ get_source_color (ECal *esource)
 }
 
 static gchar *
-get_source_backend_name (ECal *esource)
+get_source_backend_name (ECalClient *esource)
 {
   ESource *source;
-  ECalSourceType source_type;
+  ECalClientSourceType source_type;
   ESourceBackend *extension;
   const gchar *extension_name;
 
-  g_return_val_if_fail (E_IS_CAL (esource), NULL);
+  g_return_val_if_fail (E_IS_CAL_CLIENT (esource), NULL);
 
-  source = e_cal_get_source (esource);
-  source_type = e_cal_get_source_type (esource);
+  source = e_client_get_source (E_CLIENT (esource));
+  source_type = e_cal_client_get_source_type (esource);
 
   switch (source_type)
     {
-      case E_CAL_SOURCE_TYPE_EVENT:
+      case E_CAL_CLIENT_SOURCE_TYPE_EVENTS:
         extension_name = E_SOURCE_EXTENSION_CALENDAR;
         break;
-      case E_CAL_SOURCE_TYPE_TODO:
+      case E_CAL_CLIENT_SOURCE_TYPE_TASKS:
         extension_name = E_SOURCE_EXTENSION_TASK_LIST;
         break;
-      case E_CAL_SOURCE_TYPE_JOURNAL:
-      case E_CAL_SOURCE_TYPE_LAST:
+      case E_CAL_CLIENT_SOURCE_TYPE_MEMOS:
+      case E_CAL_CLIENT_SOURCE_TYPE_LAST:
       default:
         g_return_val_if_reached (NULL);
     }
@@ -866,14 +819,14 @@ calendar_appointment_init (CalendarAppointment  *appointment,
 
 static icaltimezone *
 resolve_timezone_id (const char *tzid,
-                    ECal       *source)
+                     ECalClient *source)
 {
   icaltimezone *retval;
 
   retval = icaltimezone_get_builtin_timezone_from_tzid (tzid);
   if (!retval)
     {
-      e_cal_get_timezone (source, tzid, &retval, NULL);
+      e_cal_client_get_timezone_sync (source, tzid, &retval, NULL, NULL);
     }
 
   return retval;
@@ -899,10 +852,10 @@ calendar_appointment_collect_occurrence (ECalComponent  *component,
 
 static void
 calendar_appointment_generate_ocurrences (CalendarAppointment *appointment,
-                                         icalcomponent       *ical,
-                                         ECal                *source,
-                                         time_t               start,
-                                         time_t               end,
+                                          icalcomponent       *ical,
+                                          ECalClient          *source,
+                                          time_t               start,
+                                          time_t               end,
                                           icaltimezone        *default_zone)
 {
   ECalComponent *ecal;
@@ -1134,10 +1087,10 @@ calendar_event_equal (CalendarEvent *a,
 
 static void
 calendar_event_generate_ocurrences (CalendarEvent *event,
-                                   icalcomponent *ical,
-                                   ECal          *source,
-                                   time_t         start,
-                                   time_t         end,
+                                    icalcomponent *ical,
+                                    ECalClient    *source,
+                                    time_t         start,
+                                    time_t         end,
                                     icaltimezone  *default_zone)
 {
   if (event->type != CALENDAR_EVENT_APPOINTMENT)
@@ -1241,8 +1194,8 @@ calendar_event_debug_dump (CalendarEvent *event)
 
 static inline CalendarClientQuery *
 goddamn_this_is_crack (CalendarClientSource *source,
-                      ECalView             *view,
-                      gboolean             *emit_signal)
+                       ECalClientView       *view,
+                       gboolean             *emit_signal)
 {
   g_assert (view != NULL);
 
@@ -1266,19 +1219,18 @@ goddamn_this_is_crack (CalendarClientSource *source,
 
 static void
 calendar_client_handle_query_completed (CalendarClientSource *source,
-                                       ECalendarStatus       status,
-                                       ECalView             *view)
+                                        GError               *error,
+                                        ECalClientView       *view)
 {
   CalendarClientQuery *query;
 
   query = goddamn_this_is_crack (source, view, NULL);
   
-  dprintf ("Query %p completed: %s\n", query, e_cal_get_error_message (status));
+  dprintf ("Query %p completed", query);
 
-  if (status != E_CALENDAR_STATUS_OK)
+  if (error != NULL)
     {
-      g_warning ("Calendar query failed: %s\n",
-                e_cal_get_error_message (status));
+      g_warning ("Calendar query failed: %s", error->message);
       calendar_client_stop_query (source->client, source, query);
       return;
     }
@@ -1300,8 +1252,8 @@ calendar_client_handle_query_completed (CalendarClientSource *source,
 
 static void
 calendar_client_handle_query_result (CalendarClientSource *source,
-                                    GList                *objects,
-                                    ECalView             *view)
+                                     GList                *objects,
+                                     ECalClientView       *view)
 {
   CalendarClientQuery *query;
   CalendarClient      *client;
@@ -1396,8 +1348,8 @@ check_object_remove (gpointer key,
 
 static void
 calendar_client_handle_objects_removed (CalendarClientSource *source,
-                                       GList                *ids,
-                                       ECalView             *view)
+                                        GList                *ids,
+                                        ECalClientView       *view)
 {
   CalendarClientQuery *query;
   gboolean             emit_signal;
@@ -1485,13 +1437,14 @@ calendar_client_start_query (CalendarClient       *client,
                             CalendarClientSource *source,
                             const char           *query)
 {
-  ECalView *view = NULL;
-  GError   *error = NULL;
+  ECalClientView *view = NULL;
+  GError *error = NULL;
 
-  if (!e_cal_get_query (source->source, query, &view, &error))
+  if (!e_cal_client_get_view_sync (source->source, query, &view, NULL, &error))
     {
-      g_warning ("Error preparing the query: '%s': %s\n",
-                query, error->message);
+      g_warning ("Error preparing the query: '%s': %s",
+                 query, error->message);
+
       g_error_free (error);
       return;
     }
@@ -1520,11 +1473,11 @@ calendar_client_start_query (CalendarClient       *client,
   g_signal_connect_swapped (view, "objects-removed",
                            G_CALLBACK (calendar_client_handle_objects_removed),
                            source);
-  g_signal_connect_swapped (view, "view-done",
+  g_signal_connect_swapped (view, "complete",
                            G_CALLBACK (calendar_client_handle_query_completed),
                            source);
 
-  e_cal_view_start (view);
+  e_cal_client_view_start (view, NULL);
 }
 
 static void
@@ -1553,9 +1506,6 @@ calendar_client_update_appointments (CalendarClient *client)
   for (l = client->priv->appointment_sources; l; l = l->next)
     {
       CalendarClientSource *cs = l->data;
-                  
-      if (e_cal_get_load_state (cs->source) != E_CAL_LOAD_LOADED)  
-        continue;
 
       calendar_client_start_query (client, cs, query);
     }
@@ -1621,9 +1571,6 @@ calendar_client_update_tasks (CalendarClient *client)
     {
       CalendarClientSource *cs = l->data;
 
-      if (e_cal_get_load_state (cs->source) != E_CAL_LOAD_LOADED)  
-        continue;
-
       calendar_client_start_query (client, cs, query);
     }
 
@@ -1640,8 +1587,6 @@ calendar_client_source_finalize (CalendarClientSource *source)
   source->client = NULL;
 
   if (source->source) {
-    g_signal_handlers_disconnect_by_func (source->source,
-                                          cal_opened_cb, source);
     g_object_unref (source->source);
   }
   source->source = NULL;
@@ -1676,12 +1621,12 @@ calendar_client_update_sources_list (CalendarClient *client,
       CalendarClientSource  dummy_source;
       CalendarClientSource *new_source;
       GSList               *s;
-      ECal                 *esource = link->data;
+      ECalClient           *esource = link->data;
 
       dummy_source.source = esource;
 
       dprintf ("update_sources_list: adding client %s: ",
-              e_source_peek_uid (e_cal_get_source (esource)));
+              e_source_peek_uid (e_client_get_source (E_CLIENT (esource))));
 
       if ((s = g_slist_find_custom (sources,
                                    &dummy_source,
@@ -1708,7 +1653,7 @@ calendar_client_update_sources_list (CalendarClient *client,
       CalendarClientSource *source = l->data;
 
       dprintf ("Removing client %s from list\n",
-              e_source_peek_uid (e_cal_get_source (source->source)));
+              e_source_peek_uid (e_client_get_source (E_CLIENT (source->source))));
 
       calendar_client_source_finalize (source);
       g_free (source);
@@ -2069,7 +2014,7 @@ calendar_client_set_task_completed (CalendarClient *client,
                                    guint           percent_complete)
 {
   GSList              *l;
-  ECal                *esource;
+  ECalClient          *esource;
   icalcomponent       *ical;
   icalproperty        *prop;
   icalproperty_status  status;
@@ -2085,7 +2030,7 @@ calendar_client_set_task_completed (CalendarClient *client,
       CalendarClientSource *source = l->data;
 
       esource = source->source;
-      e_cal_get_object (esource, task_uid, NULL, &ical, NULL);
+      e_cal_client_get_object_sync (esource, task_uid, NULL, &ical, NULL, NULL);
       if (ical)
        break;
     }
@@ -2147,5 +2092,5 @@ calendar_client_set_task_completed (CalendarClient *client,
                                  icalproperty_new_status (status));
     }
 
-  e_cal_modify_object (esource, ical, CALOBJ_MOD_ALL, NULL);
+  e_cal_client_modify_object_sync (esource, ical, CALOBJ_MOD_ALL, NULL, NULL);
 }
diff --git a/modules/clock/calendar-sources.c b/modules/clock/calendar-sources.c
index 8973a66e9..bb7438533 100644
--- a/modules/clock/calendar-sources.c
+++ b/modules/clock/calendar-sources.c
@@ -46,22 +46,22 @@ typedef struct _CalendarSourceData CalendarSourceData;
 
 struct _ClientData
 {
-  ECal *client;
-  gulong backend_died_id;
+  ECalClient *client;
+  gulong      backend_died_id;
 };
 
 struct _CalendarSourceData
 {
-  ECalSourceType   source_type;
-  CalendarSources *sources;
-  guint            changed_signal;
+  ECalClientSourceType  source_type;
+  CalendarSources      *sources;
+  guint                 changed_signal;
 
   /* ESource -> EClient */
-  GHashTable      *clients;
+  GHashTable           *clients;
 
-  guint            timeout_id;
+  guint                 timeout_id;
 
-  guint            loaded : 1;
+  guint                 loaded : 1;
 };
 
 struct _CalendarSourcesPrivate
@@ -77,7 +77,7 @@ struct _CalendarSourcesPrivate
 
 static void calendar_sources_finalize   (GObject             *object);
 
-static void backend_died_cb (ECal *client, CalendarSourceData *source_data);
+static void backend_died_cb (EClient *client, CalendarSourceData *source_data);
 static void calendar_sources_registry_source_changed_cb (ESourceRegistry *registry,
                                                          ESource         *source,
                                                          CalendarSources *sources);
@@ -166,7 +166,7 @@ calendar_sources_init (CalendarSources *sources)
                                                        G_CALLBACK 
(calendar_sources_registry_source_removed_cb),
                                                        sources);
 
-  sources->priv->appointment_sources.source_type    = E_CAL_SOURCE_TYPE_EVENT;
+  sources->priv->appointment_sources.source_type    = E_CAL_CLIENT_SOURCE_TYPE_EVENTS;
   sources->priv->appointment_sources.sources        = sources;
   sources->priv->appointment_sources.changed_signal = signals [APPOINTMENT_SOURCES_CHANGED];
   sources->priv->appointment_sources.clients        = g_hash_table_new_full ((GHashFunc) e_source_hash,
@@ -175,7 +175,7 @@ calendar_sources_init (CalendarSources *sources)
                                                                              (GDestroyNotify) 
client_data_free);
   sources->priv->appointment_sources.timeout_id     = 0;
 
-  sources->priv->task_sources.source_type    = E_CAL_SOURCE_TYPE_TODO;
+  sources->priv->task_sources.source_type    = E_CAL_CLIENT_SOURCE_TYPE_TASKS;
   sources->priv->task_sources.sources        = sources;
   sources->priv->task_sources.changed_signal = signals [TASK_SOURCES_CHANGED];
   sources->priv->task_sources.clients        = g_hash_table_new_full ((GHashFunc) e_source_hash,
@@ -244,26 +244,32 @@ calendar_sources_get (void)
 
 /* The clients are just created here but not loaded */
 static void
-create_client_for_source (ESource            *source,
-                         ECalSourceType      source_type,
-                         CalendarSourceData *source_data)
+create_client_for_source (ESource              *source,
+                          ECalClientSourceType  source_type,
+                          CalendarSourceData   *source_data)
 {
   ClientData *data;
-  ECal *client;
+  GError *error;
+  EClient *client;
 
   client = g_hash_table_lookup (source_data->clients, source);
   g_return_if_fail (client == NULL);
 
-  client = e_cal_new (source, source_type);
+  error = NULL;
+  client = e_cal_client_connect_sync (source, source_type, -1, NULL, &error);
+
   if (!client)
     {
-      g_warning ("Could not load source '%s'\n",
-                e_source_get_uid (source));
+      g_warning ("Could not load source '%s': %s",
+                 e_source_get_uid (source),
+                 error->message);
+
+      g_clear_error (&error);
       return;
     }
 
   data = g_slice_new0 (ClientData);
-  data->client = client;  /* takes ownership */
+  data->client = E_CAL_CLIENT (client); /* takes ownership */
   data->backend_died_id = g_signal_connect (client,
                                             "backend-died",
                                             G_CALLBACK (backend_died_cb),
@@ -311,12 +317,12 @@ backend_restart (gpointer data)
 }
 
 static void
-backend_died_cb (ECal *client, CalendarSourceData *source_data)
+backend_died_cb (EClient *client, CalendarSourceData *source_data)
 {
   ESource *source;
   const char *display_name;
 
-  source = e_cal_get_source (client);
+  source = e_client_get_source (client);
   display_name = e_source_get_display_name (source);
   g_warning ("The calendar backend for '%s' has crashed.", display_name);
   g_hash_table_remove (source_data->clients, source);
@@ -340,14 +346,14 @@ calendar_sources_load_esource_list (ESourceRegistry *registry,
 
   switch (source_data->source_type)
     {
-      case E_CAL_SOURCE_TYPE_EVENT:
+      case E_CAL_CLIENT_SOURCE_TYPE_EVENTS:
         extension_name = E_SOURCE_EXTENSION_CALENDAR;
         break;
-      case E_CAL_SOURCE_TYPE_TODO:
+      case E_CAL_CLIENT_SOURCE_TYPE_TASKS:
         extension_name = E_SOURCE_EXTENSION_TASK_LIST;
         break;
-      case E_CAL_SOURCE_TYPE_JOURNAL:
-      case E_CAL_SOURCE_TYPE_LAST:
+      case E_CAL_CLIENT_SOURCE_TYPE_MEMOS:
+      case E_CAL_CLIENT_SOURCE_TYPE_LAST:
       default:
         g_return_if_reached ();
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]