~leadman/foxtrotgps/translations

« back to all changes in this revision

Viewing changes to src/poi.c

  • Committer: Joshua Judson Rosen
  • Date: 2009-09-26 02:35:15 UTC
  • Revision ID: rozzin@geekspace.com-20090926023515-yxl5sg1a45gupuc8
Imported from tangogps-0.9.7 tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#ifdef HAVE_CONFIG_H
 
3
#  include <config.h>
 
4
#endif
 
5
 
 
6
#include "support.h"
 
7
#include "callbacks.h"
 
8
 
 
9
#include "globals.h"
 
10
#include "poi.h"
 
11
#include "converter.h"
 
12
#include "interface.h"
 
13
#include "util.h"
 
14
#include "tile_management.h"
 
15
 
 
16
#include <glib.h>
 
17
#include <glib/gprintf.h>
 
18
#include <stdio.h>
 
19
#include <sqlite3.h>
 
20
#include <stdlib.h>
 
21
#include <string.h>
 
22
#include <math.h>
 
23
 
 
24
#define POI_DB "poi.db"
 
25
 
 
26
GtkListStore *list_store;
 
27
 
 
28
gchar *my_strescape (const gchar *source, const gchar *exceptions);
 
29
gchar *my_strescape_back (const gchar *source,  const gchar *exceptions);
 
30
 
 
31
enum {
 
32
        COLUMN_STRING,
 
33
        COLUMN_INT,
 
34
        COLUMN_BOOLEAN,
 
35
        N_COLUMNS
 
36
};
 
37
 
 
38
 
 
39
static GtkWidget *combobox_subcat = NULL;
 
40
static gboolean new_dialog = TRUE;
 
41
 
 
42
 
 
43
 
 
44
#define POI_DB_CREATE  "CREATE TABLE poi (      \
 
45
                idmd5 TEXT, lat REAL, lon REAL, visibility REAL, cat REAL, subcat REAL, \
 
46
                keywords TEXT, desc TEXT, price_range REAL, extended_open REAL, \
 
47
                creator TEXT, bookmarked REAL, user_rating REAL, rating REAL, user_comment TEXT);"
 
48
 
 
49
 
 
50
 
 
51
double
 
52
parse_degrees(const char *s)
 
53
{
 
54
        float deg, min, sec;
 
55
        
 
56
        
 
57
        if (3 == sscanf(s, "%f %f %f", &deg, &min, &sec))
 
58
                return deg + min/60 + sec/3600;
 
59
        else if (3 == sscanf(s, "%f° %f' %f\"", &deg, &min, &sec))
 
60
                return deg + min/60 + sec/3600;
 
61
        else if (3 == sscanf(s, "%f°%f'%f\"", &deg, &min, &sec))
 
62
                return deg + min/60 + sec/3600;
 
63
                
 
64
        else if (2 == sscanf(s, "%f %f", &deg, &min))
 
65
                return deg + min/60;
 
66
        else if (2 == sscanf(s, "%f° %f'", &deg, &min))
 
67
                return deg + min/60;
 
68
        else if (2 == sscanf(s, "%f°%f'", &deg, &min))
 
69
                return deg + min/60;
 
70
                
 
71
        else if (1 == sscanf(s, "%f", &deg))
 
72
                return deg;
 
73
 
 
74
        return atof(s);
 
75
}
 
76
 
 
77
 
 
78
static int
 
79
sql_cb__poi_get(void *unused, int colc, char **colv, char **col_names)
 
80
{
 
81
        poi_t *poi = g_new0(poi_t,1);
 
82
 
 
83
        printf("*** %s(): \n",__PRETTY_FUNCTION__);
 
84
        
 
85
        poi->idmd5              = g_strdup(colv[0]);
 
86
        poi->lat_deg            = atof(colv[1]);
 
87
        poi->lon_deg            = atof(colv[2]);
 
88
        poi->visibility         = atoi(colv[3]);
 
89
        poi->category           = atoi(colv[4]);
 
90
        poi->subcategory        = atoi(colv[5]);
 
91
        poi->keywords           = g_strdup(colv[6]);
 
92
        poi->desc               = g_strdup(colv[7]);
 
93
        poi->price_range        = atoi(colv[8]);
 
94
        poi->extended_open      = atoi(colv[9]);
 
95
        
 
96
        poi_list = g_slist_prepend(poi_list, poi);
 
97
 
 
98
        return 0;
 
99
}
 
