]> err.no Git - mapper/blobdiff - src/cb.c
Fixes to gstreamer element and caps handlings.
[mapper] / src / cb.c
index b7ba0c44320ffd8c1ba998d020a747babc36f6b8..41cd62e7e4f37f69b71b7238f9125e90c2214e99 100644 (file)
--- a/src/cb.c
+++ b/src/cb.c
@@ -1,6 +1,29 @@
-#include <config.h>
+/*
+ * This file is part of mapper
+ *
+ * Copyright (C) 2007 Kaj-Michael Lang
+ * Copyright (C) 2006-2007 John Costigan.
+ *
+ * POI and GPS-Info code originally written by Cezary Jackiewicz.
+ *
+ * Default map data provided by http://www.openstreetmap.org/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
-#define _GNU_SOURCE
+#include <config.h>
 
 #include <unistd.h>
 #include <stdlib.h>
@@ -12,6 +35,7 @@
 #include <sys/wait.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
+#include <gdk/gdkkeysyms.h>
 #include <fcntl.h>
 #include <libintl.h>
 #include <locale.h>
 
 #include "utils.h"
 #include "poi.h"
+#include "path.h"
 #include "route.h"
 #include "track.h"
-#include "path.h"
 #include "settings.h"
 #include "gps.h"
 #include "map.h"
 #include "mapper-types.h"
-#include "bt.h"
 #include "ui-common.h"
 #include "db.h"
 #include "latlon.h"
 #include "cb.h"
+#include "poi-gui.h"
 #include "gps-panels.h"
-
+#include "gps-conn.h"
+#include "search.h"
+#include "dialogs.h"
+#include "filter-gui.h"
 #include "help.h"
+#include "map-repo.h"
 
-gboolean 
-menu_cb_route_download(GtkAction * action)
+static void
+track_tree_view_update_store(GtkWidget *tree_view, Path *track)
 {
 GtkListStore *store;
 
-route_download(NULL);
-store=route_generate_store();
+store=path_generate_store(track);
 if (store!=NULL) {
-       gtk_tree_view_set_model(route_tree_view, store);
+       gtk_tree_view_set_model(tree_view, store);
        g_object_unref(G_OBJECT(store));
 }
+}
+
+gboolean 
+menu_cb_route_download(GtkAction * action)
+{
+route_download(NULL);
+track_tree_view_update_store(route_tree_view, &_route);
 return TRUE;
 }
 
@@ -56,11 +90,7 @@ menu_cb_route_open(GtkAction * action)
 GtkListStore *store;
 
 route_open_file();
-store=route_generate_store();
-if (store!=NULL) {
-       gtk_tree_view_set_model(route_tree_view, store);
-       g_object_unref(G_OBJECT(store));
-}
+track_tree_view_update_store(route_tree_view, &_route);
 return TRUE;
 }
 
@@ -99,6 +129,7 @@ gboolean
 menu_cb_track_open(GtkAction * action)
 {
 track_open();
+track_tree_view_update_store(track_tree_view, &_track);
 return TRUE;
 }
 
@@ -106,6 +137,7 @@ gboolean
 menu_cb_track_save(GtkAction * action)
 {
 track_save();
+track_tree_view_update_store(track_tree_view, &_track);
 return TRUE;
 }
 
@@ -113,6 +145,7 @@ gboolean
 menu_cb_track_insert_break(GtkAction * action)
 {
 track_insert_break();
+track_tree_view_update_store(track_tree_view, &_track);
 return TRUE;
 }
 
@@ -120,6 +153,7 @@ gboolean
 menu_cb_track_insert_mark(GtkAction * action)
 {
 track_insert_mark();
+track_tree_view_update_store(track_tree_view, &_track);
 return TRUE;
 }
 
@@ -148,13 +182,14 @@ gboolean
 menu_cb_track_clear(GtkAction * action)
 {
 track_clear();
+track_tree_view_update_store(track_tree_view, &_track);
 return TRUE;
 }
 
 gboolean 
 menu_cb_track_filter(GtkAction * action)
 {
-filter_dialog();
+filter_dialog(_window);
 return TRUE;
 }
 
@@ -219,7 +254,7 @@ gboolean
 menu_cb_gps_show_info(GtkAction * action)
 {
 _gps_info = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
-gps_show_info();
+gps_show_info(_gps);
 return TRUE;
 }
 
@@ -246,7 +281,7 @@ switch (value) {
        break;
 }
 
-MACRO_RECALC_CENTER(new_center_unitx, new_center_unity);
+MACRO_RECALC_CENTER(_gps->data, new_center_unitx, new_center_unity);
 map_center_unit(new_center_unitx, new_center_unity);
 return TRUE;
 }
@@ -254,79 +289,7 @@ return TRUE;
 gboolean 
 menu_cb_goto_latlon(GtkAction * action)
 {
-GtkWidget *dialog;
-GtkWidget *table;
-GtkWidget *label;
-GtkWidget *txt_lat;
-GtkWidget *txt_lon;
-
-dialog = gtk_dialog_new_with_buttons(_("Go to Lat/Lon"),
-                    GTK_WINDOW(_window),
-                    GTK_DIALOG_MODAL, GTK_STOCK_OK,
-                    GTK_RESPONSE_ACCEPT,
-                    GTK_STOCK_CANCEL,
-                    GTK_RESPONSE_REJECT, NULL);
-
-gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table = gtk_table_new(2, 3, FALSE), TRUE, TRUE, 0);
-
-gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Latitude")),0, 1, 0, 1, GTK_FILL, 0, 2, 4);
-gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
-
-gtk_table_attach(GTK_TABLE(table), txt_lat = gtk_entry_new(), 1, 2, 0, 1, GTK_FILL, 0, 2, 4);
-gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
-
-gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Longitude")), 0, 1, 1, 2, GTK_FILL, 0, 2, 4);
-gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
-
-gtk_table_attach(GTK_TABLE(table), txt_lon = gtk_entry_new(), 1, 2, 1, 2, GTK_FILL, 0, 2, 4);
-gtk_misc_set_alignment(GTK_MISC(label), 0.0f, 0.5f);
-
-#if defined (WITH_DEVICE_770) && !defined(WITH_HILDON_NEW)
-g_object_set(G_OBJECT(txt_lat), HILDON_INPUT_MODE_HINT, HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
-g_object_set(G_OBJECT(txt_lon), HILDON_INPUT_MODE_HINT, HILDON_INPUT_MODE_HINT_NUMERICSPECIAL, NULL);
-#endif
-
-/* Initialize with the current center position. */
-{
-       gchar buffer[32];
-       gdouble lat, lon;
-       unit2latlon(_center.unitx, _center.unity, lat, lon);
-       snprintf(buffer, sizeof(buffer), "%.06f", lat);
-       gtk_label_set_text(GTK_LABEL(txt_lat), buffer);
-       snprintf(buffer, sizeof(buffer), "%.06f", lon);
-       gtk_label_set_text(GTK_LABEL(txt_lon), buffer);
-}
-
-gtk_widget_show_all(dialog);
-
-while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
-       const gchar *text;
-       gchar *error_check;
-       gdouble lat, lon;
-       guint unitx, unity;
-
-       text = gtk_entry_get_text(GTK_ENTRY(txt_lat));
-       lat = strtof(text, &error_check);
-       if (text == error_check || lat < -90.f || lat > 90.f) {
-               popup_error(dialog, _("Invalid Latitude"));
-               continue;
-       }
-
-       text = gtk_entry_get_text(GTK_ENTRY(txt_lon));
-       lon = strtof(text, &error_check);
-       if (text == error_check || lon < -180.f || lon > 180.f) {
-               popup_error(dialog, _("Invalid Longitude"));
-               continue;
-       }
-
-       latlon2unit(lat, lon, unitx, unity);
-       if (_center_mode > 0)
-               set_action_activate("autocenter_none", TRUE);
-
-       map_center_unit(unitx, unity);
-       break;
-}
-gtk_widget_destroy(dialog);
+map_dialog_goto_latlon();
 return TRUE;
 }
 
