From c23068c5ba97f9c48e2de4f1288056fe0d942f2d Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Fri, 26 Oct 2007 16:24:00 +0300 Subject: [PATCH] Always use guint for poi/cat id. --- src/poi-gui.c | 6 +++--- src/poi.c | 48 ++++++++++++++++++++++++------------------------ src/poi.h | 33 ++++++++++++++------------------- 3 files changed, 41 insertions(+), 46 deletions(-) diff --git a/src/poi-gui.c b/src/poi-gui.c index 045c553..c266229 100644 --- a/src/poi-gui.c +++ b/src/poi-gui.c @@ -81,7 +81,7 @@ i = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(GTK_WIDGET(dialog)); if (i == GTK_RESPONSE_OK) { - if (poi_category_delete(dpoi)==FALSE) + if (poi_category_delete(dpoi->id)==FALSE) popup_error(_window, _("Problem deleting category or POI")); gtk_widget_hide_all(dpoi->dialog); map_force_redraw(); @@ -406,7 +406,7 @@ i = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(GTK_WIDGET(dialog)); if (i == GTK_RESPONSE_OK) { - if (poi_delete(dpoi)==FALSE) { + if (poi_delete(dpoi->id)==FALSE) { popup_error(_window, _("Problem deleting POI")); } else { gtk_widget_hide_all(dpoi->dialog); @@ -535,7 +535,7 @@ GtkListStore *store; guint num_cats; GtkTreeIter iter; -if (poi_get_list(unitx, unity, &store, &num_cats)==FALSE) +if (poi_get_list_near(unitx, unity, &store, &num_cats)==FALSE) return FALSE; switch (num_cats) { diff --git a/src/poi.c b/src/poi.c index 179c6f5..dc3afda 100644 --- a/src/poi.c +++ b/src/poi.c @@ -223,7 +223,7 @@ poi_db_prepare(sqlite3 *db) " from poi p, category c " " where p.lat between ? and ? " " and p.lon between ? and ? " - " and c.enabled = 1 and p.cat_id = c.cat_id and p.label like ?", + " and c.enabled = 1 and p.cat_id = c.cat_id and p.label like ? order by p.label", -1, &poisql.select_poi_search, NULL); /* Search POI label && category */ @@ -233,7 +233,7 @@ poi_db_prepare(sqlite3 *db) " from poi p, category c " " where p.lat between ? and ? " " and p.lon between ? and ? " - " and c.enabled = 1 and p.cat_id = c.cat_id and p.label like ? and c.cat_id = ?", + " and c.enabled = 1 and p.cat_id = c.cat_id and p.label like ? and c.cat_id = ? order by p.label", -1, &poisql.select_poi_search_cat, NULL); /* insert poi */ @@ -357,7 +357,7 @@ g_slice_free(poi_category, c); } gboolean -poi_category_toggle(gint cat_id, gboolean cat_enabled) +poi_category_toggle(guint cat_id, gboolean cat_enabled) { if (SQLITE_OK != sqlite3_bind_int(poisql.toggle_cat, 1, cat_enabled) || SQLITE_OK != sqlite3_bind_int(poisql.toggle_cat, 2, cat_id) || @@ -368,7 +368,7 @@ return TRUE; } gboolean -poi_category_get(gint cat_id, poi_category **c) +poi_category_get(guint cat_id, poi_category **c) { poi_category *cc; @@ -391,7 +391,7 @@ return TRUE; } gboolean -poi_category_update(gint cat_id, poi_category *c) +poi_category_update(guint cat_id, poi_category *c) { gboolean results=TRUE; @@ -424,19 +424,19 @@ return results; } gboolean -poi_category_delete(delete_poi *dpoi) +poi_category_delete(guint id) { if (!_db) return FALSE; -if (SQLITE_OK != sqlite3_bind_int(poisql.delete_poi_by_catid, 1, dpoi->id) || SQLITE_DONE != sqlite3_step(poisql.delete_poi_by_catid)) { +if (SQLITE_OK != sqlite3_bind_int(poisql.delete_poi_by_catid, 1, id) || SQLITE_DONE != sqlite3_step(poisql.delete_poi_by_catid)) { sqlite3_reset(poisql.delete_poi_by_catid); return FALSE; } sqlite3_reset(poisql.delete_poi_by_catid); sqlite3_clear_bindings(poisql.delete_poi_by_catid); -if (SQLITE_OK != sqlite3_bind_int(poisql.delete_cat, 1, dpoi->id) || SQLITE_DONE != sqlite3_step(poisql.delete_cat)) { +if (SQLITE_OK != sqlite3_bind_int(poisql.delete_cat, 1, id) || SQLITE_DONE != sqlite3_step(poisql.delete_cat)) { sqlite3_reset(poisql.delete_cat); return FALSE; } @@ -447,12 +447,12 @@ return TRUE; gboolean -poi_delete(delete_poi *dpoi) +poi_delete(guint id) { if (!_db) return FALSE; -if (SQLITE_OK != sqlite3_bind_int(poisql.delete_poi, 1, dpoi->id) || SQLITE_DONE != sqlite3_step(poisql.delete_poi)) { +if (SQLITE_OK != sqlite3_bind_int(poisql.delete_poi, 1, id) || SQLITE_DONE != sqlite3_step(poisql.delete_poi)) { sqlite3_reset(poisql.delete_poi); return FALSE; } @@ -462,7 +462,7 @@ return TRUE; } gboolean -poi_get_list(guint unitx, guint unity, GtkListStore **store, guint *_num_cats) +poi_get_list_near(guint unitx, guint unity, GtkListStore **store, guint *_num_cats) { guint x, y; gdouble lat1, lon1, lat2, lon2; @@ -473,16 +473,6 @@ gint num_cats=0; if (!_db) return FALSE; -*store = gtk_list_store_new(POI_NUM_COLUMNS, - G_TYPE_INT, /* POI ID */ - G_TYPE_INT, /* Category ID */ - G_TYPE_DOUBLE, /* Latitude */ - G_TYPE_DOUBLE, /* Longitude */ - G_TYPE_STRING, /* Lat/Lon */ - G_TYPE_STRING, /* POI Label */ - G_TYPE_STRING, /* POI Desc. */ - G_TYPE_STRING); /* Category Label */ - x = unitx - pixel2unit(3 * _draw_width); y = unity + pixel2unit(3 * _draw_width); unit2latlon(x, y, lat1, lon1); @@ -499,6 +489,16 @@ if (SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 1, lat1) || return FALSE; } +*store = gtk_list_store_new(POI_NUM_COLUMNS, + G_TYPE_INT, /* POI ID */ + G_TYPE_INT, /* Category ID */ + G_TYPE_DOUBLE, /* Latitude */ + G_TYPE_DOUBLE, /* Longitude */ + G_TYPE_STRING, /* Lat/Lon */ + G_TYPE_STRING, /* POI Label */ + G_TYPE_STRING, /* POI Desc. */ + G_TYPE_STRING); /* Category Label */ + while (SQLITE_ROW == sqlite3_step(poisql.select_poi)) { gdouble lat, lon; @@ -527,7 +527,7 @@ return TRUE; } gboolean -poi_update(gint poi_id, gint cat_id, gchar *poi_label, gchar *poi_desc) +poi_update(guint poi_id, guint cat_id, gchar *poi_label, gchar *poi_desc) { if (!_db) return FALSE; @@ -545,7 +545,7 @@ return TRUE; } gboolean -poi_add(gdouble lat, gdouble lon, gint cat_id, gchar *poi_label, gchar *poi_desc) +poi_add(gdouble lat, gdouble lon, guint cat_id, gchar *poi_label, gchar *poi_desc) { if (!_db) return FALSE; @@ -589,7 +589,7 @@ return NULL; } GtkListStore * -poi_category_generate_store() +poi_category_generate_store(void) { GtkTreeIter iter; GtkListStore *store; diff --git a/src/poi.h b/src/poi.h index 339b4ec..80b8d83 100644 --- a/src/poi.h +++ b/src/poi.h @@ -22,19 +22,12 @@ struct _poi_db { guint zoom; }; -typedef struct _poi_data poi_data; -struct _poi_data { - gdouble lat; - gdouble lon; - gchar *name; - gchar *desc; -}; - /** Data to describe a POI. */ typedef struct _poi_info poi_info; struct _poi_info { guint poi_id; guint cat_id; + guint is_in; gdouble lat; gdouble lon; gchar *label; @@ -53,8 +46,9 @@ struct _delete_poi { typedef struct _poi_category poi_category; struct _poi_category { - gint id; - gint enabled; + guint id; + gboolean enabled; + gboolean warning; gchar *label; gchar *desc; }; @@ -86,18 +80,19 @@ gboolean poi_db_prepare(sqlite3 *db); poi_info *poi_new(void); void poi_free(poi_info *p); -gboolean poi_get_list(guint unitx, guint unity, GtkListStore **store, guint *num_cats); -gboolean poi_update(gint poi_id, gint cat_id, gchar *poi_label, gchar *poi_desc); -gboolean poi_add(gdouble lat, gdouble lon, gint cat_id, gchar *poi_label, gchar *poi_desc); -gboolean poi_delete(delete_poi * dpoi); + +gboolean poi_get_list_near(guint unitx, guint unity, GtkListStore **store, guint *num_cats); +gboolean poi_update(guint poi_id, guint cat_id, gchar *poi_label, gchar *poi_desc); +gboolean poi_add(gdouble lat, gdouble lon, guint cat_id, gchar *poi_label, gchar *poi_desc); +gboolean poi_delete(guint id); poi_category *poi_category_new(void); void poi_category_free(poi_category *c); -gboolean poi_category_get(gint cat_id, poi_category **c); -gboolean poi_category_delete(delete_poi * dpoi); -gboolean poi_category_update(gint cat_id, poi_category *c); +gboolean poi_category_get(guint cat_id, poi_category **c); +gboolean poi_category_delete(guint id); +gboolean poi_category_update(guint cat_id, poi_category *c); poi_info *poi_find_nearest(gdouble lat, gdouble lon); -gboolean poi_category_toggle(gint cat_id, gboolean cat_enabled); -GtkListStore *poi_category_generate_store(); +gboolean poi_category_toggle(guint cat_id, gboolean cat_enabled); +GtkListStore *poi_category_generate_store(void); #endif -- 2.39.5