[Xfce4-commits] <xfce4-weather-plugin:master> Remove weather-http and use only one soup session.

Harald Judt noreply at xfce.org
Tue Nov 20 20:18:16 CET 2012


Updating branch refs/heads/master
         to 94d75c2a08a05c485cae127741717387f25c2d2e (commit)
       from 7af6d45f4a83c46b58a1c88645742978ff67620a (commit)

commit 94d75c2a08a05c485cae127741717387f25c2d2e
Author: Harald Judt <h.judt at gmx.at>
Date:   Tue Nov 20 20:10:38 2012 +0100

    Remove weather-http and use only one soup session.

 panel-plugin/Makefile.am       |    2 -
 panel-plugin/weather-config.c  |    4 +-
 panel-plugin/weather-http.c    |   57 ----------------------------------------
 panel-plugin/weather-http.h    |   37 --------------------------
 panel-plugin/weather-search.c  |   14 ++++++---
 panel-plugin/weather-search.h  |    8 ++++-
 panel-plugin/weather-summary.c |    4 +-
 panel-plugin/weather.c         |   44 +++++++++++++++++++++++++-----
 panel-plugin/weather.h         |   12 ++++++++
 9 files changed, 67 insertions(+), 115 deletions(-)

diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index ee184e3..672424e 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -17,8 +17,6 @@ libweather_la_SOURCES =						\
 	weather-data.h							\
 	weather-debug.c							\
 	weather-debug.h							\
-	weather-http.c							\
-	weather-http.h							\
 	weather-icon.c							\
 	weather-icon.h							\
 	weather-parsers.c						\
diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
index d727196..030c0af 100644
--- a/panel-plugin/weather-config.c
+++ b/panel-plugin/weather-config.c
@@ -378,7 +378,7 @@ start_auto_locate(xfceweather_dialog *dialog)
 {
     gtk_widget_set_sensitive(dialog->txt_loc_name, FALSE);
     gtk_entry_set_text(GTK_ENTRY(dialog->txt_loc_name), _("Detecting..."));
-    weather_search_by_ip(auto_locate_cb, dialog);
+    weather_search_by_ip(dialog->wd->session, auto_locate_cb, dialog);
 }
 
 
