31 |
#include "custom_rating_renderer.h" |
#include "custom_rating_renderer.h" |
32 |
#include "custom_type_renderer.h" |
#include "custom_type_renderer.h" |
33 |
|
|
34 |
|
#ifdef ESPEAK |
35 |
|
#include <espeak/speak_lib.h> |
36 |
|
#endif |
37 |
|
|
38 |
#ifdef USE_MAEMO |
#ifdef USE_MAEMO |
39 |
#include <hildon/hildon-banner.h> |
#include <hildon/hildon-banner.h> |
40 |
#if MAEMO_VERSION_MAJOR >= 5 |
#if MAEMO_VERSION_MAJOR >= 5 |
123 |
free(buf); |
free(buf); |
124 |
} |
} |
125 |
|
|
126 |
|
/* ------------ app specific gps helper functions, not part -------------- */ |
127 |
|
/* --------------------- of the generic gps.[ch] ------------------------ */ |
128 |
|
|
129 |
|
void gps_change_state(appdata_t *appdata) { |
130 |
|
gps_enable(appdata->gps_state, appdata->use_gps); |
131 |
|
} |
132 |
|
|
133 |
|
pos_t *gps_get_pos(appdata_t *appdata) { |
134 |
|
static pos_t pos; |
135 |
|
|
136 |
|
if(appdata->gps.set & FIX_LATLON_SET) { |
137 |
|
pos.lat = appdata->gps.fix.latitude; |
138 |
|
pos.lon = appdata->gps.fix.longitude; |
139 |
|
return &pos; |
140 |
|
} |
141 |
|
|
142 |
|
return NULL; |
143 |
|
} |
144 |
|
|
145 |
|
float gps_get_heading(appdata_t *appdata) { |
146 |
|
if(appdata->gps.set & FIX_TRACK_SET) |
147 |
|
return appdata->gps.fix.track; |
148 |
|
|
149 |
|
return NAN; |
150 |
|
} |
151 |
|
|
152 |
|
gint gps_get_satnum(appdata_t *appdata) { |
153 |
|
printf("set = %x/%x (snum = %d)\n", |
154 |
|
appdata->gps.set, FIX_SATELLITE_SET, |
155 |
|
appdata->gps.fix.sat_num); |
156 |
|
|
157 |
|
if(appdata->gps.set & FIX_SATELLITE_SET) |
158 |
|
return appdata->gps.fix.sat_num; |
159 |
|
|
160 |
|
return 0; |
161 |
|
} |
162 |
|
|
163 |
|
gps_sat_t *gps_get_sats(appdata_t *appdata) { |
164 |
|
if(appdata->gps.set & FIX_SATELLITE_SET) |
165 |
|
return appdata->gps.fix.sat_data; |
166 |
|
|
167 |
|
return NULL; |
168 |
|
} |
169 |
|
|
170 |
|
float gps_get_eph(appdata_t *appdata) { |
171 |
|
if(appdata->gps.set & FIX_HERR_SET) |
172 |
|
return appdata->gps.fix.eph; |
173 |
|
|
174 |
|
return NAN; |
175 |
|
} |
176 |
|
|
177 |
|
static void |
178 |
|
main_gps_cb(gps_mask_t set, struct gps_t *fix, void *data) { |
179 |
|
appdata_t *appdata = (appdata_t*)data; |
180 |
|
|
181 |
|
appdata->gps.set = set; |
182 |
|
memcpy(&appdata->gps.fix, fix, sizeof(struct gps_t)); |
183 |
|
} |
184 |
|
|
185 |
gpx_t *choose_file(appdata_t *appdata, gboolean whole_dir) { |
gpx_t *choose_file(appdata_t *appdata, gboolean whole_dir) { |
186 |
GtkWidget *dialog; |
GtkWidget *dialog; |
187 |
gpx_t *gpx = NULL; |
gpx_t *gpx = NULL; |
471 |
static gboolean on_cachelist_focus_in(GtkWidget *widget, GdkEventFocus *event, |
static gboolean on_cachelist_focus_in(GtkWidget *widget, GdkEventFocus *event, |
472 |
gpointer data) { |
gpointer data) { |
473 |
|
|
|
|
|
474 |
/* we don't want a runnign timer yet */ |
/* we don't want a runnign timer yet */ |
475 |
if(!g_object_get_data(G_OBJECT(data), "handler_id")) { |
if(!g_object_get_data(G_OBJECT(data), "handler_id")) { |
476 |
printf("focus received: restarting cachelist timer\n"); |
printf("focus received: restarting cachelist timer\n"); |
481 |
|
|
482 |
g_object_set_data(G_OBJECT(data), "handler_id", (gpointer) |
g_object_set_data(G_OBJECT(data), "handler_id", (gpointer) |
483 |
gtk_timeout_add(CACHELIST_UPDATE_TIMEOUT, cachelist_update, data)); |
gtk_timeout_add(CACHELIST_UPDATE_TIMEOUT, cachelist_update, data)); |
484 |
|
|
485 |
|
/* and redo list immediately */ |
486 |
|
cachelist_redraw(appdata); |
487 |
} |
} |
488 |
|
|
489 |
return FALSE; |
return FALSE; |
504 |
return FALSE; |
return FALSE; |
505 |
} |
} |
506 |
|
|
507 |
|
gboolean on_main_focus_change(GtkWidget *widget, GdkEventFocus *event, |
508 |
|
gpointer user_data) { |
509 |
|
appdata_t *appdata = (appdata_t*)user_data; |
510 |
|
g_assert(appdata->gps_state); |
511 |
|
|
512 |
|
printf("main/cachelist focus-%s event\n", event->in?"in":"out"); |
513 |
|
|
514 |
|
/* disconnect from gps if map looses focus */ |
515 |
|
/* this is to save energy if maep runs in background */ |
516 |
|
|
517 |
|
if(event->in) { |
518 |
|
/* request all GPS information required for map display */ |
519 |
|
gps_register_callback(appdata->gps_state, |
520 |
|
LATLON_CHANGED | TRACK_CHANGED | HERR_CHANGED | SATELLITE_CHANGED, |
521 |
|
main_gps_cb, appdata); |
522 |
|
} else |
523 |
|
gps_unregister_callback(appdata->gps_state, main_gps_cb); |
524 |
|
|
525 |
|
return FALSE; |
526 |
|
} |
527 |
|
|
528 |
static GtkWidget *cachelist_create(appdata_t *appdata, gpx_t *gpx, |
static GtkWidget *cachelist_create(appdata_t *appdata, gpx_t *gpx, |
529 |
cache_t *sel_cache) { |
cache_t *sel_cache) { |
530 |
GtkCellRenderer *renderer; |
GtkCellRenderer *renderer; |
791 |
hildon_window_set_app_menu(HILDON_WINDOW(window), |
hildon_window_set_app_menu(HILDON_WINDOW(window), |
792 |
menu_create(appdata, MENU_CACHELIST)); |
menu_create(appdata, MENU_CACHELIST)); |
793 |
|
|
794 |
|
/* make sure window can control gps */ |
795 |
|
g_signal_connect(G_OBJECT(window), "focus-in-event", |
796 |
|
G_CALLBACK(on_main_focus_change), appdata); |
797 |
|
|
798 |
|
g_signal_connect(G_OBJECT(window), "focus-out-event", |
799 |
|
G_CALLBACK(on_main_focus_change), appdata); |
800 |
|
|
801 |
g_signal_connect(G_OBJECT(window), "destroy", |
g_signal_connect(G_OBJECT(window), "destroy", |
802 |
G_CALLBACK(on_cachelist_destroy), appdata); |
G_CALLBACK(on_cachelist_destroy), appdata); |
803 |
|
|
1580 |
g_signal_connect(G_OBJECT(context.in_finds), "toggled", |
g_signal_connect(G_OBJECT(context.in_finds), "toggled", |
1581 |
G_CALLBACK(callback_finds_toggled), &context); |
G_CALLBACK(callback_finds_toggled), &context); |
1582 |
|
|
1583 |
#ifndef USE_MAEMO |
context.spinner = number_editor_new(appdata->search_days, 0, 99); |
|
GtkObject *adj = gtk_adjustment_new(appdata->search_days, 0, 99, 1, 10, 10); |
|
|
context.spinner = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 1, 0); |
|
|
#else |
|
|
context.spinner = hildon_number_editor_new(0, 99); |
|
|
hildon_number_editor_set_value(HILDON_NUMBER_EDITOR(context.spinner), |
|
|
appdata->search_days); |
|
|
#endif |
|
1584 |
gtk_box_pack_start_defaults(GTK_BOX(hbox), context.spinner); |
gtk_box_pack_start_defaults(GTK_BOX(hbox), context.spinner); |
1585 |
|
|
1586 |
gtk_box_pack_start_defaults(GTK_BOX(hbox), gtk_label_new(_("days"))); |
gtk_box_pack_start_defaults(GTK_BOX(hbox), gtk_label_new(_("days"))); |
1587 |
|
|
1588 |
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox); |
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox); |
1600 |
if(strlen(p) > 0) |
if(strlen(p) > 0) |
1601 |
appdata->search_str = strdup(p); |
appdata->search_str = strdup(p); |
1602 |
|
|
1603 |
#ifndef USE_MAEMO |
appdata->search_days = number_editor_get_value(context.spinner); |
|
appdata->search_days = gtk_spin_button_get_value_as_int( |
|
|
GTK_SPIN_BUTTON(context.spinner)); |
|
|
#else |
|
|
appdata->search_days = hildon_number_editor_get_value( |
|
|
HILDON_NUMBER_EDITOR(context.spinner)); |
|
|
#endif |
|
1604 |
|
|
1605 |
if(check_button_get_active(context.in_finds)) |
if(check_button_get_active(context.in_finds)) |
1606 |
appdata->search |= SEARCH_FINDS; |
appdata->search |= SEARCH_FINDS; |
1636 |
printf("Search for %s (flags = %x)...\n", p, appdata->search); |
printf("Search for %s (flags = %x)...\n", p, appdata->search); |
1637 |
|
|
1638 |
#if !defined(USE_BREAD_CRUMB_TRAIL) && !defined(BCT) |
#if !defined(USE_BREAD_CRUMB_TRAIL) && !defined(BCT) |
1639 |
gpx_t *found = |
|
1640 |
search_do(appdata, appdata->gpx, p, appdata->search, FALSE); |
if(appdata->cur_gpx) |
1641 |
|
appdata->search_results = |
1642 |
|
search_do(appdata, appdata->cur_gpx, p, appdata->search, TRUE); |
1643 |
|
else |
1644 |
|
appdata->search_results = |
1645 |
|
search_do(appdata, appdata->gpx, p, appdata->search, FALSE); |
1646 |
|
|
1647 |
/* do search result dialog here ... */ |
/* do search result dialog here ... */ |
1648 |
cachelist_dialog(appdata, found); |
cachelist_dialog(appdata, appdata->search_results); |
1649 |
|
|
1650 |
#ifndef USE_STACKABLE_WINDOW |
#ifndef USE_STACKABLE_WINDOW |
1651 |
search_result_free(found); |
search_result_free(appdata->search_results); |
1652 |
#else |
appdata->search_results = NULL; |
|
appdata->search_results = found; |
|
1653 |
#endif |
#endif |
1654 |
#else |
#else |
1655 |
gpx_t *found = NULL; |
gpx_t *found = NULL; |
2146 |
|
|
2147 |
gpx_free_all(appdata->gpx); |
gpx_free_all(appdata->gpx); |
2148 |
|
|
2149 |
|
#ifdef ESPEAK |
2150 |
|
espeak_Terminate(); |
2151 |
|
#endif |
2152 |
|
|
2153 |
#ifdef USE_STACKABLE_WINDOW |
#ifdef USE_STACKABLE_WINDOW |
2154 |
if(appdata->export_menu) submenu_cleanup(appdata->export_menu); |
if(appdata->export_menu) submenu_cleanup(appdata->export_menu); |
2155 |
if(appdata->tools_menu) submenu_cleanup(appdata->tools_menu); |
if(appdata->tools_menu) submenu_cleanup(appdata->tools_menu); |
2157 |
|
|
2158 |
gnome_vfs_shutdown(); |
gnome_vfs_shutdown(); |
2159 |
icons_free(); |
icons_free(); |
2160 |
gps_release(appdata); |
|
2161 |
|
gps_release(appdata->gps_state); |
2162 |
|
appdata->gps_state = NULL; |
2163 |
|
|
2164 |
if(appdata->search_results) { |
if(appdata->search_results) { |
2165 |
printf("freeing pending search\n"); |
printf("freeing pending search\n"); |
2460 |
} |
} |
2461 |
} |
} |
2462 |
|
|
2463 |
|
#if (MAEMO_VERSION_MAJOR == 5) && !defined(__i386__) |
2464 |
|
/* get access to zoom buttons */ |
2465 |
|
static void |
2466 |
|
on_window_realize(GtkWidget *widget, gpointer data) { |
2467 |
|
if (widget->window) { |
2468 |
|
unsigned char value = 1; |
2469 |
|
Atom hildon_zoom_key_atom = |
2470 |
|
gdk_x11_get_xatom_by_name("_HILDON_ZOOM_KEY_ATOM"), |
2471 |
|
integer_atom = gdk_x11_get_xatom_by_name("INTEGER"); |
2472 |
|
Display *dpy = |
2473 |
|
GDK_DISPLAY_XDISPLAY(gdk_drawable_get_display(widget->window)); |
2474 |
|
Window w = GDK_WINDOW_XID(widget->window); |
2475 |
|
|
2476 |
|
XChangeProperty(dpy, w, hildon_zoom_key_atom, |
2477 |
|
integer_atom, 8, PropModeReplace, &value, 1); |
2478 |
|
} |
2479 |
|
} |
2480 |
|
#endif |
2481 |
|
|
2482 |
int main(int argc, char *argv[]) { |
int main(int argc, char *argv[]) { |
2483 |
appdata_t appdata; |
appdata_t appdata; |
2484 |
|
|
2501 |
|
|
2502 |
curl_global_init(CURL_GLOBAL_ALL); |
curl_global_init(CURL_GLOBAL_ALL); |
2503 |
|
|
2504 |
|
#ifdef ESPEAK |
2505 |
|
#if ESPEAK_API_REVISION == 1 |
2506 |
|
appdata.espeak.sample_rate = |
2507 |
|
espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 512, NULL); |
2508 |
|
#else |
2509 |
|
appdata.espeak.sample_rate = |
2510 |
|
espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 512, NULL, 0); |
2511 |
|
#endif |
2512 |
|
if(appdata.espeak.sample_rate < 0) |
2513 |
|
printf("espeak: init error\n"); |
2514 |
|
else |
2515 |
|
printf("espeak: running at %dhz\n", appdata.espeak.sample_rate); |
2516 |
|
|
2517 |
|
/* set language */ |
2518 |
|
espeak_VOICE voice_spec; |
2519 |
|
voice_spec.name = NULL; |
2520 |
|
voice_spec.languages = _("en"); |
2521 |
|
voice_spec.gender = 0; |
2522 |
|
voice_spec.age = 0; |
2523 |
|
voice_spec.variant = 0; |
2524 |
|
if(EE_OK != espeak_SetVoiceByProperties(&voice_spec)) { |
2525 |
|
printf("failed to set voice spec for %s\n", voice_spec.languages); |
2526 |
|
appdata.espeak.sample_rate = -1; |
2527 |
|
} |
2528 |
|
#endif |
2529 |
|
|
2530 |
#ifdef USE_MAEMO |
#ifdef USE_MAEMO |
2531 |
printf("Installing osso context for \"org.harbaum." APP "\"\n"); |
printf("Installing osso context for \"org.harbaum." APP "\"\n"); |
2532 |
appdata.osso_context = osso_initialize("org.harbaum."APP, |
appdata.osso_context = osso_initialize("org.harbaum."APP, |
2567 |
|
|
2568 |
#if MAEMO_VERSION_MAJOR == 5 |
#if MAEMO_VERSION_MAJOR == 5 |
2569 |
gtk_window_set_title(GTK_WINDOW(appdata.window), "GPXView"); |
gtk_window_set_title(GTK_WINDOW(appdata.window), "GPXView"); |
2570 |
|
#if !defined(__i386__) |
2571 |
|
g_signal_connect(G_OBJECT(appdata.window), "realize", |
2572 |
|
G_CALLBACK(on_window_realize), NULL); |
2573 |
|
#endif |
2574 |
#endif |
#endif |
2575 |
|
|
2576 |
g_signal_connect(G_OBJECT(appdata.window), "destroy", |
g_signal_connect(G_OBJECT(appdata.window), "destroy", |
2618 |
|
|
2619 |
appdata.gconf_client = gconf_client_get_default(); |
appdata.gconf_client = gconf_client_get_default(); |
2620 |
gconf_load_state(&appdata); |
gconf_load_state(&appdata); |
2621 |
gps_init(&appdata); |
|
2622 |
|
appdata.gps_state = gps_init(); |
2623 |
|
gps_change_state(&appdata); |
2624 |
|
|
2625 |
|
gps_register_callback(appdata.gps_state, |
2626 |
|
LATLON_CHANGED | TRACK_CHANGED | HERR_CHANGED | SATELLITE_CHANGED, |
2627 |
|
main_gps_cb, &appdata); |
2628 |
|
|
2629 |
|
/* make sure window can control gps */ |
2630 |
|
g_signal_connect(G_OBJECT(appdata.window), "focus-in-event", |
2631 |
|
G_CALLBACK(on_main_focus_change), &appdata); |
2632 |
|
|
2633 |
|
g_signal_connect(G_OBJECT(appdata.window), "focus-out-event", |
2634 |
|
G_CALLBACK(on_main_focus_change), &appdata); |
2635 |
|
|
2636 |
|
|
2637 |
appdata.cur_view = gpxlist_create_view_and_model(&appdata, NULL); |
appdata.cur_view = gpxlist_create_view_and_model(&appdata, NULL); |
2638 |
#ifndef USE_STACKABLE_WINDOW |
#ifndef USE_STACKABLE_WINDOW |