#include <gtk/gtkitemfactory.h>
#include <string.h>
#include <setjmp.h>
+#include <sys/types.h>
+#include <dirent.h>
#include "main.h"
#include "addressbook.h"
{ LDAPRC_NOENTRIES, N_("No LDAP entries found for search criteria") },
{ LDAPRC_STOP_FLAG, N_("LDAP search terminated on request") },
{ LDAPRC_TLS, N_("Error starting TLS connection") },
- { LDAPRC_NODN, N_("Distinguised Name (dn) is missing") },
+ { LDAPRC_NODN, N_("Distinguished Name (dn) is missing") },
{ LDAPRC_NAMING_VIOLATION, N_("Missing required information") },
{ LDAPRC_ALREADY_EXIST, N_("Another contact exists with that key") },
{ LDAPRC_STRONG_AUTH, N_("Strong(er) authentication required") },
item = node->data;
node = g_list_next( node );
aio = ( AddrItemObject * ) item->addressItem;
+ if (!aio)
+ continue;
if( aio->type == ADDR_ITEM_GROUP ) {
ItemGroup *item = ( ItemGroup * ) aio;
GtkCTreeNode *nd = NULL;
}
#endif
if( item ) {
+ gchar *filename = addritem_person_get_picture(item);
+ if (filename && is_file_exist(filename))
+ g_unlink(filename);
+ g_free(filename);
addritem_free_item_person( item );
}
}
static void addressbook_edit_address_post_cb( ItemPerson *person )
{
if( person ) {
-
+#ifdef USE_LDAP
+ if (strcmp2(person->nickName, ADDRITEM_NAME(person)))
+ addritem_person_set_nick_name( person, ADDRITEM_NAME(person));
+#endif
addressbook_folder_refresh_one_person( GTK_CTREE(addrbook.clist), person );
invalidate_address_completion();
}
return retVal;
}
+static gboolean migrate_addrbook(const gchar *origdir, const gchar *destdir)
+{
+ DIR *dp;
+ struct dirent *d;
+ gboolean failed = FALSE;
+
+ if( ( dp = opendir( origdir ) ) == NULL ) {
+ return FALSE;
+ }
+
+ while( ( d = readdir( dp ) ) != NULL ) {
+ if (strncmp(d->d_name, "addrbook-", strlen("addrbook-")))
+ continue;
+ else {
+ gchar *orig_file = g_strconcat(origdir, G_DIR_SEPARATOR_S,
+ d->d_name, NULL);
+ gchar *dest_file = g_strconcat(destdir, G_DIR_SEPARATOR_S,
+ d->d_name, NULL);
+ if (copy_file(orig_file, dest_file, FALSE) < 0) {
+ failed = TRUE;
+ }
+ g_free(orig_file);
+ g_free(dest_file);
+ if (failed) {
+ break;
+ }
+ }
+ }
+
+ closedir( dp );
+ if (!failed) {
+ /* all copies succeeded, we can remove source files */
+ if( ( dp = opendir( origdir ) ) == NULL ) {
+ return FALSE;
+ }
+ while( ( d = readdir( dp ) ) != NULL ) {
+ if (strncmp(d->d_name, "addrbook-", strlen("addrbook-")))
+ continue;
+ else {
+ gchar *orig_file = g_strconcat(origdir, G_DIR_SEPARATOR_S,
+ d->d_name, NULL);
+ g_unlink(orig_file);
+ g_free(orig_file);
+ }
+ }
+ closedir( dp );
+ }
+
+ return !failed;
+}
+
void addressbook_read_file( void ) {
AddressIndex *addrIndex = NULL;
-
+ gchar *indexdir = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, NULL);
+
debug_print( "Reading address index...\n" );
if( _addressIndex_ ) {
debug_print( "address book already read!!!\n" );
addrindex_initialize();
/* Use new address book index. */
- addrindex_set_file_path( addrIndex, get_rc_dir() );
+
+ if ( !is_dir_exist(indexdir) ) {
+ if ( make_dir(indexdir) < 0 ) {
+ addrindex_set_file_path( addrIndex, get_rc_dir() );
+ g_warning( "couldn't create dir %s\n", indexdir);
+ } else {
+ if (!migrate_addrbook(get_rc_dir(), indexdir)) {
+ remove_dir_recursive(indexdir);
+ addrindex_set_file_path( addrIndex, get_rc_dir() );
+ g_error("couldn't migrate dir %s", indexdir);
+ } else {
+ addrindex_set_file_path( addrIndex, indexdir);
+ }
+ }
+ } else {
+ addrindex_set_file_path( addrIndex, indexdir);
+ }
+ g_free(indexdir);
addrindex_set_file_name( addrIndex, ADDRESSBOOK_INDEX_FILE );
addrindex_read_data( addrIndex );
if( addrIndex->retVal == MGU_NO_FILE ) {
atci->showInTree = FALSE;
atci->treeExpand = FALSE;
atci->treeLeaf = TRUE;
- atci->displayName = _( "EMail Address" );
+ atci->displayName = _( "Email Address" );
atci->iconXpm = addressxpm;
atci->maskXpm = addressxpmmask;
atci->iconXpmOpen = addressxpm;
* This function is used by the Add sender to address book function.
*/
gboolean addressbook_add_contact(
- const gchar *name, const gchar *address, const gchar *remarks )
+ const gchar *name, const gchar *address, const gchar *remarks,
+ GdkPixbuf *picture )
{
debug_print( "addressbook_add_contact: name/address: %s - %s\n", name, address );
- if( addressadd_selection( _addressIndex_, name, address, remarks ) ) {
+ if( addressadd_selection( _addressIndex_, name, address, remarks, picture ) ) {
debug_print( "addressbook_add_contact - added\n" );
addressbook_refresh();
}
if( ds && ds->interface && ds->interface->readOnly)
gtk_selection_data_set(selection_data,
selection_data->target, 8,
- "Dummy_addr_copy", 15);
+ (const guchar *)"Dummy_addr_copy", 15);
else
gtk_selection_data_set(selection_data,
selection_data->target, 8,
- "Dummy_addr_move", 15);
+ (const guchar *)"Dummy_addr_move", 15);
}
}