[libsocialweb] Added video upload support to flickr service.



commit 4ed40613b7b1720c1261de80a96031ebf860e11d
Author: Eitan Isaacson <eitan monotonous org>
Date:   Wed Jan 26 14:26:49 2011 +0200

    Added video upload support to flickr service.

 services/flickr/flickr.c |  133 +++++++++++++++++++++++++++++++++++-----------
 1 files changed, 101 insertions(+), 32 deletions(-)
---
diff --git a/services/flickr/flickr.c b/services/flickr/flickr.c
index 4a3b801..b3d2251 100644
--- a/services/flickr/flickr.c
+++ b/services/flickr/flickr.c
@@ -38,6 +38,7 @@
 
 #include <interfaces/sw-query-ginterface.h>
 #include <interfaces/sw-photo-upload-ginterface.h>
+#include <interfaces/sw-video-upload-ginterface.h>
 
 #include "flickr-item-view.h"
 #include "flickr.h"
@@ -46,11 +47,13 @@
 static void initable_iface_init (gpointer g_iface, gpointer iface_data);
 static void query_iface_init (gpointer g_iface, gpointer iface_data);
 static void photo_upload_iface_init (gpointer g_iface, gpointer iface_data);
+static void video_upload_iface_init (gpointer g_iface, gpointer iface_data);
 
 G_DEFINE_TYPE_WITH_CODE (SwServiceFlickr, sw_service_flickr, SW_TYPE_SERVICE,
                          G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)
                          G_IMPLEMENT_INTERFACE (SW_TYPE_QUERY_IFACE, query_iface_init)
-                         G_IMPLEMENT_INTERFACE (SW_TYPE_PHOTO_UPLOAD_IFACE, photo_upload_iface_init));
+                         G_IMPLEMENT_INTERFACE (SW_TYPE_PHOTO_UPLOAD_IFACE, photo_upload_iface_init)
+                         G_IMPLEMENT_INTERFACE (SW_TYPE_VIDEO_UPLOAD_IFACE, video_upload_iface_init));
 
 #define GET_PRIVATE(o) \
   (G_TYPE_INSTANCE_GET_PRIVATE ((o), SW_TYPE_SERVICE_FLICKR, SwServiceFlickrPrivate))
@@ -68,6 +71,7 @@ get_static_caps (SwService *service)
   static const char * caps[] = {
     CAN_VERIFY_CREDENTIALS,
     HAS_PHOTO_UPLOAD_IFACE,
+    HAS_VIDEO_UPLOAD_IFACE,
     HAS_BANISHABLE_IFACE,
     HAS_QUERY_IFACE,
 
@@ -360,24 +364,6 @@ query_iface_init (gpointer g_iface,
                                       _flickr_query_open_view);
 }
 
-static void
-on_upload_cb (RestProxyCall *call,
-              const GError *error,
-              GObject *weak_object,
-              gpointer user_data)
-{
-  SwServiceFlickr *flickr = SW_SERVICE_FLICKR (weak_object);
-  int opid = GPOINTER_TO_INT (user_data);
-
-  if (error) {
-    sw_photo_upload_iface_emit_photo_upload_progress (flickr, opid, -1, error->message);
-    /* TODO: clean up */
-  } else {
-    /* TODO: check flickr error state */
-    sw_photo_upload_iface_emit_photo_upload_progress (flickr, opid, 100, "");
-  }
-}
-
 /* If @param_name exists in the DBus parameters, set @flickr_name on the
    RestProxyCall */
 #define MAP_PARAM(param_name, flickr_name)                      \
@@ -388,24 +374,23 @@ on_upload_cb (RestProxyCall *call,
       rest_proxy_call_add_param (call, flickr_name, param);     \
   }
 