100
 
 
101
 
 
102
 
 
103
 
 
104
 
 
105
 
 
106
 
 
107
void
 
108
paint_pois()
 
109
{
 
110
        
 
111
        
 
112
        int pixel_x, pixel_y, x, y;
 
113
        float lat, lon;
 
114
        GSList *list;
 
115
        GdkColor color;
 
116
        GError  *error = NULL;
 
117
        static GdkPixbuf *photo_icon = NULL;
 
118
        static GdkGC *gc;
 
119
        
 
120
        printf("*** %s(): \n",__PRETTY_FUNCTION__);
 
121
 
 
122
        if (!gc)
 
123
                gc = gdk_gc_new(pixmap); 
 
124
        color.green = 0;
 
125
        color.blue = 60000;
 
126
        color.red = 0;
 
127
        gdk_gc_set_rgb_fg_color(gc, &color);
 
128
        
 
129
 
 
130
        if(!photo_icon)
 
131
        {
 
132
                photo_icon = gdk_pixbuf_new_from_file_at_size (
 
133
                        PACKAGE_PIXMAPS_DIR "/tangogps-poi.png", 25,25,
 
134
                        &error);
 
135
        }
 
136
 
 
137
        if(global_show_pois)
 
138
        {
 
139
                get_pois();
 
140
                
 
141
                for(list = poi_list; list != NULL; list = list->next)
 
142
                {
 
143
                        poi_t *p = list->data;
 
144
                
 
145
                        lat = deg2rad(p->lat_deg);
 
146
                        lon = deg2rad(p->lon_deg);
 
147
                        
 
148
                        
 
149
                        
 
150
                        pixel_x = lon2pixel(global_zoom, lon);
 
151
                        pixel_y = lat2pixel(global_zoom, lat);
 
152
                        
 
153
                        x = pixel_x - global_x;
 
154
                        y = pixel_y - global_y;
 
155
                        
 
156
                        p->screen_x = x;
 
157
                        p->screen_y = y;
 
158
                        
 
159
                        
 
160
                        
 
161
                        if(!photo_icon)
 
162
                        {
 
163
                                gdk_draw_arc (
 
164
                                        pixmap,
 
165
                                        
 
166
                                        gc,
 
167
                                        TRUE,                   
 
168
                                        x-4, y-4,               
 
169
                                        8,8,                    
 
170
                                        0,23040);               
 
171
                        }
 
172
                        else
 
173
                        {
 
174
                                gdk_draw_pixbuf (
 
175
                                        pixmap,
 
176
                                        NULL,
 
177
                                        photo_icon,
 
178
                                        0,0,
 
179
                                        x-12,y-12,
 
180
                                        24,24,
 
181
                                        GDK_RGB_DITHER_NONE, 0, 0);
 
182
                                
 
183
                        }
 
184
                        
 
185
                        gtk_widget_queue_draw_area (
 
186
                                        map_drawable, 
 
187
                                        x-12, y-12,
 
188
                                        24,24);
 
189
                        
 
190
                        printf("POI: %s lat %f - lon %f\n",p->keywords,p->lat_deg, p->lon_deg);
 
191
                }
 
192
        }
 
193
}
 
194
 
 
195
 
 
196
 
 
197
 
 
198
GtkListStore *
 
199
create_combobox_list_store(char *list)
 
200
{
 
201
        GtkListStore    *list_store;
 
202
        GtkTreeIter     iter;
 
203
        int             i=0;
 
204
        char            **array;
 
205
        
 
206
        list_store = gtk_list_store_new (N_COLUMNS,
 
207
                                   G_TYPE_STRING,
 
208
                                   G_TYPE_INT,
 
209
                                   G_TYPE_BOOLEAN);
 
210
 
 
211
        array = g_strsplit(list,"|",-1);
 
212
        
 
213
        while(array[i])
 
214
        {               
 
215
                
 
216
                
 
217
                gtk_list_store_append (list_store, &iter);
 
218
                gtk_list_store_set (list_store, &iter,
 
219
                                  COLUMN_STRING, array[i],
 
220
                                  COLUMN_INT, i,
 
221
                                  COLUMN_BOOLEAN,  FALSE,
 
222
                                  -1);
 
223
                
 
224
                i++;
 
225
        }
 
226
        
 
227
        g_strfreev(array);
 
228
        return list_store;
 
229
}       
 
