From a105e0b7938eaf7c79ef4e54a0547cd316fe9a8a Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Thu, 24 Jul 2008 10:54:15 +0300 Subject: [PATCH] Dialogs: Add back a modified version of map_dialog_goto_latlon as dialog_goto_latlon --- src/dialogs.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/src/dialogs.c b/src/dialogs.c index 5219e88..b1f5776 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -1,7 +1,11 @@ #include "config.h" +#include #include +#include #include +#include +#include #include "ui-maemo.h" #include "hildon-wrappers.h" @@ -62,3 +66,76 @@ progress_dialog_remove(GtkWidget *dialog) if (dialog) gtk_widget_destroy(dialog); } + +gboolean +dialog_goto_latlon(GtkWidget *window, GtkWidget *map) +{ +GtkWidget *dialog; +GtkWidget *table; +GtkWidget *label; +GtkWidget *txt_lat; +GtkWidget *txt_lon; +gchar buffer[16]; +gdouble lat, 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 + +gtk_map_get_center_latlon(map, &lat, &lon); + +g_snprintf(buffer, sizeof(buffer), "%.06f", lat); +gtk_label_set_text(GTK_LABEL(txt_lat), buffer); + +g_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; + + text = gtk_entry_get_text(GTK_ENTRY(txt_lat)); + lat = strtod(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 = strtod(text, &error_check); + if (text == error_check || lon < -180.f || lon > 180.f) { + popup_error(dialog, _("Invalid Longitude")); + continue; + } + + gtk_map_set_center_latlon(map, lat, lon); + break; +} +gtk_widget_destroy(dialog); +return TRUE; +} -- 2.39.5