[Xfce4-commits] <xfce4-weather-plugin:master> Do away with the short location name.
Harald Judt
noreply at xfce.org
Mon Jul 16 16:00:01 CEST 2012
Updating branch refs/heads/master
to ca345ccf290e3b5019c4ce11a074b1551b1e39b6 (commit)
from 7051b709c85af72e2cdbb8b13a86590661c3038a (commit)
commit ca345ccf290e3b5019c4ce11a074b1551b1e39b6
Author: Harald Judt <h.judt at 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 | 49 +++++++++++++++++++++++++++++----------
panel-plugin/weather-summary.c | 4 +-
panel-plugin/weather.c | 14 -----------
panel-plugin/weather.h | 3 +-
4 files changed, 39 insertions(+), 31 deletions(-)
diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
index 0c10a2a..a5c7b53 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(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)));
@@ -195,14 +219,6 @@ apply_options (xfceweather_dialog *dialog)
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);
-
/* call labels_clear() here */
if (data->labels && data->labels->len > 0)
g_array_free (data->labels, TRUE);
@@ -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);
+ sane_loc_name = sanitize_location_name(loc_name);
+ gtk_label_set_text (GTK_LABEL (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);
@@ -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_label_set_text (GTK_LABEL (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);
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;
More information about the Xfce4-commits
mailing list