230
 
 
231
 
 
232
 
 
233
void
 
234
on_combobox_subcat_changed                   (GtkComboBox     *combobox,
 
235
                                        gpointer         user_data)
 
236
{
 
237
        
 
238
        
 
239
        
 
240
        GtkTreeIter iter;
 
241
        gchar *str_data;
 
242
        gint   int_data;
 
243
        
 
244
        printf("*** %s(): \n",__PRETTY_FUNCTION__);
 
245
        
 
246
        gtk_combo_box_get_active_iter(combobox, &iter);
 
247
        
 
248
        gtk_tree_model_get (GTK_TREE_MODEL(list_store), &iter, 
 
249
                          COLUMN_STRING, &str_data,
 
250
                          COLUMN_INT, &int_data,
 
251
                          -1);
 
252
        printf("Entry: (%s,%d)\n", str_data, int_data);
 
253
}
 
254
 
 
255
 
 
256
void set_combobox_subcat(GtkWidget *widget, int choice)
 
257
{
 
258
        
 
259
        GtkCellRenderer *renderer;
 
260
        GtkWidget *vbox;
 
261
        char *subcat_lists[15];
 
262
                printf("*** %s(): \n",__PRETTY_FUNCTION__);
 
263
 
 
264
        subcat_lists[0] = "---"; 
 
265
        subcat_lists[1] = "- Please choose -|Hotel|Motel|B&B|Hostel|Camping";
 
266
        subcat_lists[2] = "- Please choose -|Bank / Exchange / ATM|Post Office|Real Estate Agency|Travel Agency|Other";
 
267
        subcat_lists[3] = "- Please choose -|Parking|Gas Station|Repair Shop|Rental|Sharing|Dealer|Radar - Speed Trap|My Car";
 
268
        subcat_lists[4] = "- Please choose -|Cinema|Theatre|Concert Hall|Opera|Casino";
 
269
        subcat_lists[5] = "- Please choose -|Pharmacy|Hospital|Doctor";
 
270
        subcat_lists[6] = "- Please choose -|Cafe|Pub|Lounge Bar|Club|Dancing|Internet Cafe|Wifi Hot Spot";
 
271
        subcat_lists[7] = "- Please choose -|Church|Mosque|Synagoge|Temple|Cemetary";
 
272
        subcat_lists[8] = "- Please choose -|Bus|Metro|Tram|Taxi|Train Station|Bike|Port|Airport";
 
273
        subcat_lists[9] = "- Please choose -|Local Food|European|Asian|American|African|Pizza|Fast Food|Take Away|Barbeque|Italian|Mexican|Indian|Japanese|French";
 
274
        subcat_lists[10] = "- Please choose -|Wifi Hotspot|ATM-Money Dispenser|Post Office/Letter Box|Laundry|Hairdresser|Other";
 
275
        subcat_lists[11] = "- Please choose -|Tourist Info|Monument|Museum|Zoo|Viewpoint|Relief Map|Other";
 
276
        subcat_lists[12] = "- Please choose -|Supermarket|Shopping Center|Clothes|Shoes|Food|Baker|Butcher|DoItYourself|Other";
 
277
        subcat_lists[13] = "- Please choose -|Arena/Stadium|Swimming Pool|Freeclimbing|Ice Skating|Golf|Geo Cache|Other";
 
278
        subcat_lists[14] = "- Please choose -|Friend|Other Cool Place";
 
279
 
 
280
        vbox = lookup_widget(widget, "vbox28");
 
281
        list_store = create_combobox_list_store(subcat_lists[choice]);
 
282
        
 
283
        
 
284
        if((!combobox_subcat || new_dialog ) && choice)
 
285
        {
 
286
                combobox_subcat = gtk_combo_box_new_with_model (GTK_TREE_MODEL(list_store));
 
287
                gtk_widget_show (combobox_subcat);
 
288
                gtk_box_pack_start (GTK_BOX (vbox),combobox_subcat, FALSE, TRUE, 0);
 
289
                renderer = gtk_cell_renderer_text_new();
 
290
                gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combobox_subcat), renderer, TRUE);
 
291
                gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combobox_subcat), renderer, "text", 0, NULL);
 
