23 |
#include <sys/types.h> |
#include <sys/types.h> |
24 |
#include <sys/wait.h> |
#include <sys/wait.h> |
25 |
#include <errno.h> |
#include <errno.h> |
26 |
|
#include <math.h> |
27 |
|
|
28 |
|
#if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >= 5) |
29 |
|
#include <hildon/hildon-entry.h> |
30 |
|
#endif |
31 |
|
|
32 |
#define GEOTOAD "/usr/bin/geotoad" |
#define GEOTOAD "/usr/bin/geotoad" |
33 |
|
|
40 |
typedef struct { |
typedef struct { |
41 |
appdata_t *appdata; |
appdata_t *appdata; |
42 |
|
|
43 |
|
GtkWidget *dialog; |
44 |
|
|
45 |
char buf[BUFFER_SIZE]; |
char buf[BUFFER_SIZE]; |
46 |
int bused; |
int bused; |
47 |
|
|
54 |
GtkWidget *view; |
GtkWidget *view; |
55 |
} log; |
} log; |
56 |
|
|
57 |
GtkWidget *username, *password; |
GtkWidget *username, *password, *filename; |
58 |
|
GtkWidget *lat, *lon, *dst; |
59 |
|
|
60 |
} gt_context_t; |
} gt_context_t; |
61 |
|
|
301 |
gtk_widget_destroy(dialog); |
gtk_widget_destroy(dialog); |
302 |
} |
} |
303 |
|
|
304 |
|
static void on_browse(GtkWidget *widget, gpointer data) { |
305 |
|
gt_context_t *context = (gt_context_t*)data; |
306 |
|
|
307 |
|
printf("Browse %p\n", context->dialog); |
308 |
|
|
309 |
|
#ifdef USE_MAEMO |
310 |
|
GtkWidget *dialog = hildon_file_chooser_dialog_new(GTK_WINDOW(context->dialog), |
311 |
|
GTK_FILE_CHOOSER_ACTION_SAVE); |
312 |
|
#else |
313 |
|
GtkWidget *dialog = gtk_file_chooser_dialog_new(_("Save GPX file"), |
314 |
|
GTK_WINDOW(context->dialog), |
315 |
|
GTK_FILE_CHOOSER_ACTION_SAVE, |
316 |
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
317 |
|
GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, |
318 |
|
NULL); |
319 |
|
#endif |
320 |
|
|
321 |
|
printf("set filename <%s>\n", context->appdata->gt.filename); |
322 |
|
|
323 |
|
if(!g_file_test(context->appdata->gt.filename, G_FILE_TEST_EXISTS)) { |
324 |
|
char *last_sep = strrchr(context->appdata->gt.filename, '/'); |
325 |
|
if(last_sep) { |
326 |
|
*last_sep = 0; // seperate path from file |
327 |
|
|
328 |
|
/* the user just created a new document */ |
329 |
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), |
330 |
|
context->appdata->gt.filename); |
331 |
|
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), last_sep+1); |
332 |
|
|
333 |
|
/* restore full filename */ |
334 |
|
*last_sep = '/'; |
335 |
|
} |
336 |
|
} else |
337 |
|
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), |
338 |
|
context->appdata->gt.filename); |
339 |
|
|
340 |
|
if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_FM_OK) { |
341 |
|
gchar *name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); |
342 |
|
gtk_label_set_text(GTK_LABEL(context->filename), name); |
343 |
|
} |
344 |
|
|
345 |
|
gtk_widget_destroy (dialog); |
346 |
|
} |
347 |
|
|
348 |
static gboolean gui_setup(gt_context_t *context) { |
static gboolean gui_setup(gt_context_t *context) { |
349 |
|
appdata_t *appdata = context->appdata; |
350 |
gboolean ok = FALSE; |
gboolean ok = FALSE; |
351 |
|
|
352 |
GtkWidget *dialog = gtk_dialog_new_with_buttons(_("GeoToad - Setup"), |
/* if no filename has been setup yet, create one */ |
353 |
GTK_WINDOW(context->appdata->window), |
if(!appdata->gt.filename && appdata->path) { |
354 |
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, |
printf("creating path\n"); |
355 |
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
appdata->gt.filename = |
356 |
GTK_STOCK_OK, GTK_RESPONSE_OK, |
g_strdup_printf("%s/gtoad.gpx", appdata->path); |
357 |
NULL); |
} |
358 |
|
|
359 |
|
context->dialog = gtk_dialog_new_with_buttons(_("GeoToad - Setup"), |
360 |
|
GTK_WINDOW(appdata->window), |
361 |
|
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, |
362 |
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
363 |
|
GTK_STOCK_OK, GTK_RESPONSE_OK, |
364 |
|
NULL); |
365 |
|
|
366 |
|
/* ------------------- Coordinates ------------------------- */ |
367 |
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
368 |
|
|
369 |
GtkWidget *vbox = gtk_vbox_new(FALSE, 0); |
GtkWidget *vbox = gtk_vbox_new(FALSE, 0); |
370 |
gtk_box_pack_start_defaults(GTK_BOX(vbox), gtk_label_new(_("Username:"))); |
gtk_box_pack_start_defaults(GTK_BOX(vbox), left_label_new(_("Latitude:"))); |
371 |
gtk_box_pack_start_defaults(GTK_BOX(vbox), gtk_label_new(_("Password:"))); |
gtk_box_pack_start_defaults(GTK_BOX(vbox), left_label_new(_("Longitude:"))); |
372 |
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), left_label_new(_("Distance:"))); |
373 |
|
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
374 |
|
|
375 |
|
/* setup default positions */ |
376 |
|
pos_t *refpos = get_pos(appdata); |
377 |
|
if((isnan(appdata->gt.lat) || isnan(appdata->gt.lat)) && refpos) { |
378 |
|
appdata->gt.lat = refpos->lat; |
379 |
|
appdata->gt.lon = refpos->lon; |
380 |
|
} |
381 |
|
|
382 |
|
vbox = gtk_vbox_new(FALSE, 0); |
383 |
|
context->lat = lat_entry_new(appdata->gt.lat); |
384 |
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), context->lat); |
385 |
|
context->lon = lat_entry_new(appdata->gt.lon); |
386 |
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), context->lon); |
387 |
|
context->dst = dist_entry_new(appdata->gt.distance, appdata->imperial); |
388 |
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), context->dst); |
389 |
gtk_box_pack_start_defaults(GTK_BOX(hbox), vbox); |
gtk_box_pack_start_defaults(GTK_BOX(hbox), vbox); |
390 |
|
|
391 |
|
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(context->dialog)->vbox), hbox); |
392 |
|
|
393 |
|
/* ------------------- file name ------------------------- */ |
394 |
|
hbox = gtk_hbox_new(FALSE, 0); |
395 |
|
|
396 |
|
context->filename = gtk_label_new(appdata->gt.filename); |
397 |
|
gtk_misc_set_alignment(GTK_MISC(context->filename), 0.f, 0.5f); |
398 |
|
gtk_label_set_ellipsize(GTK_LABEL(context->filename), PANGO_ELLIPSIZE_MIDDLE); |
399 |
|
gtk_box_pack_start_defaults(GTK_BOX(hbox), context->filename); |
400 |
|
|
401 |
|
GtkWidget *button = gtk_button_new_with_label(_("Browse")); |
402 |
|
gtk_signal_connect(GTK_OBJECT(button), "clicked", |
403 |
|
GTK_SIGNAL_FUNC(on_browse), context); |
404 |
|
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); |
405 |
|
|
406 |
|
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(context->dialog)->vbox), hbox); |
407 |
|
|
408 |
|
|
409 |
|
/* ------------------- Username/Password ------------------------- */ |
410 |
|
hbox = gtk_hbox_new(FALSE, 0); |
411 |
|
vbox = gtk_vbox_new(FALSE, 0); |
412 |
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), left_label_new(_("Username:"))); |
413 |
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), left_label_new(_("Password:"))); |
414 |
|
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
415 |
|
|
416 |
vbox = gtk_vbox_new(FALSE, 0); |
vbox = gtk_vbox_new(FALSE, 0); |
417 |
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
428 |
gtk_entry_set_visibility(GTK_ENTRY(context->password), FALSE); |
gtk_entry_set_visibility(GTK_ENTRY(context->password), FALSE); |
429 |
|
|
430 |
/* set saved defaults */ |
/* set saved defaults */ |
431 |
if(context->appdata->gt.username) |
if(appdata->gt.username) |
432 |
gtk_entry_set_text(GTK_ENTRY(context->username), |
gtk_entry_set_text(GTK_ENTRY(context->username), |
433 |
context->appdata->gt.username); |
appdata->gt.username); |
434 |
|
|
435 |
if(context->appdata->gt.password) |
if(appdata->gt.password) |
436 |
gtk_entry_set_text(GTK_ENTRY(context->password), |
gtk_entry_set_text(GTK_ENTRY(context->password), |
437 |
context->appdata->gt.password); |
appdata->gt.password); |
438 |
|
|
439 |
gtk_box_pack_start_defaults(GTK_BOX(vbox), context->username); |
gtk_box_pack_start_defaults(GTK_BOX(vbox), context->username); |
440 |
gtk_box_pack_start_defaults(GTK_BOX(vbox), context->password); |
gtk_box_pack_start_defaults(GTK_BOX(vbox), context->password); |
441 |
gtk_box_pack_start_defaults(GTK_BOX(hbox), vbox); |
gtk_box_pack_start_defaults(GTK_BOX(hbox), vbox); |
442 |
|
|
443 |
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox); |
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(context->dialog)->vbox), hbox); |
444 |
|
|
445 |
gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); |
gtk_dialog_set_default_response(GTK_DIALOG(context->dialog), GTK_RESPONSE_OK); |
446 |
|
|
447 |
gtk_widget_show_all(dialog); |
gtk_widget_show_all(context->dialog); |
448 |
|
|
449 |
if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { |
if(gtk_dialog_run(GTK_DIALOG(context->dialog)) == GTK_RESPONSE_OK) { |
450 |
|
|
451 |
/* save values */ |
/* save values */ |
452 |
if(context->appdata->gt.username) g_free(context->appdata->gt.username); |
if(appdata->gt.username) g_free(appdata->gt.username); |
453 |
context->appdata->gt.username = |
appdata->gt.username = |
454 |
g_strdup(gtk_entry_get_text(GTK_ENTRY(context->username))); |
g_strdup(gtk_entry_get_text(GTK_ENTRY(context->username))); |
455 |
|
|
456 |
if(context->appdata->gt.password) g_free(context->appdata->gt.password); |
if(appdata->gt.password) g_free(appdata->gt.password); |
457 |
context->appdata->gt.password = |
appdata->gt.password = |
458 |
g_strdup(gtk_entry_get_text(GTK_ENTRY(context->password))); |
g_strdup(gtk_entry_get_text(GTK_ENTRY(context->password))); |
459 |
|
|
460 |
|
if(appdata->gt.filename) g_free(appdata->gt.filename); |
461 |
|
appdata->gt.filename = |
462 |
|
g_strdup(gtk_label_get_text(GTK_LABEL(context->filename))); |
463 |
|
|
464 |
ok = TRUE; |
ok = TRUE; |
465 |
} |
} |
466 |
|
|
467 |
gtk_widget_destroy(dialog); |
gtk_widget_destroy(context->dialog); |
468 |
|
|
469 |
return ok; |
return ok; |
470 |
} |
} |