[libzapojit] Implement videos
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libzapojit] Implement videos
- Date: Thu, 24 Oct 2013 12:16:18 +0000 (UTC)
commit df3072e7ff3ab28a7a8c58c3e8f13e4dd2c4522d
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Oct 23 16:29:15 2013 +0200
Implement videos
docs/reference/libzapojit-0.0-docs.sgml | 1 +
src/Makefile.am | 2 +
src/zpj-skydrive-entry.c | 6 +
src/zpj-skydrive-entry.h | 2 +
src/zpj-skydrive-video.c | 265 +++++++++++++++++++++++++++++++
src/zpj-skydrive-video.h | 93 +++++++++++
src/zpj-skydrive.c | 3 +
src/zpj.h | 3 +-
8 files changed, 374 insertions(+), 1 deletions(-)
---
diff --git a/docs/reference/libzapojit-0.0-docs.sgml b/docs/reference/libzapojit-0.0-docs.sgml
index ea47ea6..25c241c 100644
--- a/docs/reference/libzapojit-0.0-docs.sgml
+++ b/docs/reference/libzapojit-0.0-docs.sgml
@@ -61,6 +61,7 @@
<xi:include href="xml/zpj-skydrive-file.xml"/>
<xi:include href="xml/zpj-skydrive-folder.xml"/>
<xi:include href="xml/zpj-skydrive-photo.xml"/>
+ <xi:include href="xml/zpj-skydrive-video.xml"/>
<xi:include href="xml/zpj-error.xml"/>
</chapter>
diff --git a/src/Makefile.am b/src/Makefile.am
index 63048e5..7ca9466 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -16,6 +16,7 @@ libzapojit_0_0_la_headers = \
zpj-skydrive-file.h \
zpj-skydrive-folder.h \
zpj-skydrive-photo.h \
+ zpj-skydrive-video.h \
$(NULL)
libzapojit_0_0_la_SOURCES = \
@@ -29,6 +30,7 @@ libzapojit_0_0_la_SOURCES = \
zpj-skydrive-file.c \
zpj-skydrive-folder.c \
zpj-skydrive-photo.c \
+ zpj-skydrive-video.c \
$(NULL)
BUILT_SOURCES = \
diff --git a/src/zpj-skydrive-entry.c b/src/zpj-skydrive-entry.c
index 38f3484..df42a45 100644
--- a/src/zpj-skydrive-entry.c
+++ b/src/zpj-skydrive-entry.c
@@ -28,6 +28,7 @@
#include "zpj-skydrive-file.h"
#include "zpj-skydrive-folder.h"
#include "zpj-skydrive-photo.h"
+#include "zpj-skydrive-video.h"
/**
@@ -142,6 +143,11 @@ zpj_skydrive_entry_default_parse_json_node (ZpjSkydriveEntry *self, JsonNode *no
g_assert_cmpuint (G_OBJECT_TYPE (self), ==, ZPJ_TYPE_SKYDRIVE_PHOTO);
priv->type = ZPJ_SKYDRIVE_ENTRY_TYPE_PHOTO;
}
+ else if (g_strcmp0 (type, "video") == 0)
+ {
+ g_assert_cmpuint (G_OBJECT_TYPE (self), ==, ZPJ_TYPE_SKYDRIVE_VIDEO);
+ priv->type = ZPJ_SKYDRIVE_ENTRY_TYPE_VIDEO;
+ }
else
g_warning ("unknown type: %s", type);
}
diff --git a/src/zpj-skydrive-entry.h b/src/zpj-skydrive-entry.h
index 624d42d..4774f45 100644
--- a/src/zpj-skydrive-entry.h
+++ b/src/zpj-skydrive-entry.h
@@ -53,6 +53,7 @@ G_BEGIN_DECLS
* @ZPJ_SKYDRIVE_ENTRY_TYPE_FILE: A file.
* @ZPJ_SKYDRIVE_ENTRY_TYPE_FOLDER: A folder.
* @ZPJ_SKYDRIVE_ENTRY_TYPE_PHOTO: A photo.
+ * @ZPJ_SKYDRIVE_ENTRY_TYPE_VIDEO: A video.
* @ZPJ_SKYDRIVE_ENTRY_TYPE_INVALID: Invalid or unknown object.
*
* The types of Skydrive
@@ -66,6 +67,7 @@ typedef enum
ZPJ_SKYDRIVE_ENTRY_TYPE_FILE,
ZPJ_SKYDRIVE_ENTRY_TYPE_FOLDER,
ZPJ_SKYDRIVE_ENTRY_TYPE_PHOTO,
+ ZPJ_SKYDRIVE_ENTRY_TYPE_VIDEO,
ZPJ_SKYDRIVE_ENTRY_TYPE_INVALID
} ZpjSkydriveEntryType;
diff --git a/src/zpj-skydrive-video.c b/src/zpj-skydrive-video.c
new file mode 100644
index 0000000..1225195
--- /dev/null
+++ b/src/zpj-skydrive-video.c
@@ -0,0 +1,265 @@
+/*
+ * Zapojit - GLib/GObject wrapper for the SkyDrive and Hotmail REST APIs
+ * Copyright © 2013 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+
+#include "config.h"
+
+#include "zpj-skydrive-video.h"
+
+
+/**
+ * SECTION:zpj-skydrive-video
+ * @title: ZpjSkydriveVideo
+ * @short_description: Skydrive video object.
+ * @include: zpj/zpj.h
+ *
+ * #ZpjSkydriveVideo represents a <ulink
+ * url="http://msdn.microsoft.com/en-us/library/live/hh243648#video">
+ * Skydrive video</ulink> object.
+ */
+
+
+struct _ZpjSkydriveVideoPrivate
+{
+ guint bitrate;
+ guint height;
+ guint width;
+ guint64 duration;
+};
+
+enum
+{
+ PROP_0,
+ PROP_BITRATE,
+ PROP_DURATION,
+ PROP_HEIGHT,
+ PROP_WIDTH
+};
+
+
+G_DEFINE_TYPE (ZpjSkydriveVideo, zpj_skydrive_video, ZPJ_TYPE_SKYDRIVE_FILE);
+
+
+static void
+zpj_skydrive_video_parse_json_node (ZpjSkydriveEntry *entry, JsonNode *node)
+{
+ ZpjSkydriveVideo *self = ZPJ_SKYDRIVE_VIDEO (entry);
+ ZpjSkydriveVideoPrivate *priv = self->priv;
+ JsonObject *object;
+ gint64 bitrate;
+ gint64 duration;
+ gint64 height;
+ gint64 width;
+
+ ZPJ_SKYDRIVE_ENTRY_CLASS (zpj_skydrive_video_parent_class)->parse_json_node (entry, node);
+
+ object = json_node_get_object (node);
+
+ bitrate = json_object_get_int_member (object, "bitrate");
+ priv->bitrate = (guint) bitrate;
+
+ duration = json_object_get_int_member (object, "duration");
+ priv->duration = (guint64) duration;
+
+ height = json_object_get_int_member (object, "height");
+ priv->height = (guint) height;
+
+ width = json_object_get_int_member (object, "width");
+ priv->width = (guint) width;
+}
+
+
+static void
+zpj_skydrive_video_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ ZpjSkydriveVideo *self = ZPJ_SKYDRIVE_VIDEO (object);
+ ZpjSkydriveVideoPrivate *priv = self->priv;
+
+ switch (prop_id)
+ {
+ case PROP_BITRATE:
+ g_value_set_uint (value, priv->bitrate);
+ break;
+
+ case PROP_DURATION:
+ g_value_set_uint64 (value, priv->duration);
+ break;
+
+ case PROP_HEIGHT:
+ g_value_set_uint (value, priv->height);
+ break;
+
+ case PROP_WIDTH:
+ g_value_set_uint (value, priv->width);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+static void
+zpj_skydrive_video_init (ZpjSkydriveVideo *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, ZPJ_TYPE_SKYDRIVE_VIDEO, ZpjSkydriveVideoPrivate);
+}
+
+
+static void
+zpj_skydrive_video_class_init (ZpjSkydriveVideoClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ ZpjSkydriveEntryClass *entry_class = ZPJ_SKYDRIVE_ENTRY_CLASS (class);
+
+ object_class->get_property = zpj_skydrive_video_get_property;
+ entry_class->parse_json_node = zpj_skydrive_video_parse_json_node;
+
+ g_object_class_install_property (object_class,
+ PROP_BITRATE,
+ g_param_spec_uint ("bitrate",
+ "Bit rate",
+ "Bit rate of the video in bits per second.",
+ 0,
+ G_MAXUINT,
+ 0,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_DURATION,
+ g_param_spec_uint64 ("duration",
+ "Duration",
+ "Run time duration of the video in milliseconds.",
+ 0,
+ G_MAXUINT64,
+ 0,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_HEIGHT,
+ g_param_spec_uint ("height",
+ "Height",
+ "Height of the video in pixels.",
+ 0,
+ G_MAXUINT,
+ 0,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_WIDTH,
+ g_param_spec_uint ("width",
+ "Width",
+ "Width of the video in pixels.",
+ 0,
+ G_MAXUINT,
+ 0,
+ G_PARAM_READABLE));
+
+ g_type_class_add_private (class, sizeof (ZpjSkydriveVideoPrivate));
+}
+
+
+/**
+ * zpj_skydrive_video_new:
+ * @node: A #JsonNode returned by the server.
+ *
+ * Creates a new #ZpjSkydriveVideo from the given @node. If you already
+ * know the ID of the video then you can use
+ * zpj_skydrive_query_info_from_id().
+ *
+ * Returns: (transfer full): A new #ZpjSkydriveVideo. Free the returned
+ * object with g_object_unref().
+ */
+ZpjSkydriveEntry *
+zpj_skydrive_video_new (JsonNode *node)
+{
+ return g_object_new (ZPJ_TYPE_SKYDRIVE_VIDEO, "json", node, NULL);
+}
+
+
+/**
+ * zpj_skydrive_video_get_bitrate:
+ * @self: A #ZpjSkydriveVideo.
+ *
+ * Gets the bit rate of @self in bits per second. This is the value of
+ * the <ulink
+ * url="http://msdn.microsoft.com/en-us/library/live/hh243648#video">
+ * bitrate</ulink> member in the JSON returned by the server.
+ *
+ * Returns: The video's bit rate in bits per second.
+ */
+guint
+zpj_skydrive_video_get_bitrate (ZpjSkydriveVideo *self)
+{
+ return self->priv->bitrate;
+}
+
+
+/**
+ * zpj_skydrive_video_get_duration:
+ * @self: A #ZpjSkydriveVideo.
+ *
+ * Gets the run time duration of @self in milliseconds. This is the
+ * value of the <ulink
+ * url="http://msdn.microsoft.com/en-us/library/live/hh243648#video">
+ * duration</ulink> member in the JSON returned by the server.
+ *
+ * Returns: The video's run time duration in milliseconds.
+ */
+guint64
+zpj_skydrive_video_get_duration (ZpjSkydriveVideo *self)
+{
+ return self->priv->duration;
+}
+
+
+/**
+ * zpj_skydrive_video_get_height:
+ * @self: A #ZpjSkydriveVideo.
+ *
+ * Gets the height of @self in pixels. This is the value of the <ulink
+ * url="http://msdn.microsoft.com/en-us/library/live/hh243648#video">
+ * height</ulink> member in the JSON returned by the server.
+ *
+ * Returns: The video's height in pixels.
+ */
+guint
+zpj_skydrive_video_get_height (ZpjSkydriveVideo *self)
+{
+ return self->priv->height;
+}
+
+
+/**
+ * zpj_skydrive_video_get_width:
+ * @self: A #ZpjSkydriveVideo.
+ *
+ * Gets the width of @self in pixels. This is the value of the <ulink
+ * url="http://msdn.microsoft.com/en-us/library/live/hh243648#video">
+ * width</ulink> member in the JSON returned by the server.
+ *
+ * Returns: The video's width in pixels.
+ */
+guint
+zpj_skydrive_video_get_width (ZpjSkydriveVideo *self)
+{
+ return self->priv->width;
+}
diff --git a/src/zpj-skydrive-video.h b/src/zpj-skydrive-video.h
new file mode 100644
index 0000000..0db107f
--- /dev/null
+++ b/src/zpj-skydrive-video.h
@@ -0,0 +1,93 @@
+/*
+ * Zapojit - GLib/GObject wrapper for the SkyDrive and Hotmail REST APIs
+ * Copyright © 2013 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef ZPJ_SKYDRIVE_VIDEO_H
+#define ZPJ_SKYDRIVE_VIDEO_H
+
+#include <json-glib/json-glib.h>
+
+#include "zpj-skydrive-file.h"
+
+G_BEGIN_DECLS
+
+#define ZPJ_TYPE_SKYDRIVE_VIDEO (zpj_skydrive_video_get_type ())
+
+#define ZPJ_SKYDRIVE_VIDEO(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ ZPJ_TYPE_SKYDRIVE_VIDEO, ZpjSkydriveVideo))
+
+#define ZPJ_SKYDRIVE_VIDEO_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ ZPJ_TYPE_SKYDRIVE_VIDEO, ZpjSkydriveVideoClass))
+
+#define ZPJ_IS_SKYDRIVE_VIDEO(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ ZPJ_TYPE_SKYDRIVE_VIDEO))
+
+#define ZPJ_IS_SKYDRIVE_VIDEO_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ ZPJ_TYPE_SKYDRIVE_VIDEO))
+
+#define ZPJ_SKYDRIVE_VIDEO_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ ZPJ_TYPE_SKYDRIVE_VIDEO, ZpjSkydriveVideoClass))
+
+typedef struct _ZpjSkydriveVideo ZpjSkydriveVideo;
+typedef struct _ZpjSkydriveVideoClass ZpjSkydriveVideoClass;
+typedef struct _ZpjSkydriveVideoPrivate ZpjSkydriveVideoPrivate;
+
+/**
+ * ZpjSkydriveVideo:
+ *
+ * The #ZpjSkydriveVideo structure contains only private data and
+ * should only be accessed using the provided API.
+ */
+struct _ZpjSkydriveVideo
+{
+ ZpjSkydriveFile parent_instance;
+ ZpjSkydriveVideoPrivate *priv;
+};
+
+/**
+ * ZpjSkydriveVideoClass:
+ * @parent_class: The parent class.
+ *
+ * Class structure for #ZpjSkydriveVideo.
+ */
+struct _ZpjSkydriveVideoClass
+{
+ ZpjSkydriveFileClass parent_class;
+};
+
+GType zpj_skydrive_video_get_type (void) G_GNUC_CONST;
+
+ZpjSkydriveEntry *zpj_skydrive_video_new (JsonNode *node);
+
+guint zpj_skydrive_video_get_bitrate (ZpjSkydriveVideo *self);
+
+guint64 zpj_skydrive_video_get_duration (ZpjSkydriveVideo *self);
+
+guint zpj_skydrive_video_get_height (ZpjSkydriveVideo *self);
+
+guint zpj_skydrive_video_get_width (ZpjSkydriveVideo *self);
+
+G_END_DECLS
+
+#endif /* ZPJ_SKYDRIVE_VIDEO_H */
diff --git a/src/zpj-skydrive.c b/src/zpj-skydrive.c
index 7bec772..88f3c88 100644
--- a/src/zpj-skydrive.c
+++ b/src/zpj-skydrive.c
@@ -33,6 +33,7 @@
#include "zpj-skydrive.h"
#include "zpj-skydrive-file.h"
#include "zpj-skydrive-photo.h"
+#include "zpj-skydrive-video.h"
/**
@@ -107,6 +108,8 @@ zpj_skydrive_create_entry_from_json_node (JsonNode *node,
entry = zpj_skydrive_folder_new (node);
else if (g_strcmp0 (type, "photo") == 0)
entry = zpj_skydrive_photo_new (node);
+ else if (g_strcmp0 (type, "video") == 0)
+ entry = zpj_skydrive_video_new (node);
else
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
"Unknown entry type: %s", type);
diff --git a/src/zpj.h b/src/zpj.h
index 9cf8acb..05ba7cd 100644
--- a/src/zpj.h
+++ b/src/zpj.h
@@ -1,6 +1,6 @@
/*
* Zapojit - GLib/GObject wrapper for the SkyDrive and Hotmail REST APIs
- * Copyright © 2012 Red Hat, Inc.
+ * Copyright © 2012, 2013 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -30,5 +30,6 @@
#include <zpj/zpj-skydrive-file.h>
#include <zpj/zpj-skydrive-folder.h>
#include <zpj/zpj-skydrive-photo.h>
+#include <zpj/zpj-skydrive-video.h>
#endif /* ZPJ_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]