[evolution-ews/wip/mcrha/soup3] Cover EEwsOofSettings



commit f31255c6ca9e419b4d6bbde2da53c433d79b9308
Author: Milan Crha <mcrha redhat com>
Date:   Thu Dec 16 10:44:58 2021 +0100

    Cover EEwsOofSettings

 src/EWS/common/e-ews-connection.c   | 338 +++++++++++++++++++-
 src/EWS/common/e-ews-connection.h   |  19 +-
 src/EWS/common/e-ews-oof-settings.c | 606 ++++++------------------------------
 src/EWS/common/e-ews-oof-settings.h |  15 +-
 4 files changed, 442 insertions(+), 536 deletions(-)
---
diff --git a/src/EWS/common/e-ews-connection.c b/src/EWS/common/e-ews-connection.c
index bc51494d..f5a70f7d 100644
--- a/src/EWS/common/e-ews-connection.c
+++ b/src/EWS/common/e-ews-connection.c
@@ -27,8 +27,7 @@
 #include "e-ews-item-change.h"
 #include "e-ews-debug.h"
 #include "e-ews-notification.h"
-
-#define d(x) x
+#include "e-ews-oof-settings.h"
 
 /* A chunk size limit when moving items in chunks. */
 #define EWS_MOVE_ITEMS_CHUNK_SIZE 500