@@ -336,6 +299,7 @@ menu_cb_goto_home(GtkAction *action)
 if (map_goto_position(&_home)==FALSE) {
        MACRO_BANNER_SHOW_INFO(_window, _("Home not set."));
 } else {
+       map_set_zoom(3);
        MACRO_BANNER_SHOW_INFO(_window, _("At home location"));
 }
 return TRUE;
@@ -347,6 +311,7 @@ menu_cb_goto_destination(GtkAction *action)
 if (map_goto_position(&_dest)==FALSE) {
        MACRO_BANNER_SHOW_INFO(_window, _("Destination not set."));
 } else {
+       map_set_zoom(3);
        MACRO_BANNER_SHOW_INFO(_window, _("At destination"));
 }
 return TRUE;
@@ -356,9 +321,9 @@ gboolean
 menu_cb_goto_gps(GtkAction *action)
 {
 _center_mode = CENTER_LATLON;
-map_center_unit(_pos.unitx, _pos.unity);
+map_center_unit(_gps->data.unitx, _gps->data.unity);
 map_update_location_from_center();
-
+MACRO_BANNER_SHOW_INFO(_window, _("At GPS coordinates."));
 return TRUE;
 }
 
@@ -385,7 +350,8 @@ poi_info *p;
 
 if (_center_mode > 0) {
        /* Auto-Center is enabled - use the GPS position. */
-       unit2latlon(_pos.unitx, _pos.unity, lat, lon);
+       lat=_gps->data.lat;
+       lon=_gps->data.lon;
 } else {
        /* Auto-Center is disabled - use the view center. */
        unit2latlon(_center.unitx, _center.unity, lat, lon);
@@ -434,14 +400,14 @@ return TRUE;
 gboolean 
 cb_zoom_auto(GtkAction * action)
 {
-map_set_autozoom(TRUE);
+map_set_autozoom(TRUE, _gps->data.speed);
 return TRUE;
 }
 
 gboolean 
 cb_zoom_base(GtkAction * action)
 {
-map_set_autozoom(FALSE);
+map_set_autozoom(FALSE, 0);
 map_set_zoom(3);
 return TRUE;
 }
@@ -449,16 +415,16 @@ return TRUE;
 gboolean 
 cb_zoomin(GtkAction * action)
 {
-map_set_autozoom(FALSE);
-map_zoom(-1);
+map_set_autozoom(FALSE, 0);
+g_idle_add((GSourceFunc)map_zoom_in, NULL);
 return TRUE;
 }
 
 gboolean 
 cb_zoomout(GtkAction * action)
 {
-map_set_autozoom(FALSE);
-map_zoom(1);
+map_set_autozoom(FALSE, 0);
+g_idle_add((GSourceFunc)map_zoom_out, NULL);
 return TRUE;
 }
 
@@ -478,27 +444,28 @@ gboolean
 menu_cb_enable_gps(GtkAction * action)
 {
 if ((_enable_gps = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)))) {
-       if (_rcvr_mac) {
-               set_conn_state(RCVR_DOWN);
-               rcvr_connect_now();
+       if (_gps->io.address) {
+               gps_conn_set_state(_gps, RCVR_DOWN);
+               gps_connect_now(_gps);
        } else {
-               popup_error(_window, _("Cannot enable GPS until a GPS Receiver MAC is set in the Settings dialog box."));
-               set_action_activate("gps_enable", FALSE);
+               popup_error(_window, _("Cannot enable GPS until a GPS Receiver has been configured in the GPS Settings dialog."));
+               set_action_activate("gps_enabled", FALSE);
        }
 } else {
-       if (_conn_state > RCVR_OFF)
-               set_conn_state(RCVR_OFF);
-       rcvr_disconnect();
-       track_add(0, FALSE);
+       if (_gps->io.conn > RCVR_OFF)
+               gps_conn_set_state(_gps, RCVR_OFF);
+       gps_disconnect(_gps);
+       track_add(NULL);
        _speed_excess=FALSE;
 }
-set_action_sensitive("gps_details", _enable_gps);
+if (_enable_gps==FALSE)
+       set_action_activate("autocenter_none", TRUE);
 set_action_sensitive("goto_gps", _enable_gps);
 set_action_sensitive("autocenter_latlon", _enable_gps);
 set_action_sensitive("autocenter_lead", _enable_gps);
 
 map_move_mark();
-gps_show_info();
+gps_show_info(&_gps->data);
 
 return TRUE;
 }
