From 504ac989aad7ceaa852a638aab51a69bfc7a65dc Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Fri, 8 Jun 2007 00:05:56 +0300 Subject: [PATCH] Fix missing init of read buffer. Misc other things. --- src/bt-bluez.c | 44 +++---- src/bt-maemo.c | 3 +- src/bt.h | 35 +++++- src/cb.c | 3 +- src/config.c | 60 +++++----- src/gps-browse.c | 1 + src/gps-nmea-parse.c | 59 ++++----- src/gps-panels.c | 25 ++-- src/gps.h | 13 +- src/gpx.c | 13 +- src/map.c | 279 ++++++++++++++++++++++++------------------- src/map.h | 6 + src/mapper-types.h | 53 +------- src/mapper.c | 85 ++++++++----- src/poi.h | 19 +++ src/speed-display.c | 10 +- src/track.c | 2 + src/ui-common.c | 1 + src/utils.c | 6 +- src/utils.h | 8 +- 20 files changed, 387 insertions(+), 338 deletions(-) diff --git a/src/bt-bluez.c b/src/bt-bluez.c index 843816e..8097c63 100644 --- a/src/bt-bluez.c +++ b/src/bt-bluez.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -16,9 +17,7 @@ #include #include #include -#include #include -#include #include #include @@ -32,6 +31,7 @@ #include "utils.h" #include "mapper-types.h" #include "settings.h" +#include "ui-common.h" struct sockaddr_rc _rcvr_addr = { 0 }; @@ -88,22 +88,25 @@ static gboolean rcvr_connect_bt() r = connect(_fd, (struct sockaddr *)&_rcvr_addr, sizeof(_rcvr_addr)); e = errno; -/* The socket is non blocking so handle it */ - if (r != 0 || e != EAGAIN || e != EINPROGRESS || e) { + /* The socket is non blocking so handle it */ + if (r != 0) { switch (e) { case EAGAIN: + case EBUSY: case EINPROGRESS: case EALREADY: + g_printf("*** Connection in progress... %d %d\n", e, r); + perror("ERROR: "); return TRUE; - break; + break; default: /* Connection failed. Disconnect and try again later. */ + g_printf("### Connect failed, retrying... %d %d\n", e, r); perror("ERROR: "); - g_printf("Connect failed, retrying... %d %d\n", e, r); rcvr_disconnect(); rcvr_connect_later(); return FALSE; - break; + break; } } return TRUE; @@ -150,21 +153,20 @@ gboolean rcvr_connect_now() /* Reset GPS read buffer */ _gps_read_buf_curr = _gps_read_buf; *_gps_read_buf_curr = '\0'; + _gps_read_buf_last = _gps_read_buf + GPS_READ_BUF_SIZE - 1; /* Create channel and add watches. */ _channel = g_io_channel_unix_new(_fd); - g_io_channel_set_flags(_channel, G_IO_FLAG_NONBLOCK, - NULL); - _error_sid = - g_io_add_watch_full(_channel, G_PRIORITY_HIGH_IDLE, - G_IO_ERR | G_IO_HUP, - channel_cb_error, NULL, NULL); - _connect_sid = - g_io_add_watch_full(_channel, G_PRIORITY_HIGH_IDLE, - G_IO_OUT, channel_cb_connect, - NULL, NULL); + g_io_channel_set_encoding(_channel, NULL, NULL); + g_io_channel_set_flags(_channel, G_IO_FLAG_NONBLOCK, NULL); + _error_sid = g_io_add_watch_full(_channel, G_PRIORITY_HIGH_IDLE, + G_IO_ERR | G_IO_HUP, channel_cb_error, NULL, NULL); + _connect_sid = g_io_add_watch_full(_channel, G_PRIORITY_HIGH_IDLE, + G_IO_OUT, channel_cb_connect, NULL, NULL); if (*_rcvr_mac != '/') { rcvr_connect_bt(); + } else { + g_printf("Using dev node: %s\n", _rcvr_mac); } } #else @@ -197,18 +199,16 @@ channel_cb_connect(GIOChannel * src, GIOCondition condition, gpointer data) gint error, size = sizeof(error); printf("%s(%d)\n", __PRETTY_FUNCTION__, condition); - if (*_rcvr_mac != '/' - && (getsockopt(_fd, SOL_SOCKET, SO_ERROR, &error, &size) || error)) + if (*_rcvr_mac != '/' && (getsockopt(_fd, SOL_SOCKET, SO_ERROR, &error, &size) || error)) { - printf("%s(): Error connecting to receiver; retrying...\n", - __PRETTY_FUNCTION__); + printf("%s(): Error connecting to receiver; retrying...\n", __PRETTY_FUNCTION__); /* Try again. */ rcvr_disconnect(); rcvr_connect_later(); } else { printf("%s(): Connected to receiver!\n", __PRETTY_FUNCTION__); set_conn_state(RCVR_UP); - _input_sid = g_io_add_watch_full(_channel, G_PRIORITY_HIGH_IDLE, + _input_sid = g_io_add_watch_full(_channel, G_PRIORITY_LOW, G_IO_IN | G_IO_PRI, channel_cb_input, NULL, NULL); } diff --git a/src/bt-maemo.c b/src/bt-maemo.c index d50336f..6a0bb60 100644 --- a/src/bt-maemo.c +++ b/src/bt-maemo.c @@ -113,8 +113,7 @@ void rcvr_connect_fd(gchar * fdpath) _error_sid = g_io_add_watch_full(_channel, G_PRIORITY_HIGH_IDLE, G_IO_ERR | G_IO_HUP, channel_cb_error, NULL, NULL); - _connect_sid = - g_io_add_watch_full(_channel, G_PRIORITY_HIGH_IDLE, + _connect_sid = g_io_add_watch_full(_channel, G_PRIORITY_HIGH_IDLE, G_IO_OUT, channel_cb_connect, NULL, NULL); } diff --git a/src/bt.h b/src/bt.h index 11072cb..6463d9b 100644 --- a/src/bt.h +++ b/src/bt.h @@ -6,10 +6,43 @@ #include "utils.h" #include "mapper-types.h" +/** This enumerated type defines the possible connection states. */ +typedef enum { + /** The receiver is "off", meaning that either the bluetooth radio is + * off or the user has requested not to connect to the GPS receiver. + * No gtk_banner is visible. */ + RCVR_OFF, + + /** The connection with the receiver is down. A gtk_banner is visible with + * the text, "Connecting to GPS receiver". */ + RCVR_DOWN, + + /** The connection with the receiver is up, but a GPS fix is not available. + * A gtk_banner is visible with the text, "(Re-)Establishing GPS fix". */ + RCVR_UP, + + /** The connection with the receiver is up and a GPS fix IS available. + * No gtk_banner is visible. */ + RCVR_FIXED +} ConnState; + +typedef struct _ScanInfo ScanInfo; +struct _ScanInfo { + GtkWidget *settings_dialog; + GtkWidget *txt_rcvr_mac; + GtkWidget *scan_dialog; + GtkWidget *banner; + GtkListStore *store; + guint sid; +}; + +ConnState _conn_state; + void rcvr_disconnect(); void rcvr_connect_later(); - +gint scan_start_search(); gboolean rcvr_connect_now(); gboolean scan_bluetooth(GtkWidget * widget, ScanInfo * scan_info); +gboolean scan_bluetooth_idle(ScanInfo * scan_info); #endif diff --git a/src/cb.c b/src/cb.c index 5fd3ea3..f8bc6d1 100644 --- a/src/cb.c +++ b/src/cb.c @@ -598,8 +598,7 @@ gboolean cb_fullscreen(GtkAction * action) { printf("%s()\n", __PRETTY_FUNCTION__); - if ((_fullscreen = - gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM + if ((_fullscreen = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM (_menu_fullscreen_item)))) gtk_window_fullscreen(GTK_WINDOW(_window)); else diff --git a/src/config.c b/src/config.c index dcf429e..c237a34 100644 --- a/src/config.c +++ b/src/config.c @@ -16,7 +16,6 @@ #include #include #include -#include #include "utils.h" #include "mapper-types.h" @@ -25,6 +24,7 @@ #include "db.h" #include "poi.h" #include "gps.h" +#include "bt.h" #include "ui-common.h" #include "settings.h" @@ -57,6 +57,32 @@ void config_update_proxy() #endif } +static void config_save_track(gchar *config_dir) +{ +GnomeVFSHandle *handle; +gchar *track_file; +track_file = gnome_vfs_uri_make_full_from_relative(config_dir, CONFIG_FILE_TRACK); +if (GNOME_VFS_OK == gnome_vfs_create(&handle, track_file, GNOME_VFS_OPEN_WRITE, + FALSE, 0600)) { + write_gpx(&_track, handle); + gnome_vfs_close(handle); +} +g_free(track_file); +} + +static void config_save_route(gchar *config_dir) +{ +GnomeVFSHandle *handle; +gchar *route_file; +route_file = gnome_vfs_uri_make_full_from_relative(config_dir, CONFIG_FILE_ROUTE); +if (GNOME_VFS_OK == gnome_vfs_create(&handle, route_file, GNOME_VFS_OPEN_WRITE, + FALSE, 0600)) { + write_gpx(&_route, handle); + gnome_vfs_close(handle); +} +g_free(route_file); +} + /** * Save all configuration data to GCONF. */ @@ -292,37 +318,9 @@ void config_save() /* Save Show POI below zoom. */ gconf_client_set_int(gconf_client, GCONF_KEY_POI_ZOOM, _poi_zoom, NULL); - /* Save route. */ - { - GnomeVFSHandle *handle; - gchar *route_file; - route_file = - gnome_vfs_uri_make_full_from_relative(config_dir, - CONFIG_FILE_ROUTE); - if (GNOME_VFS_OK == - gnome_vfs_create(&handle, route_file, GNOME_VFS_OPEN_WRITE, - FALSE, 0600)) { - write_gpx(&_route, handle); - gnome_vfs_close(handle); - } - g_free(route_file); - } - /* Save track. */ - { - GnomeVFSHandle *handle; - gchar *track_file; - track_file = - gnome_vfs_uri_make_full_from_relative(config_dir, - CONFIG_FILE_TRACK); - if (GNOME_VFS_OK == - gnome_vfs_create(&handle, track_file, GNOME_VFS_OPEN_WRITE, - FALSE, 0600)) { - write_gpx(&_track, handle); - gnome_vfs_close(handle); - } - g_free(track_file); - } + config_save_track(config_dir); + config_save_route(config_dir); gconf_client_clear_cache(gconf_client); g_object_unref(gconf_client); diff --git a/src/gps-browse.c b/src/gps-browse.c index 7cbf6db..cdf0b93 100644 --- a/src/gps-browse.c +++ b/src/gps-browse.c @@ -20,6 +20,7 @@ #include "utils.h" #include "mapper-types.h" +#include "bt.h" /** * Scan for all bluetooth devices. This method can take a few seconds, diff --git a/src/gps-nmea-parse.c b/src/gps-nmea-parse.c index a81f637..fda4ff5 100644 --- a/src/gps-nmea-parse.c +++ b/src/gps-nmea-parse.c @@ -21,6 +21,11 @@ #include "mapper-types.h" #include "ui-common.h" +#include "track.h" +#include "route.h" + +#include "settings.h" + gboolean channel_cb_error(GIOChannel * src, GIOCondition condition, gpointer data) { @@ -29,7 +34,7 @@ channel_cb_error(GIOChannel * src, GIOCondition condition, gpointer data) /* An error has occurred - re-connect(). */ rcvr_disconnect(); track_add(0, FALSE); - /* _speed_excess = FALSE; */ + _speed_excess = FALSE; if (_conn_state > RCVR_OFF) { set_conn_state(RCVR_DOWN); @@ -146,15 +151,14 @@ void channel_parse_rmc(gchar * sentence) } else _pos.time = time(NULL); - /* Translate data into integers. */ - integerize_data(_vel_offsetx, _vel_offsety, _pos, _gps); - - /* Add new data to track. */ - if (_conn_state == RCVR_FIXED) + /* Add new data to track only if we have a fix */ + if (_conn_state == RCVR_FIXED) { + /* Translate data into integers. */ + integerize_data(_vel_offsetx, _vel_offsety, _pos, _gps); track_add(_pos.time, newly_fixed); - - /* Move mark to new location. */ - refresh_mark(); + /* Move mark to new location. */ + refresh_mark(); + } vprintf("%s(): return\n", __PRETTY_FUNCTION__); } @@ -350,9 +354,7 @@ void channel_parse_gsv(gchar * sentence) 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); + hildon_banner_set_fraction(HILDON_BANNER(_fix_banner), fraction); } running_total = 0; num_sats_used = 0; @@ -378,6 +380,7 @@ channel_cb_input(GIOChannel * src, GIOCondition condition, gpointer data) _gps_read_buf_curr, &bytes_read, NULL)) { gchar *eol; + _gps_read_buf_curr += bytes_read; *_gps_read_buf_curr = '\0'; /* append a \0 so we can read as string */ while ((eol = strchr(_gps_read_buf, '\n'))) { @@ -391,35 +394,23 @@ channel_cb_input(GIOChannel * src, GIOCondition condition, gpointer data) /* If we're at a \0 (meaning there is no checksum), or if the * checksum is good, then parse the sentence. */ - if (!*sptr - || csum == strtol(sptr + 1, NULL, 16)) { + if (!*sptr || csum == strtol(sptr + 1, NULL, 16)) { if (*sptr) *sptr = '\0'; /* take checksum out of the buffer. */ - if (!strncmp - (_gps_read_buf + 3, "GSV", 3)) { + if (!strncmp(_gps_read_buf + 3, "GSV", 3)) { if (_conn_state == RCVR_UP) - channel_parse_gsv - (_gps_read_buf + 7); - } else - if (!strncmp - (_gps_read_buf + 3, "RMC", 3)) - channel_parse_rmc(_gps_read_buf - + 7); - else if (!strncmp - (_gps_read_buf + 3, "GGA", 3)) - channel_parse_gga(_gps_read_buf - + 7); - else if (!strncmp - (_gps_read_buf + 3, "GSA", 3)) - channel_parse_gsa(_gps_read_buf - + 7); - -#if 0 + channel_parse_gsv(_gps_read_buf + 7); + } else if (!strncmp(_gps_read_buf + 3, "RMC", 3)) + channel_parse_rmc(_gps_read_buf + 7); + else if (!strncmp(_gps_read_buf + 3, "GGA", 3)) + channel_parse_gga(_gps_read_buf + 7); + else if (!strncmp(_gps_read_buf + 3, "GSA", 3)) + channel_parse_gsa(_gps_read_buf + 7); + else g_print("Unknown NMEA: [%s]\n", _gps_read_buf); if (_gps_info) gps_display_data(); if (_satdetails_on) gps_display_details(); -#endif } else { /* There was a checksum, and it was bad. */ g_printerr diff --git a/src/gps-panels.c b/src/gps-panels.c index 3510749..101d1d0 100644 --- a/src/gps-panels.c +++ b/src/gps-panels.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include "utils.h" #include "gps.h" @@ -19,7 +21,7 @@ #include "mapper-types.h" #include "ui-common.h" -static void gps_display_data(void) +void gps_display_data(void) { gchar *buffer, litbuf[16]; printf("%s()\n", __PRETTY_FUNCTION__); @@ -584,7 +586,8 @@ sat_details_panel_expose(GtkWidget * widget, GdkEventExpose * event) return TRUE; } -static gboolean gps_display_details(void) +gboolean +gps_display_details(void) { gchar *buffer, litbuf[16]; printf("%s()\n", __PRETTY_FUNCTION__); @@ -675,31 +678,31 @@ static gboolean gps_display_details(void) else { switch (_gps.fixquality) { case 1: - buffer = g_strdup_printf(_("SPS")); + buffer = g_strdup(_("SPS")); break; case 2: - buffer = g_strdup_printf(_("DGPS")); + buffer = g_strdup(_("DGPS")); break; case 3: - buffer = g_strdup_printf(_("PPS")); + buffer = g_strdup(_("PPS")); break; case 4: - buffer = g_strdup_printf(_("Real Time Kinematic")); + buffer = g_strdup(_("Real Time Kinematic")); break; case 5: - buffer = g_strdup_printf(_("Float RTK")); + buffer = g_strdup(_("Float RTK")); break; case 6: - buffer = g_strdup_printf(_("Estimated")); + buffer = g_strdup(_("Estimated")); break; case 7: - buffer = g_strdup_printf(_("Manual")); + buffer = g_strdup(_("Manual")); break; case 8: - buffer = g_strdup_printf(_("Simulation")); + buffer = g_strdup(_("Simulation")); break; default: - buffer = g_strdup_printf(_("none")); + buffer = g_strdup(_("none")); break; } } diff --git a/src/gps.h b/src/gps.h index d69e05f..5dec5c3 100644 --- a/src/gps.h +++ b/src/gps.h @@ -47,7 +47,7 @@ struct _GpsSatelliteData { guint snr; }; -#define GPS_READ_BUF_SIZE 256 +#define GPS_READ_BUF_SIZE 1024 /** The file descriptor of our connection with the GPS receiver. */ gint _fd; @@ -81,13 +81,8 @@ gint _vel_offsety; GpsData _gps; GpsSatelliteData _gps_sat[12]; -gboolean -channel_cb_error(GIOChannel * src, GIOCondition condition, gpointer data); - -gboolean -channel_cb_connect(GIOChannel * src, GIOCondition condition, gpointer data); - -gboolean -channel_cb_input(GIOChannel * src, GIOCondition condition, gpointer data); +gboolean channel_cb_error(GIOChannel * src, GIOCondition condition, gpointer data); +gboolean channel_cb_connect(GIOChannel * src, GIOCondition condition, gpointer data); +gboolean channel_cb_input(GIOChannel * src, GIOCondition condition, gpointer data); #endif diff --git a/src/gpx.c b/src/gpx.c index 9d49cde..1bb50d5 100644 --- a/src/gpx.c +++ b/src/gpx.c @@ -60,13 +60,12 @@ gchar XML_TZONE[7]; void gpx_init(void) { - time_t time1; - struct tm time2; - time1 = time(NULL); - localtime_r(&time1, &time2); - snprintf(XML_TZONE, sizeof(XML_TZONE), "%+03ld:%02ld", - (time2.tm_gmtoff / 60 / 60), (time2.tm_gmtoff / 60) % 60); - _gmtoffset = time2.tm_gmtoff; +time_t time1; +struct tm time2; +time1 = time(NULL); +localtime_r(&time1, &time2); +snprintf(XML_TZONE, sizeof(XML_TZONE), "%+03ld:%02ld", + (time2.tm_gmtoff / 60 / 60), (time2.tm_gmtoff / 60) % 60); } gboolean write_gpx(Path * path, GnomeVFSHandle * handle) diff --git a/src/map.c b/src/map.c index a7c3092..7942189 100644 --- a/src/map.c +++ b/src/map.c @@ -27,6 +27,7 @@ #include "map.h" #include "route.h" #include "gps.h" +#include "bt.h" #include "mapper-types.h" #include "ui-common.h" #include "settings.h" @@ -47,7 +48,8 @@ static guint release[2] = { 0, 0 }; static guint before[2] = { 0, 0 }; static guint _id = 0; -static _zoom_timeout=0; +static gint _zoom_timeout_sid=0; +static gint _map_mode=0; void map_render_paths(); void map_force_redraw(); @@ -940,12 +942,14 @@ void map_move_mark() /* Just queue the old and new draw areas. */ gtk_widget_queue_draw_area(_map_widget, - _mark_minx, - _mark_miny, _mark_width, _mark_height); + _mark_minx<0 ? 0 : _mark_minx, + _mark_miny<0 ? 0 : _mark_miny, + _mark_width, _mark_height); map_set_mark(); gtk_widget_queue_draw_area(_map_widget, - _mark_minx, - _mark_miny, _mark_width, _mark_height); + _mark_minx<0 ? 0 : _mark_minx, + _mark_miny<0 ? 0 : _mark_miny, + _mark_width, _mark_height); vprintf("%s(): return\n", __PRETTY_FUNCTION__); } @@ -1118,6 +1122,7 @@ static gboolean map_follow_move(GtkWidget * widget, GdkEventMotion * event) before[0] = xx; before[1] = yy; + return FALSE; } gboolean map_key_zoom_timeout() @@ -1154,13 +1159,123 @@ gboolean map_key_zoom_timeout() return TRUE; } +void map_scale_draw(GdkEventExpose *event) +{ + gdk_rectangle_intersect(&event->area, &_scale_rect, &event->area); + + if (event->area.width && event->area.height) { + gdk_draw_rectangle(_map_widget->window, + _map_widget->style-> + bg_gc[GTK_WIDGET_STATE(_map_widget)], + TRUE, _scale_rect.x, _scale_rect.y, + _scale_rect.width, + _scale_rect.height); + gdk_draw_rectangle(_map_widget->window, + _map_widget->style-> + fg_gc[GTK_WIDGET_STATE(_map_widget)], + FALSE, _scale_rect.x, _scale_rect.y, + _scale_rect.width, + _scale_rect.height); + + /* Now calculate and draw the distance. */ + { + gchar buffer[16]; + gfloat distance; + gfloat lat1, lon1, lat2, lon2; + gint width; + + unit2latlon(_center.unitx - + pixel2unit(SCALE_WIDTH / 2 - 4), + _center.unity, lat1, lon1); + unit2latlon(_center.unitx + + pixel2unit(SCALE_WIDTH / 2 - 4), + _center.unity, lat2, lon2); + distance = calculate_distance(lat1, lon1, lat2, lon2) * UNITS_CONVERT[_units]; + + if (distance < 1.f) + snprintf(buffer, sizeof(buffer), + "%0.2f %s", distance, + UNITS_TEXT[_units]); + else if (distance < 10.f) + snprintf(buffer, sizeof(buffer), + "%0.1f %s", distance, + UNITS_TEXT[_units]); + else + snprintf(buffer, sizeof(buffer), + "%0.f %s", distance, + UNITS_TEXT[_units]); + + pango_layout_set_text(_scale_layout, buffer, -1); + pango_layout_get_pixel_size(_scale_layout, &width, NULL); + + /* Draw the layout itself. */ + gdk_draw_layout(_map_widget->window, + _map_widget->style-> + fg_gc[GTK_WIDGET_STATE + (_map_widget)], + _scale_rect.x + + (_scale_rect.width - width) / 2, + _scale_rect.y, _scale_layout); + + /* Draw little hashes on the ends. */ + gdk_draw_line(_map_widget->window, + _map_widget->style-> + fg_gc[GTK_WIDGET_STATE + (_map_widget)], + _scale_rect.x + 4, + _scale_rect.y + + _scale_rect.height / 2 - 4, + _scale_rect.x + 4, + _scale_rect.y + + _scale_rect.height / 2 + 4); + gdk_draw_line(_map_widget->window, + _map_widget->style-> + fg_gc[GTK_WIDGET_STATE + (_map_widget)], + _scale_rect.x + 4, + _scale_rect.y + + _scale_rect.height / 2, + _scale_rect.x + + (_scale_rect.width - width) / 2 - + 4, + _scale_rect.y + + _scale_rect.height / 2); + gdk_draw_line(_map_widget->window, + _map_widget->style-> + fg_gc[GTK_WIDGET_STATE + (_map_widget)], + _scale_rect.x + + _scale_rect.width - 4, + _scale_rect.y + + _scale_rect.height / 2 - 4, + _scale_rect.x + + _scale_rect.width - 4, + _scale_rect.y + + _scale_rect.height / 2 + 4); + gdk_draw_line(_map_widget->window, + _map_widget->style-> + fg_gc[GTK_WIDGET_STATE + (_map_widget)], + _scale_rect.x + + _scale_rect.width - 4, + _scale_rect.y + + _scale_rect.height / 2, + _scale_rect.x + + (_scale_rect.width + width) / 2 + + 4, + _scale_rect.y + + _scale_rect.height / 2); + } + } +} + gboolean map_cb_expose(GtkWidget * widget, GdkEventExpose * event) { printf("%s(%d, %d, %d, %d)\n", __PRETTY_FUNCTION__, event->area.x, event->area.y, event->area.width, event->area.height); - gdk_draw_drawable(_map_widget->window, + gdk_draw_drawable(GDK_DRAWABLE(_map_widget->window), _gc[COLORABLE_MARK], _map_pixmap, event->area.x + _offsetx, event->area.y + _offsety, @@ -1169,118 +1284,8 @@ gboolean map_cb_expose(GtkWidget * widget, GdkEventExpose * event) map_draw_mark(); /* Draw scale, if necessary. */ - if (_show_scale) { - gdk_rectangle_intersect(&event->area, &_scale_rect, - &event->area); - if (event->area.width && event->area.height) { - gdk_draw_rectangle(_map_widget->window, - _map_widget->style-> - bg_gc[GTK_WIDGET_STATE(_map_widget)], - TRUE, _scale_rect.x, _scale_rect.y, - _scale_rect.width, - _scale_rect.height); - gdk_draw_rectangle(_map_widget->window, - _map_widget->style-> - fg_gc[GTK_WIDGET_STATE(_map_widget)], - FALSE, _scale_rect.x, _scale_rect.y, - _scale_rect.width, - _scale_rect.height); - - /* Now calculate and draw the distance. */ - { - gchar buffer[16]; - gfloat distance; - gfloat lat1, lon1, lat2, lon2; - gint width; - - unit2latlon(_center.unitx - - pixel2unit(SCALE_WIDTH / 2 - 4), - _center.unity, lat1, lon1); - unit2latlon(_center.unitx + - pixel2unit(SCALE_WIDTH / 2 - 4), - _center.unity, lat2, lon2); - distance = - calculate_distance(lat1, lon1, lat2, lon2) - * UNITS_CONVERT[_units]; - - if (distance < 1.f) - snprintf(buffer, sizeof(buffer), - "%0.2f %s", distance, - UNITS_TEXT[_units]); - else if (distance < 10.f) - snprintf(buffer, sizeof(buffer), - "%0.1f %s", distance, - UNITS_TEXT[_units]); - else - snprintf(buffer, sizeof(buffer), - "%0.f %s", distance, - UNITS_TEXT[_units]); - pango_layout_set_text(_scale_layout, buffer, - -1); - - pango_layout_get_pixel_size(_scale_layout, - &width, NULL); - - /* Draw the layout itself. */ - gdk_draw_layout(_map_widget->window, - _map_widget->style-> - fg_gc[GTK_WIDGET_STATE - (_map_widget)], - _scale_rect.x + - (_scale_rect.width - width) / 2, - _scale_rect.y, _scale_layout); - - /* Draw little hashes on the ends. */ - gdk_draw_line(_map_widget->window, - _map_widget->style-> - fg_gc[GTK_WIDGET_STATE - (_map_widget)], - _scale_rect.x + 4, - _scale_rect.y + - _scale_rect.height / 2 - 4, - _scale_rect.x + 4, - _scale_rect.y + - _scale_rect.height / 2 + 4); - gdk_draw_line(_map_widget->window, - _map_widget->style-> - fg_gc[GTK_WIDGET_STATE - (_map_widget)], - _scale_rect.x + 4, - _scale_rect.y + - _scale_rect.height / 2, - _scale_rect.x + - (_scale_rect.width - width) / 2 - - 4, - _scale_rect.y + - _scale_rect.height / 2); - gdk_draw_line(_map_widget->window, - _map_widget->style-> - fg_gc[GTK_WIDGET_STATE - (_map_widget)], - _scale_rect.x + - _scale_rect.width - 4, - _scale_rect.y + - _scale_rect.height / 2 - 4, - _scale_rect.x + - _scale_rect.width - 4, - _scale_rect.y + - _scale_rect.height / 2 + 4); - gdk_draw_line(_map_widget->window, - _map_widget->style-> - fg_gc[GTK_WIDGET_STATE - (_map_widget)], - _scale_rect.x + - _scale_rect.width - 4, - _scale_rect.y + - _scale_rect.height / 2, - _scale_rect.x + - (_scale_rect.width + width) / 2 + - 4, - _scale_rect.y + - _scale_rect.height / 2); - } - } - } + if (_show_scale) + map_scale_draw(event); vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__); return TRUE; @@ -1307,13 +1312,22 @@ static gboolean map_autozoomer() { static gfloat z=6.0; +static gint last=6; +gint iz; + +g_print("AutoZoom\n"); -if (_zoom_timeout==0) +if (_zoom_timeout_sid==0) return FALSE; z=(z+_gps.speed+1)/2; if (z>7) z=7.0; else if (z<1) z=1.0; -map_set_zoom(round(z)); +iz=(gint)roundf(z); +g_printf("Setting autozoom to: %f %d S:%f\n", z, iz, _gps.speed); +if (iz>last) iz=last+1; +else if (izx, event->y); + break; + case MAP_MODE_DRAW_ROUTE: + map_draw_route(event->x, event->y); + break; } map_center_unit(x2unit((gint) (event->x + 0.5)), diff --git a/src/map.h b/src/map.h index 1c24ec2..85c26b2 100644 --- a/src/map.h +++ b/src/map.h @@ -21,6 +21,12 @@ #include "utils.h" #include "mapper-types.h" +typedef enum { + MAP_MODE_NORMAL=0, + MAP_MODE_DRAW_TRACK=1, + MAP_MODE_DRAW_ROUTE=2 +} MapMode; + /** VARIABLES FOR MAINTAINING STATE OF THE CURRENT VIEW. */ /** The "zoom" level defines the resolution of a pixel, from 0 to MAX_ZOOM. diff --git a/src/mapper-types.h b/src/mapper-types.h index 6248e22..da1593e 100644 --- a/src/mapper-types.h +++ b/src/mapper-types.h @@ -1,3 +1,5 @@ +#include "config.h" + #define _GNU_SOURCE #include @@ -5,26 +7,6 @@ #ifndef _MAPPER_TYPES_H #define _MAPPER_TYPES_H -/** This enumerated type defines the possible connection states. */ -typedef enum { - /** The receiver is "off", meaning that either the bluetooth radio is - * off or the user has requested not to connect to the GPS receiver. - * No gtk_banner is visible. */ - RCVR_OFF, - - /** The connection with the receiver is down. A gtk_banner is visible with - * the text, "Connecting to GPS receiver". */ - RCVR_DOWN, - - /** The connection with the receiver is up, but a GPS fix is not available. - * A gtk_banner is visible with the text, "(Re-)Establishing GPS fix". */ - RCVR_UP, - - /** The connection with the receiver is up and a GPS fix IS available. - * No gtk_banner is visible. */ - RCVR_FIXED -} ConnState; - /** This enumerated type defines the supported types of repositories. */ typedef enum { REPOTYPE_NONE, /* No URL set. */ @@ -41,6 +23,7 @@ typedef enum { typedef enum { CENTER_WAS_LATLON = -2, CENTER_WAS_LEAD = -1, + CENTER_MANUAL =0, CENTER_LEAD = 1, CENTER_LATLON = 2 } CenterMode; @@ -234,14 +217,6 @@ struct _SaxData { GString *chars; }; -/** Data used during action: add or edit category/poi **/ -typedef struct _DeletePOI DeletePOI; -struct _DeletePOI { - GtkWidget *dialog; - gchar *txt_label; - guint id; -}; - /** Data regarding a map repository. */ typedef struct _RepoData RepoData; struct _RepoData { @@ -286,27 +261,6 @@ struct _AutoRouteDownloadData { RouteDownloadData rdl_data; }; -/** Data to describe a POI. */ -typedef struct _PoiInfo PoiInfo; -struct _PoiInfo { - guint poi_id; - guint cat_id; - gfloat lat; - gfloat lon; - gchar *label; - gchar *desc; -}; - -typedef struct _ScanInfo ScanInfo; -struct _ScanInfo { - GtkWidget *settings_dialog; - GtkWidget *txt_rcvr_mac; - GtkWidget *scan_dialog; - GtkWidget *banner; - GtkListStore *store; - guint sid; -}; - typedef struct _BrowseInfo BrowseInfo; struct _BrowseInfo { GtkWidget *dialog; @@ -314,6 +268,5 @@ struct _BrowseInfo { }; Point _point_null; -ConnState _conn_state; #endif diff --git a/src/mapper.c b/src/mapper.c index 4f60cb6..3cab0bf 100644 --- a/src/mapper.c +++ b/src/mapper.c @@ -122,6 +122,7 @@ void set_conn_state(ConnState 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; @@ -130,26 +131,35 @@ void set_conn_state(ConnState new_conn_state) 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")); + _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, + _fix_banner = hildon_banner_show_progress(_window, NULL, _("Establishing GPS fix")); +#else + +#endif break; default:; /* to quell warning. */ } @@ -232,6 +242,41 @@ void set_var_defaults(void) _conn_state = RCVR_OFF; } +gint mapper_osso_init(void) +{ +#ifdef WITH_HILDON +/* Initialize _osso. */ +_osso = osso_initialize("org.tal.mapper", VERSION, TRUE, NULL); +if (!_osso) { + g_printerr("osso_initialize failed.\n"); + return 1; +} +#endif +return 0; +} + +gint mapper_osso_cb_init(void) +{ +#ifdef WITH_HILDON +if (OSSO_OK != osso_rpc_set_default_cb_f(_osso, dbus_cb_default, NULL)) { + g_printerr("osso_rpc_set_default_cb_f failed.\n"); + return 1; +} +#endif +return 0; +} + +void timezone_init(void) +{ +time_t time1; +struct tm time2; + +time1 = time(NULL); +localtime_r(&time1, &time2); +_gmtoffset = time2.tm_gmtoff; +} + + gint main(gint argc, gchar * argv[]) { printf("%s()\n", __PRETTY_FUNCTION__); @@ -243,42 +288,26 @@ gint main(gint argc, gchar * argv[]) textdomain(GETTEXT_PACKAGE); g_thread_init(NULL); + g_type_init(); -#ifdef WITH_HILDON - /* Initialize _osso. */ - _osso = osso_initialize("org.tal.mapper", VERSION, TRUE, NULL); - if (!_osso) { - g_printerr("osso_initialize failed.\n"); + if (mapper_osso_init()!=0) return 1; - } -#endif set_var_defaults(); +#ifdef WITH_GSTREAMER gst_init(&argc, &argv); +#endif gtk_init(&argc, &argv); - - /* Init gconf. */ - g_type_init(); gconf_init(argc, argv, NULL); - - /* Init Gnome-VFS. */ gnome_vfs_init(); - - /* Init libcurl. */ curl_global_init(CURL_GLOBAL_NOTHING); - + timezone_init(); + gpx_init(); mapper_init(argc, argv); - -#ifdef WITH_HILDON - if (OSSO_OK != osso_rpc_set_default_cb_f(_osso, dbus_cb_default, NULL)) { - g_printerr("osso_rpc_set_default_cb_f failed.\n"); + if (mapper_osso_cb_init()!=0) return 1; - } -#endif - gtk_main(); - mapper_destroy(); #ifdef WITH_HILDON diff --git a/src/poi.h b/src/poi.h index bd7d085..dfa48b0 100644 --- a/src/poi.h +++ b/src/poi.h @@ -64,6 +64,25 @@ struct _PoiData { gchar *desc; }; +/** Data to describe a POI. */ +typedef struct _PoiInfo PoiInfo; +struct _PoiInfo { + guint poi_id; + guint cat_id; + gfloat lat; + gfloat lon; + gchar *label; + gchar *desc; +}; + +/** Data used during action: add or edit category/poi **/ +typedef struct _DeletePOI DeletePOI; +struct _DeletePOI { + GtkWidget *dialog; + gchar *txt_label; + guint id; +}; + /** POI */ sqlite3 *_db; gchar *_poi_db; diff --git a/src/speed-display.c b/src/speed-display.c index 597e7a2..55aa021 100644 --- a/src/speed-display.c +++ b/src/speed-display.c @@ -7,17 +7,11 @@ #include #include #include -#include #include #include -#include #include #include #include -#include -#include -#include -#include #include #include @@ -67,11 +61,9 @@ void speed_limit(void) buffer = g_strdup_printf("%0.0f", cur_speed); pango_layout_set_text(_speed_limit_layout, buffer, -1); - pango_layout_get_pixel_size(_speed_limit_layout, &width, &height); - gtk_widget_queue_draw_area(_map_widget, - x - 5, y - 5, width + 5, height + 5); + gtk_widget_queue_draw_area(_map_widget, x - 5, y - 5, width + 15, height + 5); gdk_window_process_all_updates(); switch (_speed_location) { diff --git a/src/track.c b/src/track.c index f5cdd66..7f609b3 100644 --- a/src/track.c +++ b/src/track.c @@ -9,6 +9,8 @@ #include "ui-common.h" #include "file.h" +#include "track.h" + void path_resize(Path * path, guint size) { printf("%s()\n", __PRETTY_FUNCTION__); diff --git a/src/ui-common.c b/src/ui-common.c index b2287c0..df9101f 100644 --- a/src/ui-common.c +++ b/src/ui-common.c @@ -41,6 +41,7 @@ GtkWidget *_menu_bar; GtkWidget *_toolbar; +GtkWidget *_fix_banner=NULL; /** * Update all GdkGC objects to reflect the current _draw_width. diff --git a/src/utils.c b/src/utils.c index 9e96b05..d1da655 100644 --- a/src/utils.c +++ b/src/utils.c @@ -22,6 +22,7 @@ #include "utils.h" #include "gps.h" #include "mapper-types.h" +#include "bt.h" void sound_noise(void) { @@ -52,7 +53,7 @@ void sound_speak(gchar * phrase) } #if 0 -void latlon2unit(gfloat lat, gfloat lon, gint * unitx_, gint * unity_) +void latlon2unit(gfloat lat, gfloat lon, gint *unitx_, gint *unity_) { gfloat tmp; @@ -65,7 +66,7 @@ void latlon2unit(gfloat lat, gfloat lon, gint * unitx_, gint * unity_) * (logf((1.f + tmp) / (1.f - tmp)) * 0.5f - MERCATOR_TOP); } -void unit2latlon(gint unitx, gint unity, gfloat lat, gfloat lon) +void unit2latlon(gint unitx, gint unity, gfloat *lat, gfloat *lon) { (lon) = ((unitx) * (360.f / WORLD_SIZE_UNITS)) - 180.f; (lat) = (360.f * (atanf(expf(((unity) @@ -112,6 +113,7 @@ deg_format(DegFormat degformat, gfloat coor, gchar * scoor, gchar neg_char, ((min - (int)min) * 60.0), coor < 0.f ? neg_char : pos_char); break; + default:; } vprintf("%s(): return\n", __PRETTY_FUNCTION__); } diff --git a/src/utils.h b/src/utils.h index f8a860b..4bd4fec 100644 --- a/src/utils.h +++ b/src/utils.h @@ -282,8 +282,8 @@ #define KEEP_DISPLAY_ON() #endif -#define lat_format(A, B) deg_format((A), (B), 'S', 'N') -#define lon_format(A, B) deg_format((A), (B), 'W', 'E') +#define lat_format(A, B) deg_format(_degformat,(A), (B), 'S', 'N') +#define lon_format(A, B) deg_format(_degformat,(A), (B), 'W', 'E') #define TRACKS_MASK 0x00000001 #define ROUTES_MASK 0x00000002 @@ -327,8 +327,6 @@ if (_iap_http_proxy_host) { #define MACRO_BANNER_SHOW_INFO(A, S) { hildon_banner_show_information(A, NULL, S); } #endif -#define GPS_READ_BUF_SIZE 256 - #define WRITE_STRING(string) { \ GnomeVFSResult vfs_result; \ GnomeVFSFileSize size; \ @@ -348,5 +346,7 @@ if (_iap_http_proxy_host) { gint download_comparefunc(const ProgressUpdateInfo * a, const ProgressUpdateInfo * b, gpointer user_data); gfloat calculate_distance(gfloat lat1, gfloat lon1, gfloat lat2, gfloat lon2); +void deg_format(DegFormat degformat, gfloat coor, gchar *scoor, gchar neg_char, gchar pos_char); +void integerize_data(); #endif -- 2.39.5