Revision 411 src/editjpilot.c

editjpilot.c (revision 411)
52 52
#include "addressitem.h"
53 53
#include "jpilot.h"
54 54
#include "mgutils.h"
55
#include "filesel.h"
55 56
#include "gtkutils.h"
57
#include "codeconv.h"
56 58
#include "manage_window.h"
57 59

  
58 60
#define ADDRESSBOOK_GUESS_JPILOT "MyJPilot"
......
71 73
	gint status_cid;
72 74
} jpilotedit;
73 75

  
74
static struct _AddressFileSelection jpilot_file_selector;
75

  
76 76
/*
77 77
* Edit functions.
78 78
*/
......
164 164
static void edit_jpilot_file_check( void ) {
165 165
	gint t = -1;
166 166
	gchar *sFile;
167
	gchar *sFSFile;
167 168
	gchar *sMsg;
168 169
	gboolean flg;
169 170

  
170 171
	flg = FALSE;
171 172
	sFile = gtk_editable_get_chars( GTK_EDITABLE(jpilotedit.file_entry), 0, -1 );
172 173
	if( sFile ) {
173
		g_strchomp( sFile ); g_strchug( sFile );
174
		if( *sFile != '\0' ) {
174
		sFSFile = conv_filename_from_utf8( sFile );
175
		if( sFSFile && *sFSFile != '\0' ) {
175 176
			/* Attempt to read file */
176
			JPilotFile *jpf = jpilot_create_path( sFile );
177
			JPilotFile *jpf;
178
			jpf = jpilot_create_path( sFSFile );
177 179
			t = jpilot_read_data( jpf );
178 180
			if( t == MGU_SUCCESS ) {
179 181
				/* Set check boxes */
......
183 185
			jpilot_free( jpf );
184 186
			jpf = NULL;
185 187
		}
188
		g_free( sFSFile );
189
		g_free( sFile );
186 190
	}
187 191
	if( ! flg ) {
188 192
		/* Clear all check boxes */
189 193
		edit_jpilot_fill_check_box_new();
190 194
	}
191
	g_free( sFile );
192 195

  
193 196
	/* Display appropriate message */
194 197
	if( t == MGU_SUCCESS ) {
......
203 206
	edit_jpilot_status_show( sMsg );
204 207
}
205 208

  
206
static void edit_jpilot_file_ok( GtkWidget *widget, gpointer data ) {
207
	const gchar *sFile;
208
	AddressFileSelection *afs;
209
	GtkWidget *fileSel;
210

  
211
	afs = ( AddressFileSelection * ) data;
212
	fileSel = afs->fileSelector;
213
	sFile = gtk_file_selection_get_filename( GTK_FILE_SELECTION(fileSel) );
214

  
215
	afs->cancelled = FALSE;
216
	gtk_entry_set_text( GTK_ENTRY(jpilotedit.file_entry), sFile );
217
	gtk_widget_hide( afs->fileSelector );
218
	gtk_grab_remove( afs->fileSelector );
219
	edit_jpilot_file_check();
220
	gtk_widget_grab_focus( jpilotedit.file_entry );
221
}
222

  
223
static void edit_jpilot_file_cancel( GtkWidget *widget, gpointer data ) {
224
	AddressFileSelection *afs = ( AddressFileSelection * ) data;
225
	afs->cancelled = TRUE;
226
	gtk_widget_hide( afs->fileSelector );
227
	gtk_grab_remove( afs->fileSelector );
228
	gtk_widget_grab_focus( jpilotedit.file_entry );
229
}
230

  
231
static void edit_jpilot_file_select_create( AddressFileSelection *afs ) {
232
	GtkWidget *fileSelector;
233

  
234
	fileSelector = gtk_file_selection_new( _("Select JPilot File") );
235
	gtk_file_selection_hide_fileop_buttons( GTK_FILE_SELECTION(fileSelector) );
236
	g_signal_connect( G_OBJECT (GTK_FILE_SELECTION(fileSelector)->ok_button),
237
			  "clicked", G_CALLBACK (edit_jpilot_file_ok), ( gpointer ) afs );
238
	g_signal_connect( G_OBJECT (GTK_FILE_SELECTION(fileSelector)->cancel_button),
239
			  "clicked", G_CALLBACK (edit_jpilot_file_cancel), ( gpointer ) afs );
240
	afs->fileSelector = fileSelector;
241
	afs->cancelled = TRUE;
242
}
243

  
244 209
static void edit_jpilot_file_select( void ) {
245 210
	gchar *sFile;
211
	gchar *sUTF8File;
246 212

  
247
	if (! jpilot_file_selector.fileSelector )
248
		edit_jpilot_file_select_create( & jpilot_file_selector );
213
	sFile = filesel_select_file( _("Select JPilot File"), NULL, GTK_FILE_CHOOSER_ACTION_OPEN );
249 214

  
250
	sFile = gtk_editable_get_chars( GTK_EDITABLE(jpilotedit.file_entry), 0, -1 );
251
	gtk_file_selection_set_filename( GTK_FILE_SELECTION( jpilot_file_selector.fileSelector ), sFile );
252
	g_free( sFile );
253
	gtk_widget_show( jpilot_file_selector.fileSelector );
254
	gtk_grab_add( jpilot_file_selector.fileSelector );
215
	if( sFile ) {
216
		sUTF8File = conv_filename_to_utf8( sFile );
217
		gtk_entry_set_text( GTK_ENTRY(jpilotedit.file_entry), sUTF8File );
218
		g_free( sUTF8File );
219
		g_free( sFile );
220
		edit_jpilot_file_check();
221
	}
255 222
}
256 223

  
257 224
static void addressbook_edit_jpilot_create( gboolean *cancelled ) {
......
389 356
	static gboolean cancelled;
390 357
	gchar *sName;
391 358
	gchar *sFile;
359
	gchar *sFSFile;
392 360
	AddressDataSource *ds = NULL;
393 361
	JPilotFile *jpf = NULL;
394 362
	gboolean fin;
......
431 399
	fin = FALSE;
432 400
	sName = gtk_editable_get_chars( GTK_EDITABLE(jpilotedit.name_entry), 0, -1 );
433 401
	sFile = gtk_editable_get_chars( GTK_EDITABLE(jpilotedit.file_entry), 0, -1 );
402
	sFSFile = conv_filename_from_utf8( sFile );
434 403
	if( *sName == '\0' ) fin = TRUE;
435 404
	if( *sFile == '\0' ) fin = TRUE;
405
	if( ! sFSFile || *sFSFile == '\0' ) fin = TRUE;
436 406

  
437 407
	if( ! fin ) {
438 408
		if( ! ads ) {
......
442 412
		}
443 413
		addressbook_ads_set_name( ads, sName );
444 414
		jpilot_set_name( jpf, sName );
445
		jpilot_set_file( jpf, sFile );
415
		jpilot_set_file( jpf, sFSFile );
446 416
		edit_jpilot_read_check_box( jpf );
447 417
	}
448
	g_free( sName );
418
	g_free( sFSFile );
449 419
	g_free( sFile );
420
	g_free( sName );
450 421

  
451 422
	return ads;
452 423
}

Also available in: Unified diff