manager: updated GcalManager::create_event
Move the API to use ECalComponent instead of uids.
This commit is contained in:
+63
-72
@@ -20,7 +20,14 @@
|
|||||||
#include "gcal-manager.h"
|
#include "gcal-manager.h"
|
||||||
#include "gcal-utils.h"
|
#include "gcal-utils.h"
|
||||||
|
|
||||||
typedef struct _GcalManagerUnit
|
typedef struct
|
||||||
|
{
|
||||||
|
ESource *source;
|
||||||
|
ECalComponent *component;
|
||||||
|
GcalManager *manager;
|
||||||
|
} AsyncOpsData;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
{
|
{
|
||||||
ECalClient *client;
|
ECalClient *client;
|
||||||
|
|
||||||
@@ -48,10 +55,6 @@ typedef struct
|
|||||||
|
|
||||||
/* timezone */
|
/* timezone */
|
||||||
icaltimezone *system_timezone;
|
icaltimezone *system_timezone;
|
||||||
|
|
||||||
/* uid of pending create event actions */
|
|
||||||
gchar *pending_event_uid;
|
|
||||||
gchar *pending_event_source;
|
|
||||||
} GcalManagerPrivate;
|
} GcalManagerPrivate;
|
||||||
|
|
||||||
/* FIXME: review */
|
/* FIXME: review */
|
||||||
@@ -84,6 +87,8 @@ enum
|
|||||||
|
|
||||||
static guint signals[LAST_SIGNAL];
|
static guint signals[LAST_SIGNAL];
|
||||||
|
|
||||||
|
static void free_async_ops_data (AsyncOpsData *data);
|
||||||
|
|
||||||
static void load_source (GcalManager *manager,
|
static void load_source (GcalManager *manager,
|
||||||
ESource *source);
|
ESource *source);
|
||||||
|
|
||||||
@@ -95,6 +100,10 @@ static void on_client_refreshed (GObject *sour
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
|
static void on_event_created (GObject *source_object,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data);
|
||||||
|
|
||||||
static void on_event_updated (GObject *source_object,
|
static void on_event_updated (GObject *source_object,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
@@ -110,10 +119,6 @@ static void remove_source (GcalManager *mana
|
|||||||
|
|
||||||
static void gcal_manager_finalize (GObject *object);
|
static void gcal_manager_finalize (GObject *object);
|
||||||
|
|
||||||
static void gcal_manager_on_event_created (GObject *source_object,
|
|
||||||
GAsyncResult *result,
|
|
||||||
gpointer user_data);
|
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_PRIVATE (GcalManager, gcal_manager, G_TYPE_OBJECT)
|
G_DEFINE_TYPE_WITH_PRIVATE (GcalManager, gcal_manager, G_TYPE_OBJECT)
|
||||||
|
|
||||||
/* -- start: threading related code provided by Milan Crha */
|
/* -- start: threading related code provided by Milan Crha */
|
||||||
@@ -198,6 +203,13 @@ submit_thread_job (EThreadJobFunc func,
|
|||||||
}
|
}
|
||||||
/* -- end: threading related code provided by Milan Crha -- */
|
/* -- end: threading related code provided by Milan Crha -- */
|
||||||
|
|
||||||
|
static void
|
||||||
|
free_async_ops_data (AsyncOpsData *data)
|
||||||
|
{
|
||||||
|
g_object_unref (data->component);
|
||||||
|
g_free (data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* load_source:
|
* load_source:
|
||||||
* @manager: Manager instance
|
* @manager: Manager instance
|
||||||
@@ -309,6 +321,36 @@ on_client_refreshed (GObject *source_object,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_event_created (GObject *source_object,
|
||||||
|
GAsyncResult *result,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
AsyncOpsData *data;
|
||||||
|
ECalClient *client;
|
||||||
|
gchar *new_uid;
|
||||||
|
GError *error;
|
||||||
|
|
||||||
|
data = (AsyncOpsData*) user_data;
|
||||||
|
client = E_CAL_CLIENT (source_object);
|
||||||
|
error = NULL;
|
||||||
|
|
||||||
|
if (e_cal_client_create_object_finish (client, result, &new_uid, &error))
|
||||||
|
{
|
||||||
|
g_signal_emit (data->manager, signals[EVENT_CREATED], 0,
|
||||||
|
e_source_get_uid (data->source), new_uid);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Some error */
|
||||||
|
g_warning ("Error creating object: %s", error->message);
|
||||||
|
g_error_free (error);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free (new_uid);
|
||||||
|
free_async_ops_data (data);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* on_component_updated:
|
* on_component_updated:
|
||||||
* @source_object: {@link ECalClient} source
|
* @source_object: {@link ECalClient} source
|
||||||
@@ -478,26 +520,6 @@ gcal_manager_finalize (GObject *object)
|
|||||||
g_hash_table_destroy (priv->clients);
|
g_hash_table_destroy (priv->clients);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
gcal_manager_on_event_created (GObject *source_object,
|
|
||||||
GAsyncResult *result,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
ECalClient *client;
|
|
||||||
gchar *new_uid;
|
|
||||||
GError *error;
|
|
||||||
|
|
||||||
client = E_CAL_CLIENT (source_object);
|
|
||||||
error = NULL;
|
|
||||||
if (! e_cal_client_create_object_finish (client, result, &new_uid, &error))
|
|
||||||
{
|
|
||||||
/* Some error */
|
|
||||||
g_warning ("Error creating object: %s", error->message);
|
|
||||||
g_error_free (error);
|
|
||||||
}
|
|
||||||
g_free (new_uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Public API */
|
/* Public API */
|
||||||
/**
|
/**
|
||||||
* gcal_manager_new:
|
* gcal_manager_new:
|
||||||
@@ -704,62 +726,31 @@ gcal_manager_is_client_writable (GcalManager *manager,
|
|||||||
|
|
||||||
void
|
void
|
||||||
gcal_manager_create_event (GcalManager *manager,
|
gcal_manager_create_event (GcalManager *manager,
|
||||||
const gchar *source_uid,
|
ESource *source,
|
||||||
const gchar *summary,
|
ECalComponent *component)
|
||||||
const icaltimetype *initial_date,
|
|
||||||
const icaltimetype *final_date)
|
|
||||||
{
|
{
|
||||||
GcalManagerPrivate *priv;
|
GcalManagerPrivate *priv;
|
||||||
|
|
||||||
GcalManagerUnit *unit;
|
GcalManagerUnit *unit;
|
||||||
ECalComponent *event;
|
|
||||||
ECalComponentDateTime dt;
|
|
||||||
ECalComponentText summ;
|
|
||||||
icalcomponent *new_event_icalcomp;
|
icalcomponent *new_event_icalcomp;
|
||||||
icaltimetype *dt_start;
|
AsyncOpsData *data;
|
||||||
|
|
||||||
priv = gcal_manager_get_instance_private (manager);
|
priv = gcal_manager_get_instance_private (manager);
|
||||||
|
|
||||||
unit = g_hash_table_lookup (priv->clients, source_uid);
|
unit = g_hash_table_lookup (priv->clients, source);
|
||||||
|
|
||||||
event = e_cal_component_new ();
|
new_event_icalcomp = e_cal_component_get_icalcomponent (component);
|
||||||
e_cal_component_set_new_vtype (event, E_CAL_COMPONENT_EVENT);
|
|
||||||
|
|
||||||
dt_start = gcal_dup_icaltime (initial_date);
|
data = g_new0 (AsyncOpsData, 1);
|
||||||
dt.value = dt_start;
|
data->source = source;
|
||||||
dt.tzid = NULL;
|
data->component = component;
|
||||||
e_cal_component_set_dtstart (event, &dt);
|
data->manager = manager;
|
||||||
|
|
||||||
if (final_date != NULL)
|
|
||||||
{
|
|
||||||
*dt.value = *final_date;
|
|
||||||
e_cal_component_set_dtend (event, &dt);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
icaltime_adjust (dt_start, 1, 0, 0, 0);
|
|
||||||
*dt.value = *dt_start;
|
|
||||||
e_cal_component_set_dtend (event, &dt);
|
|
||||||
}
|
|
||||||
|
|
||||||
summ.altrep = NULL;
|
|
||||||
summ.value = summary;
|
|
||||||
e_cal_component_set_summary (event, &summ);
|
|
||||||
|
|
||||||
e_cal_component_commit_sequence (event);
|
|
||||||
|
|
||||||
new_event_icalcomp = e_cal_component_get_icalcomponent (event);
|
|
||||||
|
|
||||||
priv->pending_event_source = g_strdup (source_uid);
|
|
||||||
priv->pending_event_uid =
|
|
||||||
g_strdup (icalcomponent_get_uid (new_event_icalcomp));
|
|
||||||
|
|
||||||
e_cal_client_create_object (unit->client,
|
e_cal_client_create_object (unit->client,
|
||||||
new_event_icalcomp,
|
new_event_icalcomp,
|
||||||
priv->async_ops,
|
priv->async_ops,
|
||||||
gcal_manager_on_event_created,
|
on_event_created,
|
||||||
manager);
|
data);
|
||||||
|
|
||||||
g_object_unref (event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
+2
-4
@@ -91,10 +91,8 @@ gboolean gcal_manager_is_client_writable (GcalManager *manager
|
|||||||
|
|
||||||
/* Create method */
|
/* Create method */
|
||||||
void gcal_manager_create_event (GcalManager *manager,
|
void gcal_manager_create_event (GcalManager *manager,
|
||||||
const gchar *source_uid,
|
ESource *source,
|
||||||
const gchar *summary,
|
ECalComponent *component);
|
||||||
const icaltimetype *initial_date,
|
|
||||||
const icaltimetype *final_date);
|
|
||||||
|
|
||||||
/* Update method */
|
/* Update method */
|
||||||
void gcal_manager_update_event (GcalManager *manager,
|
void gcal_manager_update_event (GcalManager *manager,
|
||||||
|
|||||||
Reference in New Issue
Block a user