summaryrefslogtreecommitdiff
path: root/gfbgraph/gfbgraph-album.c
blob: b3b5d8c6ef1843f0c20f182885f1c3166e81d9aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*-  */
/*
 * libgfbgraph - GObject library for Facebook Graph API
 * Copyright (C) 2013 Álvaro Peña <alvaropg@gmail.com>
 *
 * This library is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * libgfbgraph 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * SECTION:gfbgraph-album
 * @short_description: GFBGraph Photo album node object
 * @stability: Unstable
 * @include: gfbgraph/gfbgraph.h
 *
 * #GFGraphAlbum represents the <ulink url="https://developers.facebook.com/docs/reference/api/album/">
 * photo album node in the Graph API</ulink>.
 *
 * This node is connectable to:
 *  - #GFBGraphUser
 **/

#include "gfbgraph-album.h"
#include "gfbgraph-user.h"
#include "gfbgraph-connectable.h"

enum {
        PROP_O,

        PROP_NAME,
        PROP_DESCRIPTION,
        PROP_COVER_PHOTO,
        PROP_COUNT
};

struct _GFBGraphAlbumPrivate {
        gchar *name;
        gchar *description;
        gchar *cover_photo;
        guint  count;
};

static void gfbgraph_album_init         (GFBGraphAlbum *obj);
static void gfbgraph_album_class_init   (GFBGraphAlbumClass *klass);
static void gfbgraph_album_finalize     (GObject *obj);
static void gfbgraph_album_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
static void gfbgraph_album_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);

static void gfbgraph_album_connectable_iface_init (GFBGraphConnectableInterface *iface);
GHashTable* gfbgraph_album_get_connection_post_params (GFBGraphConnectable *self, GType node_type);

#define GFBGRAPH_ALBUM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), GFBGRAPH_TYPE_ALBUM, GFBGraphAlbumPrivate))

static GFBGraphNodeClass *parent_class = NULL;

G_DEFINE_TYPE_WITH_CODE (GFBGraphAlbum, gfbgraph_album, GFBGRAPH_TYPE_NODE,
                         G_IMPLEMENT_INTERFACE (GFBGRAPH_TYPE_CONNECTABLE, gfbgraph_album_connectable_iface_init));

static void
gfbgraph_album_init (GFBGraphAlbum *obj)
{
	obj->priv = GFBGRAPH_ALBUM_GET_PRIVATE(obj);
}

static void
gfbgraph_album_class_init (GFBGraphAlbumClass *klass)
{
	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

	parent_class            = g_type_class_peek_parent (klass);

	gobject_class->finalize = gfbgraph_album_finalize;
        gobject_class->set_property = gfbgraph_album_set_property;
        gobject_class->get_property = gfbgraph_album_get_property;

	g_type_class_add_private (gobject_class, sizeof(GFBGraphAlbumPrivate));

        /**
         * GFBGraphAlbum:name:
         *
         * The album name.
         **/
        g_object_class_install_property (gobject_class,
                                         PROP_NAME,
                                         g_param_spec_string ("name",
                                                              "The title", "The name of the album",
                                                              "",
                                                              G_PARAM_READABLE | G_PARAM_WRITABLE));

        /**
         * GFBGraphAlbum:description:
         *
         * The album description given by the owner.
         **/
        g_object_class_install_property (gobject_class,
                                         PROP_DESCRIPTION,
                                         g_param_spec_string ("description",
                                                              "The description", "The description of the album",
                                                              "",
                                                              G_PARAM_READABLE | G_PARAM_WRITABLE));

        /**
         * GFBGraphAlbum:cover_photo:
         *
         * The node ID for the album cover photo. It's an ID for a #GFBGraphPhoto node.
         **/
        g_object_class_install_property (gobject_class,
                                         PROP_COVER_PHOTO,
                                         g_param_spec_string ("cover_photo",
                                                              "Cover photo", "The ID for the cover photo of the album",
                                                              "",
                                                              G_PARAM_READABLE | G_PARAM_WRITABLE));

        /**
         * GFBGraphAlbum:count:
         *
         * The number of photos in the album.
         **/
        g_object_class_install_property (gobject_class,
                                         PROP_COUNT,
                                         g_param_spec_uint ("count",
                                                           "Number of photos", "The number of photos in the album",
                                                           0, G_MAXUINT, 0,
                                                           G_PARAM_READABLE | G_PARAM_WRITABLE));

}