@@ -507,30 +474,37 @@ gboolean
 menu_cb_auto_download(GtkAction * action)
 {
 if ((_auto_download = gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)) )) {
-       if (_curr_repo->url == REPOTYPE_NONE)
+       if (_curr_repo->url == REPOTYPE_NONE) {
                popup_error(_window, _("NOTE: You must set a Map URI in the current repository in order to download maps."));
+               /* set_action_activate("", FALSE); */
+       }
        map_force_redraw();
+} else {
+       map_download_stop();
 }
 
 return TRUE;
 }
 
 gboolean 
-menu_cb_gps_details(GtkAction * action)
+menu_cb_settings(GtkAction * action)
 {
-gps_details();
+settings_dialog();
+MACRO_RECALC_FOCUS_BASE();
+MACRO_RECALC_FOCUS_SIZE();
+map_force_redraw();
 return TRUE;
 }
 
 gboolean 
-menu_cb_settings(GtkAction * action)
+menu_cb_settings_gps(GtkAction * action)
 {
-if (settings_dialog()) {
+if (settings_dialog_gps(_gps)) {
        /* Settings have changed - reconnect to receiver. */
        if (_enable_gps) {
-               set_conn_state(RCVR_DOWN);
-               rcvr_disconnect();
-               rcvr_connect_now();
+               gps_conn_set_state(_gps, RCVR_DOWN);
+               gps_disconnect(_gps);
+               gps_connect_now(_gps);
        }
 }
 MACRO_RECALC_FOCUS_BASE();
@@ -539,6 +513,29 @@ map_force_redraw();
 return TRUE;
 }
 
+gboolean 
+menu_cb_settings_colors(GtkAction * action)
+{
+settings_dialog_colors();
+map_force_redraw();
+return TRUE;
+}
+
+gboolean 
+menu_cb_settings_osm(GtkAction * action)
+{
+settings_dialog_osm();
+return TRUE;
+}
+
+gboolean 
+menu_cb_import_osm(GtkAction * action)
+{
+osm_import_dialog(_window);
+return TRUE;
+}
+
+
 gboolean 
 menu_cb_help(GtkAction * action)
 {
@@ -633,14 +630,9 @@ switch (event->keyval) {
        case CUSTOM_ACTION_ZOOM_IN:
        case CUSTOM_ACTION_ZOOM_OUT:
                if (!_key_zoom_timeout_sid) {
-                       g_printf("Z: %d %d\n", _key_zoom_new, _zoom);
-                       _key_zoom_new = _zoom + (_action[custom_key] == CUSTOM_ACTION_ZOOM_IN
-                              ? -_curr_repo->view_zoom_steps : _curr_repo->view_zoom_steps);
+                       _key_zoom_new = _zoom + (_action[custom_key] == CUSTOM_ACTION_ZOOM_IN ? -_curr_repo->view_zoom_steps : _curr_repo->view_zoom_steps);
                        /* Remember, _key_zoom_new is unsigned. */
                        if (_key_zoom_new < MAX_ZOOM) {
-                               gchar buffer[80];
-                               snprintf(buffer, sizeof(buffer), "%s %d", _("Zoom to Level"), _key_zoom_new);
-                               MACRO_BANNER_SHOW_INFO(_window, buffer);
                                _key_zoom_timeout_sid = g_timeout_add(400, map_key_zoom_timeout, NULL);
                        }
                }
@@ -717,7 +709,7 @@ switch (event->keyval) {
                set_action_activate("gps_info", !_gps_info);
        break;
        case CUSTOM_ACTION_TOGGLE_SPEEDLIMIT:
-               _speed_limit_on ^= 1;
+               _speed_on ^= 1;
        break;
        default:
                return FALSE;
@@ -750,10 +742,10 @@ gdouble lat, lon;
 gchar buffer[80], tmp1[16], tmp2[16];
 
 unit2latlon(unitx, unity, lat, lon);
-lat_format(lat, tmp1);
-lon_format(lon, tmp2);
+lat_format(_degformat, lat, tmp1);
+lon_format(_degformat, lon, tmp2);
 
-snprintf(buffer, sizeof(buffer),
+g_snprintf(buffer, sizeof(buffer),
         "%s: %s\n"
         "%s: %s", _("Latitude"), tmp1, _("Longitude"), tmp2);
 
@@ -767,7 +759,7 @@ gchar buffer[80];
 gdouble lat, lon;
 
 unit2latlon(unitx, unity, lat, lon);
-snprintf(buffer, sizeof(buffer), "%.06f,%.06f", lat, lon);
+g_snprintf(buffer, sizeof(buffer), "%.06f,%.06f", lat, lon);
 
 gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), buffer, -1);
 }
@@ -784,7 +776,7 @@ unit2latlon(unitx, unity, lat, lon);
 
 g_ascii_formatd(strlat, 32, "%.06f", lat);
 g_ascii_formatd(strlon, 32, "%.06f", lon);
-snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
+g_snprintf(buffer, sizeof(buffer), "%s, %s", strlat, strlon);
 
 route_download(buffer);
 }
@@ -797,8 +789,8 @@ gdouble lat, lon;
 
 unit2latlon(unitx, unity, lat, lon);
 
-snprintf(buffer, sizeof(buffer), "%s: %.02lf %s", _("Distance"),
-        calculate_distance(_gps.lat, _gps.lon, lat, lon) * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
+g_snprintf(buffer, sizeof(buffer), "%s: %.02lf %s", _("Distance"),
+        calculate_distance(_gps->data.lat, _gps->data.lon, lat, lon) * UNITS_CONVERT[_units], UNITS_TEXT[_units]);
 MACRO_BANNER_SHOW_INFO(_window, buffer);
 }
 
@@ -838,8 +830,8 @@ dialog = gtk_dialog_new_with_buttons(_("Add Waypoint"),
        gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f);
 
        unit2latlon(unitx, unity, lat, lon);
-       lat_format(lat, tmp1);
-       lon_format(lon, tmp2);
+       lat_format(_degformat, lat, tmp1);
+       lon_format(_degformat, lon, tmp2);
        p_latlon = g_strdup_printf("%s, %s", tmp1, tmp2);
        gtk_table_attach(GTK_TABLE(table),
                         label = gtk_label_new(p_latlon),
@@ -976,7 +968,15 @@ return TRUE;
 gboolean 
 cmenu_cb_loc_add_poi(GtkAction * action)
 {
-poi_dialog(ACTION_ADD_POI, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
+guint ux, uy;
+poi_info *poi;
+
+poi=poi_new();
+ux=x2unit(_cmenu_position_x);
+uy=y2unit(_cmenu_position_y);
+unit2latlon(ux, uy, poi->lat, poi->lon);
+poi_edit_dialog(ACTION_ADD_POI, poi);
+
 return TRUE;
 }
 
@@ -984,34 +984,63 @@ gboolean
 cb_poi_search(GtkAction *action)
 {
 poi_info poi;
+gdouble lat, lon;
 
-poi_search_dialog(NULL, &poi);
+if (_center_mode>0) {
+       lat=_gps->data.lat;
+       lon=_gps->data.lon;
+} else {
+       unit2latlon(_center.unitx, _center.unity, lat, lon);
+}
+
+mapper_search_dialog(SEARCH_TYPE_POI, lat, lon);
 return TRUE;
 }
 
 gboolean 
 cb_poi_add(GtkAction *action)
 {
-guint unitx, unity;
+gdouble lat,lon;
 const gchar *name = gtk_action_get_name(action);
+poi_info *p;
 
-if (_center_mode > 0) {
-       latlon2unit(_gps.lat, _gps.lon, unitx, unity);
+if (_center_mode>0) {
+       lat=_gps->data.lat;
+       lon=_gps->data.lon;
 } else {
-       unitx=_center.unitx;
-       unity=_center.unity;
+       unit2latlon(_center.unitx, _center.unity, lat, lon);
 }
 
-if (strcmp(name, "poi_add")==0) 
-       poi_dialog(ACTION_ADD_POI, unitx, unity);
-else if (strcmp(name, "poi_quick_add")==0) 
-       poi_quick_dialog(unitx, unity);
-else
+if (strcmp(name, "poi_add")==0) {
+       p=poi_new();
+       p->lat=lat;
+       p->lon=lon;
+       poi_edit_dialog(ACTION_ADD_POI, p);
+       map_poi_cache_clear();
+} else if (strcmp(name, "poi_quick_add")==0) {
+       poi_quick_dialog(lat, lon);
+       map_poi_cache_clear();
+} else
        g_assert_not_reached();
 
 return TRUE;
 }
 
+gboolean
+menu_cb_search_address(GtkAction *action)
+{
+gdouble lat, lon;
+
+if (_center_mode>0) {
+       lat=_gps->data.lat;
+       lon=_gps->data.lon;
+} else {
+       unit2latlon(_center.unitx, _center.unity, lat, lon);
+}
+mapper_search_dialog(SEARCH_TYPE_WAY, lat, lon);
+return TRUE;
+}
+
 gboolean 
 cmenu_cb_loc_set_home(GtkAction * action)
 {
@@ -1036,20 +1065,23 @@ unitx = x2unit(_cmenu_position_x);
 unity = y2unit(_cmenu_position_y);
 unit2latlon(unitx, unity, _dest.lat, _dest.lon);
 _dest.valid=TRUE;
+#if 0
 map_update_location_from_center();
+#endif
 return TRUE;
 }
 
 gboolean 
 cmenu_cb_loc_set_gps(GtkAction * action)
 {
-_pos.unitx = x2unit(_cmenu_position_x);
-_pos.unity = y2unit(_cmenu_position_y);
-unit2latlon(_pos.unitx, _pos.unity, _gps.lat, _gps.lon);
+_gps->data.unitx = x2unit(_cmenu_position_x);
+_gps->data.unity = y2unit(_cmenu_position_y);
+unit2latlon(_gps->data.unitx, _gps->data.unity, _gps->data.lat, _gps->data.lon);
 
 /* Move mark to new location. */
 map_refresh_mark();
-track_add(time(NULL), FALSE);
+_gps->data.time=time(NULL);
+track_add(&_gps->data);
 
 return TRUE;
 }
@@ -1129,8 +1161,7 @@ if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_positi
        gchar buffer[BUFFER_SIZE];
        GtkWidget *confirm;
 
-       snprintf(buffer, sizeof(buffer), "%s:\n%s\n",
-                _("Confirm delete of waypoint"), way->desc);
+       g_snprintf(buffer, sizeof(buffer), "%s:\n%s\n", _("Confirm delete of waypoint"), way->desc);
        confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), buffer);
 
        if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) {
@@ -1202,9 +1233,13 @@ cmenu_cb_way_add_poi(GtkAction * action)
 {
 WayPoint *way;
 
-if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y))))
-       poi_dialog(ACTION_ADD_POI, way->point->unitx, way->point->unity);
+if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)))) {
+       poi_info *p;
 
+       p=poi_new();
+       unit2latlon(way->point->unitx, way->point->unity, p->lat, p->lon);
+       poi_edit_dialog(ACTION_ADD_POI, p);
+}
 return TRUE;
 }
 
