Misc other things.
#include <string.h>
#include <strings.h>
#include <stddef.h>
+#include <libintl.h>
#include <locale.h>
#include <math.h>
#include <errno.h>
#include <glib/gstdio.h>
#include <gtk/gtk.h>
#include <fcntl.h>
-#include <libgnomevfs/gnome-vfs.h>
#include <gconf/gconf-client.h>
-#include <libxml/parser.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include "utils.h"
#include "mapper-types.h"
#include "settings.h"
+#include "ui-common.h"
struct sockaddr_rc _rcvr_addr = { 0 };
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;
/* 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
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);
}
_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);
}
#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
{
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
#include <libgnomevfs/gnome-vfs.h>
#include <curl/multi.h>
#include <gconf/gconf-client.h>
-#include <libxml/parser.h>
#include "utils.h"
#include "mapper-types.h"
#include "db.h"
#include "poi.h"
#include "gps.h"
+#include "bt.h"
#include "ui-common.h"
#include "settings.h"
#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.
*/
/* 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);
#include "utils.h"
#include "mapper-types.h"
+#include "bt.h"
/**
* Scan for all bluetooth devices. This method can take a few seconds,
#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)
{
/* 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);
} 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__);
}
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;
_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'))) {
/* 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
#include <sys/wait.h>
#include <glib/gstdio.h>
#include <gtk/gtk.h>
+#include <libintl.h>
+#include <locale.h>
#include "utils.h"
#include "gps.h"
#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__);
return TRUE;
}
-static gboolean gps_display_details(void)
+gboolean
+gps_display_details(void)
{
gchar *buffer, litbuf[16];
printf("%s()\n", __PRETTY_FUNCTION__);
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;
}
}
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;
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
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)
#include "map.h"
#include "route.h"
#include "gps.h"
+#include "bt.h"
#include "mapper-types.h"
#include "ui-common.h"
#include "settings.h"
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();
/* 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__);
}
before[0] = xx;
before[1] = yy;
+ return FALSE;
}
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,
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;
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 (iz<last) iz=last-1;
+last=iz;
+map_set_zoom(iz);
return TRUE;
}
void
map_set_autozoom(gboolean az)
{
-if ((az==TRUE) && (_zoom_timeout!=0)) {
- _zoom_timeout=g_timeout_add(5000, (GSourceFunc) map_autozoomer, NULL);
+if (az==TRUE) {
+ g_print("Enabled autozoom\n");
+ _zoom_timeout_sid=g_timeout_add(5000, (GSourceFunc) map_autozoomer, NULL);
+ return;
+} else {
+ if (_zoom_timeout_sid) {
+ g_source_remove(_zoom_timeout_sid);
+ _zoom_timeout_sid=0;
+ }
+ g_print("Disabled autozoom\n");
return;
}
-if ((az==FALSE) && (_zoom_timeout!=0)) {
- _zoom_timeout=0;
- return;
}
+static void map_draw_route(gint x, gint y)
+{
+ cmenu_route_add_way(x, y);
}
static void map_draw_track(gint x, gint y)
(_menu_ac_none_item),
TRUE);
- if (TRUE) {
+ switch (_map_mode) {
+ case MAP_MODE_DRAW_TRACK:
map_draw_track(event->x, 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)),
#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.
+#include "config.h"
+
#define _GNU_SOURCE
#include <math.h>
#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. */
typedef enum {
CENTER_WAS_LATLON = -2,
CENTER_WAS_LEAD = -1,
+ CENTER_MANUAL =0,
CENTER_LEAD = 1,
CENTER_LATLON = 2
} CenterMode;
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 {
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;
};
Point _point_null;
-ConnState _conn_state;
#endif
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;
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. */
}
_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__);
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
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;
#include <string.h>
#include <strings.h>
#include <stddef.h>
-#include <locale.h>
#include <math.h>
#include <errno.h>
-#include <sys/wait.h>
#include <glib/gstdio.h>
#include <gtk/gtk.h>
#include <fcntl.h>
-#include <libgnomevfs/gnome-vfs.h>
-#include <curl/multi.h>
-#include <gconf/gconf-client.h>
-#include <libxml/parser.h>
#include <libintl.h>
#include <locale.h>
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) {
#include "ui-common.h"
#include "file.h"
+#include "track.h"
+
void path_resize(Path * path, guint size)
{
printf("%s()\n", __PRETTY_FUNCTION__);
GtkWidget *_menu_bar;
GtkWidget *_toolbar;
+GtkWidget *_fix_banner=NULL;
/**
* Update all GdkGC objects to reflect the current _draw_width.
#include "utils.h"
#include "gps.h"
#include "mapper-types.h"
+#include "bt.h"
void sound_noise(void)
{
}
#if 0
-void latlon2unit(gfloat lat, gfloat lon, gint * unitx_, gint * unity_)
+void latlon2unit(gfloat lat, gfloat lon, gint *unitx_, gint *unity_)
{
gfloat tmp;
* (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)
((min - (int)min) * 60.0),
coor < 0.f ? neg_char : pos_char);
break;
+ default:;
}
vprintf("%s(): return\n", __PRETTY_FUNCTION__);
}
#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
#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; \
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