Ejemplo n.º 1
0
/*
* ============================================================================================
* Read file into list. Main entry point
* Return: TRUE if file read successfully.
* ============================================================================================
*/
gint jpilot_read_data( JPilotFile *pilotFile ) {
	name_order = FAMILY_LAST;
	convert_charcode = FALSE;

	if( conv_is_ja_locale() ) {
		name_order = FAMILY_FIRST;
		convert_charcode = TRUE;
	}

	g_return_val_if_fail( pilotFile != NULL, -1 );

	pilotFile->retVal = MGU_SUCCESS;
	pilotFile->accessFlag = FALSE;

	if( jpilot_check_files( pilotFile ) ) {
		addrcache_clear( pilotFile->addressCache );
		jpilot_read_metadata( pilotFile );
		if( pilotFile->retVal == MGU_SUCCESS ) {
			jpilot_setup_labels( pilotFile );
			jpilot_build_category_list( pilotFile );
			pilotFile->retVal = jpilot_read_file( pilotFile );
			if( pilotFile->retVal == MGU_SUCCESS ) {
				jpilot_remove_empty( pilotFile );
				jpilot_mark_files( pilotFile );
				pilotFile->addressCache->modified = FALSE;
				pilotFile->addressCache->dataRead = TRUE;
			}
		}
	}
	return pilotFile->retVal;
}
Ejemplo n.º 2
0
/**
 * Read address file into address cache.
 * \param pilotFile  JPilot control data.
 * \return Error/status code. <code>MGU_SUCCESS</code> if data read
 *         successfully.
 */
static gint jpilot_read_file( JPilotFile *pilotFile ) {
	gint retVal, i;
	GList *records = NULL;
	GList *node;
	buf_rec *br;
	ItemFolder *folderInd[ JPILOT_NUM_CATEG ];

	/* Read list of records from JPilot files */
	retVal = jpilot_read_db_files( pilotFile, &records );
	if( retVal != MGU_SUCCESS ) {
		jpilot_free_addrlist( records );
		return retVal;
	}

	/* Setup labels and category folders */
	jpilot_setup_labels( pilotFile );
	jpilot_build_category_list( pilotFile );

	/* Build array of pointers to categories */
	i = 0;
	node = addrcache_get_list_folder( pilotFile->addressCache );
	while( node ) {
		if( i < JPILOT_NUM_CATEG ) {
			folderInd[i] = node->data;
		}
		node = g_list_next( node );
		i++;
	}

	/* Load all addresses, free up old stuff as we go */
	node = records;
	while( node ) {
		br = node->data;
		if( ( br->rt != DELETED_PC_REC ) &&
		    ( br->rt != DELETED_PALM_REC ) &&
		    ( br->rt != MODIFIED_PALM_REC ) &&
		    ( br->rt != DELETED_DELETED_PALM_REC ) ) {
			jpilot_load_address( pilotFile, br, folderInd );
		}
		free( br->buf );
		free( br );
		node->data = NULL;
		node = g_list_next( node );
	}

	/* Free up list */
	g_list_free( records );

	/* Remove empty category folders */
	jpilot_remove_empty( pilotFile );
	jpilot_mark_files( pilotFile );

	return retVal;
}