bigboard r7244 - in trunk: . applet bigboard bigboard/stocks/people



Author: otaylor
Date: Wed Jan 30 19:17:43 2008
New Revision: 7244
URL: http://svn.gnome.org/viewvc/bigboard?rev=7244&view=rev

Log:
applet/*: Use libsoup to download icons, rather than an online-desktop D-BUS service
  that we no longer provide.

bigboard/people_tracker.py bigboard/stocks/people/peoplewidgets.py: Bug fixes


Modified:
   trunk/applet/apps.c
   trunk/applet/apps.h
   trunk/applet/bigboard-button.c
   trunk/applet/http.c
   trunk/applet/http.h
   trunk/applet/self.c
   trunk/bigboard/people_tracker.py
   trunk/bigboard/stocks/people/peoplewidgets.py
   trunk/configure.ac

Modified: trunk/applet/apps.c
==============================================================================
--- trunk/applet/apps.c	(original)
+++ trunk/applet/apps.c	Wed Jan 30 19:17:43 2008
@@ -17,6 +17,7 @@
 struct App
 {
     GObject parent;
+    SoupSession *soup_session;
     DDMDataResource *resource;
     char *icon_url;
     GdkPixbuf *icon;
@@ -42,7 +43,6 @@
 static void
 app_init(App *app)
 {
-
 }
 
 static void
@@ -104,18 +104,12 @@
 download_new_icon_url(App        *app,
                       const char *icon_url)
 {
-    DBusConnection *connection;
-    
     g_free(app->icon_url);
     app->icon_url = g_strdup(icon_url);
 
-    connection = dbus_bus_get(DBUS_BUS_SESSION, NULL);
-    if (connection == NULL)
-        return;
-
     if (app->icon_url) {
         /* g_debug("Sending http request for app icon %s", app->icon_url); */
-        http_get_pixbuf(connection,
+        http_get_pixbuf(app->soup_session,
                         app->icon_url,
                         on_got_icon,
                         app);
@@ -166,12 +160,14 @@
 }
     
 App*