@@ -1213,7 +1248,7 @@ cmenu_cb_poi_route_to(GtkAction * action)
 {
 poi_info poi;
 
-if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
+if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), 4, &poi)) {
        guint unitx, unity;
        latlon2unit(poi.lat, poi.lon, unitx, unity);
        cmenu_route_to(unitx, unity);
@@ -1227,7 +1262,7 @@ cmenu_cb_poi_distance_to(GtkAction * action)
 {
 poi_info poi;
 
-if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
+if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), 4, &poi)) {
        guint unitx, unity;
        latlon2unit(poi.lat, poi.lon, unitx, unity);
        cmenu_distance_to(unitx, unity);
@@ -1241,7 +1276,7 @@ cmenu_cb_poi_add_route(GtkAction * action)
 {
 poi_info poi;
 
-if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
+if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), 4, &poi)) {
        guint unitx, unity;
        latlon2unit(poi.lat, poi.lon, unitx, unity);
        cmenu_add_route(unitx, unity);
@@ -1255,7 +1290,7 @@ cmenu_cb_poi_add_way(GtkAction * action)
 {
 poi_info poi;
 
-if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
+if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), 4, &poi)) {
        guint unitx, unity;
        latlon2unit(poi.lat, poi.lon, unitx, unity);
        cmenu_route_add_way(unitx, unity);
@@ -1264,9 +1299,25 @@ if (poi_select(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), &poi)) {
 return TRUE;
 }
 
+gboolean
+cmenu_cb_poi_show_poi(GtkAction *action)
+{
+/* XXX: Write this */
+return TRUE;
+}
+
 gboolean 
 cmenu_cb_poi_edit_poi(GtkAction * action)
 {
-poi_dialog(ACTION_EDIT_POI, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y));
+poi_info *p;
+gdouble lat, lon;
+
+unit2latlon(x2unit(_cmenu_position_x), y2unit(_cmenu_position_y), lat, lon);
+p=poi_find_nearest(lat, lon);
+if (!p) {
+       popup_error(_window, _("No POI found at location."));
+       return TRUE;
+}
+poi_edit_dialog(ACTION_EDIT_POI, p);
 return TRUE;
 }