[libsocialweb: 4/7] smugmug: Added SmugMug video upload.



commit 419ff2d06492ffbefbc9557cd1cc5de174a2de60
Author: Eitan Isaacson <eitan isaacson collabora co uk>
Date:   Fri Feb 11 12:10:58 2011 -0800

    smugmug: Added SmugMug video upload.

 services/smugmug/smugmug.c |   62 +++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 58 insertions(+), 4 deletions(-)
---
diff --git a/services/smugmug/smugmug.c b/services/smugmug/smugmug.c
index 2e006b7..f5b47d6 100644
--- a/services/smugmug/smugmug.c
+++ b/services/smugmug/smugmug.c
@@ -43,6 +43,7 @@
 
 #include <interfaces/sw-collections-ginterface.h>
 #include <interfaces/sw-photo-upload-ginterface.h>
+#include <interfaces/sw-video-upload-ginterface.h>
 
 #include "smugmug.h"
 
@@ -52,12 +53,15 @@
 
 static void collections_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 (SwServiceSmugmug, sw_service_smugmug, SW_TYPE_SERVICE,
                          G_IMPLEMENT_INTERFACE (SW_TYPE_COLLECTIONS_IFACE,
                                                 collections_iface_init)
                          G_IMPLEMENT_INTERFACE (SW_TYPE_PHOTO_UPLOAD_IFACE,
-                                                photo_upload_iface_init));
+                                                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_SMUGMUG, SwServiceSmugmugPrivate))
@@ -88,6 +92,7 @@ get_static_caps (SwService *service)
 {
   static const char * caps[] = {
     HAS_PHOTO_UPLOAD_IFACE,
+    HAS_VIDEO_UPLOAD_IFACE,
     HAS_BANISHABLE_IFACE,
 
     NULL
@@ -301,7 +306,7 @@ _upload_file (SwServiceSmugmug *self,
         {
           rest_proxy_call_add_param (call, "Caption", param_value);
         }
-      else
+      else if (strlen (param_value) > 0)
         {
           rest_proxy_call_add_param (call, param_key, param_value);
         }
@@ -317,12 +322,12 @@ _upload_file (SwServiceSmugmug *self,
 
   rest_proxy_call_add_param_full (call, param);
 
-
-
   rest_proxy_call_set_method (call, "POST");
 
   opid = sw_next_opid ();
 
+  SW_DEBUG (SMUGMUG, "Uploading %s (%s)", basename, bytecount);
+
   rest_proxy_call_async (call,
                          upload_cb,
                          G_OBJECT (self),
@@ -628,6 +633,55 @@ photo_upload_iface_init (gpointer g_iface,
 
 }
 
+/* Video Upload Interface */
+
+static void
+_upload_video_cb (RestProxyCall *call,
+                  const GError  *error,
+                  GObject       *weak_object,
+                  gpointer       user_data)
+{
+  SwServiceSmugmug *self = SW_SERVICE_SMUGMUG (weak_object);
+  int opid = GPOINTER_TO_INT (user_data);
+
+  if (error) {
+    sw_video_upload_iface_emit_video_upload_progress (self, opid, -1,
+        error->message);
+  } else {
+    sw_video_upload_iface_emit_video_upload_progress (self, opid, 100, "");
+  }
+}
+
+static void
+_smugmug_upload_video (SwVideoUploadIface    *self,
+                       const gchar           *filename,
+                       GHashTable            *fields,
+                       DBusGMethodInvocation *context)
+{
+  GError *error = NULL;
+  gint opid = _upload_file (SW_SERVICE_SMUGMUG (self), VIDEO, filename, fields,
+                       (RestProxyCallAsyncCallback) _upload_video_cb, &error);
+
+  if (error) {
+    dbus_g_method_return_error (context, error);
+    g_error_free (error);
+    return;
+  }
+
+  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,
+                                                _smugmug_upload_video);
+
+}
+
 static void
 sw_service_smugmug_class_init (SwServiceSmugmugClass *klass)
 {



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