Diff of /trunk/src/geotoad.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 199 by harbaum, Thu Nov 19 13:33:35 2009 UTC revision 200 by harbaum, Thu Nov 19 13:57:17 2009 UTC
# Line 157  static gboolean child_input_cb(GIOChanne Line 157  static gboolean child_input_cb(GIOChanne
157    return TRUE;    return TRUE;
158  }  }
159    
160    static void arg_free(gpointer data, gpointer user_data) {
161      if(data) g_free(data);
162    }
163    
164    static void arg_dsp(gpointer data, gpointer user_data) {
165      gt_context_t *context = (gt_context_t*)user_data;
166    
167      if(data)
168        appendf(&context->log, COLOR_SYSTEM, "%s\n", data);
169    }
170    
171  static void run(gt_context_t *context) {  static void run(gt_context_t *context) {
172      char str[8];
173    
174    /* setup context */    /* setup context */
175    context->bused = 0;    context->bused = 0;
176    context->stdout_tag = -1;    context->stdout_tag = -1;
# Line 168  static void run(gt_context_t *context) { Line 181  static void run(gt_context_t *context) {
181    
182    /* build list of arguments to call geotoad */    /* build list of arguments to call geotoad */
183    GPtrArray *gt_argv = g_ptr_array_new();    GPtrArray *gt_argv = g_ptr_array_new();
184    g_ptr_array_add (gt_argv, GEOTOAD);    g_ptr_array_add (gt_argv, g_strdup_printf(GEOTOAD));
185    g_ptr_array_add (gt_argv, "--distanceMax=1.0");    g_ascii_dtostr(str, sizeof(str), context->appdata->gt.distance);
186    g_ptr_array_add (gt_argv, "--output=gtoad.gpx");    g_ptr_array_add (gt_argv, g_strdup_printf("--distanceMax=%s", str));
187    g_ptr_array_add (gt_argv, "--password=winterblume");    g_ptr_array_add (gt_argv, g_strdup_printf("--output=%s", context->appdata->gt.filename));
188    g_ptr_array_add (gt_argv, "--queryType=coord");    g_ptr_array_add (gt_argv, g_strdup_printf("--password=%s", context->appdata->gt.password));
189    g_ptr_array_add (gt_argv, "--user=Tantil");    g_ptr_array_add (gt_argv, g_strdup_printf("--queryType=coord"));
190      g_ptr_array_add (gt_argv, g_strdup_printf("--user=%s", context->appdata->gt.username));
191    
192    /* check if we need to add proxy config */    /* check if we need to add proxy config */
193    char *proxy = NULL;    char *proxy = NULL;
# Line 191  static void run(gt_context_t *context) { Line 205  static void run(gt_context_t *context) {
205                                context->appdata->proxy->host,                                context->appdata->proxy->host,
206                                context->appdata->proxy->port);                                context->appdata->proxy->port);
207    
     appendf(&context->log, COLOR_SYSTEM, "Using proxy: %s\n", proxy);  
208      g_ptr_array_add (gt_argv, proxy);      g_ptr_array_add (gt_argv, proxy);
209    }    }
210    
211    g_ptr_array_add (gt_argv, "N49 00.000 E008 23.000");    g_ptr_array_add (gt_argv, g_strdup_printf("N49 00.000 E008 23.000"));
212    g_ptr_array_add (gt_argv, NULL);    g_ptr_array_add (gt_argv, NULL);
213    
214      /* show all entries */
215      g_ptr_array_foreach(gt_argv, arg_dsp, context);
216    
217    GError *error=NULL;    GError *error=NULL;
218    GPid pid;    GPid pid;
219    GSource *gt_watch;    GSource *gt_watch;
# Line 213  static void run(gt_context_t *context) { Line 229  static void run(gt_context_t *context) {
229                                   &context->stdout_fd,                                   &context->stdout_fd,
230                                   &context->stderr_fd,                                   &context->stderr_fd,
231                                   &error)) {                                   &error)) {
232        g_ptr_array_foreach(gt_argv, arg_free, NULL);
233      g_ptr_array_free(gt_argv, TRUE);      g_ptr_array_free(gt_argv, TRUE);
     if(proxy) g_free(proxy);  
234      appendf(&context->log, COLOR_ERR,      appendf(&context->log, COLOR_ERR,
235              _("GeoToad failed to start!\n%s\n"), error->message);              _("GeoToad failed to start!\n%s\n"), error->message);
236      g_error_free(error);      g_error_free(error);
237      return;      return;
238    }    }
239    
240      g_ptr_array_foreach(gt_argv, arg_free, NULL);
241    g_ptr_array_free (gt_argv, TRUE);    g_ptr_array_free (gt_argv, TRUE);
   if(proxy) g_free(proxy);  
242    
243    gt_watch = g_child_watch_source_new(pid);    gt_watch = g_child_watch_source_new(pid);
244    g_source_set_callback(gt_watch, (GSourceFunc) child_state_cb, context, NULL);    g_source_set_callback(gt_watch, (GSourceFunc) child_state_cb, context, NULL);
# Line 385  static gboolean gui_setup(gt_context_t * Line 401  static gboolean gui_setup(gt_context_t *
401    context->lon = lon_entry_new(appdata->gt.lon);    context->lon = lon_entry_new(appdata->gt.lon);
402    gtk_box_pack_start_defaults(GTK_BOX(ihbox), context->lon);    gtk_box_pack_start_defaults(GTK_BOX(ihbox), context->lon);
403    gtk_box_pack_start_defaults(GTK_BOX(vbox), ihbox);    gtk_box_pack_start_defaults(GTK_BOX(vbox), ihbox);
404    context->dst = dist_entry_new(appdata->gt.distance, appdata->imperial);    float dst = appdata->gt.distance;  // distance is given in kilometers
405      if(appdata->imperial) dst /= 1.609344;
406      context->dst = dist_entry_new(dst, appdata->imperial);
407    gtk_box_pack_start_defaults(GTK_BOX(vbox), context->dst);    gtk_box_pack_start_defaults(GTK_BOX(vbox), context->dst);
408    gtk_box_pack_start_defaults(GTK_BOX(hbox), vbox);    gtk_box_pack_start_defaults(GTK_BOX(hbox), vbox);
409    
# Line 453  static gboolean gui_setup(gt_context_t * Line 471  static gboolean gui_setup(gt_context_t *
471    
472    if(gtk_dialog_run(GTK_DIALOG(context->dialog)) == GTK_RESPONSE_OK) {    if(gtk_dialog_run(GTK_DIALOG(context->dialog)) == GTK_RESPONSE_OK) {
473    
474        /* parse coordinates */
475        /* ... */
476    
477      /* save values */      /* save values */
478      if(appdata->gt.username) g_free(appdata->gt.username);      if(appdata->gt.username) g_free(appdata->gt.username);
479      appdata->gt.username =      appdata->gt.username =
# Line 466  static gboolean gui_setup(gt_context_t * Line 487  static gboolean gui_setup(gt_context_t *
487      appdata->gt.filename =      appdata->gt.filename =
488        g_strdup(gtk_label_get_text(GTK_LABEL(context->filename)));        g_strdup(gtk_label_get_text(GTK_LABEL(context->filename)));
489    
490        /* get distance in kilometers */
491        appdata->gt.distance = dist_get(context->dst, FALSE);
492    
493      ok = TRUE;      ok = TRUE;
494    }    }
495    

Legend:
Removed from v.199  
changed lines
  Added in v.200