11 #include <glib/gstdio.h>
14 #include <gconf/gconf-client.h>
15 #include <libxml/parser.h>
24 #include "mapper-types.h"
31 static sqlite3 *poidb;
33 /* POI Icon theme. "classic" or "square". Should be made into a configuration option */
34 static gchar *theme="square";
36 /* Hash table for caching POI icons */
37 static GHashTable *poi_icon_hash = NULL;
39 struct _poi_categories {
41 const gchar *name, *desc, *icon, *color;
44 /* The default POI categories */
45 static struct _poi_categories default_poi_categories[] = {
46 { NODE_AMENITY_PARKING, "Parking", "Parking place for vehicles." , "vehicle/parking", "#2020ff" },
47 { NODE_AMENITY_FUEL, "Fuel", "Stations for purchasing fuel for vehicles." , "vehicle/fuel_station", "#4040f0" },
48 { NODE_AMENITY_SPEEDCAM, "Speed Cam", "Automatic speed cameras." , "vehicle/restrictions/speed_trap", "#ff0000" },
49 { NODE_AMENITY_HOSPITAL, "Hospital", "Get medical help" , "health/hospital", "#ff4040" },
50 { NODE_AMENITY_PHARMACY, "Pharmacy", "Place to get drugs." , "health/pharmacy", "#40f040" },
51 { NODE_AMENITY_POLICE, "Police", "Police station" , "public/police", "#8570ff" },
52 { NODE_TOURISM_HOTEL, "Hotel", "Places to stay temporarily or for the night." , "accommodation/hotel", "#ba20ba" },
53 { NODE_TOURISM_HOSTEL, "Hostel", "Places to stay temporarily or for the night. Cheap." , "accommodation/hostel", "#ba30ba" },
54 { NODE_TOURISM_MOTEL, "Motel", "Places to stay temporarily or for the night. Cheap." , "accommodation/motel", "#ba40ba" },
55 { NODE_AMENITY_ATM, "ATM", "Automatic Teller Machine/Cashpoint." , "money/atm", "#40a040" },
56 { NODE_AMENITY_BANK, "Bank", "Place to take care of your money." , "money/bank", "#50b550" },
57 { NODE_AMENITY_POST, "Post office", "Place to handle mail." , "public/post_office", "#ff6868" },
58 { NODE_AMENITY_POST_BOX, "Post box", "Send letters." , "public/post_box", "#ff6060" },
59 { NODE_TOURISM_INFO, "Tourism info", "A place for tourists to get information." , "misc/information", "#4af04a" },
60 { NODE_AMENITY_TAXI, "Taxi station", "Get a Taxi here." , "transport/taxi", "#50ffff" },
61 { NODE_RAILWAY_STATION, "Railway station", "Transportation by train." , "transport/railway", "#fa7070" },
62 { NODE_RAILWAY_HALT, "Railway halt", "" , "transport/railway_small", "#f27777" },
63 { NODE_AMENITY_BUS_STATION, "Bus station", "Transportation by bus." , "transport/bus", "#f07070" },
64 { NODE_AMENITY_BOAT, "Harbour", "Transportation by boat." , "transport/ferry", "#9090ee" },
65 { NODE_AIRPORT_TERMINAL, "Airport", "Transportation by air." , "transport/airport", "#909099" },
66 { NODE_TOURISM_CAMP_SITE, "Camp site", "Place to go camping" , "accommodation/camping", "#90f080" },
67 { NODE_TOURISM_CARAVAN_SITE, "Caravan site", "" , "accommodation/camping/caravan", "#90ff80" },
68 { NODE_TOURISM_PICNIC_SITE, "Picnic", "Place to have a Picnic" , "recreation/picnic", "#a5f8e5" },
69 { NODE_AMENITY_FOOD, "Restaurant, Fast food", "Places to eat or drink." , "food/fastfood", "#e5960d" },
70 { NODE_AMENITY_PUB, "Pub", "Place to drink." , "food/pub", "#f5960d" },
71 { NODE_AMENITY_NIGHTCLUB, "Disco, Club", "Place to drink, party and dance." , "food/bar", "#f59c1d" },
72 { NODE_AMENITY_CAFE, "Cafe", "Place to drink coffe or tee and eat." , "food/cafe", "#ff960d" },
73 { NODE_AMENITY_CINEMA, "Cinema", "Place to see movies" , "recreation/cinema", "#9090a0" },
74 { NODE_AMENITY_THEATRE, "Theatre", "Place to see people performing" , "recreation/theater", "#9595a5" },
75 { NODE_AMENITY_SHOP, "Shopping", "Places to shop or acquire services." , "shopping", "#61ef1b" },
76 { NODE_AMENITY_POW, "Place of Worchip", "" , "religion/church", "#7c5b0b" },
77 { NODE_TOURISM_THEME_PARK, "Theme Park", "Place to have fun and ride for example rollercoasters." , "recreation/theme_park", "#8eef1b" },
78 { NODE_AMENITY_COLLEGE, "College Campus/Building", "" , "education/college", "#813fdc" },
79 { NODE_AMENITY_SCHOOL, "School", "" , "education/school", "#813fdc" },
80 { NODE_AMENITY_LIBRARY, "Library", "Place to read and borrow books and magazines" , "shopping/rental/library", "#803090" },
81 { NODE_AMENITY_TOWNHALL, "Townhall", "" , "", "#408090" },
82 { NODE_AMENITY_WC, "WC/Toilets", "" , "public/toilets", "#e1d62c" },
83 { NODE_AMENITY_TELEPHONE, "Telephone", "Public telephone" , "public/telephone", "#208060" },
84 { NODE_TOURISM_ATTRACTION, "Attraction", "Something interesting" , "generic", "#005000" },
86 { NODE_HISTORIC_MUSEUM, "Museum", "A place where objects of historical, artistic, or scientific interest are exhibited, preserved or studied." , "sightseeing/museum", "#202020" },
87 { NODE_HISTORIC_CASTLE, "Castle", "Historical building or group of building used for defense by military forces, whose main structures are walls and towers." , "sightseeing/castle", "#404040" },
89 { NODE_SPORT_CENTER, "Sport Center", "" , "sports/centre", "#101080" },
90 { NODE_SPORT_STADIUM, "Sport Stadium", "" , "sports/stadium", "#101080" },
91 { NODE_SPORT_SKIING, "Skiing", "" , "sports/skiing", "#5050A0" },
92 { NODE_SPORT_SWIMMING, "Swimming", "" , "sports/swimming", "#102080" },
93 { NODE_SPORT_FOOTBALL, "Football", "" , "sports/football", "#102080" },
94 { NODE_SPORT_SOCCER, "Soccer", "" , "sports/soccer", "#102080" },
95 { NODE_SPORT_GOLF, "Golf", "" , "sports/golf", "#102080" },
96 { NODE_SPORT_TENNIS, "Tennis", "" , "sports/tennis", "#101080" },
97 { NODE_SPORT_BOWLING, "Bowling", "" , "", "#101080" },
98 { NODE_SPORT_RUGBY, "Rugby", "" , "", "#101080" },
99 { NODE_SPORT_CLIMBING, "Climbing", "" , "", "#101080" },
100 { NODE_SPORT_CYCLING, "Cycling", "" , "sports/bicycle", "#101080" },
101 { NODE_SPORT_MOTOR, "Motor sport", "" , "", "#101080" },
102 { NODE_SPORT_HOCKEY, "Hockey", "" , "", "#5050A0" },
103 { NODE_SPORT_SKATING, "Skating", "" , "", "#5050A0" },
104 { NODE_SPORT_SKATEBOARD, "Skateboard", "" , "", "#101080" },
105 { NODE_SPORT_HORSES, "Horses", "Horse riding or racing" , "sports/riding", "#101080" },
106 { NODE_SPORT_DOG, "Dog racing", "" , "", "#101080" },
107 { NODE_SPORT_BASKETBALL, "Basketball", "" , "", "#101080" },
108 { NODE_SPORT_BASEBALL, "Baseball", "" , "", "#101080" },
109 { NODE_SPORT_CANOE, "Canoe", "" , "", "#101080" },
110 { NODE_SPORT_CROQUET, "Croquet", "" , "", "#101080" },
111 { NODE_SPORT_CRICKET, "Cricket", "" , "", "#101080" },
112 { NODE_SPORT_SHOOTING, "Shooting", "Shooting range" , "", "#101080" },
113 { NODE_SPORT_PAINTBALL, "Paintball", "Run around and shoot people with paintballs" , "", "#101080" },
114 { NODE_SPORT_TABLE_TENNIS, "Table tennis", "" , "", "#101080" },
115 { NODE_SPORT_PELOTA, "Pelota", "" , "", "#101080" },
116 { NODE_SPORT_RACQUET, "Racquet", "" , "sports/racquetball", "#101080" },
117 { NODE_SPORT_BOWLS, "Lawn Bowls", "" , "", "#101080" },
118 { NODE_SPORT_ATHLETICS, "Athletics", "" , "", "#101080" },
119 { NODE_SPORT_OTHER, "Other Sports", "" , "sports/stadium", "#101077" },
121 { NODE_AMENITY_GENERIC, "Other", "Miscellaneous category for everything else." , "generic", "#002000" },
122 { NODE_POI_END, NULL, NULL }
126 poi_populate_categories(sqlite3 *db)
128 sqlite3_stmt *sql_cat;
131 sqlite3_prepare_v2(db,"insert or replace into category (cat_id, label, desc, enabled, priority, icon, color)"
132 " values (?, ?, ?, 1, ?, ?, ?)",
135 for (i=0; default_poi_categories[i].name; i++) {
136 sqlite3_bind_int(sql_cat, 1, default_poi_categories[i].type);
137 sqlite3_bind_text(sql_cat, 2, default_poi_categories[i].name, -1, SQLITE_STATIC);
138 sqlite3_bind_text(sql_cat, 3, default_poi_categories[i].desc, -1, SQLITE_STATIC);
139 sqlite3_bind_int(sql_cat, 4, default_poi_categories[i].type/100);
140 sqlite3_bind_text(sql_cat, 5, default_poi_categories[i].icon, -1, SQLITE_STATIC);
141 sqlite3_bind_text(sql_cat, 6, default_poi_categories[i].color, -1, SQLITE_STATIC);
142 if (sqlite3_step(sql_cat)==SQLITE_OK)
143 g_printf("Failed to update category: %d [%s]\n", i, default_poi_categories[i].name);
144 sqlite3_reset(sql_cat);
145 sqlite3_clear_bindings(sql_cat);
148 sqlite3_finalize(sql_cat);
154 poi_db_create(sqlite3 *db)
159 if (SQLITE_OK != sqlite3_get_table(db, "select label from poi limit 1",
160 &pszResult, &nRow, &nColumn, NULL)) {
163 g_printerr("Creating initial POI tables\n");
165 create_sql = sqlite3_mprintf
167 "(poi_id INTEGER PRIMARY KEY AUTOINCREMENT, "
175 "public int default 1, "
176 "source int default 0, "
177 "cat_id int default 900,"
178 "osm_id int default 0, "
179 "isin_c int default 0, "
180 "isin_p int default 0, "
181 "priority int default 2, "
183 "create table category (cat_id INTEGER PRIMARY KEY AUTOINCREMENT,"
188 "priority int default 2, "
191 if (SQLITE_OK != sqlite3_exec(db, create_sql, NULL, NULL, NULL)
192 && (SQLITE_OK != sqlite3_get_table(db, "select label from poi limit 1",
193 &pszResult, &nRow, &nColumn, NULL))) {
194 g_printf("%s:\n%s",_("Failed to open or create database"),sqlite3_errmsg(db));
200 sqlite3_free_table(pszResult);
203 /* Make sure default categories exists */
204 poi_populate_categories(db);
225 #define POI_BASE_SQL_FIELDS "p.lat, p.lon, p.poi_id, p.label, p.desc, p.cat_id, c.label, c.desc, c.icon, c.color, p.source, p.public, p.url, p.postal_code"
226 #define POI_MINI_SQL_FIELDS "p.lat, p.lon, p.poi_id, p.label, p.desc, p.cat_id, c.label, c.desc"
229 poi_db_prepare(sqlite3 *db)
231 /* Select POIs inside given minmax lat,lon */
232 if (sqlite3_prepare_v2(db,
235 " from poi p, category c "
236 " where p.lat between ? and ? "
237 " and p.lon between ? and ? "
238 " and c.enabled=1 and p.cat_id=c.cat_id order by c.priority limit 500",
239 -1, &poisql.select_poi, NULL)!=SQLITE_OK)
242 /* Get POI with given ID */
243 if (sqlite3_prepare_v2(db,
246 " from poi p, category c "
247 " where p.poi_id = ? "
248 " and p.cat_id=c.cat_id",
249 -1, &poisql.select_poi_by_id, NULL)!=SQLITE_OK)
252 /* Search POIs by label */
253 if (sqlite3_prepare_v2(db,
256 " from poi p, category c "
257 " where p.lat between ? and ? "
258 " and p.lon between ? and ? "
259 " and c.enabled=1 and p.cat_id = c.cat_id and (p.label like $NAME or p.postal_code like $NAME) order by p.label, c.label",
260 -1, &poisql.select_poi_search, NULL)!=SQLITE_OK)
263 /* Search POI by label and specific category */
264 if (sqlite3_prepare_v2(db,
267 " from poi p, category c "
268 " where p.lat between ? and ? "
269 " and p.lon between ? and ? "
270 " and c.enabled=1 and p.cat_id = c.cat_id and (p.label like $NAME or p.postal_code like $NAME) and c.cat_id = ? order by p.label",
271 -1, &poisql.select_poi_search_cat, NULL)!=SQLITE_OK)
274 /* Search specific category */
275 if (sqlite3_prepare_v2(db,
278 " from poi p, category c "
279 " where p.lat between ? and ? "
280 " and p.lon between ? and ? "
281 " and c.enabled=1 and p.cat_id=c.cat_id and c.cat_id=? order by p.label",
282 -1, &poisql.select_poi_by_cat, NULL)!=SQLITE_OK)
285 /* Select nearest POI */
286 if (sqlite3_prepare_v2(db,
289 " from poi p, category c "
290 " where c.enabled = 1 and p.cat_id = c.cat_id "
291 " and p.lat between $LAT-0.10 and $LAT+0.10 "
292 " and p.lon between $LON-0.10 and $LAT+0.10 "
293 " order by (($LAT - p.lat) * ($LAT - p.lat) "
294 "+ ($LON - p.lon) * ($LON - p.lon)) limit 1",
295 -1, &poisql.select_nearest_poi, NULL)!=SQLITE_OK)
299 sqlite3_prepare_v2(db, "insert into poi (lat, lon, label, desc, url, postal_code, cat_id, addtime, public, source)"
300 " values (?, ?, ?, ?, ?, ?, ?, ?, 1, ?)", -1, &poisql.insert_poi, NULL);
302 sqlite3_prepare_v2(db, "update poi set label=?, desc=?, cat_id=? where poi_id=?", -1, &poisql.update_poi, NULL);
303 /* delete from poi */
304 sqlite3_prepare_v2(db, "delete from poi where poi_id=?", -1, &poisql.delete_poi, NULL);
305 /* delete from poi by cat_id */
306 sqlite3_prepare_v2(db, "delete from poi where cat_id=?", -1, &poisql.delete_poi_by_catid, NULL);
308 /* select from category */
309 sqlite3_prepare_v2(db,
310 "select c.label, c.desc, c.enabled"
311 " from category c where c.cat_id = ?",
312 -1, &poisql.select_cat, NULL);
313 /* insert into category */
314 sqlite3_prepare_v2(db,
315 "insert into category (label, desc, enabled)"
316 " values (?, ?, ?)", -1, &poisql.insert_cat, NULL);
317 /* update category */
318 sqlite3_prepare_v2(db,
319 "update category set label = ?, desc = ?,"
320 " enabled = ? where poi_id = ?",
321 -1, &poisql.update_cat, NULL);
322 /* delete from category */
323 sqlite3_prepare_v2(db,"delete from category where cat_id = ?",
324 -1, &poisql.delete_cat, NULL);
325 /* enable category */
326 sqlite3_prepare_v2(db,
327 "update category set enabled = ?"
328 " where cat_id = ?", -1, &poisql.toggle_cat, NULL);
329 /* select all category */
330 sqlite3_prepare_v2(db,
331 "select c.cat_id, c.label, c.desc, c.enabled, c.icon, c.color,"
334 " left outer join poi p on c.cat_id = p.cat_id"
335 " group by c.cat_id, c.label, c.desc, c.enabled "
336 " order by c.priority,c.label", -1, &poisql.selall_cat, NULL);
338 /* Select quick categories */
339 sqlite3_prepare_v2(db,
340 "select c.cat_id, c.label, c.icon, c.color"
341 " from category c where c.enabled=1 "
342 " order by c.priority,c.label limit 9", -1, &poisql.select_quick_cat, NULL);
348 poi_icon_hash_clear(void)
350 #if (GLIB_CHECK_VERSION (2, 12, 0))
351 g_hash_table_remove_all(poi_icon_hash);
353 g_hash_table_foreach_remove(poi_icon_hash, gtk_true, NULL);
358 poi_deinit(sqlite3 *db)
361 g_hash_table_destroy(poi_icon_hash);
365 sqlite3_finalize(poisql.select_quick_cat);
366 sqlite3_finalize(poisql.selall_cat);
367 sqlite3_finalize(poisql.toggle_cat);
368 sqlite3_finalize(poisql.delete_cat);
369 sqlite3_finalize(poisql.update_cat);
370 sqlite3_finalize(poisql.insert_cat);
371 sqlite3_finalize(poisql.select_cat);
372 sqlite3_finalize(poisql.insert_poi);
373 sqlite3_finalize(poisql.update_poi);
374 sqlite3_finalize(poisql.delete_poi);
375 sqlite3_finalize(poisql.delete_poi_by_catid);
376 sqlite3_finalize(poisql.select_nearest_poi);
377 sqlite3_finalize(poisql.select_poi);
378 sqlite3_finalize(poisql.select_poi_search);
379 sqlite3_finalize(poisql.select_poi_search_cat);
383 poi_init(sqlite3 **db)
386 poi_icon_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
392 poi_db_create(poidb);
393 if (poi_db_prepare(poidb)==FALSE) {
394 g_printerr("Failed to prepare POI SQL statements:");
395 g_printf("SQLITE: %s\n", sqlite3_errmsg(poidb));
406 p=g_slice_new0(poi_info);
407 p->source=POI_SOURCE_USER;
408 /* XXX: Set defaults ? */
413 poi_free(poi_info *p)
422 g_free(p->postal_code);
424 g_free(p->cat_label);
427 g_slice_free(poi_info, p);
430 static GtkListStore *
431 poi_list_store_new(void) {
432 return gtk_list_store_new(ITEM_NUM_COLUMNS,
433 G_TYPE_INT, /* POI ID */
434 G_TYPE_INT, /* Category ID */
435 G_TYPE_DOUBLE, /* Latitude */
436 G_TYPE_DOUBLE, /* Longitude */
437 G_TYPE_DOUBLE, /* Dist */
438 G_TYPE_STRING, /* Lat/Lon */
439 G_TYPE_STRING, /* Label */
440 G_TYPE_STRING, /* Desc. */
441 G_TYPE_STRING, /* Category Label */
442 G_TYPE_STRING, /* Icon */
443 G_TYPE_STRING); /* Color */
446 /*************************************
447 * POI Category functions
452 poi_category_new(void)
454 return g_slice_new0(poi_category);
458 poi_category_free(poi_category *c)
464 g_slice_free(poi_category, c);
468 poi_category_toggle(guint cat_id, gboolean cat_enabled)
470 if (SQLITE_OK != sqlite3_bind_int(poisql.toggle_cat, 1, cat_enabled) ||
471 SQLITE_OK != sqlite3_bind_int(poisql.toggle_cat, 2, cat_id) ||
472 SQLITE_DONE != sqlite3_step(poisql.toggle_cat)) {
479 poi_category_get(guint cat_id, poi_category **c)
483 if (SQLITE_OK != sqlite3_bind_int(poisql.select_cat, 1, cat_id) || SQLITE_ROW != sqlite3_step(poisql.select_cat)) {
484 sqlite3_reset(poisql.select_cat);
488 cc=poi_category_new();
490 cc->label = g_strdup(sqlite3_column_text(poisql.select_cat, 0));
491 cc->desc = g_strdup(sqlite3_column_text(poisql.select_cat, 1));
492 cc->enabled = sqlite3_column_int(poisql.select_cat, 2);
494 sqlite3_reset(poisql.select_cat);
495 sqlite3_clear_bindings(poisql.select_cat);
501 poi_category_update(guint cat_id, poi_category *c)
503 gboolean results=TRUE;
510 if (SQLITE_OK != sqlite3_bind_text(poisql.update_cat, 1, c->label, -1, SQLITE_STATIC)
511 || SQLITE_OK != sqlite3_bind_text(poisql.update_cat, 2, c->desc, -1, SQLITE_STATIC)
512 || SQLITE_OK != sqlite3_bind_int(poisql.update_cat, 3, c->enabled)
513 || SQLITE_OK != sqlite3_bind_int(poisql.update_cat, 4, c->id)
514 || SQLITE_DONE != sqlite3_step(poisql.update_cat)) {
517 sqlite3_reset(poisql.update_cat);
518 sqlite3_clear_bindings(poisql.update_cat);
521 if (SQLITE_OK != sqlite3_bind_text(poisql.insert_cat, 1, c->label, -1, SQLITE_STATIC)
522 || SQLITE_OK != sqlite3_bind_text(poisql.insert_cat, 2, c->desc, -1, SQLITE_STATIC)
523 || SQLITE_OK != sqlite3_bind_int(poisql.insert_cat, 3, c->enabled)
524 || SQLITE_DONE != sqlite3_step(poisql.insert_cat)) {
527 sqlite3_reset(poisql.insert_cat);
528 sqlite3_clear_bindings(poisql.insert_cat);
534 poi_category_delete(guint id)
539 if (SQLITE_OK != sqlite3_bind_int(poisql.delete_poi_by_catid, 1, id) || SQLITE_DONE != sqlite3_step(poisql.delete_poi_by_catid)) {
540 sqlite3_reset(poisql.delete_poi_by_catid);
543 sqlite3_reset(poisql.delete_poi_by_catid);
544 sqlite3_clear_bindings(poisql.delete_poi_by_catid);
546 if (SQLITE_OK != sqlite3_bind_int(poisql.delete_cat, 1, id) || SQLITE_DONE != sqlite3_step(poisql.delete_cat)) {
547 sqlite3_reset(poisql.delete_cat);
550 sqlite3_reset(poisql.delete_cat);
551 sqlite3_clear_bindings(poisql.delete_cat);
562 if (SQLITE_OK != sqlite3_bind_int(poisql.delete_poi, 1, id) || SQLITE_DONE != sqlite3_step(poisql.delete_poi)) {
563 sqlite3_reset(poisql.delete_poi);
566 sqlite3_reset(poisql.delete_poi);
567 sqlite3_clear_bindings(poisql.delete_poi);
572 poi_search(poi_search_type pst, gdouble lat, gdouble lon, gchar *text, guint cat, GtkListStore **store)
575 sqlite3_stmt *sql=NULL;
578 gchar tmp1[16], tmp2[16];
584 g_printf("POI Search: [%s] around %.6f %.6f (%d %d)\n", text, lat, lon, cat, pst);
587 case POI_SEARCH_NEAR:
588 if (SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 1, lat-0.5) ||
589 SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 4, lon+0.5)) {
590 g_printerr("Failed to bind values for poisql.select_poi\n");
591 sqlite3_clear_bindings(poisql.select_poi);
594 sql=poisql.select_poi;
596 case POI_SEARCH_TEXT:
597 ltext=g_strdup_printf("%s%%", text);
599 if (SQLITE_OK != sqlite3_bind_text(poisql.select_poi_search, 5, ltext, -1, SQLITE_TRANSIENT)) {
600 g_printerr("Failed to bind values for poisql.select_poi_search\n");
601 sqlite3_clear_bindings(poisql.select_poi_search);
606 sql=poisql.select_poi_search;
608 case POI_SEARCH_TEXT_CAT:
609 ltext=g_strdup_printf("%s%%", text);
611 if (SQLITE_OK != sqlite3_bind_int(poisql.select_poi_search_cat, 6, cat) ||
612 SQLITE_OK != sqlite3_bind_text(poisql.select_poi_search_cat, 5, ltext, -1, SQLITE_TRANSIENT)) {
613 g_printerr("Failed to bind values for poisql.select_poi_search_cat\n");
614 sqlite3_clear_bindings(poisql.select_poi_search_cat);
619 sql=poisql.select_poi_search_cat;
622 if (SQLITE_OK != sqlite3_bind_int(poisql.select_poi_by_cat, 5, cat)) {
623 g_printerr("Failed to bind values for poisql.select_poi_by_cat\n");
624 sqlite3_clear_bindings(poisql.select_poi_by_cat);
627 sql=poisql.select_poi_by_cat;
630 g_assert_not_reached();
635 /* XXX: Use common bind for common variables */
636 if (SQLITE_OK != sqlite3_bind_double(sql, 1, lat-range) ||
637 SQLITE_OK != sqlite3_bind_double(sql, 2, lat+range) ||
638 SQLITE_OK != sqlite3_bind_double(sql, 3, lon-range) ||
639 SQLITE_OK != sqlite3_bind_double(sql, 4, lon+range)) {
640 g_printerr("Failed to bind common variables for POI search\n");
641 sqlite3_clear_bindings(sql);
645 *store = poi_list_store_new();
647 while (SQLITE_ROW == sqlite3_step(sql)) {
648 gdouble rlat, rlon, dist;
650 rlat=sqlite3_column_double(sql, 0);
651 rlon=sqlite3_column_double(sql, 1);
652 lat_format(_degformat, rlat, tmp1);
653 lon_format(_degformat, rlon, tmp2);
654 dist=calculate_distance(lat, lon, rlat, rlon) * UNITS_CONVERT[_units];
656 gtk_list_store_append(*store, &iter);
657 gtk_list_store_set(*store, &iter,
658 ITEM_ID, sqlite3_column_int(sql, 2),
659 ITEM_CATID, sqlite3_column_int(sql, 5),
663 ITEM_LATLON, g_strdup_printf("%s, %s", tmp1, tmp2),
664 ITEM_LABEL, sqlite3_column_text(sql, 3),
665 ITEM_DESC, sqlite3_column_text(sql, 4),
666 ITEM_CATLAB, sqlite3_column_text(sql, 6),
671 g_printf("Found: %d items\n", rows);
674 sqlite3_clear_bindings(sql);
680 poi_get_list_inside(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2, GtkListStore **store, guint *num_poi)
683 gchar tmp1[16], tmp2[16];
690 if (SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 1, lat1) ||
691 SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 2, lat2) ||
692 SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 3, lon1) ||
693 SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 4, lon2)) {
694 g_printerr("Failed to bind values for poisql.select_poi\n");
698 *store = poi_list_store_new();
700 while (SQLITE_ROW == sqlite3_step(poisql.select_poi)) {
701 gdouble lat, lon, dist=0;
703 lat=sqlite3_column_double(poisql.select_poi, 0);
704 lon=sqlite3_column_double(poisql.select_poi, 1);
705 lat_format(_degformat, lat, tmp1);
706 lon_format(_degformat, lon, tmp2);
708 gtk_list_store_append(*store, &iter);
709 gtk_list_store_set(*store, &iter,
710 ITEM_ID, sqlite3_column_int(poisql.select_poi, 2),
711 ITEM_CATID, sqlite3_column_int(poisql.select_poi, 5),
715 ITEM_LATLON, g_strdup_printf("%s, %s", tmp1, tmp2),
716 ITEM_LABEL, sqlite3_column_text(poisql.select_poi, 3),
717 ITEM_DESC, sqlite3_column_text(poisql.select_poi, 4),
718 ITEM_CATLAB, sqlite3_column_text(poisql.select_poi, 6),
719 ITEM_ICON, sqlite3_column_text(poisql.select_poi, 8),
720 ITEM_COLOR, sqlite3_column_text(poisql.select_poi, 9),
724 sqlite3_reset(poisql.select_poi);
725 sqlite3_clear_bindings(poisql.select_poi);
730 poi_get_list_near_unit(guint unitx, guint unity, guint range, GtkListStore **store, guint *num_poi)
732 gdouble lat1, lon1, lat2, lon2;
735 x=unitx-pixel2unit(3*range);
736 y=unity+pixel2unit(3*range);
737 unit2latlon(x, y, lat1, lon1);
739 x=unitx+pixel2unit(3*range);
740 y=unity-pixel2unit(3*range);
741 unit2latlon(x, y, lat2, lon2);
743 return poi_get_list_inside(lat1, lon1, lat2, lon2, store, num_poi);
747 poi_get_by_id(guint id)
751 if (SQLITE_OK!=sqlite3_bind_double(poisql.select_poi_by_id, 1, id))
754 if (SQLITE_ROW==sqlite3_step(poisql.select_poi_by_id)) {
756 p->poi_id=sqlite3_column_int(poisql.select_poi_by_id, PS_ID);
757 p->lat=sqlite3_column_double(poisql.select_poi_by_id, PS_LAT);
758 p->lon=sqlite3_column_double(poisql.select_poi_by_id, PS_LON);
759 p->source=sqlite3_column_int(poisql.select_poi_by_id, PS_SOURCE);
760 p->public=sqlite3_column_int(poisql.select_poi_by_id, PS_PUBLIC)==1 ? TRUE : FALSE;
761 p->label=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_LABEL));
762 p->desc=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_DESC));
763 p->url=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_URL));
764 p->postal_code=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_POSTAL_CODE));
766 p->cat_id=sqlite3_column_int(poisql.select_poi_by_id, PS_CAT_ID);
767 p->cat_label=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_CAT_LABEL));
768 p->cat_desc=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_CAT_DESC));
771 sqlite3_reset(poisql.select_poi_by_id);
772 sqlite3_clear_bindings(poisql.select_poi_by_id);
778 poi_update(poi_info *p)
786 if (SQLITE_OK != sqlite3_bind_text(poisql.update_poi, 1, p->label, -1, SQLITE_STATIC)
787 || SQLITE_OK != sqlite3_bind_text(poisql.update_poi, 2, p->desc, -1, SQLITE_STATIC)
788 || SQLITE_OK != sqlite3_bind_int(poisql.update_poi, 3, p->cat_id)
789 || SQLITE_OK != sqlite3_bind_int(poisql.update_poi, 4, p->poi_id)
790 || SQLITE_DONE != sqlite3_step(poisql.update_poi)) {
793 sqlite3_reset(poisql.update_poi);
794 sqlite3_clear_bindings(poisql.update_poi);
798 /* XXX: Add url and postal_code */
812 if (SQLITE_OK != sqlite3_bind_double(poisql.insert_poi, 1, p->lat)
813 || SQLITE_OK != sqlite3_bind_double(poisql.insert_poi, 2, p->lon)
814 || SQLITE_OK != sqlite3_bind_text(poisql.insert_poi, 3, p->label, -1, SQLITE_STATIC)
815 || SQLITE_OK != sqlite3_bind_text(poisql.insert_poi, 4, p->desc, -1, SQLITE_STATIC)
816 || SQLITE_OK != sqlite3_bind_text(poisql.insert_poi, 5, p->url, -1, SQLITE_STATIC)
817 || SQLITE_OK != sqlite3_bind_text(poisql.insert_poi, 6, p->postal_code, -1, SQLITE_STATIC)
818 || SQLITE_OK != sqlite3_bind_int(poisql.insert_poi, 7, p->cat_id)
819 || SQLITE_OK != sqlite3_bind_int(poisql.insert_poi, 8, t)
820 || SQLITE_OK != sqlite3_bind_int(poisql.insert_poi, 9, p->source)
821 || SQLITE_DONE != sqlite3_step(poisql.insert_poi)) {
822 sqlite3_reset(poisql.insert_poi);
823 sqlite3_clear_bindings(poisql.insert_poi);
826 sqlite3_reset(poisql.insert_poi);
827 sqlite3_clear_bindings(poisql.insert_poi);
832 poi_find_nearest(gdouble lat, gdouble lon)
839 sqlite3_reset(poisql.select_nearest_poi);
840 sqlite3_clear_bindings(poisql.select_nearest_poi);
842 if (SQLITE_OK == sqlite3_bind_double(poisql.select_nearest_poi, 1, lat)
843 && SQLITE_OK == sqlite3_bind_double(poisql.select_nearest_poi, 2, lon)
844 && SQLITE_ROW == sqlite3_step(poisql.select_nearest_poi)) {
847 p->lat=sqlite3_column_double(poisql.select_nearest_poi, 0);
848 p->lon=sqlite3_column_double(poisql.select_nearest_poi, 1);
849 p->poi_id=sqlite3_column_double(poisql.select_nearest_poi, 2);
850 p->label=g_strdup(sqlite3_column_text(poisql.select_nearest_poi, 3));
851 p->desc=g_strdup(sqlite3_column_text(poisql.select_nearest_poi, 4));
852 p->cat_id=sqlite3_column_double(poisql.select_nearest_poi, 5);
853 p->cat_desc=g_strdup(sqlite3_column_text(poisql.select_nearest_poi, 6));
854 sqlite3_reset(poisql.select_nearest_poi);
855 sqlite3_clear_bindings(poisql.select_nearest_poi);
862 poi_get_icon(gchar *icon, gboolean big)
866 GError *error = NULL;
874 g_snprintf(buffer, sizeof(buffer), DATADIR "/map-icons/%s.%s/%s.png",
875 theme, (big==TRUE) ? "big" : "small", icon);
877 pixbuf=g_hash_table_lookup(poi_icon_hash, buffer);
881 pixbuf=gdk_pixbuf_new_from_file(buffer, &error);
886 g_hash_table_insert(poi_icon_hash, g_strdup(buffer), pixbuf);
891 poi_category_generate_store(void)
899 store=gtk_list_store_new(CAT_NUM_COLUMNS, /* pixbuf */
907 while (SQLITE_ROW == sqlite3_step(poisql.selall_cat)) {
908 gtk_list_store_append(store, &iter);
909 gtk_list_store_set(store, &iter,
910 CAT_ID, sqlite3_column_int(poisql.selall_cat, 0),
911 CAT_ENABLED, sqlite3_column_int(poisql.selall_cat, 3),
912 CAT_LABEL, sqlite3_column_text(poisql.selall_cat, 1),
913 CAT_DESC, sqlite3_column_text(poisql.selall_cat, 2),
914 CAT_POI_CNT, sqlite3_column_int(poisql.selall_cat, 6),
915 CAT_ICON, poi_get_icon(sqlite3_column_text(poisql.selall_cat, 4),TRUE),
919 sqlite3_reset(poisql.selall_cat);
920 sqlite3_clear_bindings(poisql.selall_cat);