#include "viking.h"
#include "vikgototool.h"
#include "vikgoto.h"
+#include "ui_util.h"
/* Compatibility */
#if ! GLIB_CHECK_VERSION(2,22,0)
}
}
+static void
+text_changed_cb (GtkEntry *entry,
+ GParamSpec *pspec,
+ GtkWidget *button)
+{
+ gboolean has_text = gtk_entry_get_text_length(entry) > 0;
+ gtk_entry_set_icon_sensitive ( entry, GTK_ENTRY_ICON_SECONDARY, has_text );
+ gtk_widget_set_sensitive ( button, has_text );
+}
+
static gchar *a_prompt_for_goto_string(VikWindow *vw)
{
GtkWidget *dialog = NULL;
gtk_combo_box_set_active ( GTK_COMBO_BOX( tool_list ), last_goto_tool );
GtkWidget *goto_label = gtk_label_new(_("Enter address or place name:"));
- GtkWidget *goto_entry = gtk_entry_new();
- if (last_goto_str)
- gtk_entry_set_text(GTK_ENTRY(goto_entry), last_goto_str);
+ GtkWidget *goto_entry = ui_entry_new ( last_goto_str, GTK_ENTRY_ICON_SECONDARY );
// 'ok' when press return in the entry
g_signal_connect_swapped (goto_entry, "activate", G_CALLBACK(a_dialog_response_accept), dialog);
+#if GTK_CHECK_VERSION (2,20,0)
+ GtkWidget *ok_button = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
+ text_changed_cb ( GTK_ENTRY(goto_entry), NULL, ok_button );
+ g_signal_connect ( goto_entry, "notify::text", G_CALLBACK (text_changed_cb), ok_button );
+#endif
gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), tool_label, FALSE, FALSE, 5 );
gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), tool_list, FALSE, FALSE, 5 );
gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), goto_label, FALSE, FALSE, 5 );
} while (more);
}
-#define HOSTIP_LATITUDE_PATTERN "\"lat\":\""
-#define HOSTIP_LONGITUDE_PATTERN "\"lng\":\""
-#define HOSTIP_CITY_PATTERN "\"city\":\""
-#define HOSTIP_COUNTRY_PATTERN "\"country_name\":\""
+#define JSON_LATITUDE_PATTERN "\"geoplugin_latitude\":\""
+#define JSON_LONGITUDE_PATTERN "\"geoplugin_longitude\":\""
+#define JSON_CITY_PATTERN "\"geoplugin_city\":\""
+#define JSON_COUNTRY_PATTERN "\"geoplugin_countryName\":\""
/**
* Automatic attempt to find out where you are using:
- * 1. http://www.hostip.info ++
+ * 1. http://www.geoplugin.com ++
* 2. if not specific enough fallback to using the default goto tool with a country name
* ++ Using returned JSON information
* c.f. with googlesearch.c - similar implementation is used here
gint result = 0;
*name = NULL;
- gchar *tmpname = a_download_uri_to_tmp_file ( "http://api.hostip.info/get_json.php?position=true", NULL );
- //gchar *tmpname = g_strdup ("../test/hostip2.json");
+ gchar *tmpname = a_download_uri_to_tmp_file ( "http://www.geoplugin.net/json.gp", NULL );
+ //gchar *tmpname = g_strdup ("../test/www.geoplugin.net-slash-json.gp.result");
if (!tmpname) {
return result;
}
gsize len = g_mapped_file_get_length(mf);
gchar *text = g_mapped_file_get_contents(mf);
- if ((pat = g_strstr_len(text, len, HOSTIP_COUNTRY_PATTERN))) {
- pat += strlen(HOSTIP_COUNTRY_PATTERN);
+ if ((pat = g_strstr_len(text, len, JSON_COUNTRY_PATTERN))) {
+ pat += strlen(JSON_COUNTRY_PATTERN);
fragment_len = 0;
ss = pat;
while (*pat != '"') {
country = g_strndup(ss, fragment_len);
}
- if ((pat = g_strstr_len(text, len, HOSTIP_CITY_PATTERN))) {
- pat += strlen(HOSTIP_CITY_PATTERN);
+ if ((pat = g_strstr_len(text, len, JSON_CITY_PATTERN))) {
+ pat += strlen(JSON_CITY_PATTERN);
fragment_len = 0;
ss = pat;
while (*pat != '"') {
city = g_strndup(ss, fragment_len);
}
- if ((pat = g_strstr_len(text, len, HOSTIP_LATITUDE_PATTERN))) {
- pat += strlen(HOSTIP_LATITUDE_PATTERN);
+ if ((pat = g_strstr_len(text, len, JSON_LATITUDE_PATTERN))) {
+ pat += strlen(JSON_LATITUDE_PATTERN);
ss = lat_buf;
if (*pat == '-')
*ss++ = *pat++;
ll->lat = g_ascii_strtod(lat_buf, NULL);
}
- if ((pat = g_strstr_len(text, len, HOSTIP_LONGITUDE_PATTERN))) {
- pat += strlen(HOSTIP_LONGITUDE_PATTERN);
+ if ((pat = g_strstr_len(text, len, JSON_LONGITUDE_PATTERN))) {
+ pat += strlen(JSON_LONGITUDE_PATTERN);
ss = lon_buf;
if (*pat == '-')
*ss++ = *pat++;
}
else {
// Hopefully city name is unique enough to lookup position on
- // Maybe for American places where hostip appends the State code on the end
+ // For American places the service may append the State code on the end
// But if the country code is not appended if could easily get confused
// e.g. 'Portsmouth' could be at least
// Portsmouth, Hampshire, UK or