2 * Copyright (C) 2006, 2007 John Costigan.
4 * POI and GPS-Info code originally written by Cezary Jackiewicz.
6 * Default map data provided by http://www.openstreetmap.org/
8 * This file is part of Maemo Mapper.
10 * Maemo Mapper is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * Maemo Mapper is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Maemo Mapper. If not, see <http://www.gnu.org/licenses/>.
34 # include <hildon/hildon-help.h>
35 # include <hildon/hildon-note.h>
36 # include <hildon/hildon-file-chooser-dialog.h>
37 # include <hildon/hildon-number-editor.h>
38 # include <hildon/hildon-banner.h>
40 # include <osso-helplib.h>
41 # include <hildon-widgets/hildon-note.h>
42 # include <hildon-widgets/hildon-file-chooser-dialog.h>
43 # include <hildon-widgets/hildon-number-editor.h>
44 # include <hildon-widgets/hildon-banner.h>
45 # include <hildon-widgets/hildon-input-mode-hint.h>
55 #include "gdk-pixbuf-rotate.h"
61 static sqlite3 *_poi_db = NULL;
62 static sqlite3_stmt *_stmt_browse_poi = NULL;
63 static sqlite3_stmt *_stmt_browsecat_poi = NULL;
64 static sqlite3_stmt *_stmt_select_poi = NULL;
65 static sqlite3_stmt *_stmt_select_nearest_poi = NULL;
66 static sqlite3_stmt *_stmt_insert_poi = NULL;
67 static sqlite3_stmt *_stmt_update_poi = NULL;
68 static sqlite3_stmt *_stmt_delete_poi = NULL;
69 static sqlite3_stmt *_stmt_delete_poi_by_catid = NULL;
70 static sqlite3_stmt *_stmt_nextlabel_poi = NULL;
71 static sqlite3_stmt *_stmt_select_cat = NULL;
72 static sqlite3_stmt *_stmt_insert_cat = NULL;
73 static sqlite3_stmt *_stmt_update_cat = NULL;
74 static sqlite3_stmt *_stmt_delete_cat = NULL;
75 static sqlite3_stmt *_stmt_toggle_cat = NULL;
76 static sqlite3_stmt *_stmt_selall_cat = NULL;
78 typedef struct _PoiListInfo PoiListInfo;
83 GtkTreeViewColumn *select_column;
88 typedef struct _OriginToggleInfo OriginToggleInfo;
89 struct _OriginToggleInfo {
90 GtkWidget *rad_use_gps;
91 GtkWidget *rad_use_route;
92 GtkWidget *rad_use_text;
93 GtkWidget *txt_origin;
97 typedef struct _PoiCategoryEditInfo PoiCategoryEditInfo;
98 struct _PoiCategoryEditInfo
101 GtkWidget *cmb_category;
103 GtkWidget *tree_view;
106 /** Data used during action: add or edit category/poi **/
107 typedef struct _DeletePOI DeletePOI;
121 gchar *db_dirname = NULL;
122 printf("%s()\n", __PRETTY_FUNCTION__);
126 sqlite3_close(_poi_db);
130 if(!_poi_db_filename)
134 else if(NULL == (db_dirname = g_path_get_dirname(_poi_db_filename))
135 || (g_mkdir_with_parents(db_dirname, 0755), /* comma operator */
136 (SQLITE_OK != (sqlite3_open(_poi_db_filename, &_poi_db)))))
138 gchar buffer2[BUFFER_SIZE];
139 snprintf(buffer2, sizeof(buffer2),
140 "%s: %s", _("Error with POI database"),
141 sqlite3_errmsg(_poi_db));
142 sqlite3_close(_poi_db);
144 popup_error(_window, buffer2);
146 else if(SQLITE_OK != sqlite3_get_table(_poi_db,
147 "select label from poi limit 1",
148 &pszResult, &nRow, &nColumn, NULL))
150 gchar *create_sql = sqlite3_mprintf(
151 "create table poi (poi_id integer PRIMARY KEY, lat real, "
152 "lon real, label text, desc text, cat_id integer);"
153 "create table category (cat_id integer PRIMARY KEY,"
154 "label text, desc text, enabled integer);"
155 /* Add some default categories... */
156 "insert into category (label, desc, enabled) "
157 "values ('%q', '%q', 1); "
158 "insert into category (label, desc, enabled) "
159 "values ('%q', '%q', 1); "
160 "insert into category (label, desc, enabled) "
161 "values ('%q', '%q', 1); "
162 "insert into category (label, desc, enabled) "
163 "values ('%q', '%q', 1); "
164 "insert into category (label, desc, enabled) "
165 "values ('%q', '%q', 1); "
166 "insert into category (label, desc, enabled) "
167 "values ('%q', '%q', 1); "
168 "insert into category (label, desc, enabled) "
169 "values ('%q', '%q', 1); "
170 "insert into category (label, desc, enabled) "
171 "values ('%q', '%q', 1); "
172 "insert into category (label, desc, enabled) "
173 "values ('%q', '%q', 1); "
174 "insert into category (label, desc, enabled) "
175 "values ('%q', '%q', 1); "
176 "insert into category (label, desc, enabled) "
177 "values ('%q', '%q', 1); ",
178 _("Service Station"),
179 _("Stations for purchasing fuel for vehicles."),
181 _("Houses, apartments, or other residences of import."),
183 _("Places to eat or drink."),
184 _("Shopping/Services"),
185 _("Places to shop or acquire services."),
187 _("Indoor or Outdoor places to have fun."),
189 _("Bus stops, airports, train stations, etc."),
191 _("Places to stay temporarily or for the night."),
193 _("Elementary schools, college campuses, etc."),
195 _("General places of business."),
197 _("General landmarks."),
199 _("Miscellaneous category for everything else."));
201 if(SQLITE_OK != sqlite3_exec(_poi_db, create_sql, NULL, NULL, NULL)
202 && (SQLITE_OK != sqlite3_get_table(_poi_db,
203 "select label from poi limit 1",
204 &pszResult, &nRow, &nColumn, NULL)))
206 snprintf(buffer, sizeof(buffer), "%s:\n%s",
207 _("Failed to open or create database"),
208 sqlite3_errmsg(_poi_db));
209 sqlite3_close(_poi_db);
211 popup_error(_window, buffer);
215 sqlite3_free_table(pszResult);
221 /* Prepare our SQL statements. */
223 sqlite3_prepare(_poi_db,
224 "select p.poi_id, p.cat_id, p.lat, p.lon,"
225 " p.label, p.desc, c.label"
226 " from poi p inner join category c"
227 " on p.cat_id = c.cat_id"
228 " where c.enabled = 1"
229 " and p.label like $QUERY or p.desc like $QUERY"
230 " order by (($LAT - p.lat) * ($LAT - p.lat) "
231 "+ ($LON - p.lon) * ($LON - p.lon)) DESC "
233 -1, &_stmt_browse_poi, NULL);
235 /* browse poi by category */
236 sqlite3_prepare(_poi_db,
237 "select p.poi_id, p.cat_id, p.lat, p.lon,"
238 " p.label, p.desc, c.label"
239 " from poi p inner join category c"
240 " on p.cat_id = c.cat_id"
241 " where c.enabled = 1"
242 " and p.cat_id = $CATID"
243 " and ( p.label like $QUERY or p.desc like $QUERY )"
244 " order by (($LAT - p.lat) * ($LAT - p.lat) "
245 "+ ($LON - p.lon) * ($LON - p.lon)) DESC"
247 -1, &_stmt_browsecat_poi, NULL);
249 /* Prepare our SQL statements. */
250 /* select from poi */
251 sqlite3_prepare(_poi_db,
252 "select p.lat, p.lon, p.poi_id, p.label, p.desc,"
253 " p.cat_id, c.label, c.desc"
254 " from poi p inner join category c"
255 " on p.cat_id = c.cat_id"
256 " where c.enabled = 1"
257 " and p.lat between ? and ? "
258 " and p.lon between ? and ? ",
259 -1, &_stmt_select_poi, NULL);
261 /* select nearest pois */
262 sqlite3_prepare(_poi_db,
263 "select p.poi_id, p.cat_id, p.lat, p.lon,"
264 " p.label, p.desc, c.label"
265 " from poi p inner join category c"
266 " on p.cat_id = c.cat_id"
267 " where c.enabled = 1"
268 " order by (($LAT - p.lat) * ($LAT - p.lat) "
269 "+ ($LON - p.lon) * ($LON - p.lon)) limit 1",
270 -1, &_stmt_select_nearest_poi, NULL);
273 sqlite3_prepare(_poi_db,
274 "insert into poi (lat, lon, label, desc, cat_id)"
275 " values (?, ?, ?, ?, ?)",
276 -1, &_stmt_insert_poi, NULL);
278 sqlite3_prepare(_poi_db,
279 "update poi set lat = ?, lon = ?, "
280 "label = ?, desc = ?, cat_id = ? where poi_id = ?",
281 -1, &_stmt_update_poi, NULL);
282 /* delete from poi */
283 sqlite3_prepare(_poi_db,
284 " delete from poi where poi_id = ?",
285 -1, &_stmt_delete_poi, NULL);
286 /* delete from poi by cat_id */
287 sqlite3_prepare(_poi_db,
288 "delete from poi where cat_id = ?",
289 -1, &_stmt_delete_poi_by_catid, NULL);
290 /* get next poilabel */
291 sqlite3_prepare(_poi_db,
292 "select ifnull(max(poi_id) + 1,1) from poi",
293 -1, &_stmt_nextlabel_poi, NULL);
295 /* select from category */
296 sqlite3_prepare(_poi_db,
297 "select c.label, c.desc, c.enabled"
298 " from category c where c.cat_id = ?",
299 -1, &_stmt_select_cat, NULL);
300 /* insert into category */
301 sqlite3_prepare(_poi_db,
302 "insert into category (label, desc, enabled)"
304 -1, &_stmt_insert_cat, NULL);
305 /* update category */
306 sqlite3_prepare(_poi_db,
307 "update category set label = ?, desc = ?,"
308 " enabled = ? where cat_id = ?",
309 -1, &_stmt_update_cat, NULL);
310 /* delete from category */
311 sqlite3_prepare(_poi_db,
312 "delete from category where cat_id = ?",
313 -1, &_stmt_delete_cat, NULL);
314 /* enable category */
315 sqlite3_prepare(_poi_db,
316 "update category set enabled = ?"
318 -1, &_stmt_toggle_cat, NULL);
319 /* select all category */
320 sqlite3_prepare(_poi_db,
321 "select c.cat_id, c.label, c.desc, c.enabled,"
324 " left outer join poi p on c.cat_id = p.cat_id"
325 " group by c.cat_id, c.label, c.desc, c.enabled "
327 -1, &_stmt_selall_cat, NULL);
330 _poi_enabled = _poi_db != NULL;
332 gtk_widget_set_sensitive(_menu_poi_item, _poi_enabled);
333 gtk_widget_set_sensitive(_cmenu_loc_add_poi_item, _poi_enabled);
334 gtk_widget_set_sensitive(_cmenu_loc_download_poi_item, _poi_enabled);
335 gtk_widget_set_sensitive(_cmenu_loc_browse_poi_item, _poi_enabled);
336 gtk_widget_set_sensitive(_cmenu_way_add_poi_item, _poi_enabled);
337 gtk_widget_set_sensitive(_cmenu_poi_submenu, _poi_enabled);
339 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
343 get_nearest_poi(gint unitx, gint unity, PoiInfo *poi)
345 printf("%s(%d, %d)\n", __PRETTY_FUNCTION__, unitx, unity);
348 unit2latlon(unitx, unity, lat, lon);
350 if(SQLITE_OK == sqlite3_bind_double(_stmt_select_nearest_poi, 1, lat)
351 && SQLITE_OK == sqlite3_bind_double(_stmt_select_nearest_poi, 2, lon)
352 && SQLITE_ROW == sqlite3_step(_stmt_select_nearest_poi))
354 poi->poi_id = sqlite3_column_int(_stmt_select_nearest_poi, 0);
355 poi->cat_id = sqlite3_column_int(_stmt_select_nearest_poi, 1);
356 poi->lat = sqlite3_column_double(_stmt_select_nearest_poi, 2);
357 poi->lon = sqlite3_column_double(_stmt_select_nearest_poi, 3);
358 poi->label =g_strdup(sqlite3_column_text(_stmt_select_nearest_poi, 4));
359 poi->desc = g_strdup(sqlite3_column_text(_stmt_select_nearest_poi, 5));
360 poi->clabel=g_strdup(sqlite3_column_text(_stmt_select_nearest_poi, 6));
365 sqlite3_reset(_stmt_select_nearest_poi);
366 vprintf("%s(): return %d\n", __PRETTY_FUNCTION__, result);
371 select_poi(gint unitx, gint unity, PoiInfo *poi, gboolean quick)
374 gdouble lat1, lon1, lat2, lon2;
375 static GtkWidget *dialog = NULL;
376 static GtkWidget *list = NULL;
377 static GtkWidget *sw = NULL;
378 static GtkTreeViewColumn *column = NULL;
379 static GtkCellRenderer *renderer = NULL;
380 GtkListStore *store = NULL;
382 gboolean selected = FALSE;
383 gchar tmp1[LL_FMT_LEN], tmp2[LL_FMT_LEN];
385 printf("%s()\n", __PRETTY_FUNCTION__);
387 x = unitx - pixel2unit(3 * _draw_width);
388 y = unity + pixel2unit(3 * _draw_width);
389 unit2latlon(x, y, lat1, lon1);
391 x = unitx + pixel2unit(3 * _draw_width);
392 y = unity - pixel2unit(3 * _draw_width);
393 unit2latlon(x, y, lat2, lon2);
395 if(SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 1, lat1) ||
396 SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 2, lat2) ||
397 SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 3, lon1) ||
398 SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 4, lon2))
400 g_printerr("Failed to bind values for _stmt_select_poi\n");
404 /* Initialize store. */
405 store = gtk_list_store_new(POI_NUM_COLUMNS,
406 G_TYPE_BOOLEAN,/* Selected */
407 G_TYPE_INT, /* POI ID */
408 G_TYPE_INT, /* Category ID */
409 G_TYPE_DOUBLE, /* Latitude */
410 G_TYPE_DOUBLE, /* Longitude */
411 G_TYPE_STRING, /* Lat/Lon */
412 G_TYPE_FLOAT, /* Bearing */
413 G_TYPE_FLOAT, /* Distance */
414 G_TYPE_STRING, /* POI Label */
415 G_TYPE_STRING, /* POI Desc. */
416 G_TYPE_STRING);/* Category Label */
418 while(SQLITE_ROW == sqlite3_step(_stmt_select_poi))
421 lat = sqlite3_column_double(_stmt_select_poi, 0);
422 lon = sqlite3_column_double(_stmt_select_poi, 1);
424 format_lat_lon(lat, lon, tmp1, tmp2);
425 //lat_format(lat, tmp1);
426 //lon_format(lon, tmp2);
427 gtk_list_store_append(store, &iter);
428 gtk_list_store_set(store, &iter,
429 POI_POIID, sqlite3_column_int(_stmt_select_poi, 2),
430 POI_CATID, sqlite3_column_int(_stmt_select_poi, 5),
433 POI_LATLON, g_strdup_printf("%s, %s", tmp1, tmp2),
434 POI_LABEL, sqlite3_column_text(_stmt_select_poi, 3),
435 POI_DESC, sqlite3_column_text(_stmt_select_poi, 4),
436 POI_CLABEL, sqlite3_column_text(_stmt_select_poi, 6),
440 sqlite3_reset(_stmt_select_poi);
445 g_object_unref(G_OBJECT(store));
448 MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
453 /* iter is still set to the most-recently added POI. */
454 gtk_tree_model_get(GTK_TREE_MODEL(store),
456 POI_POIID, &(poi->poi_id),
457 POI_CATID, &(poi->cat_id),
458 POI_LAT, &(poi->lat),
459 POI_LON, &(poi->lon),
460 POI_LABEL, &(poi->label),
461 POI_DESC, &(poi->desc),
462 POI_CLABEL, &(poi->clabel),
464 g_object_unref(G_OBJECT(store));
470 g_object_unref(G_OBJECT(store));
471 return get_nearest_poi(unitx, unity, poi);
475 /* There are at least 2 matching POI's - let the user select one. */
478 dialog = gtk_dialog_new_with_buttons(_("Select POI"),
479 GTK_WINDOW(_window), GTK_DIALOG_MODAL,
480 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
481 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
484 gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 300);
486 sw = gtk_scrolled_window_new (NULL, NULL);
487 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
488 GTK_SHADOW_ETCHED_IN);
489 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
491 GTK_POLICY_AUTOMATIC);
492 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
495 list = gtk_tree_view_new();
496 gtk_container_add(GTK_CONTAINER(sw), list);
498 gtk_tree_selection_set_mode(
499 gtk_tree_view_get_selection(GTK_TREE_VIEW(list)),
500 GTK_SELECTION_SINGLE);
501 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list), TRUE);
503 renderer = gtk_cell_renderer_text_new();
504 column = gtk_tree_view_column_new_with_attributes(
505 _("Location"), renderer, "text", POI_LATLON, NULL);
506 gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
508 renderer = gtk_cell_renderer_text_new();
509 column = gtk_tree_view_column_new_with_attributes(
510 _("Label"), renderer, "text", POI_LABEL, NULL);
511 gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
513 renderer = gtk_cell_renderer_text_new();
514 column = gtk_tree_view_column_new_with_attributes(
515 _("Category"), renderer, "text", POI_CLABEL, NULL);
516 gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
519 gtk_tree_view_set_model(GTK_TREE_VIEW(list), GTK_TREE_MODEL(store));
520 g_object_unref(G_OBJECT(store));
522 gtk_widget_show_all(dialog);
524 while(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog)))
526 if(gtk_tree_selection_get_selected(
527 gtk_tree_view_get_selection(GTK_TREE_VIEW(list)),
530 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
531 POI_POIID, &(poi->poi_id),
532 POI_CATID, &(poi->cat_id),
533 POI_LAT, &(poi->lat),
534 POI_LON, &(poi->lon),
535 POI_LABEL, &(poi->label),
536 POI_DESC, &(poi->desc),
537 POI_CLABEL, &(poi->clabel),
543 popup_error(dialog, _("Select one POI from the list."));
548 gtk_widget_hide(dialog);
550 vprintf("%s(): return %d\n", __PRETTY_FUNCTION__, selected);
555 category_delete(GtkWidget *widget, DeletePOI *dpoi)
560 printf("%s()\n", __PRETTY_FUNCTION__);
562 buffer = g_strdup_printf("%s\n\t%s\n%s",
563 _("Delete category?"),
565 _("WARNING: All POIs in that category will also be deleted!"));
566 confirm = hildon_note_new_confirmation(GTK_WINDOW(dpoi->dialog), buffer);
568 i = gtk_dialog_run(GTK_DIALOG(confirm));
569 gtk_widget_destroy(GTK_WIDGET(confirm));
571 if(i == GTK_RESPONSE_OK)
573 /* delete dpoi->poi_id */
574 if(SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi_by_catid, 1,
576 SQLITE_DONE != sqlite3_step(_stmt_delete_poi_by_catid))
578 MACRO_BANNER_SHOW_INFO(dpoi->dialog, _("Error deleting POI"));
579 sqlite3_reset(_stmt_delete_poi_by_catid);
582 sqlite3_reset(_stmt_delete_poi_by_catid);
584 if(SQLITE_OK != sqlite3_bind_int(_stmt_delete_cat, 1, dpoi->id) ||
585 SQLITE_DONE != sqlite3_step(_stmt_delete_cat))
587 MACRO_BANNER_SHOW_INFO(dpoi->dialog, _("Error deleting category"));
588 sqlite3_reset(_stmt_delete_cat);
591 sqlite3_reset(_stmt_delete_cat);
595 gtk_widget_destroy(confirm);
597 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
602 category_edit_dialog(GtkWidget *parent, gint cat_id)
604 gchar *cat_label = NULL, *cat_desc = NULL;
609 GtkWidget *txt_label;
611 GtkWidget *btn_delete = NULL;
612 GtkWidget *txt_scroll;
613 GtkWidget *chk_enabled;
614 GtkTextBuffer *desc_txt;
615 GtkTextIter begin, end;
616 gboolean results = TRUE;
617 DeletePOI dpoi = {NULL, NULL, 0};
618 printf("%s()\n", __PRETTY_FUNCTION__);
622 if(SQLITE_OK != sqlite3_bind_double(_stmt_select_cat, 1, cat_id) ||
623 SQLITE_ROW != sqlite3_step(_stmt_select_cat))
625 vprintf("%s(): return FALSE\n", __PRETTY_FUNCTION__);
626 sqlite3_reset(_stmt_select_cat);
630 cat_label = g_strdup(sqlite3_column_text(_stmt_select_cat, 0));
631 cat_desc = g_strdup(sqlite3_column_text(_stmt_select_cat, 1));
632 cat_enabled = sqlite3_column_int(_stmt_select_cat, 2);
634 sqlite3_reset(_stmt_select_cat);
636 dialog = gtk_dialog_new_with_buttons(_("Edit Category"),
637 GTK_WINDOW(parent), GTK_DIALOG_MODAL,
638 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
641 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
642 btn_delete = gtk_button_new_with_label(_("Delete...")));
644 dpoi.dialog = dialog;
645 dpoi.txt_label = g_strdup(cat_label);
647 dpoi.deleted = FALSE;
649 g_signal_connect(G_OBJECT(btn_delete), "clicked",
650 G_CALLBACK(category_delete), &dpoi);
652 gtk_dialog_add_button(GTK_DIALOG(dialog),
653 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
658 cat_label = g_strdup("");
660 cat_desc = g_strdup("");
662 dialog = gtk_dialog_new_with_buttons(_("Add Category"),
663 GTK_WINDOW(parent), GTK_DIALOG_MODAL,
664 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
665 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
669 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
670 table = gtk_table_new(6, 4, FALSE), TRUE, TRUE, 0);
672 gtk_table_attach(GTK_TABLE(table),
673 label = gtk_label_new(_("Label")),
674 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
675 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
676 gtk_table_attach(GTK_TABLE(table),
677 txt_label = gtk_entry_new(),
678 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 4);
680 gtk_table_attach(GTK_TABLE(table),
681 label = gtk_label_new(_("Description")),
682 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
683 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
685 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
686 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
688 gtk_table_attach(GTK_TABLE(table),
690 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
692 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
693 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
695 txt_desc = gtk_text_view_new();
696 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
698 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
699 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60);
701 desc_txt = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc));
703 gtk_table_attach(GTK_TABLE(table),
704 chk_enabled = gtk_check_button_new_with_label(
706 0, 2, 2, 3, GTK_EXPAND | GTK_FILL, 0, 2, 4);
709 gtk_entry_set_text(GTK_ENTRY(txt_label), cat_label);
712 gtk_text_buffer_set_text(desc_txt, cat_desc, -1);
715 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk_enabled),
716 (cat_enabled == 1 ? TRUE : FALSE));
723 gtk_widget_show_all(dialog);
725 while(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog)))
727 if(strlen(gtk_entry_get_text(GTK_ENTRY(txt_label))))
728 cat_label = g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_label)));
731 popup_error(dialog, _("Please specify a name for the category."));
735 gtk_text_buffer_get_iter_at_offset(desc_txt, &begin,0 );
736 gtk_text_buffer_get_end_iter (desc_txt, &end);
737 cat_desc = gtk_text_buffer_get_text(desc_txt, &begin, &end, TRUE);
739 cat_enabled = (gtk_toggle_button_get_active(
740 GTK_TOGGLE_BUTTON(chk_enabled)) ? 1 : 0);
745 if(SQLITE_OK != sqlite3_bind_text(_stmt_update_cat, 1, cat_label,
747 SQLITE_OK != sqlite3_bind_text(_stmt_update_cat, 2, cat_desc,
749 SQLITE_OK != sqlite3_bind_int(_stmt_update_cat, 3,cat_enabled)||
750 SQLITE_OK != sqlite3_bind_int(_stmt_update_cat, 4, cat_id) ||
751 SQLITE_DONE != sqlite3_step(_stmt_update_cat))
753 MACRO_BANNER_SHOW_INFO(parent,_("Error updating category"));
756 sqlite3_reset(_stmt_update_cat);
761 if(SQLITE_OK != sqlite3_bind_text(_stmt_insert_cat, 1, cat_label,
763 SQLITE_OK != sqlite3_bind_text(_stmt_insert_cat, 2, cat_desc,
765 SQLITE_OK != sqlite3_bind_int(_stmt_insert_cat, 3,cat_enabled)||
766 SQLITE_DONE != sqlite3_step(_stmt_insert_cat))
768 MACRO_BANNER_SHOW_INFO(parent, _("Error adding category"));
771 sqlite3_reset(_stmt_insert_cat);
776 g_free(dpoi.txt_label);
778 g_object_unref (desc_txt);
783 gtk_widget_hide(dialog);
785 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
790 category_toggled(GtkCellRendererToggle *cell, gchar *path, GtkListStore *data)
793 gboolean cat_enabled;
795 printf("%s()\n", __PRETTY_FUNCTION__);
797 GtkTreeModel *model = GTK_TREE_MODEL(data);
798 if( !gtk_tree_model_get_iter_from_string(model, &iter, path) )
801 gtk_tree_model_get(model, &iter,
802 CAT_ENABLED, &cat_enabled,
808 if(SQLITE_OK != sqlite3_bind_int(_stmt_toggle_cat, 1, cat_enabled) ||
809 SQLITE_OK != sqlite3_bind_int(_stmt_toggle_cat, 2, cat_id) ||
810 SQLITE_DONE != sqlite3_step(_stmt_toggle_cat))
812 MACRO_BANNER_SHOW_INFO(_window, _("Error updating Category"));
816 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
817 CAT_ENABLED, cat_enabled, -1);
821 sqlite3_reset(_stmt_toggle_cat);
823 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
831 printf("%s()\n", __PRETTY_FUNCTION__);
833 store = gtk_list_store_new(CAT_NUM_COLUMNS,
840 while(SQLITE_ROW == sqlite3_step(_stmt_selall_cat))
842 gtk_list_store_append(store, &iter);
843 gtk_list_store_set(store, &iter,
844 CAT_ID, sqlite3_column_int(_stmt_selall_cat, 0),
845 CAT_ENABLED, sqlite3_column_int(_stmt_selall_cat, 3),
846 CAT_LABEL, sqlite3_column_text(_stmt_selall_cat, 1),
847 CAT_DESC, sqlite3_column_text(_stmt_selall_cat, 2),
848 CAT_POI_CNT, sqlite3_column_int(_stmt_selall_cat, 4),
851 sqlite3_reset(_stmt_selall_cat);
853 vprintf("%s(): return %p\n", __PRETTY_FUNCTION__, store);
858 category_add(GtkWidget *widget, PoiCategoryEditInfo *pcedit)
861 printf("%s()\n", __PRETTY_FUNCTION__);
863 if(category_edit_dialog(pcedit->dialog, 0))
865 store = generate_store();
866 gtk_tree_view_set_model(
867 GTK_TREE_VIEW(pcedit->tree_view),
868 GTK_TREE_MODEL(store));
869 g_object_unref(G_OBJECT(store));
871 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
876 category_edit(GtkWidget *widget, PoiCategoryEditInfo *pcedit)
880 GtkTreeSelection *selection;
881 printf("%s()\n", __PRETTY_FUNCTION__);
883 store = gtk_tree_view_get_model(GTK_TREE_VIEW(pcedit->tree_view));
884 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pcedit->tree_view));
885 if(gtk_tree_selection_get_selected(selection, &store, &iter))
888 memset(&val, 0, sizeof(val));
889 gtk_tree_model_get_value(store, &iter, 0, &val);
890 if(category_edit_dialog(pcedit->dialog, g_value_get_uint(&val)))
892 GtkListStore *new_store = generate_store();
893 gtk_tree_view_set_model(
894 GTK_TREE_VIEW(pcedit->tree_view),
895 GTK_TREE_MODEL(new_store));
896 g_object_unref(G_OBJECT(new_store));
899 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
904 category_list_dialog(GtkWidget *parent)
906 static GtkWidget *dialog = NULL;
907 static GtkWidget *tree_view = NULL;
908 static GtkWidget *sw = NULL;
909 static GtkWidget *btn_edit = NULL;
910 static GtkWidget *btn_add = NULL;
911 static GtkTreeViewColumn *column = NULL;
912 static GtkCellRenderer *renderer = NULL;
913 static GtkListStore *store;
914 static PoiCategoryEditInfo pcedit;
915 printf("%s()\n", __PRETTY_FUNCTION__);
917 store = generate_store();
922 dialog = gtk_dialog_new_with_buttons(_("POI Categories"),
923 GTK_WINDOW(parent), GTK_DIALOG_MODAL,
924 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
927 /* Enable the help button. */
929 hildon_help_dialog_help_enable(
931 ossohelp_dialog_help_enable(
933 GTK_DIALOG(dialog), HELP_ID_POICAT, _osso);
935 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
936 btn_edit = gtk_button_new_with_label(_("Edit...")));
938 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
939 btn_add = gtk_button_new_with_label(_("Add...")));
941 sw = gtk_scrolled_window_new(NULL, NULL);
942 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (sw),
944 GTK_POLICY_AUTOMATIC);
945 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
948 tree_view = gtk_tree_view_new();
950 g_object_set(tree_view, "allow-checkbox-mode", FALSE, NULL);
951 gtk_container_add (GTK_CONTAINER (sw), tree_view);
953 gtk_tree_selection_set_mode(
954 gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)),
955 GTK_SELECTION_SINGLE);
956 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_view), TRUE);
958 renderer = gtk_cell_renderer_text_new();
959 column = gtk_tree_view_column_new_with_attributes(
960 _("ID"), renderer, "text", CAT_ID, NULL);
961 gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
962 gtk_tree_view_column_set_max_width (column, 1);
964 renderer = gtk_cell_renderer_toggle_new();
965 g_signal_connect (renderer, "toggled",
966 G_CALLBACK (category_toggled), store);
967 column = gtk_tree_view_column_new_with_attributes(
968 _("Enabled"), renderer, "active", CAT_ENABLED, NULL);
969 gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
971 renderer = gtk_cell_renderer_text_new();
972 column = gtk_tree_view_column_new_with_attributes(
973 _("Label"), renderer, "text", CAT_LABEL, NULL);
974 gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
976 renderer = gtk_cell_renderer_text_new();
977 column = gtk_tree_view_column_new_with_attributes(
978 _("Description"), renderer, "text", CAT_DESC, NULL);
979 gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
981 renderer = gtk_cell_renderer_text_new();
982 column = gtk_tree_view_column_new_with_attributes(
983 _("# POIs"), renderer, "text", CAT_POI_CNT, NULL);
984 gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
986 gtk_window_set_default_size(GTK_WINDOW(dialog), -1, 400);
988 pcedit.dialog = dialog;
989 pcedit.tree_view = tree_view;
991 g_signal_connect(G_OBJECT(btn_edit), "clicked",
992 G_CALLBACK(category_edit), &pcedit);
994 g_signal_connect(G_OBJECT(btn_add), "clicked",
995 G_CALLBACK(category_add), &pcedit);
997 gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view), GTK_TREE_MODEL(store));
998 g_object_unref(G_OBJECT(store));
1000 gtk_widget_show_all(dialog);
1002 while(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog)))
1007 gtk_widget_destroy(dialog);
1009 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1014 poi_delete(GtkWidget *widget, DeletePOI *dpoi)
1019 printf("%s()\n", __PRETTY_FUNCTION__);
1021 buffer = g_strdup_printf("%s\n%s", _("Delete POI?"), dpoi->txt_label);
1022 confirm = hildon_note_new_confirmation(GTK_WINDOW(dpoi->dialog), buffer);
1024 i = gtk_dialog_run(GTK_DIALOG(confirm));
1025 gtk_widget_destroy(GTK_WIDGET(confirm));
1027 if(i == GTK_RESPONSE_OK)
1029 if(SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi, 1, dpoi->id) ||
1030 SQLITE_DONE != sqlite3_step(_stmt_delete_poi))
1032 MACRO_BANNER_SHOW_INFO(dpoi->dialog, _("Error deleting POI"));
1036 dpoi->deleted = TRUE;
1037 gtk_widget_hide(dpoi->dialog);
1040 sqlite3_reset(_stmt_delete_poi);
1043 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1048 poi_populate_categories(GtkListStore *store, gint cat_id,
1049 GtkTreeIter *out_active)
1051 gboolean has_active = FALSE;
1052 printf("%s()\n", __PRETTY_FUNCTION__);
1054 gtk_list_store_clear(store);
1056 while(SQLITE_ROW == sqlite3_step(_stmt_selall_cat))
1059 gint cid = sqlite3_column_int(_stmt_selall_cat, 0);
1060 const gchar *clab = sqlite3_column_text(_stmt_selall_cat, 1);
1062 gtk_list_store_append(store, &iter);
1063 gtk_list_store_set(store, &iter, 0, cid, 1, clab, -1);
1065 if(cid == cat_id || !has_active)
1072 sqlite3_reset(_stmt_selall_cat);
1074 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1079 poi_edit_cat(GtkWidget *widget, PoiCategoryEditInfo *data)
1081 printf("%s()\n", __PRETTY_FUNCTION__);
1082 if(category_list_dialog(data->dialog))
1085 if(poi_populate_categories(GTK_LIST_STORE(gtk_combo_box_get_model(
1086 GTK_COMBO_BOX(data->cmb_category))),
1087 data->cat_id, &active))
1089 gtk_combo_box_set_active_iter(
1090 GTK_COMBO_BOX(data->cmb_category), &active);
1093 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1098 poi_create_cat_combo()
1100 GtkWidget *cmb_category;
1101 GtkTreeModel *model;
1102 printf("%s()\n", __PRETTY_FUNCTION__);
1104 model = GTK_TREE_MODEL(gtk_list_store_new(2,
1105 G_TYPE_INT, /* Category ID */
1106 G_TYPE_STRING)); /* Category Label */
1107 cmb_category = gtk_combo_box_new_with_model(model);
1108 g_object_unref(model);
1110 /* Set up the view for the combo box. */
1112 GtkCellRenderer *renderer;
1114 renderer = gtk_cell_renderer_text_new();
1115 gtk_cell_layout_pack_start(
1116 GTK_CELL_LAYOUT(cmb_category), renderer, TRUE);
1117 gtk_cell_layout_set_attributes(
1118 GTK_CELL_LAYOUT(cmb_category), renderer, "text", 1, NULL);
1120 poi_populate_categories(GTK_LIST_STORE(gtk_combo_box_get_model(
1121 GTK_COMBO_BOX(cmb_category))), -1, &active);
1123 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1124 return cmb_category;
1128 poi_add_dialog(GtkWidget *parent, gint unitx, gint unity)
1131 static GtkWidget *dialog;
1132 static GtkWidget *table;
1133 static GtkWidget *label;
1134 static GtkWidget *txt_label;
1135 static GtkWidget *txt_lat;
1136 static GtkWidget *txt_lon;
1137 static GtkWidget *cmb_category;
1138 static GtkWidget *txt_desc;
1139 static GtkWidget *btn_catedit;
1140 static GtkWidget *hbox;
1141 static GtkWidget *txt_scroll;
1142 static GtkTextBuffer *desc_txt;
1143 static GtkTextIter begin, end;
1144 static DeletePOI dpoi = {NULL, NULL, 0};
1145 static PoiCategoryEditInfo pcedit;
1146 printf("%s()\n", __PRETTY_FUNCTION__);
1150 dialog = gtk_dialog_new_with_buttons(_("Add POI"),
1151 GTK_WINDOW(parent), GTK_DIALOG_MODAL,
1152 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1153 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
1156 /* Set the lat/lon strings. */
1157 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1158 table = gtk_table_new(6, 4, FALSE), TRUE, TRUE, 0);
1160 gtk_table_attach(GTK_TABLE(table),
1161 label = gtk_label_new(_("Lat")),
1162 0, 1, 0, 1, GTK_FILL, 0, 2, 0);
1163 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1164 gtk_table_attach(GTK_TABLE(table),
1165 txt_lat = gtk_entry_new(),
1166 1, 2, 0, 1, GTK_FILL, 0, 2, 0);
1168 gtk_table_attach(GTK_TABLE(table),
1169 label = gtk_label_new(_("Lon")),
1170 2, 3, 0, 1, GTK_FILL, 0, 2, 0);
1171 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1172 gtk_table_attach(GTK_TABLE(table),
1173 txt_lon = gtk_entry_new(),
1174 3, 4, 0, 1, GTK_FILL, 0, 2, 0);
1176 gtk_table_attach(GTK_TABLE(table),
1177 label = gtk_label_new(_("Label")),
1178 0, 1, 1, 2, GTK_FILL, 0, 2, 0);
1179 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1180 gtk_table_attach(GTK_TABLE(table),
1181 txt_label = gtk_entry_new(),
1182 1, 4, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 0);
1184 gtk_table_attach(GTK_TABLE(table),
1185 label = gtk_label_new(_("Category")),
1186 0, 1, 3, 4, GTK_FILL, 0, 2, 0);
1187 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1188 gtk_table_attach(GTK_TABLE(table),
1189 hbox = gtk_hbox_new(FALSE, 4),
1190 1, 4, 3, 4, GTK_EXPAND | GTK_FILL, 0, 2, 0);
1191 gtk_box_pack_start(GTK_BOX(hbox),
1192 cmb_category = poi_create_cat_combo(),
1195 gtk_box_pack_start(GTK_BOX(hbox),
1196 btn_catedit = gtk_button_new_with_label(
1197 _("Edit Categories...")),
1200 gtk_table_attach(GTK_TABLE(table),
1201 label = gtk_label_new(_("Description")),
1202 0, 1, 5, 6, GTK_FILL, GTK_FILL, 2, 0);
1203 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.0f);
1205 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
1206 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
1208 gtk_table_attach(GTK_TABLE(table),
1210 1, 4, 5, 6, GTK_EXPAND | GTK_FILL, 0, 2, 0);
1212 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
1213 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1215 txt_desc = gtk_text_view_new ();
1216 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
1218 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
1219 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 550, 120);
1221 desc_txt = gtk_text_view_get_buffer(GTK_TEXT_VIEW (txt_desc));
1223 g_signal_connect(G_OBJECT(btn_catedit), "clicked",
1224 G_CALLBACK(poi_edit_cat), &pcedit);
1230 poi.desc = g_strdup("");
1231 unit2latlon(unitx, unity, poi.lat, poi.lon);
1235 gchar tmp1[LL_FMT_LEN], tmp2[LL_FMT_LEN];
1237 format_lat_lon(poi.lat, poi.lon, tmp1, tmp2);
1238 //lat_format(poi.lat, tmp1);
1239 //lon_format(poi.lon, tmp2);
1241 gtk_entry_set_text(GTK_ENTRY(txt_lat), tmp1);
1242 gtk_entry_set_text(GTK_ENTRY(txt_lon), tmp2);
1246 if(SQLITE_ROW == sqlite3_step(_stmt_nextlabel_poi))
1247 poi.label = g_strdup_printf("Point%06d",
1248 sqlite3_column_int(_stmt_nextlabel_poi, 0));
1250 poi.label = g_strdup("");
1251 sqlite3_reset(_stmt_nextlabel_poi);
1252 gtk_entry_set_text(GTK_ENTRY(txt_label), poi.label);
1255 gtk_text_buffer_set_text(desc_txt, "", -1);
1261 gboolean had_cat_id = FALSE;
1263 if(gtk_combo_box_get_active_iter(
1264 GTK_COMBO_BOX(cmb_category), &iter))
1267 gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category)),&iter,
1272 gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(
1273 GTK_COMBO_BOX(cmb_category))));
1274 if(poi_populate_categories(GTK_LIST_STORE(gtk_combo_box_get_model(
1275 GTK_COMBO_BOX(cmb_category))), cat_id, &iter)
1278 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(cmb_category), &iter);
1282 pcedit.dialog = dialog;
1283 pcedit.cmb_category = cmb_category;
1284 pcedit.cat_id = poi.cat_id;
1286 gtk_widget_show_all(dialog);
1288 while(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog)))
1294 text = gtk_entry_get_text(GTK_ENTRY(txt_lat));
1295 poi.lat = strdmstod(text, &error_check);
1296 if(text == error_check || poi.lat < -90. || poi.lat > 90.) {
1297 popup_error(dialog, _("Invalid Latitude"));
1301 text = gtk_entry_get_text(GTK_ENTRY(txt_lon));
1302 poi.lon = strdmstod(text, &error_check);
1303 if(text == error_check || poi.lon < -180. || poi.lon > 180.) {
1304 popup_error(dialog, _("Invalid Longitude"));
1308 if(strlen(gtk_entry_get_text(GTK_ENTRY(txt_label))))
1312 poi.label = g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_label)));
1316 popup_error(dialog, _("Please specify a name."));
1320 if(!gtk_combo_box_get_active_iter(
1321 GTK_COMBO_BOX(cmb_category), &iter))
1323 popup_error(dialog, _("Please specify a category."));
1327 gtk_text_buffer_get_iter_at_offset(desc_txt, &begin,0 );
1328 gtk_text_buffer_get_end_iter (desc_txt, &end);
1331 poi.desc = gtk_text_buffer_get_text(desc_txt, &begin, &end, TRUE);
1336 gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category)), &iter,
1342 if(SQLITE_OK != sqlite3_bind_double(_stmt_insert_poi, 1, poi.lat)
1343 || SQLITE_OK != sqlite3_bind_double(_stmt_insert_poi, 2, poi.lon)
1344 || SQLITE_OK != sqlite3_bind_text(_stmt_insert_poi, 3, poi.label,
1346 || SQLITE_OK != sqlite3_bind_text(_stmt_insert_poi, 4, poi.desc,
1348 || SQLITE_OK != sqlite3_bind_int(_stmt_insert_poi, 5, poi.cat_id)
1349 || SQLITE_DONE != sqlite3_step(_stmt_insert_poi))
1351 MACRO_BANNER_SHOW_INFO(parent, _("Error adding POI"));
1354 sqlite3_reset(_stmt_insert_poi);
1362 g_free(dpoi.txt_label);
1366 gtk_widget_hide(dialog);
1368 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1369 return !dpoi.deleted;
1373 poi_view_dialog(GtkWidget *parent, PoiInfo *poi)
1376 static GtkWidget *dialog;
1377 static GtkWidget *table;
1378 static GtkWidget *label;
1379 static GtkWidget *txt_label;
1380 static GtkWidget *txt_lat;
1381 static GtkWidget *txt_lon;
1382 static GtkWidget *cmb_category;
1383 static GtkWidget *txt_desc;
1384 static GtkWidget *btn_delete = NULL;
1385 static GtkWidget *btn_catedit;
1386 static GtkWidget *hbox;
1387 static GtkWidget *txt_scroll;
1388 static GtkTextBuffer *desc_txt;
1389 static GtkTextIter begin, end;
1390 static DeletePOI dpoi = {NULL, NULL, 0};
1391 static PoiCategoryEditInfo pcedit;
1392 static int last_deg_format = 0;
1394 printf("%s()\n", __PRETTY_FUNCTION__);
1397 if(_degformat != last_deg_format)
1399 last_deg_format = _degformat;
1401 if(dialog != NULL) gtk_widget_destroy(dialog);
1407 dialog = gtk_dialog_new_with_buttons(_("Edit POI"),
1408 GTK_WINDOW(parent), GTK_DIALOG_MODAL,
1409 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1412 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
1413 btn_delete = gtk_button_new_with_label(_("Delete...")));
1415 gtk_dialog_add_button(GTK_DIALOG(dialog),
1416 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
1418 /* Set the lat/lon strings. */
1419 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1420 table = gtk_table_new(6, 4, FALSE), TRUE, TRUE, 0);
1422 gtk_table_attach(GTK_TABLE(table),
1423 label = gtk_label_new(DEG_FORMAT_ENUM_TEXT[_degformat].short_field_1),
1424 0, 1, 0, 1, GTK_FILL, 0, 2, 0);
1425 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1426 gtk_table_attach(GTK_TABLE(table),
1427 txt_lat = gtk_entry_new(),
1428 1, 2, 0, 1, GTK_FILL, 0, 2, 0);
1430 if(DEG_FORMAT_ENUM_TEXT[_degformat].field_2_in_use)
1432 gtk_table_attach(GTK_TABLE(table),
1433 label = gtk_label_new(DEG_FORMAT_ENUM_TEXT[_degformat].short_field_2),
1434 2, 3, 0, 1, GTK_FILL, 0, 2, 0);
1435 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1436 gtk_table_attach(GTK_TABLE(table),
1437 txt_lon = gtk_entry_new(),
1438 3, 4, 0, 1, GTK_FILL, 0, 2, 0);
1441 gtk_table_attach(GTK_TABLE(table),
1442 label = gtk_label_new(_("Label")),
1443 0, 1, 1, 2, GTK_FILL, 0, 2, 0);
1444 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1445 gtk_table_attach(GTK_TABLE(table),
1446 txt_label = gtk_entry_new(),
1447 1, 4, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 0);
1449 gtk_table_attach(GTK_TABLE(table),
1450 label = gtk_label_new(_("Category")),
1451 0, 1, 3, 4, GTK_FILL, 0, 2, 0);
1452 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1453 gtk_table_attach(GTK_TABLE(table),
1454 hbox = gtk_hbox_new(FALSE, 4),
1455 1, 4, 3, 4, GTK_EXPAND | GTK_FILL, 0, 2, 0);
1456 gtk_box_pack_start(GTK_BOX(hbox),
1457 cmb_category = poi_create_cat_combo(),
1460 gtk_box_pack_start(GTK_BOX(hbox),
1461 btn_catedit = gtk_button_new_with_label(
1462 _("Edit Categories...")),
1465 gtk_table_attach(GTK_TABLE(table),
1466 label = gtk_label_new(_("Description")),
1467 0, 1, 5, 6, GTK_FILL, GTK_FILL, 2, 0);
1468 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.0f);
1470 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
1471 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
1473 gtk_table_attach(GTK_TABLE(table),
1475 1, 4, 5, 6, GTK_EXPAND | GTK_FILL, 0, 2, 0);
1477 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
1478 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1480 txt_desc = gtk_text_view_new ();
1481 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
1483 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
1484 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 550, 120);
1486 desc_txt = gtk_text_view_get_buffer (GTK_TEXT_VIEW (txt_desc));
1488 g_signal_connect(G_OBJECT(btn_delete), "clicked",
1489 G_CALLBACK(poi_delete), &dpoi);
1491 g_signal_connect(G_OBJECT(btn_catedit), "clicked",
1492 G_CALLBACK(poi_edit_cat), &pcedit);
1495 dpoi.dialog = dialog;
1496 dpoi.txt_label = g_strdup(poi->label);
1497 dpoi.id = poi->poi_id;
1498 dpoi.deleted = FALSE;
1502 gchar tmp1[LL_FMT_LEN], tmp2[LL_FMT_LEN];
1504 format_lat_lon(poi->lat, poi->lon, tmp1, tmp2);
1505 //lat_format(poi->lat, tmp1);
1506 //lon_format(poi->lon, tmp2);
1508 gtk_entry_set_text(GTK_ENTRY(txt_lat), tmp1);
1510 if(DEG_FORMAT_ENUM_TEXT[_degformat].field_2_in_use)
1511 gtk_entry_set_text(GTK_ENTRY(txt_lon), tmp2);
1513 gtk_entry_set_text(GTK_ENTRY(txt_lon), g_strdup(""));
1517 gtk_entry_set_text(GTK_ENTRY(txt_label), poi->label);
1520 gtk_text_buffer_set_text(desc_txt, poi->desc, -1);
1523 gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(
1524 GTK_COMBO_BOX(cmb_category))));
1525 if(poi_populate_categories(GTK_LIST_STORE(gtk_combo_box_get_model(
1526 GTK_COMBO_BOX(cmb_category))), poi->cat_id, &iter))
1527 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(cmb_category), &iter);
1529 /* Connect Signals */
1530 pcedit.dialog = dialog;
1531 pcedit.cmb_category = cmb_category;
1532 pcedit.cat_id = poi->cat_id;
1534 gtk_widget_show_all(dialog);
1536 while(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog)))
1538 const gchar *text, *text_lat, *text_lon;
1541 text_lat = gtk_entry_get_text(GTK_ENTRY(txt_lat));
1542 text_lon = gtk_entry_get_text(GTK_ENTRY(txt_lon));
1544 if(!parse_coords(text_lat, text_lon, &poi->lat, &poi->lon))
1546 popup_error(dialog, _("Invalid coordinate specified"));
1551 if(strlen(gtk_entry_get_text(GTK_ENTRY(txt_label))))
1555 poi->label = g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_label)));
1559 popup_error(dialog, _("Please specify a name."));
1563 if(!gtk_combo_box_get_active_iter(
1564 GTK_COMBO_BOX(cmb_category), &iter))
1566 popup_error(dialog, _("Please specify a category."));
1570 gtk_text_buffer_get_iter_at_offset(desc_txt, &begin,0 );
1571 gtk_text_buffer_get_end_iter (desc_txt, &end);
1574 poi->desc = gtk_text_buffer_get_text(desc_txt, &begin, &end, TRUE);
1577 g_free(poi->clabel);
1579 gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category)), &iter,
1585 if(SQLITE_OK != sqlite3_bind_double(
1586 _stmt_update_poi, 1, poi->lat) ||
1587 SQLITE_OK != sqlite3_bind_double(
1588 _stmt_update_poi, 2, poi->lon) ||
1589 SQLITE_OK != sqlite3_bind_text(_stmt_update_poi, 3, poi->label,
1590 -1, SQLITE_STATIC) ||
1591 SQLITE_OK != sqlite3_bind_text(_stmt_update_poi, 4, poi->desc,
1592 -1, SQLITE_STATIC) ||
1593 SQLITE_OK != sqlite3_bind_int(
1594 _stmt_update_poi, 5, poi->cat_id) ||
1595 SQLITE_OK != sqlite3_bind_int(
1596 _stmt_update_poi, 6, poi->poi_id) ||
1597 SQLITE_DONE != sqlite3_step(_stmt_update_poi))
1599 MACRO_BANNER_SHOW_INFO(parent, _("Error updating POI"));
1602 sqlite3_reset(_stmt_update_poi);
1608 g_free(dpoi.txt_label);
1612 gtk_widget_hide(dialog); /* Destroying causes a crash.... ??? */
1614 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1615 return !dpoi.deleted;
1619 poi_list_insert(GtkWidget *parent, GList *poi_list, GtkComboBox *cmb_category)
1621 gint default_cat_id;
1622 gchar *default_cat_label;
1623 gint num_inserts = 0;
1626 printf("%s()\n", __PRETTY_FUNCTION__);
1628 /* Get defaults from the given GtkComboBox */
1629 if(!gtk_combo_box_get_active_iter(
1630 GTK_COMBO_BOX(cmb_category), &iter))
1632 vprintf("%s(): return 0\n", __PRETTY_FUNCTION__);
1636 gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category)),
1639 1, &default_cat_label,
1642 /* Iterate through the data model and import as desired. */
1643 for(curr = poi_list; curr; )
1645 PoiInfo *poi = curr->data;
1647 ( SQLITE_OK != sqlite3_bind_double(_stmt_insert_poi, 1, poi->lat)
1648 || SQLITE_OK != sqlite3_bind_double(_stmt_insert_poi, 2, poi->lon)
1649 || SQLITE_OK != sqlite3_bind_text(_stmt_insert_poi, 3, poi->label,
1651 || SQLITE_OK != sqlite3_bind_text(_stmt_insert_poi, 4, poi->desc,
1653 || SQLITE_OK != sqlite3_bind_int(_stmt_insert_poi, 5,
1654 poi->cat_id = default_cat_id)
1655 || SQLITE_DONE != sqlite3_step(_stmt_insert_poi)
1659 GList *tmp = curr->next;
1664 g_slice_free(PoiInfo, poi);
1665 poi_list = g_list_delete_link(poi_list, curr);
1672 if(default_cat_label)
1673 poi->clabel = g_strdup(default_cat_label);
1674 poi->poi_id = sqlite3_last_insert_rowid(_poi_db);
1677 sqlite3_reset(_stmt_insert_poi);
1682 gchar buffer[BUFFER_SIZE];
1684 snprintf(buffer, sizeof(buffer), "%d %s", num_inserts,
1685 _("POIs were added to the POI database. The following screen will "
1686 "allow you to modify or delete any of the new POIs."));
1687 popup_error(parent, buffer);
1691 popup_error(parent, _("No POIs were found."));
1694 if(default_cat_label)
1695 g_free(default_cat_label);
1697 vprintf("%s(): return %d\n", __PRETTY_FUNCTION__, num_inserts);
1702 poi_list_free(GList *poi_list)
1705 printf("%s()\n", __PRETTY_FUNCTION__);
1707 for(curr = poi_list; curr; curr = curr->next)
1709 PoiInfo *poi_info = curr->data;
1713 g_free(poi_info->label);
1715 g_free(poi_info->desc);
1716 if(poi_info->clabel)
1717 g_free(poi_info->clabel);
1718 g_slice_free(PoiInfo, poi_info);
1722 g_list_free(poi_list);
1724 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1728 poi_list_bearing_cell_data_func(
1729 GtkTreeViewColumn *tree_column,
1730 GtkCellRenderer *cell,
1731 GtkTreeModel *tree_model,
1736 vprintf("%s()\n", __PRETTY_FUNCTION__);
1738 gtk_tree_model_get(tree_model, iter, POI_BEARING, &f, -1);
1739 snprintf(buffer, sizeof(buffer), "%.1f", f);
1740 g_object_set(cell, "text", buffer, NULL);
1742 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1746 poi_list_distance_cell_data_func(
1747 GtkTreeViewColumn *tree_column,
1748 GtkCellRenderer *cell,
1749 GtkTreeModel *tree_model,
1754 vprintf("%s()\n", __PRETTY_FUNCTION__);
1756 gtk_tree_model_get(tree_model, iter, POI_DISTANCE, &f, -1);
1757 snprintf(buffer, sizeof(buffer), "%.2f", f);
1758 g_object_set(cell, "text", buffer, NULL);
1760 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1764 poi_list_row_selected(GtkCellRendererToggle *renderer,
1765 gchar *path_string, GtkTreeModel *tree_model)
1768 vprintf("%s()\n", __PRETTY_FUNCTION__);
1770 if(gtk_tree_model_get_iter_from_string(tree_model, &iter, path_string))
1773 gtk_tree_model_get(tree_model, &iter, POI_SELECTED, &old_value, -1);
1774 gtk_list_store_set(GTK_LIST_STORE(tree_model), &iter,
1775 POI_SELECTED, !old_value,
1779 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1784 poi_list_set_category(GtkWidget *widget, PoiListInfo *pli)
1786 static GtkWidget *dialog = NULL;
1787 static GtkWidget *cmb_category = NULL;
1788 static GtkWidget *btn_catedit = NULL;
1789 static PoiCategoryEditInfo pcedit;
1790 printf("%s()\n", __PRETTY_FUNCTION__);
1797 dialog = gtk_dialog_new_with_buttons(_("Set Category..."),
1798 GTK_WINDOW(pli->dialog2), GTK_DIALOG_MODAL,
1799 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1800 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
1803 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1804 hbox = gtk_hbox_new(FALSE, 4), FALSE, FALSE, 4);
1806 gtk_box_pack_start(GTK_BOX(hbox),
1807 label = gtk_label_new(_("Category")),
1810 gtk_box_pack_start(GTK_BOX(hbox),
1811 cmb_category = poi_create_cat_combo(),
1814 gtk_box_pack_start(GTK_BOX(hbox),
1815 btn_catedit = gtk_button_new_with_label(
1816 _("Edit Categories...")),
1819 /* Connect Signals */
1820 pcedit.dialog = dialog;
1821 pcedit.cmb_category = cmb_category;
1823 g_signal_connect(G_OBJECT(btn_catedit), "clicked",
1824 G_CALLBACK(poi_edit_cat), &pcedit);
1827 gtk_widget_show_all(dialog);
1829 while(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog)))
1832 GtkListStore *store;
1834 const gchar *cat_label;
1836 /* Get the text of the chosen category. */
1837 if(!gtk_combo_box_get_active_iter(
1838 GTK_COMBO_BOX(cmb_category), &iter))
1840 popup_error(dialog, _("Please specify a category."));
1845 gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category)),
1851 /* Iterate through the data store and categorize as desired. */
1852 store = GTK_LIST_STORE(gtk_tree_view_get_model(
1853 GTK_TREE_VIEW(pli->tree_view)));
1854 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) do
1859 memset(&poi, 0, sizeof(poi));
1861 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
1862 POI_SELECTED, &selected,
1863 POI_POIID, &(poi.poi_id),
1864 POI_LAT, &(poi.lat),
1865 POI_LON, &(poi.lon),
1866 POI_LABEL, &(poi.label),
1867 POI_DESC, &(poi.desc),
1872 gtk_list_store_set(store, &iter,
1874 POI_CLABEL, cat_label,
1877 if(SQLITE_OK != sqlite3_bind_double(
1878 _stmt_update_poi, 1, poi.lat) ||
1879 SQLITE_OK != sqlite3_bind_double(
1880 _stmt_update_poi, 2, poi.lon) ||
1881 SQLITE_OK != sqlite3_bind_text(_stmt_update_poi,
1882 3, poi.label, -1, SQLITE_STATIC) ||
1883 SQLITE_OK != sqlite3_bind_text(_stmt_update_poi,
1884 4, poi.desc, -1, SQLITE_STATIC) ||
1885 SQLITE_OK != sqlite3_bind_int(
1886 _stmt_update_poi, 5, cat_id) ||
1887 SQLITE_OK != sqlite3_bind_int(
1888 _stmt_update_poi, 6, poi.poi_id) ||
1889 SQLITE_DONE != sqlite3_step(_stmt_update_poi))
1891 MACRO_BANNER_SHOW_INFO(pli->dialog2,
1892 _("Error updating POI"));
1894 sqlite3_reset(_stmt_update_poi);
1896 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter));
1902 gtk_widget_hide(dialog);
1904 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1909 poi_list_select_all(GtkTreeViewColumn *column, PoiListInfo *pli)
1912 GtkListStore *store;
1913 printf("%s()\n", __PRETTY_FUNCTION__);
1915 /* Iterate through the data store and select as desired. */
1916 store = GTK_LIST_STORE(gtk_tree_view_get_model(
1917 GTK_TREE_VIEW(pli->tree_view)));
1918 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) do
1920 gtk_list_store_set(store, &iter,
1921 POI_SELECTED, pli->select_all,
1923 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter));
1925 pli->select_all = !pli->select_all;
1927 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1932 poi_list_view(GtkWidget *widget, PoiListInfo *pli)
1935 GtkTreeSelection *selection;
1936 GtkListStore *store;
1937 printf("%s()\n", __PRETTY_FUNCTION__);
1939 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pli->tree_view));
1940 store = GTK_LIST_STORE(gtk_tree_view_get_model(
1941 GTK_TREE_VIEW(pli->tree_view)));
1943 /* Iterate through the data store and import as desired. */
1944 if(gtk_tree_selection_get_selected(selection, NULL, &iter))
1947 memset(&poi, 0, sizeof(poi));
1949 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
1950 POI_POIID, &(poi.poi_id),
1951 POI_CATID, &(poi.cat_id),
1952 POI_LAT, &(poi.lat),
1953 POI_LON, &(poi.lon),
1954 POI_LABEL, &(poi.label),
1955 POI_DESC, &(poi.desc),
1956 POI_CLABEL, &(poi.clabel),
1959 if(poi_view_dialog(pli->dialog, &poi))
1961 gtk_list_store_set(store, &iter,
1962 POI_POIID, poi.poi_id,
1963 POI_CATID, poi.cat_id,
1966 POI_LABEL, poi.label,
1968 POI_CLABEL, poi.clabel,
1973 /* POI was deleted. */
1974 gtk_list_store_remove(store, &iter);
1978 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1983 poi_list_row_activated(GtkTreeView *tree_view, GtkTreePath *path,
1984 GtkTreeViewColumn *column, PoiListInfo *pli)
1986 printf("%s()\n", __PRETTY_FUNCTION__);
1988 if(column != pli->select_column)
1989 poi_list_view(GTK_WIDGET(tree_view), pli);
1991 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1995 poi_list_goto(GtkWidget *widget, PoiListInfo *pli)
1998 GtkTreeSelection *selection;
1999 GtkListStore *store;
2000 printf("%s()\n", __PRETTY_FUNCTION__);
2002 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pli->tree_view));
2003 store = GTK_LIST_STORE(gtk_tree_view_get_model(
2004 GTK_TREE_VIEW(pli->tree_view)));
2006 /* Iterate through the data store and import as desired. */
2007 if(gtk_tree_selection_get_selected(selection, NULL, &iter))
2012 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
2017 latlon2unit(lat, lon, unit.unitx, unit.unity);
2019 if(_center_mode > 0)
2020 gtk_check_menu_item_set_active(
2021 GTK_CHECK_MENU_ITEM(_menu_view_ac_none_item), TRUE);
2023 map_center_unit(unit);
2026 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2031 poi_list_delete(GtkWidget *widget, PoiListInfo *pli)
2034 printf("%s()\n", __PRETTY_FUNCTION__);
2036 confirm = hildon_note_new_confirmation(
2037 GTK_WINDOW(pli->dialog2), _("Delete selected POI?"));
2039 if(GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm)))
2042 GtkListStore *store;
2043 gboolean already_next;
2044 gboolean must_iterate;;
2046 /* Iterate through the data store and import as desired. */
2047 store = GTK_LIST_STORE(gtk_tree_view_get_model(
2048 GTK_TREE_VIEW(pli->tree_view)));
2049 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) do
2052 must_iterate = TRUE;
2053 already_next = FALSE;
2055 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
2056 POI_SELECTED, &selected,
2062 if(SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi, 1, poi_id)
2063 || SQLITE_DONE != sqlite3_step(_stmt_delete_poi))
2065 MACRO_BANNER_SHOW_INFO(pli->dialog2,
2066 _("Error deleting POI"));
2070 already_next = gtk_list_store_remove(store, &iter);
2071 must_iterate = FALSE;
2073 sqlite3_reset(_stmt_delete_poi);
2075 } while(already_next || (must_iterate
2076 && gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter)));
2081 gtk_widget_destroy(confirm);
2083 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2088 poi_list_export_gpx(GtkWidget *widget, PoiListInfo *pli)
2090 GnomeVFSHandle *handle;
2091 printf("%s()\n", __PRETTY_FUNCTION__);
2093 if(display_open_file(GTK_WINDOW(pli->dialog2), NULL, &handle, NULL,
2094 NULL, NULL, GTK_FILE_CHOOSER_ACTION_SAVE))
2096 gint num_exported = gpx_poi_write(
2097 gtk_tree_view_get_model(GTK_TREE_VIEW(pli->tree_view)), handle);
2098 if(num_exported >= 0)
2101 snprintf(buffer, sizeof(buffer), "%d %s\n", num_exported,
2102 _("POIs Exported"));
2103 MACRO_BANNER_SHOW_INFO(pli->dialog2, buffer);
2106 popup_error(pli->dialog2, _("Error writing GPX file."));
2107 gnome_vfs_close(handle);
2110 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2115 poi_list_manage_checks(GtkWidget *widget, PoiListInfo *pli)
2117 GtkWidget *btn_category;
2118 GtkWidget *btn_delete;
2119 GtkWidget *btn_export_gpx;
2121 printf("%s()\n", __PRETTY_FUNCTION__);
2123 pli->dialog2 = gtk_dialog_new_with_buttons(_("Checked POI Actions..."),
2124 GTK_WINDOW(pli->dialog), GTK_DIALOG_MODAL,
2127 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pli->dialog2)->vbox),
2128 gtk_label_new(_("Select an operation to perform\n"
2129 "on the POIs that you checked\n"
2130 "in the POI list.")),
2133 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pli->dialog2)->vbox),
2134 btn_category = gtk_button_new_with_label(_("Set Category...")),
2137 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pli->dialog2)->vbox),
2138 btn_delete = gtk_button_new_with_label(_("Delete...")),
2141 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pli->dialog2)->vbox),
2142 btn_export_gpx = gtk_button_new_with_label(
2143 _("Export to GPX...")),
2146 gtk_dialog_add_button(GTK_DIALOG(pli->dialog2),
2147 GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT);
2149 g_signal_connect(G_OBJECT(btn_category), "clicked",
2150 G_CALLBACK(poi_list_set_category), pli);
2152 g_signal_connect(G_OBJECT(btn_delete), "clicked",
2153 G_CALLBACK(poi_list_delete), pli);
2155 g_signal_connect(G_OBJECT(btn_export_gpx), "clicked",
2156 G_CALLBACK(poi_list_export_gpx), pli);
2158 gtk_widget_show_all(pli->dialog2);
2160 gtk_dialog_run(GTK_DIALOG(pli->dialog2));
2162 gtk_widget_destroy(pli->dialog2);
2163 pli->dialog2 = NULL;
2165 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2170 poi_list_dialog(GtkWidget *parent, gint unitx, gint unity, GList *poi_list)
2172 static PoiListInfo pli = { NULL, NULL };
2173 static GtkWidget *scroller;
2174 static GtkWidget *btn_goto;
2175 static GtkWidget *btn_edit;
2176 static GtkWidget *btn_manage_checks;
2177 static GtkListStore *store;
2180 gdouble src_lat, src_lon;
2181 printf("%s()\n", __PRETTY_FUNCTION__);
2183 if(pli.dialog == NULL)
2185 GtkCellRenderer *renderer;
2186 GtkTreeViewColumn *column;
2188 pli.dialog = gtk_dialog_new_with_buttons(_("POI List"),
2189 GTK_WINDOW(parent), GTK_DIALOG_MODAL,
2192 store = gtk_list_store_new(POI_NUM_COLUMNS,
2193 G_TYPE_BOOLEAN,/* Selected */
2194 G_TYPE_INT, /* POI ID */
2195 G_TYPE_INT, /* Category ID */
2196 G_TYPE_DOUBLE, /* Latitude */
2197 G_TYPE_DOUBLE, /* Longitude */
2198 G_TYPE_STRING, /* Lat/Lon */
2199 G_TYPE_FLOAT, /* Bearing */
2200 G_TYPE_FLOAT, /* Distance */
2201 G_TYPE_STRING, /* POI Label */
2202 G_TYPE_STRING, /* POI Desc. */
2203 G_TYPE_STRING);/* Category Label */
2205 /* Set up the tree view. */
2206 pli.tree_view = gtk_tree_view_new();
2207 g_object_set(G_OBJECT(pli.tree_view),
2208 "allow-checkbox-mode", FALSE, NULL);
2210 gtk_tree_selection_set_mode(
2211 gtk_tree_view_get_selection(GTK_TREE_VIEW(pli.tree_view)),
2212 GTK_SELECTION_SINGLE);
2213 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(pli.tree_view), TRUE);
2215 renderer = gtk_cell_renderer_toggle_new();
2216 gtk_cell_renderer_toggle_set_active(GTK_CELL_RENDERER_TOGGLE(renderer),
2218 g_signal_connect(G_OBJECT(renderer), "toggled",
2219 G_CALLBACK(poi_list_row_selected), store);
2220 pli.select_column = gtk_tree_view_column_new_with_attributes(
2221 "*", renderer, "active", POI_SELECTED, NULL);
2222 gtk_tree_view_append_column(GTK_TREE_VIEW(pli.tree_view),
2224 gtk_tree_view_column_set_clickable(pli.select_column, TRUE);
2225 g_signal_connect(G_OBJECT(pli.select_column), "clicked",
2226 G_CALLBACK(poi_list_select_all), &pli);
2228 renderer = gtk_cell_renderer_combo_new();
2229 column = gtk_tree_view_column_new_with_attributes(
2230 _("Category"), renderer, "text", POI_CLABEL, NULL);
2231 gtk_tree_view_column_set_sizing(column,GTK_TREE_VIEW_COLUMN_GROW_ONLY);
2232 gtk_tree_view_column_set_sort_column_id(column, POI_CLABEL);
2233 gtk_tree_view_append_column(GTK_TREE_VIEW(pli.tree_view), column);
2235 renderer = gtk_cell_renderer_text_new();
2236 g_object_set(renderer, "xalign", 1.f, NULL);
2237 column = gtk_tree_view_column_new_with_attributes(
2238 _("Dist."), renderer, "text", POI_DISTANCE, NULL);
2239 gtk_tree_view_column_set_cell_data_func(column, renderer,
2240 (GtkTreeCellDataFunc)poi_list_distance_cell_data_func,
2242 gtk_tree_view_column_set_sort_column_id(column, POI_DISTANCE);
2243 gtk_tree_view_append_column(GTK_TREE_VIEW(pli.tree_view), column);
2245 renderer = gtk_cell_renderer_text_new();
2246 g_object_set(renderer, "xalign", 1.f, NULL);
2247 column = gtk_tree_view_column_new_with_attributes(
2248 _("Bear."), renderer, "text", POI_BEARING, NULL);
2249 gtk_tree_view_column_set_cell_data_func(column, renderer,
2250 (GtkTreeCellDataFunc)poi_list_bearing_cell_data_func,
2252 gtk_tree_view_column_set_sort_column_id(column, POI_BEARING);
2253 gtk_tree_view_append_column(GTK_TREE_VIEW(pli.tree_view), column);
2255 renderer = gtk_cell_renderer_text_new();
2256 column = gtk_tree_view_column_new_with_attributes(
2257 _("Label"), renderer, "text", POI_LABEL, NULL);
2258 gtk_tree_view_column_set_sort_column_id(column, POI_LABEL);
2259 gtk_tree_view_append_column(GTK_TREE_VIEW(pli.tree_view), column);
2261 g_signal_connect(G_OBJECT(pli.tree_view), "row-activated",
2262 G_CALLBACK(poi_list_row_activated), &pli);
2264 gtk_tree_view_set_model(GTK_TREE_VIEW(pli.tree_view),
2265 GTK_TREE_MODEL(store));
2266 g_object_unref(G_OBJECT(store));
2268 /* Enable the help button. */
2270 hildon_help_dialog_help_enable(
2272 ossohelp_dialog_help_enable(
2274 GTK_DIALOG(pli.dialog), HELP_ID_POILIST, _osso);
2276 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(pli.dialog)->action_area),
2277 btn_goto = gtk_button_new_with_label(_("Go to")));
2279 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(pli.dialog)->action_area),
2280 btn_edit = gtk_button_new_with_label(_("Edit...")));
2282 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(pli.dialog)->action_area),
2283 btn_manage_checks = gtk_button_new_with_label(
2284 _("Checked POI Actions...")));
2286 gtk_dialog_add_button(GTK_DIALOG(pli.dialog),
2287 GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT);
2289 gtk_window_set_default_size(GTK_WINDOW(pli.dialog), 500, 400);
2291 scroller = gtk_scrolled_window_new (NULL, NULL);
2292 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroller),
2293 GTK_SHADOW_ETCHED_IN);
2294 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroller),
2296 GTK_POLICY_AUTOMATIC);
2297 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pli.dialog)->vbox),
2298 scroller, TRUE, TRUE, 0);
2300 gtk_container_add(GTK_CONTAINER(scroller), pli.tree_view);
2302 g_signal_connect(G_OBJECT(btn_goto), "clicked",
2303 G_CALLBACK(poi_list_goto), &pli);
2305 g_signal_connect(G_OBJECT(btn_edit), "clicked",
2306 G_CALLBACK(poi_list_view), &pli);
2308 g_signal_connect(G_OBJECT(btn_manage_checks), "clicked",
2309 G_CALLBACK(poi_list_manage_checks), &pli);
2312 /* Initialize the tree store. */
2314 gtk_list_store_clear(store);
2315 pli.select_all = FALSE;
2317 unit2latlon(unitx, unity, src_lat, src_lon);
2319 for(curr = poi_list; curr; curr = curr->next)
2321 PoiInfo *poi_info = curr->data;
2322 gchar tmp1[LL_FMT_LEN], tmp2[LL_FMT_LEN];
2324 printf("poi: (%f, %f, %s, %s)\n",
2325 poi_info->lat, poi_info->lon,
2326 poi_info->label, poi_info->desc);
2328 format_lat_lon(poi_info->lat, poi_info->lon, tmp1, tmp2);
2329 //lat_format(poi_info->lat, tmp1);
2330 //lon_format(poi_info->lon, tmp2);
2332 gtk_list_store_append(store, &iter);
2333 gtk_list_store_set(store, &iter,
2335 POI_POIID, poi_info->poi_id,
2336 POI_LAT, poi_info->lat,
2337 POI_LON, poi_info->lon,
2338 POI_BEARING, calculate_bearing(src_lat, src_lon,
2339 poi_info->lat, poi_info->lon),
2340 POI_DISTANCE, calculate_distance(src_lat,src_lon,
2341 poi_info->lat, poi_info->lon) * UNITS_CONVERT[_units],
2342 POI_LABEL, poi_info->label,
2343 POI_DESC, poi_info->desc,
2344 POI_CATID, poi_info->cat_id,
2345 POI_CLABEL, poi_info->clabel,
2349 gtk_widget_show_all(pli.dialog);
2351 GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(pli.dialog));
2355 gtk_widget_hide(pli.dialog);
2357 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2362 poi_import_dialog(gint unitx, gint unity)
2364 GtkWidget *dialog = NULL;
2365 gboolean success = FALSE;
2366 printf("%s()\n", __PRETTY_FUNCTION__);
2368 dialog = hildon_file_chooser_dialog_new(GTK_WINDOW(_window),
2369 GTK_FILE_CHOOSER_ACTION_OPEN);
2371 gtk_widget_show_all(dialog);
2373 while(!success && gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
2375 gchar *file_uri_str = NULL;
2376 gchar *bytes = NULL;
2378 GnomeVFSResult vfs_result;
2379 GList *poi_list = NULL;
2381 file_uri_str = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
2383 /* Parse the given file as GPX. */
2384 if(GNOME_VFS_OK != (vfs_result = gnome_vfs_read_entire_file(
2385 file_uri_str, &size, &bytes)))
2387 popup_error(dialog, gnome_vfs_result_to_string(vfs_result));
2389 else if(gpx_poi_parse(bytes, size, &poi_list))
2391 static GtkWidget *cat_dialog = NULL;
2392 static GtkWidget *cmb_category = NULL;
2393 static GtkWidget *btn_catedit = NULL;
2394 static PoiCategoryEditInfo pcedit;
2400 cat_dialog = gtk_dialog_new_with_buttons(_("Default Category"),
2401 GTK_WINDOW(dialog), GTK_DIALOG_MODAL,
2402 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
2403 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
2406 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(cat_dialog)->vbox),
2407 hbox = gtk_hbox_new(FALSE, 4), FALSE, FALSE, 4);
2409 gtk_box_pack_start(GTK_BOX(hbox),
2410 label = gtk_label_new(_("Category")),
2413 gtk_box_pack_start(GTK_BOX(hbox),
2414 cmb_category = poi_create_cat_combo(),
2417 gtk_box_pack_start(GTK_BOX(hbox),
2418 btn_catedit = gtk_button_new_with_label(
2419 _("Edit Categories...")),
2422 /* Connect Signals */
2423 pcedit.dialog = dialog;
2424 pcedit.cmb_category = cmb_category;
2426 g_signal_connect(G_OBJECT(btn_catedit), "clicked",
2427 G_CALLBACK(poi_edit_cat), &pcedit);
2430 gtk_widget_show_all(cat_dialog);
2432 while(GTK_RESPONSE_ACCEPT ==gtk_dialog_run(GTK_DIALOG(cat_dialog)))
2434 if(gtk_combo_box_get_active(GTK_COMBO_BOX(cmb_category)) == -1)
2437 _("Please specify a default category."));
2441 /* Insert the POIs into the database. */
2442 gint num_inserts = poi_list_insert(dialog,
2443 poi_list, GTK_COMBO_BOX(cmb_category));
2447 /* Hide the dialogs. */
2448 gtk_widget_hide(cat_dialog);
2450 /* Create a new dialog with the results. */
2451 poi_list_dialog(dialog, unitx, unity, poi_list);
2457 gtk_widget_hide(cat_dialog);
2459 poi_list_free(poi_list);
2462 popup_error(dialog, _("Error parsing GPX file."));
2464 g_free(file_uri_str);
2468 /* Hide the dialog. */
2469 gtk_widget_destroy(dialog);
2471 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2476 poi_download_cat_selected(GtkComboBox *cmb_category, GtkEntry *txt_query)
2479 printf("%s()\n", __PRETTY_FUNCTION__);
2481 if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(cmb_category), &iter))
2483 gchar buffer[BUFFER_SIZE];
2484 GtkWidget *confirm = NULL;
2485 gchar *category = NULL;
2488 gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category)), &iter,
2492 if(*gtk_entry_get_text(txt_query))
2494 snprintf(buffer, sizeof(buffer), "%s\n %s",
2495 _("Overwrite query with the following text?"), category);
2496 confirm = hildon_note_new_confirmation(GTK_WINDOW(_window),buffer);
2501 || GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm)))
2502 gtk_entry_set_text(txt_query, category);
2505 gtk_widget_destroy(confirm);
2508 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2514 origin_type_selected(GtkWidget *toggle, OriginToggleInfo *oti)
2516 printf("%s()\n", __PRETTY_FUNCTION__);
2518 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle)))
2519 gtk_widget_set_sensitive(oti->txt_origin, toggle == oti->rad_use_text);
2521 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2526 poi_download_dialog(gint unitx, gint unity)
2528 static GtkWidget *dialog = NULL;
2529 static GtkWidget *hbox = NULL;
2530 static GtkWidget *table = NULL;
2531 static GtkWidget *table2 = NULL;
2532 static GtkWidget *label = NULL;
2533 static GtkWidget *num_page = NULL;
2534 static GtkWidget *txt_source_url = NULL;
2535 static OriginToggleInfo oti;
2536 static GtkWidget *cmb_category;
2537 printf("%s()\n", __PRETTY_FUNCTION__);
2539 conic_recommend_connected();
2543 GtkEntryCompletion *origin_comp;
2545 dialog = gtk_dialog_new_with_buttons(_("Download POIs"),
2546 GTK_WINDOW(_window), GTK_DIALOG_MODAL,
2547 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
2548 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
2551 /* Enable the help button. */
2553 hildon_help_dialog_help_enable(
2555 ossohelp_dialog_help_enable(
2557 GTK_DIALOG(dialog), HELP_ID_DOWNPOI, _osso);
2559 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
2560 table = gtk_table_new(4, 4, FALSE), TRUE, TRUE, 0);
2563 gtk_table_attach(GTK_TABLE(table),
2564 hbox = gtk_hbox_new(FALSE, 4),
2565 0, 4, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 4);
2566 gtk_box_pack_start(GTK_BOX(hbox),
2567 label = gtk_label_new(_("Source URL")), FALSE, TRUE, 4);
2568 gtk_box_pack_start(GTK_BOX(hbox),
2569 txt_source_url = gtk_entry_new(), TRUE, TRUE, 4);
2572 gtk_table_attach(GTK_TABLE(table),
2573 oti.rad_use_gps = gtk_radio_button_new_with_label(NULL,
2574 _("Use GPS Location")),
2575 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
2577 /* Use End of Route. */
2578 gtk_table_attach(GTK_TABLE(table),
2579 oti.rad_use_route = gtk_radio_button_new_with_label_from_widget(
2580 GTK_RADIO_BUTTON(oti.rad_use_gps), _("Use End of Route")),
2581 0, 1, 2, 3, GTK_FILL, 0, 2, 4);
2584 gtk_table_attach(GTK_TABLE(table),
2585 gtk_vseparator_new(),
2586 1, 2, 1, 3, GTK_FILL, GTK_FILL, 2,4);
2589 gtk_table_attach(GTK_TABLE(table),
2590 label = gtk_label_new(_("Category")),
2591 2, 3, 1, 2, GTK_FILL, 0, 2, 4);
2592 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
2593 gtk_table_attach(GTK_TABLE(table),
2594 cmb_category = poi_create_cat_combo(),
2595 3, 4, 1, 2, GTK_FILL, 0, 2, 4);
2598 gtk_table_attach(GTK_TABLE(table),
2599 label = gtk_label_new(_("Page")),
2600 2, 3, 2, 3, GTK_FILL, 0, 2, 4);
2601 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
2602 gtk_table_attach(GTK_TABLE(table),
2603 num_page = hildon_number_editor_new(1, 999),
2604 3, 4, 2, 3, GTK_FILL, 0, 2, 4);
2607 /* Another table for the Origin and Query. */
2608 gtk_table_attach(GTK_TABLE(table),
2609 table2 = gtk_table_new(2, 2, FALSE),
2610 0, 4, 3, 4, GTK_EXPAND | GTK_FILL, 0, 2, 4);
2613 gtk_table_attach(GTK_TABLE(table2),
2614 oti.rad_use_text = gtk_radio_button_new_with_label_from_widget(
2615 GTK_RADIO_BUTTON(oti.rad_use_gps), _("Origin")),
2616 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
2617 gtk_table_attach(GTK_TABLE(table2),
2618 oti.txt_origin = gtk_entry_new(),
2619 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 4);
2620 gtk_entry_set_width_chars(GTK_ENTRY(oti.txt_origin), 25);
2621 #ifdef MAEMO_CHANGES
2623 g_object_set(G_OBJECT(oti.txt_origin), "hildon-input-mode",
2624 HILDON_GTK_INPUT_MODE_FULL, NULL);
2626 g_object_set(G_OBJECT(oti.txt_origin), HILDON_AUTOCAP, FALSE, NULL);
2631 gtk_table_attach(GTK_TABLE(table2),
2632 label = gtk_label_new(_("Query")),
2633 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
2634 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
2635 gtk_table_attach(GTK_TABLE(table2),
2636 oti.txt_query = gtk_entry_new(),
2637 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
2638 gtk_entry_set_width_chars(GTK_ENTRY(oti.txt_query), 25);
2639 #ifdef MAEMO_CHANGES
2641 g_object_set(G_OBJECT(oti.txt_query), "hildon-input-mode",
2642 HILDON_GTK_INPUT_MODE_FULL, NULL);
2644 g_object_set(G_OBJECT(oti.txt_query), HILDON_AUTOCAP, FALSE, NULL);
2648 /* Set up auto-completion. */
2649 origin_comp = gtk_entry_completion_new();
2650 gtk_entry_completion_set_model(origin_comp,GTK_TREE_MODEL(_loc_model));
2651 gtk_entry_completion_set_text_column(origin_comp, 0);
2652 gtk_entry_set_completion(GTK_ENTRY(oti.txt_origin), origin_comp);
2654 g_signal_connect(G_OBJECT(oti.rad_use_gps), "toggled",
2655 G_CALLBACK(origin_type_selected), &oti);
2656 g_signal_connect(G_OBJECT(oti.rad_use_route), "toggled",
2657 G_CALLBACK(origin_type_selected), &oti);
2658 g_signal_connect(G_OBJECT(oti.rad_use_text), "toggled",
2659 G_CALLBACK(origin_type_selected), &oti);
2661 g_signal_connect(G_OBJECT(cmb_category), "changed",
2662 G_CALLBACK(poi_download_cat_selected), oti.txt_query);
2665 /* Initialize fields. */
2667 hildon_number_editor_set_value(HILDON_NUMBER_EDITOR(num_page), 1);
2669 gtk_entry_set_text(GTK_ENTRY(txt_source_url), _poi_dl_url);
2677 unit2latlon(unitx, unity, lat, lon);
2679 g_ascii_formatd(strlat, 32, "%.06f", lat);
2680 g_ascii_formatd(strlon, 32, "%.06f", lon);
2681 snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
2683 gtk_entry_set_text(GTK_ENTRY(oti.txt_origin), buffer);
2684 gtk_toggle_button_set_active(
2685 GTK_TOGGLE_BUTTON(oti.rad_use_text), TRUE);
2687 /* Else use "End of Route" by default if they have a route. */
2688 else if(_route.head != _route.tail)
2690 /* There is no route, so make it the default. */
2691 gtk_widget_set_sensitive(oti.rad_use_route, TRUE);
2692 gtk_toggle_button_set_active(
2693 GTK_TOGGLE_BUTTON(oti.rad_use_route), TRUE);
2694 gtk_widget_grab_focus(oti.rad_use_route);
2696 /* Else use "GPS Location" if they have GPS enabled. */
2699 /* There is no route, so desensitize "Use End of Route." */
2700 gtk_widget_set_sensitive(oti.rad_use_route, FALSE);
2703 gtk_toggle_button_set_active(
2704 GTK_TOGGLE_BUTTON(oti.rad_use_gps), TRUE);
2705 gtk_widget_grab_focus(oti.rad_use_gps);
2707 /* Else use text. */
2710 gtk_toggle_button_set_active(
2711 GTK_TOGGLE_BUTTON(oti.rad_use_text), TRUE);
2712 gtk_widget_grab_focus(oti.txt_origin);
2716 gtk_widget_show_all(dialog);
2718 while(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
2720 gchar origin_buffer[BUFFER_SIZE];
2721 const gchar *source_url, *origin, *query;
2722 gchar *file_uri_str = NULL;
2723 gchar *bytes = NULL;
2725 GnomeVFSResult vfs_result;
2726 GList *poi_list = NULL;
2728 source_url = gtk_entry_get_text(GTK_ENTRY(txt_source_url));
2729 if(!strlen(source_url))
2731 popup_error(dialog, _("Please specify a source URL."));
2736 g_free(_poi_dl_url);
2737 _poi_dl_url = g_strdup(source_url);
2740 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(oti.rad_use_gps)))
2744 latlon2unit(_gps.lat, _gps.lon, unitx, unity);
2745 g_ascii_formatd(strlat, 32, "%.06f", _gps.lat);
2746 g_ascii_formatd(strlon, 32, "%.06f", _gps.lon);
2747 snprintf(origin_buffer, sizeof(origin_buffer),
2748 "%s, %s", strlat, strlon);
2749 origin = origin_buffer;
2751 else if(gtk_toggle_button_get_active(
2752 GTK_TOGGLE_BUTTON(oti.rad_use_route)))
2759 /* Use last non-zero route point. */
2760 for(p = _route.tail; !p->unity; p--) { }
2764 unit2latlon(p->unitx, p->unity, lat, lon);
2765 g_ascii_formatd(strlat, 32, "%.06f", lat);
2766 g_ascii_formatd(strlon, 32, "%.06f", lon);
2767 snprintf(origin_buffer, sizeof(origin_buffer),
2768 "%s, %s", strlat, strlon);
2769 origin = origin_buffer;
2774 origin = gtk_entry_get_text(GTK_ENTRY(oti.txt_origin));
2777 porig = locate_address(dialog, origin);
2785 popup_error(dialog, _("Please specify an origin."));
2789 if(gtk_combo_box_get_active(GTK_COMBO_BOX(cmb_category)) == -1)
2791 popup_error(dialog, _("Please specify a default category."));
2795 query = gtk_entry_get_text(GTK_ENTRY(oti.txt_query));
2798 popup_error(dialog, _("Please specify a query."));
2802 /* Construct the URL. */
2804 gchar *origin_escaped;
2805 gchar *query_escaped;
2807 origin_escaped = gnome_vfs_escape_string(origin);
2808 query_escaped = gnome_vfs_escape_string(query);
2809 file_uri_str = g_strdup_printf(
2810 source_url, origin_escaped, query_escaped,
2811 hildon_number_editor_get_value(
2812 HILDON_NUMBER_EDITOR(num_page)));
2813 g_free(origin_escaped);
2814 g_free(query_escaped);
2817 /* Parse the given file as GPX. */
2818 if(GNOME_VFS_OK != (vfs_result = gnome_vfs_read_entire_file(
2819 file_uri_str, &size, &bytes)))
2821 popup_error(dialog, gnome_vfs_result_to_string(vfs_result));
2823 else if(strncmp(bytes, "<?xml", strlen("<?xml")))
2825 /* Not an XML document - must be bad locations. */
2826 popup_error(dialog, _("Invalid origin or query."));
2827 printf("bytes: %s\n", bytes);
2829 else if(gpx_poi_parse(bytes, size, &poi_list))
2831 /* Insert the POIs into the database. */
2832 gint num_inserts = poi_list_insert(dialog, poi_list,
2833 GTK_COMBO_BOX(cmb_category));
2837 /* Create a new dialog with the results. */
2838 poi_list_dialog(dialog, unitx, unity, poi_list);
2841 poi_list_free(poi_list);
2844 popup_error(dialog, _("Error parsing GPX file."));
2846 g_free(file_uri_str);
2849 /* Increment the page number for them. */
2850 hildon_number_editor_set_value(HILDON_NUMBER_EDITOR(num_page),
2851 hildon_number_editor_get_value(HILDON_NUMBER_EDITOR(num_page)) +1);
2854 /* Hide the dialog. */
2855 gtk_widget_hide(dialog);
2857 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2862 poi_browse_dialog(gint unitx, gint unity)
2864 static GtkWidget *dialog = NULL;
2865 static GtkWidget *table = NULL;
2866 static GtkWidget *table2 = NULL;
2867 static GtkWidget *label = NULL;
2868 static GtkWidget *cmb_category = NULL;
2869 static OriginToggleInfo oti;
2870 printf("%s()\n", __PRETTY_FUNCTION__);
2874 GtkEntryCompletion *origin_comp;
2876 dialog = gtk_dialog_new_with_buttons(_("Browse POIs"),
2877 GTK_WINDOW(_window), GTK_DIALOG_MODAL,
2878 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
2879 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
2882 /* Enable the help button. */
2884 hildon_help_dialog_help_enable(
2886 ossohelp_dialog_help_enable(
2888 GTK_DIALOG(dialog), HELP_ID_BROWSEPOI, _osso);
2890 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
2891 table = gtk_table_new(3, 4, FALSE), TRUE, TRUE, 0);
2894 gtk_table_attach(GTK_TABLE(table),
2895 oti.rad_use_gps = gtk_radio_button_new_with_label(NULL,
2896 _("Use GPS Location")),
2897 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
2899 /* Use End of Route. */
2900 gtk_table_attach(GTK_TABLE(table),
2901 oti.rad_use_route = gtk_radio_button_new_with_label_from_widget(
2902 GTK_RADIO_BUTTON(oti.rad_use_gps), _("Use End of Route")),
2903 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
2905 gtk_table_attach(GTK_TABLE(table),
2906 gtk_vseparator_new(),
2907 1, 2, 0, 2, GTK_FILL, GTK_FILL, 2, 4);
2910 gtk_table_attach(GTK_TABLE(table),
2911 label = gtk_label_new(_("Category")),
2912 2, 3, 0, 1, GTK_FILL, 0, 2, 4);
2913 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
2914 gtk_table_attach(GTK_TABLE(table),
2915 cmb_category = poi_create_cat_combo(),
2916 3, 4, 0, 1, GTK_FILL, 0, 2, 4);
2917 /* Add an extra, "<any>" category. */
2920 GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(
2921 GTK_COMBO_BOX(cmb_category)));
2922 gtk_list_store_prepend(store, &iter);
2923 gtk_list_store_set(store, &iter, 0, -1, 1, "<any>", -1);
2924 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(cmb_category), &iter);
2928 /* Another table for the Origin and Query. */
2929 gtk_table_attach(GTK_TABLE(table),
2930 table2 = gtk_table_new(2, 2, FALSE),
2931 0, 4, 2, 3, GTK_EXPAND | GTK_FILL, 0, 2, 4);
2934 gtk_table_attach(GTK_TABLE(table2),
2935 oti.rad_use_text = gtk_radio_button_new_with_label_from_widget(
2936 GTK_RADIO_BUTTON(oti.rad_use_gps), _("Origin")),
2937 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
2938 gtk_table_attach(GTK_TABLE(table2),
2939 oti.txt_origin = gtk_entry_new(),
2940 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 4);
2941 gtk_entry_set_width_chars(GTK_ENTRY(oti.txt_origin), 25);
2942 #ifdef MAEMO_CHANGES
2944 g_object_set(G_OBJECT(oti.txt_origin), "hildon-input-mode",
2945 HILDON_GTK_INPUT_MODE_FULL, NULL);
2947 g_object_set(G_OBJECT(oti.txt_origin), HILDON_AUTOCAP, FALSE, NULL);
2952 gtk_table_attach(GTK_TABLE(table2),
2953 label = gtk_label_new(_("Query")),
2954 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
2955 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
2956 gtk_table_attach(GTK_TABLE(table2),
2957 oti.txt_query = gtk_entry_new(),
2958 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
2959 gtk_entry_set_width_chars(GTK_ENTRY(oti.txt_query), 25);
2960 #ifdef MAEMO_CHANGES
2962 g_object_set(G_OBJECT(oti.txt_query), "hildon-input-mode",
2963 HILDON_GTK_INPUT_MODE_FULL, NULL);
2965 g_object_set(G_OBJECT(oti.txt_query), HILDON_AUTOCAP, FALSE, NULL);
2969 /* Set up auto-completion. */
2970 origin_comp = gtk_entry_completion_new();
2971 gtk_entry_completion_set_model(origin_comp,GTK_TREE_MODEL(_loc_model));
2972 gtk_entry_completion_set_text_column(origin_comp, 0);
2973 gtk_entry_set_completion(GTK_ENTRY(oti.txt_origin), origin_comp);
2975 g_signal_connect(G_OBJECT(oti.rad_use_gps), "toggled",
2976 G_CALLBACK(origin_type_selected), &oti);
2977 g_signal_connect(G_OBJECT(oti.rad_use_route), "toggled",
2978 G_CALLBACK(origin_type_selected), &oti);
2979 g_signal_connect(G_OBJECT(oti.rad_use_text), "toggled",
2980 G_CALLBACK(origin_type_selected), &oti);
2983 /* Initialize fields. */
2992 unit2latlon(unitx, unity, lat, lon);
2994 g_ascii_formatd(strlat, 32, "%.06f", lat);
2995 g_ascii_formatd(strlon, 32, "%.06f", lon);
2996 snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
2998 gtk_entry_set_text(GTK_ENTRY(oti.txt_origin), buffer);
2999 gtk_toggle_button_set_active(
3000 GTK_TOGGLE_BUTTON(oti.rad_use_text), TRUE);
3002 /* Else use "End of Route" by default if they have a route. */
3003 else if(_route.head != _route.tail)
3005 /* There is no route, so make it the default. */
3006 gtk_widget_set_sensitive(oti.rad_use_route, TRUE);
3007 gtk_toggle_button_set_active(
3008 GTK_TOGGLE_BUTTON(oti.rad_use_route), TRUE);
3009 gtk_widget_grab_focus(oti.rad_use_route);
3011 /* Else use "GPS Location" if they have GPS enabled. */
3014 /* There is no route, so desensitize "Use End of Route." */
3015 gtk_widget_set_sensitive(oti.rad_use_route, FALSE);
3018 gtk_toggle_button_set_active(
3019 GTK_TOGGLE_BUTTON(oti.rad_use_gps), TRUE);
3020 gtk_widget_grab_focus(oti.rad_use_gps);
3022 /* Else use text. */
3025 gtk_toggle_button_set_active(
3026 GTK_TOGGLE_BUTTON(oti.rad_use_text), TRUE);
3027 gtk_widget_grab_focus(oti.txt_origin);
3031 gtk_widget_show_all(dialog);
3033 while(gtk_dialog_run(GTK_DIALOG(dialog)) ==GTK_RESPONSE_ACCEPT)
3035 gchar buffer[BUFFER_SIZE];
3036 const gchar *origin, *query;
3038 GList *poi_list = NULL;
3040 gboolean is_cat = FALSE;
3043 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(oti.rad_use_gps)))
3047 latlon2unit(_gps.lat, _gps.lon, unitx, unity);
3048 g_ascii_formatd(strlat, 32, "%.06f", _gps.lat);
3049 g_ascii_formatd(strlon, 32, "%.06f", _gps.lon);
3050 snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
3053 else if(gtk_toggle_button_get_active(
3054 GTK_TOGGLE_BUTTON(oti.rad_use_route)))
3061 /* Use last non-zero route point. */
3062 for(p = _route.tail; !p->unity; p--) { }
3066 unit2latlon(p->unitx, p->unity, lat, lon);
3067 g_ascii_formatd(strlat, 32, "%.06f", lat);
3068 g_ascii_formatd(strlon, 32, "%.06f", lon);
3069 snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
3075 origin = gtk_entry_get_text(GTK_ENTRY(oti.txt_origin));
3076 porig = locate_address(dialog, origin);
3083 popup_error(dialog, _("Please specify an origin."));
3087 /* Check if we're doing a category search. */
3090 if(gtk_combo_box_get_active_iter(
3091 GTK_COMBO_BOX(cmb_category), &iter))
3094 gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category)),
3095 &iter, 0, &cat_id, -1);
3103 query = g_strdup_printf("%%%s%%",
3104 gtk_entry_get_text(GTK_ENTRY(oti.txt_query)));
3106 unit2latlon(unitx, unity, lat, lon);
3110 if(SQLITE_OK != sqlite3_bind_int(_stmt_browsecat_poi, 1, cat_id) ||
3111 SQLITE_OK != sqlite3_bind_text(_stmt_browsecat_poi, 2, query,
3113 SQLITE_OK != sqlite3_bind_double(_stmt_browsecat_poi, 3, lat) ||
3114 SQLITE_OK != sqlite3_bind_double(_stmt_browsecat_poi, 4, lon))
3116 g_printerr("Failed to bind values for _stmt_browsecat_poi\n");
3119 stmt = _stmt_browsecat_poi;
3123 if(SQLITE_OK != sqlite3_bind_text(_stmt_browse_poi, 1, query,
3125 SQLITE_OK != sqlite3_bind_double(_stmt_browse_poi, 2, lat) ||
3126 SQLITE_OK != sqlite3_bind_double(_stmt_browse_poi, 3, lon))
3128 g_printerr("Failed to bind values for _stmt_browse_poi\n");
3131 stmt = _stmt_browse_poi;
3134 while(SQLITE_ROW == sqlite3_step(stmt))
3136 PoiInfo *poi = g_slice_new(PoiInfo);
3137 poi->poi_id = sqlite3_column_int(stmt, 0);
3138 poi->cat_id = sqlite3_column_int(stmt, 1);
3139 poi->lat = sqlite3_column_double(stmt, 2);
3140 poi->lon = sqlite3_column_double(stmt, 3);
3141 poi->label =g_strdup(sqlite3_column_text(stmt, 4));
3142 poi->desc = g_strdup(sqlite3_column_text(stmt, 5));
3143 poi->clabel=g_strdup(sqlite3_column_text(stmt, 6));
3144 poi_list = g_list_prepend(poi_list, poi);
3146 sqlite3_reset(stmt);
3150 /* Create a new dialog with the results. */
3151 poi_list_dialog(dialog, unitx, unity, poi_list);
3152 poi_list_free(poi_list);
3155 popup_error(dialog, _("No POIs found."));
3160 /* Hide the dialog. */
3161 gtk_widget_hide(dialog);
3163 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
3168 * Render all the POI data. This should be done before rendering track data.
3174 gdouble lat1, lat2, lon1, lon2;
3177 GdkPixbuf *pixbuf = NULL;
3178 GError *error = NULL;
3179 printf("%s()\n", __PRETTY_FUNCTION__);
3181 if(_poi_db && _poi_zoom > _zoom)
3183 gint diag_offset = pixel2unit(MAX(_view_width_pixels,
3184 _view_height_pixels) / 2);
3185 buf2unit(0, _view_height_pixels, unitx, unity);
3186 unitx = _center.unitx - diag_offset;
3187 unity = _center.unity + diag_offset;
3188 unit2latlon(unitx, unity, lat1, lon1);
3189 unitx = _center.unitx + diag_offset;
3190 unity = _center.unity - diag_offset;
3191 unit2latlon(unitx, unity, lat2, lon2);
3193 if(SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 1, lat1) ||
3194 SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 2, lat2) ||
3195 SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 3, lon1) ||
3196 SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 4, lon2))
3198 g_printerr("Failed to bind values for _stmt_select_poi\n");
3202 while(SQLITE_ROW == sqlite3_step(_stmt_select_poi))
3204 lat1 = sqlite3_column_double(_stmt_select_poi, 0);
3205 lon1 = sqlite3_column_double(_stmt_select_poi, 1);
3206 gchar *poi_label = g_utf8_strdown(sqlite3_column_text(
3207 _stmt_select_poi, 3), -1);
3208 gchar *cat_label = g_utf8_strdown(sqlite3_column_text(
3209 _stmt_select_poi, 6), -1);
3211 latlon2unit(lat1, lon1, unitx, unity);
3212 unit2buf(unitx, unity, poix, poiy);
3214 /* Try to get icon for specific POI first. */
3215 snprintf(buffer, sizeof(buffer), "%s/%s.jpg",
3216 _poi_db_dirname, poi_label);
3217 pixbuf = gdk_pixbuf_new_from_file(buffer, &error);
3220 /* No icon for specific POI - try for category. */
3222 snprintf(buffer, sizeof(buffer), "%s/%s.jpg",
3223 _poi_db_dirname, cat_label);
3224 pixbuf = gdk_pixbuf_new_from_file(buffer, &error);
3228 /* No icon for POI or for category.
3229 * Try default POI icon file. */
3231 snprintf(buffer, sizeof(buffer), "%s/poi.jpg",
3233 pixbuf = gdk_pixbuf_new_from_file(buffer, &error);
3237 /* No icon for POI or for category or default POI icon file.
3238 Draw default purple square. */
3240 gdk_draw_rectangle(_map_pixmap, _gc[COLORABLE_POI], TRUE,
3241 poix - (gint)(1.5f * _draw_width),
3242 poiy - (gint)(1.5f * _draw_width),
3248 /* We found an icon to draw. */
3254 poix - gdk_pixbuf_get_width(pixbuf) / 2,
3255 poiy - gdk_pixbuf_get_height(pixbuf) / 2,
3257 GDK_RGB_DITHER_NONE, 0, 0);
3258 g_object_unref(pixbuf);
3264 sqlite3_reset(_stmt_select_poi);
3267 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
3273 printf("%s()\n", __PRETTY_FUNCTION__);
3277 sqlite3_close(_poi_db);
3281 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
3285 extern AprsDataRow *n_first; // pointer to first element in name sorted station list
3288 /////////////////////
3291 * Render all the APRS data.
3297 printf("%s()\n", __PRETTY_FUNCTION__);
3300 if(_poi_zoom > _zoom)
3303 AprsDataRow *p_station = n_first;
3305 while ( (p_station) != NULL)
3307 if( p_station->coord_lat != 0.0f
3308 || p_station->coord_lon != 0.0f )
3310 plot_aprs_station( p_station, FALSE);
3313 (p_station) = (p_station)->n_next; // Next element in list
3314 } // End of while loop
3317 } // check for zoom level
3319 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
3322 #endif // INCLUDE_APRS