예제 #1
0
파일: importpine.c 프로젝트: Mortal/claws
static gboolean imp_pine_import_file( gchar *sName, gchar *sFile ) {
	gboolean retVal = FALSE;
	gchar *newFile;
	AddressBookFile *abf = NULL;
	PineFile *pdf = NULL;

	if( _importedBook_ ) {
		addrbook_free_book( _importedBook_ );
	}

	abf = addrbook_create_book();
	addrbook_set_path( abf, _imp_addressIndex_->filePath );
	addrbook_set_name( abf, sName );
	newFile = addrbook_guess_next_file( abf );
	addrbook_set_file( abf, newFile );
	g_free( newFile );

	/* Import data from file */
	pdf = pine_create();
	pine_set_file( pdf, sFile );
	if( pine_import_data( pdf, abf->addressCache ) == MGU_SUCCESS ) {
		addrbook_save_data( abf );
		_importedBook_ = abf;
		retVal = TRUE;
	}
	else {
		addrbook_free_book( abf );
	}
	pine_free(pdf);

	return retVal;
}
예제 #2
0
파일: importldif.c 프로젝트: twolife/claws
/**
 * Test whether we can move off fields page.
 * \return <i>TRUE</i> if OK to move off page.
 */
static gboolean imp_ldif_field_move() {
	gboolean retVal = FALSE;
	gchar *newFile;
	AddressBookFile *abf = NULL;

	if( _importedBook_ ) {
		addrbook_free_book( _importedBook_ );
	}

	abf = addrbook_create_book();
	addrbook_set_path( abf, _imp_addressIndex_->filePath );
	addrbook_set_name( abf, impldif_dlg.nameBook );
	newFile = addrbook_guess_next_file( abf );
	addrbook_set_file( abf, newFile );
	g_free( newFile );

	/* Import data into file */
	if( ldif_import_data( _ldifFile_, abf->addressCache ) == MGU_SUCCESS ) {
		addrbook_save_data( abf );
		_importedBook_ = abf;
		retVal = TRUE;
	}
	else {
		addrbook_free_book( abf );
	}

	return retVal;
}
예제 #3
0
파일: editbook.c 프로젝트: Mortal/claws
AdapterDSource *addressbook_edit_book( AddressIndex *addrIndex, AdapterDSource *ads ) {
	static gboolean cancelled;
	gchar *sName;
	AddressDataSource *ds = NULL;
	AddressBookFile *abf;
	gboolean fin;
	gboolean newBook = FALSE;
	gchar *newFile = NULL;

	if (!addrbookedit_dlg.window)
		addressbook_edit_book_create(&cancelled);
	gtk_widget_grab_focus(addrbookedit_dlg.ok_btn);
	gtk_widget_grab_focus(addrbookedit_dlg.name_entry);
	gtk_widget_show(addrbookedit_dlg.window);
	manage_window_set_transient(GTK_WINDOW(addrbookedit_dlg.window));
	gtk_window_set_modal(GTK_WINDOW(addrbookedit_dlg.window), TRUE);

	edit_book_status_show( "" );
	gtk_label_set_text( GTK_LABEL(addrbookedit_dlg.file_label), "" );
	if( ads ) {
		ds = ads->dataSource;
		abf = ds->rawDataSource;
		if ( addrbook_get_name( abf ) )
			gtk_entry_set_text(GTK_ENTRY(addrbookedit_dlg.name_entry),
				addrbook_get_name( abf ) );
		if( abf->fileName )
			gtk_label_set_text(GTK_LABEL(addrbookedit_dlg.file_label), abf->fileName);
		gtk_window_set_title( GTK_WINDOW(addrbookedit_dlg.window), _("Edit Addressbook"));
		edit_book_enable_buttons( TRUE );
	}
	else {
		gchar *tmp = NULL;
		newBook = TRUE;
		abf = addrbook_create_book();
		addrbook_set_path( abf, addrIndex->filePath );

		/* Take initial guess at file name */
		newFile = addrbook_guess_next_file( abf );
		if( newFile ) {
			tmp = g_strdup_printf( "<%s>", newFile );
			gtk_label_set_text(GTK_LABEL(addrbookedit_dlg.file_label), tmp );
			g_free( tmp );
		}
		g_free( newFile );

		gtk_entry_set_text( GTK_ENTRY(addrbookedit_dlg.name_entry), ADDRESSBOOK_GUESS_BOOK );
		gtk_window_set_title( GTK_WINDOW(addrbookedit_dlg.window), _("Add New Addressbook") );
		edit_book_enable_buttons( FALSE );
	}

	addrbookedit_dlg.bookFile = abf;

	gtk_main();
	gtk_widget_hide(addrbookedit_dlg.window);
	gtk_window_set_modal(GTK_WINDOW(addrbookedit_dlg.window), FALSE);
	if( cancelled == TRUE ) {
		if( newBook ) {
			addrbook_free_book( abf );
			abf = NULL;
		}
		return NULL;
	}

	fin = FALSE;
	sName = gtk_editable_get_chars( GTK_EDITABLE(addrbookedit_dlg.name_entry), 0, -1 );
	if( *sName == '\0' ) fin = TRUE;

	if( fin ) {
		if( newBook ) {
			addrbook_free_book( abf );
			abf = NULL;
		}
	}
	else {
		if( newBook ) {
			/* Get final file name in case it changed */
			newFile = addrbook_guess_next_file( abf );
			addrbook_set_file( abf, newFile );
			g_free( newFile );
			ds = addrindex_index_add_datasource( addrIndex, ADDR_IF_BOOK, abf );
			ads = addressbook_create_ds_adapter( ds, ADDR_BOOK, NULL );
		}
		addressbook_ads_set_name( ads, sName );
		addrbook_set_name( abf, sName );
	}
	g_free( sName );

	/* Save data */
	if( abf ) addrbook_save_data( abf );

	return ads;
}