+2002-08-05 [match] 0.8.0claws20
+
+ * src/addritem.[ch]
+ * src/addrcache.c
+ * src/addrbook.c
+ * src/editaddress.c
+ * src/addressbook.c
+ fixes to improve cut/copy/paste
+
2002-08-06 [melvin] 0.8.0claws19
* src/account.[ch]
MICRO_VERSION=1
INTERFACE_AGE=0
BINARY_AGE=0
-EXTRA_VERSION=claws19
+EXTRA_VERSION=claws20
VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
dnl set $target
}
/*
-* Hash table visitor function.
+* Hash table visitor function for deletion of hashtable entries.
*/
-static gboolean addrbook_free_simple_hash_vis( gpointer *key, gpointer *value, gpointer *data ) {
+static gboolean addrbook_free_simple_hash_vis(
+ gpointer *key, gpointer *value, gpointer *data )
+{
g_free( key );
key = NULL;
value = NULL;
* Update address book email list for specified person.
* Enter: book Address book.
* person Person to update.
-* listEMail New list of email addresses.
+* listEMail List of new email addresses.
* Note: The existing email addresses are replaced with the new addresses. Any references
* to old addresses in the groups are re-linked to the new addresses. All old addresses
* linked to the person are removed.
*/
-void addrbook_update_address_list( AddressBookFile *book, ItemPerson *person, GList *listEMail ) {
+void addrbook_update_address_list(
+ AddressBookFile *book, ItemPerson *person, GList *listEMail )
+{
GList *node;
- GList *oldData;
+ GList *listDelete;
GList *listGroup;
g_return_if_fail( book != NULL );
g_return_if_fail( person != NULL );
- /* Remember old list */
- oldData = person->listEMail;
-
- /* Attach new address list to person. */
- node = listEMail;
- while( node ) {
- ItemEMail *email = node->data;
- if( ADDRITEM_ID(email) == NULL ) {
- /* Allocate an ID */
- addrcache_id_email( book->addressCache, email );
- }
- ADDRITEM_PARENT(email) = ADDRITEM_OBJECT(person);
- node = g_list_next( node );
- }
- person->listEMail = listEMail;
-
- /* Get groups where person's email is listed */
+ /* Get groups where person's existing email addresses are listed */
listGroup = addrcache_get_group_for_person( book->addressCache, person );
if( listGroup ) {
GHashTable *hashEMail;
while( node ) {
ItemEMail *email = node->data;
gchar *addr = g_strdup( email->address );
+
g_strdown( addr );
if( ! g_hash_table_lookup( hashEMail, addr ) ) {
g_hash_table_insert( hashEMail, addr, email );
nodeGrpEM = groupEMail;
while( nodeGrpEM ) {
ItemEMail *emailGrp = ( ItemEMail * ) nodeGrpEM->data;
+
if( ADDRITEM_PARENT(emailGrp) == ADDRITEM_OBJECT(person) ) {
/* Found an email address for this person */
ItemEMail *emailNew = NULL;
gchar *addr = g_strdup( emailGrp->address );
+
g_strdown( addr );
- emailNew = ( ItemEMail * ) g_hash_table_lookup( hashEMail, addr );
+ emailNew = ( ItemEMail * )
+ g_hash_table_lookup( hashEMail, addr );
g_free( addr );
if( emailNew ) {
/* Point to this entry */
nodeGrpEM = g_list_next( nodeGrpEM );
}
+ g_list_free( listRemove );
+
/* Move on to next group */
nodeGrp = g_list_next( nodeGrp );
}
/* Clear hash table */
- g_hash_table_foreach_remove( hashEMail, ( GHRFunc ) addrbook_free_simple_hash_vis, NULL );
+ g_hash_table_foreach_remove(
+ hashEMail, ( GHRFunc ) addrbook_free_simple_hash_vis, NULL );
g_hash_table_destroy( hashEMail );
hashEMail = NULL;
g_list_free( listGroup );
listGroup = NULL;
}
+
+ /* Remove old addresses from person and cache */
+ listDelete = NULL;
+ node = person->listEMail;
+ while( node ) {
+ ItemEMail *email = node->data;
+
+ if( addrcache_person_remove_email( book->addressCache, person, email ) ) {
+ addrcache_remove_email( book->addressCache, email );
+ }
+ listDelete = g_list_append( listDelete, email );
+ node = person->listEMail;
+ }
+
+ /* Add new address entries */
+ node = listEMail;
+ while( node ) {
+ ItemEMail *email = node->data;
+
+ if( ADDRITEM_ID(email) == NULL ) {
+ /* Allocate an ID for new address */
+ addrcache_id_email( book->addressCache, email );
+ }
+ addrcache_person_add_email( book->addressCache, person, email );
+ node = g_list_next( node );
+ }
+
addrcache_set_dirty( book->addressCache, TRUE );
- /* Free up old data */
- addritem_free_list_email( oldData );
- oldData = NULL;
+ /* Free up memory */
+ g_list_free( listEMail );
+ listEMail = NULL;
+
+ node = listDelete;
+ while( node ) {
+ ItemEMail *email = node->data;
+
+ addritem_free_item_email( email );
+ node = g_list_next( node );
+ }
+ g_list_free( listDelete );
+ listDelete = NULL;
}
*/
static gint addrcache_free_item_vis( gpointer key, gpointer value, gpointer data ) {
AddrItemObject *obj = ( AddrItemObject * ) value;
+
if( ADDRITEM_TYPE(obj) == ITEMTYPE_PERSON ) {
- /* Free person and their email */
addritem_free_item_person( ( ItemPerson * ) obj );
}
+ else if( ADDRITEM_TYPE(obj) == ITEMTYPE_EMAIL ) {
+ addritem_free_item_email( ( ItemEMail * ) obj );
+ }
else if( ADDRITEM_TYPE(obj) == ITEMTYPE_GROUP ) {
addritem_free_item_group( ( ItemGroup * ) obj );
}
ItemEMail *found;
found = addritem_person_remove_email( person, email );
if( found ) {
+ /*
if( person->listEMail ) {
person->listEMail = g_list_remove( person->listEMail, found );
addritem_person_add_email( target, found );
cache->dirtyFlag = TRUE;
}
+ */
+ addritem_person_add_email( target, found );
+ cache->dirtyFlag = TRUE;
}
}
}
}
/*
-* Free linked list of item addresses.
-*/
+ * Test whether person's data is empty.
+ * Enter: person Person to test.
+ * Return: TRUE if empty.
+ */
+gboolean addritem_person_empty( ItemPerson *person ) {
+ gchar *t;
+
+ if( person == NULL ) return FALSE;
+
+ t = ADDRITEM_NAME(person);
+ if( t != NULL && strlen( t ) > 0 ) return FALSE;
+
+ t = person->firstName;
+ if( t != NULL && strlen( t ) > 0 ) return FALSE;
+
+ t = person->lastName;
+ if( t != NULL && strlen( t ) > 0 ) return FALSE;
+
+ t = person->nickName;
+ if( t != NULL && strlen( t ) > 0 ) return FALSE;
+
+ if( person->listEMail != NULL ) return FALSE;
+ if( person->listAttrib != NULL ) return FALSE;
+
+ return TRUE;
+}
+
+/*
+ * Free linked list of item addresses; both addresses and the list are freed.
+ * It is assumed that addresses are *NOT* contained within some other
+ * container.
+ * Enter: list List of addresses to be freed.
+ */
void addritem_free_list_email( GList *list ) {
GList *node = list;
while( node ) {
- addritem_free_item_email( node->data );
+ ItemEMail *email = node->data;
+
+ addritem_free_item_email( email );
node->data = NULL;
node = g_list_next( node );
}
g_list_free( list );
+ list = NULL;
}
/*
g_free( person->lastName );
g_free( person->nickName );
g_free( person->externalID );
- addritem_free_list_email( person->listEMail );
+ g_list_free( person->listEMail );
addritem_free_list_attribute( person->listAttrib );
ADDRITEM_OBJECT(person)->type = ITEMTYPE_NONE;
}
/*
-* Free up list of person in specified folder.
+* Free up list of persons in specified folder.
*/
void addritem_folder_free_person( ItemFolder *folder ) {
GList *node;
void addritem_person_set_external_id ( ItemPerson *person, const gchar *value );
void addritem_person_set_opened ( ItemPerson *person, const gboolean value );
void addritem_free_item_person ( ItemPerson *person );
+gboolean addritem_person_empty ( ItemPerson *person );
void addritem_free_list_email ( GList *list );
void addritem_free_list_attribute ( GList *list );
listAttrib = edit_person_build_attrib_list();
if( cancelled ) {
addritem_free_list_email( listEMail );
+ addritem_free_list_attribute( listAttrib );
gtk_clist_clear( GTK_CLIST(personeditdlg.clist_email) );
gtk_clist_clear( GTK_CLIST(personeditdlg.clist_attrib) );
return NULL;
cn = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_name), 0, -1 );
if( person ) {
- /* Update email/attribute list */
+ /* Update email/attribute list for existing person */
addrbook_update_address_list( abf, person, listEMail );
addrbook_update_attrib_list( abf, person, listAttrib );
}
addrbook_add_attrib_list( abf, person, listAttrib );
}
}
+ listEMail = NULL;
+ listAttrib = NULL;
- if( !cancelled ) {
+ if( ! cancelled ) {
/* Set person stuff */
gchar *name;
addritem_person_set_common_name( person, cn );
}
g_free( cn );
- listEMail = NULL;
-
gtk_clist_clear( GTK_CLIST(personeditdlg.clist_email) );
gtk_clist_clear( GTK_CLIST(personeditdlg.clist_attrib) );
/*
* Build an address list entry and append to list of address items.
*/
-static void vcard_build_items( VCardFile *cardFile, GSList *listName, GSList *listAddr, GSList *listRem,
- GSList *listID )
+static void vcard_build_items(
+ VCardFile *cardFile, GSList *listName, GSList *listAddr,
+ GSList *listRem, GSList *listID )
{
GSList *nodeName = listName;
GSList *nodeID = listID;
if( nodeRemarks ) {
if( str ) {
if( g_strcasecmp( str, "internet" ) != 0 ) {
- if( *str != '\0' ) addritem_email_set_remarks( email, str );
+ if( *str != '\0' )
+ addritem_email_set_remarks( email, str );
}
}
}
if( person->listEMail ) {
addrcache_id_person( cardFile->addressCache, person );
addrcache_add_person( cardFile->addressCache, person );
+ if( nodeID ) {
+ str = nodeID->data;
+ addritem_person_set_external_id( person, str );
+ }
}
else {
addritem_free_item_person( person );
}
- if( nodeID ) {
- str = nodeID->data;
- addritem_person_set_external_id( person, str );
- }
nodeName = g_slist_next( nodeName );
nodeID = g_slist_next( nodeID );
}