improvements to support cut/paste
authorMatch Grun <match@dimensional.com>
Tue, 6 Aug 2002 05:52:56 +0000 (05:52 +0000)
committerMatch Grun <match@dimensional.com>
Tue, 6 Aug 2002 05:52:56 +0000 (05:52 +0000)
ChangeLog.claws
configure.in
src/addrbook.c
src/addrcache.c
src/addritem.c
src/addritem.h
src/editaddress.c
src/vcard.c

index 96a1f59108628df8511cd029c7ae43f75effeac2..ae039bb5c89375ced5bb4ef3b1e8a13a04bd4760 100644 (file)
@@ -1,3 +1,12 @@
+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]
index 39e6acd1cc78d4ee33d424ec4c060e74056b5217..6fa504d8b95dbf36db4843c085fc272364e6b649 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=8
 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
index b51ad901704544643627019773e763af87ddce72..89e4506b2864196ab7fc18a8ec9739b5f19ccf7c 100644 (file)
@@ -1180,9 +1180,11 @@ ItemEMail *addrbook_move_email_after( AddressBookFile *book, ItemPerson *person,
 }
 
 /*
-* 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;
@@ -1193,36 +1195,22 @@ static gboolean addrbook_free_simple_hash_vis( gpointer *key, gpointer *value, g
 * 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;
@@ -1234,6 +1222,7 @@ void addrbook_update_address_list( AddressBookFile *book, ItemPerson *person, GL
                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 );
@@ -1253,12 +1242,15 @@ void addrbook_update_address_list( AddressBookFile *book, ItemPerson *person, GL
                        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 */
@@ -1281,23 +1273,63 @@ void addrbook_update_address_list( AddressBookFile *book, ItemPerson *person, GL
                                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;
 
 }
 
index ae82b4fcf525b23e43d7717b296f7526f37ed41f..eb87c1162674342eb30618b93e1df3d6b2c58f7f 100644 (file)
@@ -161,10 +161,13 @@ void addrcache_refresh( AddressCache *cache ) {
 */
 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 );
        }
@@ -955,11 +958,15 @@ void addrcache_person_move_email(
                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;
                }
        }
 }
index 2a440e05a16733eee339662b3945b960d390f7de..bc0d4a91a1561b59f62adc5958138390207bcc2d 100644 (file)
@@ -227,16 +227,50 @@ void addritem_person_set_opened( ItemPerson *person, const gboolean value ) {
 }
 
 /*
-* 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;
 }
 
 /*
@@ -265,7 +299,7 @@ void addritem_free_item_person( ItemPerson *person ) {
        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;
@@ -828,7 +862,7 @@ void addritem_free_item_folder_recurse( ItemFolder *parent ) {
 }
 
 /*
-* 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;
index 910f7d71615425cada1ccacfc6d8cde60660d305..df4ca39533eef13785903cccd187dee2b9643ab8 100644 (file)
@@ -125,6 +125,7 @@ void addritem_person_set_common_name        ( ItemPerson *person, const gchar *value );
 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 );
 
index 55ab6254f2991dd53b3f601e34938a4097baa873..6e62db7399dcebe85d0e8f4af1cd2abf4f2920fc 100644 (file)
@@ -986,6 +986,7 @@ ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent, I
        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;
@@ -993,7 +994,7 @@ ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent, I
 
        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 );
        }
@@ -1008,8 +1009,10 @@ ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent, I
                        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 );
@@ -1025,8 +1028,6 @@ ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent, I
        }
        g_free( cn );
 
-       listEMail = NULL;
-
        gtk_clist_clear( GTK_CLIST(personeditdlg.clist_email) );
        gtk_clist_clear( GTK_CLIST(personeditdlg.clist_attrib) );
 
index 55a8bedeef05f475b5228bbaf9acddce458a1350..6ea67452fbabb7e5ac75d8fabb42082ad93a28d6 100644 (file)
@@ -350,8 +350,9 @@ static gchar *vcard_get_tagvalue( gchar* line, gchar dlm ) {
 /*
 * 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;
@@ -370,7 +371,8 @@ static void vcard_build_items( VCardFile *cardFile, GSList *listName, GSList *li
                                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 );
                                                }
                                        }
                                }
@@ -383,14 +385,14 @@ static void vcard_build_items( VCardFile *cardFile, GSList *listName, GSList *li
                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 );
        }