[Xfce4-commits] <xfce4-weather-plugin:master> Add hidden option for setting GeoNames username.

Harald Judt noreply at xfce.org
Sun Feb 3 19:06:01 CET 2013


Updating branch refs/heads/master
         to 6b27103bebf451b0e159f368ad9c038253d6071d (commit)
       from 4d94c8747702afcbe1c9adb92f667ffd5a39c504 (commit)

commit 6b27103bebf451b0e159f368ad9c038253d6071d
Author: Harald Judt <h.judt at gmx.at>
Date:   Sun Feb 3 19:00:30 2013 +0100

    Add hidden option for setting GeoNames username.
    
    Although a bit unlikely, there might be a time when credits run out,
    so add a hidden user option to be on the safe side.

 README                        |   21 +++++++++++++++++++++
 panel-plugin/weather-config.c |    8 ++++++--
 panel-plugin/weather-debug.c  |    3 +++
 panel-plugin/weather.c        |   10 ++++++++++
 panel-plugin/weather.h        |    1 +
 5 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/README b/README
index db3c0d0..bfd3919 100644
--- a/README
+++ b/README
@@ -16,6 +16,7 @@ CONTENTS
 * TRANSLATING THE PLUGIN FOR YOUR LANGUAGE
 * ICON THEMES
 * CACHING
+* HIDDEN OPTIONS
 
 
 ABOUT
@@ -521,3 +522,23 @@ Note that refreshing data by middle-clicking the icon or by clicking
 on the appropriate context menu entry does not clear the cache.
 However, data that is download will always overwrite any existing
 data.
+
+
+HIDDEN OPTIONS
+==========================================================================
+Further options are available which are not exposed via the UI because
+they are usually not needed. To add or edit these, quit the panel with
+"xfce4-panel -q", make the desired modifications to the appropriate
+config file in $HOME/.config/xfce4/panel, then restart the panel with
+"xfce4-panel &".
+
+* cache_file_max_age: Maximum allowed age of the cache file in seconds.
+  See the previous section CACHING for an explanation.
+
+* geonames_username: The GeoNames webservices are credit-based, and
+  although the plugin uses them only for setting up its configuration,
+  the credits could get exhausted if many users use the plugin. This
+  configuration option gives the user the chance to set a registered
+  GeoNames username manually (see INFORMATION FOR PACKAGE MAINTAINERS
+  AND DISTRIBUTORS on how to register). Delete this option completely
+  to use the default GeoNames username set at build time.
diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
index 5145467..ae5f431 100644
--- a/panel-plugin/weather-config.c
+++ b/panel-plugin/weather-config.c
@@ -286,7 +286,9 @@ lookup_altitude_timezone(const gpointer user_data)
     /* lookup altitude */
     url = g_strdup_printf("http://api.geonames.org"
                           "/srtm3XML?lat=%s&lng=%s&username=%s",
-                          latstr, lonstr, GEONAMES_USERNAME);
+                          latstr, lonstr,
+                          dialog->pd->geonames_username
+                          ? dialog->pd->geonames_username : GEONAMES_USERNAME);
     weather_http_queue_request(dialog->pd->session, url,
                                cb_lookup_altitude, user_data);
     g_free(url);
@@ -294,7 +296,9 @@ lookup_altitude_timezone(const gpointer user_data)
     /* lookup timezone */
     url = g_strdup_printf("http://api.geonames.org"
                           "/timezone?lat=%s&lng=%s&username=%s",
-                          latstr, lonstr, GEONAMES_USERNAME);
+                          latstr, lonstr,
+                          dialog->pd->geonames_username
+                          ? dialog->pd->geonames_username : GEONAMES_USERNAME);
     weather_http_queue_request(dialog->pd->session, url,
                                cb_lookup_timezone, user_data);
     g_free(url);
diff --git a/panel-plugin/weather-debug.c b/panel-plugin/weather-debug.c
index 6ced8c0..e9f7123 100644
--- a/panel-plugin/weather-debug.c
+++ b/panel-plugin/weather-debug.c
@@ -420,6 +420,8 @@ weather_dump_plugindata(const plugin_data *data)
                            "  next scheduled wakeup: %s\n"
                            "  wakeup reason: %s\n"
                            "  --------------------------------------------\n"
+                           "  geonames username set by user: %s\n"
+                           "  --------------------------------------------\n"
                            "  location name: %s\n"
                            "  latitude: %s\n"
                            "  longitude: %s\n"
@@ -455,6 +457,7 @@ weather_dump_plugindata(const plugin_data *data)
                            next_conditions_update,
                            next_wakeup,
                            data->next_wakeup_reason,
+                           YESNO(data->geonames_username),
                            data->location_name,
                            data->lat,
                            data->lon,
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index 34f2a43..dabb434 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -793,6 +793,12 @@ xfceweather_read_config(XfcePanelPlugin *plugin,
         data->timezone = g_strdup(value);
     }
 
+    value = xfce_rc_read_entry(rc, "geonames_username", NULL);
+    if (value) {
+        g_free(data->geonames_username);
+        data->geonames_username = g_strdup(value);
+    }
+
     data->cache_file_max_age =
         xfce_rc_read_int_entry(rc, "cache_file_max_age", CACHE_FILE_MAX_AGE);
 
@@ -905,6 +911,9 @@ xfceweather_write_config(XfcePanelPlugin *plugin,
 
     xfce_rc_write_entry(rc, "timezone", data->timezone);
 
+    if (data->geonames_username)
+        xfce_rc_write_entry(rc, "geonames_username", data->geonames_username);
+
     xfce_rc_write_int_entry(rc, "cache_file_max_age",
                             data->cache_file_max_age);
 
@@ -1792,6 +1801,7 @@ xfceweather_free(XfcePanelPlugin *plugin,
     g_free(data->scrollbox_font);
     g_free(data->timezone);
     g_free(data->timezone_initial);
+    g_free(data->geonames_username);
 
     /* free update infos */
     g_slice_free(update_info, data->weather_update);
diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h
index d0da2ca..f2b5a1c 100644
--- a/panel-plugin/weather.h
+++ b/panel-plugin/weather.h
@@ -60,6 +60,7 @@ typedef struct {
     XfcePanelPlugin *plugin;
 
     SoupSession *session;
+    gchar *geonames_username;
 
     GtkWidget *button;
     GtkWidget *alignbox;


More information about the Xfce4-commits mailing list