@@ -4044,7 +4043,6 @@ e_ews_connection_sync_folder_items_sync (EEwsConnection *cnc,
        /* Max changes requested */
        e_ews_request_write_int_parameter (request, "MaxChangesReturned", "messages", max_entries);
 
-       /* Complete the footer and print the request */
        e_ews_request_write_footer (request);
 
        response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
@@ -4240,7 +4238,6 @@ e_ews_connection_find_folder_items_sync (EEwsConnection *cnc,
 
        e_soap_request_end_element (request);
 
-       /* Complete the footer and print the request */
        e_ews_request_write_footer (request);
 
        response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
@@ -5051,7 +5048,7 @@ e_ews_connection_create_items_sync (EEwsConnection *cnc,
 
        e_soap_request_end_element (request); /* Items */
 
-       e_ews_request_write_footer (request); /* CreateItem */
+       e_ews_request_write_footer (request);
 
        response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
 
@@ -9397,3 +9394,334 @@ e_ews_connection_convert_id_sync (EEwsConnection *cnc,
 
        return success;
 }
+
+static GDateTime *
+ews_oof_settings_string_to_date_time (const gchar *string)
+{
+       GDateTime *date_time = NULL;
+
+       if (string) {
+               GTimeZone *utc = g_time_zone_new_utc ();
+
+               date_time = g_date_time_new_from_iso8601 (string, utc);
+
+               g_time_zone_unref (utc);
+       }
+
+       return date_time;
+}
+
+static gchar *
+ews_oof_settings_text_from_html (gchar *html_text)
+{
+       gsize haystack_len;
+       gchar *plain_text;
+       gchar *start, *end;
+       gchar *ii, *jj;
+
+       g_return_val_if_fail (html_text != NULL, NULL);
+
+       haystack_len = strlen (html_text);
+       start = g_strstr_len (html_text, haystack_len, "<body");
+       end = g_strstr_len (html_text, haystack_len, "</body>");
+
+       /* Parse the status set by Outlook Web Access. */
+       if (g_strrstr (html_text, "BodyFragment") != NULL && start == NULL) {
+               start = html_text;
+               end = html_text + haystack_len;
+       }
+
+       /* Strip HTML tags. */
+       plain_text = jj = g_malloc (end - start);
+       for (ii = start; ii < end; ii++) {
+               if (*ii == '<') {
+                       while (*ii != '>')
+                               ii++;
+               } else {
+                       *jj++ = *ii;
+               }
+       }
+       *jj = '\0';
+
+       return plain_text;
+}
+
+static gboolean
+e_ews_process_get_user_oof_settings_response (EEwsConnection *cnc,
+                                             ESoapResponse *response,
+                                             EEwsOofSettings *oof_settings,
+                                             GError **error)
+{
+       ESoapParameter *param;
+       ESoapParameter *subparam;
+       ESoapParameter *subsubparam;
+       GDateTime *date_time;
+       gchar *string;
+       gchar *text;
+       GError *local_error = NULL;
+
+       param = e_soap_response_get_first_parameter_by_name (response, "ResponseMessage", &local_error);
+
+       /* Sanity check */
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
+
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
+       }
+
+       if (!ews_get_response_status (param, error))
+               return FALSE;
+
+       param = e_soap_response_get_first_parameter_by_name (response, "OofSettings", &local_error);
+
+       /* Sanity check */
+       g_return_val_if_fail (
+               (param != NULL && local_error == NULL) ||
+               (param == NULL && local_error != NULL), FALSE);
+
+       if (local_error) {
+               g_propagate_error (error, local_error);
+               return FALSE;
+       }
+
+       subparam = e_soap_parameter_get_first_child_by_name (param, "OofState");
+       string = e_soap_parameter_get_string_value (subparam);
+       if (g_strcmp0 (string, "Disabled") == 0)
+               e_ews_oof_settings_set_state (settings, E_EWS_OOF_STATE_DISABLED);
+       else if (g_strcmp0 (string, "Enabled") == 0)
+               e_ews_oof_settings_set_state (settings, E_EWS_OOF_STATE_ENABLED);
+       else if (g_strcmp0 (string, "Scheduled") == 0)
+               e_ews_oof_settings_set_state (settings, E_EWS_OOF_STATE_SCHEDULED);
+       g_free (string);
+
+       subparam = e_soap_parameter_get_first_child_by_name (param, "ExternalAudience");
+       string = e_soap_parameter_get_string_value (subparam);
+       if (g_strcmp0 (string, "None") == 0)
+               e_ews_oof_settings_set_external_audience (settings, E_EWS_EXTERNAL_AUDIENCE_NONE);
+       else if (g_strcmp0 (string, "Known") == 0)
+               e_ews_oof_settings_set_external_audience (settings, E_EWS_EXTERNAL_AUDIENCE_KNOWN);
+       else if (g_strcmp0 (string, "All") == 0)
+               e_ews_oof_settings_set_external_audience (settings, E_EWS_EXTERNAL_AUDIENCE_ALL);
+       g_free (string);
+
+       subparam = e_soap_parameter_get_first_child_by_name (param, "Duration");
+       subsubparam = e_soap_parameter_get_first_child_by_name (subparam, "StartTime");
+       string = e_soap_parameter_get_string_value (subsubparam);
+       date_time = ews_oof_settings_string_to_date_time (string);
+       if (date_time != NULL) {
+               e_ews_oof_settings_set_start_time (settings, date_time);
+               g_date_time_unref (date_time);
+       }
+       g_free (string);
+
+       subsubparam = e_soap_parameter_get_first_child_by_name (subparam, "EndTime");
+       string = e_soap_parameter_get_string_value (subsubparam);
+       date_time = ews_oof_settings_string_to_date_time (string);
+       if (date_time != NULL) {
+               e_ews_oof_settings_set_end_time (settings, date_time);
+               g_date_time_unref (date_time);
+       }
+       g_free (string);
+
+       subparam = e_soap_parameter_get_first_child_by_name (param, "InternalReply");
+       subsubparam = e_soap_parameter_get_first_child_by_name (subparam, "Message");
+       string = e_soap_parameter_get_string_value (subsubparam);
+       if (string == NULL)
+               text = NULL;
+       else if (g_strrstr (string, "</body>") != NULL)
+               text = ews_oof_settings_text_from_html (string);
+       else if (g_strrstr (string, "BodyFragment") != NULL)
+               text = ews_oof_settings_text_from_html (string);
+       else
+               text = g_strdup (string);
+       e_ews_oof_settings_set_internal_reply (settings, text ? text : "");
+       g_free (string);
+       g_free (text);
+
+       subparam = e_soap_parameter_get_first_child_by_name (param, "ExternalReply");
+       subsubparam = e_soap_parameter_get_first_child_by_name (subparam, "Message");
+       string = e_soap_parameter_get_string_value (subsubparam);
+       if (string == NULL)
+               text = NULL;
+       else if (g_strrstr (string, "</body>") != NULL)
+               text = ews_oof_settings_text_from_html (string);
+       else if (g_strrstr (string, "BodyFragment") != NULL)
+               text = ews_oof_settings_text_from_html (string);
+       else
+               text = g_strdup (string);
+       e_ews_oof_settings_set_external_reply (settings, text ? text : "");
+       g_free (string);
+       g_free (text);
+
+       return TRUE;
+}
+
+gboolean
+e_ews_connection_get_user_oof_settings_sync (EEwsConnection *cnc,
+                                            gint pri,
+                                            EEwsOofSettings *inout_oof_settings,
+                                            GCancellable *cancellable,
+                                            GError **error);
+{
+       ESoapRequest *request;
+       ESoapResponse *response;
+       gboolean success;
+
+       g_return_val_if_fail (cnc != NULL, FALSE);
+       g_return_val_if_fail (inout_oof_settings != NULL, FALSE);
+
+       request = e_ews_request_new_with_header (
+               cnc->priv->uri,
+               cnc->priv->impersonate_user,
+               "GetUserOofSettingsRequest",
+               NULL,
+               NULL,
+               cnc->priv->version,
+               E_EWS_EXCHANGE_2007_SP1,
+               FALSE);
+
+       e_soap_request_start_element (request, "Mailbox", NULL, NULL);
+       e_ews_request_write_string_parameter (request, "Address", NULL, e_ews_connection_get_mailbox (cnc));
+       e_soap_request_end_element (request);
+
+       e_ews_request_write_footer (request);
+
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
+
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
+
+       success = e_ews_process_get_user_oof_settings_response (cnc, response, out_converted_id, error);
+
+       g_clear_object (&request);
+       g_clear_object (&response);
+
+       if (!success)
+               g_clear_pointer (out_converted_id, g_free);
+
+       return success;
+}
+
+static gchar *
+ews_oof_settings_date_time_to_string (GDateTime *date_time)
+{
+       gchar *string = NULL;
+
+       if (date_time)
+               string = g_date_time_format_iso8601 (date_time);
+
+       return string;
+}
+
+gboolean
+e_ews_connection_set_user_oof_settings_sync (EEwsConnection *cnc,
+                                            gint pri,
+                                            EEwsOofState state,
+                                            EEwsExternalAudience external_audience,
+                                            const GDateTime *start_date,
+                                            const GDateTime *end_date,
+                                            const gchar *internal_reply,
+                                            const gchar *external_reply,
+                                            GCancellable *cancellable,
+                                            GError **error);
+{
+       ESoapRequest *request;
+       ESoapResponse *response;
+       gchar *start_time;
+       gchar *end_time;
+       gboolean success;
+
+       g_return_val_if_fail (cnc != NULL, FALSE);
+
+       request = e_ews_request_new_with_header (
+               cnc->priv->uri,
+               cnc->priv->impersonate_user,
+               "SetUserOofSettingsRequest",
+               NULL,
+               NULL,
+               cnc->priv->version,
+               E_EWS_EXCHANGE_2007_SP1,
+               FALSE);
+
+       e_soap_request_start_element (request, "Mailbox", NULL, NULL);
+       e_ews_request_write_string_parameter (request, "Address", NULL, e_ews_connection_get_mailbox (cnc));
+       e_soap_request_end_element (request);
+
+       e_soap_request_start_element (request, "UserOofSettings", NULL, NULL);
+
+       switch (state) {
+               default:
+                       g_warn_if_reached ();
+                       /* fall through */
+               case E_EWS_OOF_STATE_DISABLED:
+                       string = "Disabled";
+                       break;
+               case E_EWS_OOF_STATE_ENABLED:
+                       string = "Enabled";
+                       break;
+               case E_EWS_OOF_STATE_SCHEDULED:
+                       string = "Scheduled";
+                       break;
+       }
+
+       e_ews_request_write_string_parameter (request, "OofState", NULL, string);
+
+       switch (external_audience) {
+               default:
+                       g_warn_if_reached ();
+                       /* fall through */
+               case E_EWS_EXTERNAL_AUDIENCE_NONE:
+                       string = "None";
+                       break;
+               case E_EWS_EXTERNAL_AUDIENCE_KNOWN:
+                       string = "Known";
+                       break;
+               case E_EWS_EXTERNAL_AUDIENCE_ALL:
+                       string = "All";
+                       break;
+       }
+
+       e_ews_request_write_string_parameter (request, "ExternalAudience", NULL, string);
+
+       start_time = ews_oof_settings_date_time_to_string (start_date);
+       end_time = ews_oof_settings_date_time_to_string (end_date);
+
+       e_soap_request_start_element (request, "Duration", NULL, NULL);
+       e_ews_request_write_string_parameter (request, "StartTime", NULL, start_time);
+       e_ews_request_write_string_parameter (request, "EndTime", NULL, end_time);
+       e_soap_request_end_element (request);
+
+       g_free (start_time);
+       g_free (end_time);
+
+       e_soap_request_start_element (request, "InternalReply", NULL, NULL);
+       e_ews_request_write_string_parameter (request, "Message", NULL, internal_reply);
+       e_soap_request_end_element (request);
+
+       e_soap_request_start_element (request, "ExternalReply", NULL, NULL);
+       e_ews_request_write_string_parameter (request, "Message", NULL, external_reply);
+       e_soap_request_end_element (request);
+
+       e_soap_request_end_element (request); /* UserOofSettings */
+
+       e_ews_request_write_footer (request);
+
+       response = e_ews_connection_send_request_sync (cnc, request, cancellable, error);
+
+       if (!response) {
+               g_clear_object (&request);
+               return FALSE;
+       }
+
+       success = e_ews_process_generic_response (cnc, response, error);
+
+       g_clear_object (&request);
+       g_clear_object (&response);
+
+       return success;
+}
diff --git a/src/EWS/common/e-ews-connection.h b/src/EWS/common/e-ews-connection.h
index 97d9e5be..6776a0e6 100644
--- a/src/EWS/common/e-ews-connection.h
+++ b/src/EWS/common/e-ews-connection.h
@@ -20,6 +20,7 @@
 #include "ews-errors.h"
 #include "e-ews-folder.h"
 #include "e-ews-item.h"
+#include "e-ews-oof-settings.h"
 #include "camel-ews-settings.h"
 
 /* Standard GObject macros */
@@ -869,7 +870,23 @@ gboolean   e_ews_connection_convert_id_sync(EEwsConnection *cnc,
                                                 gchar **out_converted_id,
                                                 GCancellable *cancellable,
                                                 GError **error);
-
+gboolean       e_ews_connection_get_user_oof_settings_sync
+                                               (EEwsConnection *cnc,
+                                                gint pri,
+                                                EEwsOofSettings *inout_oof_settings, /* caller-allocates */
+                                                GCancellable *cancellable,
+                                                GError **error);
+gboolean       e_ews_connection_set_user_oof_settings_sync
+                                               (EEwsConnection *cnc,
+                                                gint pri,
+                                                EEwsOofState state,
+                                                EEwsExternalAudience external_audience,
+                                                const GDateTime *date_start,
+                                                const GDateTime *date_end,
+                                                const gchar *internal_reply,
+                                                const gchar *external_reply,
+                                                GCancellable *cancellable,
+                                                GError **error);
 G_END_DECLS
 
 #endif
diff --git a/src/EWS/common/e-ews-oof-settings.c b/src/EWS/common/e-ews-oof-settings.c
index a369d4ab..be96d441 100644
--- a/src/EWS/common/e-ews-oof-settings.c
+++ b/src/EWS/common/e-ews-oof-settings.c
@@ -6,21 +6,20 @@
 
 #include "evolution-ews-config.h"
 
-#include "e-ews-oof-settings.h"
-
 #include <glib/gi18n-lib.h>
 
 #include <libedataserver/libedataserver.h>
 
 #include "ews-errors.h"
+#include "e-ews-connection.h"
 #include "e-ews-enumtypes.h"
 #include "e-ews-request.h"
 
+#include "e-ews-oof-settings.h"
+
 /* Forward Declarations */
 static void    e_ews_oof_settings_initable_init
                                        (GInitableIface *iface);
-static void    e_ews_oof_settings_async_initable_init
-                                       (GAsyncInitableIface *iface);
 
 struct _EEwsOofSettingsPrivate {
        GMutex property_lock;
@@ -46,203 +45,7 @@ enum {
 
 G_DEFINE_TYPE_WITH_CODE (EEwsOofSettings, e_ews_oof_settings, G_TYPE_OBJECT,
        G_ADD_PRIVATE (EEwsOofSettings)
-       G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, e_ews_oof_settings_initable_init)
-       G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, e_ews_oof_settings_async_initable_init))
-
-static GDateTime *
-ews_oof_settings_string_to_date_time (const gchar *string)
-{
-       GTimeVal tv = { 0, 0 };
-       GDateTime *date_time = NULL;
-
-       if (g_time_val_from_iso8601 (string, &tv))
-               date_time = g_date_time_new_from_timeval_utc (&tv);
-
-       return date_time;
-}
-
-static gchar *
-ews_oof_settings_date_time_to_string (GDateTime *date_time)
-{
-       GTimeVal tv = { 0, 0 };
-       gchar *string = NULL;
-
-       if (g_date_time_to_timeval (date_time, &tv))
-               string = g_time_val_to_iso8601 (&tv);
-
-       return string;
-}
-
-static gchar *
-ews_oof_settings_text_from_html (gchar *html_text)
-{
-       gsize haystack_len;
-       gchar *plain_text;
-       gchar *start, *end;
-       gchar *ii, *jj;
-
-       g_return_val_if_fail (html_text != NULL, NULL);
-
-       haystack_len = strlen (html_text);
-       start = g_strstr_len (html_text, haystack_len, "<body");
-       end = g_strstr_len (html_text, haystack_len, "</body>");
-
-       /* Parse the status set by Outlook Web Access. */
-       if (g_strrstr (html_text, "BodyFragment") != NULL && start == NULL) {
-               start = html_text;
-               end = html_text + haystack_len;
-       }
-
-       /* Strip HTML tags. */
-       plain_text = jj = g_malloc (end - start);
-       for (ii = start; ii < end; ii++) {
-               if (*ii == '<') {
-                       while (*ii != '>')
-                               ii++;
-               } else {
-                       *jj++ = *ii;
-               }
-       }
-       *jj = '\0';
-
-       return plain_text;
-}
-
-static void
-ews_oof_settings_get_response_cb (ESoapResponse *response,
-                                  GSimpleAsyncResult *simple)
-{
-       GAsyncResult *result;
-       GObject *source_object;
-       EEwsOofSettings *settings;
-       ESoapParameter *param;
-       ESoapParameter *subparam;
-       ESoapParameter *subsubparam;
-       GDateTime *date_time;
-       gchar *string;
-       gchar *text;
-       GError *error = NULL;
-
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessage", &error);
-
-       /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
-
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
-       }
-
-       if (!ews_get_response_status (param, &error)) {
-               g_simple_async_result_take_error (simple, error);
-               return;
-       }
-
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "OofSettings", &error);
-
-       /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
-
-       if (error != NULL) {
-               g_simple_async_result_take_error (simple, error);
-               return;
-       }
-
-       result = G_ASYNC_RESULT (simple);
-       source_object = g_async_result_get_source_object (result);
-       settings = E_EWS_OOF_SETTINGS (source_object);
-
-       subparam = e_soap_parameter_get_first_child_by_name (
-               param, "OofState");
-       string = e_soap_parameter_get_string_value (subparam);
-       if (g_strcmp0 (string, "Disabled") == 0)
-               e_ews_oof_settings_set_state (
-                       settings, E_EWS_OOF_STATE_DISABLED);
-       else if (g_strcmp0 (string, "Enabled") == 0)
-               e_ews_oof_settings_set_state (
-                       settings, E_EWS_OOF_STATE_ENABLED);
-       else if (g_strcmp0 (string, "Scheduled") == 0)
-               e_ews_oof_settings_set_state (
-                       settings, E_EWS_OOF_STATE_SCHEDULED);
-       g_free (string);
-
-       subparam = e_soap_parameter_get_first_child_by_name (
-               param, "ExternalAudience");
-       string = e_soap_parameter_get_string_value (subparam);
-       if (g_strcmp0 (string, "None") == 0)
-               e_ews_oof_settings_set_external_audience (
-                       settings, E_EWS_EXTERNAL_AUDIENCE_NONE);
-       else if (g_strcmp0 (string, "Known") == 0)
-               e_ews_oof_settings_set_external_audience (
-                       settings, E_EWS_EXTERNAL_AUDIENCE_KNOWN);
-       else if (g_strcmp0 (string, "All") == 0)
-               e_ews_oof_settings_set_external_audience (
-                       settings, E_EWS_EXTERNAL_AUDIENCE_ALL);
-       g_free (string);
-
-       subparam = e_soap_parameter_get_first_child_by_name (
-               param, "Duration");
-       subsubparam = e_soap_parameter_get_first_child_by_name (
-               subparam, "StartTime");
-       string = e_soap_parameter_get_string_value (subsubparam);
-       date_time = ews_oof_settings_string_to_date_time (string);
-       if (date_time != NULL) {
-               e_ews_oof_settings_set_start_time (settings, date_time);
-               g_date_time_unref (date_time);
-       }
-       g_free (string);
-       subsubparam = e_soap_parameter_get_first_child_by_name (
-               subparam, "EndTime");
-       string = e_soap_parameter_get_string_value (subsubparam);
-       date_time = ews_oof_settings_string_to_date_time (string);
-       if (date_time != NULL) {
-               e_ews_oof_settings_set_end_time (settings, date_time);
-               g_date_time_unref (date_time);
-       }
-       g_free (string);
-
-       subparam = e_soap_parameter_get_first_child_by_name (
-               param, "InternalReply");
-       subsubparam = e_soap_parameter_get_first_child_by_name (
-               subparam, "Message");
-       string = e_soap_parameter_get_string_value (subsubparam);
-       if (string == NULL)
-               text = NULL;
-       else if (g_strrstr (string, "</body>") != NULL)
-               text = ews_oof_settings_text_from_html (string);
-       else if (g_strrstr (string, "BodyFragment") != NULL)
-               text = ews_oof_settings_text_from_html (string);
-       else
-               text = g_strdup (string);
-       e_ews_oof_settings_set_internal_reply (settings, text ? text : "");
-       g_free (string);
-       g_free (text);
-
-       subparam = e_soap_parameter_get_first_child_by_name (
-               param, "ExternalReply");
-       subsubparam = e_soap_parameter_get_first_child_by_name (
-               subparam, "Message");
-       string = e_soap_parameter_get_string_value (subsubparam);
-       if (string == NULL)
-               text = NULL;
-       else if (g_strrstr (string, "</body>") != NULL)
-               text = ews_oof_settings_text_from_html (string);
-       else if (g_strrstr (string, "BodyFragment") != NULL)
-               text = ews_oof_settings_text_from_html (string);
-       else
-               text = g_strdup (string);
-       e_ews_oof_settings_set_external_reply (settings, text ? text : "");
-       g_free (string);
-       g_free (text);
-
-       g_object_unref (source_object);
-}
+       G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, e_ews_oof_settings_initable_init))
 
 static void
 ews_oof_settings_set_connection (EEwsOofSettings *settings,
@@ -400,101 +203,12 @@ ews_oof_settings_initable_init (GInitable *initable,
                                 GCancellable *cancellable,
                                 GError **error)
 {
-       EAsyncClosure *closure;
-       GAsyncResult *result;
-       gboolean success;
-
-       closure = e_async_closure_new ();
+       EEwsOofSettings *settings = E_EWS_OOF_SETTINGS (initable);
 
-       g_async_initable_init_async (
-               G_ASYNC_INITABLE (initable),
-               G_PRIORITY_DEFAULT, cancellable,
-               e_async_closure_callback, closure);
+       g_return_val_if_fail (settings->priv->connection != NULL, FALSE);
 
-       result = e_async_closure_wait (closure);
-
-       success = g_async_initable_init_finish (
-               G_ASYNC_INITABLE (initable), result, error);
-
-       e_async_closure_free (closure);
-
-       return success;
-}
-
-static void
-ews_oof_settings_initable_init_async (GAsyncInitable *initable,
-                                      gint io_priority,
-                                      GCancellable *cancellable,
-                                      GAsyncReadyCallback callback,
-                                      gpointer user_data)
-{
-       GSimpleAsyncResult *simple;
-       EEwsOofSettings *settings;
-       EEwsConnection *connection;
-       ESoapRequest *request;
-       CamelEwsSettings *ews_settings;
-       const gchar *uri, *impersonate_user;
-       const gchar *mailbox;
-       EEwsServerVersion version;
-
-       settings = E_EWS_OOF_SETTINGS (initable);
-       connection = e_ews_oof_settings_get_connection (settings);
-
-       uri = e_ews_connection_get_uri (connection);
-       impersonate_user = e_ews_connection_get_impersonate_user (connection);
-       mailbox = e_ews_connection_get_mailbox (connection);
-       version = e_ews_connection_get_server_version (connection);
-       ews_settings = e_ews_connection_ref_settings (connection);
-
-       request = e_ews_request_new_with_header (
-               uri,
-               impersonate_user,
-               "GetUserOofSettingsRequest",
-               NULL,
-               NULL,
-               version,
-               E_EWS_EXCHANGE_2007_SP1,
-               FALSE);
-
-       g_clear_object (&ews_settings);
-
-       e_soap_request_start_element (message, "Mailbox", NULL, NULL);
-       e_ews_request_write_string_parameter (
-               message, "Address", NULL, mailbox);
-       e_soap_request_end_element (message);
-
-       e_ews_request_write_footer (message);
-
-       simple = g_simple_async_result_new (
-               G_OBJECT (initable), callback, user_data,
-               ews_oof_settings_initable_init_async);
-
-       g_simple_async_result_set_check_cancellable (simple, cancellable);
-
-       e_ews_connection_queue_request (
-               connection, message,
-               ews_oof_settings_get_response_cb,
-               EWS_PRIORITY_MEDIUM, cancellable, simple);
-
-       g_object_unref (simple);
-}
-
-static gboolean
-ews_oof_settings_initable_init_finish (GAsyncInitable *initable,
-                                       GAsyncResult *result,
-                                       GError **error)
-{
-       GSimpleAsyncResult *simple;
-
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (initable),
-               ews_oof_settings_initable_init_async), FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-
-       /* Assume success unless a GError is set. */
-       return !g_simple_async_result_propagate_error (simple, error);
+       return e_ews_connection_get_user_oof_settings_sync (settings->priv->connection,
+               G_PRIORITY_DEFAULT, settings, cancellable, error);
 }
 
 static void
