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",
232 -1, &_stmt_browse_poi, NULL);
234 /* browse poi by category */
235 sqlite3_prepare(_poi_db,
236 "select p.poi_id, p.cat_id, p.lat, p.lon,"
237 " p.label, p.desc, c.label"
238 " from poi p inner join category c"
239 " on p.cat_id = c.cat_id"
240 " where c.enabled = 1"
241 " and p.cat_id = $CATID"
242 " and ( p.label like $QUERY or p.desc like $QUERY )"
243 " order by (($LAT - p.lat) * ($LAT - p.lat) "
244 "+ ($LON - p.lon) * ($LON - p.lon)) DESC",
245 -1, &_stmt_browsecat_poi, NULL);
247 /* Prepare our SQL statements. */
248 /* select from poi */
249 sqlite3_prepare(_poi_db,
250 "select p.lat, p.lon, p.poi_id, p.label, p.desc,"
251 " p.cat_id, c.label, c.desc"
252 " from poi p inner join category c"
253 " on p.cat_id = c.cat_id"
254 " where c.enabled = 1"
255 " and p.lat between ? and ? "
256 " and p.lon between ? and ? ",
257 -1, &_stmt_select_poi, NULL);
259 /* select nearest pois */
260 sqlite3_prepare(_poi_db,
261 "select p.poi_id, p.cat_id, p.lat, p.lon,"
262 " p.label, p.desc, c.label"
263 " from poi p inner join category c"
264 " on p.cat_id = c.cat_id"
265 " where c.enabled = 1"
266 " order by (($LAT - p.lat) * ($LAT - p.lat) "
267 "+ ($LON - p.lon) * ($LON - p.lon)) limit 1",
268 -1, &_stmt_select_nearest_poi, NULL);
271 sqlite3_prepare(_poi_db,
272 "insert into poi (lat, lon, label, desc, cat_id)"
273 " values (?, ?, ?, ?, ?)",
274 -1, &_stmt_insert_poi, NULL);
276 sqlite3_prepare(_poi_db,
277 "update poi set lat = ?, lon = ?, "
278 "label = ?, desc = ?, cat_id = ? where poi_id = ?",
279 -1, &_stmt_update_poi, NULL);
280 /* delete from poi */
281 sqlite3_prepare(_poi_db,
282 " delete from poi where poi_id = ?",
283 -1, &_stmt_delete_poi, NULL);
284 /* delete from poi by cat_id */
285 sqlite3_prepare(_poi_db,
286 "delete from poi where cat_id = ?",
287 -1, &_stmt_delete_poi_by_catid, NULL);
288 /* get next poilabel */
289 sqlite3_prepare(_poi_db,
290 "select ifnull(max(poi_id) + 1,1) from poi",
291 -1, &_stmt_nextlabel_poi, NULL);
293 /* select from category */
294 sqlite3_prepare(_poi_db,
295 "select c.label, c.desc, c.enabled"
296 " from category c where c.cat_id = ?",
297 -1, &_stmt_select_cat, NULL);
298 /* insert into category */
299 sqlite3_prepare(_poi_db,
300 "insert into category (label, desc, enabled)"
302 -1, &_stmt_insert_cat, NULL);
303 /* update category */
304 sqlite3_prepare(_poi_db,
305 "update category set label = ?, desc = ?,"
306 " enabled = ? where cat_id = ?",
307 -1, &_stmt_update_cat, NULL);
308 /* delete from category */
309 sqlite3_prepare(_poi_db,
310 "delete from category where cat_id = ?",
311 -1, &_stmt_delete_cat, NULL);
312 /* enable category */
313 sqlite3_prepare(_poi_db,
314 "update category set enabled = ?"
316 -1, &_stmt_toggle_cat, NULL);
317 /* select all category */
318 sqlite3_prepare(_poi_db,
319 "select c.cat_id, c.label, c.desc, c.enabled,"
322 " left outer join poi p on c.cat_id = p.cat_id"
323 " group by c.cat_id, c.label, c.desc, c.enabled "
325 -1, &_stmt_selall_cat, NULL);
328 _poi_enabled = _poi_db != NULL;
330 gtk_widget_set_sensitive(_menu_poi_item, _poi_enabled);
331 gtk_widget_set_sensitive(_cmenu_loc_add_poi_item, _poi_enabled);
332 gtk_widget_set_sensitive(_cmenu_loc_download_poi_item, _poi_enabled);
333 gtk_widget_set_sensitive(_cmenu_loc_browse_poi_item, _poi_enabled);
334 gtk_widget_set_sensitive(_cmenu_way_add_poi_item, _poi_enabled);
335 gtk_widget_set_sensitive(_cmenu_poi_submenu, _poi_enabled);
337 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
341 get_nearest_poi(gint unitx, gint unity, PoiInfo *poi)
343 printf("%s(%d, %d)\n", __PRETTY_FUNCTION__, unitx, unity);
346 unit2latlon(unitx, unity, lat, lon);
348 if(SQLITE_OK == sqlite3_bind_double(_stmt_select_nearest_poi, 1, lat)
349 && SQLITE_OK == sqlite3_bind_double(_stmt_select_nearest_poi, 2, lon)
350 && SQLITE_ROW == sqlite3_step(_stmt_select_nearest_poi))
352 poi->poi_id = sqlite3_column_int(_stmt_select_nearest_poi, 0);
353 poi->cat_id = sqlite3_column_int(_stmt_select_nearest_poi, 1);
354 poi->lat = sqlite3_column_double(_stmt_select_nearest_poi, 2);
355 poi->lon = sqlite3_column_double(_stmt_select_nearest_poi, 3);
356 poi->label =g_strdup(sqlite3_column_text(_stmt_select_nearest_poi, 4));
357 poi->desc = g_strdup(sqlite3_column_text(_stmt_select_nearest_poi, 5));
358 poi->clabel=g_strdup(sqlite3_column_text(_stmt_select_nearest_poi, 6));
363 sqlite3_reset(_stmt_select_nearest_poi);
364 vprintf("%s(): return %d\n", __PRETTY_FUNCTION__, result);
369 select_poi(gint unitx, gint unity, PoiInfo *poi, gboolean quick)
372 gdouble lat1, lon1, lat2, lon2;
373 static GtkWidget *dialog = NULL;
374 static GtkWidget *list = NULL;
375 static GtkWidget *sw = NULL;
376 static GtkTreeViewColumn *column = NULL;
377 static GtkCellRenderer *renderer = NULL;
378 GtkListStore *store = NULL;
380 gboolean selected = FALSE;
381 gchar tmp1[LL_FMT_LEN], tmp2[LL_FMT_LEN];
383 printf("%s()\n", __PRETTY_FUNCTION__);
385 x = unitx - pixel2unit(3 * _draw_width);
386 y = unity + pixel2unit(3 * _draw_width);
387 unit2latlon(x, y, lat1, lon1);
389 x = unitx + pixel2unit(3 * _draw_width);
390 y = unity - pixel2unit(3 * _draw_width);
391 unit2latlon(x, y, lat2, lon2);
393 if(SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 1, lat1) ||
394 SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 2, lat2) ||
395 SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 3, lon1) ||
396 SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 4, lon2))
398 g_printerr("Failed to bind values for _stmt_select_poi\n");
402 /* Initialize store. */
403 store = gtk_list_store_new(POI_NUM_COLUMNS,
404 G_TYPE_BOOLEAN,/* Selected */
405 G_TYPE_INT, /* POI ID */
406 G_TYPE_INT, /* Category ID */
407 G_TYPE_DOUBLE, /* Latitude */
408 G_TYPE_DOUBLE, /* Longitude */
409 G_TYPE_STRING, /* Lat/Lon */
410 G_TYPE_FLOAT, /* Bearing */
411 G_TYPE_FLOAT, /* Distance */
412 G_TYPE_STRING, /* POI Label */
413 G_TYPE_STRING, /* POI Desc. */
414 G_TYPE_STRING);/* Category Label */
416 while(SQLITE_ROW == sqlite3_step(_stmt_select_poi))
419 lat = sqlite3_column_double(_stmt_select_poi, 0);
420 lon = sqlite3_column_double(_stmt_select_poi, 1);
421 lat_format(lat, tmp1);
422 lon_format(lon, tmp2);
423 gtk_list_store_append(store, &iter);
424 gtk_list_store_set(store, &iter,
425 POI_POIID, sqlite3_column_int(_stmt_select_poi, 2),
426 POI_CATID, sqlite3_column_int(_stmt_select_poi, 5),
429 POI_LATLON, g_strdup_printf("%s, %s", tmp1, tmp2),
430 POI_LABEL, sqlite3_column_text(_stmt_select_poi, 3),
431 POI_DESC, sqlite3_column_text(_stmt_select_poi, 4),
432 POI_CLABEL, sqlite3_column_text(_stmt_select_poi, 6),
436 sqlite3_reset(_stmt_select_poi);
441 g_object_unref(G_OBJECT(store));
444 MACRO_BANNER_SHOW_INFO(_window, _("No POIs found."));
449 /* iter is still set to the most-recently added POI. */
450 gtk_tree_model_get(GTK_TREE_MODEL(store),
452 POI_POIID, &(poi->poi_id),
453 POI_CATID, &(poi->cat_id),
454 POI_LAT, &(poi->lat),
455 POI_LON, &(poi->lon),
456 POI_LABEL, &(poi->label),
457 POI_DESC, &(poi->desc),
458 POI_CLABEL, &(poi->clabel),
460 g_object_unref(G_OBJECT(store));
466 g_object_unref(G_OBJECT(store));
467 return get_nearest_poi(unitx, unity, poi);
471 /* There are at least 2 matching POI's - let the user select one. */
474 dialog = gtk_dialog_new_with_buttons(_("Select POI"),
475 GTK_WINDOW(_window), GTK_DIALOG_MODAL,
476 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
477 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
480 gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 300);
482 sw = gtk_scrolled_window_new (NULL, NULL);
483 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
484 GTK_SHADOW_ETCHED_IN);
485 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
487 GTK_POLICY_AUTOMATIC);
488 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
491 list = gtk_tree_view_new();
492 gtk_container_add(GTK_CONTAINER(sw), list);
494 gtk_tree_selection_set_mode(
495 gtk_tree_view_get_selection(GTK_TREE_VIEW(list)),
496 GTK_SELECTION_SINGLE);
497 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list), TRUE);
499 renderer = gtk_cell_renderer_text_new();
500 column = gtk_tree_view_column_new_with_attributes(
501 _("Location"), renderer, "text", POI_LATLON, NULL);
502 gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
504 renderer = gtk_cell_renderer_text_new();
505 column = gtk_tree_view_column_new_with_attributes(
506 _("Label"), renderer, "text", POI_LABEL, NULL);
507 gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
509 renderer = gtk_cell_renderer_text_new();
510 column = gtk_tree_view_column_new_with_attributes(
511 _("Category"), renderer, "text", POI_CLABEL, NULL);
512 gtk_tree_view_append_column(GTK_TREE_VIEW(list), column);
515 gtk_tree_view_set_model(GTK_TREE_VIEW(list), GTK_TREE_MODEL(store));
516 g_object_unref(G_OBJECT(store));
518 gtk_widget_show_all(dialog);
520 while(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog)))
522 if(gtk_tree_selection_get_selected(
523 gtk_tree_view_get_selection(GTK_TREE_VIEW(list)),
526 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
527 POI_POIID, &(poi->poi_id),
528 POI_CATID, &(poi->cat_id),
529 POI_LAT, &(poi->lat),
530 POI_LON, &(poi->lon),
531 POI_LABEL, &(poi->label),
532 POI_DESC, &(poi->desc),
533 POI_CLABEL, &(poi->clabel),
539 popup_error(dialog, _("Select one POI from the list."));
544 gtk_widget_hide(dialog);
546 vprintf("%s(): return %d\n", __PRETTY_FUNCTION__, selected);
551 category_delete(GtkWidget *widget, DeletePOI *dpoi)
556 printf("%s()\n", __PRETTY_FUNCTION__);
558 buffer = g_strdup_printf("%s\n\t%s\n%s",
559 _("Delete category?"),
561 _("WARNING: All POIs in that category will also be deleted!"));
562 confirm = hildon_note_new_confirmation(GTK_WINDOW(dpoi->dialog), buffer);
564 i = gtk_dialog_run(GTK_DIALOG(confirm));
565 gtk_widget_destroy(GTK_WIDGET(confirm));
567 if(i == GTK_RESPONSE_OK)
569 /* delete dpoi->poi_id */
570 if(SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi_by_catid, 1,
572 SQLITE_DONE != sqlite3_step(_stmt_delete_poi_by_catid))
574 MACRO_BANNER_SHOW_INFO(dpoi->dialog, _("Error deleting POI"));
575 sqlite3_reset(_stmt_delete_poi_by_catid);
578 sqlite3_reset(_stmt_delete_poi_by_catid);
580 if(SQLITE_OK != sqlite3_bind_int(_stmt_delete_cat, 1, dpoi->id) ||
581 SQLITE_DONE != sqlite3_step(_stmt_delete_cat))
583 MACRO_BANNER_SHOW_INFO(dpoi->dialog, _("Error deleting category"));
584 sqlite3_reset(_stmt_delete_cat);
587 sqlite3_reset(_stmt_delete_cat);
591 gtk_widget_destroy(confirm);
593 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
598 category_edit_dialog(GtkWidget *parent, gint cat_id)
600 gchar *cat_label = NULL, *cat_desc = NULL;
605 GtkWidget *txt_label;
607 GtkWidget *btn_delete = NULL;
608 GtkWidget *txt_scroll;
609 GtkWidget *chk_enabled;
610 GtkTextBuffer *desc_txt;
611 GtkTextIter begin, end;
612 gboolean results = TRUE;
613 DeletePOI dpoi = {NULL, NULL, 0};
614 printf("%s()\n", __PRETTY_FUNCTION__);
618 if(SQLITE_OK != sqlite3_bind_double(_stmt_select_cat, 1, cat_id) ||
619 SQLITE_ROW != sqlite3_step(_stmt_select_cat))
621 vprintf("%s(): return FALSE\n", __PRETTY_FUNCTION__);
622 sqlite3_reset(_stmt_select_cat);
626 cat_label = g_strdup(sqlite3_column_text(_stmt_select_cat, 0));
627 cat_desc = g_strdup(sqlite3_column_text(_stmt_select_cat, 1));
628 cat_enabled = sqlite3_column_int(_stmt_select_cat, 2);
630 sqlite3_reset(_stmt_select_cat);
632 dialog = gtk_dialog_new_with_buttons(_("Edit Category"),
633 GTK_WINDOW(parent), GTK_DIALOG_MODAL,
634 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
637 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
638 btn_delete = gtk_button_new_with_label(_("Delete...")));
640 dpoi.dialog = dialog;
641 dpoi.txt_label = g_strdup(cat_label);
643 dpoi.deleted = FALSE;
645 g_signal_connect(G_OBJECT(btn_delete), "clicked",
646 G_CALLBACK(category_delete), &dpoi);
648 gtk_dialog_add_button(GTK_DIALOG(dialog),
649 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
654 cat_label = g_strdup("");
656 cat_desc = g_strdup("");
658 dialog = gtk_dialog_new_with_buttons(_("Add Category"),
659 GTK_WINDOW(parent), GTK_DIALOG_MODAL,
660 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
661 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
665 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
666 table = gtk_table_new(6, 4, FALSE), TRUE, TRUE, 0);
668 gtk_table_attach(GTK_TABLE(table),
669 label = gtk_label_new(_("Label")),
670 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
671 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
672 gtk_table_attach(GTK_TABLE(table),
673 txt_label = gtk_entry_new(),
674 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 4);
676 gtk_table_attach(GTK_TABLE(table),
677 label = gtk_label_new(_("Description")),
678 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
679 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
681 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
682 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
684 gtk_table_attach(GTK_TABLE(table),
686 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
688 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
689 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
691 txt_desc = gtk_text_view_new();
692 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
694 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
695 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60);
697 desc_txt = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc));
699 gtk_table_attach(GTK_TABLE(table),
700 chk_enabled = gtk_check_button_new_with_label(
702 0, 2, 2, 3, GTK_EXPAND | GTK_FILL, 0, 2, 4);
705 gtk_entry_set_text(GTK_ENTRY(txt_label), cat_label);
708 gtk_text_buffer_set_text(desc_txt, cat_desc, -1);
711 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk_enabled),
712 (cat_enabled == 1 ? TRUE : FALSE));
719 gtk_widget_show_all(dialog);
721 while(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog)))
723 if(strlen(gtk_entry_get_text(GTK_ENTRY(txt_label))))
724 cat_label = g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_label)));
727 popup_error(dialog, _("Please specify a name for the category."));
731 gtk_text_buffer_get_iter_at_offset(desc_txt, &begin,0 );
732 gtk_text_buffer_get_end_iter (desc_txt, &end);
733 cat_desc = gtk_text_buffer_get_text(desc_txt, &begin, &end, TRUE);
735 cat_enabled = (gtk_toggle_button_get_active(
736 GTK_TOGGLE_BUTTON(chk_enabled)) ? 1 : 0);
741 if(SQLITE_OK != sqlite3_bind_text(_stmt_update_cat, 1, cat_label,
743 SQLITE_OK != sqlite3_bind_text(_stmt_update_cat, 2, cat_desc,
745 SQLITE_OK != sqlite3_bind_int(_stmt_update_cat, 3,cat_enabled)||
746 SQLITE_OK != sqlite3_bind_int(_stmt_update_cat, 4, cat_id) ||
747 SQLITE_DONE != sqlite3_step(_stmt_update_cat))
749 MACRO_BANNER_SHOW_INFO(parent,_("Error updating category"));
752 sqlite3_reset(_stmt_update_cat);
757 if(SQLITE_OK != sqlite3_bind_text(_stmt_insert_cat, 1, cat_label,
759 SQLITE_OK != sqlite3_bind_text(_stmt_insert_cat, 2, cat_desc,
761 SQLITE_OK != sqlite3_bind_int(_stmt_insert_cat, 3,cat_enabled)||
762 SQLITE_DONE != sqlite3_step(_stmt_insert_cat))
764 MACRO_BANNER_SHOW_INFO(parent, _("Error adding category"));
767 sqlite3_reset(_stmt_insert_cat);
772 g_free(dpoi.txt_label);
774 g_object_unref (desc_txt);
779 gtk_widget_hide(dialog);
781 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
786 category_toggled(GtkCellRendererToggle *cell, gchar *path, GtkListStore *data)
789 gboolean cat_enabled;
791 printf("%s()\n", __PRETTY_FUNCTION__);
793 GtkTreeModel *model = GTK_TREE_MODEL(data);
794 if( !gtk_tree_model_get_iter_from_string(model, &iter, path) )
797 gtk_tree_model_get(model, &iter,
798 CAT_ENABLED, &cat_enabled,
804 if(SQLITE_OK != sqlite3_bind_int(_stmt_toggle_cat, 1, cat_enabled) ||
805 SQLITE_OK != sqlite3_bind_int(_stmt_toggle_cat, 2, cat_id) ||
806 SQLITE_DONE != sqlite3_step(_stmt_toggle_cat))
808 MACRO_BANNER_SHOW_INFO(_window, _("Error updating Category"));
812 gtk_list_store_set(GTK_LIST_STORE(model), &iter,
813 CAT_ENABLED, cat_enabled, -1);
817 sqlite3_reset(_stmt_toggle_cat);
819 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
827 printf("%s()\n", __PRETTY_FUNCTION__);
829 store = gtk_list_store_new(CAT_NUM_COLUMNS,
836 while(SQLITE_ROW == sqlite3_step(_stmt_selall_cat))
838 gtk_list_store_append(store, &iter);
839 gtk_list_store_set(store, &iter,
840 CAT_ID, sqlite3_column_int(_stmt_selall_cat, 0),
841 CAT_ENABLED, sqlite3_column_int(_stmt_selall_cat, 3),
842 CAT_LABEL, sqlite3_column_text(_stmt_selall_cat, 1),
843 CAT_DESC, sqlite3_column_text(_stmt_selall_cat, 2),
844 CAT_POI_CNT, sqlite3_column_int(_stmt_selall_cat, 4),
847 sqlite3_reset(_stmt_selall_cat);
849 vprintf("%s(): return %p\n", __PRETTY_FUNCTION__, store);
854 category_add(GtkWidget *widget, PoiCategoryEditInfo *pcedit)
857 printf("%s()\n", __PRETTY_FUNCTION__);
859 if(category_edit_dialog(pcedit->dialog, 0))
861 store = generate_store();
862 gtk_tree_view_set_model(
863 GTK_TREE_VIEW(pcedit->tree_view),
864 GTK_TREE_MODEL(store));
865 g_object_unref(G_OBJECT(store));
867 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
872 category_edit(GtkWidget *widget, PoiCategoryEditInfo *pcedit)
876 GtkTreeSelection *selection;
877 printf("%s()\n", __PRETTY_FUNCTION__);
879 store = gtk_tree_view_get_model(GTK_TREE_VIEW(pcedit->tree_view));
880 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pcedit->tree_view));
881 if(gtk_tree_selection_get_selected(selection, &store, &iter))
884 memset(&val, 0, sizeof(val));
885 gtk_tree_model_get_value(store, &iter, 0, &val);
886 if(category_edit_dialog(pcedit->dialog, g_value_get_uint(&val)))
888 GtkListStore *new_store = generate_store();
889 gtk_tree_view_set_model(
890 GTK_TREE_VIEW(pcedit->tree_view),
891 GTK_TREE_MODEL(new_store));
892 g_object_unref(G_OBJECT(new_store));
895 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
900 category_list_dialog(GtkWidget *parent)
902 static GtkWidget *dialog = NULL;
903 static GtkWidget *tree_view = NULL;
904 static GtkWidget *sw = NULL;
905 static GtkWidget *btn_edit = NULL;
906 static GtkWidget *btn_add = NULL;
907 static GtkTreeViewColumn *column = NULL;
908 static GtkCellRenderer *renderer = NULL;
909 static GtkListStore *store;
910 static PoiCategoryEditInfo pcedit;
911 printf("%s()\n", __PRETTY_FUNCTION__);
913 store = generate_store();
918 dialog = gtk_dialog_new_with_buttons(_("POI Categories"),
919 GTK_WINDOW(parent), GTK_DIALOG_MODAL,
920 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
923 /* Enable the help button. */
925 hildon_help_dialog_help_enable(
927 ossohelp_dialog_help_enable(
929 GTK_DIALOG(dialog), HELP_ID_POICAT, _osso);
931 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
932 btn_edit = gtk_button_new_with_label(_("Edit...")));
934 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
935 btn_add = gtk_button_new_with_label(_("Add...")));
937 sw = gtk_scrolled_window_new(NULL, NULL);
938 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (sw),
940 GTK_POLICY_AUTOMATIC);
941 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
944 tree_view = gtk_tree_view_new();
946 g_object_set(tree_view, "allow-checkbox-mode", FALSE, NULL);
947 gtk_container_add (GTK_CONTAINER (sw), tree_view);
949 gtk_tree_selection_set_mode(
950 gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)),
951 GTK_SELECTION_SINGLE);
952 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_view), TRUE);
954 renderer = gtk_cell_renderer_text_new();
955 column = gtk_tree_view_column_new_with_attributes(
956 _("ID"), renderer, "text", CAT_ID, NULL);
957 gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
958 gtk_tree_view_column_set_max_width (column, 1);
960 renderer = gtk_cell_renderer_toggle_new();
961 g_signal_connect (renderer, "toggled",
962 G_CALLBACK (category_toggled), store);
963 column = gtk_tree_view_column_new_with_attributes(
964 _("Enabled"), renderer, "active", CAT_ENABLED, NULL);
965 gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
967 renderer = gtk_cell_renderer_text_new();
968 column = gtk_tree_view_column_new_with_attributes(
969 _("Label"), renderer, "text", CAT_LABEL, NULL);
970 gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
972 renderer = gtk_cell_renderer_text_new();
973 column = gtk_tree_view_column_new_with_attributes(
974 _("Description"), renderer, "text", CAT_DESC, NULL);
975 gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
977 renderer = gtk_cell_renderer_text_new();
978 column = gtk_tree_view_column_new_with_attributes(
979 _("# POIs"), renderer, "text", CAT_POI_CNT, NULL);
980 gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column);
982 gtk_window_set_default_size(GTK_WINDOW(dialog), -1, 400);
984 pcedit.dialog = dialog;
985 pcedit.tree_view = tree_view;
987 g_signal_connect(G_OBJECT(btn_edit), "clicked",
988 G_CALLBACK(category_edit), &pcedit);
990 g_signal_connect(G_OBJECT(btn_add), "clicked",
991 G_CALLBACK(category_add), &pcedit);
993 gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view), GTK_TREE_MODEL(store));
994 g_object_unref(G_OBJECT(store));
996 gtk_widget_show_all(dialog);
998 while(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog)))
1003 gtk_widget_destroy(dialog);
1005 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1010 poi_delete(GtkWidget *widget, DeletePOI *dpoi)
1015 printf("%s()\n", __PRETTY_FUNCTION__);
1017 buffer = g_strdup_printf("%s\n%s", _("Delete POI?"), dpoi->txt_label);
1018 confirm = hildon_note_new_confirmation(GTK_WINDOW(dpoi->dialog), buffer);
1020 i = gtk_dialog_run(GTK_DIALOG(confirm));
1021 gtk_widget_destroy(GTK_WIDGET(confirm));
1023 if(i == GTK_RESPONSE_OK)
1025 if(SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi, 1, dpoi->id) ||
1026 SQLITE_DONE != sqlite3_step(_stmt_delete_poi))
1028 MACRO_BANNER_SHOW_INFO(dpoi->dialog, _("Error deleting POI"));
1032 dpoi->deleted = TRUE;
1033 gtk_widget_hide(dpoi->dialog);
1036 sqlite3_reset(_stmt_delete_poi);
1039 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1044 poi_populate_categories(GtkListStore *store, gint cat_id,
1045 GtkTreeIter *out_active)
1047 gboolean has_active = FALSE;
1048 printf("%s()\n", __PRETTY_FUNCTION__);
1050 gtk_list_store_clear(store);
1052 while(SQLITE_ROW == sqlite3_step(_stmt_selall_cat))
1055 gint cid = sqlite3_column_int(_stmt_selall_cat, 0);
1056 const gchar *clab = sqlite3_column_text(_stmt_selall_cat, 1);
1058 gtk_list_store_append(store, &iter);
1059 gtk_list_store_set(store, &iter, 0, cid, 1, clab, -1);
1061 if(cid == cat_id || !has_active)
1068 sqlite3_reset(_stmt_selall_cat);
1070 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1075 poi_edit_cat(GtkWidget *widget, PoiCategoryEditInfo *data)
1077 printf("%s()\n", __PRETTY_FUNCTION__);
1078 if(category_list_dialog(data->dialog))
1081 if(poi_populate_categories(GTK_LIST_STORE(gtk_combo_box_get_model(
1082 GTK_COMBO_BOX(data->cmb_category))),
1083 data->cat_id, &active))
1085 gtk_combo_box_set_active_iter(
1086 GTK_COMBO_BOX(data->cmb_category), &active);
1089 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1094 poi_create_cat_combo()
1096 GtkWidget *cmb_category;
1097 GtkTreeModel *model;
1098 printf("%s()\n", __PRETTY_FUNCTION__);
1100 model = GTK_TREE_MODEL(gtk_list_store_new(2,
1101 G_TYPE_INT, /* Category ID */
1102 G_TYPE_STRING)); /* Category Label */
1103 cmb_category = gtk_combo_box_new_with_model(model);
1104 g_object_unref(model);
1106 /* Set up the view for the combo box. */
1108 GtkCellRenderer *renderer;
1110 renderer = gtk_cell_renderer_text_new();
1111 gtk_cell_layout_pack_start(
1112 GTK_CELL_LAYOUT(cmb_category), renderer, TRUE);
1113 gtk_cell_layout_set_attributes(
1114 GTK_CELL_LAYOUT(cmb_category), renderer, "text", 1, NULL);
1116 poi_populate_categories(GTK_LIST_STORE(gtk_combo_box_get_model(
1117 GTK_COMBO_BOX(cmb_category))), -1, &active);
1119 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1120 return cmb_category;
1124 poi_add_dialog(GtkWidget *parent, gint unitx, gint unity)
1127 static GtkWidget *dialog;
1128 static GtkWidget *table;
1129 static GtkWidget *label;
1130 static GtkWidget *txt_label;
1131 static GtkWidget *txt_lat;
1132 static GtkWidget *txt_lon;
1133 static GtkWidget *cmb_category;
1134 static GtkWidget *txt_desc;
1135 static GtkWidget *btn_catedit;
1136 static GtkWidget *hbox;
1137 static GtkWidget *txt_scroll;
1138 static GtkTextBuffer *desc_txt;
1139 static GtkTextIter begin, end;
1140 static DeletePOI dpoi = {NULL, NULL, 0};
1141 static PoiCategoryEditInfo pcedit;
1142 printf("%s()\n", __PRETTY_FUNCTION__);
1146 dialog = gtk_dialog_new_with_buttons(_("Add POI"),
1147 GTK_WINDOW(parent), GTK_DIALOG_MODAL,
1148 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1149 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
1152 /* Set the lat/lon strings. */
1153 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1154 table = gtk_table_new(6, 4, FALSE), TRUE, TRUE, 0);
1156 gtk_table_attach(GTK_TABLE(table),
1157 label = gtk_label_new(_("Lat")),
1158 0, 1, 0, 1, GTK_FILL, 0, 2, 0);
1159 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1160 gtk_table_attach(GTK_TABLE(table),
1161 txt_lat = gtk_entry_new(),
1162 1, 2, 0, 1, GTK_FILL, 0, 2, 0);
1164 gtk_table_attach(GTK_TABLE(table),
1165 label = gtk_label_new(_("Lon")),
1166 2, 3, 0, 1, GTK_FILL, 0, 2, 0);
1167 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1168 gtk_table_attach(GTK_TABLE(table),
1169 txt_lon = gtk_entry_new(),
1170 3, 4, 0, 1, GTK_FILL, 0, 2, 0);
1172 gtk_table_attach(GTK_TABLE(table),
1173 label = gtk_label_new(_("Label")),
1174 0, 1, 1, 2, GTK_FILL, 0, 2, 0);
1175 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1176 gtk_table_attach(GTK_TABLE(table),
1177 txt_label = gtk_entry_new(),
1178 1, 4, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 0);
1180 gtk_table_attach(GTK_TABLE(table),
1181 label = gtk_label_new(_("Category")),
1182 0, 1, 3, 4, GTK_FILL, 0, 2, 0);
1183 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1184 gtk_table_attach(GTK_TABLE(table),
1185 hbox = gtk_hbox_new(FALSE, 4),
1186 1, 4, 3, 4, GTK_EXPAND | GTK_FILL, 0, 2, 0);
1187 gtk_box_pack_start(GTK_BOX(hbox),
1188 cmb_category = poi_create_cat_combo(),
1191 gtk_box_pack_start(GTK_BOX(hbox),
1192 btn_catedit = gtk_button_new_with_label(
1193 _("Edit Categories...")),
1196 gtk_table_attach(GTK_TABLE(table),
1197 label = gtk_label_new(_("Description")),
1198 0, 1, 5, 6, GTK_FILL, GTK_FILL, 2, 0);
1199 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.0f);
1201 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
1202 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
1204 gtk_table_attach(GTK_TABLE(table),
1206 1, 4, 5, 6, GTK_EXPAND | GTK_FILL, 0, 2, 0);
1208 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
1209 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1211 txt_desc = gtk_text_view_new ();
1212 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
1214 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
1215 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 550, 120);
1217 desc_txt = gtk_text_view_get_buffer(GTK_TEXT_VIEW (txt_desc));
1219 g_signal_connect(G_OBJECT(btn_catedit), "clicked",
1220 G_CALLBACK(poi_edit_cat), &pcedit);
1226 poi.desc = g_strdup("");
1227 unit2latlon(unitx, unity, poi.lat, poi.lon);
1231 gchar tmp1[LL_FMT_LEN], tmp2[LL_FMT_LEN];
1233 lat_format(poi.lat, tmp1);
1234 lon_format(poi.lon, tmp2);
1236 gtk_entry_set_text(GTK_ENTRY(txt_lat), tmp1);
1237 gtk_entry_set_text(GTK_ENTRY(txt_lon), tmp2);
1241 if(SQLITE_ROW == sqlite3_step(_stmt_nextlabel_poi))
1242 poi.label = g_strdup_printf("Point%06d",
1243 sqlite3_column_int(_stmt_nextlabel_poi, 0));
1245 poi.label = g_strdup("");
1246 sqlite3_reset(_stmt_nextlabel_poi);
1247 gtk_entry_set_text(GTK_ENTRY(txt_label), poi.label);
1250 gtk_text_buffer_set_text(desc_txt, "", -1);
1256 gboolean had_cat_id = FALSE;
1258 if(gtk_combo_box_get_active_iter(
1259 GTK_COMBO_BOX(cmb_category), &iter))
1262 gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category)),&iter,
1267 gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(
1268 GTK_COMBO_BOX(cmb_category))));
1269 if(poi_populate_categories(GTK_LIST_STORE(gtk_combo_box_get_model(
1270 GTK_COMBO_BOX(cmb_category))), cat_id, &iter)
1273 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(cmb_category), &iter);
1277 pcedit.dialog = dialog;
1278 pcedit.cmb_category = cmb_category;
1279 pcedit.cat_id = poi.cat_id;
1281 gtk_widget_show_all(dialog);
1283 while(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog)))
1289 text = gtk_entry_get_text(GTK_ENTRY(txt_lat));
1290 poi.lat = strdmstod(text, &error_check);
1291 if(text == error_check || poi.lat < -90. || poi.lat > 90.) {
1292 popup_error(dialog, _("Invalid Latitude"));
1296 text = gtk_entry_get_text(GTK_ENTRY(txt_lon));
1297 poi.lon = strdmstod(text, &error_check);
1298 if(text == error_check || poi.lon < -180. || poi.lon > 180.) {
1299 popup_error(dialog, _("Invalid Longitude"));
1303 if(strlen(gtk_entry_get_text(GTK_ENTRY(txt_label))))
1307 poi.label = g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_label)));
1311 popup_error(dialog, _("Please specify a name."));
1315 if(!gtk_combo_box_get_active_iter(
1316 GTK_COMBO_BOX(cmb_category), &iter))
1318 popup_error(dialog, _("Please specify a category."));
1322 gtk_text_buffer_get_iter_at_offset(desc_txt, &begin,0 );
1323 gtk_text_buffer_get_end_iter (desc_txt, &end);
1326 poi.desc = gtk_text_buffer_get_text(desc_txt, &begin, &end, TRUE);
1331 gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category)), &iter,
1337 if(SQLITE_OK != sqlite3_bind_double(_stmt_insert_poi, 1, poi.lat)
1338 || SQLITE_OK != sqlite3_bind_double(_stmt_insert_poi, 2, poi.lon)
1339 || SQLITE_OK != sqlite3_bind_text(_stmt_insert_poi, 3, poi.label,
1341 || SQLITE_OK != sqlite3_bind_text(_stmt_insert_poi, 4, poi.desc,
1343 || SQLITE_OK != sqlite3_bind_int(_stmt_insert_poi, 5, poi.cat_id)
1344 || SQLITE_DONE != sqlite3_step(_stmt_insert_poi))
1346 MACRO_BANNER_SHOW_INFO(parent, _("Error adding POI"));
1349 sqlite3_reset(_stmt_insert_poi);
1357 g_free(dpoi.txt_label);
1361 gtk_widget_hide(dialog);
1363 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1364 return !dpoi.deleted;
1368 poi_view_dialog(GtkWidget *parent, PoiInfo *poi)
1371 static GtkWidget *dialog;
1372 static GtkWidget *table;
1373 static GtkWidget *label;
1374 static GtkWidget *txt_label;
1375 static GtkWidget *txt_lat;
1376 static GtkWidget *txt_lon;
1377 static GtkWidget *cmb_category;
1378 static GtkWidget *txt_desc;
1379 static GtkWidget *btn_delete = NULL;
1380 static GtkWidget *btn_catedit;
1381 static GtkWidget *hbox;
1382 static GtkWidget *txt_scroll;
1383 static GtkTextBuffer *desc_txt;
1384 static GtkTextIter begin, end;
1385 static DeletePOI dpoi = {NULL, NULL, 0};
1386 static PoiCategoryEditInfo pcedit;
1387 printf("%s()\n", __PRETTY_FUNCTION__);
1391 dialog = gtk_dialog_new_with_buttons(_("Edit POI"),
1392 GTK_WINDOW(parent), GTK_DIALOG_MODAL,
1393 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1396 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
1397 btn_delete = gtk_button_new_with_label(_("Delete...")));
1399 gtk_dialog_add_button(GTK_DIALOG(dialog),
1400 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
1402 /* Set the lat/lon strings. */
1403 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1404 table = gtk_table_new(6, 4, FALSE), TRUE, TRUE, 0);
1406 gtk_table_attach(GTK_TABLE(table),
1407 label = gtk_label_new(_("Lat")),
1408 0, 1, 0, 1, GTK_FILL, 0, 2, 0);
1409 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1410 gtk_table_attach(GTK_TABLE(table),
1411 txt_lat = gtk_entry_new(),
1412 1, 2, 0, 1, GTK_FILL, 0, 2, 0);
1414 gtk_table_attach(GTK_TABLE(table),
1415 label = gtk_label_new(_("Lon")),
1416 2, 3, 0, 1, GTK_FILL, 0, 2, 0);
1417 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1418 gtk_table_attach(GTK_TABLE(table),
1419 txt_lon = gtk_entry_new(),
1420 3, 4, 0, 1, GTK_FILL, 0, 2, 0);
1422 gtk_table_attach(GTK_TABLE(table),
1423 label = gtk_label_new(_("Label")),
1424 0, 1, 1, 2, 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_label = gtk_entry_new(),
1428 1, 4, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 0);
1430 gtk_table_attach(GTK_TABLE(table),
1431 label = gtk_label_new(_("Category")),
1432 0, 1, 3, 4, GTK_FILL, 0, 2, 0);
1433 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
1434 gtk_table_attach(GTK_TABLE(table),
1435 hbox = gtk_hbox_new(FALSE, 4),
1436 1, 4, 3, 4, GTK_EXPAND | GTK_FILL, 0, 2, 0);
1437 gtk_box_pack_start(GTK_BOX(hbox),
1438 cmb_category = poi_create_cat_combo(),
1441 gtk_box_pack_start(GTK_BOX(hbox),
1442 btn_catedit = gtk_button_new_with_label(
1443 _("Edit Categories...")),
1446 gtk_table_attach(GTK_TABLE(table),
1447 label = gtk_label_new(_("Description")),
1448 0, 1, 5, 6, GTK_FILL, GTK_FILL, 2, 0);
1449 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.0f);
1451 txt_scroll = gtk_scrolled_window_new(NULL, NULL);
1452 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll),
1454 gtk_table_attach(GTK_TABLE(table),
1456 1, 4, 5, 6, GTK_EXPAND | GTK_FILL, 0, 2, 0);
1458 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll),
1459 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1461 txt_desc = gtk_text_view_new ();
1462 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD);
1464 gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc);
1465 gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 550, 120);
1467 desc_txt = gtk_text_view_get_buffer (GTK_TEXT_VIEW (txt_desc));
1469 g_signal_connect(G_OBJECT(btn_delete), "clicked",
1470 G_CALLBACK(poi_delete), &dpoi);
1472 g_signal_connect(G_OBJECT(btn_catedit), "clicked",
1473 G_CALLBACK(poi_edit_cat), &pcedit);
1476 dpoi.dialog = dialog;
1477 dpoi.txt_label = g_strdup(poi->label);
1478 dpoi.id = poi->poi_id;
1479 dpoi.deleted = FALSE;
1483 gchar tmp1[LL_FMT_LEN], tmp2[LL_FMT_LEN];
1485 lat_format(poi->lat, tmp1);
1486 lon_format(poi->lon, tmp2);
1488 gtk_entry_set_text(GTK_ENTRY(txt_lat), tmp1);
1489 gtk_entry_set_text(GTK_ENTRY(txt_lon), tmp2);
1493 gtk_entry_set_text(GTK_ENTRY(txt_label), poi->label);
1496 gtk_text_buffer_set_text(desc_txt, poi->desc, -1);
1499 gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(
1500 GTK_COMBO_BOX(cmb_category))));
1501 if(poi_populate_categories(GTK_LIST_STORE(gtk_combo_box_get_model(
1502 GTK_COMBO_BOX(cmb_category))), poi->cat_id, &iter))
1503 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(cmb_category), &iter);
1505 /* Connect Signals */
1506 pcedit.dialog = dialog;
1507 pcedit.cmb_category = cmb_category;
1508 pcedit.cat_id = poi->cat_id;
1510 gtk_widget_show_all(dialog);
1512 while(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog)))
1517 text = gtk_entry_get_text(GTK_ENTRY(txt_lat));
1518 poi->lat = strdmstod(text, &error_check);
1519 if(text == error_check || poi->lat < -90. || poi->lat > 90.) {
1520 popup_error(dialog, _("Invalid Latitude"));
1524 text = gtk_entry_get_text(GTK_ENTRY(txt_lon));
1525 poi->lon = strdmstod(text, &error_check);
1526 if(text == error_check || poi->lon < -180. || poi->lon > 180.) {
1527 popup_error(dialog, _("Invalid Longitude"));
1531 if(strlen(gtk_entry_get_text(GTK_ENTRY(txt_label))))
1535 poi->label = g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_label)));
1539 popup_error(dialog, _("Please specify a name."));
1543 if(!gtk_combo_box_get_active_iter(
1544 GTK_COMBO_BOX(cmb_category), &iter))
1546 popup_error(dialog, _("Please specify a category."));
1550 gtk_text_buffer_get_iter_at_offset(desc_txt, &begin,0 );
1551 gtk_text_buffer_get_end_iter (desc_txt, &end);
1554 poi->desc = gtk_text_buffer_get_text(desc_txt, &begin, &end, TRUE);
1557 g_free(poi->clabel);
1559 gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category)), &iter,
1565 if(SQLITE_OK != sqlite3_bind_double(
1566 _stmt_update_poi, 1, poi->lat) ||
1567 SQLITE_OK != sqlite3_bind_double(
1568 _stmt_update_poi, 2, poi->lon) ||
1569 SQLITE_OK != sqlite3_bind_text(_stmt_update_poi, 3, poi->label,
1570 -1, SQLITE_STATIC) ||
1571 SQLITE_OK != sqlite3_bind_text(_stmt_update_poi, 4, poi->desc,
1572 -1, SQLITE_STATIC) ||
1573 SQLITE_OK != sqlite3_bind_int(
1574 _stmt_update_poi, 5, poi->cat_id) ||
1575 SQLITE_OK != sqlite3_bind_int(
1576 _stmt_update_poi, 6, poi->poi_id) ||
1577 SQLITE_DONE != sqlite3_step(_stmt_update_poi))
1579 MACRO_BANNER_SHOW_INFO(parent, _("Error updating POI"));
1582 sqlite3_reset(_stmt_update_poi);
1588 g_free(dpoi.txt_label);
1592 gtk_widget_hide(dialog); /* Destroying causes a crash.... ??? */
1594 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1595 return !dpoi.deleted;
1599 poi_list_insert(GtkWidget *parent, GList *poi_list, GtkComboBox *cmb_category)
1601 gint default_cat_id;
1602 gchar *default_cat_label;
1603 gint num_inserts = 0;
1606 printf("%s()\n", __PRETTY_FUNCTION__);
1608 /* Get defaults from the given GtkComboBox */
1609 if(!gtk_combo_box_get_active_iter(
1610 GTK_COMBO_BOX(cmb_category), &iter))
1612 vprintf("%s(): return 0\n", __PRETTY_FUNCTION__);
1616 gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category)),
1619 1, &default_cat_label,
1622 /* Iterate through the data model and import as desired. */
1623 for(curr = poi_list; curr; )
1625 PoiInfo *poi = curr->data;
1627 ( SQLITE_OK != sqlite3_bind_double(_stmt_insert_poi, 1, poi->lat)
1628 || SQLITE_OK != sqlite3_bind_double(_stmt_insert_poi, 2, poi->lon)
1629 || SQLITE_OK != sqlite3_bind_text(_stmt_insert_poi, 3, poi->label,
1631 || SQLITE_OK != sqlite3_bind_text(_stmt_insert_poi, 4, poi->desc,
1633 || SQLITE_OK != sqlite3_bind_int(_stmt_insert_poi, 5,
1634 poi->cat_id = default_cat_id)
1635 || SQLITE_DONE != sqlite3_step(_stmt_insert_poi)
1639 GList *tmp = curr->next;
1644 g_slice_free(PoiInfo, poi);
1645 poi_list = g_list_delete_link(poi_list, curr);
1652 if(default_cat_label)
1653 poi->clabel = g_strdup(default_cat_label);
1654 poi->poi_id = sqlite3_last_insert_rowid(_poi_db);
1657 sqlite3_reset(_stmt_insert_poi);
1662 gchar buffer[BUFFER_SIZE];
1664 snprintf(buffer, sizeof(buffer), "%d %s", num_inserts,
1665 _("POIs were added to the POI database. The following screen will "
1666 "allow you to modify or delete any of the new POIs."));
1667 popup_error(parent, buffer);
1671 popup_error(parent, _("No POIs were found."));
1674 if(default_cat_label)
1675 g_free(default_cat_label);
1677 vprintf("%s(): return %d\n", __PRETTY_FUNCTION__, num_inserts);
1682 poi_list_free(GList *poi_list)
1685 printf("%s()\n", __PRETTY_FUNCTION__);
1687 for(curr = poi_list; curr; curr = curr->next)
1689 PoiInfo *poi_info = curr->data;
1693 g_free(poi_info->label);
1695 g_free(poi_info->desc);
1696 if(poi_info->clabel)
1697 g_free(poi_info->clabel);
1698 g_slice_free(PoiInfo, poi_info);
1702 g_list_free(poi_list);
1704 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1708 poi_list_bearing_cell_data_func(
1709 GtkTreeViewColumn *tree_column,
1710 GtkCellRenderer *cell,
1711 GtkTreeModel *tree_model,
1716 vprintf("%s()\n", __PRETTY_FUNCTION__);
1718 gtk_tree_model_get(tree_model, iter, POI_BEARING, &f, -1);
1719 snprintf(buffer, sizeof(buffer), "%.1f", f);
1720 g_object_set(cell, "text", buffer, NULL);
1722 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1726 poi_list_distance_cell_data_func(
1727 GtkTreeViewColumn *tree_column,
1728 GtkCellRenderer *cell,
1729 GtkTreeModel *tree_model,
1734 vprintf("%s()\n", __PRETTY_FUNCTION__);
1736 gtk_tree_model_get(tree_model, iter, POI_DISTANCE, &f, -1);
1737 snprintf(buffer, sizeof(buffer), "%.2f", f);
1738 g_object_set(cell, "text", buffer, NULL);
1740 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
1744 poi_list_row_selected(GtkCellRendererToggle *renderer,
1745 gchar *path_string, GtkTreeModel *tree_model)
1748 vprintf("%s()\n", __PRETTY_FUNCTION__);
1750 if(gtk_tree_model_get_iter_from_string(tree_model, &iter, path_string))
1753 gtk_tree_model_get(tree_model, &iter, POI_SELECTED, &old_value, -1);
1754 gtk_list_store_set(GTK_LIST_STORE(tree_model), &iter,
1755 POI_SELECTED, !old_value,
1759 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1764 poi_list_set_category(GtkWidget *widget, PoiListInfo *pli)
1766 static GtkWidget *dialog = NULL;
1767 static GtkWidget *cmb_category = NULL;
1768 static GtkWidget *btn_catedit = NULL;
1769 static PoiCategoryEditInfo pcedit;
1770 printf("%s()\n", __PRETTY_FUNCTION__);
1777 dialog = gtk_dialog_new_with_buttons(_("Set Category..."),
1778 GTK_WINDOW(pli->dialog2), GTK_DIALOG_MODAL,
1779 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1780 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
1783 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
1784 hbox = gtk_hbox_new(FALSE, 4), FALSE, FALSE, 4);
1786 gtk_box_pack_start(GTK_BOX(hbox),
1787 label = gtk_label_new(_("Category")),
1790 gtk_box_pack_start(GTK_BOX(hbox),
1791 cmb_category = poi_create_cat_combo(),
1794 gtk_box_pack_start(GTK_BOX(hbox),
1795 btn_catedit = gtk_button_new_with_label(
1796 _("Edit Categories...")),
1799 /* Connect Signals */
1800 pcedit.dialog = dialog;
1801 pcedit.cmb_category = cmb_category;
1803 g_signal_connect(G_OBJECT(btn_catedit), "clicked",
1804 G_CALLBACK(poi_edit_cat), &pcedit);
1807 gtk_widget_show_all(dialog);
1809 while(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog)))
1812 GtkListStore *store;
1814 const gchar *cat_label;
1816 /* Get the text of the chosen category. */
1817 if(!gtk_combo_box_get_active_iter(
1818 GTK_COMBO_BOX(cmb_category), &iter))
1820 popup_error(dialog, _("Please specify a category."));
1825 gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category)),
1831 /* Iterate through the data store and categorize as desired. */
1832 store = GTK_LIST_STORE(gtk_tree_view_get_model(
1833 GTK_TREE_VIEW(pli->tree_view)));
1834 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) do
1839 memset(&poi, 0, sizeof(poi));
1841 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
1842 POI_SELECTED, &selected,
1843 POI_POIID, &(poi.poi_id),
1844 POI_LAT, &(poi.lat),
1845 POI_LON, &(poi.lon),
1846 POI_LABEL, &(poi.label),
1847 POI_DESC, &(poi.desc),
1852 gtk_list_store_set(store, &iter,
1854 POI_CLABEL, cat_label,
1857 if(SQLITE_OK != sqlite3_bind_double(
1858 _stmt_update_poi, 1, poi.lat) ||
1859 SQLITE_OK != sqlite3_bind_double(
1860 _stmt_update_poi, 2, poi.lon) ||
1861 SQLITE_OK != sqlite3_bind_text(_stmt_update_poi,
1862 3, poi.label, -1, SQLITE_STATIC) ||
1863 SQLITE_OK != sqlite3_bind_text(_stmt_update_poi,
1864 4, poi.desc, -1, SQLITE_STATIC) ||
1865 SQLITE_OK != sqlite3_bind_int(
1866 _stmt_update_poi, 5, cat_id) ||
1867 SQLITE_OK != sqlite3_bind_int(
1868 _stmt_update_poi, 6, poi.poi_id) ||
1869 SQLITE_DONE != sqlite3_step(_stmt_update_poi))
1871 MACRO_BANNER_SHOW_INFO(pli->dialog2,
1872 _("Error updating POI"));
1874 sqlite3_reset(_stmt_update_poi);
1876 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter));
1882 gtk_widget_hide(dialog);
1884 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1889 poi_list_select_all(GtkTreeViewColumn *column, PoiListInfo *pli)
1892 GtkListStore *store;
1893 printf("%s()\n", __PRETTY_FUNCTION__);
1895 /* Iterate through the data store and select as desired. */
1896 store = GTK_LIST_STORE(gtk_tree_view_get_model(
1897 GTK_TREE_VIEW(pli->tree_view)));
1898 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) do
1900 gtk_list_store_set(store, &iter,
1901 POI_SELECTED, pli->select_all,
1903 } while(gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter));
1905 pli->select_all = !pli->select_all;
1907 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1912 poi_list_view(GtkWidget *widget, PoiListInfo *pli)
1915 GtkTreeSelection *selection;
1916 GtkListStore *store;
1917 printf("%s()\n", __PRETTY_FUNCTION__);
1919 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pli->tree_view));
1920 store = GTK_LIST_STORE(gtk_tree_view_get_model(
1921 GTK_TREE_VIEW(pli->tree_view)));
1923 /* Iterate through the data store and import as desired. */
1924 if(gtk_tree_selection_get_selected(selection, NULL, &iter))
1927 memset(&poi, 0, sizeof(poi));
1929 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
1930 POI_POIID, &(poi.poi_id),
1931 POI_CATID, &(poi.cat_id),
1932 POI_LAT, &(poi.lat),
1933 POI_LON, &(poi.lon),
1934 POI_LABEL, &(poi.label),
1935 POI_DESC, &(poi.desc),
1936 POI_CLABEL, &(poi.clabel),
1939 if(poi_view_dialog(pli->dialog, &poi))
1941 gtk_list_store_set(store, &iter,
1942 POI_POIID, poi.poi_id,
1943 POI_CATID, poi.cat_id,
1946 POI_LABEL, poi.label,
1948 POI_CLABEL, poi.clabel,
1953 /* POI was deleted. */
1954 gtk_list_store_remove(store, &iter);
1958 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1963 poi_list_row_activated(GtkTreeView *tree_view, GtkTreePath *path,
1964 GtkTreeViewColumn *column, PoiListInfo *pli)
1966 printf("%s()\n", __PRETTY_FUNCTION__);
1968 if(column != pli->select_column)
1969 poi_list_view(GTK_WIDGET(tree_view), pli);
1971 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
1975 poi_list_goto(GtkWidget *widget, PoiListInfo *pli)
1978 GtkTreeSelection *selection;
1979 GtkListStore *store;
1980 printf("%s()\n", __PRETTY_FUNCTION__);
1982 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(pli->tree_view));
1983 store = GTK_LIST_STORE(gtk_tree_view_get_model(
1984 GTK_TREE_VIEW(pli->tree_view)));
1986 /* Iterate through the data store and import as desired. */
1987 if(gtk_tree_selection_get_selected(selection, NULL, &iter))
1992 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
1997 latlon2unit(lat, lon, unit.unitx, unit.unity);
1999 if(_center_mode > 0)
2000 gtk_check_menu_item_set_active(
2001 GTK_CHECK_MENU_ITEM(_menu_view_ac_none_item), TRUE);
2003 map_center_unit(unit);
2006 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2011 poi_list_delete(GtkWidget *widget, PoiListInfo *pli)
2014 printf("%s()\n", __PRETTY_FUNCTION__);
2016 confirm = hildon_note_new_confirmation(
2017 GTK_WINDOW(pli->dialog2), _("Delete selected POI?"));
2019 if(GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm)))
2022 GtkListStore *store;
2023 gboolean already_next;
2024 gboolean must_iterate;;
2026 /* Iterate through the data store and import as desired. */
2027 store = GTK_LIST_STORE(gtk_tree_view_get_model(
2028 GTK_TREE_VIEW(pli->tree_view)));
2029 if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) do
2032 must_iterate = TRUE;
2033 already_next = FALSE;
2035 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
2036 POI_SELECTED, &selected,
2042 if(SQLITE_OK != sqlite3_bind_int(_stmt_delete_poi, 1, poi_id)
2043 || SQLITE_DONE != sqlite3_step(_stmt_delete_poi))
2045 MACRO_BANNER_SHOW_INFO(pli->dialog2,
2046 _("Error deleting POI"));
2050 already_next = gtk_list_store_remove(store, &iter);
2051 must_iterate = FALSE;
2053 sqlite3_reset(_stmt_delete_poi);
2055 } while(already_next || (must_iterate
2056 && gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter)));
2061 gtk_widget_destroy(confirm);
2063 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2068 poi_list_export_gpx(GtkWidget *widget, PoiListInfo *pli)
2070 GnomeVFSHandle *handle;
2071 printf("%s()\n", __PRETTY_FUNCTION__);
2073 if(display_open_file(GTK_WINDOW(pli->dialog2), NULL, &handle, NULL,
2074 NULL, NULL, GTK_FILE_CHOOSER_ACTION_SAVE))
2076 gint num_exported = gpx_poi_write(
2077 gtk_tree_view_get_model(GTK_TREE_VIEW(pli->tree_view)), handle);
2078 if(num_exported >= 0)
2081 snprintf(buffer, sizeof(buffer), "%d %s\n", num_exported,
2082 _("POIs Exported"));
2083 MACRO_BANNER_SHOW_INFO(pli->dialog2, buffer);
2086 popup_error(pli->dialog2, _("Error writing GPX file."));
2087 gnome_vfs_close(handle);
2090 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2095 poi_list_manage_checks(GtkWidget *widget, PoiListInfo *pli)
2097 GtkWidget *btn_category;
2098 GtkWidget *btn_delete;
2099 GtkWidget *btn_export_gpx;
2101 printf("%s()\n", __PRETTY_FUNCTION__);
2103 pli->dialog2 = gtk_dialog_new_with_buttons(_("Checked POI Actions..."),
2104 GTK_WINDOW(pli->dialog), GTK_DIALOG_MODAL,
2107 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pli->dialog2)->vbox),
2108 gtk_label_new(_("Select an operation to perform\n"
2109 "on the POIs that you checked\n"
2110 "in the POI list.")),
2113 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pli->dialog2)->vbox),
2114 btn_category = gtk_button_new_with_label(_("Set Category...")),
2117 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pli->dialog2)->vbox),
2118 btn_delete = gtk_button_new_with_label(_("Delete...")),
2121 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pli->dialog2)->vbox),
2122 btn_export_gpx = gtk_button_new_with_label(
2123 _("Export to GPX...")),
2126 gtk_dialog_add_button(GTK_DIALOG(pli->dialog2),
2127 GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT);
2129 g_signal_connect(G_OBJECT(btn_category), "clicked",
2130 G_CALLBACK(poi_list_set_category), pli);
2132 g_signal_connect(G_OBJECT(btn_delete), "clicked",
2133 G_CALLBACK(poi_list_delete), pli);
2135 g_signal_connect(G_OBJECT(btn_export_gpx), "clicked",
2136 G_CALLBACK(poi_list_export_gpx), pli);
2138 gtk_widget_show_all(pli->dialog2);
2140 gtk_dialog_run(GTK_DIALOG(pli->dialog2));
2142 gtk_widget_destroy(pli->dialog2);
2143 pli->dialog2 = NULL;
2145 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2150 poi_list_dialog(GtkWidget *parent, gint unitx, gint unity, GList *poi_list)
2152 static PoiListInfo pli = { NULL, NULL };
2153 static GtkWidget *scroller;
2154 static GtkWidget *btn_goto;
2155 static GtkWidget *btn_edit;
2156 static GtkWidget *btn_manage_checks;
2157 static GtkListStore *store;
2160 gdouble src_lat, src_lon;
2161 printf("%s()\n", __PRETTY_FUNCTION__);
2163 if(pli.dialog == NULL)
2165 GtkCellRenderer *renderer;
2166 GtkTreeViewColumn *column;
2168 pli.dialog = gtk_dialog_new_with_buttons(_("POI List"),
2169 GTK_WINDOW(parent), GTK_DIALOG_MODAL,
2172 store = gtk_list_store_new(POI_NUM_COLUMNS,
2173 G_TYPE_BOOLEAN,/* Selected */
2174 G_TYPE_INT, /* POI ID */
2175 G_TYPE_INT, /* Category ID */
2176 G_TYPE_DOUBLE, /* Latitude */
2177 G_TYPE_DOUBLE, /* Longitude */
2178 G_TYPE_STRING, /* Lat/Lon */
2179 G_TYPE_FLOAT, /* Bearing */
2180 G_TYPE_FLOAT, /* Distance */
2181 G_TYPE_STRING, /* POI Label */
2182 G_TYPE_STRING, /* POI Desc. */
2183 G_TYPE_STRING);/* Category Label */
2185 /* Set up the tree view. */
2186 pli.tree_view = gtk_tree_view_new();
2187 g_object_set(G_OBJECT(pli.tree_view),
2188 "allow-checkbox-mode", FALSE, NULL);
2190 gtk_tree_selection_set_mode(
2191 gtk_tree_view_get_selection(GTK_TREE_VIEW(pli.tree_view)),
2192 GTK_SELECTION_SINGLE);
2193 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(pli.tree_view), TRUE);
2195 renderer = gtk_cell_renderer_toggle_new();
2196 gtk_cell_renderer_toggle_set_active(GTK_CELL_RENDERER_TOGGLE(renderer),
2198 g_signal_connect(G_OBJECT(renderer), "toggled",
2199 G_CALLBACK(poi_list_row_selected), store);
2200 pli.select_column = gtk_tree_view_column_new_with_attributes(
2201 "*", renderer, "active", POI_SELECTED, NULL);
2202 gtk_tree_view_append_column(GTK_TREE_VIEW(pli.tree_view),
2204 gtk_tree_view_column_set_clickable(pli.select_column, TRUE);
2205 g_signal_connect(G_OBJECT(pli.select_column), "clicked",
2206 G_CALLBACK(poi_list_select_all), &pli);
2208 renderer = gtk_cell_renderer_combo_new();
2209 column = gtk_tree_view_column_new_with_attributes(
2210 _("Category"), renderer, "text", POI_CLABEL, NULL);
2211 gtk_tree_view_column_set_sizing(column,GTK_TREE_VIEW_COLUMN_GROW_ONLY);
2212 gtk_tree_view_column_set_sort_column_id(column, POI_CLABEL);
2213 gtk_tree_view_append_column(GTK_TREE_VIEW(pli.tree_view), column);
2215 renderer = gtk_cell_renderer_text_new();
2216 g_object_set(renderer, "xalign", 1.f, NULL);
2217 column = gtk_tree_view_column_new_with_attributes(
2218 _("Dist."), renderer, "text", POI_DISTANCE, NULL);
2219 gtk_tree_view_column_set_cell_data_func(column, renderer,
2220 (GtkTreeCellDataFunc)poi_list_distance_cell_data_func,
2222 gtk_tree_view_column_set_sort_column_id(column, POI_DISTANCE);
2223 gtk_tree_view_append_column(GTK_TREE_VIEW(pli.tree_view), column);
2225 renderer = gtk_cell_renderer_text_new();
2226 g_object_set(renderer, "xalign", 1.f, NULL);
2227 column = gtk_tree_view_column_new_with_attributes(
2228 _("Bear."), renderer, "text", POI_BEARING, NULL);
2229 gtk_tree_view_column_set_cell_data_func(column, renderer,
2230 (GtkTreeCellDataFunc)poi_list_bearing_cell_data_func,
2232 gtk_tree_view_column_set_sort_column_id(column, POI_BEARING);
2233 gtk_tree_view_append_column(GTK_TREE_VIEW(pli.tree_view), column);
2235 renderer = gtk_cell_renderer_text_new();
2236 column = gtk_tree_view_column_new_with_attributes(
2237 _("Label"), renderer, "text", POI_LABEL, NULL);
2238 gtk_tree_view_column_set_sort_column_id(column, POI_LABEL);
2239 gtk_tree_view_append_column(GTK_TREE_VIEW(pli.tree_view), column);
2241 g_signal_connect(G_OBJECT(pli.tree_view), "row-activated",
2242 G_CALLBACK(poi_list_row_activated), &pli);
2244 gtk_tree_view_set_model(GTK_TREE_VIEW(pli.tree_view),
2245 GTK_TREE_MODEL(store));
2246 g_object_unref(G_OBJECT(store));
2248 /* Enable the help button. */
2250 hildon_help_dialog_help_enable(
2252 ossohelp_dialog_help_enable(
2254 GTK_DIALOG(pli.dialog), HELP_ID_POILIST, _osso);
2256 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(pli.dialog)->action_area),
2257 btn_goto = gtk_button_new_with_label(_("Go to")));
2259 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(pli.dialog)->action_area),
2260 btn_edit = gtk_button_new_with_label(_("Edit...")));
2262 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(pli.dialog)->action_area),
2263 btn_manage_checks = gtk_button_new_with_label(
2264 _("Checked POI Actions...")));
2266 gtk_dialog_add_button(GTK_DIALOG(pli.dialog),
2267 GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT);
2269 gtk_window_set_default_size(GTK_WINDOW(pli.dialog), 500, 400);
2271 scroller = gtk_scrolled_window_new (NULL, NULL);
2272 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroller),
2273 GTK_SHADOW_ETCHED_IN);
2274 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroller),
2276 GTK_POLICY_AUTOMATIC);
2277 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(pli.dialog)->vbox),
2278 scroller, TRUE, TRUE, 0);
2280 gtk_container_add(GTK_CONTAINER(scroller), pli.tree_view);
2282 g_signal_connect(G_OBJECT(btn_goto), "clicked",
2283 G_CALLBACK(poi_list_goto), &pli);
2285 g_signal_connect(G_OBJECT(btn_edit), "clicked",
2286 G_CALLBACK(poi_list_view), &pli);
2288 g_signal_connect(G_OBJECT(btn_manage_checks), "clicked",
2289 G_CALLBACK(poi_list_manage_checks), &pli);
2292 /* Initialize the tree store. */
2294 gtk_list_store_clear(store);
2295 pli.select_all = FALSE;
2297 unit2latlon(unitx, unity, src_lat, src_lon);
2299 for(curr = poi_list; curr; curr = curr->next)
2301 PoiInfo *poi_info = curr->data;
2302 gchar tmp1[LL_FMT_LEN], tmp2[LL_FMT_LEN];
2304 printf("poi: (%f, %f, %s, %s)\n",
2305 poi_info->lat, poi_info->lon,
2306 poi_info->label, poi_info->desc);
2308 lat_format(poi_info->lat, tmp1);
2309 lon_format(poi_info->lon, tmp2);
2311 gtk_list_store_append(store, &iter);
2312 gtk_list_store_set(store, &iter,
2314 POI_POIID, poi_info->poi_id,
2315 POI_LAT, poi_info->lat,
2316 POI_LON, poi_info->lon,
2317 POI_BEARING, calculate_bearing(src_lat, src_lon,
2318 poi_info->lat, poi_info->lon),
2319 POI_DISTANCE, calculate_distance(src_lat,src_lon,
2320 poi_info->lat, poi_info->lon) * UNITS_CONVERT[_units],
2321 POI_LABEL, poi_info->label,
2322 POI_DESC, poi_info->desc,
2323 POI_CATID, poi_info->cat_id,
2324 POI_CLABEL, poi_info->clabel,
2328 gtk_widget_show_all(pli.dialog);
2330 GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(pli.dialog));
2334 gtk_widget_hide(pli.dialog);
2336 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2341 poi_import_dialog(gint unitx, gint unity)
2343 GtkWidget *dialog = NULL;
2344 gboolean success = FALSE;
2345 printf("%s()\n", __PRETTY_FUNCTION__);
2347 dialog = hildon_file_chooser_dialog_new(GTK_WINDOW(_window),
2348 GTK_FILE_CHOOSER_ACTION_OPEN);
2350 gtk_widget_show_all(dialog);
2352 while(!success && gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK)
2354 gchar *file_uri_str = NULL;
2355 gchar *bytes = NULL;
2357 GnomeVFSResult vfs_result;
2358 GList *poi_list = NULL;
2360 file_uri_str = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(dialog));
2362 /* Parse the given file as GPX. */
2363 if(GNOME_VFS_OK != (vfs_result = gnome_vfs_read_entire_file(
2364 file_uri_str, &size, &bytes)))
2366 popup_error(dialog, gnome_vfs_result_to_string(vfs_result));
2368 else if(gpx_poi_parse(bytes, size, &poi_list))
2370 static GtkWidget *cat_dialog = NULL;
2371 static GtkWidget *cmb_category = NULL;
2372 static GtkWidget *btn_catedit = NULL;
2373 static PoiCategoryEditInfo pcedit;
2379 cat_dialog = gtk_dialog_new_with_buttons(_("Default Category"),
2380 GTK_WINDOW(dialog), GTK_DIALOG_MODAL,
2381 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
2382 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
2385 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(cat_dialog)->vbox),
2386 hbox = gtk_hbox_new(FALSE, 4), FALSE, FALSE, 4);
2388 gtk_box_pack_start(GTK_BOX(hbox),
2389 label = gtk_label_new(_("Category")),
2392 gtk_box_pack_start(GTK_BOX(hbox),
2393 cmb_category = poi_create_cat_combo(),
2396 gtk_box_pack_start(GTK_BOX(hbox),
2397 btn_catedit = gtk_button_new_with_label(
2398 _("Edit Categories...")),
2401 /* Connect Signals */
2402 pcedit.dialog = dialog;
2403 pcedit.cmb_category = cmb_category;
2405 g_signal_connect(G_OBJECT(btn_catedit), "clicked",
2406 G_CALLBACK(poi_edit_cat), &pcedit);
2409 gtk_widget_show_all(cat_dialog);
2411 while(GTK_RESPONSE_ACCEPT ==gtk_dialog_run(GTK_DIALOG(cat_dialog)))
2413 if(gtk_combo_box_get_active(GTK_COMBO_BOX(cmb_category)) == -1)
2416 _("Please specify a default category."));
2420 /* Insert the POIs into the database. */
2421 gint num_inserts = poi_list_insert(dialog,
2422 poi_list, GTK_COMBO_BOX(cmb_category));
2426 /* Hide the dialogs. */
2427 gtk_widget_hide(cat_dialog);
2429 /* Create a new dialog with the results. */
2430 poi_list_dialog(dialog, unitx, unity, poi_list);
2436 gtk_widget_hide(cat_dialog);
2438 poi_list_free(poi_list);
2441 popup_error(dialog, _("Error parsing GPX file."));
2443 g_free(file_uri_str);
2447 /* Hide the dialog. */
2448 gtk_widget_destroy(dialog);
2450 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2455 poi_download_cat_selected(GtkComboBox *cmb_category, GtkEntry *txt_query)
2458 printf("%s()\n", __PRETTY_FUNCTION__);
2460 if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(cmb_category), &iter))
2462 gchar buffer[BUFFER_SIZE];
2463 GtkWidget *confirm = NULL;
2464 gchar *category = NULL;
2467 gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category)), &iter,
2471 if(*gtk_entry_get_text(txt_query))
2473 snprintf(buffer, sizeof(buffer), "%s\n %s",
2474 _("Overwrite query with the following text?"), category);
2475 confirm = hildon_note_new_confirmation(GTK_WINDOW(_window),buffer);
2480 || GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm)))
2481 gtk_entry_set_text(txt_query, category);
2484 gtk_widget_destroy(confirm);
2487 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2493 origin_type_selected(GtkWidget *toggle, OriginToggleInfo *oti)
2495 printf("%s()\n", __PRETTY_FUNCTION__);
2497 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle)))
2498 gtk_widget_set_sensitive(oti->txt_origin, toggle == oti->rad_use_text);
2500 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2505 poi_download_dialog(gint unitx, gint unity)
2507 static GtkWidget *dialog = NULL;
2508 static GtkWidget *hbox = NULL;
2509 static GtkWidget *table = NULL;
2510 static GtkWidget *table2 = NULL;
2511 static GtkWidget *label = NULL;
2512 static GtkWidget *num_page = NULL;
2513 static GtkWidget *txt_source_url = NULL;
2514 static OriginToggleInfo oti;
2515 static GtkWidget *cmb_category;
2516 printf("%s()\n", __PRETTY_FUNCTION__);
2518 conic_recommend_connected();
2522 GtkEntryCompletion *origin_comp;
2524 dialog = gtk_dialog_new_with_buttons(_("Download POIs"),
2525 GTK_WINDOW(_window), GTK_DIALOG_MODAL,
2526 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
2527 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
2530 /* Enable the help button. */
2532 hildon_help_dialog_help_enable(
2534 ossohelp_dialog_help_enable(
2536 GTK_DIALOG(dialog), HELP_ID_DOWNPOI, _osso);
2538 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
2539 table = gtk_table_new(4, 4, FALSE), TRUE, TRUE, 0);
2542 gtk_table_attach(GTK_TABLE(table),
2543 hbox = gtk_hbox_new(FALSE, 4),
2544 0, 4, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 4);
2545 gtk_box_pack_start(GTK_BOX(hbox),
2546 label = gtk_label_new(_("Source URL")), FALSE, TRUE, 4);
2547 gtk_box_pack_start(GTK_BOX(hbox),
2548 txt_source_url = gtk_entry_new(), TRUE, TRUE, 4);
2551 gtk_table_attach(GTK_TABLE(table),
2552 oti.rad_use_gps = gtk_radio_button_new_with_label(NULL,
2553 _("Use GPS Location")),
2554 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
2556 /* Use End of Route. */
2557 gtk_table_attach(GTK_TABLE(table),
2558 oti.rad_use_route = gtk_radio_button_new_with_label_from_widget(
2559 GTK_RADIO_BUTTON(oti.rad_use_gps), _("Use End of Route")),
2560 0, 1, 2, 3, GTK_FILL, 0, 2, 4);
2563 gtk_table_attach(GTK_TABLE(table),
2564 gtk_vseparator_new(),
2565 1, 2, 1, 3, GTK_FILL, GTK_FILL, 2,4);
2568 gtk_table_attach(GTK_TABLE(table),
2569 label = gtk_label_new(_("Category")),
2570 2, 3, 1, 2, GTK_FILL, 0, 2, 4);
2571 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
2572 gtk_table_attach(GTK_TABLE(table),
2573 cmb_category = poi_create_cat_combo(),
2574 3, 4, 1, 2, GTK_FILL, 0, 2, 4);
2577 gtk_table_attach(GTK_TABLE(table),
2578 label = gtk_label_new(_("Page")),
2579 2, 3, 2, 3, GTK_FILL, 0, 2, 4);
2580 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
2581 gtk_table_attach(GTK_TABLE(table),
2582 num_page = hildon_number_editor_new(1, 999),
2583 3, 4, 2, 3, GTK_FILL, 0, 2, 4);
2586 /* Another table for the Origin and Query. */
2587 gtk_table_attach(GTK_TABLE(table),
2588 table2 = gtk_table_new(2, 2, FALSE),
2589 0, 4, 3, 4, GTK_EXPAND | GTK_FILL, 0, 2, 4);
2592 gtk_table_attach(GTK_TABLE(table2),
2593 oti.rad_use_text = gtk_radio_button_new_with_label_from_widget(
2594 GTK_RADIO_BUTTON(oti.rad_use_gps), _("Origin")),
2595 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
2596 gtk_table_attach(GTK_TABLE(table2),
2597 oti.txt_origin = gtk_entry_new(),
2598 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 4);
2599 gtk_entry_set_width_chars(GTK_ENTRY(oti.txt_origin), 25);
2600 #ifdef MAEMO_CHANGES
2602 g_object_set(G_OBJECT(oti.txt_origin), "hildon-input-mode",
2603 HILDON_GTK_INPUT_MODE_FULL, NULL);
2605 g_object_set(G_OBJECT(oti.txt_origin), HILDON_AUTOCAP, FALSE, NULL);
2610 gtk_table_attach(GTK_TABLE(table2),
2611 label = gtk_label_new(_("Query")),
2612 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
2613 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
2614 gtk_table_attach(GTK_TABLE(table2),
2615 oti.txt_query = gtk_entry_new(),
2616 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
2617 gtk_entry_set_width_chars(GTK_ENTRY(oti.txt_query), 25);
2618 #ifdef MAEMO_CHANGES
2620 g_object_set(G_OBJECT(oti.txt_query), "hildon-input-mode",
2621 HILDON_GTK_INPUT_MODE_FULL, NULL);
2623 g_object_set(G_OBJECT(oti.txt_query), HILDON_AUTOCAP, FALSE, NULL);
2627 /* Set up auto-completion. */
2628 origin_comp = gtk_entry_completion_new();
2629 gtk_entry_completion_set_model(origin_comp,GTK_TREE_MODEL(_loc_model));
2630 gtk_entry_completion_set_text_column(origin_comp, 0);
2631 gtk_entry_set_completion(GTK_ENTRY(oti.txt_origin), origin_comp);
2633 g_signal_connect(G_OBJECT(oti.rad_use_gps), "toggled",
2634 G_CALLBACK(origin_type_selected), &oti);
2635 g_signal_connect(G_OBJECT(oti.rad_use_route), "toggled",
2636 G_CALLBACK(origin_type_selected), &oti);
2637 g_signal_connect(G_OBJECT(oti.rad_use_text), "toggled",
2638 G_CALLBACK(origin_type_selected), &oti);
2640 g_signal_connect(G_OBJECT(cmb_category), "changed",
2641 G_CALLBACK(poi_download_cat_selected), oti.txt_query);
2644 /* Initialize fields. */
2646 hildon_number_editor_set_value(HILDON_NUMBER_EDITOR(num_page), 1);
2648 gtk_entry_set_text(GTK_ENTRY(txt_source_url), _poi_dl_url);
2656 unit2latlon(unitx, unity, lat, lon);
2658 g_ascii_formatd(strlat, 32, "%.06f", lat);
2659 g_ascii_formatd(strlon, 32, "%.06f", lon);
2660 snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
2662 gtk_entry_set_text(GTK_ENTRY(oti.txt_origin), buffer);
2663 gtk_toggle_button_set_active(
2664 GTK_TOGGLE_BUTTON(oti.rad_use_text), TRUE);
2666 /* Else use "End of Route" by default if they have a route. */
2667 else if(_route.head != _route.tail)
2669 /* There is no route, so make it the default. */
2670 gtk_widget_set_sensitive(oti.rad_use_route, TRUE);
2671 gtk_toggle_button_set_active(
2672 GTK_TOGGLE_BUTTON(oti.rad_use_route), TRUE);
2673 gtk_widget_grab_focus(oti.rad_use_route);
2675 /* Else use "GPS Location" if they have GPS enabled. */
2678 /* There is no route, so desensitize "Use End of Route." */
2679 gtk_widget_set_sensitive(oti.rad_use_route, FALSE);
2682 gtk_toggle_button_set_active(
2683 GTK_TOGGLE_BUTTON(oti.rad_use_gps), TRUE);
2684 gtk_widget_grab_focus(oti.rad_use_gps);
2686 /* Else use text. */
2689 gtk_toggle_button_set_active(
2690 GTK_TOGGLE_BUTTON(oti.rad_use_text), TRUE);
2691 gtk_widget_grab_focus(oti.txt_origin);
2695 gtk_widget_show_all(dialog);
2697 while(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
2699 gchar origin_buffer[BUFFER_SIZE];
2700 const gchar *source_url, *origin, *query;
2701 gchar *file_uri_str = NULL;
2702 gchar *bytes = NULL;
2704 GnomeVFSResult vfs_result;
2705 GList *poi_list = NULL;
2707 source_url = gtk_entry_get_text(GTK_ENTRY(txt_source_url));
2708 if(!strlen(source_url))
2710 popup_error(dialog, _("Please specify a source URL."));
2715 g_free(_poi_dl_url);
2716 _poi_dl_url = g_strdup(source_url);
2719 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(oti.rad_use_gps)))
2723 latlon2unit(_gps.lat, _gps.lon, unitx, unity);
2724 g_ascii_formatd(strlat, 32, "%.06f", _gps.lat);
2725 g_ascii_formatd(strlon, 32, "%.06f", _gps.lon);
2726 snprintf(origin_buffer, sizeof(origin_buffer),
2727 "%s, %s", strlat, strlon);
2728 origin = origin_buffer;
2730 else if(gtk_toggle_button_get_active(
2731 GTK_TOGGLE_BUTTON(oti.rad_use_route)))
2738 /* Use last non-zero route point. */
2739 for(p = _route.tail; !p->unity; p--) { }
2743 unit2latlon(p->unitx, p->unity, lat, lon);
2744 g_ascii_formatd(strlat, 32, "%.06f", lat);
2745 g_ascii_formatd(strlon, 32, "%.06f", lon);
2746 snprintf(origin_buffer, sizeof(origin_buffer),
2747 "%s, %s", strlat, strlon);
2748 origin = origin_buffer;
2753 origin = gtk_entry_get_text(GTK_ENTRY(oti.txt_origin));
2756 porig = locate_address(dialog, origin);
2764 popup_error(dialog, _("Please specify an origin."));
2768 if(gtk_combo_box_get_active(GTK_COMBO_BOX(cmb_category)) == -1)
2770 popup_error(dialog, _("Please specify a default category."));
2774 query = gtk_entry_get_text(GTK_ENTRY(oti.txt_query));
2777 popup_error(dialog, _("Please specify a query."));
2781 /* Construct the URL. */
2783 gchar *origin_escaped;
2784 gchar *query_escaped;
2786 origin_escaped = gnome_vfs_escape_string(origin);
2787 query_escaped = gnome_vfs_escape_string(query);
2788 file_uri_str = g_strdup_printf(
2789 source_url, origin_escaped, query_escaped,
2790 hildon_number_editor_get_value(
2791 HILDON_NUMBER_EDITOR(num_page)));
2792 g_free(origin_escaped);
2793 g_free(query_escaped);
2796 /* Parse the given file as GPX. */
2797 if(GNOME_VFS_OK != (vfs_result = gnome_vfs_read_entire_file(
2798 file_uri_str, &size, &bytes)))
2800 popup_error(dialog, gnome_vfs_result_to_string(vfs_result));
2802 else if(strncmp(bytes, "<?xml", strlen("<?xml")))
2804 /* Not an XML document - must be bad locations. */
2805 popup_error(dialog, _("Invalid origin or query."));
2806 printf("bytes: %s\n", bytes);
2808 else if(gpx_poi_parse(bytes, size, &poi_list))
2810 /* Insert the POIs into the database. */
2811 gint num_inserts = poi_list_insert(dialog, poi_list,
2812 GTK_COMBO_BOX(cmb_category));
2816 /* Create a new dialog with the results. */
2817 poi_list_dialog(dialog, unitx, unity, poi_list);
2820 poi_list_free(poi_list);
2823 popup_error(dialog, _("Error parsing GPX file."));
2825 g_free(file_uri_str);
2828 /* Increment the page number for them. */
2829 hildon_number_editor_set_value(HILDON_NUMBER_EDITOR(num_page),
2830 hildon_number_editor_get_value(HILDON_NUMBER_EDITOR(num_page)) +1);
2833 /* Hide the dialog. */
2834 gtk_widget_hide(dialog);
2836 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
2841 poi_browse_dialog(gint unitx, gint unity)
2843 static GtkWidget *dialog = NULL;
2844 static GtkWidget *table = NULL;
2845 static GtkWidget *table2 = NULL;
2846 static GtkWidget *label = NULL;
2847 static GtkWidget *cmb_category = NULL;
2848 static OriginToggleInfo oti;
2849 printf("%s()\n", __PRETTY_FUNCTION__);
2853 GtkEntryCompletion *origin_comp;
2855 dialog = gtk_dialog_new_with_buttons(_("Browse POIs"),
2856 GTK_WINDOW(_window), GTK_DIALOG_MODAL,
2857 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
2858 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
2861 /* Enable the help button. */
2863 hildon_help_dialog_help_enable(
2865 ossohelp_dialog_help_enable(
2867 GTK_DIALOG(dialog), HELP_ID_BROWSEPOI, _osso);
2869 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
2870 table = gtk_table_new(3, 4, FALSE), TRUE, TRUE, 0);
2873 gtk_table_attach(GTK_TABLE(table),
2874 oti.rad_use_gps = gtk_radio_button_new_with_label(NULL,
2875 _("Use GPS Location")),
2876 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
2878 /* Use End of Route. */
2879 gtk_table_attach(GTK_TABLE(table),
2880 oti.rad_use_route = gtk_radio_button_new_with_label_from_widget(
2881 GTK_RADIO_BUTTON(oti.rad_use_gps), _("Use End of Route")),
2882 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
2884 gtk_table_attach(GTK_TABLE(table),
2885 gtk_vseparator_new(),
2886 1, 2, 0, 2, GTK_FILL, GTK_FILL, 2, 4);
2889 gtk_table_attach(GTK_TABLE(table),
2890 label = gtk_label_new(_("Category")),
2891 2, 3, 0, 1, GTK_FILL, 0, 2, 4);
2892 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
2893 gtk_table_attach(GTK_TABLE(table),
2894 cmb_category = poi_create_cat_combo(),
2895 3, 4, 0, 1, GTK_FILL, 0, 2, 4);
2896 /* Add an extra, "<any>" category. */
2899 GtkListStore *store = GTK_LIST_STORE(gtk_combo_box_get_model(
2900 GTK_COMBO_BOX(cmb_category)));
2901 gtk_list_store_prepend(store, &iter);
2902 gtk_list_store_set(store, &iter, 0, -1, 1, "<any>", -1);
2903 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(cmb_category), &iter);
2907 /* Another table for the Origin and Query. */
2908 gtk_table_attach(GTK_TABLE(table),
2909 table2 = gtk_table_new(2, 2, FALSE),
2910 0, 4, 2, 3, GTK_EXPAND | GTK_FILL, 0, 2, 4);
2913 gtk_table_attach(GTK_TABLE(table2),
2914 oti.rad_use_text = gtk_radio_button_new_with_label_from_widget(
2915 GTK_RADIO_BUTTON(oti.rad_use_gps), _("Origin")),
2916 0, 1, 0, 1, GTK_FILL, 0, 2, 4);
2917 gtk_table_attach(GTK_TABLE(table2),
2918 oti.txt_origin = gtk_entry_new(),
2919 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 4);
2920 gtk_entry_set_width_chars(GTK_ENTRY(oti.txt_origin), 25);
2921 #ifdef MAEMO_CHANGES
2923 g_object_set(G_OBJECT(oti.txt_origin), "hildon-input-mode",
2924 HILDON_GTK_INPUT_MODE_FULL, NULL);
2926 g_object_set(G_OBJECT(oti.txt_origin), HILDON_AUTOCAP, FALSE, NULL);
2931 gtk_table_attach(GTK_TABLE(table2),
2932 label = gtk_label_new(_("Query")),
2933 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
2934 gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
2935 gtk_table_attach(GTK_TABLE(table2),
2936 oti.txt_query = gtk_entry_new(),
2937 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4);
2938 gtk_entry_set_width_chars(GTK_ENTRY(oti.txt_query), 25);
2939 #ifdef MAEMO_CHANGES
2941 g_object_set(G_OBJECT(oti.txt_query), "hildon-input-mode",
2942 HILDON_GTK_INPUT_MODE_FULL, NULL);
2944 g_object_set(G_OBJECT(oti.txt_query), HILDON_AUTOCAP, FALSE, NULL);
2948 /* Set up auto-completion. */
2949 origin_comp = gtk_entry_completion_new();
2950 gtk_entry_completion_set_model(origin_comp,GTK_TREE_MODEL(_loc_model));
2951 gtk_entry_completion_set_text_column(origin_comp, 0);
2952 gtk_entry_set_completion(GTK_ENTRY(oti.txt_origin), origin_comp);
2954 g_signal_connect(G_OBJECT(oti.rad_use_gps), "toggled",
2955 G_CALLBACK(origin_type_selected), &oti);
2956 g_signal_connect(G_OBJECT(oti.rad_use_route), "toggled",
2957 G_CALLBACK(origin_type_selected), &oti);
2958 g_signal_connect(G_OBJECT(oti.rad_use_text), "toggled",
2959 G_CALLBACK(origin_type_selected), &oti);
2962 /* Initialize fields. */
2971 unit2latlon(unitx, unity, lat, lon);
2973 g_ascii_formatd(strlat, 32, "%.06f", lat);
2974 g_ascii_formatd(strlon, 32, "%.06f", lon);
2975 snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
2977 gtk_entry_set_text(GTK_ENTRY(oti.txt_origin), buffer);
2978 gtk_toggle_button_set_active(
2979 GTK_TOGGLE_BUTTON(oti.rad_use_text), TRUE);
2981 /* Else use "End of Route" by default if they have a route. */
2982 else if(_route.head != _route.tail)
2984 /* There is no route, so make it the default. */
2985 gtk_widget_set_sensitive(oti.rad_use_route, TRUE);
2986 gtk_toggle_button_set_active(
2987 GTK_TOGGLE_BUTTON(oti.rad_use_route), TRUE);
2988 gtk_widget_grab_focus(oti.rad_use_route);
2990 /* Else use "GPS Location" if they have GPS enabled. */
2993 /* There is no route, so desensitize "Use End of Route." */
2994 gtk_widget_set_sensitive(oti.rad_use_route, FALSE);
2997 gtk_toggle_button_set_active(
2998 GTK_TOGGLE_BUTTON(oti.rad_use_gps), TRUE);
2999 gtk_widget_grab_focus(oti.rad_use_gps);
3001 /* Else use text. */
3004 gtk_toggle_button_set_active(
3005 GTK_TOGGLE_BUTTON(oti.rad_use_text), TRUE);
3006 gtk_widget_grab_focus(oti.txt_origin);
3010 gtk_widget_show_all(dialog);
3012 while(gtk_dialog_run(GTK_DIALOG(dialog)) ==GTK_RESPONSE_ACCEPT)
3014 gchar buffer[BUFFER_SIZE];
3015 const gchar *origin, *query;
3017 GList *poi_list = NULL;
3019 gboolean is_cat = FALSE;
3022 if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(oti.rad_use_gps)))
3026 latlon2unit(_gps.lat, _gps.lon, unitx, unity);
3027 g_ascii_formatd(strlat, 32, "%.06f", _gps.lat);
3028 g_ascii_formatd(strlon, 32, "%.06f", _gps.lon);
3029 snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
3032 else if(gtk_toggle_button_get_active(
3033 GTK_TOGGLE_BUTTON(oti.rad_use_route)))
3040 /* Use last non-zero route point. */
3041 for(p = _route.tail; !p->unity; p--) { }
3045 unit2latlon(p->unitx, p->unity, lat, lon);
3046 g_ascii_formatd(strlat, 32, "%.06f", lat);
3047 g_ascii_formatd(strlon, 32, "%.06f", lon);
3048 snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
3054 origin = gtk_entry_get_text(GTK_ENTRY(oti.txt_origin));
3055 porig = locate_address(dialog, origin);
3062 popup_error(dialog, _("Please specify an origin."));
3066 /* Check if we're doing a category search. */
3069 if(gtk_combo_box_get_active_iter(
3070 GTK_COMBO_BOX(cmb_category), &iter))
3073 gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category)),
3074 &iter, 0, &cat_id, -1);
3082 query = g_strdup_printf("%%%s%%",
3083 gtk_entry_get_text(GTK_ENTRY(oti.txt_query)));
3085 unit2latlon(unitx, unity, lat, lon);
3089 if(SQLITE_OK != sqlite3_bind_int(_stmt_browsecat_poi, 1, cat_id) ||
3090 SQLITE_OK != sqlite3_bind_text(_stmt_browsecat_poi, 2, query,
3092 SQLITE_OK != sqlite3_bind_double(_stmt_browsecat_poi, 3, lat) ||
3093 SQLITE_OK != sqlite3_bind_double(_stmt_browsecat_poi, 4, lon))
3095 g_printerr("Failed to bind values for _stmt_browsecat_poi\n");
3098 stmt = _stmt_browsecat_poi;
3102 if(SQLITE_OK != sqlite3_bind_text(_stmt_browse_poi, 1, query,
3104 SQLITE_OK != sqlite3_bind_double(_stmt_browse_poi, 2, lat) ||
3105 SQLITE_OK != sqlite3_bind_double(_stmt_browse_poi, 3, lon))
3107 g_printerr("Failed to bind values for _stmt_browse_poi\n");
3110 stmt = _stmt_browse_poi;
3113 while(SQLITE_ROW == sqlite3_step(stmt))
3115 PoiInfo *poi = g_slice_new(PoiInfo);
3116 poi->poi_id = sqlite3_column_int(stmt, 0);
3117 poi->cat_id = sqlite3_column_int(stmt, 1);
3118 poi->lat = sqlite3_column_double(stmt, 2);
3119 poi->lon = sqlite3_column_double(stmt, 3);
3120 poi->label =g_strdup(sqlite3_column_text(stmt, 4));
3121 poi->desc = g_strdup(sqlite3_column_text(stmt, 5));
3122 poi->clabel=g_strdup(sqlite3_column_text(stmt, 6));
3123 poi_list = g_list_prepend(poi_list, poi);
3125 sqlite3_reset(stmt);
3129 /* Create a new dialog with the results. */
3130 poi_list_dialog(dialog, unitx, unity, poi_list);
3131 poi_list_free(poi_list);
3134 popup_error(dialog, _("No POIs found."));
3139 /* Hide the dialog. */
3140 gtk_widget_hide(dialog);
3142 vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
3147 * Render all the POI data. This should be done before rendering track data.
3153 gdouble lat1, lat2, lon1, lon2;
3156 GdkPixbuf *pixbuf = NULL;
3157 GError *error = NULL;
3158 printf("%s()\n", __PRETTY_FUNCTION__);
3160 if(_poi_db && _poi_zoom > _zoom)
3162 gint diag_offset = pixel2unit(MAX(_view_width_pixels,
3163 _view_height_pixels) / 2);
3164 buf2unit(0, _view_height_pixels, unitx, unity);
3165 unitx = _center.unitx - diag_offset;
3166 unity = _center.unity + diag_offset;
3167 unit2latlon(unitx, unity, lat1, lon1);
3168 unitx = _center.unitx + diag_offset;
3169 unity = _center.unity - diag_offset;
3170 unit2latlon(unitx, unity, lat2, lon2);
3172 if(SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 1, lat1) ||
3173 SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 2, lat2) ||
3174 SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 3, lon1) ||
3175 SQLITE_OK != sqlite3_bind_double(_stmt_select_poi, 4, lon2))
3177 g_printerr("Failed to bind values for _stmt_select_poi\n");
3181 while(SQLITE_ROW == sqlite3_step(_stmt_select_poi))
3183 lat1 = sqlite3_column_double(_stmt_select_poi, 0);
3184 lon1 = sqlite3_column_double(_stmt_select_poi, 1);
3185 gchar *poi_label = g_utf8_strdown(sqlite3_column_text(
3186 _stmt_select_poi, 3), -1);
3187 gchar *cat_label = g_utf8_strdown(sqlite3_column_text(
3188 _stmt_select_poi, 6), -1);
3190 latlon2unit(lat1, lon1, unitx, unity);
3191 unit2buf(unitx, unity, poix, poiy);
3193 /* Try to get icon for specific POI first. */
3194 snprintf(buffer, sizeof(buffer), "%s/%s.jpg",
3195 _poi_db_dirname, poi_label);
3196 pixbuf = gdk_pixbuf_new_from_file(buffer, &error);
3199 /* No icon for specific POI - try for category. */
3201 snprintf(buffer, sizeof(buffer), "%s/%s.jpg",
3202 _poi_db_dirname, cat_label);
3203 pixbuf = gdk_pixbuf_new_from_file(buffer, &error);
3207 /* No icon for POI or for category.
3208 * Try default POI icon file. */
3210 snprintf(buffer, sizeof(buffer), "%s/poi.jpg",
3212 pixbuf = gdk_pixbuf_new_from_file(buffer, &error);
3216 /* No icon for POI or for category or default POI icon file.
3217 Draw default purple square. */
3219 gdk_draw_rectangle(_map_pixmap, _gc[COLORABLE_POI], TRUE,
3220 poix - (gint)(1.5f * _draw_width),
3221 poiy - (gint)(1.5f * _draw_width),
3227 /* We found an icon to draw. */
3233 poix - gdk_pixbuf_get_width(pixbuf) / 2,
3234 poiy - gdk_pixbuf_get_height(pixbuf) / 2,
3236 GDK_RGB_DITHER_NONE, 0, 0);
3237 g_object_unref(pixbuf);
3243 sqlite3_reset(_stmt_select_poi);
3246 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
3252 printf("%s()\n", __PRETTY_FUNCTION__);
3256 sqlite3_close(_poi_db);
3260 vprintf("%s(): return\n", __PRETTY_FUNCTION__);