示例#1
0
AdapterDSource *addressbook_edit_vcard( AddressIndex *addrIndex, AdapterDSource *ads ) {
	static gboolean cancelled;
	gchar *sName;
	gchar *sFile;
	AddressDataSource *ds = NULL;
	VCardFile *vcf = NULL;
	gboolean fin;

	if( ! vcardedit.window )
		addressbook_edit_vcard_create(&cancelled);
	gtk_widget_grab_focus(vcardedit.ok_btn);
	gtk_widget_grab_focus(vcardedit.name_entry);
	gtk_widget_show(vcardedit.window);
	manage_window_set_transient(GTK_WINDOW(vcardedit.window));

	edit_vcard_status_show( "" );
	if( ads ) {
		ds = ads->dataSource;
		vcf = ds->rawDataSource;
		if ( vcard_get_name( vcf ) )
			gtk_entry_set_text(GTK_ENTRY(vcardedit.name_entry), vcard_get_name( vcf ) );
		if (vcf->path)
			gtk_entry_set_text(GTK_ENTRY(vcardedit.file_entry), vcf->path);
		gtk_window_set_title( GTK_WINDOW(vcardedit.window), _("Edit vCard Entry"));
	}
	else {
		gtk_entry_set_text(GTK_ENTRY(vcardedit.name_entry), ADDRESSBOOK_GUESS_VCARD );
		gtk_entry_set_text(GTK_ENTRY(vcardedit.file_entry), vcard_find_gnomecard() );
		gtk_window_set_title( GTK_WINDOW(vcardedit.window), _("Add New vCard Entry"));
	}

	gtk_main();
	gtk_widget_hide(vcardedit.window);
	if (cancelled == TRUE) return NULL;

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

	if( ! fin ) {
		if( ! ads ) {
			vcf = vcard_create();
			ds = addrindex_index_add_datasource( addrIndex, ADDR_IF_VCARD, vcf );
			ads = addressbook_create_ds_adapter( ds, ADDR_VCARD, NULL );
		}
		addressbook_ads_set_name( ads, sName );
		vcard_set_name( vcf, sName );
		vcard_set_file( vcf, sFile );
	}
	g_free( sName );
	g_free( sFile );

	return ads;
}
示例#2
0
AdapterDSource *addressbook_edit_jpilot( AddressIndex *addrIndex, AdapterDSource *ads ) {
	static gboolean cancelled;
	gchar *sName;
	gchar *sFile;
	gchar *sFSFile;
	AddressDataSource *ds = NULL;
	JPilotFile *jpf = NULL;
	gboolean fin;

	if( ! jpilotedit.window )
		addressbook_edit_jpilot_create(&cancelled);
	gtkut_box_set_reverse_order(GTK_BOX(jpilotedit.hbbox),
				    !prefs_common.comply_gnome_hig);
	gtk_widget_grab_focus(jpilotedit.ok_btn);
	gtk_widget_grab_focus(jpilotedit.name_entry);
	gtk_widget_show(jpilotedit.window);
	manage_window_set_transient(GTK_WINDOW(jpilotedit.window));

	edit_jpilot_status_show( "" );
	if( ads ) {
		ds = ads->dataSource;
		jpf = ds->rawDataSource;
		if (jpf->name)
			gtk_entry_set_text(GTK_ENTRY(jpilotedit.name_entry), jpf->name);
		if (jpf->path)
			gtk_entry_set_text(GTK_ENTRY(jpilotedit.file_entry), jpf->path);
		gtk_window_set_title( GTK_WINDOW(jpilotedit.window), _("Edit JPilot Entry"));
		edit_jpilot_fill_check_box( jpf );
	}
	else {
		gchar *guessFile = jpilot_find_pilotdb();
		gtk_entry_set_text(GTK_ENTRY(jpilotedit.name_entry), ADDRESSBOOK_GUESS_JPILOT );
		gtk_entry_set_text(GTK_ENTRY(jpilotedit.file_entry), guessFile );
		gtk_window_set_title( GTK_WINDOW(jpilotedit.window), _("Add New JPilot Entry"));
		edit_jpilot_fill_check_box_new();
		if( *guessFile != '\0' ) {
			edit_jpilot_file_check();
		}
	}

	gtk_main();
	gtk_widget_hide(jpilotedit.window);
	if (cancelled == TRUE) return NULL;

	fin = FALSE;
	sName = gtk_editable_get_chars( GTK_EDITABLE(jpilotedit.name_entry), 0, -1 );
	sFile = gtk_editable_get_chars( GTK_EDITABLE(jpilotedit.file_entry), 0, -1 );
	sFSFile = conv_filename_from_utf8( sFile );
	if( *sName == '\0' ) fin = TRUE;
	if( *sFile == '\0' ) fin = TRUE;
	if( ! sFSFile || *sFSFile == '\0' ) fin = TRUE;

	if( ! fin ) {
		if( ! ads ) {
			jpf = jpilot_create();
			ds = addrindex_index_add_datasource( addrIndex, ADDR_IF_JPILOT, jpf );
			ads = addressbook_create_ds_adapter( ds, ADDR_JPILOT, NULL );
		}
		addressbook_ads_set_name( ads, sName );
		jpilot_set_name( jpf, sName );
		jpilot_set_file( jpf, sFSFile );
		edit_jpilot_read_check_box( jpf );
	}
	g_free( sFSFile );
	g_free( sFile );
	g_free( sName );

	return ads;
}
示例#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;
}