[Xfce4-commits] <xfce4-weather-plugin:master> Use a shortened location name in the summary window.

Harald Judt noreply at xfce.org
Mon Jul 2 12:38:20 CEST 2012


Updating branch refs/heads/master
         to 107042c717197e1897c7445f59ac3f7b47394dd8 (commit)
       from 78eb3300efe9ce0cc7246c5fe84800a143ae1842 (commit)

commit 107042c717197e1897c7445f59ac3f7b47394dd8
Author: Harald Judt <h.judt at gmx.at>
Date:   Mon Jul 2 12:28:14 2012 +0200

    Use a shortened location name in the summary window.
    
    When the location name is too big it causes the summary window
    to grow, making the layout look awful. So for the subtitle, shorten
    the location name and only use the name of the city.
    
    We might want to use the shortened name elsewhere, and maybe
    let the user change it, so let's serialize it.

 panel-plugin/weather-config.c  |   13 ++++++++++++-
 panel-plugin/weather-summary.c |    4 ++--
 panel-plugin/weather.c         |   13 +++++++++++++
 panel-plugin/weather.h         |    1 +
 4 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
index 3b6c382..a211823 100644
--- a/panel-plugin/weather-config.c
+++ b/panel-plugin/weather-config.c
@@ -161,7 +161,7 @@ apply_options (xfceweather_dialog *dialog)
   gint         history = 0;
   gboolean     hasiter = FALSE;
   GtkTreeIter  iter;
-  gchar       *text;
+  gchar       *text, *pos;
   gint         option;
   GValue       value = { 0, };
   GtkWidget   *widget;
@@ -184,6 +184,9 @@ 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,6 +196,14 @@ 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);
diff --git a/panel-plugin/weather-summary.c b/panel-plugin/weather-summary.c
index 64e4b0e..cc822b9 100644
--- a/panel-plugin/weather-summary.c
+++ b/panel-plugin/weather-summary.c
@@ -531,8 +531,8 @@ create_summary_window (xfceweather_data *data)
 						GTK_RESPONSE_HELP,
                                                 GTK_STOCK_CLOSE,
                                                 GTK_RESPONSE_ACCEPT, NULL);
-  if (data->location_name != NULL) {
-    title = g_strdup_printf (_("Weather report for: %s"), data->location_name);
+  if (data->location_name_short != NULL) {
+    title = g_strdup_printf (_("Weather report for: %s"), data->location_name_short);
     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 0f1ffbe..23fcd12 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -473,6 +473,16 @@ 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);
+    }
+
   if (xfce_rc_read_bool_entry (rc, "celcius", TRUE))
     data->unit = METRIC;
   else
@@ -567,6 +577,9 @@ 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)
diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h
index 81b666e..147f72f 100644
--- a/panel-plugin/weather.h
+++ b/panel-plugin/weather.h
@@ -52,6 +52,7 @@ typedef struct
   gchar           *lat;
   gchar           *lon;
   gchar		  *location_name;
+  gchar           *location_name_short;
   units            unit;
 
   xml_weather     *weatherdata;


More information about the Xfce4-commits mailing list