static void
gfbgraph_album_finalize (GObject *obj)
{
	G_OBJECT_CLASS(parent_class)->finalize (obj);
}

static void
gfbgraph_album_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
        GFBGraphAlbumPrivate *priv;

        priv = GFBGRAPH_ALBUM_GET_PRIVATE (object);

        switch (prop_id) {
                case PROP_NAME:
                        if (priv->name)
                                g_free (priv->name);
                        priv->name = g_strdup (g_value_get_string (value));
                        break;
                case PROP_DESCRIPTION:
                        if (priv->description)
                                g_free (priv->description);
                        priv->description = g_strdup (g_value_get_string (value));
                        break;
                case PROP_COVER_PHOTO:
                        if (priv->cover_photo)
                                g_free (priv->cover_photo);
                        priv->cover_photo = g_strdup (g_value_get_string (value));
                        break;
                case PROP_COUNT:
                        priv->count = g_value_get_uint (value);
                        break;
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
        }
}

static void
gfbgraph_album_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
        GFBGraphAlbumPrivate *priv;

        priv = GFBGRAPH_ALBUM_GET_PRIVATE (object);

        switch (prop_id) {
                case PROP_NAME:
                        g_value_set_string (value, priv->name);
                        break;
                case PROP_DESCRIPTION:
                        g_value_set_string (value, priv->description);
                        break;
                case PROP_COVER_PHOTO:
                        g_value_set_string (value, priv->cover_photo);
                        break;
                case PROP_COUNT:
                        g_value_set_uint (value, priv->count);
                        break;
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
        }
}

static void
gfbgraph_album_connectable_iface_init (GFBGraphConnectableInterface *iface)
{
        GHashTable *connections;

        connections = g_hash_table_new (g_str_hash, g_str_equal);
        g_hash_table_insert (connections, (gpointer) g_type_name (GFBGRAPH_TYPE_USER), (gpointer) "albums");

        iface->connections = connections;
        iface->get_connection_post_params = gfbgraph_album_get_connection_post_params;
        iface->parse_connected_data = gfbgraph_connectable_default_parse_connected_data;
}

GHashTable*
gfbgraph_album_get_connection_post_params (GFBGraphConnectable *self, GType node_type)
{
        GHashTable *params;
        GFBGraphAlbumPrivate *priv;

        priv = GFBGRAPH_ALBUM_GET_PRIVATE (self);

        params = g_hash_table_new (g_str_hash, g_str_equal);
        g_hash_table_insert (params, "name", priv->name);
        if (priv->description != NULL)
                g_hash_table_insert (params, "message", priv->description);
        /* TODO: Incorpate the "privacy" param */

        return params;
}

/**
 * gfbgraph_album_new:
 *
 * Creates a new #GFBGraphAlbum.
 *
 * Returns: (transfer full): a new #GFBGraphAlbum; unref with g_object_unref() 
 **/
GFBGraphAlbum*
gfbgraph_album_new (void)
{
	return GFBGRAPH_ALBUM (g_object_new(GFBGRAPH_TYPE_ALBUM, NULL));
}

/**
 * gfbgraph_album_new_from_id:
 * @authorizer: a #GFBGraphAuthorizer.
 * @id: a const #gchar with the album ID.
 * @error: (allow-none): a #GError or %NULL.
 *
 * Retrieves an album node from the Facebook Graph with the give ID.
 *
 * Returns: (transfer full): a new #GFBGraphAlbum; unref with g_object_unref()
 **/
GFBGraphAlbum*
gfbgraph_album_new_from_id (GFBGraphAuthorizer *authorizer, const gchar *id, GError **error)
{
        return GFBGRAPH_ALBUM (gfbgraph_node_new_from_id (authorizer, id, GFBGRAPH_TYPE_ALBUM, error));
}