19 |
|
|
20 |
#include "gpxview.h" |
#include "gpxview.h" |
21 |
|
|
22 |
|
#define __USE_GNU |
23 |
|
#include <string.h> |
24 |
|
|
25 |
#include <fcntl.h> |
#include <fcntl.h> |
26 |
#include <sys/types.h> |
#include <sys/types.h> |
27 |
#include <sys/wait.h> |
#include <sys/wait.h> |
40 |
|
|
41 |
#define BUFFER_SIZE 256 |
#define BUFFER_SIZE 256 |
42 |
|
|
43 |
|
typedef enum { |
44 |
|
GT_STATE_ILLEGAL = 0, |
45 |
|
GT_STATE_STARTED, |
46 |
|
GT_STATE_PREMATURE_END, |
47 |
|
GT_STATE_SAVE_FOUND, |
48 |
|
} gt_state_t; |
49 |
|
|
50 |
typedef struct { |
typedef struct { |
51 |
appdata_t *appdata; |
appdata_t *appdata; |
52 |
|
|
53 |
|
GPtrArray *argv; |
54 |
|
gchar *info, *color; |
55 |
|
GMutex *update_mutex; |
56 |
|
GCond *update_cond; |
57 |
|
|
58 |
GtkWidget *dialog; |
gt_state_t state; |
59 |
|
|
60 |
char buf[BUFFER_SIZE]; |
GtkWidget *dialog; |
|
int bused; |
|
61 |
|
|
62 |
/** gdk input tag for async IO */ |
long pid; |
|
gint stdout_tag, stderr_tag; |
|
|
gint stdin_fd, stdout_fd, stderr_fd; |
|
63 |
|
|
64 |
struct log_s { |
struct log_s { |
65 |
GtkTextBuffer *buffer; |
GtkTextBuffer *buffer; |
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 |
|
|
76 |
|
static void arg_free(gpointer data, gpointer user_data) { |
77 |
|
if(data) g_free(data); |
78 |
|
} |
79 |
|
|
80 |
|
static void context_free(gt_context_t *context) { |
81 |
|
context->use_cnt--; |
82 |
|
|
83 |
|
if(context->use_cnt > 0) |
84 |
|
printf("still in use by %d, keeping context\n", context->use_cnt); |
85 |
|
else { |
86 |
|
printf("freeing context\n"); |
87 |
|
|
88 |
|
if(context->info) g_free(context->info); |
89 |
|
|
90 |
|
g_ptr_array_foreach(context->argv, arg_free, NULL); |
91 |
|
g_ptr_array_free (context->argv, TRUE); |
92 |
|
|
93 |
|
g_free(context); |
94 |
|
} |
95 |
|
} |
96 |
|
|
97 |
static void appendf(struct log_s *log, char *colname, |
static void appendf(struct log_s *log, char *colname, |
98 |
const char *fmt, ...) { |
const char *fmt, ...) { |
99 |
va_list args; |
va_list args; |
101 |
char *buf = g_strdup_vprintf(fmt, args); |
char *buf = g_strdup_vprintf(fmt, args); |
102 |
va_end( args ); |
va_end( args ); |
103 |
|
|
104 |
printf("append: %s", buf); |
// printf("append: %s", buf); |
105 |
|
|
106 |
GtkTextTag *tag = NULL; |
GtkTextTag *tag = NULL; |
107 |
if(colname) |
if(colname) |
118 |
|
|
119 |
g_free(buf); |
g_free(buf); |
120 |
|
|
|
gtk_text_buffer_get_end_iter(log->buffer, &end); |
|
121 |
gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(log->view), |
gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(log->view), |
122 |
&end, 0.0, FALSE, 0, 0); |
&end, 0.0, TRUE, 1.0, 1.0); |
123 |
} |
} |
124 |
|
|
125 |
/* watch child process and receive events */ |
// This function receives a requst from a worker thread asking to |
126 |
static void child_state_cb(GPid pid, gint status, gpointer data) { |
// update the gui with the required info. |
127 |
gt_context_t *context = (gt_context_t*)data; |
gboolean cb_update_job(gt_context_t *context) { |
128 |
|
if (context->info) { |
129 |
puts("child state"); |
|
130 |
|
/* check if client reports "saved to ..." */ |
131 |
|
if(strstr(context->info, "Saved to ")) |
132 |
|
context->state = GT_STATE_SAVE_FOUND; |
133 |
|
|
134 |
if(WIFEXITED(status)) { |
appendf(&context->log, context->color, context->info); |
135 |
printf("child exited with return code %d\n", WEXITSTATUS(status)); |
|
136 |
} else |
g_free(context->info); |
137 |
printf("child failed\n"); |
context->info = NULL; |
138 |
|
} |
139 |
|
|
140 |
|
// Indicate that the update is done |
141 |
|
g_mutex_lock(context->update_mutex); |
142 |
|
g_cond_signal(context->update_cond); |
143 |
|
g_mutex_unlock(context->update_mutex); |
144 |
|
|
145 |
|
return FALSE; |
146 |
|
} |
147 |
|
|
148 |
puts("gt exited"); |
// A helper function run in the job thread receiving the string that |
149 |
|
// should be displayed in the textview. |
150 |
|
void append_parentf(gt_context_t *context, char *colname, |
151 |
|
const char *fmt, ...) { |
152 |
|
va_list args; |
153 |
|
va_start( args, fmt ); |
154 |
|
context->info = g_strdup_vprintf(fmt, args); |
155 |
|
va_end( args ); |
156 |
|
|
157 |
appendf(&context->log, COLOR_SYSTEM, "GeoToad finished\n"); |
if(colname) |
158 |
|
context->color = colname; |
159 |
|
else |
160 |
|
context->color = NULL; |
161 |
|
|
162 |
appendf(&context->log, COLOR_SYSTEM, "TODO: free context!!!\n"); |
// Lock mutex to make sure that we will receive the condition signal |
163 |
// printf("freeing context\n"); |
g_mutex_lock(context->update_mutex); |
|
// g_free(context); |
|
164 |
|
|
165 |
/* Reap child if needed. */ |
g_idle_add((GSourceFunc)cb_update_job, context); |
166 |
waitpid (pid, NULL, WNOHANG); |
|
167 |
|
// Wait for cb_update_job to tell me that the update is done |
168 |
|
g_cond_wait(context->update_cond, context->update_mutex); |
169 |
|
g_mutex_unlock(context->update_mutex); |
170 |
} |
} |
171 |
|
|
172 |
static gboolean child_input_cb(GIOChannel *source, |
/* custom version of popen to get access to the pid and to be able */ |
173 |
GIOCondition condition, |
/* to slaughter the child process */ |
174 |
gpointer data) { |
static FILE *gt_popen(gt_context_t *context, char **args, |
175 |
gt_context_t *context = (gt_context_t*)data; |
const char *type, long *tid) { |
176 |
int fd = g_io_channel_unix_get_fd(source); |
int p[2]; |
177 |
ssize_t bytes; |
FILE *fp; |
178 |
|
|
179 |
g_assert(condition == G_IO_IN); |
if (*type != 'r' && *type != 'w') |
180 |
|
return NULL; |
181 |
/* append to current buffer content */ |
|
182 |
while( (bytes = read(fd, context->buf+context->bused, |
if (pipe(p) < 0) |
183 |
sizeof(context->buf) - context->bused - 1)) > 0) { |
return NULL; |
184 |
context->bused += bytes; |
|
185 |
context->buf[context->bused]='\0'; |
if ((*tid = fork()) > 0) { /* then we are the parent */ |
186 |
|
if (*type == 'r') { |
187 |
|
close(p[1]); |
188 |
|
fp = fdopen(p[0], type); |
189 |
|
} else { |
190 |
|
close(p[0]); |
191 |
|
fp = fdopen(p[1], type); |
192 |
|
} |
193 |
|
|
194 |
|
return fp; |
195 |
|
} else if (*tid == 0) { /* we're the child */ |
196 |
|
|
197 |
/* consume line by line */ |
/* make our thread id the process group leader */ |
198 |
gchar *ptr = context->buf; |
setpgid(0, 0); |
199 |
|
|
200 |
|
if (*type == 'r') { |
201 |
|
fflush(stdout); |
202 |
|
fflush(stderr); |
203 |
|
close(1); |
204 |
|
if (dup(p[1]) < 0) |
205 |
|
perror("dup of write side of pipe failed"); |
206 |
|
close(2); |
207 |
|
if (dup(p[1]) < 0) |
208 |
|
perror("dup of write side of pipe failed"); |
209 |
|
} else { |
210 |
|
close(0); |
211 |
|
if (dup(p[0]) < 0) |
212 |
|
perror("dup of read side of pipe failed"); |
213 |
|
} |
214 |
|
|
215 |
/* parse as long as the buffer contains a newline */ |
close(p[0]); /* close since we dup()'ed what we needed */ |
216 |
while( strchr(ptr, '\n') != NULL) { |
close(p[1]); |
217 |
char *p = strchr(ptr, '\n'); |
|
218 |
*p = '\0'; |
execve(args[0], args, NULL); |
219 |
|
|
220 |
char *color = NULL; |
/* this printf will actually be redirected through the pipe */ |
221 |
if(strstr(ptr, "Saved to ") != NULL) |
printf("Error: Failed to execute!\n"); |
222 |
color = COLOR_OK; |
exit(1); |
223 |
|
} else { /* we're having major problems... */ |
224 |
|
close(p[0]); |
225 |
|
close(p[1]); |
226 |
|
|
227 |
|
/* this printf will actually be redirected through the pipe??? No! */ |
228 |
|
printf("Error: Failed to fork!\n"); |
229 |
|
} |
230 |
|
|
231 |
|
return NULL; |
232 |
|
} |
233 |
|
|
234 |
appendf(&context->log, color, "%s\n", ptr); |
// The thread entry point. It will do the job, send the data to the |
235 |
|
// GUI and self destruct when it is done. |
236 |
|
static gpointer thread_worker(gt_context_t *context) |
237 |
|
{ |
238 |
|
FILE *fh; |
239 |
|
GIOStatus status; |
240 |
|
GError *error = NULL; |
241 |
|
gsize length; |
242 |
|
gsize terminator_pos; |
243 |
|
gchar *str_return; |
244 |
|
|
245 |
|
fh = gt_popen(context, (char**)(context->argv->pdata),"r", &context->pid); |
246 |
|
if(!fh) { |
247 |
|
printf("fail free\n"); |
248 |
|
context_free(context); |
249 |
|
// g_thread_exit(NULL); |
250 |
|
return NULL; |
251 |
|
} |
252 |
|
|
253 |
ptr = p+1; |
/* the client is running */ |
254 |
} |
printf("client inc use_cnt\n"); |
255 |
|
context->use_cnt++; |
256 |
|
|
257 |
|
/* switch to line buffered mode */ |
258 |
|
if(setvbuf(fh, NULL, _IOLBF, 0)) |
259 |
|
perror("setvbuf(_IOLBF)"); |
260 |
|
|
261 |
|
GIOChannel *gh = g_io_channel_unix_new(fileno(fh)); |
262 |
|
|
263 |
/* move remaining bytes down the buffer */ |
while( (status = g_io_channel_read_line(gh, |
264 |
memmove(context->buf, ptr, sizeof(context->buf)-(ptr-context->buf)); |
&str_return, |
265 |
context->bused -= ptr - context->buf; |
&length, |
266 |
|
&terminator_pos, |
267 |
/* check if buffer is full but doesn't contain any newline */ |
&error)) == G_IO_STATUS_NORMAL) { |
268 |
if(context->bused >= sizeof(context->buf)-1) { |
char *color = NULL; |
269 |
printf("ERROR: reply buffer overflow\n"); |
if(strstr(str_return, "Saved to ")) color = COLOR_OK; |
270 |
context->bused = 0; |
if(strcasestr(str_return, "error")) color = COLOR_ERR; |
271 |
} |
|
272 |
|
append_parentf(context, color, str_return); |
273 |
|
g_free(str_return); |
274 |
} |
} |
275 |
|
|
276 |
|
g_io_channel_unref(gh); |
277 |
|
pclose(fh); |
278 |
|
append_parentf(context, COLOR_SYSTEM, "Job done!"); |
279 |
|
|
280 |
|
context_free(context); |
281 |
|
|
282 |
|
g_thread_exit(NULL); |
283 |
|
return NULL; |
284 |
|
} |
285 |
|
|
286 |
return TRUE; |
|
287 |
|
static void arg_dsp(gpointer data, gpointer user_data) { |
288 |
|
gt_context_t *context = (gt_context_t*)user_data; |
289 |
|
|
290 |
|
if(data) |
291 |
|
appendf(&context->log, COLOR_SYSTEM, "%s\n", data); |
292 |
} |
} |
293 |
|
|
294 |
static void run(gt_context_t *context) { |
static void run(gt_context_t *context) { |
295 |
/* setup context */ |
GError *error = NULL; |
296 |
context->bused = 0; |
char str[8]; |
|
context->stdout_tag = -1; |
|
|
context->stderr_tag = -1; |
|
|
context->stdin_fd = -1; |
|
|
context->stderr_fd = -1; |
|
|
context->stderr_fd = -1; |
|
297 |
|
|
298 |
/* build list of arguments to call geotoad */ |
/* build list of arguments to call geotoad */ |
299 |
GPtrArray *gt_argv = g_ptr_array_new(); |
context->argv = g_ptr_array_new(); |
300 |
g_ptr_array_add (gt_argv, GEOTOAD); |
g_ptr_array_add (context->argv, g_strdup_printf(GEOTOAD)); |
301 |
g_ptr_array_add (gt_argv, "--distanceMax=1.0"); |
g_ascii_dtostr(str, sizeof(str), context->appdata->gt.distance); |
302 |
g_ptr_array_add (gt_argv, "--output=gtoad.gpx"); |
g_ptr_array_add (context->argv, |
303 |
g_ptr_array_add (gt_argv, "--password=winterblume"); |
g_strdup_printf("--distanceMax=%s", str)); |
304 |
g_ptr_array_add (gt_argv, "--queryType=coord"); |
g_ptr_array_add (context->argv, |
305 |
g_ptr_array_add (gt_argv, "--user=Tantil"); |
g_strdup_printf("--output=%s", context->appdata->gt.filename)); |
306 |
|
g_ptr_array_add (context->argv, |
307 |
|
g_strdup_printf("--password=%s", context->appdata->gt.password)); |
308 |
|
g_ptr_array_add (context->argv, |
309 |
|
g_strdup_printf("--queryType=coord")); |
310 |
|
g_ptr_array_add (context->argv, |
311 |
|
g_strdup_printf("--user=%s", context->appdata->username)); |
312 |
|
|
313 |
/* check if we need to add proxy config */ |
/* check if we need to add proxy config */ |
314 |
char *proxy = NULL; |
char *proxy = NULL; |
315 |
|
|
316 |
if(context->appdata->proxy && context->appdata->proxy->host) { |
if(context->appdata->proxy && context->appdata->proxy->host) { |
317 |
if(context->appdata->proxy->use_authentication && |
if(context->appdata->proxy->use_authentication && |
318 |
context->appdata->proxy->authentication_user && |
context->appdata->proxy->authentication_user && |
319 |
context->appdata->proxy->authentication_password) |
context->appdata->proxy->authentication_password) |
320 |
proxy = g_strdup_printf("--proxy=http://%s:%s@%s:%d", |
proxy = g_strdup_printf("--proxy=http://%s:%s@%s:%d", |
321 |
context->appdata->proxy->authentication_user, |
context->appdata->proxy->authentication_user, |
322 |
context->appdata->proxy->authentication_password, |
context->appdata->proxy->authentication_password, |
323 |
context->appdata->proxy->host, |
context->appdata->proxy->host, |
324 |
context->appdata->proxy->port); |
context->appdata->proxy->port); |
325 |
else |
else |
326 |
proxy = g_strdup_printf("--proxy=http://%s:%d", |
proxy = g_strdup_printf("--proxy=http://%s:%d", |
327 |
context->appdata->proxy->host, |
context->appdata->proxy->host, |
328 |
context->appdata->proxy->port); |
context->appdata->proxy->port); |
329 |
|
|
330 |
appendf(&context->log, COLOR_SYSTEM, "Using proxy: %s\n", proxy); |
} else { |
331 |
g_ptr_array_add (gt_argv, proxy); |
/* use environment settings if preset (for scratchbox) */ |
332 |
|
const char *proxy_env = g_getenv("http_proxy"); |
333 |
|
if(proxy_env) |
334 |
|
proxy = g_strdup_printf("--proxy=%s", proxy_env); |
335 |
} |
} |
336 |
|
|
337 |
|
if(proxy) |
338 |
|
g_ptr_array_add (context->argv, proxy); |
339 |
|
|
340 |
g_ptr_array_add (gt_argv, "N49 00.000 E008 23.000"); |
/* convert coordinates into simple ascii format */ |
341 |
g_ptr_array_add (gt_argv, NULL); |
char n = (context->appdata->gt.lat >= 0)?'N':'S'; |
342 |
|
char e = (context->appdata->gt.lon >= 0)?'E':'W'; |
343 |
GError *error=NULL; |
float lat = fabs(context->appdata->gt.lat); |
344 |
GPid pid; |
float lon = fabs(context->appdata->gt.lon); |
345 |
GSource *gt_watch; |
float lat_mint, lat_int, lat_frac = modff(lat, &lat_int); |
346 |
|
float lon_mint, lon_int, lon_frac = modff(lon, &lon_int); |
347 |
if (!g_spawn_async_with_pipes (NULL, /* CWD */ |
lat_frac = modff(lat_frac*60.0, &lat_mint); |
348 |
(char **) gt_argv->pdata, /* argv */ |
lon_frac = modff(lon_frac*60.0, &lon_mint); |
349 |
NULL, /* envp */ |
|
350 |
G_SPAWN_DO_NOT_REAP_CHILD, /* flags */ |
g_ptr_array_add (context->argv, |
351 |
NULL, /* child setup */ |
g_strdup_printf("%c%02u %02u.%03u %c%03u %02u.%03u", |
352 |
NULL, /* user data */ |
n, (int)lat_int, (int)lat_mint, (int)(lat_frac*1000.0+0.5), |
353 |
&pid, |
e, (int)lon_int, (int)lon_mint, (int)(lon_frac*1000.0+0.5))); |
354 |
&context->stdin_fd, |
|
355 |
&context->stdout_fd, |
g_ptr_array_add (context->argv, NULL); |
356 |
&context->stderr_fd, |
|
357 |
&error)) { |
/* show all entries */ |
358 |
g_ptr_array_free(gt_argv, TRUE); |
g_ptr_array_foreach(context->argv, arg_dsp, context); |
359 |
if(proxy) g_free(proxy); |
|
360 |
appendf(&context->log, COLOR_ERR, |
g_thread_create((GThreadFunc)thread_worker, context, FALSE, &error); |
361 |
_("GeoToad failed to start!\n%s\n"), error->message); |
if (error) { |
362 |
|
appendf(&context->log, COLOR_ERR, "Error: %s\n", error->message); |
363 |
g_error_free(error); |
g_error_free(error); |
|
return; |
|
364 |
} |
} |
|
|
|
|
g_ptr_array_free (gt_argv, TRUE); |
|
|
if(proxy) g_free(proxy); |
|
|
|
|
|
gt_watch = g_child_watch_source_new(pid); |
|
|
g_source_set_callback(gt_watch, (GSourceFunc) child_state_cb, context, NULL); |
|
|
|
|
|
g_source_attach(gt_watch, NULL); |
|
|
g_source_unref(gt_watch); |
|
|
|
|
|
/* make nonblocking */ |
|
|
if(fcntl(context->stdout_fd, F_SETFL, O_NONBLOCK) == -1) |
|
|
perror("fcntl failed"); |
|
|
|
|
|
if(fcntl(context->stderr_fd, F_SETFL, O_NONBLOCK) == -1) |
|
|
perror("fcntl failed"); |
|
|
|
|
|
GIOChannel *ioc = g_io_channel_unix_new(context->stdout_fd); |
|
|
g_io_channel_set_close_on_unref (ioc, TRUE); |
|
|
g_io_channel_set_encoding (ioc, NULL, NULL); |
|
|
g_io_add_watch(ioc, G_IO_IN, child_input_cb, context); |
|
|
g_io_channel_unref(ioc); |
|
|
|
|
|
// ioc = g_io_channel_unix_new(context->stderr_fd); |
|
|
// g_io_add_watch(ioc, G_IO_IN, child_input_cb, context); |
|
|
// g_io_channel_unref(ioc); |
|
365 |
} |
} |
366 |
|
|
367 |
/* show text window and display output of running geotoad */ |
/* show text window and display output of running geotoad */ |
501 |
context->lon = lon_entry_new(appdata->gt.lon); |
context->lon = lon_entry_new(appdata->gt.lon); |
502 |
gtk_box_pack_start_defaults(GTK_BOX(ihbox), context->lon); |
gtk_box_pack_start_defaults(GTK_BOX(ihbox), context->lon); |
503 |
gtk_box_pack_start_defaults(GTK_BOX(vbox), ihbox); |
gtk_box_pack_start_defaults(GTK_BOX(vbox), ihbox); |
504 |
context->dst = dist_entry_new(appdata->gt.distance, appdata->imperial); |
float dst = appdata->gt.distance; // distance is given in kilometers |
505 |
|
if(appdata->imperial) dst /= 1.609344; |
506 |
|
context->dst = dist_entry_new(dst, appdata->imperial); |
507 |
gtk_box_pack_start_defaults(GTK_BOX(vbox), context->dst); |
gtk_box_pack_start_defaults(GTK_BOX(vbox), context->dst); |
508 |
gtk_box_pack_start_defaults(GTK_BOX(hbox), vbox); |
gtk_box_pack_start_defaults(GTK_BOX(hbox), vbox); |
509 |
|
|
537 |
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
538 |
|
|
539 |
vbox = gtk_vbox_new(FALSE, 0); |
vbox = gtk_vbox_new(FALSE, 0); |
540 |
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
#ifndef FREMANTLE |
541 |
context->username = gtk_entry_new(); |
context->username = gtk_entry_new(); |
542 |
context->password = gtk_entry_new(); |
context->password = gtk_entry_new(); |
543 |
#else |
#else |
551 |
gtk_entry_set_visibility(GTK_ENTRY(context->password), FALSE); |
gtk_entry_set_visibility(GTK_ENTRY(context->password), FALSE); |
552 |
|
|
553 |
/* set saved defaults */ |
/* set saved defaults */ |
554 |
if(appdata->gt.username) |
if(appdata->username) |
555 |
gtk_entry_set_text(GTK_ENTRY(context->username), |
gtk_entry_set_text(GTK_ENTRY(context->username), |
556 |
appdata->gt.username); |
appdata->username); |
557 |
|
|
558 |
if(appdata->gt.password) |
if(appdata->gt.password) |
559 |
gtk_entry_set_text(GTK_ENTRY(context->password), |
gtk_entry_set_text(GTK_ENTRY(context->password), |
571 |
|
|
572 |
if(gtk_dialog_run(GTK_DIALOG(context->dialog)) == GTK_RESPONSE_OK) { |
if(gtk_dialog_run(GTK_DIALOG(context->dialog)) == GTK_RESPONSE_OK) { |
573 |
|
|
574 |
|
/* parse coordinates */ |
575 |
|
appdata->gt.lat = lat_get(context->lat); |
576 |
|
appdata->gt.lon = lon_get(context->lon); |
577 |
|
|
578 |
/* save values */ |
/* save values */ |
579 |
if(appdata->gt.username) g_free(appdata->gt.username); |
if(appdata->username) g_free(appdata->username); |
580 |
appdata->gt.username = |
appdata->username = |
581 |
g_strdup(gtk_entry_get_text(GTK_ENTRY(context->username))); |
g_strdup(gtk_entry_get_text(GTK_ENTRY(context->username))); |
582 |
|
|
583 |
if(appdata->gt.password) g_free(appdata->gt.password); |
if(appdata->gt.password) g_free(appdata->gt.password); |
588 |
appdata->gt.filename = |
appdata->gt.filename = |
589 |
g_strdup(gtk_label_get_text(GTK_LABEL(context->filename))); |
g_strdup(gtk_label_get_text(GTK_LABEL(context->filename))); |
590 |
|
|
591 |
ok = TRUE; |
/* get distance in kilometers */ |
592 |
|
appdata->gt.distance = dist_get(context->dst, FALSE); |
593 |
|
|
594 |
|
|
595 |
|
/* check for valid entries */ |
596 |
|
if(isnan(appdata->gt.lat) || isnan(appdata->gt.lon) || |
597 |
|
isnan(appdata->gt.distance) || !appdata->gt.filename || |
598 |
|
!appdata->username || !appdata->gt.password) |
599 |
|
errorf(_("The GeoToad setup is not complete.")); |
600 |
|
else |
601 |
|
ok = TRUE; |
602 |
} |
} |
603 |
|
|
604 |
gtk_widget_destroy(context->dialog); |
gtk_widget_destroy(context->dialog); |
615 |
|
|
616 |
gt_context_t *context = g_new0(gt_context_t, 1); |
gt_context_t *context = g_new0(gt_context_t, 1); |
617 |
context->appdata = appdata; |
context->appdata = appdata; |
618 |
|
context->use_cnt++; // parent still uses this |
619 |
|
|
620 |
|
context->update_mutex = g_mutex_new(); |
621 |
|
context->update_cond = g_cond_new(); |
622 |
|
|
623 |
printf("geoToad\n"); |
printf("geoToad\n"); |
624 |
|
|
625 |
if(gui_setup(context)) |
if(gui_setup(context)) |
626 |
gui_run(context); |
gui_run(context); |
627 |
|
|
628 |
|
/* continue to process if something has actually been saved */ |
629 |
|
if(context->state == GT_STATE_SAVE_FOUND) { |
630 |
|
/* download seems to be successful. Make sure the GUI is */ |
631 |
|
/* updated if required */ |
632 |
|
|
633 |
|
gpx_t **gpx = &(appdata->gpx); |
634 |
|
while(*gpx && strcmp((*gpx)->filename, appdata->gt.filename)) |
635 |
|
gpx = &(*gpx)->next; |
636 |
|
|
637 |
|
if(*gpx) { |
638 |
|
/* return main GUI to GPX list */ |
639 |
|
|
640 |
|
#ifdef USE_BREAD_CRUMB_TRAIL |
641 |
|
while(appdata->cur_gpx) |
642 |
|
hildon_bread_crumb_trail_pop(HILDON_BREAD_CRUMB_TRAIL(appdata->bct)); |
643 |
|
#elif defined(BCT) |
644 |
|
while(appdata->cur_gpx) |
645 |
|
bct_pop(appdata->bct); |
646 |
|
#else |
647 |
|
HildonWindowStack *stack = hildon_window_stack_get_default(); |
648 |
|
gint num = hildon_window_stack_size(stack)-1; |
649 |
|
while(num--) { |
650 |
|
GtkWidget *top = hildon_window_stack_peek(stack); |
651 |
|
gtk_widget_destroy(top); |
652 |
|
} |
653 |
|
#endif |
654 |
|
|
655 |
|
GtkTreeIter iter; |
656 |
|
g_assert(gpxlist_find(appdata, &iter, *gpx)); |
657 |
|
|
658 |
|
gpx_t *next = (*gpx)->next; |
659 |
|
|
660 |
|
gpx_free(*gpx); |
661 |
|
*gpx = gpx_parse(NULL, appdata->gt.filename, appdata->username); |
662 |
|
(*gpx)->next = next; |
663 |
|
|
664 |
|
/* update gpxlist */ |
665 |
|
gpxlist_set(appdata->gpxstore, &iter, *gpx); |
666 |
|
|
667 |
|
/* select that row */ |
668 |
|
GtkTreeSelection *selection = |
669 |
|
gtk_tree_view_get_selection(GTK_TREE_VIEW(appdata->gpxview)); |
670 |
|
gtk_tree_selection_select_iter(selection, &iter); |
671 |
|
GtkTreePath *path = |
672 |
|
gtk_tree_model_get_path(GTK_TREE_MODEL(appdata->gpxstore), &iter); |
673 |
|
gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(appdata->gpxview), |
674 |
|
path, NULL, TRUE, 0.0, 0.0); |
675 |
|
gtk_tree_path_free(path); |
676 |
|
|
677 |
|
} else |
678 |
|
printf("GPX file not imported\n"); |
679 |
|
|
680 |
|
} else |
681 |
|
errorf(_("GeoToad finished without result")); |
682 |
|
|
683 |
|
printf("main context free\n"); |
684 |
|
context_free(context); |
685 |
} |
} |
686 |
|
|
687 |
gboolean geotoad_available(void) { |
gboolean geotoad_available(void) { |