evolution-3.6.4/calendar/gui/dialogs/e-send-options-utils.c

No issues found

  1 /*
  2  * Evolution calendar - Timezone selector dialog
  3  *
  4  * This program is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2 of the License, or (at your option) version 3.
  8  *
  9  * This program is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 16  *
 17  *
 18  * Authors:
 19  *		Damon Chaplin <damon@ximian.com>
 20  *
 21  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 22  *
 23  */
 24 
 25 #ifdef HAVE_CONFIG_H
 26 #include <config.h>
 27 #endif
 28 
 29 #include "e-send-options-utils.h"
 30 
 31 #include <stdlib.h>
 32 #include <string.h>
 33 
 34 void
 35 e_send_options_utils_set_default_data (ESendOptionsDialog *sod,
 36                                        ESource *source,
 37                                        const gchar *type)
 38 {
 39 	ESendOptionsGeneral *gopts = NULL;
 40 	ESendOptionsStatusTracking *sopts;
 41 	ESourceExtension *extension;
 42 	const gchar *extension_name;
 43 	gchar *value;
 44 
 45 	/* FIXME These is all GroupWise-specific settings.
 46 	 *       They absolutely do not belong here. */
 47 
 48 	extension_name = "GroupWise Backend";
 49 
 50 	if (!e_source_has_extension (source, extension_name))
 51 		return;
 52 
 53 	extension = e_source_get_extension (source, extension_name);
 54 
 55 	gopts = sod->data->gopts;
 56 	sopts = sod->data->sopts;
 57 
 58 		/* priority */
 59 	g_object_get (extension, "priority", &value, NULL);
 60 	if (value) {
 61 		if (!strcmp (value, "high"))
 62 			gopts->priority = E_PRIORITY_HIGH;
 63 		else if (!strcmp (value, "standard"))
 64 			gopts->priority = E_PRIORITY_STANDARD;
 65 		else if (!strcmp (value, "low"))
 66 			gopts->priority = E_PRIORITY_LOW;
 67 		else
 68 			gopts->priority = E_PRIORITY_UNDEFINED;
 69 	}
 70 	g_free (value);
 71 
 72 		/* Reply requested */
 73 	g_object_get (extension, "reply-requested", &value, NULL);
 74 	if (value) {
 75 		if (!strcmp (value, "none"))
 76 			gopts->reply_enabled = FALSE;
 77 		else if (!strcmp (value, "convinient")) {
 78 			gopts->reply_enabled = TRUE;
 79 			gopts->reply_convenient = TRUE;
 80 		} else {
 81 			gint i = atoi (value);
 82 			gopts->reply_within = i;
 83 		}
 84 	}
 85 	g_free (value);
 86 
 87 		/* Delay delivery */
 88 	g_object_get (extension, "delivery-delay", &value, NULL);
 89 	if (value) {
 90 		if (!strcmp (value, "none"))
 91 			gopts->delay_enabled = FALSE;
 92 		else {
 93 			gopts->delay_enabled = TRUE;
 94 			gopts->delay_until = icaltime_as_timet (icaltime_from_string (value));
 95 		}
 96 	}
 97 	g_free (value);
 98 
 99 		/* Expiration Date */
100 	g_object_get (extension, "expiration", &value, NULL);
101 	if (value) {
102 		if (!strcmp (value, "none"))
103 			gopts->expiration_enabled = FALSE;
104 		else {
105 			gint i = atoi (value);
106 			if (i == 0)
107 				gopts->expiration_enabled = FALSE;
108 			else
109 				gopts->expiration_enabled = TRUE;
110 			gopts->expire_after = i;
111 		}
112 	}
113 	g_free (value);
114 
115 		/* status tracking */
116 	g_object_get (extension, "status-tracking", &value, NULL);
117 	if (value) {
118 		if (!strcmp (value, "none"))
119 			sopts->tracking_enabled = FALSE;
120 		else {
121 			sopts->tracking_enabled = TRUE;
122 			if (!strcmp (value, "delivered"))
123 				sopts->track_when = E_DELIVERED;
124 			else if (!strcmp (value, "delivered-opened"))
125 				sopts->track_when = E_DELIVERED_OPENED;
126 			else
127 				sopts->track_when = E_ALL;
128 		}
129 	}
130 	g_free (value);
131 
132 		/* Return Notifications */
133 
134 	g_object_get (extension, "return-open", &value, NULL);
135 	if (value) {
136 		if (!strcmp (value, "none"))
137 			sopts->opened = E_RETURN_NOTIFY_NONE;
138 		else
139 			sopts->opened = E_RETURN_NOTIFY_MAIL;
140 	}
141 	g_free (value);
142 
143 	g_object_get (extension, "return-accept", &value, NULL);
144 	if (value) {
145 		if (!strcmp (value, "none"))
146 			sopts->accepted = E_RETURN_NOTIFY_NONE;
147 		else
148 			sopts->accepted = E_RETURN_NOTIFY_MAIL;
149 	}
150 	g_free (value);
151 
152 	g_object_get (extension, "return-decline", &value, NULL);
153 	if (value) {
154 		if (!strcmp (value, "none"))
155 			sopts->declined = E_RETURN_NOTIFY_NONE;
156 		else
157 			sopts->declined = E_RETURN_NOTIFY_MAIL;
158 	}
159 	g_free (value);
160 
161 	g_object_get (extension, "return-complete", &value, NULL);
162 	if (value) {
163 		if (!strcmp (value, "none"))
164 			sopts->completed = E_RETURN_NOTIFY_NONE;
165 		else
166 			sopts->completed = E_RETURN_NOTIFY_MAIL;
167 	}
168 	g_free (value);
169 }
170 
171 void
172 e_send_options_utils_fill_component (ESendOptionsDialog *sod,
173                                      ECalComponent *comp,
174                                      icaltimezone *zone)
175 {
176 	gint i = 1;
177 	icalproperty *prop;
178 	icalcomponent *icalcomp;
179 	ESendOptionsGeneral *gopts;
180 	ESendOptionsStatusTracking *sopts;
181 
182 	gopts = sod->data->gopts;
183 	sopts = sod->data->sopts;
184 
185 	e_cal_component_set_sequence (comp, &i);
186 	icalcomp = e_cal_component_get_icalcomponent (comp);
187 
188 	if (e_send_options_get_need_general_options (sod)) {
189 		prop = icalproperty_new_x ((const gchar *) g_strdup_printf ("%d", gopts->priority));
190 		icalproperty_set_x_name (prop, "X-EVOLUTION-OPTIONS-PRIORITY");
191 		icalcomponent_add_property (icalcomp, prop);
192 
193 		if (gopts->reply_enabled) {
194 			if (gopts->reply_convenient)
195 				prop = icalproperty_new_x ("convenient");
196 			else
197 				prop = icalproperty_new_x ((const gchar *) g_strdup_printf ("%d", gopts->reply_within));
198 			icalproperty_set_x_name (prop, "X-EVOLUTION-OPTIONS-REPLY");
199 			icalcomponent_add_property (icalcomp, prop);
200 		}
201 
202 		if (gopts->expiration_enabled && gopts->expire_after) {
203 			prop = icalproperty_new_x ((const gchar *) g_strdup_printf ("%d", gopts->expire_after));
204 			icalproperty_set_x_name (prop, "X-EVOLUTION-OPTIONS-EXPIRE");
205 			icalcomponent_add_property (icalcomp, prop);
206 		}
207 
208 		if (gopts->delay_enabled) {
209 			struct icaltimetype temp;
210 			gchar *str;
211 
212 			temp = icaltime_from_timet_with_zone (gopts->delay_until, FALSE, zone);
213 
214 			str = icaltime_as_ical_string_r (temp);
215 			prop = icalproperty_new_x (str);
216 			g_free (str);
217 			icalproperty_set_x_name (prop, "X-EVOLUTION-OPTIONS-DELAY");
218 			icalcomponent_add_property (icalcomp, prop);
219 		}
220 	}
221 
222 	if (sopts->tracking_enabled)
223 		prop = icalproperty_new_x ((const gchar *) g_strdup_printf ("%d", sopts->track_when));
224 	else
225 		prop = icalproperty_new_x ("0");
226 
227 	icalproperty_set_x_name (prop, "X-EVOLUTION-OPTIONS-TRACKINFO");
228 	icalcomponent_add_property (icalcomp, prop);
229 
230 	prop = icalproperty_new_x ((const gchar *) g_strdup_printf ("%d", sopts->opened));
231 	icalproperty_set_x_name (prop, "X-EVOLUTION-OPTIONS-OPENED");
232 	icalcomponent_add_property (icalcomp, prop);
233 
234 	prop = icalproperty_new_x ((const gchar *) g_strdup_printf ("%d", sopts->accepted));
235 	icalproperty_set_x_name (prop, "X-EVOLUTION-OPTIONS-ACCEPTED");
236 	icalcomponent_add_property (icalcomp, prop);
237 
238 	prop = icalproperty_new_x ((const gchar *) g_strdup_printf ("%d", sopts->declined));
239 	icalproperty_set_x_name (prop, "X-EVOLUTION-OPTIONS-DECLINED");
240 	icalcomponent_add_property (icalcomp, prop);
241 
242 	prop = icalproperty_new_x ((const gchar *) g_strdup_printf ("%d", sopts->completed));
243 	icalproperty_set_x_name (prop, "X-EVOLUTION-OPTIONS-COMPLETED");
244 	icalcomponent_add_property (icalcomp, prop);
245 }