-app_new(DDMDataResource *resource)
+app_new(SoupSession     *soup_session,
+        DDMDataResource *resource)
 {
     App *app;
 
     app = g_object_new(APP_TYPE, NULL);
 
+    app->soup_session = g_object_ref(soup_session);
     app->resource = ddm_data_resource_ref(resource);
 
     ddm_data_resource_connect(app->resource,
@@ -189,11 +185,20 @@
     App *app;
 
     app = APP(object);
-    
-    if (app->icon)
+
+    if (app->icon) {
         g_object_unref(app->icon);
+        app->icon = NULL;
+    }
+
+    if (app->soup_session) {
+        g_object_unref(app->soup_session);
+        app->soup_session = NULL;
+    }
     
     g_free(app->icon_url);
+
+    
 }
 
 static void

Modified: trunk/applet/apps.h
==============================================================================
--- trunk/applet/apps.h	(original)
+++ trunk/applet/apps.h	Wed Jan 30 19:17:43 2008
@@ -7,11 +7,13 @@
 #define DDM_I_KNOW_THIS_IS_UNSTABLE 1
 #include <ddm/ddm.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
+#include <libsoup/soup.h>
 
 G_BEGIN_DECLS
 
 typedef struct App App;
-App*        app_new               (DDMDataResource *resource);
+App*        app_new               (SoupSession     *soup_session,
+                                   DDMDataResource *resource);
 void        app_ref               (App             *app);
 void        app_unref             (App             *app);
 const char *app_get_tooltip       (App             *app);

Modified: trunk/applet/bigboard-button.c
==============================================================================
--- trunk/applet/bigboard-button.c	(original)
+++ trunk/applet/bigboard-button.c	Wed Jan 30 19:17:43 2008
@@ -1025,27 +1025,13 @@
 
 #include <stdlib.h>
 
-static void
-print_http_result_func(const char *content_type,
-                       GString    *content_or_error,
-                       void       *data)
-{
-        if (content_type == NULL) {
-                g_printerr("Error getting url: %s\n", content_or_error->str);
-                exit(1);
-        } else {
-                g_print("Received HTTP data, %d bytes content type %s\n",
-                        (int) content_or_error->len, content_type);
-                exit(0);
-        }
-}
-
 int
 main (int argc, char **argv)
 {
-#if 1
         GtkWidget *window;
 
+        g_thread_init(NULL);
+        
         gtk_init (&argc, &argv);
 
         log_debug_messages = TRUE;
@@ -1069,26 +1055,5 @@
         gtk_main ();
 
         return 0;
-#else
-        GMainLoop *loop;
-        DBusConnection *connection;
-
-        g_type_init();
-
-        connection = dbus_bus_get (DBUS_BUS_SESSION, NULL);
-        dbus_connection_setup_with_g_main(connection, NULL);
-
-        http_get(connection, "http://www.yahoo.com/";,
-                 print_http_result_func,
-                 NULL);
-
-        loop = g_main_loop_new(NULL, FALSE);
-
-        g_main_loop_run(loop);
-
-        dbus_connection_unref(connection);
-
-        return 0;
-#endif
 }
 #endif /* main() test mode */

Modified: trunk/applet/http.c
==============================================================================
--- trunk/applet/http.c	(original)
+++ trunk/applet/http.c	Wed Jan 30 19:17:43 2008
@@ -1,283 +1,10 @@
 /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
 
 #include "http.h"
-#include <unistd.h> /* getpid() */
-
-#define HIPPO_DBUS_HTTP_BUS_NAME  "org.freedesktop.od.Http"
-#define HIPPO_DBUS_HTTP_INTERFACE "org.freedesktop.od.Http"
-#define HIPPO_DBUS_HTTP_PATH      "/org/freedesktop/od/http"
-#define HIPPO_DBUS_HTTP_DATA_SINK_INTERFACE  "org.freedesktop.od.HttpDataSink"
-
-typedef struct {
-    int refcount;
-    DBusConnection *connection;
-    char *sink_path;
-    char *url;
-    char *content_type;
-    GString *content;    
-    HttpFunc func;
-    HttpPixbufFunc pixbuf_func;
-    void *data;
-    void *pixbuf_data;
-} Request;
-
-static void
-request_ref(Request *r)
-{
-    g_return_if_fail(r->refcount > 0);
-    r->refcount += 1;
-}
-
-static void
-request_unref(Request *r)
-{
-    g_return_if_fail(r->refcount > 0);
-    
-    r->refcount -= 1;
-    if (r->refcount == 0) {
-        if (r->connection)
-            dbus_connection_unref(r->connection);
-        g_free(r->sink_path);
-        g_free(r->url);
-        g_free(r->content_type);
-        if (r->content)
-            g_string_free(r->content, TRUE);
-        g_free(r);
-    }
-}
-
-static void
-request_unregister(Request *r)
-{
-    if (r->sink_path) {
-        hippo_dbus_helper_unregister_object(r->connection,
-                                            r->sink_path);
-        g_free(r->sink_path);
-        r->sink_path = NULL;
-    }
-}
-
-static void
-request_failed(Request    *r,
-               const char *message)
-{
-    GString *str;
-
-    /* remember the failure could come after a partial success */
-
-    if (r->sink_path) {
-        request_unregister(r);
-        
-        str = g_string_new(message);
-        (* r->func) (NULL, str, r->data);
-        g_string_free(str, TRUE);
-        
-        /* drop ref held by the object registration */
-        request_unref(r);
-    }
-}
-
-static DBusMessage*
-handle_error (void            *object,
-              DBusMessage     *message,
-              DBusError       *error)
-{
-    const char *what;
-    Request *r;
-
-#ifdef VERBOSE_HTTP
-    g_debug("Got Error() in http sink");
-#endif
-    
-    r = object;
-    
-    what = NULL;
-    dbus_message_get_args(message, NULL,
-                          DBUS_TYPE_STRING, &what,
-                          DBUS_TYPE_INVALID);
-
-    /* call error callback and unregister object */
-    request_failed(r, what);
-
-    return dbus_message_new_method_return(message);
-}
-
-static DBusMessage*
-handle_begin (void            *object,
-              DBusMessage     *message,
-              DBusError       *error)
-{
-    Request *r;
-    const char *content_type;
-    gint64 estimated_size;
-
-#ifdef VERBOSE_HTTP
-    g_debug("Got Begin() in http sink");
-#endif
-    
-    r = object;
-
-    if (r->content_type != NULL) {
-        dbus_set_error(error, DBUS_ERROR_FAILED,
-                       "Begin() invoked twice");
-        request_failed(r, "Received two Begin() from http provider");
-        return NULL;
-    }
-    
-    content_type = NULL;
-    estimated_size = 0;
-    dbus_message_get_args(message, NULL,
-                          DBUS_TYPE_STRING, &content_type,
-                          DBUS_TYPE_INT64, &estimated_size,
-                          DBUS_TYPE_INVALID);
-
-    r->content_type = g_strdup(content_type);
-    r->content = g_string_sized_new(MIN(estimated_size, 1024*64) + 16);
-
-#ifdef VERBOSE_HTTP
-    g_debug("  content-type '%s' estimated size %d", content_type, (int) estimated_size);
-#endif
-    
-    return dbus_message_new_method_return(message);
-}
-
-static DBusMessage*
-handle_end (void            *object,
-            DBusMessage     *message,
-            DBusError       *error)
-{
-    Request *r;
-
-#ifdef VERBOSE_HTTP
-    g_debug("Got End() in http sink");
-#endif
-    
-    r = object;
-
-    if (r->content_type == NULL) {
-        dbus_set_error(error, DBUS_ERROR_FAILED,
-                       "End() invoked but no Begin()");
-        request_failed(r, "Received End() with no Begin() from http provider");
-        return NULL;
-    }
-
-    if (r->sink_path) {
-        request_unregister(r);
-        
-        (* r->func) (r->content_type, r->content, r->data);
-        
-        /* drop ref held by registration */
-        request_unref(r);
-    }
-
-    return dbus_message_new_method_return(message);
-}
-
-static DBusMessage*
-handle_data (void            *object,
-             DBusMessage     *message,
-             DBusError       *error)
-{
-    Request *r;
-    const char *bytes;
-    int bytes_len;
-    gint64 start_offset;
-    gint64 estimated_remaining;
-    DBusMessageIter toplevel_iter, array_iter;
-
-#ifdef VERBOSE_HTTP
-    g_debug("Got Data() in http sink");
-#endif
-    
-    r = object;
-
-    if (r->content_type == NULL) {
-        dbus_set_error(error, DBUS_ERROR_FAILED,
-                       "Data() invoked but no Begin()");
-        request_failed(r, "Received Data() with no Begin() from http provider");
-        return NULL;
-    }
-
-    dbus_message_iter_init(message, &toplevel_iter);
-    dbus_message_iter_get_basic(&toplevel_iter, &start_offset);
-    dbus_message_iter_next(&toplevel_iter);
-
-    dbus_message_iter_get_basic(&toplevel_iter, &estimated_remaining);
-    dbus_message_iter_next(&toplevel_iter);
-
-    dbus_message_iter_recurse(&toplevel_iter, &array_iter);
-
-    bytes = NULL;
-    bytes_len = 0;
-    dbus_message_iter_get_fixed_array(&array_iter, &bytes, &bytes_len);
-
-    if (start_offset != (gint64) r->content->len) {
-        dbus_set_error(error, DBUS_ERROR_FAILED,
-                       "Data() received for byte %ld but expecting next byte to be %ld",
-                       (long) start_offset, (long) r->content->len);
-        request_failed(r, "Received wrong byte offset in Data() from http provider");
-        return NULL;
-    }
-
-    g_string_append_len(r->content, bytes, bytes_len);
-
-    return dbus_message_new_method_return(message);
-}
-
-static const HippoDBusMember sink_members[] = {
-    /* arg is error message */
-    { HIPPO_DBUS_MEMBER_METHOD, "Error", "s",  "",       handle_error },
-    /* args are content type and estimated data length */
-    { HIPPO_DBUS_MEMBER_METHOD, "Begin", "sx", "",       handle_begin },
-    { HIPPO_DBUS_MEMBER_METHOD, "End",   "",   "",       handle_end },
-    /* args are total data sent in previous calls, estimated remaining data, and a block of data */
-    { HIPPO_DBUS_MEMBER_METHOD, "Data",  "xxay",   "",   handle_data },
-    { 0, NULL }
-};
-
-static const HippoDBusProperty sink_properties[] = {
-    { NULL }
-};
-
-
-static void
-on_request_reply(DBusMessage *reply,
-                 void        *data)
-{
-    Request *r = data;
-
-#ifdef VERBOSE_HTTP
-    g_debug("Got reply to http request message");
-#endif
-    
-    if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
-        const char *message = NULL;
-        if (dbus_message_get_args(reply, NULL,
-                                  DBUS_TYPE_STRING, &message,
-                                  DBUS_TYPE_INVALID)) {
-            request_failed(r, message);
-        } else {
-            request_failed(r, "Unknown error");
-        }
-    }
-
-    /* If it wasn't an error there's nothing to do yet, we just wait for
-     * the data sink to hear something back.
-     *
-     * To be fully robust we should bind to the specific HTTP provider's
-     * unique bus name and monitor when it vanishes, or alternatively
-     * have some kind of timeout. FIXME
-     */
-
-    /* drop ref owned by the reply, leaving one owned by the registration
-     * object path
-     */
-    request_unref(r);
-}
-
 
 static GdkPixbuf*