@@ -390,7 +390,7 @@ cb_findlocation(GtkButton *button,
     search_dialog *sdialog;
     gchar *loc_name;
 
-    sdialog = create_search_dialog(NULL);
+    sdialog = create_search_dialog(NULL, dialog->wd->session);
 
     gtk_widget_set_sensitive(GTK_WIDGET(button), FALSE);
     if (run_search_dialog(sdialog)) {
diff --git a/panel-plugin/weather-http.c b/panel-plugin/weather-http.c
deleted file mode 100644
index e91a491..0000000
--- a/panel-plugin/weather-http.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/* Copyright (c) 2003-2012 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
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <glib.h>
-
-#include "weather-http.h"
-
-#define WEATHER_MAX_CONN_TIMEOUT   (10)        /* connection timeout in seconds */
-
-
-void
-weather_http_queue_request(const gchar *uri,
-                           SoupSessionCallback callback_func,
-                           gpointer user_data)
-{
-    SoupSession *session;
-    SoupMessage *msg;
-    SoupURI *soup_proxy_uri;
-    const gchar *proxy_uri;
-
-    /* create a new soup session */
-    session = soup_session_async_new();
-    g_object_set(session, SOUP_SESSION_TIMEOUT,
-                 WEATHER_MAX_CONN_TIMEOUT, NULL);
-
-    /* Set the proxy URI if any */
-    proxy_uri = g_getenv("HTTP_PROXY");
-    if (!proxy_uri)
-        proxy_uri = g_getenv("http_proxy");
-    if (proxy_uri) {
-        soup_proxy_uri = soup_uri_new (proxy_uri);
-        g_object_set(session, SOUP_SESSION_PROXY_URI, soup_proxy_uri, NULL);
-        soup_uri_free(soup_proxy_uri);
-    }
-
-    msg = soup_message_new("GET", uri);
-    soup_session_queue_message(session, msg, callback_func, user_data);
-}
diff --git a/panel-plugin/weather-http.h b/panel-plugin/weather-http.h
deleted file mode 100644
index 5dfab75..0000000
--- a/panel-plugin/weather-http.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*  Copyright (c) 2003-2012 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
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#ifndef __WEATHER_HTTP_H__
-#define __WEATHER_HTTP_H__
-
-#include <libsoup/soup.h>
-
-G_BEGIN_DECLS
-
-typedef void (*SoupSessionCallback) (SoupSession *session,
-                                     SoupMessage *msg,
-                                     gpointer user_data);
-
-
-void weather_http_queue_request(const gchar *uri,
-                                SoupSessionCallback callback_func,
-                                gpointer user_data);
-
-G_END_DECLS
-
-#endif
diff --git a/panel-plugin/weather-search.c b/panel-plugin/weather-search.c
index 39b5a39..3618b8a 100644
--- a/panel-plugin/weather-search.c
+++ b/panel-plugin/weather-search.c
@@ -29,7 +29,6 @@
 #include "weather.h"
 
 #include "weather-search.h"
-#include "weather-http.h"
 #include "weather-debug.h"
 
 #define BORDER 8
@@ -168,7 +167,7 @@ search_cb(GtkWidget *widget,
 
     gtk_tree_view_column_set_title(dialog->column, _("Searching..."));
     g_message("getting %s", url);
-    weather_http_queue_request(url, cb_searchdone, dialog);
+    weather_http_queue_request(dialog->session, url, cb_searchdone, dialog);
     g_free(url);
 }
 
@@ -184,7 +183,8 @@ pass_search_results(GtkTreeView *tree_view,
 
 
 search_dialog *
-create_search_dialog(GtkWindow *parent)
+create_search_dialog(GtkWindow *parent,
+                     SoupSession *session)
 {
     search_dialog *dialog;
     GtkWidget *dialog_vbox, *vbox, *hbox, *scroll, *frame;
@@ -195,6 +195,8 @@ create_search_dialog(GtkWindow *parent)
     if (!dialog)
         return NULL;
 
+    dialog->session = session;
+
     dialog->dialog =
         xfce_titled_dialog_new_with_buttons(_("Search location"),
                                             parent,
@@ -376,7 +378,8 @@ cb_geolocation(SoupSession *session,
 }
 
 
-void weather_search_by_ip(void (*gui_cb) (const gchar *loc_name,
+void weather_search_by_ip(SoupSession *session,
+                          void (*gui_cb) (const gchar *loc_name,
                                           const gchar *lat,
                                           const gchar *lon,
                                           const unit_systems unit_system,
@@ -393,5 +396,6 @@ void weather_search_by_ip(void (*gui_cb) (const gchar *loc_name,
     data->user_data = user_data;
 
     g_message("getting http://geoip.xfce.org/");
-    weather_http_queue_request("http://geoip.xfce.org/", cb_geolocation, data);
+    weather_http_queue_request(session, "http://geoip.xfce.org/",
+                               cb_geolocation, data);
 }
diff --git a/panel-plugin/weather-search.h b/panel-plugin/weather-search.h
index 11f37ae..eb00879 100644
--- a/panel-plugin/weather-search.h
+++ b/panel-plugin/weather-search.h
@@ -38,14 +38,18 @@ typedef struct {
     gchar *result_name;
 
     gchar *last_search;
+
+    SoupSession *session;
 } search_dialog;
 
 
-search_dialog *create_search_dialog(GtkWindow *parent);
+search_dialog *create_search_dialog(GtkWindow *parent,
+                                    SoupSession *session);
 
 gboolean run_search_dialog(search_dialog *dialog);
 
-void weather_search_by_ip(void (*gui_cb) (const gchar *loc_name,
+void weather_search_by_ip(SoupSession *session,
+                          void (*gui_cb) (const gchar *loc_name,
                                           const gchar *lat,
                                           const gchar *lon,
                                           const unit_systems unit_system,
diff --git a/panel-plugin/weather-summary.c b/panel-plugin/weather-summary.c
index 0a458c3..6c01707 100644
--- a/panel-plugin/weather-summary.c
+++ b/panel-plugin/weather-summary.c
@@ -24,7 +24,6 @@
 
 #include "weather-parsers.h"
 #include "weather-data.h"
-#include "weather-http.h"
 #include "weather.h"
 
 #include "weather-summary.h"
@@ -254,7 +253,8 @@ weather_summary_get_logo(xfceweather_data *data)
     pixbuf = gdk_pixbuf_new_from_file(path, NULL);
     g_free(path);
     if (pixbuf == NULL)
-        weather_http_queue_request("http://met.no/filestore/met.no-logo.gif",
+        weather_http_queue_request(data->session,
+                                   "http://met.no/filestore/met.no-logo.gif",
                                    logo_fetched, image);
     else {
         gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
index ed248da..03c7e87 100644
--- a/panel-plugin/weather.c
+++ b/panel-plugin/weather.c
@@ -31,7 +31,6 @@
 #include "weather.h"
 
 #include "weather-translate.h"
-#include "weather-http.h"
 #include "weather-summary.h"
 #include "weather-config.h"
 #include "weather-icon.h"
@@ -42,7 +41,7 @@
 #define UPDATE_INTERVAL 15
 #define DATA_MAX_AGE (3 * 3600)
 #define BORDER 8
-
+#define CONNECTION_TIMEOUT (10)        /* connection timeout in seconds */
 
 #define DATA_AND_UNIT(var, item)                            \
     value = get_data(conditions, data->unit_system, item);  \
@@ -58,6 +57,19 @@
 gboolean debug_mode = FALSE;
 
 
+void
+weather_http_queue_request(SoupSession *session,
+                           const gchar *uri,
+                           SoupSessionCallback callback_func,
+                           gpointer user_data)
+{
+    SoupMessage *msg;
+
+    msg = soup_message_new("GET", uri);
+    soup_session_queue_message(session, msg, callback_func, user_data);
+}
+
+
 static const gchar *
 get_label_size(const xfceweather_data *data)
 {
@@ -399,7 +411,7 @@ update_weatherdata(xfceweather_data *data)
 
         /* start receive thread */
         g_message("getting %s", url);
-        weather_http_queue_request(url, cb_astro_update, data);
+        weather_http_queue_request(data->session, url, cb_astro_update, data);
         g_free(url);
     }
 
@@ -413,7 +425,8 @@ update_weatherdata(xfceweather_data *data)
 
         /* start receive thread */
         g_message("getting %s", url);
-        weather_http_queue_request(url, cb_weather_update, data);
+        weather_http_queue_request(data->session, url,
+                                   cb_weather_update, data);
         g_free(url);
 
         /* cb_update will deal with everything that follows this
@@ -896,20 +909,35 @@ static xfceweather_data *
 xfceweather_create_control(XfcePanelPlugin *plugin)
 {
     xfceweather_data *data = g_slice_new0(xfceweather_data);
+    SoupMessage *msg;
+    SoupURI *soup_proxy_uri;
+    const gchar *proxy_uri;
     GtkWidget *refresh;
     data_types lbl;
     GdkPixbuf *icon = NULL;
 
     /* Initialize with sane default values */
     data->plugin = plugin;
-    data->lat = NULL;
-    data->lon = NULL;
-    data->location_name = NULL;
     data->unit_system = METRIC;
     data->weatherdata = NULL;
-    data->animation_transitions = FALSE;
     data->forecast_days = DEFAULT_FORECAST_DAYS;
 
+    /* Setup session for HTTP connections */
+    data->session = soup_session_async_new();
+    g_object_set(data->session, SOUP_SESSION_TIMEOUT,
+                 CONNECTION_TIMEOUT, NULL);
+
+    /* Set the proxy URI from environment */
+    proxy_uri = g_getenv("HTTP_PROXY");
+    if (!proxy_uri)
+        proxy_uri = g_getenv("http_proxy");
+    if (proxy_uri) {
+        soup_proxy_uri = soup_uri_new (proxy_uri);
+        g_object_set(data->session, SOUP_SESSION_PROXY_URI,
+                     soup_proxy_uri, NULL);
+        soup_uri_free(soup_proxy_uri);
+    }
+
     data->scrollbox = gtk_scrollbox_new();
 
     data->size = xfce_panel_plugin_get_size(plugin);
diff --git a/panel-plugin/weather.h b/panel-plugin/weather.h
index 76b3c48..d4113c9 100644
--- a/panel-plugin/weather.h
+++ b/panel-plugin/weather.h
@@ -21,6 +21,7 @@
 
 #include <libxfce4panel/libxfce4panel.h>
 #include <libxfce4util/libxfce4util.h>
+#include <libsoup/soup.h>
 #include "weather-icon.h"
 
 #define PLUGIN_WEBSITE "http://goodies.xfce.org/projects/panel-plugins/xfce4-weather-plugin"
@@ -32,6 +33,8 @@ G_BEGIN_DECLS
 typedef struct {
     XfcePanelPlugin *plugin;
 
+    SoupSession *session;
+
     GtkWidget *top_vbox;
     GtkWidget *top_hbox;
     GtkWidget *vbox_center_scrollbox;
@@ -70,6 +73,15 @@ typedef struct {
 
 extern gboolean debug_mode;
 
+typedef void (*SoupSessionCallback) (SoupSession *session,
+                                     SoupMessage *msg,
+                                     gpointer user_data);
+
+void weather_http_queue_request(SoupSession *session,
+                                const gchar *uri,
+                                SoupSessionCallback callback_func,
+                                gpointer user_data);
+
 G_END_DECLS
 
 #endif


More information about the Xfce4-commits mailing list