292
                g_signal_connect ((gpointer) combobox_subcat, "changed",
 
293
                                        G_CALLBACK (on_combobox_subcat_changed),
 
294
                                        NULL);
 
295
                gtk_combo_box_set_active(GTK_COMBO_BOX(combobox_subcat), 0);
 
296
                printf("reorder\n");
 
297
                gtk_box_reorder_child(GTK_BOX(vbox),combobox_subcat,4);
 
298
                new_dialog = FALSE;
 
299
        }
 
300
        else if (choice)
 
301
        {
 
302
                gtk_combo_box_set_model(GTK_COMBO_BOX(combobox_subcat), GTK_TREE_MODEL(list_store));
 
303
                gtk_combo_box_set_active(GTK_COMBO_BOX(combobox_subcat), 0);
 
304
        }
 
305
        
 
306
 
 
307
}
 
308
 
 
309
 
 
310
void
 
311
on_combobox_cat_changed(GtkComboBox     *combobox)
 
312
{
 
313
        int choice;
 
314
                printf("*** %s(): \n",__PRETTY_FUNCTION__);
 
315
 
 
316
        
 
317
        choice = gtk_combo_box_get_active(combobox);
 
318
        
 
319
        
 
320
        set_combobox_subcat(GTK_WIDGET(combobox),choice);
 
321
        
 
322
}
 
323
 
 
324
 
 
325
void
 
326
show_window6()
 
327
{
 
328
        GtkWidget *dialog;
 
329
        GtkWidget *entry14, *entry15, *combobox2;
 
330
 
 
331
        double lat, lon, lat_deg, lon_deg;
 
332
        char buf[64];
 
333
 
 
334
        printf("*** %s(): \n",__PRETTY_FUNCTION__);
 
335
        dialog = create_window6();
 
336
        gtk_widget_show(dialog);
 
337
        new_dialog = TRUE;
 
338
        
 
339
        
 
340
        lat = pixel2lat(global_zoom, global_y+mouse_y);
 
341
        lon = pixel2lon(global_zoom, global_x+mouse_x);
 
342
        lat_deg = rad2deg(lat);
 
343
        lon_deg = rad2deg(lon);
 
344
        entry14 = lookup_widget(dialog, "entry14");
 
345
        entry15 = lookup_widget(dialog, "entry15");
 
346
        
 
347
        g_sprintf(buf, "%f", lat_deg);
 
348
        gtk_entry_set_text(GTK_ENTRY(entry14), buf);
 
349
        g_sprintf(buf, "%f", lon_deg);
 
350
        gtk_entry_set_text(GTK_ENTRY(entry15), buf);
 
351
        
 
352
        
 
353
        combobox2 = lookup_widget(dialog, "combobox2");
 
354
        gtk_combo_box_set_active(GTK_COMBO_BOX(combobox2), 0);
 
355
 
 
356
}
 
357
 
 
358
 
 
359
 
 
360
void
 
361
set_poi(GtkWidget *dialog)
 
362
{
 
363
        GtkComboBox *combo_box;
 
364
        GtkTextView *text_view;
 
365
        GtkTextBuffer *buffer;
 
366
        GtkTextIter start, end;
 
367
        GtkWidget *entry, *radiobutton;
 
368
 
 
369
        const char *keyword_raw;
 
370
        char *desc, *desc_raw, *keyword;
 
371
        char *sql;
 
372
        char *db;
 
373
        int visibility, price_range = 0, extended_open;
 
374
        int category, subcategory;
 
375
        double lat_deg, lon_deg;
 
376
        int res;
 
377
        double rand1, rand2;
 
378
 
 
379
        printf("*** %s(): \n",__PRETTY_FUNCTION__);
 
380
 
 
381
        entry = lookup_widget(dialog, "entry14");
 
382
        
 
383
        lat_deg = parse_degrees(gtk_entry_get_text(GTK_ENTRY(entry)));
 
384
        entry = lookup_widget(dialog, "entry15");
 
385
        
 
386
        lon_deg = parse_degrees(gtk_entry_get_text(GTK_ENTRY(entry)));
 
387
        radiobutton = lookup_widget(dialog, "radiobutton11");
 
388
        visibility = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radiobutton))) ? 1 : 0;    
 
389
        combo_box = GTK_COMBO_BOX(lookup_widget(dialog, "combobox2"));
 
390
        category = gtk_combo_box_get_active(combo_box);
 
