diff options
Diffstat (limited to 'sync/src/sync_evo2_item.c')
-rw-r--r-- | sync/src/sync_evo2_item.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/sync/src/sync_evo2_item.c b/sync/src/sync_evo2_item.c new file mode 100644 index 0000000..69a0c65 --- /dev/null +++ b/sync/src/sync_evo2_item.c @@ -0,0 +1,93 @@ + +#include <opensync/opensync.h> +#include <glib.h> +#include <string.h> +#include "sync.h" +#include "sync_item.h" +#include "sync_evo2_item.h" + +#define EVO2_PLUGIN "evo2-sync" +#define EVO2_CONFIG "<config>" \ + "<adress_path>%s</adress_path>" \ + "<calendar_path>%s</calendar_path>" \ + "<tasks_path>%s</tasks_path>" \ + "</config>" + +typedef struct { + gchar *adr_path; + gchar *cal_path; + gchar *task_path; +} SyncEvo2ItemData; + +static OSyncMember * +sync_evo2_item_get_member (SyncItem *item) +{ + OSyncMember *member; + OSyncError *error = NULL; + OSyncConfigurationTypes type = NO_CONFIGURATION; + + /* Setup Evolution2 sync member */ + member = osync_member_new (sync_group_get_osync_group ( + sync_item_get_group (item))); + if (!osync_member_instance_plugin (member, EVO2_PLUGIN, &error)) { + g_warning ("Error instancing Evolution2 plug-in: %s", + osync_error_print (&error)); + osync_error_free (&error); + return NULL; + } + if (!osync_member_need_config (member, &type, &error)) { + g_warning ("Error reading plug-in config requirements: %s", + osync_error_print (&error)); + osync_error_free (&error); + return NULL; + } + if (type == NO_CONFIGURATION) { + g_warning ( + "Evolution2 plug-in reports no need for configuration"); + } else { + SyncEvo2ItemData *data; + gchar *evo2_config; + + data = (SyncEvo2ItemData *)sync_item_get_data (item); + evo2_config = g_strdup_printf (EVO2_CONFIG, data->adr_path, + data->cal_path, data->task_path); + osync_member_set_config ( + member, evo2_config, strlen (evo2_config)); + g_free (evo2_config); + } + + return member; +} + +static void +sync_evo2_free_data (SyncEvo2ItemData *data) +{ + g_free (data->adr_path); + g_free (data->cal_path); + g_free (data->task_path); + g_free (data); +} + +SyncItem * +sync_evo2_item_new (const gchar *name, const gchar *address_path, + const gchar *calendar_path, const gchar *tasks_path) +{ + SyncItem *item; + SyncEvo2ItemData *data; + + item = sync_item_new (name, NULL, sync_evo2_item_get_member); + + data = g_new0 (SyncEvo2ItemData, 1); + data->adr_path = address_path ? + g_strdup (address_path) : g_strdup ("default"); + data->cal_path = calendar_path ? + g_strdup (calendar_path) : g_strdup ("default"); + data->task_path = tasks_path ? + g_strdup (tasks_path) : g_strdup ("default"); + + sync_item_set_data (item, data); + sync_item_set_data_free_func ( + item, (SyncItemDataFreeFunc)sync_evo2_free_data); + + return item; +} |