@@ -609,13 +323,6 @@ e_ews_oof_settings_initable_init (GInitableIface *iface)
        iface->init = ews_oof_settings_initable_init;
 }
 
-static void
-e_ews_oof_settings_async_initable_init (GAsyncInitableIface *iface)
-{
-       iface->init_async = ews_oof_settings_initable_init_async;
-       iface->init_finish = ews_oof_settings_initable_init_finish;
-}
-
 EEwsOofSettings *
 e_ews_oof_settings_new_sync (EEwsConnection *connection,
                              GCancellable *cancellable,
@@ -628,41 +335,6 @@ e_ews_oof_settings_new_sync (EEwsConnection *connection,
                "connection", connection, NULL);
 }
 
-void
-e_ews_oof_settings_new (EEwsConnection *connection,
-                        gint io_priority,
-                        GCancellable *cancellable,
-                        GAsyncReadyCallback callback,
-                        gpointer user_data)
-{
-       g_return_if_fail (E_IS_EWS_CONNECTION (connection));
-
-       g_async_initable_new_async (
-               E_TYPE_EWS_OOF_SETTINGS, io_priority,
-               cancellable, callback, user_data,
-               "connection", connection, NULL);
-}
-
-EEwsOofSettings *
-e_ews_oof_settings_new_finish (GAsyncResult *result,
-                               GError **error)
-{
-       GObject *source_object;
-       GObject *object;
-
-       g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
-
-       source_object = g_async_result_get_source_object (result);
-       g_return_val_if_fail (source_object != NULL, NULL);
-
-       object = g_async_initable_new_finish (
-               G_ASYNC_INITABLE (source_object), result, error);
-
-       g_object_unref (source_object);
-
-       return (object != NULL) ? E_EWS_OOF_SETTINGS (object) : NULL;
-}
-
 EEwsConnection *
 e_ews_oof_settings_get_connection (EEwsOofSettings *settings)
 {
@@ -877,51 +549,92 @@ e_ews_oof_settings_set_external_reply (EEwsOofSettings *settings,
        g_object_notify (G_OBJECT (settings), "external-reply");
 }
 
+typedef struct _SubmitData {
+       EEwsOofState state;
+       EEwsExternalAudience external_audience;
+       GDateTime *date_start;
+       GDateTime *date_end;
+       gchar *internal_reply;
+       gchar *external_reply;
+} SubmitData;
+
+static SubmitData *
+submit_data_new (EEwsOofSettings *settings)
+{
+       SubmitData *sd;
+
+       sd = g_slice_new0 (SubmitData);
+       sd->state = e_ews_oof_settings_get_state (settings);
+       sd->external_audience = e_ews_oof_settings_get_external_audience (settings);
+       sd->date_start = e_ews_oof_settings_ref_start_time (settings);
+       sd->date_end = e_ews_oof_settings_ref_end_time (settings);
+       sd->internal_reply = e_ews_oof_settings_dup_internal_reply (settings);
+       sd->external_reply = e_ews_oof_settings_dup_external_reply (settings);
+
+       return sd;
+}
+
+static void
+submit_data_free (gpointer ptr)
+{
+       SubmitData *sd = ptr;
+
+       if (sd) {
+               g_clear_pointer (&sd->date_start, g_date_time_unref);
+               g_clear_pointer (&sd->date_end, g_date_time_unref);
+               g_clear_pointer (&sd->internal_reply, g_free);
+               g_clear_pointer (&sd->external_reply, g_free);
+               g_slice_free (SubmitData, sd);
+       }
+}
+
+static gboolean
+ews_oof_settings_call_submit_sync (EEwsOofSettings *settings,
+                                  SubmitData *sd,
+                                  GCancellable *cancellable,
+                                  GError **error)
+{
+       EEwsConnection *cnc = e_ews_oof_settings_get_connection (settings);
+
+       g_return_val_if_fail (sd != NULL, FALSE);
+       g_return_val_if_fail (cnc != NULL, FALSE);
+
+       return e_ews_connection_set_user_oof_settings_sync (cnc,
+               G_PRIORITY_DEFAULT, sd->state, sd->external_audience, sd->date_start,
+               sd->date_end, sd->internal_reply, sd->external_reply,
+               cancellable, error);
+}
+
 gboolean
 e_ews_oof_settings_submit_sync (EEwsOofSettings *settings,
                                 GCancellable *cancellable,
                                 GError **error)
 {
-       EAsyncClosure *closure;
-       GAsyncResult *result;
+       SubmitData *sd;
        gboolean success;
 
        g_return_val_if_fail (E_IS_EWS_OOF_SETTINGS (settings), FALSE);
 
-       closure = e_async_closure_new ();
-
-       e_ews_oof_settings_submit (
-               settings, cancellable, e_async_closure_callback, closure);
-
-       result = e_async_closure_wait (closure);
-
-       success = e_ews_oof_settings_submit_finish (settings, result, error);
-
-       e_async_closure_free (closure);
+       sd = submit_data_new (settings);
+       success = ews_oof_settings_call_submit_sync (settings, sd, cancellable, error);
+       submit_data_free (sd);
 
        return success;
 }
 
 static void
-ews_oof_settings_submit_response_cb (ESoapResponse *response,
-                                     GSimpleAsyncResult *simple)
+ews_oof_settings_submit_thread (GTask *task,
+                               gpointer source_object,
+                               gpointer task_data,
+                               GCancellable *cancellable)
 {
-       ESoapParameter *param;
+       SubmitData *sd = task_data;
        GError *error = NULL;
 
-       param = e_soap_response_get_first_parameter_by_name (
-               response, "ResponseMessage", &error);
-
-       /* Sanity check */
-       g_return_if_fail (
-               (param != NULL && error == NULL) ||
-               (param == NULL && error != NULL));
-
-       if (error != NULL)
-               g_simple_async_result_take_error (simple, error);
-
-       else if (!ews_get_response_status (param, &error))
-               g_simple_async_result_take_error (simple, error);
+       if (ews_oof_settings_call_submit_sync (E_EWS_OOF_SETTINGS (source_object), sd, cancellable, error))
+               g_task_return_boolean (task, TRUE);
+       else
+               g_task_return_error (task, error);
 }
 
 void
@@ -930,156 +643,20 @@ e_ews_oof_settings_submit (EEwsOofSettings *settings,
                            GAsyncReadyCallback callback,
                            gpointer user_data)
 {
-       ESoapRequest *request;
-       EEwsConnection *connection;
-       GSimpleAsyncResult *simple;
-       GDateTime *date_time;
-       const gchar *mailbox;
-       const gchar *string;
-       const gchar *uri, *impersonate_user;
-       gchar *internal_reply;
-       gchar *external_reply;
-       gchar *start_time;
-       gchar *end_time;
-       EEwsServerVersion version;
-       CamelEwsSettings *ews_settings;
+       GTask *task;
+       SubmitData *sd;
 
        g_return_if_fail (E_IS_EWS_OOF_SETTINGS (settings));
 
-       connection = e_ews_oof_settings_get_connection (settings);
-       mailbox = e_ews_connection_get_mailbox (connection);
-       uri = e_ews_connection_get_uri (connection);
-       impersonate_user = e_ews_connection_get_impersonate_user (connection);
-       version = e_ews_connection_get_server_version (connection);
-       ews_settings = e_ews_connection_ref_settings (connection);
-
-       internal_reply = e_ews_oof_settings_dup_internal_reply (settings);
-       external_reply = e_ews_oof_settings_dup_external_reply (settings);
-
-       date_time = e_ews_oof_settings_ref_start_time (settings);
-       start_time = ews_oof_settings_date_time_to_string (date_time);
-       g_date_time_unref (date_time);
-
-       date_time = e_ews_oof_settings_ref_end_time (settings);
-       end_time = ews_oof_settings_date_time_to_string (date_time);
-       g_date_time_unref (date_time);
-
-       request = e_ews_request_new_with_header (
-               uri,
-               impersonate_user,
-               "SetUserOofSettingsRequest",
-               NULL,
-               NULL,
-               version,
-               E_EWS_EXCHANGE_2007_SP1,
-               FALSE);
-
-       g_clear_object (&ews_settings);
-
-       /* <Mailbox> */
-
-       e_soap_request_start_element (
-               message, "Mailbox", NULL, NULL);
-       e_ews_request_write_string_parameter (
-               message, "Address", NULL, mailbox);
-       e_soap_request_end_element (message);
-
-       /* </Mailbox> */
-
-       /* <UserOofSettings> */
-
-       e_soap_request_start_element (
-               message, "UserOofSettings", NULL, NULL);
-
-       switch (e_ews_oof_settings_get_state (settings)) {
-               default:
-                       g_warn_if_reached ();
-                       /* fall through */
-               case E_EWS_OOF_STATE_DISABLED:
-                       string = "Disabled";
-                       break;
-               case E_EWS_OOF_STATE_ENABLED:
-                       string = "Enabled";
-                       break;
-               case E_EWS_OOF_STATE_SCHEDULED:
-                       string = "Scheduled";
-                       break;
-       }
-
-       e_ews_request_write_string_parameter (
-               message, "OofState", NULL, string);
-
-       switch (e_ews_oof_settings_get_external_audience (settings)) {
-               default:
-                       g_warn_if_reached ();
-                       /* fall through */
-               case E_EWS_EXTERNAL_AUDIENCE_NONE:
-                       string = "None";
-                       break;
-               case E_EWS_EXTERNAL_AUDIENCE_KNOWN:
-                       string = "Known";
-                       break;
-               case E_EWS_EXTERNAL_AUDIENCE_ALL:
-                       string = "All";
-                       break;
-       }
-
-       e_ews_request_write_string_parameter (
-               message, "ExternalAudience", NULL, string);
+       task = g_task_new (settings, cancellable, callback, user_data);
+       g_task_set_source_tag (task, e_ews_oof_settings_submit);
 
-       /* <Duration> */
+       sd = submit_data_new (settings);
+       g_task_set_task_data (task, sd, submit_data_free);
 
-       e_soap_request_start_element (
-               message, "Duration", NULL, NULL);
-       e_ews_request_write_string_parameter (
-               message, "StartTime", NULL, start_time);
-       e_ews_request_write_string_parameter (
-               message, "EndTime", NULL, end_time);
-       e_soap_request_end_element (message);
+       g_task_run_in_thread (task, ews_oof_settings_submit_thread);
 
-       /* </Duration> */
-
-       /* <InternalReply> */
-
-       e_soap_request_start_element (
-               message, "InternalReply", NULL, NULL);
-       e_ews_request_write_string_parameter (
-               message, "Message", NULL, internal_reply);
-       e_soap_request_end_element (message);
-
-       /* </InternalReply> */
-
-       /* <ExternalReply> */
-
-       e_soap_request_start_element (
-               message, "ExternalReply", NULL, NULL);
-       e_ews_request_write_string_parameter (
-               message, "Message", NULL, external_reply);
-       e_soap_request_end_element (message);
-
-       /* </ExternalReply> */
-
-       e_soap_request_end_element (message);
-
-       /* </UserOofSettings> */
-
-       e_ews_request_write_footer (message);
-
-       simple = g_simple_async_result_new (
-               G_OBJECT (settings), callback,
-               user_data, e_ews_oof_settings_submit);
-
-       e_ews_connection_queue_request (
-               connection, message,
-               ews_oof_settings_submit_response_cb,
-               EWS_PRIORITY_MEDIUM, cancellable, simple);
-
-       g_object_unref (simple);
-
-       g_free (internal_reply);
-       g_free (external_reply);
-       g_free (start_time);
-       g_free (end_time);
+       g_object_unref (task);
 }
 
 gboolean
@@ -1087,16 +664,7 @@ e_ews_oof_settings_submit_finish (EEwsOofSettings *settings,
                                   GAsyncResult *result,
                                   GError **error)
 {
-       GSimpleAsyncResult *simple;
+       g_return_val_if_fail (g_task_is_valid (result, settings), FALSE);
 
-       g_return_val_if_fail (
-               g_simple_async_result_is_valid (
-               result, G_OBJECT (settings),
-               e_ews_oof_settings_submit), FALSE);
-
-       simple = G_SIMPLE_ASYNC_RESULT (result);
-
-       /* Assume success unless a GError is set. */
-       return !g_simple_async_result_propagate_error (simple, error);
+       return g_task_propagate_boolean (G_TASK (result), error);
 }
-
diff --git a/src/EWS/common/e-ews-oof-settings.h b/src/EWS/common/e-ews-oof-settings.h
index a6c2e1c8..4130c5da 100644
--- a/src/EWS/common/e-ews-oof-settings.h
+++ b/src/EWS/common/e-ews-oof-settings.h
@@ -7,7 +7,6 @@
 #ifndef E_EWS_OOF_SETTINGS_H
 #define E_EWS_OOF_SETTINGS_H
 
-#include <common/e-ews-connection.h>
 #include <common/e-ews-enums.h>
 
 /* Standard GObject macros */
@@ -31,6 +30,8 @@
 
 G_BEGIN_DECLS
 
+struct _EEwsConnection;
+
 typedef struct _EEwsOofSettings EEwsOofSettings;
 typedef struct _EEwsOofSettingsClass EEwsOofSettingsClass;
 typedef struct _EEwsOofSettingsPrivate EEwsOofSettingsPrivate;
@@ -46,18 +47,10 @@ struct _EEwsOofSettingsClass {
 
 GType          e_ews_oof_settings_get_type     (void) G_GNUC_CONST;
 EEwsOofSettings *
-               e_ews_oof_settings_new_sync     (EEwsConnection *connection,
-                                                GCancellable *cancellable,
-                                                GError **error);
-void           e_ews_oof_settings_new          (EEwsConnection *connection,
-                                                gint io_priority,
+               e_ews_oof_settings_new_sync     (struct _EEwsConnection *connection,
                                                 GCancellable *cancellable,
-                                                GAsyncReadyCallback callback,
-                                                gpointer user_data);
-EEwsOofSettings *
-               e_ews_oof_settings_new_finish   (GAsyncResult *result,
                                                 GError **error);
-EEwsConnection *
+struct _EEwsConnection *
                e_ews_oof_settings_get_connection
                                                (EEwsOofSettings *settings);
 EEwsOofState   e_ews_oof_settings_get_state    (EEwsOofSettings *settings);


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