391
        subcategory = gtk_combo_box_get_active(GTK_COMBO_BOX(combobox_subcat));
 
392
        entry = lookup_widget(dialog, "entry13");
 
393
        keyword_raw = gtk_entry_get_text(GTK_ENTRY(entry));
 
394
        keyword = my_strescape(keyword_raw, NULL);
 
395
        text_view = GTK_TEXT_VIEW(lookup_widget(dialog, "textview1"));
 
396
        buffer = gtk_text_view_get_buffer(text_view);
 
397
        gtk_text_buffer_get_start_iter (buffer, &start);
 
398
        gtk_text_buffer_get_end_iter (buffer, &end);
 
399
        desc_raw = gtk_text_buffer_get_text(buffer, &start, &end, TRUE);
 
400
        desc = my_strescape(desc_raw, NULL);
 
401
        radiobutton = lookup_widget(dialog, "radiobutton8");
 
402
        price_range = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radiobutton))) ? 1 : price_range;
 
403
        radiobutton = lookup_widget(dialog, "radiobutton9");
 
404
        price_range = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radiobutton))) ? 3 : price_range;
 
405
        radiobutton = lookup_widget(dialog, "radiobutton10");
 
406
        price_range = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radiobutton))) ? 5 : price_range;
 
407
        radiobutton = lookup_widget(dialog, "checkbutton10");
 
408
        extended_open = (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radiobutton))) ? 1 : 0;
 
409
 
 
410
        
 
411
        rand1 = g_random_double_range (100000000,1000000000);
 
412
        rand2 = g_random_double_range (100000000,1000000000);
 
413
 
 
414
        
 
415
        db = g_strconcat(tangogps_dir, "/", POI_DB, NULL);      
 
416
        
 
417
        sql = g_strdup_printf(  
 
418
                        "INSERT INTO poi "
 
419
                        "(idmd5, lat, lon, visibility, cat, subcat, keywords, desc, price_range, extended_open) "
 
420
                        "VALUES ('%.0f%.0f',%f,%f,%d,%d,%d,'%s','%s',%d,%d)",
 
421
                        rand1, rand2, lat_deg, lon_deg, visibility, category, subcategory, 
 
422
                        keyword, desc, price_range, extended_open);
 
423
                  
 
424
printf("SQL: %s\n",sql);
 
425
printf("size of gdouble: %d",sizeof(double));
 
426
 
 
427
        res = sql_execute(db, sql, NULL);
 
428
        
 
429
        if(res==1)
 
430
        {
 
431
                sql_execute(db, POI_DB_CREATE, NULL);
 
432
                sql_execute(db, sql, NULL);
 
433
        }
 
434
 
 
435
        g_free(desc);
 
436
        g_free(desc_raw);
 
437
        g_free(sql);
 
438
        gtk_widget_destroy(dialog);
 
439
        
 
440
        
 
441
        global_poi_cat = category;
 
442
}
 
443
 
 
444
 
 
445
void
 
446
update_poi(GtkWidget *dialog)
 
