Ejemplo n.º 1
0
/*
* Create new address cache.
*/
AddressCache *addrcache_create() {
	AddressCache *cache;
	gint t;

	cache = g_new0( AddressCache, 1 );
	cache->itemHash = g_hash_table_new( g_str_hash, g_str_equal );
	cache->cacheID = g_strdup_printf( "%d", addrcache_next_cache_id() );

	cache->dataRead = FALSE;
	cache->modified = FALSE;
	cache->dirtyFlag = FALSE;
	cache->accessFlag = FALSE;
	cache->name = NULL;
	cache->modifyTime = 0;

	/* Generate the next ID using system time */
	cache->nextID = 1;
	t = time( NULL );
	if( t > 0 ) {
		cache->nextID = t - ID_TIME_OFFSET;
	}

	cache->tempList = NULL;
	cache->rootFolder = addritem_create_item_folder();
	cache->rootFolder->isRoot = TRUE;
	ADDRITEM_PARENT(cache->rootFolder) = NULL;
	return cache;
}
Ejemplo n.º 2
0
/*
 * Insert address into cache.
 * Enter: harvester Harvester object.
 *        entry     Header object.
 *        cache     Address cache to load.
 *        name      Name.
 *        address   eMail address.
 */
static void addrharvest_insert_cache(
		AddressHarvester *harvester, HeaderEntry *entry,
		AddressCache *cache, const gchar *name,
		const gchar *address )
{
	ItemPerson *person;
	ItemFolder *folder;
	gchar *folderName;
	gboolean newFolder;
	gint cnt;
	gchar *key, *value;

	newFolder = FALSE;
	folder = entry->folder;
	if( folder == NULL ) {
		newFolder = TRUE;	/* No folder yet */
	}
	if( entry->count % harvester->folderSize == 0 ) {
		newFolder = TRUE;	/* Folder is full */
	}

	/* Insert address */
	key = g_strdup( address );
	g_strdown( key );
	person = g_hash_table_lookup( harvester->dupTable, key );
	if( person ) {
		/* Update existing person to use longest name */
		value = ADDRITEM_NAME(person);
		if( strlen( name ) > strlen( value ) ) {
			addritem_person_set_common_name( person, name );
		}
		g_free( key );
	}
	else {
		/* Folder if required */
		if( newFolder ) {
			cnt = 1 + ( entry->count / harvester->folderSize );
			folderName =g_strdup_printf( "%s (%d)",
					entry->header, cnt );
			folder = addritem_create_item_folder();
			addritem_folder_set_name( folder, folderName );
			addritem_folder_set_remarks( folder, "" );
			addrcache_id_folder( cache, folder );
			addrcache_add_folder( cache, folder );
			entry->folder = folder;
			g_free( folderName );
		}

		/* Insert entry */
		person = addrcache_add_contact(
				cache, folder, name, address, "" );
		g_hash_table_insert( harvester->dupTable, key, person );
		entry->count++;
	}
	addritem_parse_first_last( person );
}
Ejemplo n.º 3
0
/**
 * Copy address book folder. Note that only the folder and not its contents are
 * copied.
 * \param  item Folder to copy.
 * \return A copy of the folder, or <i>NULL</i> if null argument supplied.
 */
ItemFolder *addritem_copy_item_folder( ItemFolder *item ) {
	ItemFolder *itemNew;

	itemNew = g_new0( ItemFolder, 1 );
	if( item ) {
		itemNew = addritem_create_item_folder();
		ADDRITEM_NAME(itemNew) = g_strdup( ADDRITEM_NAME(item) );
		itemNew->folderType = item->folderType;
	}
	return itemNew;
}
Ejemplo n.º 4
0
/*
* Build folder for each category.
*/
static void jpilot_build_category_list( JPilotFile *pilotFile ) {
	struct AddressAppInfo *ai = & pilotFile->addrInfo;
	struct CategoryAppInfo *cat = &	ai->category;
	gint i;

	for( i = 0; i < JPILOT_NUM_CATEG; i++ ) {
		ItemFolder *folder = addritem_create_item_folder();
		gchar *catName;

		catName = jpilot_convert_encoding( cat->name[i] );
		addritem_folder_set_name( folder, catName );
		g_free( catName );

		addrcache_id_folder( pilotFile->addressCache, folder );
		addrcache_add_folder( pilotFile->addressCache, folder );
	}
}
Ejemplo n.º 5
0
/**
 * Create a new folder and add to address cache.
 * \param  cache  Address cache.
 * \param  folder Parent folder where to add folder, or <i>NULL</i> for
 *                root folder.
 * \return Folder that was created. This should <b>*NOT*</b> be
 *         <code>g_free()</code> when done.
 */
ItemFolder *addrcache_add_new_folder( AddressCache *cache, ItemFolder *parent )
{
	ItemFolder *folder;
	ItemFolder *p = parent;

	cm_return_val_if_fail( cache != NULL, NULL );

	if( !p ) p = cache->rootFolder;
	folder = addritem_create_item_folder();
	addrcache_id_folder( cache, folder );
	if( addrcache_hash_add_folder( cache, folder ) ) {
		p->listFolder = g_list_append( p->listFolder, folder );
		ADDRITEM_PARENT(folder) = ADDRITEM_OBJECT(p);
		addrcache_set_dirty( cache, TRUE );
	}
	else {
		addritem_free_item_folder( folder );
		folder = NULL;
	}
	return folder;
}
Ejemplo n.º 6
0
/**
 * Build folder in address book for each category.
 * \param pilotFile  JPilot control data.
 */
static void jpilot_build_category_list( JPilotFile *pilotFile ) {
	struct AddressAppInfo *ai = & pilotFile->addrInfo;
	struct CategoryAppInfo *cat = &	ai->category;
	gint i;

	for( i = 0; i < JPILOT_NUM_CATEG; i++ ) {
		ItemFolder *folder = addritem_create_item_folder();

		if( convert_charcode ) {
			gchar catName[ JPILOT_LEN_CATEG ];
			conv_sjistoeuc( catName, JPILOT_LEN_CATEG, cat->name[i] );
			addritem_folder_set_name( folder, catName );
		}
		else {
			addritem_folder_set_name( folder, cat->name[i] );
		}

		addrcache_id_folder( pilotFile->addressCache, folder );
		addrcache_add_folder( pilotFile->addressCache, folder );
	}
}
Ejemplo n.º 7
0
/*
* Clear the address cache.
*/
void addrcache_clear( AddressCache *cache ) {
	cm_return_if_fail( cache != NULL );

	/* g_print( "...addrcache_clear :%s:\n", cache->name ); */
	/* Free up folders and hash table */
	addrcache_free_all_folders( cache->rootFolder );
	addrcache_free_item_hash( cache->itemHash );
	g_hash_table_destroy( cache->itemHash );
	cache->itemHash = NULL;
	ADDRITEM_PARENT(cache->rootFolder) = NULL;
	addritem_free_item_folder( cache->rootFolder );
	cache->rootFolder = NULL;
	if( cache->tempList ) g_list_free( cache->tempList );
	cache->tempList = NULL;

	/* Reset to initial state */
	cache->itemHash = g_hash_table_new( g_str_hash, g_str_equal );
	cache->rootFolder = addritem_create_item_folder();
	cache->rootFolder->isRoot = TRUE;
	ADDRITEM_PARENT(cache->rootFolder) = NULL;

	addrcache_refresh( cache );
}