summaryrefslogtreecommitdiffstats
path: root/sync/src/sync_evo2_item.c
blob: 19666b97edc28533ee80c224d8a789fa4b0912b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <opensync/opensync.h>
#include <glib.h>
#include <string.h>
#include "sync_group.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;
}