447
{
 
448
 
 
449
        GtkTextView *text_view;
 
450
        GtkTextBuffer *buffer;
 
451
        GtkTextIter start, end;
 
452
        GtkWidget *entry, *widget; 
 
453
 
 
454
        const char *keyword_raw, *idmd5;
 
455
        char *desc, *desc_raw, *keyword;
 
456
        char *sql;
 
457
        char *db;
 
458
 
 
459
 
 
460
        double lat_deg, lon_deg;
 
461
        int res;
 
462
        
 
463
 
 
464
        printf("*** %s(): \n",__PRETTY_FUNCTION__);
 
465
 
 
466
        
 
467
        widget = lookup_widget(dialog, "label126");
 
468
        idmd5 = gtk_label_get_text(GTK_LABEL(widget));
 
469
        
 
470
        entry = lookup_widget(dialog, "entry17");
 
471
        
 
472
        lat_deg = parse_degrees(gtk_entry_get_text(GTK_ENTRY(entry)));
 
473
        entry = lookup_widget(dialog, "entry18");
 
474
        
 
475
        lon_deg = parse_degrees(gtk_entry_get_text(GTK_ENTRY(entry)));
 
476
 
 
477
 
 
478
 
 
479
        
 
480
 
 
481
 
 
482
 
 
483
        entry = lookup_widget(dialog, "entry19");
 
484
        keyword_raw = gtk_entry_get_text(GTK_ENTRY(entry));
 
485
        keyword = my_strescape(keyword_raw, NULL);
 
486
        text_view = GTK_TEXT_VIEW(lookup_widget(dialog, "textview2"));
 
487
        buffer = gtk_text_view_get_buffer(text_view);
 
488
        gtk_text_buffer_get_start_iter (buffer, &start);
 
489
        gtk_text_buffer_get_end_iter (buffer, &end);
 
490
        desc_raw = gtk_text_buffer_get_text(buffer, &start, &end, TRUE);
 
491
        desc = my_strescape(desc_raw, NULL);
 
492
 
 
493
 
 
494
        db = g_strconcat(tangogps_dir, "/", POI_DB, NULL);      
 
495
        
 
496
 
 
497
 
 
498
        sql = g_strdup_printf(  
 
499
                        "UPDATE "
 
500
                                "poi "
 
501
                        "SET "
 
502
                                "lat=%f,"
 
503
                                "lon=%f,"
 
504
                                "keywords='%s',"
 
505
                                "desc='%s'"
 
506
                        "WHERE "
 
507
                                "idmd5='%s'" 
 
508
                        ,
 
509
                        lat_deg, lon_deg, 
 
510
                        keyword, desc, idmd5);
 
511
 
 
512
 
 
513
printf("SQL: %s\n",sql);
 
514
 
 
515
        res = sql_execute(db, sql, NULL);
 
516
        
 
517
        if(res==1)
 
518
        {
 
519
                sql_execute(db, POI_DB_CREATE, NULL);
 
520
                sql_execute(db, sql, NULL);
 
521
        }
 
522
 
 
523
        g_free(desc);
 
524
        g_free(desc_raw);
 
525
        g_free(sql);
 
526
        
 
527
        gtk_widget_destroy(dialog);
 
528
        
 
529
        
 
530
 
 
531
}
 
532
 
 
533
 
 
534
 
 
535
 
 
536
 
 
537
void
 
538
delete_poi(poi_t *p)
 
539
{
 
540
        char *db;
 
541
        char *sql;
 
542
        int res;
 
543
 
 
544
        printf("*** %s(): \n",__PRETTY_FUNCTION__);
 
545
 
 
546
        
 
547
 
 
548
        db = g_strconcat(tangogps_dir, "/", POI_DB, NULL);      
 
549
        
 
550
        sql = g_strdup_printf(  
 
551
                        "DELETE FROM "
 
552
                                "poi "
 
553
                        "WHERE "
 
554
                                "idmd5='%s'" 
 
555
                        , p->idmd5);
 
556
 
 
557
printf("SQL: %s\n",sql);
 
558
 
 
559
        res = sql_execute(db, sql, NULL);
 
560
        
 
561
 
 
562
        repaint_all();
 
563
 
 
564
        
 
565
        
 
566
}
 
567
 
 
568
 
 
569
 
 
570
 
 
571
 
 
572
void
 
573
get_pois()
 
574
{
 
575
        char sql[256];
 
576
        char *db;
 
577
        bbox_t bbox;
 
578
                
 
579
        printf("*** %s(): \n",__PRETTY_FUNCTION__);
 
580
 
 
581
        bbox = get_bbox_deg();
 
582
 
 
583
        db = g_strconcat(tangogps_dir, "/", POI_DB, NULL);
 
584
 
 
585
        
 
586
        if(poi_list) g_slist_free(poi_list);
 
587
        poi_list = NULL;
 
588
        
 
589
        
 
590
        
 
591
        if(global_poi_cat==0)
 
592
        {
 
593
                g_snprintf(sql, 256, 
 
594
                                "SELECT * FROM poi "
 
595
                                "WHERE lat<%f AND lat>%f AND lon>%f AND lon<%f "
 
596
                                "LIMIT 1000;",
 
597
                                bbox.lat1,bbox.lat2,
 
598
                                bbox.lon1, bbox.lon2
 
599
                                );
 
600
                printf("%s \n",sql);
 
601
        }
 
602
        else if(global_poi_cat>=1)
 
603
        {
 
604
 
 
605
                g_snprintf(sql, 256, 
 
606
                                "SELECT * FROM poi "
 
607
                                "WHERE  cat=%d AND lat<%f AND lat>%f AND lon>%f AND lon<%f "
 
608
                                "LIMIT 1000;",
 
609
                                global_poi_cat,
 
610
                                bbox.lat1,bbox.lat2,
 
611
                                bbox.lon1, bbox.lon2
 
612
                                );              
 
613
                
 
614
        }
 
615
        
 
616
 
 
617
 
 
618
        
 
619
        if(poi_list)
 
620
        {
 
621
                g_slist_free(poi_list);
 
622
                poi_list = NULL;
 
623
        }
 
624
        sql_execute(db, sql, sql_cb__poi_get);  
 
625
        
 
626
        
 
627
        global_show_pois = TRUE;
 
628
        
 
629
}
 
630
 
 
631
void
 
632
show_poi_detail()
 
633
{
 
634
        GtkWidget *window, *widget;
 
635
        GtkWidget *label;
 
636
        GSList *list;
 
637
        gchar *buffer = NULL, *buffer2 = NULL;
 
638
        gboolean poi_found = FALSE;
 
639
        float lat, lon,lat_deg,lon_deg;
 
640
        float distance=0;
 
641
        waypoint_t *wp = g_new0(waypoint_t, 1);
 
642
        poi_t *p, *this_poi = NULL;
 
643
        
 
644
        window = create_window5();
 
645
        
 
646
        printf("screen x,y: %d %d \n",mouse_x, mouse_y);
 
647
        lat = pixel2lat(global_zoom, global_y+mouse_y);
 
648
        lon = pixel2lon(global_zoom, global_x+mouse_x);
 
649
        
 
650
 
 
651
        
 
652
        lat_deg = rad2deg(lat);
 
653
        lon_deg = rad2deg(lon);
 
654
        printf ("##### Lonitude: %f %f - %f %f \n", lat, lon, lat_deg, lon_deg);
 
655
        
 
656
        
 
657
        if(gpsdata !=NULL && !global_myposition.lat && !global_myposition.lon)
 
658
        {
 
659
                distance =      6371.0 *  
 
660
                                acos(sin(deg2rad(gpsdata->fix.latitude)) * 
 
661
                                sin(lat) +
 
662
                
 
663
                                cos(deg2rad(gpsdata->fix.latitude)) * 
 
664
                                cos(lat) * 
 
665
                                cos(lon - deg2rad(gpsdata->fix.longitude)) );
 
666
        }
 
667
        else if(global_myposition.lat && global_myposition.lon)
 
668
        {
 
669
                distance =      6371.0 *  
 
670
                                acos(sin(deg2rad(global_myposition.lat)) * 
 
671
                                sin(lat) +
 
672
                
 
673
                                cos(deg2rad(global_myposition.lat)) * 
 
674
                                cos(lat) * 
 
675
                                cos(lon - deg2rad(global_myposition.lon)) );
 
676
                                
 
677
        }
 
678
        
 
679
        printf("*** %s(): \n",__PRETTY_FUNCTION__);
 
680
 
 
681
 
 
682
 
 
683
        
 
684
        label = lookup_widget(window,"label110");
 
685
        
 
686
        
 
687
 
 
688
        
 
689
        
 
690
        
 
691
        for(list = poi_list; list != NULL; list = list->next)
 
692
        {
 
693
                p = list->data;
 
694
                printf("\n\nPIXEL POI: %d %d   \n\n",p->screen_x,p->screen_y);
 
695
                
 
696
                if(abs(p->screen_x - mouse_x) < 12 &&
 
697
                   abs(p->screen_y - mouse_y) < 12 )
 
698
                   
 
699
                {
 
700
                        
 
701
                        printf("FOUND POI X: %d %d %s\n",p->screen_x, mouse_x, 
 
702
                                my_strescape_back(p->keywords,NULL));
 
703
        
 
704
                        
 
705
                        buffer = g_strdup_printf( 
 
706
                                "<b>%s</b> ",
 
707
                                my_strescape_back(p->keywords,NULL));
 
708
                        buffer2 = g_strdup_printf("%s \n\nDistance: %.3fkm ",
 
709
                                my_strescape_back(p->desc,NULL), distance);
 
710
printf("%s %s \n",buffer, buffer2);                     
 
711
                        poi_found = TRUE;
 
712
                        
 
713
                        wp->lat = deg2rad(p->lat_deg);
 
714
                        wp->lon = deg2rad(p->lon_deg);
 
715
                        
 
716
                        this_poi = list->data;
 
717
                }
 
718
        
 
719
        }
 
720
        
 
721
        if(!poi_found)
 
722
                g_sprintf(buffer, "<b>No POI found</b>\n");
 
723
        
 
724
        gtk_label_set_label(GTK_LABEL(label),buffer);
 
725
        
 
726
        label = lookup_widget(window,"label111");
 
727
        gtk_label_set_label(GTK_LABEL(label), buffer2);
 
728
 
 
729
        widget = lookup_widget(window, "button27");
 
730
        g_signal_connect (      (gpointer) widget, "clicked",
 
731
                                G_CALLBACK (on_button27_clicked),
 
732
                                (gpointer) wp);
 
733
        
 
734
        if (this_poi != NULL)
 
735
        {
 
736
                this_poi->widget = window;
 
737
 
 
738
                widget = lookup_widget(window, "button33");
 
739
                g_signal_connect (      (gpointer) widget, "clicked",
 
740
                                        G_CALLBACK (on_button33_clicked),
 
741
                                        (gpointer) this_poi);
 
742
                
 
743
                widget = lookup_widget(window, "button34");
 
744
                g_signal_connect (      (gpointer) widget, "clicked",
 
745
                                        G_CALLBACK (on_button34_clicked),
 
746
                                        (gpointer) this_poi);
 
747
        }
 
748
        
 
749
        gtk_widget_show(window);
 
750
        
 
751
 
 
752
}
 
