Updating branch refs/heads/master to a1cd2ccae937847fce078198449e152ddf366d19 (commit) from 5afb761ed7e95754f9565cb36e3bd8a152e3d642 (commit)
commit a1cd2ccae937847fce078198449e152ddf366d19 Merge: 5afb761 03eeed2 Author: Harald Judt <h.j...@gmx.at> Date: Mon Jul 16 15:59:04 2012 +0200 Merge branch 'short-location-name' commit 03eeed2caf8da0b4bd66772861379cc834718365 Author: Harald Judt <h.j...@gmx.at> Date: Mon Jul 16 15:50:46 2012 +0200 Make location name editable. The user can now set the location name manually. commit ca345ccf290e3b5019c4ce11a074b1551b1e39b6 Author: Harald Judt <h.j...@gmx.at> Date: Mon Jul 16 15:20:31 2012 +0200 Do away with the short location name. Since the forecast data is requested using latitude and longitude, we're free to set the location name to something arbitrary. As a first step, sanitize the location name returned by the search dialog or by auto-detection via IP address and remove the code added previously for keeping an extra short location name. panel-plugin/weather-config.c | 75 ++++++++++++++++++++++++++-------------- panel-plugin/weather-summary.c | 4 +- panel-plugin/weather.c | 14 ------- panel-plugin/weather.h | 3 +- 4 files changed, 52 insertions(+), 44 deletions(-) diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c index 0c10a2a..2929292 100644 --- a/panel-plugin/weather-config.c +++ b/panel-plugin/weather-config.c @@ -32,6 +32,7 @@ #define OPTIONS_N 13 #define BORDER 8 +#define LOC_NAME_MAX_LEN 50 static const labeloption labeloptions[OPTIONS_N] = { {N_("Temperature (T)"), TEMPERATURE}, @@ -155,13 +156,39 @@ make_label (void) +gchar * +sanitize_location_name(const gchar *location_name) +{ + gchar *pos; + long len; + + pos = g_utf8_strchr (location_name, -1, ','); + if (pos != NULL) + return g_utf8_substring (location_name, 0, + g_utf8_pointer_to_offset (location_name, pos)); + else + { + len = g_utf8_strlen(location_name, LOC_NAME_MAX_LEN); + + if (len >= LOC_NAME_MAX_LEN) + return g_utf8_substring (location_name, 0, len); + + if (len > 0) + return g_strdup(location_name); + + return g_strdup(_("Unset")); + } +} + + + void apply_options (xfceweather_dialog *dialog) { gint option; gboolean hasiter = FALSE; GtkTreeIter iter; - gchar *text, *pos; + gchar *text; GValue value = { 0, }; GtkWidget *widget; @@ -183,9 +210,6 @@ apply_options (xfceweather_dialog *dialog) if (data->location_name) g_free (data->location_name); - if (data->location_name_short) - g_free (data->location_name_short); - data->lat = g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->txt_lat))); @@ -193,15 +217,7 @@ apply_options (xfceweather_dialog *dialog) g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->txt_lon))); data->location_name = - g_strdup (gtk_label_get_text (GTK_LABEL (dialog->txt_loc_name))); - - pos = g_utf8_strchr(data->location_name, -1, ','); - if (pos != NULL) - data->location_name_short = - g_utf8_substring (data->location_name, 0, - g_utf8_pointer_to_offset (data->location_name, pos)); - else - data->location_name_short = g_strdup (data->location_name); + g_strdup (gtk_entry_get_text (GTK_ENTRY (dialog->txt_loc_name))); /* call labels_clear() here */ if (data->labels && data->labels->len > 0) @@ -302,11 +318,15 @@ option_i (datas opt) static void auto_locate_cb(const gchar *loc_name, const gchar *lat, const gchar *lon, gpointer user_data) { xfceweather_dialog *dialog = (xfceweather_dialog *) user_data; + gchar *sane_loc_name; if (lat && lon && loc_name) { gtk_entry_set_text (GTK_ENTRY (dialog->txt_lat), lat); gtk_entry_set_text (GTK_ENTRY (dialog->txt_lon), lon); - gtk_label_set_text (GTK_LABEL (dialog->txt_loc_name), loc_name); + gtk_entry_set_text (GTK_ENTRY (dialog->txt_loc_name), loc_name); + sane_loc_name = sanitize_location_name(loc_name); + gtk_entry_set_text (GTK_ENTRY (dialog->txt_loc_name), sane_loc_name); + g_free(sane_loc_name); gtk_widget_set_sensitive(dialog->txt_loc_name, TRUE); #if GTK_CHECK_VERSION(2,12,0) gtk_widget_set_tooltip_text(dialog->txt_loc_name,loc_name); @@ -314,7 +334,7 @@ static void auto_locate_cb(const gchar *loc_name, const gchar *lat, const gchar } else { gtk_entry_set_text (GTK_ENTRY (dialog->txt_lat), ""); gtk_entry_set_text (GTK_ENTRY (dialog->txt_lon), ""); - gtk_label_set_text (GTK_LABEL (dialog->txt_loc_name), _("Unset")); + gtk_entry_set_text (GTK_ENTRY (dialog->txt_loc_name), _("Unset")); gtk_widget_set_sensitive(dialog->txt_loc_name, TRUE); } } @@ -322,7 +342,7 @@ static void auto_locate_cb(const gchar *loc_name, const gchar *lat, const gchar static void start_auto_locate(xfceweather_dialog *dialog) { gtk_widget_set_sensitive(dialog->txt_loc_name, FALSE); - gtk_label_set_text (GTK_LABEL (dialog->txt_loc_name), _("Detecting...")); + gtk_entry_set_text (GTK_ENTRY (dialog->txt_loc_name), _("Detecting...")); weather_search_by_ip(dialog->wd->proxy_host, dialog->wd->proxy_port, auto_locate_cb, dialog); } @@ -333,6 +353,7 @@ cb_findlocation (GtkButton *button, { xfceweather_dialog *dialog = (xfceweather_dialog *) user_data; search_dialog *sdialog; + gchar *loc_name; sdialog = create_search_dialog (NULL, dialog->wd->proxy_host, @@ -341,7 +362,9 @@ cb_findlocation (GtkButton *button, if (run_search_dialog (sdialog)) { gtk_entry_set_text (GTK_ENTRY (dialog->txt_lat), sdialog->result_lat); gtk_entry_set_text (GTK_ENTRY (dialog->txt_lon), sdialog->result_lon); - gtk_label_set_text (GTK_LABEL (dialog->txt_loc_name), sdialog->result_name); + loc_name = sanitize_location_name(sdialog->result_name); + gtk_entry_set_text (GTK_ENTRY (dialog->txt_loc_name), loc_name); + g_free(loc_name); gtk_widget_set_sensitive(dialog->txt_loc_name, TRUE); #if GTK_CHECK_VERSION(2,12,0) gtk_widget_set_tooltip_text(dialog->txt_loc_name,sdialog->result_name); @@ -396,17 +419,14 @@ create_config_dialog (xfceweather_data *data, gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - label = gtk_label_new (_("Location:")); + label = gtk_label_new_with_mnemonic (_("L_ocation:")); dialog->txt_lat = gtk_entry_new (); dialog->txt_lon = gtk_entry_new (); - dialog->txt_loc_name = gtk_label_new (""); + dialog->txt_loc_name = gtk_entry_new (); gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); - gtk_misc_set_alignment (GTK_MISC (dialog->txt_loc_name), 0, 0.5); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), GTK_WIDGET (dialog->txt_loc_name)); -#if GTK_CHECK_VERSION(2,12,0) - gtk_label_set_ellipsize (GTK_LABEL(dialog->txt_loc_name), PANGO_ELLIPSIZE_END); -#endif if (dialog->wd->lat != NULL) gtk_entry_set_text (GTK_ENTRY (dialog->txt_lat), dialog->wd->lat); @@ -415,12 +435,15 @@ create_config_dialog (xfceweather_data *data, dialog->wd->lon); if (dialog->wd->location_name != NULL) - gtk_label_set_text (GTK_LABEL (dialog->txt_loc_name), + gtk_entry_set_text (GTK_ENTRY (dialog->txt_loc_name), dialog->wd->location_name); + else + gtk_entry_set_text (GTK_ENTRY (dialog->txt_loc_name), _("Unset")); + gtk_entry_set_max_length (GTK_ENTRY (dialog->txt_loc_name), LOC_NAME_MAX_LEN); #if GTK_CHECK_VERSION(2,12,0) - gtk_widget_set_tooltip_text(dialog->txt_loc_name, - gtk_label_get_text(GTK_LABEL(dialog->txt_loc_name))); + gtk_widget_set_tooltip_text (dialog->txt_loc_name, + gtk_entry_get_text (GTK_ENTRY (dialog->txt_loc_name))); #endif if (dialog->wd->lat == NULL || dialog->wd->lon == NULL) { diff --git a/panel-plugin/weather-summary.c b/panel-plugin/weather-summary.c index 1122f46..bf437cd 100644 --- a/panel-plugin/weather-summary.c +++ b/panel-plugin/weather-summary.c @@ -605,8 +605,8 @@ create_summary_window (xfceweather_data *data) GTK_RESPONSE_HELP, GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT, NULL); - if (data->location_name_short != NULL) { - title = g_strdup_printf (_("Weather report for: %s"), data->location_name_short); + if (data->location_name != NULL) { + title = g_strdup_printf (_("Weather report for: %s"), data->location_name); xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (window), title); g_free (title); } diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c index c8c7750..802761f 100644 --- a/panel-plugin/weather.c +++ b/panel-plugin/weather.c @@ -553,16 +553,6 @@ xfceweather_read_config (XfcePanelPlugin *plugin, data->location_name = g_strdup (value); } - value = xfce_rc_read_entry (rc, "loc_name_short", NULL); - - if (value) - { - if (data->location_name_short) - g_free (data->location_name_short); - - data->location_name_short = g_strdup (value); - } - data->unit_system = xfce_rc_read_int_entry(rc, "unit_system", METRIC); if (data->proxy_host) @@ -657,9 +647,6 @@ xfceweather_write_config (XfcePanelPlugin *plugin, if (data->location_name) xfce_rc_write_entry (rc, "loc_name", data->location_name); - if (data->location_name_short) - xfce_rc_write_entry (rc, "loc_name_short", data->location_name_short); - xfce_rc_write_bool_entry (rc, "proxy_fromenv", data->proxy_fromenv); if (data->proxy_host) @@ -1018,7 +1005,6 @@ xfceweather_free (XfcePanelPlugin *plugin, g_free (data->lat); g_free (data->lon); g_free (data->location_name); - g_free (data->location_name_short); g_free (data->proxy_host); /* Free Array */ diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h index a7df36e..557509e 100644 --- a/panel-plugin/weather.h +++ b/panel-plugin/weather.h @@ -54,8 +54,7 @@ typedef struct gchar *lat; gchar *lon; - gchar *location_name; - gchar *location_name_short; + gchar *location_name; unit_systems unit_system; xml_weather *weatherdata; _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits