68 |
|
|
69 |
GtkWidget *username, *password, *filename; |
GtkWidget *username, *password, *filename; |
70 |
GtkWidget *lat, *lon, *dst; |
GtkWidget *lat, *lon, *dst; |
71 |
|
|
72 |
|
int use_cnt; |
73 |
|
|
74 |
} gt_context_t; |
} gt_context_t; |
75 |
|
|
78 |
} |
} |
79 |
|
|
80 |
static void context_free(gt_context_t *context) { |
static void context_free(gt_context_t *context) { |
81 |
// printf("freeing context\n"); |
context->use_cnt--; |
82 |
|
|
83 |
if(context->info) g_free(context->info); |
if(context->use_cnt > 0) |
84 |
|
printf("still in use by %d, keeping context\n", context->use_cnt); |
85 |
g_ptr_array_foreach(context->argv, arg_free, NULL); |
else { |
86 |
g_ptr_array_free (context->argv, TRUE); |
printf("freeing context\n"); |
87 |
|
|
88 |
|
if(context->info) g_free(context->info); |
89 |
|
|
90 |
|
if(context->argv) { |
91 |
|
g_ptr_array_foreach(context->argv, arg_free, NULL); |
92 |
|
g_ptr_array_free (context->argv, TRUE); |
93 |
|
} |
94 |
|
|
95 |
g_free(context); |
g_free(context); |
96 |
|
} |
97 |
} |
} |
98 |
|
|
99 |
static void appendf(struct log_s *log, char *colname, |
static void appendf(struct log_s *log, char *colname, |
121 |
g_free(buf); |
g_free(buf); |
122 |
|
|
123 |
gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(log->view), |
gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(log->view), |
124 |
&end, 0.0, TRUE, 0, 1.0); |
&end, 0.0, TRUE, 1.0, 1.0); |
125 |
} |
} |
126 |
|
|
127 |
// This function receives a requst from a worker thread asking to |
// This function receives a requst from a worker thread asking to |
221 |
|
|
222 |
/* this printf will actually be redirected through the pipe */ |
/* this printf will actually be redirected through the pipe */ |
223 |
printf("Error: Failed to execute!\n"); |
printf("Error: Failed to execute!\n"); |
224 |
|
exit(1); |
225 |
} else { /* we're having major problems... */ |
} else { /* we're having major problems... */ |
226 |
close(p[0]); |
close(p[0]); |
227 |
close(p[1]); |
close(p[1]); |
228 |
|
|
229 |
/* this printf will actually be redirected through the pipe */ |
/* this printf will actually be redirected through the pipe??? No! */ |
230 |
printf("Error: Failed to fork!\n"); |
printf("Error: Failed to fork!\n"); |
231 |
} |
} |
232 |
|
|
246 |
|
|
247 |
fh = gt_popen(context, (char**)(context->argv->pdata),"r", &context->pid); |
fh = gt_popen(context, (char**)(context->argv->pdata),"r", &context->pid); |
248 |
if(!fh) { |
if(!fh) { |
249 |
append_parentf(context, COLOR_ERR, _("Failed to run GeoToad")); |
printf("fail free\n"); |
250 |
|
context_free(context); |
251 |
|
// g_thread_exit(NULL); |
252 |
return NULL; |
return NULL; |
253 |
} |
} |
254 |
|
|
255 |
|
/* the client is running */ |
256 |
|
printf("client inc use_cnt\n"); |
257 |
|
context->use_cnt++; |
258 |
|
|
259 |
/* switch to line buffered mode */ |
/* switch to line buffered mode */ |
260 |
if(setvbuf(fh, NULL, _IOLBF, 0)) |
if(setvbuf(fh, NULL, _IOLBF, 0)) |
261 |
perror("setvbuf(_IOLBF)"); |
perror("setvbuf(_IOLBF)"); |
278 |
g_io_channel_unref(gh); |
g_io_channel_unref(gh); |
279 |
pclose(fh); |
pclose(fh); |
280 |
append_parentf(context, COLOR_SYSTEM, "Job done!"); |
append_parentf(context, COLOR_SYSTEM, "Job done!"); |
281 |
|
|
|
g_thread_exit(NULL); |
|
282 |
context_free(context); |
context_free(context); |
283 |
|
|
284 |
|
g_thread_exit(NULL); |
285 |
return NULL; |
return NULL; |
286 |
} |
} |
287 |
|
|
301 |
context->argv = g_ptr_array_new(); |
context->argv = g_ptr_array_new(); |
302 |
g_ptr_array_add (context->argv, g_strdup_printf(GEOTOAD)); |
g_ptr_array_add (context->argv, g_strdup_printf(GEOTOAD)); |
303 |
g_ascii_dtostr(str, sizeof(str), context->appdata->gt.distance); |
g_ascii_dtostr(str, sizeof(str), context->appdata->gt.distance); |
304 |
g_ptr_array_add (context->argv, g_strdup_printf("--distanceMax=%s", str)); |
g_ptr_array_add (context->argv, |
305 |
g_ptr_array_add (context->argv, g_strdup_printf("--output=%s", context->appdata->gt.filename)); |
g_strdup_printf("--distanceMax=%s", str)); |
306 |
g_ptr_array_add (context->argv, g_strdup_printf("--password=%s", context->appdata->gt.password)); |
g_ptr_array_add (context->argv, |
307 |
g_ptr_array_add (context->argv, g_strdup_printf("--queryType=coord")); |
g_strdup_printf("--output=%s", context->appdata->gt.filename)); |
308 |
g_ptr_array_add (context->argv, g_strdup_printf("--user=%s", context->appdata->username)); |
g_ptr_array_add (context->argv, |
309 |
|
g_strdup_printf("--password=%s", context->appdata->gt.password)); |
310 |
|
g_ptr_array_add (context->argv, |
311 |
|
g_strdup_printf("--queryType=coord")); |
312 |
|
g_ptr_array_add (context->argv, |
313 |
|
g_strdup_printf("--user=%s", context->appdata->username)); |
314 |
|
|
315 |
/* check if we need to add proxy config */ |
/* check if we need to add proxy config */ |
316 |
char *proxy = NULL; |
char *proxy = NULL; |
317 |
|
|
318 |
if(context->appdata->proxy && context->appdata->proxy->host) { |
if(context->appdata->proxy && context->appdata->proxy->host) { |
319 |
if(context->appdata->proxy->use_authentication && |
if(context->appdata->proxy->use_authentication && |
320 |
context->appdata->proxy->authentication_user && |
context->appdata->proxy->authentication_user && |
329 |
context->appdata->proxy->host, |
context->appdata->proxy->host, |
330 |
context->appdata->proxy->port); |
context->appdata->proxy->port); |
331 |
|
|
332 |
g_ptr_array_add (context->argv, proxy); |
} else { |
333 |
|
/* use environment settings if preset (for scratchbox) */ |
334 |
|
const char *proxy_env = g_getenv("http_proxy"); |
335 |
|
if(proxy_env) |
336 |
|
proxy = g_strdup_printf("--proxy=%s", proxy_env); |
337 |
} |
} |
338 |
|
|
339 |
|
if(proxy) |
340 |
|
g_ptr_array_add (context->argv, proxy); |
341 |
|
|
342 |
/* convert coordinates into simple ascii format */ |
/* convert coordinates into simple ascii format */ |
343 |
char n = (context->appdata->gt.lat >= 0)?'N':'S'; |
char n = (context->appdata->gt.lat >= 0)?'N':'S'; |
354 |
n, (int)lat_int, (int)lat_mint, (int)(lat_frac*1000.0+0.5), |
n, (int)lat_int, (int)lat_mint, (int)(lat_frac*1000.0+0.5), |
355 |
e, (int)lon_int, (int)lon_mint, (int)(lon_frac*1000.0+0.5))); |
e, (int)lon_int, (int)lon_mint, (int)(lon_frac*1000.0+0.5))); |
356 |
|
|
|
// g_ptr_array_add (context->argv, g_strdup_printf("2>&1")); |
|
357 |
g_ptr_array_add (context->argv, NULL); |
g_ptr_array_add (context->argv, NULL); |
358 |
|
|
359 |
/* show all entries */ |
/* show all entries */ |
417 |
gtk_dialog_run(GTK_DIALOG(dialog)); |
gtk_dialog_run(GTK_DIALOG(dialog)); |
418 |
|
|
419 |
gtk_widget_destroy(dialog); |
gtk_widget_destroy(dialog); |
|
|
|
|
errorf("Fertig!\n"); |
|
|
|
|
420 |
} |
} |
421 |
|
|
422 |
static void on_browse(GtkWidget *widget, gpointer data) { |
static void on_browse(GtkWidget *widget, gpointer data) { |
502 |
gtk_box_pack_start_defaults(GTK_BOX(ihbox), context->lat); |
gtk_box_pack_start_defaults(GTK_BOX(ihbox), context->lat); |
503 |
context->lon = lon_entry_new(appdata->gt.lon); |
context->lon = lon_entry_new(appdata->gt.lon); |
504 |
gtk_box_pack_start_defaults(GTK_BOX(ihbox), context->lon); |
gtk_box_pack_start_defaults(GTK_BOX(ihbox), context->lon); |
505 |
|
GtkWidget *popup = preset_coordinate_picker(appdata, context->lat, context->lon); |
506 |
|
gtk_box_pack_start_defaults(GTK_BOX(ihbox), popup); |
507 |
gtk_box_pack_start_defaults(GTK_BOX(vbox), ihbox); |
gtk_box_pack_start_defaults(GTK_BOX(vbox), ihbox); |
508 |
float dst = appdata->gt.distance; // distance is given in kilometers |
float dst = appdata->gt.distance; // distance is given in kilometers |
509 |
if(appdata->imperial) dst /= 1.609344; |
if(appdata->imperial) dst /= 1.609344; |
541 |
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
542 |
|
|
543 |
vbox = gtk_vbox_new(FALSE, 0); |
vbox = gtk_vbox_new(FALSE, 0); |
544 |
#ifndef FREMANTLE |
context->username = entry_new(); |
545 |
context->username = gtk_entry_new(); |
context->password = entry_new(); |
|
context->password = gtk_entry_new(); |
|
|
#else |
|
|
context->username = hildon_entry_new(HILDON_SIZE_AUTO); |
|
|
hildon_gtk_entry_set_input_mode(GTK_ENTRY(context->username), |
|
|
HILDON_GTK_INPUT_MODE_FULL); |
|
|
context->password = hildon_entry_new(HILDON_SIZE_AUTO); |
|
|
hildon_gtk_entry_set_input_mode(GTK_ENTRY(context->password), |
|
|
HILDON_GTK_INPUT_MODE_FULL); |
|
|
#endif |
|
546 |
gtk_entry_set_visibility(GTK_ENTRY(context->password), FALSE); |
gtk_entry_set_visibility(GTK_ENTRY(context->password), FALSE); |
547 |
|
|
548 |
/* set saved defaults */ |
/* set saved defaults */ |
567 |
if(gtk_dialog_run(GTK_DIALOG(context->dialog)) == GTK_RESPONSE_OK) { |
if(gtk_dialog_run(GTK_DIALOG(context->dialog)) == GTK_RESPONSE_OK) { |
568 |
|
|
569 |
/* parse coordinates */ |
/* parse coordinates */ |
570 |
appdata->gt.lat = lat_get(context->lat); |
appdata->gt.lat = lat_entry_get(context->lat); |
571 |
appdata->gt.lon = lon_get(context->lon); |
appdata->gt.lon = lon_entry_get(context->lon); |
572 |
|
|
573 |
/* save values */ |
/* save values */ |
574 |
if(appdata->username) g_free(appdata->username); |
if(appdata->username) g_free(appdata->username); |
584 |
g_strdup(gtk_label_get_text(GTK_LABEL(context->filename))); |
g_strdup(gtk_label_get_text(GTK_LABEL(context->filename))); |
585 |
|
|
586 |
/* get distance in kilometers */ |
/* get distance in kilometers */ |
587 |
appdata->gt.distance = dist_get(context->dst, FALSE); |
appdata->gt.distance = dist_entry_get(context->dst, FALSE); |
588 |
|
|
589 |
|
|
590 |
/* check for valid entries */ |
/* check for valid entries */ |
591 |
if(isnan(appdata->gt.lat) || isnan(appdata->gt.lon) || |
if(isnan(appdata->gt.lat) || isnan(appdata->gt.lon) || |
592 |
isnan(appdata->gt.distance) || !appdata->gt.filename || |
isnan(appdata->gt.distance) || !appdata->gt.filename || |
593 |
!appdata->username || !appdata->gt.password) |
!appdata->username || !appdata->gt.password) |
594 |
errorf(_("GeoToad setup not complete")); |
errorf(_("The GeoToad setup is not complete.")); |
595 |
else |
else |
596 |
ok = TRUE; |
ok = TRUE; |
597 |
} |
} |
610 |
|
|
611 |
gt_context_t *context = g_new0(gt_context_t, 1); |
gt_context_t *context = g_new0(gt_context_t, 1); |
612 |
context->appdata = appdata; |
context->appdata = appdata; |
613 |
|
context->use_cnt++; // parent still uses this |
614 |
|
|
615 |
context->update_mutex = g_mutex_new(); |
context->update_mutex = g_mutex_new(); |
616 |
context->update_cond = g_cond_new(); |
context->update_cond = g_cond_new(); |
|
// context->mutex_to_run = mutex_to_run; |
|
|
|
|
|
printf("geoToad\n"); |
|
617 |
|
|
618 |
if(gui_setup(context)) |
if(gui_setup(context)) |
619 |
gui_run(context); |
gui_run(context); |
620 |
|
|
621 |
|
/* continue to process if something has actually been saved */ |
622 |
|
if(context->state == GT_STATE_SAVE_FOUND) { |
623 |
|
/* download seems to be successful. Make sure the GUI is */ |
624 |
|
/* updated if required */ |
625 |
|
|
626 |
|
gpx_t **gpx = &(appdata->gpx); |
627 |
|
while(*gpx && strcmp((*gpx)->filename, appdata->gt.filename)) |
628 |
|
gpx = &(*gpx)->next; |
629 |
|
|
630 |
|
/* return main GUI to GPX list */ |
631 |
|
#ifdef USE_BREAD_CRUMB_TRAIL |
632 |
|
while(appdata->cur_gpx) |
633 |
|
hildon_bread_crumb_trail_pop(HILDON_BREAD_CRUMB_TRAIL(appdata->bct)); |
634 |
|
#elif defined(BCT) |
635 |
|
while(appdata->cur_gpx) |
636 |
|
bct_pop(appdata->bct); |
637 |
|
#else |
638 |
|
HildonWindowStack *stack = hildon_window_stack_get_default(); |
639 |
|
gint num = hildon_window_stack_size(stack)-1; |
640 |
|
while(num--) { |
641 |
|
GtkWidget *top = hildon_window_stack_peek(stack); |
642 |
|
gtk_widget_destroy(top); |
643 |
|
} |
644 |
|
#endif |
645 |
|
|
646 |
|
/* replace an existing entry or add to end of list */ |
647 |
|
if(*gpx) { |
648 |
|
GtkTreeIter iter; |
649 |
|
g_assert(gpxlist_find(appdata, &iter, *gpx)); |
650 |
|
|
651 |
|
gpx_t *next = (*gpx)->next; |
652 |
|
|
653 |
|
gpx_free(*gpx); |
654 |
|
*gpx = gpx_parse(NULL, appdata->gt.filename, appdata->username); |
655 |
|
(*gpx)->next = next; |
656 |
|
|
657 |
|
/* update gpxlist */ |
658 |
|
gpxlist_set(appdata->gpxstore, &iter, *gpx); |
659 |
|
|
660 |
|
/* select that row */ |
661 |
|
GtkTreeSelection *selection = |
662 |
|
gtk_tree_view_get_selection(GTK_TREE_VIEW(appdata->gpxview)); |
663 |
|
gtk_tree_selection_select_iter(selection, &iter); |
664 |
|
GtkTreePath *path = |
665 |
|
gtk_tree_model_get_path(GTK_TREE_MODEL(appdata->gpxstore), &iter); |
666 |
|
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(appdata->gpxview), |
667 |
|
path, NULL, TRUE, 0.0, 0.0); |
668 |
|
gtk_tree_path_free(path); |
669 |
|
} else { |
670 |
|
gpx_t *new = gpx_parse(NULL, appdata->gt.filename, appdata->username); |
671 |
|
if(new) gpxlist_add(appdata, new); |
672 |
|
} |
673 |
|
} |
674 |
|
|
675 |
|
printf("main context free\n"); |
676 |
|
context_free(context); |
677 |
} |
} |
678 |
|
|
679 |
gboolean geotoad_available(void) { |
gboolean geotoad_available(void) { |