[gnome-video-arcade] Add gva_get_soup_session().



commit 01c8a4c4795406809dc52b9f6e083eb04238c029
Author: Matthew Barnes <mbarnes redhat com>
Date:   Fri Jun 3 21:38:46 2011 -0500

    Add gva_get_soup_session().

 docs/reference/gnome-video-arcade-sections.txt |    1 +
 docs/reference/tmpl/gva-util.sgml              |    9 +++++
 src/gva-common.h                               |    1 +
 src/gva-util.c                                 |   39 ++++++++++++++++++++++++
 src/gva-util.h                                 |    1 +
 5 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gnome-video-arcade-sections.txt b/docs/reference/gnome-video-arcade-sections.txt
index f39d7fa..99acb84 100644
--- a/docs/reference/gnome-video-arcade-sections.txt
+++ b/docs/reference/gnome-video-arcade-sections.txt
@@ -520,6 +520,7 @@ GvaDebugFlags
 gva_get_last_version
 gva_get_monospace_font_name
 gva_get_settings
+gva_get_soup_session
 gva_get_time_elapsed
 gva_get_user_data_dir
 gva_help_display
diff --git a/docs/reference/tmpl/gva-util.sgml b/docs/reference/tmpl/gva-util.sgml
index 8bf96c9..822a791 100644
--- a/docs/reference/tmpl/gva-util.sgml
+++ b/docs/reference/tmpl/gva-util.sgml
@@ -87,6 +87,15 @@
 @Returns: 
 
 
+<!-- ##### FUNCTION gva_get_soup_session ##### -->
+<para>
+
+</para>
+
+ void: 
+ Returns: 
+
+
 <!-- ##### FUNCTION gva_get_time_elapsed ##### -->
 <para>
 
diff --git a/src/gva-common.h b/src/gva-common.h
index bcc97ce..7555b27 100644
--- a/src/gva-common.h
+++ b/src/gva-common.h
@@ -39,6 +39,7 @@
 #endif
 
 #include <sqlite3.h>
+#include <libsoup/soup.h>
 
 #define GVA_SETTING_ALL_COLUMNS                 "all-columns"
 #define GVA_SETTING_AUTO_PLAY                   "auto-play"
diff --git a/src/gva-util.c b/src/gva-util.c
index 7c62527..9ff83da 100644
--- a/src/gva-util.c
+++ b/src/gva-util.c
@@ -23,6 +23,10 @@
 #include "gva-error.h"
 #include "gva-mame.h"
 
+/* SoupCache API is still unstable as of libsoup 2.35. */
+#define LIBSOUP_USE_UNSTABLE_REQUEST_API
+#include <libsoup/soup-cache.h>
+
 #define DEFAULT_MONOSPACE_FONT_NAME     "Monospace 10"
 
 /* Command Line Options */
@@ -280,6 +284,41 @@ gva_get_settings (void)
 }
 
 /**
+ * gva_get_soup_session:
+ *
+ * Returns a #SoupSessionAsync configured to cache responses.
+ *
+ * Returns: the #SoupSession object for
+ *          <emphasis>GNOME Video Arcade</emphasis>
+ **/
+SoupSession *
+gva_get_soup_session (void)
+{
+        static SoupSession *soup_session = NULL;
+
+        if (G_UNLIKELY (soup_session == NULL))
+        {
+                soup_session = soup_session_async_new ();
+
+                soup_session_add_feature_by_type (
+                        soup_session, SOUP_TYPE_CACHE);
+
+                if (gva_get_debug_flags () & GVA_DEBUG_HTTP)
+                        soup_session_add_feature_by_type (
+                                soup_session, SOUP_TYPE_LOGGER);
+
+                /* Spoof the "User-Agent" header,
+                 * otherwise MAWS will block us. */
+                g_object_set (
+                        soup_session,
+                        SOUP_SESSION_USER_AGENT,
+                        "Mozilla/5.0", NULL);
+        }
+
+        return soup_session;
+}
+
+/**
  * gva_get_time_elapsed:
  * @start_time: a start time
  * @time_elapsed: location to put the time elasped
diff --git a/src/gva-util.h b/src/gva-util.h
index 3285d90..d24e6d8 100644
--- a/src/gva-util.h
+++ b/src/gva-util.h
@@ -70,6 +70,7 @@ GvaDebugFlags   gva_get_debug_flags             (void);
 const gchar *   gva_get_last_version            (void);
 gchar *         gva_get_monospace_font_name     (void);
 GSettings *     gva_get_settings                (void);
+SoupSession *   gva_get_soup_session            (void);
 void            gva_get_time_elapsed            (GTimeVal *start_time,
                                                  GTimeVal *time_elapsed);
 const gchar *   gva_get_user_data_dir           (void);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]