From d267b9e11095f3438824eb80ff78a6c51eaeb72b Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 8 Mar 2016 17:02:29 +0100 Subject: [PATCH] Add the Matrix.ImageInfo type --- .gitignore | 2 +- src/Makefile.am | 2 +- src/{matrix-enums.vala => matrix-types.vala} | 31 ++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) rename src/{matrix-enums.vala => matrix-types.vala} (93%) diff --git a/.gitignore b/.gitignore index 4e8fad4..c969237 100644 --- a/.gitignore +++ b/.gitignore @@ -48,7 +48,7 @@ Makefile.in /src/matrix-glib.h /src/matrix-api.c /src/matrix-client.c -/src/matrix-enums.c +/src/matrix-types.c /src/matrix-http-api.c /src/matrix-http-client.c /src/matrix-compacts.c diff --git a/src/Makefile.am b/src/Makefile.am index 9de2b4d..4e4e908 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -19,7 +19,7 @@ libmatrix_glib_0_0_la_VALA_SOURCES = \ namespace-info.vala \ matrix-api.vala \ matrix-client.vala \ - matrix-enums.vala \ + matrix-types.vala \ matrix-http-api.vala \ matrix-http-client.vala \ matrix-compacts.vala \ diff --git a/src/matrix-enums.vala b/src/matrix-types.vala similarity index 93% rename from src/matrix-enums.vala rename to src/matrix-types.vala index c31c747..267462c 100644 --- a/src/matrix-enums.vala +++ b/src/matrix-types.vala @@ -270,6 +270,37 @@ namespace Matrix { WORLD_READABLE; } + public struct ImageInfo { + int? size; + int? height; + int? width; + string? mimetype; + + public Json.Node + get_json_node() + throws Matrix.Error + { + if ((size == null) + || (height == null) + || (width == null) + || (mimetype == null)) { + throw new Matrix.Error.INCOMPLETE( + "Won't generate an ImageInfo without all fields set."); + } + + var node = new Json.Node(Json.NodeType.OBJECT); + var obj = new Json.Object(); + node.set_object(obj); + + obj.set_int_member("size", size); + obj.set_int_member("h", height); + obj.set_int_member("w", width); + obj.set_string_member("mimetype", mimetype); + + return node; + } + } + private int? _g_enum_nick_to_value(Type enum_type, string nick) {