-static void
-_flickr_upload_photo (SwPhotoUploadIface    *self,
-                      const gchar           *filename,
-                      GHashTable            *params_in,
-                      DBusGMethodInvocation *context)
+static gint
+_flickr_upload (SwServiceFlickr           *self,
+                const gchar               *filename,
+                GHashTable                *params_in,
+                GError                   **error,
+                RestProxyCallAsyncCallback callback)
 {
   SwServiceFlickrPrivate *priv = GET_PRIVATE (self);
-  GError *error = NULL;
   RestProxyCall *call;
-  int opid;
+  gint opid;
 
   call = flickr_proxy_new_upload_for_file (FLICKR_PROXY (priv->proxy),
                                            filename,
-                                           &error);
+                                           error);
 
-  if (error) {
-    dbus_g_method_return_error (context, error);
-    return;
+  if (*error != NULL) {
+    return -1;
   }
 
   /* Now add the parameters that we support */
@@ -416,9 +401,46 @@ _flickr_upload_photo (SwPhotoUploadIface    *self,
 
   opid = sw_next_opid ();
 
-  rest_proxy_call_async (call, on_upload_cb, (GObject *)self, GINT_TO_POINTER (opid), NULL);
+  rest_proxy_call_async (call, callback, (GObject *)self,
+                         GINT_TO_POINTER (opid), NULL);
 
-  sw_photo_upload_iface_return_from_upload_photo (context, opid);
+  return opid;
+}
+
+static void
+on_photo_upload_cb (RestProxyCall *call,
+              const GError *error,
+              GObject *weak_object,
+              gpointer user_data)
+{
+  SwServiceFlickr *flickr = SW_SERVICE_FLICKR (weak_object);
+  int opid = GPOINTER_TO_INT (user_data);
+
+  if (error) {
+    sw_photo_upload_iface_emit_photo_upload_progress (flickr, opid, -1, error->message);
+    /* TODO: clean up */
+  } else {
+    /* TODO: check flickr error state */
+    sw_photo_upload_iface_emit_photo_upload_progress (flickr, opid, 100, "");
+  }
+}
+
+static void
+_flickr_upload_photo (SwPhotoUploadIface    *self,
+                      const gchar           *filename,
+                      GHashTable            *params_in,
+                      DBusGMethodInvocation *context)
+{
+  GError *error = NULL;
+  int opid;
+
+  opid = _flickr_upload (SW_SERVICE_FLICKR (self), filename, params_in,
+                         &error, on_photo_upload_cb);
+
+  if (opid == -1)
+    dbus_g_method_return_error (context, error);
+  else
+    sw_photo_upload_iface_return_from_upload_photo (context, opid);
 }
 
 
@@ -432,6 +454,53 @@ photo_upload_iface_init (gpointer g_iface,
                                                 _flickr_upload_photo);
 }
 
+static void
+on_video_upload_cb (RestProxyCall *call,
+              const GError *error,
+              GObject *weak_object,
+              gpointer user_data)
+{
+  SwServiceFlickr *flickr = SW_SERVICE_FLICKR (weak_object);
+  int opid = GPOINTER_TO_INT (user_data);
+
+  if (error) {
+    sw_video_upload_iface_emit_video_upload_progress (flickr, opid, -1, error->message);
+    /* TODO: clean up */
+  } else {
+    /* TODO: check flickr error state */
+    sw_video_upload_iface_emit_video_upload_progress (flickr, opid, 100, "");
+  }
+}
+
+static void
+_flickr_upload_video (SwVideoUploadIface    *self,
+                      const gchar           *filename,
+                      GHashTable            *params_in,
+                      DBusGMethodInvocation *context)
+{
+  GError *error = NULL;
+  int opid;
+
+  opid = _flickr_upload (SW_SERVICE_FLICKR (self), filename, params_in,
+                         &error, on_video_upload_cb);
+
+  if (opid == -1)
+    dbus_g_method_return_error (context, error);
+  else
+    sw_video_upload_iface_return_from_upload_video (context, opid);
+}
+
+
+static void
+video_upload_iface_init (gpointer g_iface,
+                         gpointer iface_data)
+{
+  SwVideoUploadIfaceClass *klass = (SwVideoUploadIfaceClass *)g_iface;
+
+  sw_video_upload_iface_implement_upload_video (klass,
+                                                _flickr_upload_video);
+}
+
 
 static void
 sw_service_flickr_class_init (SwServiceFlickrClass *klass)



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