#include "gpx.h"
struct sql_select_stmt {
- sqlite3_stmt *select_path;
- sqlite3_stmt *select_path_nodes;
- sqlite3_stmt *insert_path;
- sqlite3_stmt *insert_path_node;
- sqlite3_stmt *delete_path_nodes;
- sqlite3_stmt *delete_path;
+ sqlite3_stmt *select_paths;
+ sqlite3_stmt *select_path_nodes;
+
+ sqlite3_stmt *insert_path;
+ sqlite3_stmt *insert_path_node;
+
+ sqlite3_stmt *delete_path;
+ sqlite3_stmt *delete_path_nodes;
};
static struct sql_select_stmt sql;
+#define PATH_TABLE_PATHS "create table IF NOT EXISTS paths ( \
+ nid int primary key, \
+ name text not null, \
+ desc text, \
+ t int not null);"
+
+#define PATH_TABLE_NODES "create table IF NOT EXISTS path_nodes ( \
+ nid int not null, \
+ lat real not null, \
+ lon real not null, \
+ sats int, \
+ speed real, \
+ course real, \
+ pdop real, \
+ hdop real, \
+ vdop real, \
+ name text default null, \
+ t int not null);"
+
/* Path point add sensitivity */
static gint sensitivity=3;
gboolean
path_resize(Path *path, guint size)
{
+g_return_val_if_fail(path, FALSE);
+
if (path->head + size != path->cap) {
- Point *old_head = path->head;
WayPoint *curr;
+ Point *old_head = path->head;
+
path->head = g_renew(Point, old_head, size);
+ g_assert(path->head);
path->cap = path->head + size;
if (path->head != old_head) {
path->tail = path->head + (path->tail - old_head);
gboolean
path_wresize(Path *path, guint wsize)
{
+g_return_val_if_fail(path, FALSE);
+
if (path->whead + wsize != path->wcap) {
WayPoint *old_whead = path->whead;
+
path->whead = g_renew(WayPoint, old_whead, wsize);
path->wtail = path->whead + (path->wtail - old_whead);
path->wcap = path->whead + wsize;
+
return TRUE;
}
return FALSE;
gboolean
path_add_point(Path *path, GpsData *gps)
{
+g_return_val_if_fail(path, FALSE);
+
if (!gps) {
MACRO_PATH_INCREMENT_TAIL(*path);
*path->tail=_point_null;
gboolean
path_insert_break(Path *path)
{
-if (!path)
- return FALSE;
-
-if (!path->tail)
- return FALSE;
+g_return_val_if_fail(path, FALSE);
+g_return_val_if_fail(path->tail, FALSE);
if (path->tail->unity) {
guint x1, y1;
{
Point *p=NULL;
+g_return_val_if_fail(path, NULL);
+
if (path->head == path->tail)
return p;
gdouble lat1, lon1, lat2, lon2;
gdouble sum=0.0;
+g_return_val_if_fail(path, 0.0);
+
/* If point is NULL, use the next waypoint. */
if (point == NULL && path->next_way)
point = path->next_way->point;
gchar *bytes;
gint size;
+g_return_val_if_fail(path, FALSE);
+g_return_val_if_fail(config_dir, FALSE);
+g_return_val_if_fail(file, FALSE);
+
pfile = gnome_vfs_uri_make_full_from_relative(config_dir, file);
if (gnome_vfs_read_entire_file(pfile, &size, &bytes)==GNOME_VFS_OK)
gpx_parse(path, bytes, size, GPX_PATH_NEW);
{
GnomeVFSHandle *handle;
gchar *tfile;
+
+g_return_val_if_fail(path, FALSE);
+g_return_val_if_fail(config_dir, FALSE);
+g_return_val_if_fail(file, FALSE);
+
tfile=gnome_vfs_uri_make_full_from_relative(config_dir, file);
if (gnome_vfs_create(&handle, tfile, GNOME_VFS_OPEN_WRITE, FALSE, 0600)==GNOME_VFS_OK) {
gpx_write(path, handle);
void
path_insert_mark_text(Path *path, gchar *text)
{
-g_assert(path);
+g_return_if_fail(path);
MACRO_PATH_INCREMENT_WTAIL(*path);
path->wtail->point=path->tail;
if (text) {
gdouble lat1, lon1, lat2, lon2;
gdouble sum=0.0;
-if (path->whead==path->wtail)
- return NULL;
+g_return_val_if_fail(path, NULL);
wcurr=path->whead;
-if (!wcurr)
- return NULL;
+g_return_val_if_fail(wcurr, NULL);
+g_return_val_if_fail(wcurr->point, NULL);
-if (!wcurr->point)
- return NULL;
+store=gtk_list_store_new(ROUTE_NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
-unit2latlon(wcurr->point->unitx, wcurr->point->unity, lat1, lon1);
+if (path->whead==path->wtail)
+ return store;
-store=gtk_list_store_new(ROUTE_NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
+unit2latlon(wcurr->point->unitx, wcurr->point->unity, lat1, lon1);
while (wcurr!=path->wtail) {
- if (!wcurr) {
+ if (!wcurr)
break;
- }
if (!wcurr->point) {
- g_debug("No point for waypoint (%s) skipping", wcurr->desc);
+ g_debug("PSTORE: No point for waypoint (%s) skipping", wcurr->desc);
wcurr++;
continue;
}
void
position_set(Position *pos, gboolean valid, gdouble lat, gdouble lon)
{
+g_assert(pos);
pos->valid=valid;
pos->lat=valid ? lat : NAN;
pos->lon=valid ? lon : NAN;
}
-
-void
-position_update(Position *pos, GpsData *data)
-{
-if (!pos->valid)
- return;
-}
GtkWidget *confirm;
gboolean r=FALSE;
+g_return_val_if_fail(route, FALSE);
+
confirm=hildon_note_new_confirmation(GTK_WINDOW(_window), _("Really clear the route?"));
if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
{
guint announce_thres_unsquared;
-if (!gps)
- return;
+g_return_if_fail(route);
+g_return_if_fail(gps);
if (!_announce_waypoints)
return;
void
route_autoroute_check(Path *route)
{
+g_return_if_fail(route);
+
if (_autoroute_data.enabled && !_autoroute_data.in_progress && route->near_point_dist_squared > 400) {
MACRO_BANNER_SHOW_INFO(_window, _("Recalculating directions..."));
_autoroute_data.in_progress = TRUE;
gchar *buffer;
gint size;
+g_return_val_if_fail(route, FALSE);
+
if (file_open_get_contents(&_route_dir_uri, &buffer, &size)) {
/* If auto is enabled, append the route, otherwise replace it. */
if (gpx_parse(route, buffer, size, _autoroute_data.enabled ? GPX_PATH_APPEND : GPX_PATH_NEW)) {
MACRO_BANNER_SHOW_INFO(_window, _("Route Opened"));
/* Find the nearest route point, if we're connected. */
route_find_nearest_point(route);
- route_set_destination_from_last(route);
+ route_set_destination_from_last(route, &_dest);
return TRUE;
} else {
popup_error(_window, _("Error parsing GPX file."));
{
GnomeVFSHandle *handle;
+g_return_val_if_fail(route, FALSE);
+
if (route->head==route->tail) {
MACRO_BANNER_SHOW_INFO(_window, _("No route exist."));
return FALSE;
MACRO_BANNER_SHOW_INFO(_window, _("Route Downloaded"));
g_free(rdl_data.bytes);
- route_set_destination_from_last(route);
+ route_set_destination_from_last(route, &_dest);
/* Success! Get out of the while loop. */
r=TRUE;
guint64 nearest_squared;
Point pos = { unitx, unity, 0, NAN };
+g_return_val_if_fail(route, NULL);
+
wcurr = wnear = route->whead;
if (wcurr && wcurr->point && wcurr != route->wtail) {
nearest_squared = DISTANCE_SQUARED(pos, *(wcurr->point));
WayPoint *wcurr, *wnext;
guint64 near_dist_squared;
+g_return_val_if_fail(route, FALSE);
+
/* If we have waypoints (_next_way != NULL), then determine the "next
* waypoint", which is defined as the waypoint after the nearest point,
* UNLESS we've passed that waypoint, in which case the waypoint after
void
route_find_nearest_point(Path *route)
{
+g_return_if_fail(route);
+
/* Initialize near_point to first non-zero point. */
route->near_point = route->head;
while (!route->near_point->unity && route->near_point != route->tail)
gdouble lat, lon;
gdouble sum;
+g_return_val_if_fail(route, FALSE);
+g_return_val_if_fail(point, FALSE);
+
unit2latlon(_gps->data.unitx, _gps->data.unity, lat, lon);
sum=path_get_distance_to(route, point, lat, lon);
g_snprintf(buffer, sizeof(buffer), "%s: %.02f %s", _("Distance"), sum * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
void
route_show_distance_to_next(Path *route)
{
+g_return_if_fail(route);
+
if (!route_show_distance_to(route, NULL))
MACRO_BANNER_SHOW_INFO(_window, _("There is no next waypoint."));
}
Point *p;
gdouble lat,lon;
+g_return_val_if_fail(route, FALSE);
+g_return_val_if_fail(pos, FALSE);
+
if (route->head==route->tail) {
position_set(pos, FALSE, NAN, NAN);
return FALSE;
void
route_show_distance_to_last(Path *route)
{
+g_return_if_fail(route);
+
if (route->head != route->tail) {
route_show_distance_to(route, path_find_last_point(route));
} else {