-pixbuf_parse(GString               *content,
+pixbuf_parse(const char            *data,
+             guint                  length,
              GError               **error_p)
 {
     GdkPixbufLoader *loader;
@@ -285,7 +12,7 @@
 
     loader = gdk_pixbuf_loader_new();
 
-    if (!gdk_pixbuf_loader_write(loader, (guchar*) content->str, content->len, error_p))
+    if (!gdk_pixbuf_loader_write(loader, (guchar*) data, length, error_p))
         goto failed;
     
     if (!gdk_pixbuf_loader_close(loader, error_p))
@@ -313,130 +40,57 @@
     return NULL;
 }
 
+typedef struct {
+    HttpPixbufFunc func;
+    void *data;
+} GetPixbufClosure;
+
 static void
-pixbuf_closure_func(const char *content_type,
-                    GString    *content_or_error,
-                    void       *data)
+on_pixbuf_result(SoupSession  *session,
+                 SoupMessage  *message,
+                 void         *data)
 {
-    GdkPixbuf *new_icon;
+    GetPixbufClosure *closure = data;
+    GdkPixbuf *new_icon = NULL;
     GError *error;
-    Request *r;
-
-    r = data;
-
+    
 #ifdef VERBOSE_HTTP
     g_debug("Got reply to http GET for pixbuf");
 #endif
-    
-    if (content_type == NULL) {
-        g_printerr("Failed to download image: %s\n",
-                   content_or_error->str);
-        (* r->pixbuf_func) (NULL, r->pixbuf_data);
-        return;
-    }
 
+    if (!SOUP_STATUS_IS_SUCCESSFUL(message->status_code)) {
+        g_printerr("Failed to download image: %d\n", message->status_code);
+        goto out;
+    }
+    
     error = NULL;
-    new_icon = pixbuf_parse(content_or_error, &error);
+    new_icon = pixbuf_parse(message->response_body->data, message->response_body->length, &error);
     if (new_icon == NULL) {
-        g_printerr("Failed to parse image: %s\n",
-                   error->message);
+        g_printerr("Failed to parse image: %s\n", error->message);
         g_error_free(error);
-        (* r->pixbuf_func) (NULL, r->pixbuf_data);
-        return;
+        goto out;
     }
 
-    g_assert(GDK_IS_PIXBUF(new_icon));
-    (* r->pixbuf_func) (new_icon, r->pixbuf_data);
-    g_assert(GDK_IS_PIXBUF(new_icon));
+ out:
+    (* closure->func) (new_icon, closure->data);
     
-    g_object_unref(new_icon);
-}
-
-static void
-http_get_full(DBusConnection *connection,
-              const char     *url,
-              HttpFunc        func,
-              HttpPixbufFunc  pixbuf_func,
-              void           *data)
-{
-    Request *r;
-    HippoDBusProxy *proxy;
-    static int sink_number = 0;
-
-    g_return_if_fail(!(func && pixbuf_func));
-    g_return_if_fail(func || pixbuf_func);
-    
-    hippo_dbus_helper_register_interface(connection,
-                                         HIPPO_DBUS_HTTP_DATA_SINK_INTERFACE,
-                                         sink_members, sink_properties);
-
-    r = g_new0(Request, 1);
-    r->refcount = 1;
-    r->connection = connection;
-    dbus_connection_ref(r->connection);
-    r->url = g_strdup(url);
-
-    if (func) {
-        r->func = func;
-        r->data = data;
-    } else {
-        r->func = pixbuf_closure_func;
-        r->data = r;
-    }
-
-    r->pixbuf_func = pixbuf_func;
-    r->pixbuf_data = data;
-
-    /* the pid is to prevent recycling issues when we restart, though
-     * in theory the other end should also deal with this by using
-     * our unique bus name
-     */
-    r->sink_path = g_strdup_printf("/org/freedesktop/od/http_sinks/%d_%d",
-                                   sink_number, (int) getpid());
-    sink_number += 1;
-    
-    /* pass ownership of initial refcount to the registration */
-    hippo_dbus_helper_register_object(connection,
-                                      r->sink_path,
-                                      r,
-                                      HIPPO_DBUS_HTTP_DATA_SINK_INTERFACE,
-                                      NULL);
-    
-    proxy = hippo_dbus_proxy_new(connection,
-                                 HIPPO_DBUS_HTTP_BUS_NAME,
-                                 HIPPO_DBUS_HTTP_PATH,
-                                 HIPPO_DBUS_HTTP_INTERFACE);
-    request_ref(r); /* extra ref held by the reply handler */
-    hippo_dbus_proxy_call_method_async(proxy,
-                                       "Request",
-                                       on_request_reply,
-                                       r,
-                                       NULL,
-                                       DBUS_TYPE_STRING, &r->url,
-                                       DBUS_TYPE_OBJECT_PATH, &r->sink_path,
-                                       DBUS_TYPE_INVALID);
-    hippo_dbus_proxy_unref(proxy);
-
-#ifdef VERBOSE_HTTP
-    g_debug("requesting http url '%s' using sink path '%s'",
-            r->url, r->sink_path);
-#endif
+    if (new_icon)
+        g_object_unref(new_icon);
 }
 
 void
-http_get(DBusConnection *connection,
-         const char     *url,
-         HttpFunc        func,
-         void           *data)
-{
-    http_get_full(connection, url, func, NULL, data);
-}
-
-void
-http_get_pixbuf(DBusConnection *connection,
+http_get_pixbuf(SoupSession   *session,
                 const char     *url,
                 HttpPixbufFunc  func,
                 void           *data)
 {
-    http_get_full(connection, url, NULL, func, data);
+    SoupMessage *message;
+    GetPixbufClosure *closure;
+
+    closure = g_new0(GetPixbufClosure, 1);
+    closure->func = func;
+    closure->data = data;
+
+    message = soup_message_new("GET", url);
+    soup_session_queue_message(session, message, on_pixbuf_result, closure);
 }

Modified: trunk/applet/http.h
==============================================================================
--- trunk/applet/http.h	(original)
+++ trunk/applet/http.h	Wed Jan 30 19:17:43 2008
@@ -2,24 +2,15 @@
 #ifndef __HTTP_H__
 #define __HTTP_H__
 
-#include "hippo-dbus-helper.h"
+#include <libsoup/soup.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
 G_BEGIN_DECLS
 
-typedef void (* HttpFunc) (const char *content_type,
-                           GString    *content_or_error,
-                           void       *data);
-
 typedef void (* HttpPixbufFunc) (GdkPixbuf  *pixbuf_or_null,
                                  void       *data);
 
-void http_get(DBusConnection *connection,
-              const char     *url,
-              HttpFunc        func,
-              void           *data);
-
-void http_get_pixbuf(DBusConnection *connection,
+void http_get_pixbuf(SoupSession    *session,
                      const char     *url,
                      HttpPixbufFunc  func,
                      void           *data);

Modified: trunk/applet/self.c
==============================================================================
--- trunk/applet/self.c	(original)
+++ trunk/applet/self.c	Wed Jan 30 19:17:43 2008
@@ -20,6 +20,7 @@
 } AppsChangedClosure;
 
 typedef struct {
+    SoupSession *soup_session;
     DDMDataModel *ddm_model;
     DDMDataResource *self_resource;
     char *photo_url;
@@ -66,18 +67,12 @@
 download_new_photo_url(SelfData   *sd,
                        const char *photo_url)
 {
-    DBusConnection *connection;
-    
     g_free(sd->photo_url);
     sd->photo_url = g_strdup(photo_url);
 
-    connection = dbus_bus_get(DBUS_BUS_SESSION, NULL);
-    if (connection == NULL)
-        return;
-
     if (sd->photo_url) {
         g_debug("Sending http request for user photo %s", sd->photo_url);
-        http_get_pixbuf(connection,
+        http_get_pixbuf(sd->soup_session,
                         sd->photo_url,
                         on_got_photo,
                         sd);
@@ -212,7 +207,7 @@
                 old_app = NULL;
             
             if (old_app == NULL) {
-                new_app = app_new(new_app_resource);
+                new_app = app_new(sd->soup_session, new_app_resource);
                 new_created += 1;
             } else {
                 app_ref(old_app);
@@ -336,6 +331,7 @@
 {
     if (global_self_data == NULL) {
         global_self_data = g_new0(SelfData, 1);
+        global_self_data->soup_session = soup_session_async_new();
         global_self_data->ddm_model = ddm_data_model_get_default();
 
         g_signal_connect(G_OBJECT(global_self_data->ddm_model),

Modified: trunk/bigboard/people_tracker.py
==============================================================================
--- trunk/bigboard/people_tracker.py	(original)
+++ trunk/bigboard/people_tracker.py	Wed Jan 30 19:17:43 2008
@@ -136,6 +136,8 @@
         self.__update_aim_buddies()
         self.__update_xmpp_buddies()
         self.__update_local_buddies()
+        self.__update_aims()
+        self.__update_xmpps()
         
     ##############################################################
         

Modified: trunk/bigboard/stocks/people/peoplewidgets.py
==============================================================================
--- trunk/bigboard/stocks/people/peoplewidgets.py	(original)
+++ trunk/bigboard/stocks/people/peoplewidgets.py	Wed Jan 30 19:17:43 2008
@@ -711,9 +711,9 @@
         if self.person.aims:
             self.__create_contact('aim', self.person.aims[0])
         elif self.person.xmpps:
-            self.__create_contact('xmpp', self.person.xmpp[0])
-        elif self.person.local_buddy:
-            self.__create_user_contact(self.person.local_buddy.user)
+            self.__create_contact('xmpp', self.person.xmpps[0])
+        elif self.person.local_buddies:
+            self.__create_user_contact(self.person.local_buddies[0].user)
 
         # action_taken = False to leave the stock open which seems nicer in this case
         self.emit("close", False)

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Wed Jan 30 19:17:43 2008
@@ -161,7 +161,7 @@
 AC_SUBST(BIGBOARD_LIBS)
 AC_SUBST(BIGBOARD_CFLAGS)
 
-PKG_CHECK_MODULES(BIGBOARD_APPLET, libpanelapplet-2.0 gtk+-2.0 >= 2.8 dbus-1 ddm-1 gnome-desktop-2.0 gnome-vfs-2.0)
+PKG_CHECK_MODULES(BIGBOARD_APPLET, libpanelapplet-2.0 gtk+-2.0 >= 2.8 dbus-1 ddm-1 gnome-desktop-2.0 gnome-vfs-2.0 libsoup-2.4 >= 2.3.0)
 AC_SUBST(BIGBOARD_APPLET_LIBS)
 AC_SUBST(BIGBOARD_APPLET_CFLAGS)
 



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