21 |
#include <string.h> |
#include <string.h> |
22 |
#include <ctype.h> |
#include <ctype.h> |
23 |
|
|
24 |
|
#include <glib.h> |
25 |
|
#include <glib/gstdio.h> |
26 |
|
|
27 |
#include "gpxview.h" |
#include "gpxview.h" |
28 |
|
|
29 |
char strlastchr(char *str) { |
char strlastchr(char *str) { |
68 |
char *c = _("N"); |
char *c = _("N"); |
69 |
float integral, fractional; |
float integral, fractional; |
70 |
|
|
71 |
if(latitude < 0) { latitude = fabs(latitude); c = _("S"); } |
if(isnan(latitude)) |
72 |
fractional = modff(latitude, &integral); |
str[0] = 0; |
73 |
|
else { |
74 |
|
if(latitude < 0) { latitude = fabs(latitude); c = _("S"); } |
75 |
|
fractional = modff(latitude, &integral); |
76 |
|
|
77 |
snprintf(str, len, "%s %02d° %06.3f'", c, (int)integral, fractional*60.0); |
snprintf(str, len, "%s %02d° %06.3f'", c, (int)integral, fractional*60.0); |
78 |
|
} |
79 |
} |
} |
80 |
|
|
81 |
GtkWidget *pos_lat(float latitude, int size, int strikethrough) { |
GtkWidget *pos_lat(float latitude, int size, int strikethrough) { |
89 |
char *c = _("E"); |
char *c = _("E"); |
90 |
float integral, fractional; |
float integral, fractional; |
91 |
|
|
92 |
if(longitude < 0) { longitude = fabs(longitude); c = _("W"); } |
if(isnan(longitude)) |
93 |
fractional = modff(longitude, &integral); |
str[0] = 0; |
94 |
|
else { |
95 |
|
if(longitude < 0) { longitude = fabs(longitude); c = _("W"); } |
96 |
|
fractional = modff(longitude, &integral); |
97 |
|
|
98 |
snprintf(str, len, "%s %03d° %06.3f'", c, (int)integral, fractional*60.0); |
snprintf(str, len, "%s %03d° %06.3f'", c, (int)integral, fractional*60.0); |
99 |
|
} |
100 |
} |
} |
101 |
|
|
102 |
GtkWidget *pos_lon(float longitude, int size, int strikethrough) { |
GtkWidget *pos_lon(float longitude, int size, int strikethrough) { |
244 |
} |
} |
245 |
|
|
246 |
void distance_str(char *str, int len, float dist, gboolean imperial) { |
void distance_str(char *str, int len, float dist, gboolean imperial) { |
247 |
if(imperial) { |
if(isnan(dist)) |
248 |
|
snprintf(str, len, "---"); |
249 |
|
else if(imperial) { |
250 |
/* 1 mil = 1760 yd = 5280 ft ... */ |
/* 1 mil = 1760 yd = 5280 ft ... */ |
251 |
if(dist<0.018) snprintf(str, len, "%.1f ft", dist*5280.0); |
if(dist<0.018) snprintf(str, len, "%.1f ft", dist*5280.0); |
252 |
else if(dist<0.055) snprintf(str, len, "%.1f yd", dist*1760.0); |
else if(dist<0.055) snprintf(str, len, "%.1f yd", dist*1760.0); |
388 |
} |
} |
389 |
#endif |
#endif |
390 |
#endif |
#endif |
391 |
|
|
392 |
|
/* recursively remove an entire file system */ |
393 |
|
void rmdir_recursive(char *path) { |
394 |
|
GDir *dir = g_dir_open(path, 0, NULL); |
395 |
|
if(dir) { |
396 |
|
const char *name = g_dir_read_name(dir); |
397 |
|
while(name) { |
398 |
|
char *fullname = g_strdup_printf("%s/%s", path, name); |
399 |
|
// printf("deleting %s\n", fullname); |
400 |
|
|
401 |
|
if(g_file_test(fullname, G_FILE_TEST_IS_DIR)) |
402 |
|
rmdir_recursive(fullname); |
403 |
|
else if(g_file_test(fullname, G_FILE_TEST_IS_REGULAR)) |
404 |
|
g_remove(fullname); |
405 |
|
|
406 |
|
g_free(fullname); |
407 |
|
name = g_dir_read_name(dir); |
408 |
|
} |
409 |
|
|
410 |
|
g_dir_close(dir); |
411 |
|
} |
412 |
|
g_rmdir(path); |
413 |
|
} |
414 |
|
|
415 |
|
#ifdef ENABLE_BROWSER_INTERFACE |
416 |
|
static void on_link_clicked(GtkButton *button, gpointer data) { |
417 |
|
appdata_t *appdata = (appdata_t*)data; |
418 |
|
char *url = g_object_get_data(G_OBJECT(button), "url"); |
419 |
|
if(url) browser_url(appdata, url); |
420 |
|
} |
421 |
|
#endif |
422 |
|
|
423 |
|
/* a button containing a weblink */ |
424 |
|
GtkWidget *link_button_attrib(appdata_t *appdata, char *str, char *url, |
425 |
|
int size, int strikethrough) { |
426 |
|
|
427 |
|
#ifdef ENABLE_BROWSER_INTERFACE |
428 |
|
if(url) { |
429 |
|
GtkWidget *button = gtk_button_attrib(str, size, strikethrough); |
430 |
|
g_object_set_data(G_OBJECT(button), "url", url); |
431 |
|
gtk_signal_connect(GTK_OBJECT(button), "clicked", |
432 |
|
(GtkSignalFunc)on_link_clicked, appdata); |
433 |
|
|
434 |
|
return button; |
435 |
|
} |
436 |
|
#endif |
437 |
|
return gtk_label_attrib(str, size, strikethrough); |
438 |
|
} |
439 |
|
|
440 |
|
#ifdef ENABLE_BROWSER_INTERFACE |
441 |
|
static void on_link_id_clicked(GtkButton *button, gpointer data) { |
442 |
|
appdata_t *appdata = (appdata_t*)data; |
443 |
|
|
444 |
|
unsigned int id = (unsigned int)g_object_get_data(G_OBJECT(button), "id"); |
445 |
|
char *type = g_object_get_data(G_OBJECT(button), "type"); |
446 |
|
|
447 |
|
char *url = g_strdup_printf("http://www.geocaching.com/%s?id=%u", |
448 |
|
type, id); |
449 |
|
|
450 |
|
if(url) { |
451 |
|
browser_url(appdata, url); |
452 |
|
g_free(url); |
453 |
|
} |
454 |
|
} |
455 |
|
#endif |
456 |
|
|
457 |
|
GtkWidget *link_button_by_id(appdata_t *appdata, char *str, |
458 |
|
const char *type, int id) { |
459 |
|
|
460 |
|
#ifdef ENABLE_BROWSER_INTERFACE |
461 |
|
if(id) { |
462 |
|
GtkWidget *ref = gtk_button_new_with_label(str); |
463 |
|
#if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) |
464 |
|
// hildon_gtk_widget_set_theme_size(ref, |
465 |
|
// (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); |
466 |
|
#endif |
467 |
|
g_object_set_data(G_OBJECT(ref), "id", (gpointer)id); |
468 |
|
g_object_set_data(G_OBJECT(ref), "type", (gpointer)type); |
469 |
|
gtk_signal_connect(GTK_OBJECT(ref), "clicked", |
470 |
|
GTK_SIGNAL_FUNC(on_link_id_clicked), appdata); |
471 |
|
|
472 |
|
return ref; |
473 |
|
} |
474 |
|
#endif |
475 |
|
return gtk_label_new(str); |
476 |
|
} |
477 |
|
|