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 |
|
#if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >= 5) |
30 |
|
#include <hildon/hildon-entry.h> |
31 |
|
#include <hildon/hildon-touch-selector.h> |
32 |
|
#include <hildon/hildon-picker-button.h> |
33 |
|
#include <hildon/hildon-picker-dialog.h> |
34 |
|
#endif |
35 |
|
|
36 |
|
#ifdef FREMANTLE |
37 |
|
#define PICKER_DIALOG |
38 |
|
#endif |
39 |
|
|
40 |
char strlastchr(char *str) { |
char strlastchr(char *str) { |
41 |
return str[strlen(str)]-1; |
return str[strlen(str)]-1; |
42 |
} |
} |
79 |
char *c = _("N"); |
char *c = _("N"); |
80 |
float integral, fractional; |
float integral, fractional; |
81 |
|
|
82 |
if(latitude < 0) { latitude = fabs(latitude); c = _("S"); } |
if(isnan(latitude)) |
83 |
fractional = modff(latitude, &integral); |
str[0] = 0; |
84 |
|
else { |
85 |
|
if(latitude < 0) { latitude = fabs(latitude); c = _("S"); } |
86 |
|
fractional = modff(latitude, &integral); |
87 |
|
|
88 |
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); |
89 |
|
} |
90 |
} |
} |
91 |
|
|
92 |
GtkWidget *pos_lat(float latitude, int size, int strikethrough) { |
GtkWidget *pos_lat(float latitude, int size, int strikethrough) { |
100 |
char *c = _("E"); |
char *c = _("E"); |
101 |
float integral, fractional; |
float integral, fractional; |
102 |
|
|
103 |
if(longitude < 0) { longitude = fabs(longitude); c = _("W"); } |
if(isnan(longitude)) |
104 |
fractional = modff(longitude, &integral); |
str[0] = 0; |
105 |
|
else { |
106 |
|
if(longitude < 0) { longitude = fabs(longitude); c = _("W"); } |
107 |
|
fractional = modff(longitude, &integral); |
108 |
|
|
109 |
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); |
110 |
|
} |
111 |
} |
} |
112 |
|
|
113 |
GtkWidget *pos_lon(float longitude, int size, int strikethrough) { |
GtkWidget *pos_lon(float longitude, int size, int strikethrough) { |
162 |
|
|
163 |
const char *pos_get_bearing_str(pos_t from, pos_t to) { |
const char *pos_get_bearing_str(pos_t from, pos_t to) { |
164 |
static const char *bear_str[]={ |
static const char *bear_str[]={ |
165 |
"N", "NE", "E", "SE", "S", "SW", "W", "NW" }; |
"N", "NE", "E", "SE", "S", "SW", "W", "NW", "" }; |
166 |
int idx = (gpx_pos_get_bearing(from, to)+22.5)/45.0; |
|
167 |
/* make sure we stay in icon bounds */ |
float bearing = gpx_pos_get_bearing(from, to); |
168 |
while(idx < 0) idx += 8; |
if(!isnan(bearing)) { |
169 |
while(idx > 7) idx -= 8; |
int idx = (bearing+22.5)/45.0; |
170 |
return _(bear_str[idx]); |
/* make sure we stay in icon bounds */ |
171 |
|
while(idx < 0) idx += 8; |
172 |
|
while(idx > 7) idx -= 8; |
173 |
|
return _(bear_str[idx]); |
174 |
|
} |
175 |
|
|
176 |
|
return bear_str[8]; // empty string |
177 |
} |
} |
178 |
|
|
179 |
/* the maemo font size is quite huge, so we adjust some fonts */ |
/* the maemo font size is quite huge, so we adjust some fonts */ |
261 |
} |
} |
262 |
|
|
263 |
void distance_str(char *str, int len, float dist, gboolean imperial) { |
void distance_str(char *str, int len, float dist, gboolean imperial) { |
264 |
if(imperial) { |
if(isnan(dist)) |
265 |
|
snprintf(str, len, "---"); |
266 |
|
else if(imperial) { |
267 |
/* 1 mil = 1760 yd = 5280 ft ... */ |
/* 1 mil = 1760 yd = 5280 ft ... */ |
268 |
if(dist<0.018) snprintf(str, len, "%.1f ft", dist*5280.0); |
if(dist<0.018) snprintf(str, len, "%.1f ft", dist*5280.0); |
269 |
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); |
317 |
/* a entry that is colored red when being "active" */ |
/* a entry that is colored red when being "active" */ |
318 |
GtkWidget *lat_entry_new(float lat) { |
GtkWidget *lat_entry_new(float lat) { |
319 |
GdkColor color; |
GdkColor color; |
320 |
GtkWidget *widget = gtk_entry_new(); |
|
321 |
|
GtkWidget *widget = entry_new(); |
322 |
gdk_color_parse("#ff0000", &color); |
gdk_color_parse("#ff0000", &color); |
323 |
gtk_widget_modify_text(widget, TAG_STATE, &color); |
gtk_widget_modify_text(widget, TAG_STATE, &color); |
324 |
|
|
340 |
/* a entry that is colored red when filled with invalid coordinate */ |
/* a entry that is colored red when filled with invalid coordinate */ |
341 |
GtkWidget *lon_entry_new(float lon) { |
GtkWidget *lon_entry_new(float lon) { |
342 |
GdkColor color; |
GdkColor color; |
343 |
GtkWidget *widget = gtk_entry_new(); |
|
344 |
|
GtkWidget *widget = entry_new(); |
345 |
|
// gtk_entry_set_width_chars(GTK_ENTRY(widget), 14); |
346 |
|
|
347 |
gdk_color_parse("#ff0000", &color); |
gdk_color_parse("#ff0000", &color); |
348 |
gtk_widget_modify_text(widget, TAG_STATE, &color); |
gtk_widget_modify_text(widget, TAG_STATE, &color); |
349 |
|
|
378 |
/* a entry that is colored red when filled with invalid distance */ |
/* a entry that is colored red when filled with invalid distance */ |
379 |
GtkWidget *dist_entry_new(float dist, gboolean mil) { |
GtkWidget *dist_entry_new(float dist, gboolean mil) { |
380 |
GdkColor color; |
GdkColor color; |
381 |
GtkWidget *widget = gtk_entry_new(); |
GtkWidget *widget = entry_new(); |
382 |
gdk_color_parse("#ff0000", &color); |
gdk_color_parse("#ff0000", &color); |
383 |
gtk_widget_modify_text(widget, TAG_STATE, &color); |
gtk_widget_modify_text(widget, TAG_STATE, &color); |
384 |
|
|
409 |
} |
} |
410 |
#endif |
#endif |
411 |
#endif |
#endif |
412 |
|
|
413 |
|
/* recursively remove an entire file system */ |
414 |
|
void rmdir_recursive(char *path) { |
415 |
|
GDir *dir = g_dir_open(path, 0, NULL); |
416 |
|
if(dir) { |
417 |
|
const char *name = g_dir_read_name(dir); |
418 |
|
while(name) { |
419 |
|
char *fullname = g_strdup_printf("%s/%s", path, name); |
420 |
|
// printf("deleting %s\n", fullname); |
421 |
|
|
422 |
|
if(g_file_test(fullname, G_FILE_TEST_IS_DIR)) |
423 |
|
rmdir_recursive(fullname); |
424 |
|
else if(g_file_test(fullname, G_FILE_TEST_IS_REGULAR)) |
425 |
|
g_remove(fullname); |
426 |
|
|
427 |
|
g_free(fullname); |
428 |
|
name = g_dir_read_name(dir); |
429 |
|
} |
430 |
|
|
431 |
|
g_dir_close(dir); |
432 |
|
} |
433 |
|
g_rmdir(path); |
434 |
|
} |
435 |
|
|
436 |
|
#ifdef ENABLE_BROWSER_INTERFACE |
437 |
|
static void on_link_clicked(GtkButton *button, gpointer data) { |
438 |
|
appdata_t *appdata = (appdata_t*)data; |
439 |
|
char *url = g_object_get_data(G_OBJECT(button), "url"); |
440 |
|
if(url) browser_url(appdata, url); |
441 |
|
} |
442 |
|
#endif |
443 |
|
|
444 |
|
/* a button containing a weblink */ |
445 |
|
GtkWidget *link_button_attrib(appdata_t *appdata, char *str, char *url, |
446 |
|
int size, int strikethrough) { |
447 |
|
|
448 |
|
#ifdef ENABLE_BROWSER_INTERFACE |
449 |
|
if(url) { |
450 |
|
GtkWidget *button = gtk_button_attrib(str, size, strikethrough); |
451 |
|
g_object_set_data(G_OBJECT(button), "url", url); |
452 |
|
gtk_signal_connect(GTK_OBJECT(button), "clicked", |
453 |
|
(GtkSignalFunc)on_link_clicked, appdata); |
454 |
|
|
455 |
|
return button; |
456 |
|
} |
457 |
|
#endif |
458 |
|
return gtk_label_attrib(str, size, strikethrough); |
459 |
|
} |
460 |
|
|
461 |
|
#ifdef ENABLE_BROWSER_INTERFACE |
462 |
|
static void on_link_id_clicked(GtkButton *button, gpointer data) { |
463 |
|
appdata_t *appdata = (appdata_t*)data; |
464 |
|
|
465 |
|
unsigned int id = (unsigned int)g_object_get_data(G_OBJECT(button), "id"); |
466 |
|
char *type = g_object_get_data(G_OBJECT(button), "type"); |
467 |
|
|
468 |
|
char *url = g_strdup_printf("http://www.geocaching.com/%s?id=%u", |
469 |
|
type, id); |
470 |
|
|
471 |
|
if(url) { |
472 |
|
browser_url(appdata, url); |
473 |
|
g_free(url); |
474 |
|
} |
475 |
|
} |
476 |
|
#endif |
477 |
|
|
478 |
|
GtkWidget *link_button_by_id(appdata_t *appdata, char *str, |
479 |
|
const char *type, int id) { |
480 |
|
|
481 |
|
#ifdef ENABLE_BROWSER_INTERFACE |
482 |
|
if(id) { |
483 |
|
GtkWidget *ref = gtk_button_new_with_label(str); |
484 |
|
#if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) |
485 |
|
// hildon_gtk_widget_set_theme_size(ref, |
486 |
|
// (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); |
487 |
|
#endif |
488 |
|
g_object_set_data(G_OBJECT(ref), "id", (gpointer)id); |
489 |
|
g_object_set_data(G_OBJECT(ref), "type", (gpointer)type); |
490 |
|
gtk_signal_connect(GTK_OBJECT(ref), "clicked", |
491 |
|
GTK_SIGNAL_FUNC(on_link_id_clicked), appdata); |
492 |
|
|
493 |
|
return ref; |
494 |
|
} |
495 |
|
#endif |
496 |
|
return gtk_label_new(str); |
497 |
|
} |
498 |
|
|
499 |
|
|
500 |
|
GtkWidget *link_icon_button_by_id(appdata_t *appdata, GtkWidget *icon, |
501 |
|
const char *type, int id) { |
502 |
|
|
503 |
|
#ifdef ENABLE_BROWSER_INTERFACE |
504 |
|
if(id) { |
505 |
|
GtkWidget *ref = gtk_button_new(); |
506 |
|
gtk_button_set_image(GTK_BUTTON(ref), icon); |
507 |
|
|
508 |
|
#if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) |
509 |
|
// hildon_gtk_widget_set_theme_size(ref, |
510 |
|
// (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); |
511 |
|
#endif |
512 |
|
g_object_set_data(G_OBJECT(ref), "id", (gpointer)id); |
513 |
|
g_object_set_data(G_OBJECT(ref), "type", (gpointer)type); |
514 |
|
gtk_signal_connect(GTK_OBJECT(ref), "clicked", |
515 |
|
GTK_SIGNAL_FUNC(on_link_id_clicked), appdata); |
516 |
|
|
517 |
|
return ref; |
518 |
|
} |
519 |
|
#endif |
520 |
|
return icon; |
521 |
|
} |
522 |
|
|
523 |
|
/* left aligned, word wrapped multiline widget */ |
524 |
|
GtkWidget *simple_text_widget(char *text) { |
525 |
|
GtkWidget *label = gtk_label_new(text); |
526 |
|
|
527 |
|
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
528 |
|
gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD); |
529 |
|
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); |
530 |
|
|
531 |
|
return label; |
532 |
|
} |
533 |
|
|
534 |
|
|
535 |
|
/* a label that is left aligned */ |
536 |
|
GtkWidget *left_label_new(char *str) { |
537 |
|
GtkWidget *widget = gtk_label_new(str); |
538 |
|
gtk_misc_set_alignment(GTK_MISC(widget), 0.0f, 0.5f); |
539 |
|
return widget; |
540 |
|
} |
541 |
|
|
542 |
|
static void pos_set(GtkWidget *item, float lat, float lon) { |
543 |
|
char str[32]; |
544 |
|
|
545 |
|
pos_lat_str(str, sizeof(str)-1, lat); |
546 |
|
GtkWidget *lat_entry = g_object_get_data(G_OBJECT(item), "lat_entry"); |
547 |
|
gtk_entry_set_text(GTK_ENTRY(lat_entry), str); |
548 |
|
|
549 |
|
pos_lon_str(str, sizeof(str)-1, lon); |
550 |
|
GtkWidget *lon_entry = g_object_get_data(G_OBJECT(item), "lon_entry"); |
551 |
|
gtk_entry_set_text(GTK_ENTRY(lon_entry), str); |
552 |
|
} |
553 |
|
|
554 |
|
static void cb_gps(GtkWidget *item, gpointer data) { |
555 |
|
appdata_t *appdata = (appdata_t*)data; |
556 |
|
|
557 |
|
pos_t *refpos = get_pos(appdata); |
558 |
|
if(!refpos) pos_set(item, NAN, NAN); |
559 |
|
else pos_set(item, refpos->lat, refpos->lon); |
560 |
|
} |
561 |
|
|
562 |
|
static void cb_geomath(GtkWidget *item, gpointer data) { |
563 |
|
appdata_t *appdata = (appdata_t*)data; |
564 |
|
|
565 |
|
pos_set(item, appdata->geomath.lat, appdata->geomath.lon); |
566 |
|
} |
567 |
|
|
568 |
|
#ifdef ENABLE_OSM_GPS_MAP |
569 |
|
static void cb_map(GtkWidget *item, gpointer data) { |
570 |
|
appdata_t *appdata = (appdata_t*)data; |
571 |
|
|
572 |
|
pos_set(item, appdata->map.pos.lat, appdata->map.pos.lon); |
573 |
|
} |
574 |
|
#endif |
575 |
|
|
576 |
|
static void cb_cache(GtkWidget *item, gpointer data) { |
577 |
|
appdata_t *appdata = (appdata_t*)data; |
578 |
|
|
579 |
|
cache_t *cache = appdata->cur_cache; |
580 |
|
g_assert(cache); |
581 |
|
|
582 |
|
gint id = (gint)g_object_get_data(G_OBJECT(item), "id"); |
583 |
|
|
584 |
|
if(!id) |
585 |
|
pos_set(item, cache->pos.lat, cache->pos.lon); |
586 |
|
else { |
587 |
|
wpt_t *wpt = cache->wpt; |
588 |
|
while(wpt && id > 1) { |
589 |
|
wpt = wpt->next; |
590 |
|
id--; |
591 |
|
} |
592 |
|
|
593 |
|
if(id == 1) |
594 |
|
pos_set(item, wpt->pos.lat, wpt->pos.lon); |
595 |
|
} |
596 |
|
} |
597 |
|
|
598 |
|
#ifndef PICKER_DIALOG |
599 |
|
static GtkWidget *menu_add(GtkWidget *menu, appdata_t *appdata, |
600 |
|
GtkWidget *icon, char *menu_str, |
601 |
|
void(*func)(GtkWidget*, gpointer), gint id, |
602 |
|
GtkWidget *lon_entry, GtkWidget *lat_entry) { |
603 |
|
|
604 |
|
GtkWidget *item = gtk_image_menu_item_new_with_label(menu_str); |
605 |
|
|
606 |
|
if(icon) |
607 |
|
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), icon); |
608 |
|
|
609 |
|
g_object_set_data(G_OBJECT(item), "lat_entry", (gpointer)lat_entry); |
610 |
|
g_object_set_data(G_OBJECT(item), "lon_entry", (gpointer)lon_entry); |
611 |
|
g_object_set_data(G_OBJECT(item), "id", (gpointer)id); |
612 |
|
|
613 |
|
if(func) |
614 |
|
gtk_signal_connect(GTK_OBJECT(item), "activate", |
615 |
|
(GtkSignalFunc)func, appdata); |
616 |
|
|
617 |
|
gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); |
618 |
|
|
619 |
|
return item; |
620 |
|
} |
621 |
|
|
622 |
|
static GtkWidget *popup_menu_create(appdata_t *appdata, |
623 |
|
GtkWidget *lat_entry, GtkWidget *lon_entry) { |
624 |
|
GtkWidget *menu = gtk_menu_new(); |
625 |
|
|
626 |
|
menu_add(menu, appdata, icon_get_widget(ICON_POS, 18), |
627 |
|
_("Current position (GPS)"), cb_gps, 0, lon_entry, lat_entry); |
628 |
|
menu_add(menu, appdata, icon_get_widget(ICON_POS, 19), |
629 |
|
_("Geomath projection"), cb_geomath, 0, lon_entry, lat_entry); |
630 |
|
#ifdef ENABLE_OSM_GPS_MAP |
631 |
|
menu_add(menu, appdata, icon_get_widget(ICON_POS, 20), |
632 |
|
_("Map position"), cb_map, 0, lon_entry, lat_entry); |
633 |
|
#endif |
634 |
|
|
635 |
|
if(appdata->cur_cache) { |
636 |
|
cache_t *cache = appdata->cur_cache; |
637 |
|
|
638 |
|
char *name = cache->name; |
639 |
|
if(!name) name = cache->id; |
640 |
|
|
641 |
|
if(!isnan(cache->pos.lat) && !isnan(cache->pos.lon)) { |
642 |
|
menu_add(menu, appdata, icon_get_widget(ICON_POS, cache->type + 6), |
643 |
|
name, cb_cache, 0, lon_entry, lat_entry); |
644 |
|
} |
645 |
|
|
646 |
|
wpt_t *wpt = cache->wpt; |
647 |
|
gint id = 1; |
648 |
|
while(wpt) { |
649 |
|
GtkWidget *icon = NULL; |
650 |
|
if(wpt->sym != WPT_SYM_UNKNOWN) |
651 |
|
icon = icon_get_widget(ICON_POS, wpt->sym); |
652 |
|
|
653 |
|
char *name = wpt->desc; |
654 |
|
if(!name) name = wpt->cmt; |
655 |
|
if(!name) name = wpt->id; |
656 |
|
|
657 |
|
menu_add(menu, appdata, icon, name, cb_cache, id++, |
658 |
|
lon_entry, lat_entry); |
659 |
|
|
660 |
|
wpt = wpt->next; |
661 |
|
} |
662 |
|
} |
663 |
|
|
664 |
|
gtk_widget_show_all(menu); |
665 |
|
|
666 |
|
return menu; |
667 |
|
} |
668 |
|
|
669 |
|
static gint on_popup_button_press(GtkWidget *button, GdkEventButton *event, |
670 |
|
gpointer data) { |
671 |
|
|
672 |
|
if(event->type == GDK_BUTTON_PRESS) { |
673 |
|
GtkWidget *menu = g_object_get_data(G_OBJECT(button), "menu"); |
674 |
|
|
675 |
|
/* draw a popup menu */ |
676 |
|
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, |
677 |
|
event->button, event->time); |
678 |
|
return TRUE; |
679 |
|
} |
680 |
|
return FALSE; |
681 |
|
} |
682 |
|
|
683 |
|
static void on_popup_destroy(GtkWidget *widget, gpointer user_data ) { |
684 |
|
GtkWidget *menu = g_object_get_data(G_OBJECT(widget), "menu"); |
685 |
|
gtk_widget_destroy(menu); |
686 |
|
} |
687 |
|
#endif |
688 |
|
|
689 |
|
#ifdef PICKER_DIALOG |
690 |
|
|
691 |
|
enum { |
692 |
|
PICKER_COL_ICON = 0, |
693 |
|
PICKER_COL_NAME, |
694 |
|
PICKER_COL_ID, |
695 |
|
PICKER_COL_CB, |
696 |
|
PICKER_NUM_COLS |
697 |
|
}; |
698 |
|
|
699 |
|
static void picker_add(GtkListStore *store, appdata_t *appdata, |
700 |
|
GdkPixbuf *icon, char *menu_str, |
701 |
|
void(*func)(GtkWidget*, gpointer), gint id) { |
702 |
|
GtkTreeIter iter; |
703 |
|
|
704 |
|
/* Append a row and fill in some data */ |
705 |
|
gtk_list_store_append (store, &iter); |
706 |
|
|
707 |
|
gtk_list_store_set(store, &iter, |
708 |
|
PICKER_COL_ICON, icon, |
709 |
|
PICKER_COL_NAME, menu_str, |
710 |
|
PICKER_COL_ID, id, |
711 |
|
PICKER_COL_CB, func, |
712 |
|
-1); |
713 |
|
} |
714 |
|
|
715 |
|
static void on_picker_activated(GtkTreeView *treeview, |
716 |
|
GtkTreePath *path, |
717 |
|
GtkTreeViewColumn *col, |
718 |
|
gpointer userdata) { |
719 |
|
GtkTreeIter iter; |
720 |
|
GtkTreeModel *model = gtk_tree_view_get_model(treeview); |
721 |
|
|
722 |
|
if(gtk_tree_model_get_iter(model, &iter, path)) { |
723 |
|
gint id; |
724 |
|
void(*func)(GtkWidget*, gpointer); |
725 |
|
gtk_tree_model_get(model, &iter, |
726 |
|
PICKER_COL_ID, &id, |
727 |
|
PICKER_COL_CB, &func, |
728 |
|
-1); |
729 |
|
|
730 |
|
/* set id on widget as callbacks expect it this way */ |
731 |
|
g_object_set_data(G_OBJECT(treeview), "id", (gpointer)id); |
732 |
|
func(GTK_WIDGET(treeview), userdata); |
733 |
|
} |
734 |
|
} |
735 |
|
|
736 |
|
static GtkWidget *picker_create(appdata_t *appdata, |
737 |
|
GtkWidget *lat_entry, GtkWidget *lon_entry) { |
738 |
|
GtkCellRenderer *renderer; |
739 |
|
GtkListStore *store; |
740 |
|
|
741 |
|
GtkWidget *view = gtk_tree_view_new(); |
742 |
|
|
743 |
|
g_object_set_data(G_OBJECT(view), "lat_entry", (gpointer)lat_entry); |
744 |
|
g_object_set_data(G_OBJECT(view), "lon_entry", (gpointer)lon_entry); |
745 |
|
|
746 |
|
/* --- "Icon" column --- */ |
747 |
|
renderer = gtk_cell_renderer_pixbuf_new(); |
748 |
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), |
749 |
|
-1, "Icon", renderer, "pixbuf", PICKER_COL_ICON, NULL); |
750 |
|
|
751 |
|
/* --- "Name" column --- */ |
752 |
|
renderer = gtk_cell_renderer_text_new(); |
753 |
|
g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL ); |
754 |
|
GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes( |
755 |
|
"Name", renderer, "text", PICKER_COL_NAME, NULL); |
756 |
|
gtk_tree_view_column_set_expand(column, TRUE); |
757 |
|
gtk_tree_view_insert_column(GTK_TREE_VIEW(view), column, -1); |
758 |
|
|
759 |
|
store = gtk_list_store_new(PICKER_NUM_COLS, |
760 |
|
GDK_TYPE_PIXBUF, |
761 |
|
G_TYPE_STRING, |
762 |
|
G_TYPE_INT, |
763 |
|
G_TYPE_POINTER); |
764 |
|
|
765 |
|
picker_add(store, appdata, icon_get(ICON_POS, 18), |
766 |
|
_("Current position (GPS)"), cb_gps, 0); |
767 |
|
picker_add(store, appdata, icon_get(ICON_POS, 19), |
768 |
|
_("Geomath projection"), cb_geomath, 0); |
769 |
|
#ifdef ENABLE_OSM_GPS_MAP |
770 |
|
picker_add(store, appdata, icon_get(ICON_POS, 20), |
771 |
|
_("Map position"), cb_map, 0); |
772 |
|
#endif |
773 |
|
|
774 |
|
if(appdata->cur_cache) { |
775 |
|
cache_t *cache = appdata->cur_cache; |
776 |
|
|
777 |
|
char *name = cache->name; |
778 |
|
if(!name) name = cache->id; |
779 |
|
|
780 |
|
if(!isnan(cache->pos.lat) && !isnan(cache->pos.lon)) { |
781 |
|
picker_add(store, appdata, icon_get(ICON_POS, cache->type + 6), |
782 |
|
name, cb_cache, 0); |
783 |
|
} |
784 |
|
|
785 |
|
wpt_t *wpt = cache->wpt; |
786 |
|
gint id = 1; |
787 |
|
while(wpt) { |
788 |
|
GdkPixbuf *icon = NULL; |
789 |
|
if(wpt->sym != WPT_SYM_UNKNOWN) |
790 |
|
icon = icon_get(ICON_POS, wpt->sym); |
791 |
|
|
792 |
|
char *name = wpt->desc; |
793 |
|
if(!name) name = wpt->cmt; |
794 |
|
if(!name) name = wpt->id; |
795 |
|
|
796 |
|
picker_add(store, appdata, icon, name, cb_cache, id++); |
797 |
|
wpt = wpt->next; |
798 |
|
} |
799 |
|
} |
800 |
|
|
801 |
|
|
802 |
|
gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); |
803 |
|
g_object_unref(store); |
804 |
|
|
805 |
|
/* make list react on clicks */ |
806 |
|
g_signal_connect(view, "row-activated", |
807 |
|
(GCallback)on_picker_activated, appdata); |
808 |
|
|
809 |
|
#if 0 |
810 |
|
g_signal_connect(view, "destroy", |
811 |
|
(GCallback)cachelist_destroy, ce); |
812 |
|
#endif |
813 |
|
|
814 |
|
/* put this inside a scrolled view */ |
815 |
|
#ifndef USE_PANNABLE_AREA |
816 |
|
GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL); |
817 |
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), |
818 |
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); |
819 |
|
gtk_container_add(GTK_CONTAINER(scrolled_window), view); |
820 |
|
return scrolled_window; |
821 |
|
#else |
822 |
|
GtkWidget *pannable_area = hildon_pannable_area_new(); |
823 |
|
gtk_container_add(GTK_CONTAINER(pannable_area), view); |
824 |
|
return pannable_area; |
825 |
|
#endif |
826 |
|
} |
827 |
|
|
828 |
|
static gint on_picker_button_press(GtkWidget *button, |
829 |
|
GdkEventButton *event, gpointer data) { |
830 |
|
appdata_t *appdata = (appdata_t*)data; |
831 |
|
|
832 |
|
gpointer lat_entry = g_object_get_data(G_OBJECT(button), "lat_entry"); |
833 |
|
gpointer lon_entry = g_object_get_data(G_OBJECT(button), "lon_entry"); |
834 |
|
|
835 |
|
if(event->type == GDK_BUTTON_PRESS) { |
836 |
|
GtkWidget *dialog = |
837 |
|
gtk_dialog_new_with_buttons(_("Preset coordinates"), |
838 |
|
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), |
839 |
|
GTK_DIALOG_MODAL, |
840 |
|
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, |
841 |
|
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, |
842 |
|
NULL); |
843 |
|
|
844 |
|
gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 200); |
845 |
|
|
846 |
|
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), |
847 |
|
picker_create(appdata, lat_entry, lon_entry)); |
848 |
|
|
849 |
|
gtk_widget_show_all(dialog); |
850 |
|
gtk_dialog_run(GTK_DIALOG(dialog)); |
851 |
|
gtk_widget_destroy(dialog); |
852 |
|
|
853 |
|
return TRUE; |
854 |
|
} |
855 |
|
return FALSE; |
856 |
|
} |
857 |
|
#endif |
858 |
|
|
859 |
|
GtkWidget *coo_popup(appdata_t *appdata, |
860 |
|
GtkWidget *lat_entry, GtkWidget *lon_entry) { |
861 |
|
|
862 |
|
GtkWidget *button = gtk_button_new(); |
863 |
|
|
864 |
|
gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_POS, 17)); |
865 |
|
|
866 |
|
gtk_widget_set_tooltip_text(button, _("Preset coordinates")); |
867 |
|
|
868 |
|
#ifndef PICKER_DIALOG |
869 |
|
gtk_signal_connect(GTK_OBJECT(button), "button-press-event", |
870 |
|
(GtkSignalFunc)on_popup_button_press, appdata); |
871 |
|
|
872 |
|
gtk_signal_connect(GTK_OBJECT(button), "destroy", |
873 |
|
(GtkSignalFunc)on_popup_destroy, appdata); |
874 |
|
|
875 |
|
g_object_set_data(G_OBJECT(button), "menu", |
876 |
|
popup_menu_create(appdata, lat_entry, lon_entry)); |
877 |
|
#else |
878 |
|
#ifdef FREMANTLE |
879 |
|
hildon_gtk_widget_set_theme_size(button, |
880 |
|
(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); |
881 |
|
#endif |
882 |
|
|
883 |
|
g_object_set_data(G_OBJECT(button), "lat_entry", (gpointer)lat_entry); |
884 |
|
g_object_set_data(G_OBJECT(button), "lon_entry", (gpointer)lon_entry); |
885 |
|
|
886 |
|
gtk_signal_connect(GTK_OBJECT(button), "button-press-event", |
887 |
|
(GtkSignalFunc)on_picker_button_press, appdata); |
888 |
|
#endif |
889 |
|
|
890 |
|
return button; |
891 |
|
} |
892 |
|
|
893 |
|
GtkWidget *entry_new(void) { |
894 |
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
895 |
|
return gtk_entry_new(); |
896 |
|
#else |
897 |
|
return hildon_entry_new(HILDON_SIZE_AUTO); |
898 |
|
#endif |
899 |
|
} |
900 |
|
|
901 |
|
gboolean pos_differ(pos_t *pos1, pos_t *pos2) { |
902 |
|
int lat1 = (60000 * pos1->lat)+0.5, lon1 = (60000 * pos1->lon)+0.5; |
903 |
|
int lat2 = (60000 * pos2->lat)+0.5, lon2 = (60000 * pos2->lon)+0.5; |
904 |
|
|
905 |
|
return((lat1 != lat2) || (lon1 != lon2)); |
906 |
|
} |
907 |
|
|