[Goodies-commits] r3231 - in xfce4-weather-plugin/trunk: . panel-plugin

Nick Schermer nick at xfce.org
Fri Sep 14 16:43:27 CEST 2007


Author: nick
Date: 2007-09-14 14:43:27 +0000 (Fri, 14 Sep 2007)
New Revision: 3231

Modified:
   xfce4-weather-plugin/trunk/ChangeLog
   xfce4-weather-plugin/trunk/panel-plugin/weather-data.c
   xfce4-weather-plugin/trunk/panel-plugin/weather-http.c
   xfce4-weather-plugin/trunk/panel-plugin/weather.c
Log:
* Code cleanups.
* Fix problem with requests.


Modified: xfce4-weather-plugin/trunk/ChangeLog
===================================================================
--- xfce4-weather-plugin/trunk/ChangeLog	2007-09-14 08:26:43 UTC (rev 3230)
+++ xfce4-weather-plugin/trunk/ChangeLog	2007-09-14 14:43:27 UTC (rev 3231)
@@ -1,3 +1,7 @@
+2007-09-14  Nick Schermer <nick at xfce.org>
+    * Code cleanups.
+    * Fix problem with requests.
+
 2007-09-12  Nick Schermer <nick at xfce.org>
 
     * Add fully threaded data update, prevent loops, timeout check,

Modified: xfce4-weather-plugin/trunk/panel-plugin/weather-data.c
===================================================================
--- xfce4-weather-plugin/trunk/panel-plugin/weather-data.c	2007-09-14 08:26:43 UTC (rev 3230)
+++ xfce4-weather-plugin/trunk/panel-plugin/weather-data.c	2007-09-14 14:43:27 UTC (rev 3231)
@@ -1,7 +1,7 @@
 /*  $Id$
  *
  *  Copyright (c) 2003-2007 Xfce Development Team
- * 
+ *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
@@ -148,8 +148,6 @@
       return EMPTY_STRING;
     }
 
-  DBG ("starting");
-
   switch (type)
     {
     case _WIND_SPEED:
@@ -166,10 +164,6 @@
       break;
     }
 
-  DBG ("print %p", data->d);
-
-  DBG ("%s", str);
-
   return CHK_NULL (str);
 }
 

Modified: xfce4-weather-plugin/trunk/panel-plugin/weather-http.c
===================================================================
--- xfce4-weather-plugin/trunk/panel-plugin/weather-http.c	2007-09-14 08:26:43 UTC (rev 3230)
+++ xfce4-weather-plugin/trunk/panel-plugin/weather-http.c	2007-09-14 14:43:27 UTC (rev 3231)
@@ -126,24 +126,21 @@
   gchar               buffer[1024];
   gint                bytes, n, m;
   gchar              *request;
-  struct hostent       *host;
+  struct hostent     *host;
   struct sockaddr_in  sockaddr;
-  const gchar        *p, *hostname;
+  const gchar        *p;
   GTimeVal            timeout;
 
   /* set the current time */
   g_get_current_time (&timeout);
 
-  /* hostname we're going to use */
-  hostname = connection->proxy_host ? connection->proxy_host : connection->hostname;
-
   /* try to get the hostname */
