From af7c0d4c4d5f20cc09dc7f709cd88c43dab567b8 Mon Sep 17 00:00:00 2001 From: hiro Date: Tue, 26 Jan 2010 09:41:32 +0000 Subject: implemented auto-registration of new recipients. git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@2442 ee746299-78ed-0310-b773-934348b2243d --- src/addressadd.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'src/addressadd.c') diff --git a/src/addressadd.c b/src/addressadd.c index cb5e3ae7..03d79c96 100644 --- a/src/addressadd.c +++ b/src/addressadd.c @@ -51,6 +51,7 @@ #include "addrindex.h" #include "editaddress.h" #include "manage_window.h" +#include "utils.h" typedef struct { AddressBookFile *book; @@ -361,6 +362,9 @@ gboolean addressadd_selection( AddressIndex *addrIndex, const gchar *name, const if( remarks ) gtk_label_set_text( GTK_LABEL(addressadd_dlg.label_remarks ), remarks ); + if( ! name ) + name = ""; + gtk_main(); gtk_widget_hide( addressadd_dlg.window ); @@ -382,6 +386,53 @@ gboolean addressadd_selection( AddressIndex *addrIndex, const gchar *name, const return retVal; } +gboolean addressadd_autoreg(AddressIndex *addrIndex, const gchar *name, + const gchar *address, const gchar *remarks) +{ + ItemPerson *person = NULL; + AddressInterface *interface = NULL; + AddressDataSource *ds = NULL; + AddressBookFile *abf = NULL; + GList *node_ds; + const gchar *ds_name; + + g_return_val_if_fail(address != NULL, FALSE); + + if (!name) + name = ""; + + interface = addrindex_get_interface(addrIndex, ADDR_IF_BOOK); + if (!interface) + return FALSE; + + for (node_ds = interface->listSource; node_ds != NULL; + node_ds = node_ds->next) { + ds = node_ds->data; + ds_name = addrindex_ds_get_name(ds); + if (!ds_name) + continue; + if (strcmp(ds_name, ADDR_DS_AUTOREG) != 0) + continue; + debug_print("addressadd_autoreg: AddressDataSource: %s found\n", ds_name); + + if (!addrindex_ds_get_read_flag(ds)) + addrindex_ds_read_data(ds); + abf = ds->rawDataSource; + } + + if (!abf) + return FALSE; + + person = addrbook_add_contact(abf, NULL, name, address, remarks); + if (person) { + debug_print("addressadd_autoreg: person added: %s <%s>\n", + name, address); + return TRUE; + } + + return FALSE; +} + /* * End of Source. */ -- cgit v1.2.3