From ee1175c17aa4b0856861fb1eb9cb579ede5d3b62 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Fri, 3 Aug 2007 08:57:28 +0300 Subject: [PATCH] Move gps banner handling from mapper.c to their own file. Misc other cleanups. --- src/Makefile.am | 1 + src/bt-bluez.c | 6 +++ src/cb.c | 20 +++----- src/gps-conn.c | 80 ++++++++++++++++++++++++++++++++ src/gps-nmea-parse.c | 10 +--- src/gps-panels.c | 12 +++-- src/hildon-wrappers.c | 103 ++++++++++++++++++++---------------------- src/iap.c | 2 +- src/mapper.c | 60 ------------------------ src/ui-common.c | 4 +- src/ui-common.h | 4 +- 11 files changed, 157 insertions(+), 145 deletions(-) create mode 100644 src/gps-conn.c diff --git a/src/Makefile.am b/src/Makefile.am index 61cedb2..9c1e3fb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -38,6 +38,7 @@ mapper_SOURCES = utils.c \ gps-browse.c \ gps-nmea-parse.c \ gps-panels.c \ + gps-conn.c \ cb.c \ iap.c \ route.c \ diff --git a/src/bt-bluez.c b/src/bt-bluez.c index 187378f..7c41d74 100644 --- a/src/bt-bluez.c +++ b/src/bt-bluez.c @@ -102,6 +102,12 @@ static gboolean rcvr_connect_bt() perror("ERROR: "); return TRUE; break; + case EHOSTUNREACH: + g_printf("*** Bluetooth/GPS device not found.\n"); + rcvr_disconnect(); + rcvr_connect_later(); + return FALSE; + break; default: /* Connection failed. Disconnect and try again later. */ g_printf("### Connect failed, retrying... %d %d\n", e, r); diff --git a/src/cb.c b/src/cb.c index e12efcc..839a092 100644 --- a/src/cb.c +++ b/src/cb.c @@ -14,17 +14,15 @@ #include #include #include -#include -#include #include -#include #include #include -#include -#ifdef WITH_HILDON +#ifdef WITH_OSSO #include #include +#endif +#ifdef WITH_HILDON #include #include #include @@ -1125,14 +1123,11 @@ void cmenu_route_add_way(guint unitx, guint unity) g_free(desc); - confirm = - hildon_note_new_confirmation(GTK_WINDOW(dialog), - _ - ("Creating a \"waypoint\" with no description actually " + confirm = hildon_note_new_confirmation(GTK_WINDOW(dialog), + _("Creating a \"waypoint\" with no description actually " "adds a break point. Is that what you want?")); - if (GTK_RESPONSE_OK == - gtk_dialog_run(GTK_DIALOG(confirm))) { + if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) { /* There's no description. Add a break by adding a (0, 0) * point (if necessary), and then the ordinary route point. */ if (_route.tail->unity) { @@ -1436,8 +1431,7 @@ gboolean cmenu_cb_poi_route_to(GtkAction * action) PoiInfo poi; printf("%s()\n", __PRETTY_FUNCTION__); - if (select_poi - (x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) { + if (select_poi(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) { guint unitx, unity; latlon2unit(poi.lat, poi.lon, unitx, unity); cmenu_route_to(unitx, unity); diff --git a/src/gps-conn.c b/src/gps-conn.c new file mode 100644 index 0000000..ad27bf6 --- /dev/null +++ b/src/gps-conn.c @@ -0,0 +1,80 @@ +#define _GNU_SOURCE + +#define _(String) gettext(String) + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef WITH_HILDON +#include +#endif + +static GtkWidget *connect_banner = NULL; +static GtkWidget *fix_banner = NULL; + +#include +#include + +#include "utils.h" +#include "settings.h" +#include "gps.h" +#include "map.h" +#include "bt.h" +#include "ui-common.h" + +/** + * Set the connection state. This function controls all connection-related + * banners. + */ +void +set_conn_state(ConnState new_conn_state) +{ +switch (_conn_state = new_conn_state) { + case RCVR_OFF: + case RCVR_FIXED: + if (connect_banner) { + gtk_widget_destroy(connect_banner); + connect_banner = NULL; + } + if (fix_banner) { + gtk_widget_destroy(fix_banner); + fix_banner = NULL; + } + break; + case RCVR_DOWN: + if (fix_banner) { + gtk_widget_destroy(fix_banner); + fix_banner = NULL; + } + if (!connect_banner) + connect_banner = hildon_banner_show_animation(_window, NULL, _("Searching for GPS receiver")); + break; + case RCVR_UP: + if (connect_banner) { + gtk_widget_destroy(connect_banner); + connect_banner = NULL; + } + if (!fix_banner) + fix_banner = hildon_banner_show_progress(_window, NULL, _("Establishing GPS fix")); + break; + default:; /* to quell warning. */ +} +} + +void +set_fix_progress(gdouble fix) +{ +#ifdef WITH_HILDON +hildon_banner_set_fraction(fix_banner, fix); +#else +gtk_progress_bar_set_fraction(_progress_item, fix); +#endif +} diff --git a/src/gps-nmea-parse.c b/src/gps-nmea-parse.c index d9a39d2..56a8a2c 100644 --- a/src/gps-nmea-parse.c +++ b/src/gps-nmea-parse.c @@ -15,10 +15,6 @@ #include #include -#ifdef WITH_HILDON -#include -#endif - #include "utils.h" #include "bt.h" #include "gps.h" @@ -378,11 +374,9 @@ void channel_parse_gsv(gchar * sentence) /* This is the last message. Calculate signal strength. */ if (num_sats_used) { if (_conn_state == RCVR_UP) { - gdouble fraction = - running_total * sqrt(num_sats_used) - / num_sats_used / 100.0; + gdouble fraction = running_total * sqrt(num_sats_used) / num_sats_used / 100.0; BOUND(fraction, 0.0, 1.0); - hildon_banner_set_fraction(HILDON_BANNER(_fix_banner), fraction); + set_fix_progress(fraction); } running_total = 0; num_sats_used = 0; diff --git a/src/gps-panels.c b/src/gps-panels.c index f0bd846..af5335d 100644 --- a/src/gps-panels.c +++ b/src/gps-panels.c @@ -21,7 +21,8 @@ #include "mapper-types.h" #include "ui-common.h" -void gps_display_data(void) +void +gps_display_data(void) { gchar *buffer, litbuf[16]; printf("%s()\n", __PRETTY_FUNCTION__); @@ -112,7 +113,8 @@ if (_gps_info) vprintf("%s(): return\n", __PRETTY_FUNCTION__); } -void gps_show_info(void) +void +gps_show_info(void) { printf("%s()\n", __PRETTY_FUNCTION__); @@ -252,7 +254,8 @@ vprintf("%s(): return\n", __PRETTY_FUNCTION__); return TRUE; } -gboolean heading_panel_expose(GtkWidget * widget, GdkEventExpose * event) +gboolean +heading_panel_expose(GtkWidget * widget, GdkEventExpose * event) { guint size, xoffset, yoffset, i, x, y; gint dir; @@ -737,7 +740,8 @@ gps_display_details(void) return TRUE; } -void gps_details_dialog(void) +void +gps_details_dialog(void) { GtkWidget *dialog; diff --git a/src/hildon-wrappers.c b/src/hildon-wrappers.c index e62174a..607cca3 100644 --- a/src/hildon-wrappers.c +++ b/src/hildon-wrappers.c @@ -15,123 +15,120 @@ static gint _sb_sid=0; GtkWidget *hildon_file_chooser_dialog_new(GtkWindow * parent, GtkFileChooserAction action) { - GtkWidget *dialog; - - if (action == GTK_FILE_CHOOSER_ACTION_SAVE) { - dialog = gtk_file_chooser_dialog_new("Save", parent, action, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, - GTK_RESPONSE_ACCEPT, NULL); - gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER - (dialog), TRUE); - } else { - dialog = gtk_file_chooser_dialog_new("Open", parent, action, - GTK_STOCK_CANCEL, - GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, - GTK_RESPONSE_ACCEPT, NULL); - } - - return dialog; +GtkWidget *dialog; + +if (action == GTK_FILE_CHOOSER_ACTION_SAVE) { + dialog = gtk_file_chooser_dialog_new("Save", parent, action, + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, + GTK_RESPONSE_ACCEPT, NULL); + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); +} else { + dialog = gtk_file_chooser_dialog_new("Open", parent, action, + GTK_STOCK_CANCEL, + GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, + GTK_RESPONSE_ACCEPT, NULL); +} +return dialog; } static gboolean status_bar_clear(void) { - gtk_statusbar_pop(_status_bar, 0); - _sb_sid=0; - return FALSE; +gtk_statusbar_pop(_status_bar, 0); +_sb_sid=0; +return FALSE; } void hildon_banner_show_information(GtkWidget *w, void *t, gchar *text) { - gtk_statusbar_pop(GTK_STATUSBAR(_status_bar), 0); - gtk_statusbar_push(GTK_STATUSBAR(_status_bar), 0, text); - if (_sb_sid!=0) - g_source_remove(_sb_sid); - _sb_sid=g_timeout_add(6000, status_bar_clear, NULL); +gtk_statusbar_pop(GTK_STATUSBAR(_status_bar), 0); +gtk_statusbar_push(GTK_STATUSBAR(_status_bar), 0, text); +if (_sb_sid!=0) + g_source_remove(_sb_sid); +_sb_sid=g_timeout_add(6000, status_bar_clear, NULL); } GtkWidget *hildon_banner_show_progress(GtkWidget * widget, GtkProgressBar *bar, const gchar * text) { - gtk_widget_show(_progress_item); - gtk_progress_bar_set_text(_progress_item, text); - hildon_banner_show_information(_status_bar, NULL, text); - return NULL; +gtk_widget_show(_progress_item); +gtk_progress_bar_set_text(_progress_item, text); +hildon_banner_show_information(_status_bar, NULL, text); +return NULL; } GtkWidget *hildon_note_new_confirmation(GtkWidget *widget, const gchar *text) { - return gtk_message_dialog_new(widget, - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK_CANCEL, text); +return gtk_message_dialog_new(widget, + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK_CANCEL, text); } void hildon_banner_set_fraction(GtkWidget * widget, gdouble fraction) { - gtk_progress_bar_set_fraction(_progress_item, fraction); - if (fraction==1.0) - gtk_widget_hide(_progress_item); - else - gtk_widget_show(_progress_item); +gtk_progress_bar_set_fraction(_progress_item, fraction); +if (fraction==1.0) + gtk_widget_hide(_progress_item); +else + gtk_widget_show(_progress_item); } GtkWidget *hildon_banner_show_animation(GtkWidget *widget, const gchar *animation_name, const gchar *text) { - hildon_banner_show_information(_status_bar, NULL, text); - gtk_widget_show(_progress_item); - gtk_progress_bar_pulse(_progress_item); - return NULL; +hildon_banner_show_information(_status_bar, NULL, text); +gtk_widget_show(_progress_item); +gtk_progress_bar_pulse(_progress_item); +return NULL; } void gtk_widget_tap_and_hold_setup(GtkWidget * a, GtkWidget * w, void *p, gint t) { - } GtkWidget *hildon_number_editor_new(gint min, gint max) { - return gtk_spin_button_new_with_range(min, max, 1); +return gtk_spin_button_new_with_range(min, max, 1); } gint hildon_number_editor_get_value(GtkWidget * w) { - return gtk_spin_button_get_value_as_int(GTK_WIDGET(w)); +return gtk_spin_button_get_value_as_int(GTK_WIDGET(w)); } void hildon_number_editor_set_value(GtkWidget * w, gint v) { - gtk_spin_button_set_value(w, v); +gtk_spin_button_set_value(w, v); } void hildon_number_editor_set_range(GtkWidget * w, gint min, gint max) { - gtk_spin_button_set_range(w, min, max); +gtk_spin_button_set_range(w, min, max); } GtkWidget *hildon_controlbar_new() { - return gtk_hscale_new_with_range(1, 10, 1); +return gtk_hscale_new_with_range(1, 10, 1); } gint hildon_controlbar_get_value(GtkWidget * w) { - return gtk_range_get_value(w); +return gtk_range_get_value(w); } void hildon_controlbar_set_value(GtkWidget * w, gint v) { - gtk_range_set_value(w, (gdouble)v); +gtk_range_set_value(w, (gdouble)v); } void hildon_controlbar_set_range(GtkWidget * w, gint min, gint max) { - gtk_range_set_range(w, (gdouble)min, (gdouble)max); +gtk_range_set_range(w, (gdouble)min, (gdouble)max); } #else diff --git a/src/iap.c b/src/iap.c index 1125aa4..e2d2ead 100644 --- a/src/iap.c +++ b/src/iap.c @@ -1,6 +1,6 @@ #include -#ifdef WITH_HILDON +#ifdef WITH_OSSO #include #include diff --git a/src/mapper.c b/src/mapper.c index 258bea0..17d46d6 100644 --- a/src/mapper.c +++ b/src/mapper.c @@ -57,11 +57,6 @@ #include #include #include -#include -#include -#include -#include -#include #include #include #endif @@ -105,61 +100,6 @@ GdkColor COLORABLE_DEFAULT[COLORABLE_ENUM_COUNT] = { {0, 0xa000, 0x0000, 0xa000} /* COLORABLE_POI */ }; -/** - * Set the connection state. This function controls all connection-related - * banners. - */ -void set_conn_state(ConnState new_conn_state) -{ - printf("%s(%d)\n", __PRETTY_FUNCTION__, new_conn_state); - - switch (_conn_state = new_conn_state) { - case RCVR_OFF: - case RCVR_FIXED: -#ifdef WITH_HILDON - if (_connect_banner) { - gtk_widget_destroy(_connect_banner); - _connect_banner = NULL; - } - if (_fix_banner) { - gtk_widget_destroy(_fix_banner); - _fix_banner = NULL; - } -#else - -#endif - break; - case RCVR_DOWN: -#ifdef WITH_HILDON - if (_fix_banner) { - gtk_widget_destroy(_fix_banner); - _fix_banner = NULL; - } - if (!_connect_banner) - _connect_banner = hildon_banner_show_animation(_window, NULL, - _("Searching for GPS receiver")); -#else - -#endif - break; - case RCVR_UP: -#ifdef WITH_HILDON - if (_connect_banner) { - gtk_widget_destroy(_connect_banner); - _connect_banner = NULL; - } - if (!_fix_banner) - _fix_banner = hildon_banner_show_progress(_window, NULL, - _("Establishing GPS fix")); -#else - -#endif - break; - default:; /* to quell warning. */ - } - - vprintf("%s(): return\n", __PRETTY_FUNCTION__); -} /** * Save state and destroy all non-UI elements created by this program in diff --git a/src/ui-common.c b/src/ui-common.c index a273354..f4491f3 100644 --- a/src/ui-common.c +++ b/src/ui-common.c @@ -546,9 +546,7 @@ static void menu_init() gtk_menu_append(submenu, _cmenu_loc_distance_to_item = gtk_menu_item_new_with_label(_("Show Distance to"))); gtk_menu_append(submenu, _cmenu_loc_route_to_item - = - gtk_menu_item_new_with_label(_ - ("Download Route to..."))); + = gtk_menu_item_new_with_label(_("Download Route to..."))); gtk_menu_append(submenu, gtk_separator_menu_item_new()); gtk_menu_append(submenu, _cmenu_loc_add_route = gtk_menu_item_new_with_label(_("Add Route Point"))); diff --git a/src/ui-common.h b/src/ui-common.h index 5236461..16c7a09 100644 --- a/src/ui-common.h +++ b/src/ui-common.h @@ -187,9 +187,7 @@ GtkWidget *_cmenu_poi_add_route; GtkWidget *_cmenu_poi_add_way; GtkWidget *_cmenu_poi_goto_nearpoi; -/** BANNERS. */ -GtkWidget *_connect_banner; -GtkWidget *_fix_banner; +/* Banners/Progress bars */ GtkWidget *_download_banner; GtkWidget *_status_bar; -- 2.39.5