-  host = gethostbyname (hostname);
+  host = gethostbyname (connection->proxy_host ? connection->proxy_host : connection->hostname);
   if (G_UNLIKELY (host == NULL))
     {
       /* display error */
-      g_message (_("Failed to get the hostname \"%s\". Retry in %d seconds."),
-                 hostname, WEATHER_RESCHEDULE_TIMEOUT / 1000);
+      g_message (_("Failed to get the hostname. Retry in %d seconds."),
+                 WEATHER_RESCHEDULE_TIMEOUT / 1000);
 
       /* try again later */
       connection->status = STATUS_RESCHEDULE;
@@ -194,9 +191,9 @@
 
   /* create the request */
   if (connection->proxy_host)
-    request = g_strdup_printf ("GET http://%s%s HTTP/1.0\r\n\r\n", hostname, connection->url);
+    request = g_strdup_printf ("GET http://%s%s HTTP/1.0\r\n\r\n", connection->hostname, connection->url);
   else
-    request = g_strdup_printf ("GET %s HTTP/1.0\r\nHost: %s\r\n\r\n", connection->url, hostname);
+    request = g_strdup_printf ("GET %s HTTP/1.0\r\nHost: %s\r\n\r\n", connection->url, connection->hostname);
 
   /* send the request */
   for (m = 0, n = strlen (request); m < n;)

Modified: xfce4-weather-plugin/trunk/panel-plugin/weather.c
===================================================================
--- xfce4-weather-plugin/trunk/panel-plugin/weather.c	2007-09-14 08:26:43 UTC (rev 3230)
+++ xfce4-weather-plugin/trunk/panel-plugin/weather.c	2007-09-14 14:43:27 UTC (rev 3231)
@@ -236,11 +236,11 @@
 static void
 set_icon_current (xfceweather_data *data)
 {
-  guint      i;
-  GdkPixbuf *icon = NULL;
-  datas      opt;
-  gchar     *str;
-  gint       size, height;
+  guint           i;
+  GdkPixbuf      *icon = NULL;
+  datas           opt;
+  gchar          *str;
+  gint            size, height;
 
   for (i = 0; i < data->labels->len; i++)
     {
@@ -255,8 +255,6 @@
 
   gtk_scrollbox_enablecb (GTK_SCROLLBOX (data->scrollbox), TRUE);
 
-
-
   if (i == 0)
     {
       size = data->size;
@@ -297,15 +295,15 @@
 
       g_free (result);
 
-     if (G_LIKELY (doc))
-       {
-         cur_node = xmlDocGetRootElement (doc);
+      if (G_LIKELY (doc))
+        {
+          cur_node = xmlDocGetRootElement (doc);
 
-         if (cur_node)
-           weather = parse_weather (cur_node);
+          if (cur_node)
+            weather = parse_weather (cur_node);
 
-         xmlFreeDoc (doc);
-       }
+          xmlFreeDoc (doc);
+        }
     }
 
   gtk_scrollbox_clear (GTK_SCROLLBOX (data->scrollbox));
@@ -326,10 +324,8 @@
 
 
 
-/* -1 error 0 no update needed 1 updating */
-static void
-update_weatherdata (xfceweather_data *data,
-                    gboolean          force)
+static gboolean
+update_weatherdata (xfceweather_data *data)
 {
   gchar *url;
 
@@ -338,23 +334,23 @@
       gtk_scrollbox_clear (GTK_SCROLLBOX (data->scrollbox));
       set_icon_error (data);
 
-      return;
+      return TRUE;
     }
 
-  //if (force || ((time (NULL) - attrs.st_mtime) > (UPDATE_TIME)))
-    {
-      /* build url */
-      url = g_strdup_printf ("/weather/local/%s?cc=*&dayf=%d&unit=%c",
-                             data->location_code, XML_WEATHER_DAYF_N,
-                             data->unit == METRIC ? 'm' : 'i');
+  /* build url */
+  url = g_strdup_printf ("/weather/local/%s?cc=*&dayf=%d&unit=%c",
+                         data->location_code, XML_WEATHER_DAYF_N,
+                         data->unit == METRIC ? 'm' : 'i');
 
-      /* start receive thread */
-      weather_http_receive_data ("xoap.weather.com", url, data->proxy_host,
-                                 data->proxy_port, cb_update, data);
+  /* start receive thread */
+  weather_http_receive_data ("xoap.weather.com", url, data->proxy_host,
+                             data->proxy_port, cb_update, data);
 
-      /* cleanup */
-      g_free (url);
-    }
+  /* cleanup */
+  g_free (url);
+
+  /* keep timeout running */
+  return TRUE;
 }
 
 
@@ -521,38 +517,23 @@
 
 
 
-static gboolean
-update_cb (xfceweather_data *data)
-{
-  DBG ("update_cb(): callback called");
-
-  update_weatherdata (data, FALSE);
-
-  DBG ("update_cb(): request added, returning");
-
-  return TRUE;
-}
-
-
-
 static void
-update_weatherdata_with_reset (xfceweather_data *data,
-                          gboolean          force)
+update_weatherdata_with_reset (xfceweather_data *data)
 {
   if (data->updatetimeout)
     g_source_remove (data->updatetimeout);
 
-  update_weatherdata (data, force);
+  update_weatherdata (data);
 
   data->updatetimeout =
-    gtk_timeout_add (UPDATE_TIME * 1000, (GSourceFunc) update_cb, data);
+    gtk_timeout_add (UPDATE_TIME * 1000, (GSourceFunc) update_weatherdata, data);
 }
 
 
 static void
 update_config (xfceweather_data * data)
 {
-  update_weatherdata_with_reset (data, TRUE);        /* force because units could have changed */
+  update_weatherdata_with_reset (data);
 }
 
 
@@ -594,7 +575,9 @@
         }
     }
   else if (event->button == 2)
-    update_weatherdata_with_reset (data, TRUE);
+    {
+      update_weatherdata_with_reset (data);
+    }
 
   return FALSE;
 }
@@ -607,7 +590,7 @@
 {
   xfceweather_data *data = (xfceweather_data *) user_data;
 
-  update_weatherdata_with_reset (data, TRUE);
+  update_weatherdata_with_reset (data);
 }
 
 
@@ -747,7 +730,7 @@
   gtk_scrollbox_clear (GTK_SCROLLBOX (data->scrollbox));
 
   data->updatetimeout =
-    gtk_timeout_add (UPDATE_TIME * 1000, (GSourceFunc) update_cb, data);
+    gtk_timeout_add (UPDATE_TIME * 1000, (GSourceFunc) update_weatherdata, data);
 
   return data;
 }
@@ -802,6 +785,7 @@
   else
     set_icon_error (data);
 
+  /* we handled the size */
   return TRUE;
 }
 
@@ -837,7 +821,7 @@
   g_signal_connect (G_OBJECT (plugin), "configure-plugin",
                     G_CALLBACK (xfceweather_create_options), data);
 
-  update_weatherdata (data, TRUE);
+  update_weatherdata (data);
 }
 
 XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (weather_construct);




More information about the Goodies-commits mailing list