2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2001-2002 Match Grun
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * General primitive address item objects.
32 * Create new email address item.
34 ItemEMail
*addritem_create_item_email( void ) {
36 item
= g_new0( ItemEMail
, 1 );
37 ADDRITEM_TYPE(item
) = ITEMTYPE_EMAIL
;
38 ADDRITEM_ID(item
) = NULL
;
39 ADDRITEM_NAME(item
) = NULL
;
40 ADDRITEM_PARENT(item
) = NULL
;
41 ADDRITEM_SUBTYPE(item
) = 0;
48 * Create a shallow copy of specified email address item.
49 * Enter: item E-Mail to copy.
51 ItemEMail
*addritem_copy_item_email( ItemEMail
*item
) {
52 ItemEMail
*itemNew
= NULL
;
54 itemNew
= addritem_create_item_email();
55 ADDRITEM_NAME(itemNew
) = g_strdup( ADDRITEM_NAME(item
) );
56 itemNew
->address
= g_strdup( item
->address
);
57 itemNew
->remarks
= g_strdup( item
->remarks
);
63 * Create a full copy of specified email address item.
64 * Enter: item E-Mail to copy.
66 ItemEMail
*addritem_copyfull_item_email( ItemEMail
*item
) {
67 ItemEMail
*itemNew
= NULL
;
69 itemNew
= addritem_create_item_email();
70 ADDRITEM_ID(itemNew
) = g_strdup( ADDRITEM_ID(item
) );
71 ADDRITEM_NAME(itemNew
) = g_strdup( ADDRITEM_NAME(item
) );
72 ADDRITEM_PARENT(itemNew
) = ADDRITEM_PARENT(item
);
73 itemNew
->address
= g_strdup( item
->address
);
74 itemNew
->remarks
= g_strdup( item
->remarks
);
79 void addritem_email_set_id( ItemEMail
*email
, const gchar
*value
) {
80 ADDRITEM_ID(email
) = mgu_replace_string( ADDRITEM_ID(email
), value
);
82 void addritem_email_set_alias( ItemEMail
*email
, const gchar
*value
) {
83 ADDRITEM_NAME(email
) = mgu_replace_string( ADDRITEM_NAME(email
), value
);
85 void addritem_email_set_address( ItemEMail
*email
, const gchar
*value
) {
86 email
->address
= mgu_replace_string( email
->address
, value
);
88 void addritem_email_set_remarks( ItemEMail
*email
, const gchar
*value
) {
89 email
->remarks
= mgu_replace_string( email
->remarks
, value
);
93 * Free address item email.
95 void addritem_free_item_email( ItemEMail
*item
) {
96 g_return_if_fail( item
!= NULL
);
98 /* Free internal stuff */
99 g_free( ADDRITEM_ID(item
) );
100 g_free( ADDRITEM_NAME(item
) );
101 g_free( item
->address
);
102 g_free( item
->remarks
);
104 ADDRITEM_OBJECT(item
)->type
= ITEMTYPE_NONE
;
105 ADDRITEM_ID(item
) = NULL
;
106 ADDRITEM_NAME(item
) = NULL
;
107 ADDRITEM_PARENT(item
) = NULL
;
108 ADDRITEM_SUBTYPE(item
) = 0;
109 item
->address
= NULL
;
110 item
->remarks
= NULL
;
115 * Create new attribute.
117 UserAttribute
*addritem_create_attribute( void ) {
119 item
= g_new0( UserAttribute
, 1 );
127 * Create copy of specified attribute.
129 UserAttribute
*addritem_copy_attribute( UserAttribute
*item
) {
130 UserAttribute
*itemNew
= NULL
;
132 itemNew
= addritem_create_attribute();
133 itemNew
->uid
= g_strdup( item
->uid
);
134 itemNew
->name
= g_strdup( item
->name
);
135 itemNew
->value
= g_strdup( item
->value
);
140 void addritem_attrib_set_id( UserAttribute
*item
, const gchar
*value
) {
141 g_return_if_fail( item
!= NULL
);
142 item
->uid
= mgu_replace_string( item
->uid
, value
);
144 void addritem_attrib_set_name( UserAttribute
*item
, const gchar
*value
) {
145 g_return_if_fail( item
!= NULL
);
146 item
->name
= mgu_replace_string( item
->name
, value
);
148 void addritem_attrib_set_value( UserAttribute
*item
, const gchar
*value
) {
149 g_return_if_fail( item
!= NULL
);
150 item
->value
= mgu_replace_string( item
->value
, value
);
154 * Free user attribute.
156 void addritem_free_attribute( UserAttribute
*item
) {
157 g_return_if_fail( item
!= NULL
);
159 g_free( item
->name
);
160 g_free( item
->value
);
168 * Create new address book person.
170 ItemPerson
*addritem_create_item_person( void ) {
172 person
= g_new0( ItemPerson
, 1 );
173 ADDRITEM_TYPE(person
) = ITEMTYPE_PERSON
;
174 ADDRITEM_ID(person
) = NULL
;
175 ADDRITEM_NAME(person
) = NULL
;
176 ADDRITEM_PARENT(person
) = NULL
;
177 ADDRITEM_SUBTYPE(person
) = 0;
178 person
->firstName
= NULL
;
179 person
->lastName
= NULL
;
180 person
->nickName
= NULL
;
181 person
->listEMail
= NULL
;
182 person
->listAttrib
= NULL
;
183 person
->externalID
= NULL
;
184 person
->isOpened
= FALSE
;
189 * Create a shallow copy of address book person.
190 * Enter: item Person to copy.
192 ItemPerson
*addritem_copy_item_person( ItemPerson
*item
) {
197 itemNew
= addritem_create_item_person();
198 ADDRITEM_NAME(itemNew
) = g_strdup( ADDRITEM_NAME(item
) );
199 itemNew
->firstName
= g_strdup( item
->firstName
);
200 itemNew
->lastName
= g_strdup( item
->lastName
);
201 itemNew
->nickName
= g_strdup( item
->nickName
);
202 itemNew
->externalID
= g_strdup( item
->externalID
);
207 void addritem_person_set_id( ItemPerson
*person
, const gchar
*value
) {
208 ADDRITEM_ID(person
) = mgu_replace_string( ADDRITEM_ID(person
), value
);
210 void addritem_person_set_first_name( ItemPerson
*person
, const gchar
*value
) {
211 person
->firstName
= mgu_replace_string( person
->firstName
, value
);
213 void addritem_person_set_last_name( ItemPerson
*person
, const gchar
*value
) {
214 person
->lastName
= mgu_replace_string( person
->lastName
, value
);
216 void addritem_person_set_nick_name( ItemPerson
*person
, const gchar
*value
) {
217 person
->nickName
= mgu_replace_string( person
->nickName
, value
);
219 void addritem_person_set_common_name( ItemPerson
*person
, const gchar
*value
) {
220 ADDRITEM_NAME(person
) = mgu_replace_string( ADDRITEM_NAME(person
), value
);
222 void addritem_person_set_external_id( ItemPerson
*person
, const gchar
*value
) {
223 person
->externalID
= mgu_replace_string( person
->externalID
, value
);
225 void addritem_person_set_opened( ItemPerson
*person
, const gboolean value
) {
226 person
->isOpened
= value
;
230 * Test whether person's data is empty.
231 * Enter: person Person to test.
232 * Return: TRUE if empty.
234 gboolean
addritem_person_empty( ItemPerson
*person
) {
237 if( person
== NULL
) return FALSE
;
239 t
= ADDRITEM_NAME(person
);
240 if( t
!= NULL
&& strlen( t
) > 0 ) return FALSE
;
242 t
= person
->firstName
;
243 if( t
!= NULL
&& strlen( t
) > 0 ) return FALSE
;
245 t
= person
->lastName
;
246 if( t
!= NULL
&& strlen( t
) > 0 ) return FALSE
;
248 t
= person
->nickName
;
249 if( t
!= NULL
&& strlen( t
) > 0 ) return FALSE
;
251 if( person
->listEMail
!= NULL
) return FALSE
;
252 if( person
->listAttrib
!= NULL
) return FALSE
;
258 * Free linked list of item addresses; both addresses and the list are freed.
259 * It is assumed that addresses are *NOT* contained within some other
261 * Enter: list List of addresses to be freed.
263 void addritem_free_list_email( GList
*list
) {
266 ItemEMail
*email
= node
->data
;
268 addritem_free_item_email( email
);
270 node
= g_list_next( node
);
277 * Free linked list of attributes.
279 void addritem_free_list_attribute( GList
*list
) {
282 addritem_free_attribute( node
->data
);
284 node
= g_list_next( node
);
290 * Free address person.
292 void addritem_free_item_person( ItemPerson
*person
) {
293 g_return_if_fail( person
!= NULL
);
295 /* Free internal stuff */
296 g_free( ADDRITEM_ID(person
) );
297 g_free( ADDRITEM_NAME(person
) );
298 g_free( person
->firstName
);
299 g_free( person
->lastName
);
300 g_free( person
->nickName
);
301 g_free( person
->externalID
);
302 g_list_free( person
->listEMail
);
303 addritem_free_list_attribute( person
->listAttrib
);
305 ADDRITEM_OBJECT(person
)->type
= ITEMTYPE_NONE
;
306 ADDRITEM_ID(person
) = NULL
;
307 ADDRITEM_NAME(person
) = NULL
;
308 ADDRITEM_PARENT(person
) = NULL
;
309 ADDRITEM_SUBTYPE(person
) = 0;
310 person
->firstName
= NULL
;
311 person
->lastName
= NULL
;
312 person
->nickName
= NULL
;
313 person
->externalID
= NULL
;
314 person
->listEMail
= NULL
;
315 person
->listAttrib
= NULL
;
321 * Print address item.
323 void addritem_print_item_email( ItemEMail
*item
, FILE *stream
) {
324 g_return_if_fail( item
!= NULL
);
325 fprintf( stream
, "\t\tt/id: %d : '%s'\n", ADDRITEM_TYPE(item
), ADDRITEM_ID(item
) );
326 fprintf( stream
, "\t\tsubty: %d\n", ADDRITEM_SUBTYPE(item
) );
327 fprintf( stream
, "\t\talis: '%s'\n", ADDRITEM_NAME(item
) );
328 fprintf( stream
, "\t\taddr: '%s'\n", item
->address
);
329 fprintf( stream
, "\t\trems: '%s'\n", item
->remarks
);
330 fprintf( stream
, "\t\t---\n" );
334 * Print user attribute.
336 void addritem_print_attribute( UserAttribute
*item
, FILE *stream
) {
337 g_return_if_fail( item
!= NULL
);
338 fprintf( stream
, "\t\tuid : '%s'\n", item
->uid
);
339 fprintf( stream
, "\t\tname : '%s'\n", item
->name
);
340 fprintf( stream
, "\t\tvalue: '%s'\n", item
->value
);
341 fprintf( stream
, "\t\t---\n" );
347 void addritem_print_item_person( ItemPerson
*person
, FILE *stream
) {
349 g_return_if_fail( person
!= NULL
);
350 fprintf( stream
, "Person:\n" );
351 fprintf( stream
, "\tt/uid: %d : '%s'\n", ADDRITEM_TYPE(person
), ADDRITEM_ID(person
) );
352 fprintf( stream
, "\tsubty: %d\n", ADDRITEM_SUBTYPE(person
) );
353 fprintf( stream
, "\tcommn: '%s'\n", ADDRITEM_NAME(person
) );
354 fprintf( stream
, "\tfirst: '%s'\n", person
->firstName
);
355 fprintf( stream
, "\tlast : '%s'\n", person
->lastName
);
356 fprintf( stream
, "\tnick : '%s'\n", person
->nickName
);
357 fprintf( stream
, "\textID: '%s'\n", person
->externalID
);
358 fprintf( stream
, "\teMail:\n" );
359 fprintf( stream
, "\t---\n" );
360 node
= person
->listEMail
;
362 addritem_print_item_email( node
->data
, stream
);
363 node
= g_list_next( node
);
365 fprintf( stream
, "\tuAttr:\n" );
366 fprintf( stream
, "\t---\n" );
367 node
= person
->listAttrib
;
369 addritem_print_attribute( node
->data
, stream
);
370 node
= g_list_next( node
);
372 fprintf( stream
, "\t===\n" );
376 * Add EMail address to person.
377 * return: TRUE if item added.
379 gboolean
addritem_person_add_email( ItemPerson
*person
, ItemEMail
*email
) {
382 g_return_val_if_fail( person
!= NULL
, FALSE
);
383 g_return_val_if_fail( email
!= NULL
, FALSE
);
385 node
= person
->listEMail
;
387 if( node
->data
== email
) return FALSE
;
388 node
= g_list_next( node
);
390 person
->listEMail
= g_list_append( person
->listEMail
, email
);
391 ADDRITEM_PARENT(email
) = ADDRITEM_OBJECT(person
);
396 * Return email object with specified ID.
397 * param: person Person object.
399 * return: EMail object, or NULL if not found.
401 ItemEMail
*addritem_person_get_email( ItemPerson
*person
, const gchar
*eid
) {
402 ItemEMail
*email
= NULL
;
405 g_return_val_if_fail( person
!= NULL
, NULL
);
406 if( eid
== NULL
|| *eid
== '\0' ) return NULL
;
409 node
= person
->listEMail
;
411 AddrItemObject
*objE
= node
->data
;
412 gchar
*ide
= ADDRITEM_ID(objE
);
414 if( strcmp( ide
, eid
) == 0 ) {
415 email
= ( ItemEMail
* ) objE
;
418 node
= g_list_next( node
);
424 * Remove email address for specified person.
425 * param: person Person object.
427 * return: EMail object, or NULL if not found. Note that object should still be freed.
429 ItemEMail
*addritem_person_remove_email_id( ItemPerson
*person
, const gchar
*eid
) {
430 ItemEMail
*email
= NULL
;
433 g_return_val_if_fail( person
!= NULL
, NULL
);
434 if( eid
== NULL
|| *eid
== '\0' ) return NULL
;
437 node
= person
->listEMail
;
439 AddrItemObject
*objE
= node
->data
;
440 gchar
*ide
= ADDRITEM_ID(objE
);
442 if( strcmp( ide
, eid
) == 0 ) {
443 email
= ( ItemEMail
* ) objE
;
446 node
= g_list_next( node
);
450 /* Remove email from person's address list */
451 if( person
->listEMail
) {
452 person
->listEMail
= g_list_remove( person
->listEMail
, email
);
454 /* Unlink reference to person. */
455 ADDRITEM_PARENT(email
) = NULL
;
461 * Remove email address for specified.
462 * param: person Person.
463 * email EMail to remove.
464 * return: EMail object, or NULL if not found. Note that object should still be freed.
466 ItemEMail
*addritem_person_remove_email( ItemPerson
*person
, ItemEMail
*email
) {
467 gboolean found
= FALSE
;
470 g_return_val_if_fail( person
!= NULL
, NULL
);
471 if( email
== NULL
) return NULL
;
474 node
= person
->listEMail
;
476 if( node
-> data
== email
) {
480 node
= g_list_next( node
);
484 /* Remove email from person's address list */
485 if( person
->listEMail
) {
486 person
->listEMail
= g_list_remove( person
->listEMail
, email
);
488 /* Unlink reference to person. */
489 ADDRITEM_PARENT(email
) = NULL
;
496 * Add user attribute to person.
497 * return: TRUE if item added.
499 void addritem_person_add_attribute( ItemPerson
*person
, UserAttribute
*attrib
) {
500 g_return_if_fail( person
!= NULL
);
501 person
->listAttrib
= g_list_append( person
->listAttrib
, attrib
);
505 * Return attribute with specified ID.
506 * param: person Person object.
508 * return: UserAttribute object, or NULL if not found. Note that object should still be freed.
510 UserAttribute
*addritem_person_get_attribute( ItemPerson
*person
, const gchar
*aid
) {
511 UserAttribute
*attrib
= NULL
;
514 g_return_val_if_fail( person
!= NULL
, NULL
);
515 if( aid
== NULL
|| *aid
== '\0' ) return NULL
;
517 /* Look for attribute */
518 node
= person
->listAttrib
;
520 UserAttribute
*attr
= node
->data
;
521 gchar
*ida
= attr
->uid
;
523 if( strcmp( ida
, aid
) == 0 ) {
527 node
= g_list_next( node
);
533 * Remove attribute from person.
534 * param: person Person object.
536 * return: UserAttribute object, or NULL if not found. Note that object should still be freed.
538 UserAttribute
*addritem_person_remove_attrib_id( ItemPerson
*person
, const gchar
*aid
) {
539 UserAttribute
*attrib
= NULL
;
542 g_return_val_if_fail( person
!= NULL
, NULL
);
543 if( aid
== NULL
|| *aid
== '\0' ) return NULL
;
545 /* Look for attribute */
546 node
= person
->listAttrib
;
548 UserAttribute
*attr
= node
->data
;
549 gchar
*ida
= attr
->uid
;
551 if( strcmp( ida
, aid
) == 0 ) {
555 node
= g_list_next( node
);
558 /* Remove email from person's address list */
559 if( person
->listAttrib
) {
560 person
->listAttrib
= g_list_remove( person
->listAttrib
, attrib
);
566 * Remove attribute from person.
567 * param: person Person.
568 * attrib Attribute to remove.
569 * return: UserAttribute object. Note that object should still be freed.
571 UserAttribute
*addritem_person_remove_attribute( ItemPerson
*person
, UserAttribute
*attrib
) {
572 gboolean found
= FALSE
;
575 g_return_val_if_fail( person
!= NULL
, NULL
);
576 if( attrib
== NULL
) return NULL
;
578 /* Look for attribute */
579 node
= person
->listAttrib
;
581 if( node
-> data
== attrib
) {
585 node
= g_list_next( node
);
589 /* Remove attribute */
590 if( person
->listAttrib
) {
591 person
->listAttrib
= g_list_remove( person
->listAttrib
, attrib
);
598 * Create new address book group.
600 ItemGroup
*addritem_create_item_group( void ) {
603 group
= g_new0( ItemGroup
, 1 );
604 ADDRITEM_TYPE(group
) = ITEMTYPE_GROUP
;
605 ADDRITEM_ID(group
) = NULL
;
606 ADDRITEM_NAME(group
) = NULL
;
607 ADDRITEM_PARENT(group
) = NULL
;
608 ADDRITEM_SUBTYPE(group
) = 0;
609 group
->remarks
= NULL
;
610 group
->listEMail
= NULL
;
615 * Copy address book group.
616 * Enter: item Group to copy.
617 * Return: A copy of the group.
619 ItemGroup
*addritem_copy_item_group( ItemGroup
*item
) {
622 itemNew
= g_new0( ItemGroup
, 1 );
624 itemNew
= addritem_create_item_group();
625 ADDRITEM_NAME(itemNew
) = g_strdup( ADDRITEM_NAME(item
) );
626 itemNew
->remarks
= g_strdup( item
->remarks
);
632 * Specify name to be used.
634 void addritem_group_set_id( ItemGroup
*group
, const gchar
*value
) {
635 ADDRITEM_ID(group
) = mgu_replace_string( ADDRITEM_ID(group
), value
);
637 void addritem_group_set_name( ItemGroup
*group
, const gchar
*value
) {
638 ADDRITEM_NAME(group
) = mgu_replace_string( ADDRITEM_NAME(group
), value
);
640 void addritem_group_set_remarks( ItemGroup
*group
, const gchar
*value
) {
641 group
->remarks
= mgu_replace_string( group
->remarks
, value
);
645 * Free address group.
647 void addritem_free_item_group( ItemGroup
*group
) {
648 g_return_if_fail( group
!= NULL
);
650 /* Free internal stuff */
651 g_free( ADDRITEM_ID(group
) );
652 g_free( ADDRITEM_NAME(group
) );
653 g_free( group
->remarks
);
654 mgu_clear_list( group
->listEMail
);
655 g_list_free( group
->listEMail
);
657 ADDRITEM_TYPE(group
) = ITEMTYPE_NONE
;
658 ADDRITEM_ID(group
) = NULL
;
659 ADDRITEM_NAME(group
) = NULL
;
660 ADDRITEM_PARENT(group
) = NULL
;
661 ADDRITEM_SUBTYPE(group
) = 0;
662 group
->remarks
= NULL
;
663 group
->listEMail
= NULL
;
669 * Add EMail address to group.
670 * return: TRUE if item added.
672 gboolean
addritem_group_add_email( ItemGroup
*group
, ItemEMail
*email
) {
675 g_return_val_if_fail( group
!= NULL
, FALSE
);
676 g_return_val_if_fail( email
!= NULL
, FALSE
);
678 node
= group
->listEMail
;
680 if( node
->data
== email
) return FALSE
;
681 node
= g_list_next( node
);
683 group
->listEMail
= g_list_append( group
->listEMail
, email
);
688 * Remove email address for specified group.
689 * param: group Group from which to remove address.
690 * email EMail to remove
691 * return: EMail object, or NULL if email not found in group. Note that this object is
692 * referenced (linked) to a group and should *NOT* be freed. This object should only be
693 * freed after removing from a person.
695 ItemEMail
*addritem_group_remove_email( ItemGroup
*group
, ItemEMail
*email
) {
696 if( group
&& email
) {
697 GList
*node
= group
->listEMail
;
699 if( node
->data
== email
) {
700 group
->listEMail
= g_list_remove( group
->listEMail
, email
);
703 node
= g_list_next( node
);
710 * Remove email address for specified group and ID.
711 * param: group Group from which to remove address.
713 * return: EMail object, or NULL if email not found in group. Note that this object is
714 * referenced (linked) to a group and should *NOT* be freed. This object should only be
715 * freed after removing from a person.
717 ItemEMail
*addritem_group_remove_email_id( ItemGroup
*group
, const gchar
*eid
) {
719 GList
*node
= group
->listEMail
;
721 ItemEMail
*email
= ( ItemEMail
* ) node
->data
;
722 if( strcmp( ADDRITEM_ID( email
), eid
) == 0 ) {
723 group
->listEMail
= g_list_remove( group
->listEMail
, email
);
726 node
= g_list_next( node
);
733 * Print address group item.
735 void addritem_print_item_group( ItemGroup
*group
, FILE *stream
) {
739 g_return_if_fail( group
!= NULL
);
740 fprintf( stream
, "Group:\n" );
741 fprintf( stream
, "\tt/u: %d : '%s'\n", ADDRITEM_TYPE(group
), ADDRITEM_ID(group
) );
742 fprintf( stream
, "\tsub: %d\n", ADDRITEM_SUBTYPE(group
) );
743 fprintf( stream
, "\tgrp: '%s'\n", ADDRITEM_NAME(group
) );
744 fprintf( stream
, "\trem: '%s'\n", group
->remarks
);
745 fprintf( stream
, "\t---\n" );
746 node
= group
->listEMail
;
749 person
= ( ItemPerson
* ) ADDRITEM_PARENT(item
);
751 fprintf( stream
, "\t\tpid : '%s'\n", ADDRITEM_ID(person
) );
752 fprintf( stream
, "\t\tcomn: '%s'\n", ADDRITEM_NAME(person
) );
755 fprintf( stream
, "\t\tpid : ???\n" );
756 fprintf( stream
, "\t\tcomn: ???\n" );
758 addritem_print_item_email( item
, stream
);
759 node
= g_list_next( node
);
761 fprintf( stream
, "\t***\n" );
765 * Create new address folder.
767 ItemFolder
*addritem_create_item_folder( void ) {
769 folder
= g_new0( ItemFolder
, 1 );
770 ADDRITEM_TYPE(folder
) = ITEMTYPE_FOLDER
;
771 ADDRITEM_ID(folder
) = NULL
;
772 ADDRITEM_NAME(folder
) = NULL
;
773 ADDRITEM_PARENT(folder
) = NULL
;
774 ADDRITEM_SUBTYPE(folder
) = 0;
775 folder
->remarks
= NULL
;
776 folder
->isRoot
= FALSE
;
777 folder
->listItems
= NULL
;
778 folder
->listFolder
= NULL
;
779 folder
->listPerson
= NULL
;
780 folder
->listGroup
= NULL
;
785 * Copy address book folder.
786 * Enter: item Folder to copy.
787 * Return: A copy of the folder.
789 ItemFolder
*addritem_copy_item_folder( ItemFolder
*item
) {
792 itemNew
= g_new0( ItemFolder
, 1 );
794 itemNew
= addritem_create_item_folder();
795 ADDRITEM_NAME(itemNew
) = g_strdup( ADDRITEM_NAME(item
) );
801 * Specify name to be used.
803 void addritem_folder_set_id( ItemFolder
*folder
, const gchar
*value
) {
804 ADDRITEM_ID(folder
) = mgu_replace_string( ADDRITEM_ID(folder
), value
);
806 void addritem_folder_set_name( ItemFolder
*folder
, const gchar
*value
) {
807 ADDRITEM_NAME(folder
) = mgu_replace_string( ADDRITEM_NAME(folder
), value
);
809 void addritem_folder_set_remarks( ItemFolder
*folder
, const gchar
*value
) {
810 folder
->remarks
= mgu_replace_string( folder
->remarks
, value
);
814 * Free address folder. Note: this does not free up the lists of children
815 * (folders, groups and person). This should be done prior to calling this
818 void addritem_free_item_folder( ItemFolder
*folder
) {
819 g_return_if_fail( folder
!= NULL
);
821 /* Free internal stuff */
822 g_free( ADDRITEM_ID(folder
) );
823 g_free( ADDRITEM_NAME(folder
) );
824 g_free( folder
->remarks
);
825 mgu_clear_list( folder
->listItems
);
826 g_list_free( folder
->listItems
);
828 ADDRITEM_TYPE(folder
) = ITEMTYPE_NONE
;
829 ADDRITEM_ID(folder
) = NULL
;
830 ADDRITEM_NAME(folder
) = NULL
;
831 ADDRITEM_PARENT(folder
) = NULL
;
832 ADDRITEM_SUBTYPE(folder
) = 0;
833 folder
->isRoot
= FALSE
;
834 folder
->remarks
= NULL
;
835 folder
->listItems
= NULL
;
836 folder
->listFolder
= NULL
;
837 folder
->listGroup
= NULL
;
838 folder
->listPerson
= NULL
;
844 * Free up folders recursively. Note: this does not free up the lists of children
845 * (folders, groups and person). This should be done prior to calling this
848 void addritem_free_item_folder_recurse( ItemFolder
*parent
) {
849 GList
*node
= parent
->listFolder
;
852 ItemFolder
*folder
= node
->data
;
853 addritem_free_item_folder_recurse( folder
);
854 node
= g_list_next( node
);
856 g_list_free( parent
->listPerson
);
857 g_list_free( parent
->listGroup
);
858 g_list_free( parent
->listFolder
);
859 parent
->listPerson
= NULL
;
860 parent
->listGroup
= NULL
;
861 parent
->listFolder
= NULL
;
865 * Free up list of persons in specified folder.
867 void addritem_folder_free_person( ItemFolder
*folder
) {
870 g_return_if_fail( folder
!= NULL
);
872 /* Free up folder of persons. */
873 node
= folder
->listPerson
;
875 ItemPerson
*person
= node
->data
;
876 addritem_free_item_person( person
);
878 node
= g_list_next( node
);
883 * Add person into folder.
884 * return: TRUE if person added.
886 gboolean
addritem_folder_add_person( ItemFolder
*folder
, ItemPerson
*item
) {
887 g_return_val_if_fail( folder
!= NULL
, FALSE
);
888 g_return_val_if_fail( item
!= NULL
, FALSE
);
890 folder
->listPerson
= g_list_append( folder
->listPerson
, item
);
891 ADDRITEM_PARENT(item
) = ADDRITEM_OBJECT(folder
);
896 * Add folder into folder.
897 * return: TRUE if folder added.
899 gboolean
addritem_folder_add_folder( ItemFolder
*folder
, ItemFolder
*item
) {
900 g_return_val_if_fail( folder
!= NULL
, FALSE
);
901 g_return_val_if_fail( item
!= NULL
, FALSE
);
903 folder
->listFolder
= g_list_append( folder
->listFolder
, item
);
904 ADDRITEM_PARENT(item
) = ADDRITEM_OBJECT(folder
);
909 * Add group into folder.
910 * return: TRUE if folder added.
912 gboolean
addritem_folder_add_group( ItemFolder
*folder
, ItemGroup
*item
) {
913 g_return_val_if_fail( folder
!= NULL
, FALSE
);
914 g_return_val_if_fail( item
!= NULL
, FALSE
);
916 folder
->listGroup
= g_list_append( folder
->listGroup
, item
);
917 ADDRITEM_PARENT(item
) = ADDRITEM_OBJECT(folder
);
922 * Print address folder item.
924 void addritem_print_item_folder( ItemFolder
*folder
, FILE *stream
) {
926 /* ItemPerson *person; */
929 g_return_if_fail( folder
!= NULL
);
931 fprintf( stream
, "Folder:\n" );
932 fprintf( stream
, "\tt/u: %d : '%s'\n", ADDRITEM_TYPE(folder
), ADDRITEM_ID(folder
) );
933 fprintf( stream
, "\tsub: %d\n", ADDRITEM_SUBTYPE(folder
) );
934 fprintf( stream
, "\tnam: '%s'\n", ADDRITEM_NAME(folder
) );
935 fprintf( stream
, "\trem: '%s'\n", folder
->remarks
);
936 fprintf( stream
, "\t---\n" );
937 parent
= ( ItemFolder
* ) ADDRITEM_PARENT(folder
);
939 fprintf( stream
, "\tpar: %s : %s\n", ADDRITEM_ID(parent
), ADDRITEM_NAME(parent
) );
942 fprintf( stream
, "\tpar: NULL\n" );
944 node
= folder
->listFolder
;
946 AddrItemObject
*aio
= node
->data
;
948 if( aio
->type
== ITEMTYPE_FOLDER
) {
949 ItemFolder
*item
= ( ItemFolder
* ) aio
;
950 addritem_print_item_folder( item
, stream
);
954 fprintf( stream
, "\t\tpid : ???\n" );
957 node
= g_list_next( node
);
960 node
= folder
->listPerson
;
962 AddrItemObject
*aio
= node
->data
;
964 if( aio
->type
== ITEMTYPE_PERSON
) {
965 ItemPerson
*item
= ( ItemPerson
* ) aio
;
966 addritem_print_item_person( item
, stream
);
970 fprintf( stream
, "\t\tpid : ???\n" );
973 node
= g_list_next( node
);
976 node
= folder
->listGroup
;
978 AddrItemObject
*aio
= node
->data
;
980 if( aio
->type
== ITEMTYPE_GROUP
) {
981 ItemGroup
*item
= ( ItemGroup
* ) aio
;
982 addritem_print_item_group( item
, stream
);
986 fprintf( stream
, "\t\tpid : ???\n" );
988 node
= g_list_next( node
);
990 fprintf( stream
, "\t###\n" );
994 * Print address item.
996 void addritem_print_item( AddrItemObject
*aio
, FILE *stream
) {
997 g_return_if_fail( aio
!= NULL
);
999 if( aio
->type
== ITEMTYPE_PERSON
) {
1000 ItemPerson
*item
= ( ItemPerson
* ) aio
;
1001 addritem_print_item_person( item
, stream
);
1003 else if( aio
->type
== ITEMTYPE_EMAIL
) {
1004 ItemEMail
*item
= ( ItemEMail
* ) aio
;
1005 addritem_print_item_email( item
, stream
);
1007 else if( aio
->type
== ITEMTYPE_GROUP
) {
1008 ItemGroup
*item
= ( ItemGroup
* ) aio
;
1009 addritem_print_item_group( item
, stream
);
1011 else if( aio
->type
== ITEMTYPE_FOLDER
) {
1012 ItemFolder
*item
= ( ItemFolder
* ) aio
;
1013 addritem_print_item_folder( item
, stream
);
1018 * Return link list of persons for specified folder. Note that the list contains
1019 * references to items and should be g_free() when done. Do *NOT* attempt to use the
1020 * addritem_free_xxx() functions... this will destroy the addressbook data!
1021 * Return: List of items, or NULL if none.
1023 GList
*addritem_folder_get_person_list( ItemFolder
*folder
) {
1027 g_return_val_if_fail( folder
!= NULL
, NULL
);
1029 node
= folder
->listPerson
;
1031 ItemPerson
*person
= node
->data
;
1032 list
= g_list_append( list
, person
);
1033 node
= g_list_next( node
);
1039 * Return link list of groups for specified folder. Note that the list contains
1040 * references to items and should be g_free() when done. Do *NOT* attempt to use the
1041 * addritem_free_xxx() functions... this will destroy the addressbook data!
1042 * Return: List of items, or NULL if none.
1044 GList
*addritem_folder_get_group_list( ItemFolder
*folder
) {
1048 g_return_val_if_fail( folder
!= NULL
, NULL
);
1050 node
= folder
->listGroup
;
1052 ItemGroup
*group
= node
->data
;
1053 list
= g_list_append( list
, group
);
1054 node
= g_list_next( node
);
1060 * Move person's email item.
1061 * param: person Person.
1062 * itemMove Item to move.
1063 * itemTarget Target item before which to move item.
1066 ItemEMail
*addritem_move_email_before( ItemPerson
*person
, ItemEMail
*itemMove
, ItemEMail
*itemTarget
) {
1069 g_return_val_if_fail( person
!= NULL
, NULL
);
1071 if( itemTarget
== NULL
) return NULL
;
1072 if( itemMove
== NULL
) return NULL
;
1073 if( itemMove
== itemTarget
) return itemMove
;
1075 posT
= g_list_index( person
->listEMail
, itemTarget
);
1076 if( posT
< 0 ) return NULL
;
1077 posM
= g_list_index( person
->listEMail
, itemMove
);
1078 if( posM
< 0 ) return NULL
;
1079 person
->listEMail
= g_list_remove( person
->listEMail
, itemMove
);
1080 person
->listEMail
= g_list_insert( person
->listEMail
, itemMove
, posT
);
1085 * Move person's email item.
1086 * param: person Person.
1087 * itemMove Item to move.
1088 * itemTarget Target item after which to move item.
1090 ItemEMail
*addritem_move_email_after( ItemPerson
*person
, ItemEMail
*itemMove
, ItemEMail
*itemTarget
) {
1093 g_return_val_if_fail( person
!= NULL
, NULL
);
1095 if( itemTarget
== NULL
) return NULL
;
1096 if( itemMove
== NULL
) return NULL
;
1097 if( itemMove
== itemTarget
) return itemMove
;
1099 posT
= g_list_index( person
->listEMail
, itemTarget
);
1100 if( posT
< 0 ) return NULL
;
1101 posM
= g_list_index( person
->listEMail
, itemMove
);
1102 if( posM
< 0 ) return NULL
;
1103 person
->listEMail
= g_list_remove( person
->listEMail
, itemMove
);
1104 person
->listEMail
= g_list_insert( person
->listEMail
, itemMove
, 1+posT
);
1109 * Parse first and last names for person from common name.
1110 * Enter: person Person to process.
1112 void addritem_parse_first_last( ItemPerson
*person
) {
1114 gchar
*fName
, *lName
;
1118 g_return_if_fail( person
!= NULL
);
1120 name
= ADDRITEM_NAME(person
);
1121 if( name
== NULL
) return;
1125 p
= strchr( name
, ',' );
1127 len
= ( size_t ) ( p
- name
);
1128 lName
= g_strndup( name
, len
);
1129 fName
= g_strdup( p
+ 1 );
1132 /* Other way around */
1135 if( name
[i
] == ' ' ) {
1136 fName
= g_strndup( name
, i
);
1137 lName
= g_strdup( &name
[i
] );
1142 if( fName
== NULL
) {
1143 fName
= g_strdup( name
);
1147 if( person
->firstName
) {
1148 g_free( person
->firstName
);
1150 person
->firstName
= fName
;
1151 if( person
->firstName
)
1152 g_strstrip( person
->firstName
);
1154 if( person
->lastName
) {
1155 g_free( person
->lastName
);
1157 person
->lastName
= lName
;
1158 if( person
->lastName
)
1159 g_strstrip( person
->lastName
);
1163 * Build a path of all ancestor folders for specified folder.
1164 * Enter: folder Folder.
1165 * seq Path sequence, FALSE top down, TRUE bottom up.
1166 * Return: List of folders from the top down.
1168 GList
*addritem_folder_path( const ItemFolder
*folder
, const gboolean seq
) {
1170 AddrItemObject
*item
;
1173 item
= ( AddrItemObject
* ) folder
;
1176 list
= g_list_prepend( list
, item
);
1177 item
= ADDRITEM_PARENT( item
);
1182 list
= g_list_append( list
, item
);
1183 item
= ADDRITEM_PARENT( item
);