38 |
#define SAT_WIDTH 330 |
#define SAT_WIDTH 330 |
39 |
#define SAT_HEIGHT 60 |
#define SAT_HEIGHT 60 |
40 |
|
|
41 |
/* http://www.gtk.org/tutorial1.2/gtk_tut-30.html */ |
#ifdef ESPEAK |
42 |
/* http://developer.gimp.org/api/2.0/gdk/gdk-Drawing-Primitives.html */ |
#include <espeak/speak_lib.h> |
43 |
|
|
44 |
|
#define ESPEAK_TIMEOUT (15000) // every 15 seconds |
45 |
|
|
46 |
|
char *espeak_make_string(float dist, gboolean imperial) { |
47 |
|
char *retval = NULL; |
48 |
|
|
49 |
|
if(!imperial) { |
50 |
|
/* distance is in kilometers */ |
51 |
|
if(dist < 2.0/1000.0) |
52 |
|
retval = g_strdup(_("1 meter")); |
53 |
|
else if(dist < 1.0) |
54 |
|
retval = g_strdup_printf(_("%u meters"), (int)(dist*1000)); |
55 |
|
else if(dist < 2.0) |
56 |
|
retval = g_strdup(_("1 kilometer")); |
57 |
|
else |
58 |
|
retval = g_strdup_printf(_("%u kilometers"), (int)dist); |
59 |
|
} else { |
60 |
|
|
61 |
|
/* 1 mil = 1760 yd = 5280 ft ... */ |
62 |
|
if(dist < (2.0/5280.0)) |
63 |
|
retval = g_strdup(_("1 foot")); |
64 |
|
else if(dist < (1.0/1760.0)) |
65 |
|
retval = g_strdup_printf(_("%u feet"), (int)(dist*5280)); |
66 |
|
else if(dist < (2.0/1760.0)) |
67 |
|
retval = g_strdup(_("1 yard")); |
68 |
|
else if(dist < 1.0) |
69 |
|
retval = g_strdup_printf(_("%u yard"), (int)(dist*1760)); |
70 |
|
else if(dist < 2.0) |
71 |
|
retval = g_strdup(_("1 mile")); |
72 |
|
else |
73 |
|
retval = g_strdup_printf(_("%u miles"), (int)dist); |
74 |
|
} |
75 |
|
return retval; |
76 |
|
} |
77 |
|
|
78 |
|
static gboolean espeak_do(gpointer data) { |
79 |
|
cache_context_t *context = (cache_context_t*)data; |
80 |
|
|
81 |
|
pos_t *pos = gps_get_pos(context->appdata); |
82 |
|
if(pos && !isnan(pos->lat) && !isnan(pos->lon) && |
83 |
|
!isnan(context->gotoc.pos.lat) && !isnan(context->gotoc.pos.lon)) { |
84 |
|
|
85 |
|
/* build distance */ |
86 |
|
float dist = |
87 |
|
gpx_pos_get_distance(*pos, context->gotoc.pos, |
88 |
|
context->appdata->imperial); |
89 |
|
|
90 |
|
char *talk = espeak_make_string(dist, context->appdata->imperial); |
91 |
|
|
92 |
|
unsigned int unique_identifier=0; |
93 |
|
espeak_Synth(talk, strlen(talk)+1, 0, 0, 0, espeakCHARS_AUTO, |
94 |
|
&unique_identifier, NULL); |
95 |
|
|
96 |
|
g_free(talk); |
97 |
|
} |
98 |
|
|
99 |
|
return TRUE; // speak again |
100 |
|
} |
101 |
|
|
102 |
|
static void espeak_enable(cache_context_t *context, gboolean enable) { |
103 |
|
if(enable) { |
104 |
|
g_assert(!context->gotoc.espeak_handler); |
105 |
|
|
106 |
|
context->gotoc.espeak_handler = |
107 |
|
gtk_timeout_add(ESPEAK_TIMEOUT, espeak_do, context); |
108 |
|
|
109 |
|
espeak_do(context); |
110 |
|
|
111 |
|
} else { |
112 |
|
if(context->gotoc.espeak_handler) { |
113 |
|
gtk_timeout_remove(context->gotoc.espeak_handler); |
114 |
|
context->gotoc.espeak_handler = 0; |
115 |
|
} |
116 |
|
} |
117 |
|
} |
118 |
|
#endif |
119 |
|
|
120 |
static float rad2deg(float rad) { |
static float rad2deg(float rad) { |
121 |
return fmodf(360.0 + (180.0/M_PI) * rad, 360.0); |
return fmodf(360.0 + (180.0/M_PI) * rad, 360.0); |
163 |
/* draw the locked/unlocked icon */ |
/* draw the locked/unlocked icon */ |
164 |
gdk_draw_pixbuf(context->gotoc.compass_pixmap, |
gdk_draw_pixbuf(context->gotoc.compass_pixmap, |
165 |
widget->style->fg_gc[GTK_STATE_NORMAL], |
widget->style->fg_gc[GTK_STATE_NORMAL], |
166 |
icon_get(ICON_MISC, context->appdata->compass_locked?1:2), |
icon_get(ICON_MISC, context->appdata->compass_locked?0:1), |
167 |
0, 0, (width-diameter)/2 + diameter/32, |
0, 0, (width-diameter)/2 + diameter/32, |
168 |
(height+diameter)/2 - 16 - diameter/32 , 16, 16, |
(height+diameter)/2 - 16 - diameter/32 , 16, 16, |
169 |
GDK_RGB_DITHER_NONE,0,0); |
GDK_RGB_DITHER_NONE,0,0); |
462 |
|
|
463 |
printf("destroying goto view\n"); |
printf("destroying goto view\n"); |
464 |
|
|
465 |
|
#ifdef ESPEAK |
466 |
|
espeak_enable(context, FALSE); |
467 |
|
#endif |
468 |
|
|
469 |
/* stop timer */ |
/* stop timer */ |
470 |
if(context->gotoc.handler_id) |
if(context->gotoc.handler_id) |
471 |
gtk_timeout_remove(context->gotoc.handler_id); |
gtk_timeout_remove(context->gotoc.handler_id); |
531 |
return TRUE; // fire again |
return TRUE; // fire again |
532 |
} |
} |
533 |
|
|
|
#ifdef ENABLE_MAEMO_MAPPER |
|
|
static void on_mm_button_clicked(GtkButton *button, gpointer data) { |
|
|
cache_context_t *context = (cache_context_t*)data; |
|
|
|
|
|
dbus_mm_set_position(context->appdata, &context->gotoc.pos); |
|
|
} |
|
|
#endif |
|
|
|
|
534 |
static gboolean compass_clicked_event(GtkWidget *widget, GdkEventButton *event, |
static gboolean compass_clicked_event(GtkWidget *widget, GdkEventButton *event, |
535 |
gpointer user_data) { |
gpointer user_data) { |
536 |
cache_context_t *context = (cache_context_t*)user_data; |
cache_context_t *context = (cache_context_t*)user_data; |
560 |
goto_update(context); |
goto_update(context); |
561 |
} |
} |
562 |
|
|
563 |
|
#ifdef ESPEAK |
564 |
|
static void espeak_clicked(GtkWidget *widget, gpointer data) { |
565 |
|
cache_context_t *context = (cache_context_t*)data; |
566 |
|
|
567 |
|
GtkWidget *icon = gtk_button_get_image(GTK_BUTTON(widget)); |
568 |
|
gtk_widget_destroy(icon); |
569 |
|
context->appdata->espeak.enabled = !context->appdata->espeak.enabled; |
570 |
|
gtk_button_set_image(GTK_BUTTON(widget), icon_get_widget(ICON_MISC, |
571 |
|
context->appdata->espeak.enabled?6:7)); |
572 |
|
|
573 |
|
espeak_enable(context, context->appdata->espeak.enabled); |
574 |
|
} |
575 |
|
#endif |
576 |
|
|
577 |
GtkWidget *goto_cache(cache_context_t *context) { |
GtkWidget *goto_cache(cache_context_t *context) { |
578 |
int i; |
int i; |
579 |
|
|
619 |
g_signal_connect(G_OBJECT(context->gotoc.lon_entry), "changed", |
g_signal_connect(G_OBJECT(context->gotoc.lon_entry), "changed", |
620 |
G_CALLBACK(pos_modified), context); |
G_CALLBACK(pos_modified), context); |
621 |
|
|
622 |
context->gotoc.coo_popup = preset_coordinate_picker(context->appdata, |
gtk_table_attach_defaults(GTK_TABLE(table), preset_coordinate_picker(context->appdata, |
623 |
context->gotoc.lat_entry, context->gotoc.lon_entry); |
context->gotoc.lat_entry, context->gotoc.lon_entry), 2,3,0,1); |
624 |
gtk_table_attach_defaults(GTK_TABLE(table), |
|
625 |
context->gotoc.coo_popup, 2,3,0,1); |
gtk_table_attach_defaults(GTK_TABLE(table), goto_coordinate(context->appdata, |
626 |
|
context->gotoc.lat_entry, context->gotoc.lon_entry), 2,3,1,2); |
627 |
|
|
628 |
gtk_table_set_row_spacing(GTK_TABLE(table), 1, 16); |
gtk_table_set_row_spacing(GTK_TABLE(table), 1, 16); |
629 |
gtk_table_set_col_spacing(GTK_TABLE(table), 0, 16); |
gtk_table_set_col_spacing(GTK_TABLE(table), 0, 16); |
631 |
/* -------------- distance label ------------------------- */ |
/* -------------- distance label ------------------------- */ |
632 |
gtk_table_attach_defaults(GTK_TABLE(table), left_label_new(_("Distance:")), 0,1,2,3); |
gtk_table_attach_defaults(GTK_TABLE(table), left_label_new(_("Distance:")), 0,1,2,3); |
633 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), |
634 |
(context->gotoc.distance_label = left_label_new("-----")), 1,2,2,3); |
(context->gotoc.distance_label = gtk_label_new("-----")), 1,2,2,3); |
635 |
|
|
636 |
/* -------------- bearing label ------------------------- */ |
/* -------------- bearing label ------------------------- */ |
637 |
gtk_table_attach_defaults(GTK_TABLE(table), left_label_new(_("Bearing:")), 0,1,3,4); |
gtk_table_attach_defaults(GTK_TABLE(table), left_label_new(_("Bearing:")), 0,1,3,4); |
638 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), |
639 |
(context->gotoc.bearing_label = left_label_new("-----")), 1,2,3,4); |
(context->gotoc.bearing_label = gtk_label_new("-----")), 1,2,3,4); |
640 |
|
|
641 |
/* -------------- error label ------------------------- */ |
/* -------------- error label ------------------------- */ |
642 |
gtk_table_attach_defaults(GTK_TABLE(table), left_label_new(_("Est. error:")), 0,1,4,5); |
gtk_table_attach_defaults(GTK_TABLE(table), left_label_new(_("Est. error:")), 0,1,4,5); |
643 |
gtk_table_attach_defaults(GTK_TABLE(table), |
gtk_table_attach_defaults(GTK_TABLE(table), |
644 |
(context->gotoc.eph_label = left_label_new("-----")), 1,2,4,5); |
(context->gotoc.eph_label = gtk_label_new("-----")), 1,2,4,5); |
645 |
|
|
646 |
gtk_table_set_row_spacing(GTK_TABLE(table), 4, 16); |
gtk_table_set_row_spacing(GTK_TABLE(table), 4, 16); |
647 |
|
|
661 |
|
|
662 |
gtk_box_pack_start(GTK_BOX(ihbox), context->gotoc.sat_area, 1,0,0); |
gtk_box_pack_start(GTK_BOX(ihbox), context->gotoc.sat_area, 1,0,0); |
663 |
|
|
664 |
#ifdef ENABLE_MAEMO_MAPPER |
#ifdef ESPEAK |
665 |
GtkWidget *mm_button = gtk_button_new(); |
GtkWidget *ivbox = gtk_vbox_new(FALSE, 0); |
666 |
gtk_button_set_image(GTK_BUTTON(mm_button), icon_get_widget(ICON_MISC, 0)); |
GtkWidget *button = button_new(); |
667 |
gtk_signal_connect(GTK_OBJECT(mm_button), "clicked", |
gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_MISC, |
668 |
(GtkSignalFunc)on_mm_button_clicked, context); |
context->appdata->espeak.enabled?6:7)); |
669 |
gtk_box_pack_start(GTK_BOX(ihbox), mm_button, 1,0,0); |
gtk_signal_connect (GTK_OBJECT(button), "clicked", |
670 |
|
GTK_SIGNAL_FUNC(espeak_clicked), context); |
671 |
|
if(context->appdata->espeak.sample_rate < 0) |
672 |
|
gtk_widget_set_sensitive(button, FALSE); |
673 |
|
else |
674 |
|
if(context->appdata->espeak.enabled) |
675 |
|
espeak_enable(context, TRUE); |
676 |
|
|
677 |
|
gtk_box_pack_start(GTK_BOX(ivbox), button, 1,0,0); |
678 |
|
gtk_box_pack_start(GTK_BOX(ihbox), ivbox, 1,0,0); |
679 |
#endif |
#endif |
680 |
|
|
681 |
gtk_table_attach_defaults(GTK_TABLE(table), ihbox, 0,3,5,6); |
gtk_table_attach_defaults(GTK_TABLE(table), ihbox, 0,3,5,6); |