Dynamic LDAP queries
[claws.git] / src / addrbook.c
index 8df82763b09c93fe9d2f64407295d054f12aa010..e81625c91963df75d33949e155c45a271116b9ae 100644 (file)
@@ -61,6 +61,10 @@ AddressBookFile *addrbook_create_book()
        book->tempList = NULL;
        book->tempHash = NULL;
        book->addressCache->modified = TRUE;
+
+       /* We want to use an address completion index */
+       addrcache_use_index( book->addressCache, TRUE );
+
        return book;
 }
 
@@ -188,7 +192,6 @@ void addrbook_free_book(AddressBookFile *book)
        g_return_if_fail(book != NULL);
 
        /* Clear cache */
-       addrcache_clear(book->addressCache);
        addrcache_free(book->addressCache);
 
        /* Free up internal objects */
@@ -233,9 +236,9 @@ void addrbook_print_book(AddressBookFile *book, FILE *stream)
        g_return_if_fail(book != NULL);
 
        fprintf(stream, "AddressBook:\n");
-       fprintf(stream, "\t  path : '%s'\n", book->path);
-       fprintf(stream, "\t  file : '%s'\n", book->fileName);
-       fprintf(stream, "\tstatus : %d\n",   book->retVal );
+       fprintf(stream, "\tpath : '%s'\n", book->path);
+       fprintf(stream, "\tfile : '%s'\n", book->fileName);
+       fprintf(stream, "\tstatus : %d\n", book->retVal );
        addrcache_print(book->addressCache, stream);
 }
 
@@ -875,6 +878,9 @@ gint addrbook_read_data(AddressBookFile *book)
                book->addressCache->modified = FALSE;
                book->addressCache->dataRead = TRUE;
                addrcache_set_dirty(book->addressCache, FALSE);
+
+               /* Build address completion index */
+               addrcache_build_index( book->addressCache );
        }
        return book->retVal;
 }
@@ -1965,27 +1971,36 @@ GList *addrbook_get_all_persons(AddressBookFile *book)
        return addrcache_get_all_persons(book->addressCache);
 }
 
-/* Add person and address data to address book.
-   Enter: book      Address book.
-          folder    Folder where to add person, or NULL for root folder.
-          name      Common name.
-          address   EMail address.
-          remarks   Remarks.
-   Return: Person added. Do not *NOT* to use the addrbook_free_xxx() functions...
-   this will destroy the address book data */
+/**
+ * Add person and address data to address book.
+ * \param  book    Address book.
+ * \param  folder  Folder where to add person, or NULL for root folder.
+ * \param  name    Common name.
+ * \param  address EMail address.
+ * \param  remarks Remarks.
+ * \return Person added. Do not <b>*NOT*</b> to use the
+ *         <code>addrbook_free_xxx()</code> functions... this will destroy
+ *         the address book data.
+ */
 ItemPerson *addrbook_add_contact(AddressBookFile *book, ItemFolder *folder, 
                                 const gchar *name,const gchar *address, 
                                 const gchar *remarks)
 {
+       ItemPerson *person;
+
        g_return_val_if_fail(book != NULL, NULL);
-       return addrcache_add_contact(book->addressCache, folder, name, address, 
-                                    remarks);
+       person = addrcache_add_contact(
+                       book->addressCache, folder, name, address, remarks );
+       addrcache_invalidate( book->addressCache );
+       return person;
 }
 
-/* Return file name for next address book file.
-   Enter:  book Address book.
-   Return: File name, or NULL if could not create. This should be g_free()
-           when done */
+/**
+ * Return file name for next address book file.
+ * \param  book Address book.
+ * \return File name, or <i>NULL</i> if could not create. This should be
+ *         <code>g_free()</code> when done.
+ */
 gchar *addrbook_guess_next_file(AddressBookFile *book)
 {
        gchar *newFile = NULL;
@@ -2000,3 +2015,18 @@ gchar *addrbook_guess_next_file(AddressBookFile *book)
        fileList = NULL;
        return newFile;
 }
+
+/**
+ * Invalidate the address book data. This will cause index to be rebuilt.
+ * \param book Address book.
+ */
+void addrbook_invalidate( AddressBookFile *book ) {
+       g_return_if_fail( book != NULL );
+       addrcache_invalidate( book->addressCache );
+}
+
+/*
+* End of Source.
+*/
+
+