753
 
 
754
gchar *
 
755
my_strescape (const gchar *source,
 
756
             const gchar *exceptions)
 
757
{
 
758
  const guchar *p;
 
759
  gchar *dest;
 
760
  gchar *q;
 
761
  guchar excmap[256];
 
762
 
 
763
  g_return_val_if_fail (source != NULL, NULL);
 
764
 
 
765
  p = (guchar *) source;
 
766
  
 
767
  q = dest = g_malloc (strlen (source) * 4 + 1);
 
768
 
 
769
  memset (excmap, 0, 256);
 
770
  if (exceptions)
 
771
    {
 
772
      guchar *e = (guchar *) exceptions;
 
773
 
 
774
      while (*e)
 
775
        {
 
776
          excmap[*e] = 1;
 
777
          e++;
 
778
        }
 
779
    }
 
780
 
 
781
  while (*p)
 
782
    {
 
783
      if (excmap[*p])
 
784
        *q++ = *p;
 
785
      else
 
786
        {
 
787
          switch (*p)
 
788
            {
 
789
            case '"':
 
790
              
 
791
              *q++ = '`';
 
792
              break;
 
793
            case '\'':
 
794
              
 
795
              *q++ = '`';
 
796
              break;
 
797
            default:
 
798
                *q++ = *p;
 
799
              break;
 
800
            }
 
801
        }
 
802
      p++;
 
803
    }
 
804
  *q = 0;
 
805
  return dest;
 
806
}
 
807
 
 
808
 
 
809
gchar *
 
810
my_strescape_back (const gchar *source,
 
811
             const gchar *exceptions)
 
812
{
 
813
  const guchar *p;
 
814
  gchar *dest;
 
815
  gchar *q;
 
816
  guchar excmap[256];
 
817
 
 
818
  g_return_val_if_fail (source != NULL, NULL);
 
819
 
 
820
  p = (guchar *) source;
 
821
  
 
822
  q = dest = g_malloc (strlen (source) * 4 + 1);
 
823
 
 
824
  memset (excmap, 0, 256);
 
825
  if (exceptions)
 
826
    {
 
827
      guchar *e = (guchar *) exceptions;
 
828
 
 
829
      while (*e)
 
830
        {
 
831
          excmap[*e] = 1;
 
832
          e++;
 
833
        }
 
834
    }
 
835
 
 
836
  while (*p)
 
837
    {
 
838
 
 
839
          switch (*p)
 
840
            {
 
841
 
 
842
            case '&':
 
843
                    *q++ = '&';
 
844
                *q++ = 'a';
 
845
                *q++ = 'm';
 
846
                *q++ = 'p';
 
847
                *q++ = ';';
 
848
                break;
 
849
            default:
 
850
                *q++ = *p;
 
851
              break;
 
852
            }
 
853
        
 
854
      p++;
 
855
    }
 
856
  *q = 0;
 
857
  return dest;
 
858
}