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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
/*
* Evolution calendar - Copy source dialog
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
*
* Authors:
* Rodrigo Moya <rodrigo@ximian.com>
*
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <glib/gi18n.h>
#include <libedataserverui/libedataserverui.h>
#include "copy-source-dialog.h"
#include "select-source-dialog.h"
typedef struct {
GtkWindow *parent;
ESource *orig_source;
EClientSourceType obj_type;
ESource *selected_source;
ECalClient *source_client, *dest_client;
} CopySourceDialogData;
static void
show_error (CopySourceDialogData *csdd,
const gchar *msg,
const GError *error)
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (
csdd->parent, 0, GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE, error ? "%s\n%s" : "%s", msg, error ? error->message : "");
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
struct ForeachTzidData
{
ECalClient *source_client;
ECalClient *dest_client;
};
static void
add_timezone_to_cal_cb (icalparameter *param,
gpointer data)
{
struct ForeachTzidData *ftd = data;
icaltimezone *tz = NULL;
const gchar *tzid;
g_return_if_fail (ftd != NULL);
g_return_if_fail (ftd->source_client != NULL);
g_return_if_fail (ftd->dest_client != NULL);
tzid = icalparameter_get_tzid (param);
if (!tzid || !*tzid)
return;
if (e_cal_client_get_timezone_sync (ftd->source_client, tzid, &tz, NULL, NULL) && tz)
e_cal_client_add_timezone_sync (ftd->dest_client, tz, NULL, NULL);
}
static void
free_copy_data (CopySourceDialogData *csdd)
{
if (!csdd)
return;
if (csdd->orig_source)
g_object_unref (csdd->orig_source);
if (csdd->selected_source)
g_object_unref (csdd->selected_source);
if (csdd->source_client)
g_object_unref (csdd->source_client);
if (csdd->dest_client)
g_object_unref (csdd->dest_client);
g_free (csdd);
}
static void
dest_source_opened_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
ESource *source = E_SOURCE (source_object);
CopySourceDialogData *csdd = user_data;
EClient *client = NULL;
GError *error = NULL;
e_client_utils_open_new_finish (source, result, &client, &error);
if (error != NULL) {
g_warn_if_fail (client == NULL);
show_error (csdd, _("Could not open destination"), error);
g_error_free (error);
free_copy_data (csdd);
return;
}
g_return_if_fail (E_IS_CLIENT (client));
csdd->dest_client = E_CAL_CLIENT (client);
/* check if the destination is read only */
if (e_client_is_readonly (E_CLIENT (csdd->dest_client))) {
show_error (csdd, _("Destination is read only"), NULL);
} else {
GSList *obj_list = NULL;
if (e_cal_client_get_object_list_sync (csdd->source_client, "#t", &obj_list, NULL, NULL)) {
GSList *l;
icalcomponent *icalcomp;
struct ForeachTzidData ftd;
ftd.source_client = csdd->source_client;
ftd.dest_client = csdd->dest_client;
for (l = obj_list; l != NULL; l = l->next) {
/* FIXME: process recurrences */
/* FIXME: process errors */
if (e_cal_client_get_object_sync (csdd->dest_client, icalcomponent_get_uid (l->data), NULL,
&icalcomp, NULL, NULL)) {
e_cal_client_modify_object_sync (csdd->dest_client, l->data, CALOBJ_MOD_ALL, NULL, NULL);
icalcomponent_free (icalcomp);
} else {
gchar *uid = NULL;
GError *error = NULL;
icalcomp = l->data;
/* Add timezone information from source
* ECal to the destination ECal. */
icalcomponent_foreach_tzid (
icalcomp,
add_timezone_to_cal_cb, &ftd);
if (e_cal_client_create_object_sync (csdd->dest_client, icalcomp, &uid, NULL, &error)) {
g_free (uid);
} else {
if (error) {
show_error (csdd, _("Cannot create object"), error);
g_error_free (error);
}
break;
}
}
}
e_cal_client_free_icalcomp_slist (obj_list);
}
}
free_copy_data (csdd);
}
static void
orig_source_opened_cb (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
ESource *source = E_SOURCE (source_object);
CopySourceDialogData *csdd = user_data;
EClient *client = NULL;
GError *error = NULL;
e_client_utils_open_new_finish (source, result, &client, &error);
if (error != NULL) {
g_warn_if_fail (client == NULL);
show_error (csdd, _("Could not open source"), error);
g_error_free (error);
free_copy_data (csdd);
return;
}
g_return_if_fail (E_IS_CLIENT (client));
csdd->source_client = E_CAL_CLIENT (client);
e_client_utils_open_new (
csdd->selected_source, csdd->obj_type, FALSE, NULL,
dest_source_opened_cb, csdd);
}
static void
copy_source (const CopySourceDialogData *const_csdd)
{
CopySourceDialogData *csdd;
if (!const_csdd->selected_source)
return;
g_return_if_fail (const_csdd->obj_type != E_CLIENT_SOURCE_TYPE_LAST);
csdd = g_new0 (CopySourceDialogData, 1);
csdd->parent = const_csdd->parent;
csdd->orig_source = g_object_ref (const_csdd->orig_source);
csdd->obj_type = const_csdd->obj_type;
csdd->selected_source = g_object_ref (const_csdd->selected_source);
e_client_utils_open_new (
csdd->orig_source, csdd->obj_type, FALSE, NULL,
orig_source_opened_cb, csdd);
}
/**
* copy_source_dialog
*
* Implements the Copy command for sources, allowing the user to select a target
* source to copy to.
*/
void
copy_source_dialog (GtkWindow *parent,
ESourceRegistry *registry,
ESource *source,
ECalClientSourceType obj_type)
{
CopySourceDialogData csdd;
g_return_if_fail (E_IS_SOURCE_REGISTRY (registry));
g_return_if_fail (E_IS_SOURCE (source));
g_return_if_fail (obj_type == E_CAL_CLIENT_SOURCE_TYPE_EVENTS ||
obj_type == E_CAL_CLIENT_SOURCE_TYPE_TASKS ||
obj_type == E_CAL_CLIENT_SOURCE_TYPE_MEMOS);
csdd.parent = parent;
csdd.orig_source = source;
csdd.selected_source = NULL;
csdd.obj_type = obj_type == E_CAL_CLIENT_SOURCE_TYPE_EVENTS ? E_CLIENT_SOURCE_TYPE_EVENTS :
obj_type == E_CAL_CLIENT_SOURCE_TYPE_TASKS ? E_CLIENT_SOURCE_TYPE_TASKS :
obj_type == E_CAL_CLIENT_SOURCE_TYPE_MEMOS ? E_CLIENT_SOURCE_TYPE_MEMOS :
E_CLIENT_SOURCE_TYPE_LAST;
csdd.selected_source = select_source_dialog (
parent, registry, obj_type, source);
if (csdd.selected_source) {
copy_source (&csdd);
/* free memory */
g_object_unref (csdd.selected_source);
}
}
|