11 #include <glib/gstdio.h>
14 #include <gconf/gconf-client.h>
15 #include <libxml/parser.h>
24 #include "mapper-types.h"
30 #include "image-cache.h"
32 static sqlite3 *poidb;
34 /* POI Icon theme. "classic" or "square". Should be made into a configuration option */
35 static gchar *theme="square";
36 static gchar *theme_base=DATADIR "/icons/map-icons";
38 static ImageCache *poi_ic=NULL;
40 struct _poi_categories {
42 const gchar *name, *desc, *icon, *color;
45 /* The default POI categories */
46 static struct _poi_categories default_poi_categories[] = {
47 { NODE_AMENITY_PARKING, "Parking", "Parking place for vehicles." , "vehicle/parking", "#2020ff" },
48 { NODE_AMENITY_FUEL, "Fuel", "Stations for purchasing fuel for vehicles." , "vehicle/fuel_station", "#4040f0" },
49 { NODE_AMENITY_SPEEDCAM, "Speed Cam", "Automatic speed cameras." , "vehicle/restrictions/speed_trap", "#ff0000" },
50 { NODE_AMENITY_HOSPITAL, "Hospital", "Get medical help" , "health/hospital", "#ff4040" },
51 { NODE_AMENITY_PHARMACY, "Pharmacy", "Place to get drugs." , "health/pharmacy", "#40f040" },
52 { NODE_AMENITY_POLICE, "Police", "Police station" , "public/police", "#8570ff" },
53 { NODE_TOURISM_HOTEL, "Hotel", "Places to stay temporarily or for the night." , "accommodation/hotel", "#ba20ba" },
54 { NODE_TOURISM_HOSTEL, "Hostel", "Places to stay temporarily or for the night. Cheap." , "accommodation/hostel", "#ba30ba" },
55 { NODE_TOURISM_MOTEL, "Motel", "Places to stay temporarily or for the night. Cheap." , "accommodation/motel", "#ba40ba" },
56 { NODE_AMENITY_ATM, "ATM", "Automatic Teller Machine/Cashpoint." , "money/atm", "#40a040" },
57 { NODE_AMENITY_BANK, "Bank", "Place to take care of your money." , "money/bank", "#50b550" },
58 { NODE_AMENITY_POST, "Post office", "Place to handle mail." , "public/post_office", "#ff6868" },
59 { NODE_AMENITY_POST_BOX, "Post box", "Send letters." , "public/post_box", "#ff6060" },
60 { NODE_TOURISM_INFO, "Tourism info", "A place for tourists to get information." , "misc/information", "#4af04a" },
61 { NODE_AMENITY_TAXI, "Taxi station", "Get a Taxi here." , "transport/taxi", "#50ffff" },
62 { NODE_RAILWAY_STATION, "Railway station", "Transportation by train." , "transport/railway", "#fa7070" },
63 { NODE_RAILWAY_HALT, "Railway halt", "" , "transport/railway_small", "#f27777" },
64 { NODE_AMENITY_BUS_STATION, "Bus station", "Transportation by bus." , "transport/bus", "#f07070" },
65 { NODE_AMENITY_BOAT, "Harbour", "Transportation by boat." , "transport/ferry", "#9090ee" },
66 { NODE_AIRPORT_TERMINAL, "Airport", "Transportation by air." , "transport/airport", "#909099" },
67 { NODE_TOURISM_CAMP_SITE, "Camp site", "Place to go camping" , "accommodation/camping", "#90f080" },
68 { NODE_TOURISM_CARAVAN_SITE, "Caravan site", "" , "accommodation/camping/caravan", "#90ff80" },
69 { NODE_TOURISM_PICNIC_SITE, "Picnic", "Place to have a Picnic" , "recreation/picnic", "#a5f8e5" },
70 { NODE_AMENITY_FOOD, "Fast food", "Places to eat or drink." , "food/fastfood", "#e5960d" },
71 { NODE_AMENITY_RESTAURANT, "Restaurant", "Fancy places to eat or drink." , "food/restaurant", "#e5960d" },
72 { NODE_AMENITY_PUB, "Pub", "Place to drink." , "food/pub", "#f5960d" },
73 { NODE_AMENITY_NIGHTCLUB, "Disco, Club", "Place to drink, party and dance." , "food/bar", "#f59c1d" },
74 { NODE_AMENITY_CAFE, "Cafe", "Place to drink coffe or tee and eat." , "food/cafe", "#ff960d" },
75 { NODE_AMENITY_CINEMA, "Cinema", "Place to see movies" , "recreation/cinema", "#9090a0" },
76 { NODE_AMENITY_THEATRE, "Theatre", "Place to see people performing" , "recreation/theater", "#9595a5" },
77 { NODE_AMENITY_SHOP, "Shopping", "Places to shop or acquire services." , "shopping", "#61ef1b" },
78 { NODE_AMENITY_SHOP_ADULT, "Adult shop", "Shops providing adult items, such as sex toys,pornography and fetish clothing" , "", "#ff0000" },
79 { NODE_AMENITY_POW, "Place of Worchip", "" , "religion/church", "#7c5b0b" },
80 { NODE_TOURISM_THEME_PARK, "Theme Park", "Place to have fun and ride for example rollercoasters." , "recreation/theme_park", "#8eef1b" },
81 { NODE_AMENITY_COLLEGE, "College Campus/Building", "" , "education/college", "#813fdc" },
82 { NODE_AMENITY_SCHOOL, "School", "" , "education/school", "#813fdc" },
83 { NODE_AMENITY_LIBRARY, "Library", "Place to read and borrow books and magazines" , "shopping/rental/library", "#803090" },
84 { NODE_AMENITY_TOWNHALL, "Townhall", "" , "", "#408090" },
85 { NODE_AMENITY_WC, "WC/Toilets", "" , "public/toilets", "#e1d62c" },
86 { NODE_AMENITY_TELEPHONE, "Telephone", "Public telephone" , "public/telephone", "#208060" },
87 { NODE_TOURISM_ATTRACTION, "Attraction", "Something interesting" , "misc", "#005000" },
89 { NODE_HISTORIC_MUSEUM, "Museum", "A place where objects of historical, artistic, or scientific interest are exhibited, preserved or studied." , "sightseeing/museum", "#202020" },
90 { 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" },
92 { NODE_SPORT_CENTER, "Sport Center", "" , "sports/centre", "#101080" },
93 { NODE_SPORT_STADIUM, "Sport Stadium", "" , "sports/stadium", "#101080" },
94 { NODE_SPORT_SKIING, "Skiing", "" , "sports/skiing", "#5050A0" },
95 { NODE_SPORT_SWIMMING, "Swimming", "" , "sports/swimming", "#102080" },
96 { NODE_SPORT_FOOTBALL, "Football", "" , "sports/football", "#102080" },
97 { NODE_SPORT_SOCCER, "Soccer", "" , "sports/soccer", "#102080" },
98 { NODE_SPORT_GOLF, "Golf", "" , "sports/golf", "#102080" },
99 { NODE_SPORT_TENNIS, "Tennis", "" , "sports/tennis", "#101080" },
100 { NODE_SPORT_BOWLING, "Bowling", "" , "sports", "#101080" },
101 { NODE_SPORT_RUGBY, "Rugby", "" , "sports", "#101080" },
102 { NODE_SPORT_CLIMBING, "Climbing", "" , "sports", "#101080" },
103 { NODE_SPORT_CYCLING, "Cycling", "" , "sports/bicycle", "#101080" },
104 { NODE_SPORT_MOTOR, "Motor sport", "" , "sports", "#101080" },
105 { NODE_SPORT_HOCKEY, "Hockey", "" , "sports", "#5050A0" },
106 { NODE_SPORT_SKATING, "Skating", "" , "sports", "#5050A0" },
107 { NODE_SPORT_SKATEBOARD, "Skateboard", "" , "sports", "#101080" },
108 { NODE_SPORT_HORSES, "Horses", "Horse riding or racing" , "sports/riding", "#101080" },
109 { NODE_SPORT_DOG, "Dog racing", "" , "sports", "#101080" },
110 { NODE_SPORT_BASKETBALL, "Basketball", "" , "sports", "#101080" },
111 { NODE_SPORT_BASEBALL, "Baseball", "" , "sports", "#101080" },
112 { NODE_SPORT_CANOE, "Canoe", "" , "", "#101080" },
113 { NODE_SPORT_CROQUET, "Croquet", "" , "sports", "#101080" },
114 { NODE_SPORT_CRICKET, "Cricket", "" , "sports", "#101080" },
115 { NODE_SPORT_SHOOTING, "Shooting", "Shooting range" , "sports", "#101080" },
116 { NODE_SPORT_PAINTBALL, "Paintball", "Run around and shoot people with paintballs" , "sports", "#101080" },
117 { NODE_SPORT_TABLE_TENNIS, "Table tennis", "" , "sports", "#101080" },
118 { NODE_SPORT_PELOTA, "Pelota", "" , "sports", "#101080" },
119 { NODE_SPORT_RACQUET, "Racquet", "" , "sports/racquetball", "#101080" },
120 { NODE_SPORT_BOWLS, "Lawn Bowls", "" , "sports", "#101080" },
121 { NODE_SPORT_ATHLETICS, "Athletics", "" , "sports", "#101080" },
122 { NODE_SPORT_OTHER, "Other Sports", "" , "sports/stadium", "#101077" },
124 { NODE_AMENITY_GENERIC, "Other", "Miscellaneous category for everything else." , "misc", "#002000" },
125 { NODE_POI_END, NULL, NULL }
129 poi_populate_categories(sqlite3 *db)
131 sqlite3_stmt *sql_cat;
134 DB_PREP(db,"insert or replace into category (cat_id, label, desc, enabled, priority, icon, color)"
135 " values (?, ?, ?, 1, ?, ?, ?)", sql_cat);
137 for (i=0; default_poi_categories[i].name; i++) {
138 sqlite3_bind_int(sql_cat, 1, default_poi_categories[i].type);
139 sqlite3_bind_text(sql_cat, 2, default_poi_categories[i].name, -1, SQLITE_STATIC);
140 sqlite3_bind_text(sql_cat, 3, default_poi_categories[i].desc, -1, SQLITE_STATIC);
141 sqlite3_bind_int(sql_cat, 4, default_poi_categories[i].type/100);
142 sqlite3_bind_text(sql_cat, 5, default_poi_categories[i].icon, -1, SQLITE_STATIC);
143 sqlite3_bind_text(sql_cat, 6, default_poi_categories[i].color, -1, SQLITE_STATIC);
144 if (sqlite3_step(sql_cat)==SQLITE_OK)
145 g_printf("Failed to update category: %d [%s]\n", i, default_poi_categories[i].name);
146 sqlite3_reset(sql_cat);
147 sqlite3_clear_bindings(sql_cat);
150 sqlite3_finalize(sql_cat);
156 poi_get_icon_from_type(node_type_t t)
160 for (i=0; default_poi_categories[i].name; i++) {
161 if (t==default_poi_categories[i].type)
162 return default_poi_categories[i].icon;
168 poi_db_create(sqlite3 *db)
173 if (SQLITE_OK != sqlite3_get_table(db, "select label from poi limit 1", &pszResult, &nRow, &nColumn, NULL)) {
176 g_printerr("Creating initial POI tables\n");
178 create_sql = sqlite3_mprintf
180 "(poi_id INTEGER PRIMARY KEY AUTOINCREMENT, "
188 "public int default 1, "
189 "source int default 0, "
190 "cat_id int default 900,"
191 "osm_id int default 0, "
192 "isin_c int default 0, "
193 "isin_p int default 0, "
194 "priority int default 2, "
196 "create table category (cat_id INTEGER PRIMARY KEY AUTOINCREMENT,"
201 "priority int default 2, "
204 if (SQLITE_OK != sqlite3_exec(db, create_sql, NULL, NULL, NULL)
205 && (SQLITE_OK != sqlite3_get_table(db, "select label from poi limit 1",
206 &pszResult, &nRow, &nColumn, NULL))) {
207 g_printf("%s:\n%s",_("Failed to open or create database"),sqlite3_errmsg(db));
213 sqlite3_free_table(pszResult);
216 /* Make sure default categories exists */
217 poi_populate_categories(db);
238 #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"
239 #define POI_MINI_SQL_FIELDS "p.lat, p.lon, p.poi_id, p.label, p.desc, p.cat_id, c.label, c.desc"
242 poi_db_prepare(sqlite3 *db)
244 /* Select POIs inside given minmax lat,lon */
245 DB_PREP(db, "select "
247 " from poi p, category c "
248 " where p.lat between ? and ? "
249 " and p.lon between ? and ? "
250 " and c.enabled=1 and p.cat_id=c.cat_id order by c.priority limit 500",
253 /* Get POI with given ID */
254 DB_PREP(db, "select "
256 " from poi p, category c "
257 " where p.poi_id = ? "
258 " and p.cat_id=c.cat_id",
259 poisql.select_poi_by_id);
261 /* Search POIs by label and any category */
262 DB_PREP(db, "select "
264 " from poi p, category c "
265 " where p.lat between ? and ? "
266 " and p.lon between ? and ? "
267 " 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",
268 poisql.select_poi_search);
270 /* Search POI by label and category */
271 DB_PREP(db, "select "
273 " from poi p, category c "
274 " where p.lat between ? and ? "
275 " and p.lon between ? and ? "
276 " 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",
277 poisql.select_poi_search_cat);
279 /* Search POIs by category */
280 DB_PREP(db, "select "
282 " from poi p, category c "
283 " where p.lat between ? and ? "
284 " and p.lon between ? and ? "
285 " and c.enabled=1 and p.cat_id=c.cat_id and c.cat_id=? order by p.label",
286 poisql.select_poi_by_cat);
288 /* Select any nearest POI */
289 DB_PREP(db, "select "
291 " from poi p, category c "
292 " where c.enabled = 1 and p.cat_id = c.cat_id "
293 " and p.lat between $LAT-0.10 and $LAT+0.10 "
294 " and p.lon between $LON-0.10 and $LAT+0.10 "
295 " order by (($LAT - p.lat) * ($LAT - p.lat) "
296 "+ ($LON - p.lon) * ($LON - p.lon)) limit 1",
297 poisql.select_nearest_poi);
300 DB_PREP(db, "insert into poi (lat, lon, label, desc, url, postal_code, cat_id, addtime, public, source)"
301 " values (?, ?, ?, ?, ?, ?, ?, ?, 1, ?)", poisql.insert_poi);
303 DB_PREP(db, "update poi set label=?, desc=?, cat_id=? where poi_id=?", poisql.update_poi);
304 /* delete from poi */
305 DB_PREP(db, "delete from poi where poi_id=?", poisql.delete_poi);
306 /* delete from poi by cat_id */
307 DB_PREP(db, "delete from poi where cat_id=?", poisql.delete_poi_by_catid);
309 /* select from category */
310 DB_PREP(db, "select c.label, c.desc, c.enabled from category c where c.cat_id = ?", poisql.select_cat);
311 /* insert into category */
312 DB_PREP(db, "insert into category (label, desc, enabled) values (?, ?, ?)", poisql.insert_cat);
313 /* update category */
314 DB_PREP(db, "update category set label = ?, desc = ?, enabled = ? where cat_id = ?", poisql.update_cat);
315 /* delete from category */
316 DB_PREP(db,"delete from category where cat_id = ?", poisql.delete_cat);
317 /* enable category */
318 DB_PREP(db, "update category set enabled = ? where cat_id = ?", poisql.toggle_cat);
319 /* select all category */
320 DB_PREP(db, "select c.cat_id, c.label, c.desc, c.enabled, c.icon, c.color,"
323 " left outer join poi p on c.cat_id = p.cat_id"
324 " group by c.cat_id, c.label, c.desc, c.enabled "
325 " order by c.priority,c.label",
327 /* Select quick categories */
328 DB_PREP(db, "select c.cat_id, c.label, c.icon, c.color"
329 " from category c where c.enabled=1 "
330 " order by c.priority,c.label limit 9",
331 poisql.select_quick_cat);
336 poi_icon_hash_clear(void)
338 image_cache_clear(poi_ic);
342 poi_deinit(sqlite3 *db)
345 image_cache_free(poi_ic);
349 sqlite3_finalize(poisql.select_quick_cat);
350 sqlite3_finalize(poisql.selall_cat);
351 sqlite3_finalize(poisql.toggle_cat);
352 sqlite3_finalize(poisql.delete_cat);
353 sqlite3_finalize(poisql.update_cat);
354 sqlite3_finalize(poisql.insert_cat);
355 sqlite3_finalize(poisql.select_cat);
356 sqlite3_finalize(poisql.insert_poi);
357 sqlite3_finalize(poisql.update_poi);
358 sqlite3_finalize(poisql.delete_poi);
359 sqlite3_finalize(poisql.delete_poi_by_catid);
360 sqlite3_finalize(poisql.select_nearest_poi);
361 sqlite3_finalize(poisql.select_poi);
362 sqlite3_finalize(poisql.select_poi_search);
363 sqlite3_finalize(poisql.select_poi_search_cat);
367 poi_init(sqlite3 **db)
373 poi_ic=image_cache_new(128);
376 poi_db_create(poidb);
377 if (poi_db_prepare(poidb)==FALSE) {
378 g_printerr("Failed to prepare POI SQL statements:");
379 g_printf("SQLITE: %s\n", sqlite3_errmsg(poidb));
390 p=g_slice_new0(poi_info);
391 p->source=POI_SOURCE_USER;
392 /* XXX: Set defaults ? */
397 poi_free(poi_info *p)
406 g_free(p->postal_code);
408 g_free(p->cat_label);
411 g_slice_free(poi_info, p);
415 poi_list_store_new(void) {
416 return gtk_list_store_new(ITEM_NUM_COLUMNS,
417 G_TYPE_INT, /* POI ID */
418 G_TYPE_INT, /* Category ID */
419 G_TYPE_DOUBLE, /* Latitude */
420 G_TYPE_DOUBLE, /* Longitude */
421 G_TYPE_DOUBLE, /* Dist */
422 G_TYPE_STRING, /* Lat/Lon */
423 G_TYPE_STRING, /* Label */
424 G_TYPE_STRING, /* Desc. */
425 G_TYPE_STRING, /* Category Label */
426 G_TYPE_STRING, /* Icon */
427 G_TYPE_STRING); /* Color */
430 /*************************************
431 * POI Category functions
436 poi_category_new(void)
438 return g_slice_new0(poi_category);
442 poi_category_free(poi_category *c)
448 g_slice_free(poi_category, c);
452 poi_category_toggle(guint cat_id, gboolean cat_enabled)
454 g_return_val_if_fail(poisql.toggle_cat, FALSE);
456 if (SQLITE_OK != sqlite3_bind_int(poisql.toggle_cat, 1, cat_enabled) ||
457 SQLITE_OK != sqlite3_bind_int(poisql.toggle_cat, 2, cat_id) ||
458 SQLITE_DONE != sqlite3_step(poisql.toggle_cat)) {
465 poi_category_get(guint cat_id, poi_category **c)
469 g_return_val_if_fail(poisql.select_cat, FALSE);
470 if (SQLITE_OK != sqlite3_bind_int(poisql.select_cat, 1, cat_id) || SQLITE_ROW != sqlite3_step(poisql.select_cat)) {
471 sqlite3_reset(poisql.select_cat);
475 cc=poi_category_new();
477 cc->label = g_strdup(sqlite3_column_text(poisql.select_cat, 0));
478 cc->desc = g_strdup(sqlite3_column_text(poisql.select_cat, 1));
479 cc->enabled = sqlite3_column_int(poisql.select_cat, 2);
481 sqlite3_reset(poisql.select_cat);
482 sqlite3_clear_bindings(poisql.select_cat);
488 poi_category_update(guint cat_id, poi_category *c)
490 gboolean results=TRUE;
495 g_return_val_if_fail(poisql.update_cat, FALSE);
496 g_return_val_if_fail(poisql.insert_cat, FALSE);
500 if (SQLITE_OK != sqlite3_bind_text(poisql.update_cat, 1, c->label, -1, SQLITE_STATIC)
501 || SQLITE_OK != sqlite3_bind_text(poisql.update_cat, 2, c->desc, -1, SQLITE_STATIC)
502 || SQLITE_OK != sqlite3_bind_int(poisql.update_cat, 3, c->enabled)
503 || SQLITE_OK != sqlite3_bind_int(poisql.update_cat, 4, c->id)
504 || SQLITE_DONE != sqlite3_step(poisql.update_cat)) {
507 sqlite3_reset(poisql.update_cat);
508 sqlite3_clear_bindings(poisql.update_cat);
511 if (SQLITE_OK != sqlite3_bind_text(poisql.insert_cat, 1, c->label, -1, SQLITE_STATIC)
512 || SQLITE_OK != sqlite3_bind_text(poisql.insert_cat, 2, c->desc, -1, SQLITE_STATIC)
513 || SQLITE_OK != sqlite3_bind_int(poisql.insert_cat, 3, c->enabled)
514 || SQLITE_DONE != sqlite3_step(poisql.insert_cat)) {
517 sqlite3_reset(poisql.insert_cat);
518 sqlite3_clear_bindings(poisql.insert_cat);
524 poi_category_delete(guint id)
529 g_return_val_if_fail(poisql.delete_poi_by_catid, FALSE);
530 g_return_val_if_fail(poisql.delete_cat, FALSE);
532 if (SQLITE_OK != sqlite3_bind_int(poisql.delete_poi_by_catid, 1, id) || SQLITE_DONE != sqlite3_step(poisql.delete_poi_by_catid)) {
533 sqlite3_reset(poisql.delete_poi_by_catid);
536 sqlite3_reset(poisql.delete_poi_by_catid);
537 sqlite3_clear_bindings(poisql.delete_poi_by_catid);
539 if (SQLITE_OK != sqlite3_bind_int(poisql.delete_cat, 1, id) || SQLITE_DONE != sqlite3_step(poisql.delete_cat)) {
540 sqlite3_reset(poisql.delete_cat);
543 sqlite3_reset(poisql.delete_cat);
544 sqlite3_clear_bindings(poisql.delete_cat);
555 g_return_val_if_fail(poisql.delete_poi, FALSE);
557 if (SQLITE_OK != sqlite3_bind_int(poisql.delete_poi, 1, id) || SQLITE_DONE != sqlite3_step(poisql.delete_poi)) {
558 sqlite3_reset(poisql.delete_poi);
561 sqlite3_reset(poisql.delete_poi);
562 sqlite3_clear_bindings(poisql.delete_poi);
567 poi_search(poi_search_type pst, gdouble lat, gdouble lon, gchar *text, guint cat, GtkListStore *store)
570 sqlite3_stmt *sql=NULL;
573 gchar tmp1[16], tmp2[16];
579 g_return_val_if_fail(poisql.select_poi, FALSE);
580 g_return_val_if_fail(store, FALSE);
582 g_printf("POI Search: [%s] around %.6f %.6f (%d %d)\n", text, lat, lon, cat, pst);
585 case POI_SEARCH_NEAR:
586 if (SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 1, lat-0.5) ||
587 SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 4, lon+0.5)) {
588 g_printerr("Failed to bind values for poisql.select_poi\n");
589 sqlite3_clear_bindings(poisql.select_poi);
592 sql=poisql.select_poi;
594 case POI_SEARCH_TEXT:
595 ltext=g_strdup_printf("%s%%", text);
597 if (SQLITE_OK != sqlite3_bind_text(poisql.select_poi_search, 5, ltext, -1, SQLITE_TRANSIENT)) {
598 g_printerr("Failed to bind values for poisql.select_poi_search\n");
599 sqlite3_clear_bindings(poisql.select_poi_search);
604 sql=poisql.select_poi_search;
606 case POI_SEARCH_TEXT_CAT:
607 ltext=g_strdup_printf("%s%%", text);
609 if (SQLITE_OK != sqlite3_bind_int(poisql.select_poi_search_cat, 6, cat) ||
610 SQLITE_OK != sqlite3_bind_text(poisql.select_poi_search_cat, 5, ltext, -1, SQLITE_TRANSIENT)) {
611 g_printerr("Failed to bind values for poisql.select_poi_search_cat\n");
612 sqlite3_clear_bindings(poisql.select_poi_search_cat);
617 sql=poisql.select_poi_search_cat;
620 if (SQLITE_OK != sqlite3_bind_int(poisql.select_poi_by_cat, 5, cat)) {
621 g_printerr("Failed to bind values for poisql.select_poi_by_cat\n");
622 sqlite3_clear_bindings(poisql.select_poi_by_cat);
625 sql=poisql.select_poi_by_cat;
628 g_assert_not_reached();
633 /* XXX: Use common bind for common variables */
634 if (SQLITE_OK != sqlite3_bind_double(sql, 1, lat-range) ||
635 SQLITE_OK != sqlite3_bind_double(sql, 2, lat+range) ||
636 SQLITE_OK != sqlite3_bind_double(sql, 3, lon-range) ||
637 SQLITE_OK != sqlite3_bind_double(sql, 4, lon+range)) {
638 g_printerr("Failed to bind common variables for POI search\n");
639 sqlite3_clear_bindings(sql);
643 while (SQLITE_ROW == sqlite3_step(sql)) {
644 gdouble rlat, rlon, dist;
646 rlat=sqlite3_column_double(sql, 0);
647 rlon=sqlite3_column_double(sql, 1);
648 lat_format(_degformat, rlat, tmp1);
649 lon_format(_degformat, rlon, tmp2);
650 dist=calculate_distance(lat, lon, rlat, rlon) * UNITS_CONVERT[_units];
652 gtk_list_store_append(store, &iter);
653 gtk_list_store_set(store, &iter,
654 ITEM_ID, sqlite3_column_int(sql, 2),
655 ITEM_CATID, sqlite3_column_int(sql, 5),
659 ITEM_LATLON, g_strdup_printf("%s, %s", tmp1, tmp2),
660 ITEM_LABEL, sqlite3_column_text(sql, 3),
661 ITEM_DESC, sqlite3_column_text(sql, 4),
662 ITEM_CATLAB, sqlite3_column_text(sql, 6),
667 g_printf("Found: %d items\n", rows);
670 sqlite3_clear_bindings(sql);
676 poi_get_list_inside(gdouble lat1, gdouble lon1, gdouble lat2, gdouble lon2, GtkListStore *store, guint *num_poi)
678 static gboolean active=FALSE;
680 gchar tmp1[16], tmp2[16];
687 g_return_val_if_fail(poisql.select_poi, FALSE);
688 g_return_val_if_fail(store, FALSE);
694 if (SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 1, lat1) ||
695 SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 2, lat2) ||
696 SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 3, lon1) ||
697 SQLITE_OK != sqlite3_bind_double(poisql.select_poi, 4, lon2)) {
698 g_printerr("Failed to bind values for poisql.select_poi\n");
702 while (SQLITE_ROW == sqlite3_step(poisql.select_poi)) {
703 gdouble lat, lon, dist=0;
705 lat=sqlite3_column_double(poisql.select_poi, 0);
706 lon=sqlite3_column_double(poisql.select_poi, 1);
707 lat_format(_degformat, lat, tmp1);
708 lon_format(_degformat, lon, tmp2);
710 gtk_list_store_append(store, &iter);
711 gtk_list_store_set(store, &iter,
712 ITEM_ID, sqlite3_column_int(poisql.select_poi, 2),
713 ITEM_CATID, sqlite3_column_int(poisql.select_poi, 5),
717 ITEM_LATLON, g_strdup_printf("%s, %s", tmp1, tmp2),
718 ITEM_LABEL, sqlite3_column_text(poisql.select_poi, 3),
719 ITEM_DESC, sqlite3_column_text(poisql.select_poi, 4),
720 ITEM_CATLAB, sqlite3_column_text(poisql.select_poi, 6),
721 ITEM_ICON, sqlite3_column_text(poisql.select_poi, 8),
722 ITEM_COLOR, sqlite3_column_text(poisql.select_poi, 9),
726 sqlite3_reset(poisql.select_poi);
727 sqlite3_clear_bindings(poisql.select_poi);
733 poi_get_list_near(gdouble lat, gdouble lon, gfloat range, GtkListStore *store, guint *num_poi)
735 gdouble lat1, lon1, lat2, lon2;
742 return poi_get_list_inside(lat1, lon1, lat2, lon2, store, num_poi);
746 poi_get_by_id(guint id)
750 g_return_val_if_fail(poisql.select_poi_by_id, FALSE);
752 if (SQLITE_OK!=sqlite3_bind_double(poisql.select_poi_by_id, 1, id))
755 if (SQLITE_ROW==sqlite3_step(poisql.select_poi_by_id)) {
757 p->poi_id=sqlite3_column_int(poisql.select_poi_by_id, PS_ID);
758 p->lat=sqlite3_column_double(poisql.select_poi_by_id, PS_LAT);
759 p->lon=sqlite3_column_double(poisql.select_poi_by_id, PS_LON);
760 p->source=sqlite3_column_int(poisql.select_poi_by_id, PS_SOURCE);
761 p->public=sqlite3_column_int(poisql.select_poi_by_id, PS_PUBLIC)==1 ? TRUE : FALSE;
762 p->label=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_LABEL));
763 p->desc=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_DESC));
764 p->url=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_URL));
765 p->postal_code=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_POSTAL_CODE));
767 p->cat_id=sqlite3_column_int(poisql.select_poi_by_id, PS_CAT_ID);
768 p->cat_label=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_CAT_LABEL));
769 p->cat_desc=g_strdup(sqlite3_column_text(poisql.select_poi_by_id, PS_CAT_DESC));
772 sqlite3_reset(poisql.select_poi_by_id);
773 sqlite3_clear_bindings(poisql.select_poi_by_id);
779 poi_update(poi_info *p)
784 g_return_val_if_fail(poisql.update_poi, FALSE);
789 if (SQLITE_OK != sqlite3_bind_text(poisql.update_poi, 1, p->label, -1, SQLITE_STATIC)
790 || SQLITE_OK != sqlite3_bind_text(poisql.update_poi, 2, p->desc, -1, SQLITE_STATIC)
791 || SQLITE_OK != sqlite3_bind_int(poisql.update_poi, 3, p->cat_id)
792 || SQLITE_OK != sqlite3_bind_int(poisql.update_poi, 4, p->poi_id)
793 || SQLITE_DONE != sqlite3_step(poisql.update_poi)) {
796 sqlite3_reset(poisql.update_poi);
797 sqlite3_clear_bindings(poisql.update_poi);
801 /* XXX: Add url and postal_code */
810 g_return_val_if_fail(poisql.insert_poi, FALSE);
817 if (SQLITE_OK != sqlite3_bind_double(poisql.insert_poi, 1, p->lat)
818 || SQLITE_OK != sqlite3_bind_double(poisql.insert_poi, 2, p->lon)
819 || SQLITE_OK != sqlite3_bind_text(poisql.insert_poi, 3, p->label, -1, SQLITE_STATIC)
820 || SQLITE_OK != sqlite3_bind_text(poisql.insert_poi, 4, p->desc, -1, SQLITE_STATIC)
821 || SQLITE_OK != sqlite3_bind_text(poisql.insert_poi, 5, p->url, -1, SQLITE_STATIC)
822 || SQLITE_OK != sqlite3_bind_text(poisql.insert_poi, 6, p->postal_code, -1, SQLITE_STATIC)
823 || SQLITE_OK != sqlite3_bind_int(poisql.insert_poi, 7, p->cat_id)
824 || SQLITE_OK != sqlite3_bind_int(poisql.insert_poi, 8, t)
825 || SQLITE_OK != sqlite3_bind_int(poisql.insert_poi, 9, p->source)
826 || SQLITE_DONE != sqlite3_step(poisql.insert_poi)) {
827 sqlite3_reset(poisql.insert_poi);
828 sqlite3_clear_bindings(poisql.insert_poi);
831 sqlite3_reset(poisql.insert_poi);
832 sqlite3_clear_bindings(poisql.insert_poi);
837 poi_find_nearest(gdouble lat, gdouble lon)
844 g_return_val_if_fail(poisql.select_nearest_poi, FALSE);
846 sqlite3_reset(poisql.select_nearest_poi);
847 sqlite3_clear_bindings(poisql.select_nearest_poi);
849 if (SQLITE_OK == sqlite3_bind_double(poisql.select_nearest_poi, 1, lat)
850 && SQLITE_OK == sqlite3_bind_double(poisql.select_nearest_poi, 2, lon)
851 && SQLITE_ROW == sqlite3_step(poisql.select_nearest_poi)) {
854 p->lat=sqlite3_column_double(poisql.select_nearest_poi, 0);
855 p->lon=sqlite3_column_double(poisql.select_nearest_poi, 1);
856 p->poi_id=sqlite3_column_double(poisql.select_nearest_poi, 2);
857 p->label=g_strdup(sqlite3_column_text(poisql.select_nearest_poi, 3));
858 p->desc=g_strdup(sqlite3_column_text(poisql.select_nearest_poi, 4));
859 p->cat_id=sqlite3_column_double(poisql.select_nearest_poi, 5);
860 p->cat_desc=g_strdup(sqlite3_column_text(poisql.select_nearest_poi, 6));
861 sqlite3_reset(poisql.select_nearest_poi);
862 sqlite3_clear_bindings(poisql.select_nearest_poi);
869 poi_get_icon(const gchar *icon, gboolean big)
880 g_snprintf(buffer, sizeof(buffer), "%s/%s.%s/%s.png", theme_base, theme, (big==TRUE) ? "big" : "small", icon);
881 g_snprintf(key, sizeof(key), "%s:%s:%s", theme, (big==TRUE) ? "big" : "small", icon);
883 return image_cache_get(poi_ic, key, buffer);
887 poi_category_generate_store(void)
895 g_return_val_if_fail(poisql.selall_cat, FALSE);
897 store=gtk_list_store_new(CAT_NUM_COLUMNS, /* pixbuf */
905 while (SQLITE_ROW == sqlite3_step(poisql.selall_cat)) {
906 gtk_list_store_append(store, &iter);
907 gtk_list_store_set(store, &iter,
908 CAT_ID, sqlite3_column_int(poisql.selall_cat, 0),
909 CAT_ENABLED, sqlite3_column_int(poisql.selall_cat, 3),
910 CAT_LABEL, sqlite3_column_text(poisql.selall_cat, 1),
911 CAT_DESC, sqlite3_column_text(poisql.selall_cat, 2),
912 CAT_POI_CNT, sqlite3_column_int(poisql.selall_cat, 6),
913 CAT_ICON, poi_get_icon(sqlite3_column_text(poisql.selall_cat, 4),TRUE),
917 sqlite3_reset(poisql.selall_cat);
918 sqlite3_clear_bindings(poisql.selall_cat);