1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
4 * JP Rosevear <jpr@ximian.com>
5 * Rodrigo Moya <rodrigo@ximian.com>
7 * Copyright 2003, Novell, Inc.
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU Lesser General Public
11 * License as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
28 #include "e-gw-container.h"
29 #include "e-gw-message.h"
31 struct _EGwContainerPrivate {
41 EGwContainerType type ;
44 gboolean is_frequent_contacts; /*indicates whether this folder is frequent contacts or not */
45 gboolean is_shared_by_me;
46 gboolean is_shared_to_me;
50 static GObjectClass *parent_class = NULL;
52 static void e_gw_container_set_sequence (EGwContainer *container, int sequence);
53 static void e_gw_container_set_modified (EGwContainer *container, const char *modified);
54 static void e_gw_container_set_owner(EGwContainer *container, const char *owner);
55 static void e_gw_container_set_is_shared_by_me (EGwContainer *container, gboolean is_shared_by_me);
56 static void e_gw_container_set_is_shared_to_me (EGwContainer *container, gboolean is_shared_to_me);
59 free_node(EShUsers *user)
70 e_gw_container_dispose (GObject *object)
72 EGwContainer *container = (EGwContainer *) object;
74 g_return_if_fail (E_IS_GW_CONTAINER (container));
76 if (parent_class->dispose)
77 (* parent_class->dispose) (object);
81 e_gw_container_finalize (GObject *object)
83 EGwContainer *container = (EGwContainer *) object;
84 EGwContainerPrivate *priv;
86 g_return_if_fail (E_IS_GW_CONTAINER (container));
88 priv = container->priv;
101 g_free (priv->parent);
106 g_free (priv->owner);
110 if (priv->modified) {
111 g_free (priv->modified);
112 priv->modified = NULL;
115 if(priv->user_list) {
116 g_list_foreach (priv->user_list,(GFunc) free_node, NULL);
117 g_list_free (priv->user_list);
118 priv->user_list = NULL;
122 container->priv = NULL;
125 if (parent_class->finalize)
126 (* parent_class->finalize) (object);
130 e_gw_container_class_init (EGwContainerClass *klass)
132 GObjectClass *object_class = G_OBJECT_CLASS (klass);
134 parent_class = g_type_class_peek_parent (klass);
136 object_class->dispose = e_gw_container_dispose;
137 object_class->finalize = e_gw_container_finalize;
141 e_gw_container_init (EGwContainer *container, EGwContainerClass *klass)
143 EGwContainerPrivate *priv;
145 /* allocate internal structure */
146 priv = g_new0 (EGwContainerPrivate, 1);
147 priv->is_writable = TRUE;
148 priv->is_frequent_contacts = FALSE;
149 container->priv = priv;
153 e_gw_container_get_type (void)
155 static GType type = 0;
158 static GTypeInfo info = {
159 sizeof (EGwContainerClass),
160 (GBaseInitFunc) NULL,
161 (GBaseFinalizeFunc) NULL,
162 (GClassInitFunc) e_gw_container_class_init,
164 sizeof (EGwContainer),
166 (GInstanceInitFunc) e_gw_container_init
168 type = g_type_register_static (G_TYPE_OBJECT, "EGwContainer", &info, 0);
175 e_gw_container_new_from_soap_parameter (SoupSoapParameter *param)
177 EGwContainer *container;
179 g_return_val_if_fail (param != NULL, NULL);
181 container = g_object_new (E_TYPE_GW_CONTAINER, NULL);
182 if (!e_gw_container_set_from_soap_parameter (container, param)) {
183 g_object_unref (container);
191 e_gw_container_set_from_soap_parameter (EGwContainer *container, SoupSoapParameter *param)
196 gboolean byme = FALSE;
197 gboolean tome = FALSE;
198 SoupSoapParameter *subparam;
199 SoupSoapParameter *entry_subparam;
200 SoupSoapParameter *email_rt_subparam;
201 SoupSoapParameter *rights_subparam;
203 g_return_val_if_fail (E_IS_GW_CONTAINER (container), FALSE);
204 g_return_val_if_fail (param != NULL, FALSE);
206 /* retrieve the name */
207 subparam = soup_soap_parameter_get_first_child_by_name (param, "name");
209 g_warning (G_STRLOC ": found container with no name");
213 value = soup_soap_parameter_get_string_value (subparam);
214 e_gw_container_set_name (container, (const char *) value);
217 /* retrieve the ID */
218 subparam = soup_soap_parameter_get_first_child_by_name (param, "id");
220 g_warning (G_STRLOC ": found container with no ID");
224 value = soup_soap_parameter_get_string_value (subparam);
225 e_gw_container_set_id (container, (const char *) value);
228 /* retrieve the parent container id */
229 subparam = soup_soap_parameter_get_first_child_by_name (param, "parent");
231 e_gw_container_set_parent_id (container, "");
232 container->priv->is_root = TRUE ;
235 value = soup_soap_parameter_get_string_value (subparam);
236 e_gw_container_set_parent_id (container, (const char *) value);
240 /*retrieve the folder type*/
241 subparam = soup_soap_parameter_get_first_child_by_name (param, "folderType") ;
243 container->priv->type = E_GW_CONTAINER_TYPE_FOLDER ;
245 value = soup_soap_parameter_get_string_value (subparam);
246 if (!strcmp (value, "Root"))
247 container->priv->type = E_GW_CONTAINER_TYPE_ROOT ;
248 else if (!strcmp (value, "Mailbox"))
249 container->priv->type = E_GW_CONTAINER_TYPE_INBOX ;
250 else if (!strcmp (value, "SentItems"))
251 container->priv->type = E_GW_CONTAINER_TYPE_SENT;
252 else if (!strcmp (value, "Calendar"))
253 container->priv->type = E_GW_CONTAINER_TYPE_CALENDAR ;
254 else if (!strcmp (value, "Contacts"))
255 container->priv->type = E_GW_CONTAINER_TYPE_CONTACTS ;
256 else if (!strcmp (value, "Draft"))
257 container->priv->type = E_GW_CONTAINER_TYPE_DRAFT ;
258 else if (!strcmp (value, "Trash"))
259 container->priv->type = E_GW_CONTAINER_TYPE_TRASH ;
260 else if (!strcmp (value, "JunkMail"))
261 container->priv->type = E_GW_CONTAINER_TYPE_JUNK;
265 /* retrive the unread and total count */
266 subparam = soup_soap_parameter_get_first_child_by_name (param, "hasUnread") ;
268 container->priv->unread = 0 ;
270 subparam = soup_soap_parameter_get_first_child_by_name (param, "unreadCount") ;
272 value = soup_soap_parameter_get_string_value (subparam) ;
274 container->priv->unread = atoi(value) ;
276 container->priv->unread = 0 ; /*XXX:should it be 0?*/
282 subparam = soup_soap_parameter_get_first_child_by_name (param, "count") ;
284 value = soup_soap_parameter_get_string_value (subparam) ;
286 container->priv->total = atoi(value) ;
290 subparam = soup_soap_parameter_get_first_child_by_name (param, "isSharedByMe");
292 e_gw_container_set_is_shared_by_me(container, FALSE);
295 value = soup_soap_parameter_get_string_value (subparam);
297 e_gw_container_set_is_shared_by_me (container, TRUE);
300 e_gw_container_set_is_shared_by_me (container, FALSE);
307 subparam = soup_soap_parameter_get_first_child_by_name (param, "isSharedToMe");
310 e_gw_container_set_is_shared_to_me (container, FALSE);
313 value = soup_soap_parameter_get_string_value (subparam);
315 e_gw_container_set_is_shared_to_me (container, TRUE);
318 e_gw_container_set_is_shared_to_me (container, FALSE);
324 /*Retrieve email add of the sharing person*/
326 subparam = soup_soap_parameter_get_first_child_by_name (param, "acl");
328 g_warning (G_STRLOC ": No ACL");
331 for (entry_subparam = soup_soap_parameter_get_first_child_by_name (subparam, "entry");
332 entry_subparam != NULL;
333 entry_subparam = soup_soap_parameter_get_next_child_by_name (entry_subparam, "entry")) {
335 EShUsers *user = g_new0(EShUsers , 1);
336 email_rt_subparam = soup_soap_parameter_get_first_child_by_name (entry_subparam, "email");
338 if (!email_rt_subparam) {
339 g_warning (G_STRLOC ":Email Tag Not Available");
341 value = soup_soap_parameter_get_string_value (email_rt_subparam);
346 email_rt_subparam = soup_soap_parameter_get_first_child_by_name (entry_subparam, "rights");
348 if (!email_rt_subparam)
349 g_warning (G_STRLOC ": User without any Rights");
352 rights_subparam = soup_soap_parameter_get_first_child_by_name (email_rt_subparam, "add");
354 rights = rights | 0x1;
356 rights_subparam = soup_soap_parameter_get_first_child_by_name (email_rt_subparam, "edit");
358 rights = rights | 0x2;
360 rights_subparam = soup_soap_parameter_get_first_child_by_name (email_rt_subparam, "delete");
362 rights = rights | 0x4;
364 user->rights = rights;
367 container->priv->user_list = g_list_append (container->priv->user_list, user);
376 subparam = soup_soap_parameter_get_first_child_by_name (param, "owner");
378 value = soup_soap_parameter_get_string_value (subparam);
379 e_gw_container_set_owner (container, value);
385 /*Retrieve When Modified last*/
386 subparam = soup_soap_parameter_get_first_child_by_name (param, "modified");
389 value = soup_soap_parameter_get_string_value (subparam);
390 e_gw_container_set_modified (container, (const char *) value);
394 /*retrieve sequence*/
395 subparam = soup_soap_parameter_get_first_child_by_name (param, "sequence");
398 int_value = soup_soap_parameter_get_int_value (subparam);
399 e_gw_container_set_sequence (container, int_value);
406 e_gw_container_get_user_list (EGwContainer *container, GList **user_list)
408 g_return_if_fail (E_GW_CONTAINER (container));
410 *user_list = container->priv->user_list;
415 e_gw_container_get_sequence (EGwContainer *container)
417 g_return_val_if_fail (E_IS_GW_CONTAINER (container), 0);
419 return (int)container->priv->sequence;
423 e_gw_container_set_sequence (EGwContainer *container, int sequence)
425 g_return_if_fail (E_IS_GW_CONTAINER (container));
426 container->priv->sequence = sequence;
430 e_gw_container_get_modified (EGwContainer *container)
432 g_return_val_if_fail (E_IS_GW_CONTAINER (container), NULL);
434 return (const char *) container->priv->modified;
438 e_gw_container_set_modified (EGwContainer *container, const char *modified)
440 EGwContainerPrivate *priv;
442 g_return_if_fail (E_IS_GW_CONTAINER (container));
443 g_return_if_fail (modified != NULL);
445 priv = container->priv;
448 g_free (priv->modified);
449 priv->modified = g_strdup (modified);
453 e_gw_container_set_owner(EGwContainer *container, const char *owner)
455 EGwContainerPrivate *priv;
457 g_return_if_fail (E_IS_GW_CONTAINER(container));
458 g_return_if_fail (owner!=NULL);
460 priv = container->priv;
462 g_free (container->priv->owner);
463 container->priv->owner = g_strdup (owner);
467 e_gw_container_get_owner (EGwContainer *container)
469 g_return_val_if_fail (E_GW_CONTAINER (container), NULL);
471 return (const char *) container->priv->owner;
475 e_gw_container_get_rights (EGwContainer *container, gchar *email)
477 GList *user_list = NULL;
479 EShUsers *user = NULL;
481 g_return_val_if_fail (E_IS_GW_CONTAINER (container), 0);
483 user_list = container->priv->user_list;
485 for (node = user_list; node != NULL; node = node->next) {
487 if( !strcmp (user->email, email))
495 e_gw_container_get_is_shared_by_me (EGwContainer *container)
497 g_return_val_if_fail (E_IS_GW_CONTAINER (container), FALSE);
499 return (gboolean) container->priv->is_shared_by_me;
503 e_gw_container_set_is_shared_by_me (EGwContainer *container, gboolean is_shared_by_me)
505 g_return_if_fail (E_IS_GW_CONTAINER (container));
507 container->priv->is_shared_by_me = is_shared_by_me;
511 e_gw_container_get_is_shared_to_me (EGwContainer *container)
513 g_return_val_if_fail (E_IS_GW_CONTAINER (container), FALSE);
515 return (gboolean) container->priv->is_shared_to_me;
519 e_gw_container_set_is_shared_to_me (EGwContainer *container, gboolean is_shared_to_me)
521 g_return_if_fail (E_IS_GW_CONTAINER (container));
523 container->priv->is_shared_to_me = is_shared_to_me;
527 e_gw_container_get_name (EGwContainer *container)
529 g_return_val_if_fail (E_IS_GW_CONTAINER (container), NULL);
531 return (const char *) container->priv->name;
535 e_gw_container_set_name (EGwContainer *container, const char *new_name)
537 EGwContainerPrivate *priv;
539 g_return_if_fail (E_IS_GW_CONTAINER (container));
540 g_return_if_fail (new_name != NULL);
542 priv = container->priv;
546 priv->name = g_strdup (new_name);
550 e_gw_container_get_id (EGwContainer *container)
552 g_return_val_if_fail (E_IS_GW_CONTAINER (container), NULL);
554 return (const char *) container->priv->id;
558 e_gw_container_set_id (EGwContainer *container, const char *new_id)
560 EGwContainerPrivate *priv;
562 g_return_if_fail (E_IS_GW_CONTAINER (container));
563 g_return_if_fail (new_id != NULL);
565 priv = container->priv;
569 priv->id = g_strdup (new_id);
573 e_gw_container_get_parent_id (EGwContainer *container)
575 g_return_val_if_fail (E_IS_GW_CONTAINER (container), NULL);
577 return (const char *) container->priv->parent;
581 e_gw_container_set_parent_id (EGwContainer *container, const char *parent_id)
583 EGwContainerPrivate *priv ;
585 g_return_if_fail (E_IS_GW_CONTAINER (container));
586 g_return_if_fail (parent_id != NULL);
588 priv = container->priv ;
591 g_free (priv->parent) ;
593 priv->parent = g_strdup (parent_id) ;
597 e_gw_container_get_total_count (EGwContainer *container)
599 g_return_val_if_fail (E_IS_GW_CONTAINER (container), -1) ;
601 return container->priv->total ;
605 e_gw_container_get_unread_count (EGwContainer *container)
607 g_return_val_if_fail (E_IS_GW_CONTAINER (container), -1) ;
609 return container->priv->unread ;
615 e_gw_container_get_is_writable (EGwContainer *container)
617 g_return_val_if_fail (E_IS_GW_CONTAINER (container), FALSE);
619 return container->priv->is_writable;
624 e_gw_container_set_is_writable (EGwContainer *container, gboolean is_writable)
626 g_return_if_fail (E_IS_GW_CONTAINER (container));
628 container->priv->is_writable = is_writable;
632 e_gw_container_get_is_frequent_contacts (EGwContainer *container)
634 g_return_val_if_fail (E_IS_GW_CONTAINER (container), FALSE);
636 return container->priv->is_frequent_contacts;
641 e_gw_container_set_is_frequent_contacts (EGwContainer *container, gboolean is_frequent_contacts)
643 g_return_if_fail (E_IS_GW_CONTAINER (container));
645 container->priv->is_frequent_contacts = is_frequent_contacts;
649 e_gw_container_is_root (EGwContainer *container)
651 g_return_val_if_fail (E_IS_GW_CONTAINER (container), FALSE) ;
653 return container->priv->is_root ;
657 e_gw_container_get_container_type (EGwContainer *container)
659 g_return_val_if_fail (E_IS_GW_CONTAINER (container), FALSE) ;
660 return container->priv->type ;
663 /* flag specifies whether we are adding to acl or deleting one or more entries*/
664 /* flag = 1 :delete entry
665 * flag = 2 :update entry
666 * flag = 0 :add to acl
669 e_gw_container_form_message (SoupSoapMessage *msg, gchar *id, GList *new_list, const char *sub, const char *mesg, int flag)
671 gboolean add, edit, del;
674 EShUsers *user = NULL;
676 e_gw_message_write_string_parameter (msg, "id", NULL, id);
677 soup_soap_message_start_element (msg, "notification", NULL, NULL);
678 e_gw_message_write_string_parameter (msg, "subject", NULL, sub);
679 e_gw_message_write_string_parameter (msg, "message", NULL, mesg);
680 soup_soap_message_end_element (msg);
681 soup_soap_message_start_element (msg, "updates", NULL, NULL);
684 soup_soap_message_start_element (msg, "add", NULL, NULL);
685 soup_soap_message_start_element (msg, "acl", NULL, NULL);
687 for (node = new_list; node != NULL; node = node->next) {
690 soup_soap_message_start_element (msg, "entry", NULL, NULL);
691 e_gw_message_write_string_parameter (msg, "displayName", NULL,"");
692 email = g_strdup (user->email);
693 if (user->rights & 0x1)
695 if (user->rights & 0x2)
697 if (user->rights & 0x4)
700 e_gw_message_write_string_parameter (msg, "email", NULL, email);
701 soup_soap_message_start_element (msg, "rights", NULL, NULL);
702 e_gw_message_write_int_parameter (msg, "read", NULL, 1);
703 e_gw_message_write_int_parameter (msg, "add", NULL, add);
704 e_gw_message_write_int_parameter (msg, "edit", NULL, edit);
705 e_gw_message_write_int_parameter (msg, "delete", NULL, del);
707 soup_soap_message_end_element (msg);
708 soup_soap_message_end_element (msg);
711 soup_soap_message_end_element (msg);
712 soup_soap_message_end_element (msg);
714 } else if (flag == 1) {
715 soup_soap_message_start_element (msg, "delete", NULL, NULL);
716 soup_soap_message_start_element (msg, "acl", NULL, NULL);
718 for (node = new_list; node != NULL; node = node->next) {
720 add = edit = del = FALSE;
721 soup_soap_message_start_element (msg, "entry", NULL, NULL);
722 e_gw_message_write_string_parameter (msg, "displayName", NULL, "name");
723 email = g_strdup (user->email);
725 if(user->rights & 0x1)
727 if(user->rights & 0x2)
729 if(user->rights & 0x4)
732 e_gw_message_write_string_parameter (msg, "email", NULL, email);
733 soup_soap_message_start_element(msg, "rights", NULL, NULL);
734 e_gw_message_write_int_parameter (msg, "read", NULL, 1);
735 e_gw_message_write_int_parameter (msg, "add", NULL, add);
736 e_gw_message_write_int_parameter (msg, "edit", NULL, edit);
737 e_gw_message_write_int_parameter (msg, "delete", NULL, del);
739 soup_soap_message_end_element (msg);
740 soup_soap_message_end_element (msg);
743 soup_soap_message_end_element (msg);
744 soup_soap_message_end_element (msg);
746 } else if (flag == 2) {
747 soup_soap_message_start_element (msg, "update", NULL, NULL);
748 soup_soap_message_start_element (msg, "acl", NULL, NULL);
750 for (node = new_list; node != NULL; node = node->next) {
752 add = edit = del = FALSE;
753 soup_soap_message_start_element (msg, "entry", NULL, NULL);
754 e_gw_message_write_string_parameter (msg, "displayName",NULL,"");
755 email = g_strdup (user->email);
756 if (user->rights & 0x1)
758 if (user->rights & 0x2)
760 if (user->rights & 0x4)
763 e_gw_message_write_string_parameter (msg, "email", NULL, email);
764 soup_soap_message_start_element (msg, "rights", NULL, NULL);
765 e_gw_message_write_int_parameter (msg, "read", NULL, 1);
766 e_gw_message_write_int_parameter (msg, "add", NULL, add);
767 e_gw_message_write_int_parameter (msg, "edit", NULL, edit);
768 e_gw_message_write_int_parameter (msg, "delete", NULL, del);
770 soup_soap_message_end_element (msg);
771 soup_soap_message_end_element (msg);
774 soup_soap_message_end_element (msg);
775 soup_soap_message_end_element (msg);
779 soup_soap_message_end_element (msg);