AddressBookFile *addressbook_imp_ldif_file( AddressIndex *addrIndex, const gchar *file, const gchar *book_name ) { gchar *fsfile; GList *node, *list; gboolean ret = FALSE; g_return_val_if_fail(addrIndex != NULL, NULL); g_return_val_if_fail(file != NULL, NULL); g_return_val_if_fail(book_name != NULL, NULL); debug_print("addressbook_imp_ldif_file: file: %s name: %s\n", file, book_name); _importedBook_ = NULL; _imp_addressIndex_ = addrIndex; _ldifFile_ = ldif_create(); fsfile = conv_filename_from_utf8( file ); ldif_set_file(_ldifFile_, fsfile); g_free( fsfile ); if( ldif_read_tags( _ldifFile_ ) != MGU_SUCCESS ) goto finish; list = ldif_get_fieldlist( _ldifFile_ ); node = list; while( node ) { Ldif_FieldRec *rec = node->data; if( ! rec->reserved ) { if( g_ascii_strcasecmp( rec->tagName, "dn" ) != 0 ) { rec->selected = TRUE; } } node = g_list_next( node ); } g_list_free( list ); g_free( impldif_dlg.nameBook ); impldif_dlg.nameBook = g_strdup(book_name); ret = imp_ldif_field_move(); g_free( impldif_dlg.nameBook ); impldif_dlg.nameBook = NULL; finish: ldif_free( _ldifFile_ ); _ldifFile_ = NULL; _imp_addressIndex_ = NULL; if (ret) debug_print("addressbook_imp_ldif_file: import succeeded\n"); return _importedBook_; }
/* * Move off fields page. * return: TRUE if OK to move off page. */ static gboolean imp_ldif_file_move() { gboolean retVal = FALSE; gchar *sName; gchar *sFile; gchar *sMsg = NULL; gboolean errFlag = FALSE; sFile = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.file_entry), 0, -1 ); g_strchug( sFile ); g_strchomp( sFile ); sName = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.name_entry), 0, -1 ); g_strchug( sName ); g_strchomp( sName ); g_free( impldif_dlg.nameBook ); g_free( impldif_dlg.fileName ); impldif_dlg.nameBook = sName; impldif_dlg.fileName = sFile; gtk_entry_set_text( GTK_ENTRY(impldif_dlg.file_entry), sFile ); gtk_entry_set_text( GTK_ENTRY(impldif_dlg.name_entry), sName ); if( *sFile == '\0'|| strlen( sFile ) < 1 ) { sMsg = _( "Please select a file." ); gtk_widget_grab_focus(impldif_dlg.file_entry); errFlag = TRUE; } if( *sName == '\0'|| strlen( sName ) < 1 ) { if( ! errFlag ) sMsg = _( "Address book name must be supplied." ); gtk_widget_grab_focus(impldif_dlg.name_entry); errFlag = TRUE; } if( ! errFlag ) { gchar *sFSFile; /* Read attribute list */ sFSFile = conv_filename_from_utf8( sFile ); ldif_set_file( _ldifFile_, sFSFile ); g_free( sFSFile ); if( ldif_read_tags( _ldifFile_ ) == MGU_SUCCESS ) { /* Load fields */ /* ldif_print_file( _ldifFile_, stdout ); */ imp_ldif_load_fields( _ldifFile_ ); retVal = TRUE; } else { sMsg = _( "Error reading LDIF fields." ); } } imp_ldif_status_show( sMsg ); return retVal; }
/** * Test whether we can move off file page. * \return <i>TRUE</i> if OK to move off page. */ static gboolean imp_ldif_file_move() { gboolean retVal = FALSE; gchar *sName; gchar *sFile; gchar *sMsg = NULL; gboolean errFlag = FALSE; sFile = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.entryFile), 0, -1 ); g_strstrip( sFile ); sName = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.entryName), 0, -1 ); g_strstrip( sName ); g_free( impldif_dlg.nameBook ); g_free( impldif_dlg.fileName ); impldif_dlg.nameBook = sName; impldif_dlg.fileName = sFile; gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryFile), sFile ); gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryName), sName ); if( *sFile == '\0' ) { sMsg = _( "Please select a file." ); gtk_widget_grab_focus(impldif_dlg.entryFile); errFlag = TRUE; } if( ! errFlag && *sName == '\0' ) { sMsg = _( "Address book name must be supplied." ); gtk_widget_grab_focus(impldif_dlg.entryName); errFlag = TRUE; } if( ! errFlag ) { /* Read attribute list */ ldif_set_file( _ldifFile_, sFile ); if( ldif_read_tags( _ldifFile_ ) == MGU_SUCCESS ) { /* Load fields */ /* ldif_print_file( _ldifFile_, stdout ); */ imp_ldif_load_fields( _ldifFile_ ); retVal = TRUE; } else { sMsg = imp_ldif_err2string( _lutErrorsLDIF_, _ldifFile_->retVal ); } } imp_ldif_status_show( sMsg ); return retVal; }