b94b71aa063e6a0aefa66791a2ddb4b40feb7255
[maevies] / src / mvs-tmdb-movie.c
1 /*
2  * mvs-tmdb-movie.c
3  *
4  * This file is part of maevies
5  * Copyright (C) 2010 Simón Pena <spenap@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  */
18
19 #include "mvs-tmdb-movie.h"
20
21 G_DEFINE_TYPE (MvsTmdbMovie, mvs_tmdb_movie, G_TYPE_OBJECT)
22
23 enum {
24         PROP_0,
25         PROP_SCORE,
26         PROP_POPULARITY,
27         PROP_TRANSLATED,
28         PROP_LANGUAGE,
29         PROP_NAME,
30         PROP_ALT_NAME,
31         PROP_TYPE,
32         PROP_ID,
33         PROP_IMDB_ID,
34         PROP_URL,
35         PROP_RATING,
36         PROP_CERTIFICATION,
37         PROP_OVERVIEW,
38         PROP_RELEASED,
39         PROP_IMAGES,
40         PROP_LAST_MODIFIED,
41 };
42
43
44
45 #define GET_PRIVATE(o) \
46   (G_TYPE_INSTANCE_GET_PRIVATE ((o), MVS_TYPE_TMDB_MOVIE, MvsTmdbMoviePrivate))
47
48 struct _MvsTmdbMoviePrivate {
49         gchar *score;
50         gchar *popularity;
51         gchar *translated;
52         gchar *language;
53         gchar *name;
54         gchar *alt_name;
55         gchar *type;
56         gchar *id;
57         gchar *imdb_id;
58         gchar *url;
59         gchar *rating;
60         gchar *certification;
61         gchar *overview;
62         gchar *released;
63         gchar *images;
64         gchar *last_modified;
65 };
66
67 static void
68 mvs_tmdb_movie_get_property (GObject *object, guint property_id,
69                          GValue *value, GParamSpec *pspec)
70 {
71         MvsTmdbMovie *self = MVS_TMDB_MOVIE (object);
72
73         switch (property_id) {
74         case PROP_ALT_NAME:
75                 g_value_set_string (value, self->priv->alt_name);
76                 break;
77         case PROP_CERTIFICATION:
78                 g_value_set_string (value, self->priv->certification);
79                 break;
80         case PROP_ID:
81                 g_value_set_string (value, self->priv->id);
82                 break;
83         case PROP_IMAGES:
84                 g_value_set_string (value, self->priv->images);
85                 break;
86         case PROP_IMDB_ID:
87                 g_value_set_string (value, self->priv->imdb_id);
88                 break;
89         case PROP_LANGUAGE:
90                 g_value_set_string (value, self->priv->language);
91                 break;
92         case PROP_LAST_MODIFIED:
93                 g_value_set_string (value, self->priv->last_modified);
94                 break;
95         case PROP_NAME:
96                 g_value_set_string (value, self->priv->name);
97                 break;
98         case PROP_OVERVIEW:
99                 g_value_set_string (value, self->priv->overview);
100                 break;
101         case PROP_POPULARITY:
102                 g_value_set_string (value, self->priv->popularity);
103                 break;
104         case PROP_RATING:
105                 g_value_set_string (value, self->priv->rating);
106                 break;
107         case PROP_RELEASED:
108                 g_value_set_string (value, self->priv->released);
109                 break;
110         case PROP_SCORE:
111                 g_value_set_string (value, self->priv->score);
112                 break;
113         case PROP_TRANSLATED:
114                 g_value_set_string (value, self->priv->id);
115                 break;
116         case PROP_TYPE:
117                 g_value_set_string (value, self->priv->id);
118                 break;
119         case PROP_URL:
120                 g_value_set_string (value, self->priv->url);
121                 break;
122         default:
123                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
124         }
125 }
126
127 static void
128 mvs_tmdb_movie_set_property (GObject *object, guint property_id,
129                          const GValue *value, GParamSpec *pspec)
130 {
131         MvsTmdbMovie *self = MVS_TMDB_MOVIE (object);
132         GDate *date = NULL;
133
134         switch (property_id) {
135         case PROP_ALT_NAME:
136                 mvs_tmdb_movie_set_alt_name (self, g_value_get_string (value));
137                 break;
138         case PROP_CERTIFICATION:
139                 mvs_tmdb_movie_set_certification (self,
140                                 g_value_get_string (value));
141                 break;
142         case PROP_ID:
143                 mvs_tmdb_movie_set_id (self,
144                                 g_value_get_string (value));
145                 break;
146         case PROP_IMAGES:
147                 mvs_tmdb_movie_set_images (self,
148                                 g_value_get_string (value));
149                 break;
150         case PROP_IMDB_ID:
151                 mvs_tmdb_movie_set_imdb_id (self,
152                                 g_value_get_string (value));
153                 break;
154         case PROP_LANGUAGE:
155                 mvs_tmdb_movie_set_language (self,
156                                 g_value_get_string (value));
157                 break;
158         case PROP_LAST_MODIFIED:
159                 mvs_tmdb_movie_set_last_modified (self,
160                                 g_value_get_string (value));
161                 break;
162         case PROP_NAME:
163                 mvs_tmdb_movie_set_name (self,
164                                 g_value_get_string (value));
165                 break;
166         case PROP_OVERVIEW:
167                 mvs_tmdb_movie_set_overview (self,
168                                 g_value_get_string (value));
169                 break;
170         case PROP_POPULARITY:
171                 mvs_tmdb_movie_set_popularity (self,
172                                 g_value_get_string (value));
173                 break;
174         case PROP_RATING:
175                 mvs_tmdb_movie_set_rating (self,
176                                 g_value_get_string (value));
177                 break;
178         case PROP_RELEASED:
179                 mvs_tmdb_movie_set_released (self,
180                                 g_value_get_string (value));
181                 break;
182         case PROP_SCORE:
183                 mvs_tmdb_movie_set_score (self,
184                                 g_value_get_string (value));
185                 break;
186         case PROP_TRANSLATED:
187                 mvs_tmdb_movie_set_translated (self,
188                                 g_value_get_string (value));
189                 break;
190         case PROP_TYPE:
191                 mvs_tmdb_movie_set_type (self,
192                                 g_value_get_string (value));
193                 break;
194         case PROP_URL:
195                 mvs_tmdb_movie_set_url (self,
196                                 g_value_get_string (value));
197                 break;
198         default:
199                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
200         }
201 }
202
203 static void
204 mvs_tmdb_movie_finalize (GObject *object)
205 {
206         MvsTmdbMovie *self = MVS_TMDB_MOVIE (object);
207
208         g_free (self->priv->alt_name);
209         g_free (self->priv->certification);
210         g_free (self->priv->id);
211         g_free (self->priv->images);
212         g_free (self->priv->imdb_id);
213         g_free (self->priv->language);
214         g_free (self->priv->last_modified);
215         g_free (self->priv->name);
216         g_free (self->priv->overview);
217         g_free (self->priv->popularity);
218         g_free (self->priv->rating);
219         g_free (self->priv->released);
220         g_free (self->priv->score);
221         g_free (self->priv->translated);
222         g_free (self->priv->type);
223         g_free (self->priv->url);
224
225         G_OBJECT_CLASS (mvs_tmdb_movie_parent_class)->finalize (object);
226 }
227
228 static void
229 mvs_tmdb_movie_class_init (MvsTmdbMovieClass *klass)
230 {
231         GObjectClass *object_class = G_OBJECT_CLASS (klass);
232
233         g_type_class_add_private (klass, sizeof (MvsTmdbMoviePrivate));
234
235         object_class->get_property = mvs_tmdb_movie_get_property;
236         object_class->set_property = mvs_tmdb_movie_set_property;
237         object_class->finalize = mvs_tmdb_movie_finalize;
238
239         g_object_class_install_property
240                 (object_class, PROP_ALT_NAME,
241                  g_param_spec_string ("alternative_name", "Alternative name",
242                                  "The movie alternative name",
243                                  NULL,
244                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
245
246         g_object_class_install_property
247                 (object_class, PROP_CERTIFICATION,
248                  g_param_spec_string ("certification", "Movie certification",
249                                  "The movie certification",
250                                  NULL,
251                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
252
253         g_object_class_install_property
254                 (object_class, PROP_ID,
255                  g_param_spec_string ("id", "Movie ID", "The movie ID",
256                                  NULL,
257                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
258
259         g_object_class_install_property
260                 (object_class, PROP_IMAGES,
261                  g_param_spec_string ("images", "Movie images",
262                                  "The movie images",
263                                  NULL,
264                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
265
266         g_object_class_install_property
267                 (object_class, PROP_IMDB_ID,
268                  g_param_spec_string ("imdb_id", "Movie IMDB ID",
269                                  "The movie IMDB ID",
270                                  NULL,
271                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
272
273         g_object_class_install_property
274                 (object_class, PROP_LANGUAGE,
275                  g_param_spec_string ("language", "Movie language",
276                                  "The movie language",
277                                  NULL,
278                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
279
280         g_object_class_install_property
281                 (object_class, PROP_LAST_MODIFIED,
282                  g_param_spec_string ("last_modified_at",
283                                  "Movie last modified date",
284                                  "The movie last modification date",
285                                  NULL,
286                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
287
288         g_object_class_install_property
289                 (object_class, PROP_NAME,
290                  g_param_spec_string ("name", "Movie name", "The movie name",
291                                  NULL,
292                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
293
294         g_object_class_install_property
295                 (object_class, PROP_OVERVIEW,
296                  g_param_spec_string ("overview", "Movie overview", "The movie overview",
297                                  NULL,
298                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
299
300         g_object_class_install_property
301                 (object_class, PROP_POPULARITY,
302                  g_param_spec_string ("popularity", "Movie popularity", "The movie popularity",
303                                  NULL,
304                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
305
306         g_object_class_install_property
307                 (object_class, PROP_RATING,
308                  g_param_spec_string ("rating", "Movie rating", "The movie rating",
309                                  NULL,
310                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
311
312         g_object_class_install_property
313                 (object_class, PROP_RELEASED,
314                  g_param_spec_string ("released", "Movie released date", "The movie released date",
315                                  NULL,
316                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
317
318         g_object_class_install_property
319                 (object_class, PROP_SCORE,
320                  g_param_spec_string ("score", "Movie score", "The movie score",
321                                  NULL,
322                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
323
324         g_object_class_install_property
325                 (object_class, PROP_TRANSLATED,
326                  g_param_spec_string ("translated", "Movie translated status", "Tells if the movie is translated",
327                                  NULL,
328                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
329
330         g_object_class_install_property
331                         (object_class, PROP_TYPE,
332                          g_param_spec_string ("type", "Movie type", "The movie type",
333                                  NULL,
334                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
335
336         g_object_class_install_property
337                         (object_class, PROP_URL,
338                          g_param_spec_string ("url", "Movie url", "The movie url",
339                                  NULL,
340                                  G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
341 }
342
343 static void
344 mvs_tmdb_movie_init (MvsTmdbMovie *self)
345 {
346         self->priv = GET_PRIVATE (self);
347
348         self->priv->alt_name = NULL;
349         self->priv->certification = NULL;
350         self->priv->id = NULL;
351         self->priv->images = NULL;
352         self->priv->imdb_id = NULL;
353         self->priv->language = NULL;
354         self->priv->last_modified = NULL;
355         self->priv->name = NULL;
356         self->priv->overview = NULL;
357         self->priv->popularity = NULL;
358         self->priv->rating = NULL;
359         self->priv->released = NULL;
360         self->priv->score = NULL;
361         self->priv->translated = NULL;
362         self->priv->type = NULL;
363         self->priv->url = NULL;
364 }
365
366 MvsTmdbMovie*
367 mvs_tmdb_movie_new (void)
368 {
369         return g_object_new (MVS_TYPE_TMDB_MOVIE, NULL);
370 }
371
372 gboolean
373 set_property (gchar **property, const gchar *value)
374 {
375         g_free (*property);
376
377         *property = g_strdup (value);
378
379         return TRUE;
380 }
381
382 gboolean
383 mvs_tmdb_movie_set_alt_name (MvsTmdbMovie *self, const gchar *alt_name)
384 {
385         g_return_val_if_fail (MVS_TMDB_MOVIE (self), FALSE);
386         return set_property (&self->priv->alt_name, alt_name);
387 }
388
389 gboolean
390 mvs_tmdb_movie_set_certification (MvsTmdbMovie *self,
391                                   const gchar *certification)
392 {
393         g_return_val_if_fail (MVS_TMDB_MOVIE (self), FALSE);
394         return set_property (&self->priv->certification, certification);
395 }
396
397 gboolean
398 mvs_tmdb_movie_set_id (MvsTmdbMovie *self, const gchar *id)
399 {
400         g_return_val_if_fail (MVS_TMDB_MOVIE (self), FALSE);
401         return set_property (&self->priv->id, id);
402 }
403
404 gboolean
405 mvs_tmdb_movie_set_images (MvsTmdbMovie *self, const gchar *images)
406 {
407         g_return_val_if_fail (MVS_TMDB_MOVIE (self), FALSE);
408         return set_property (&self->priv->images, images);
409 }
410
411 gboolean
412 mvs_tmdb_movie_set_imdb_id (MvsTmdbMovie *self, const gchar *imdb_id)
413 {
414         g_return_val_if_fail (MVS_TMDB_MOVIE (self), FALSE);
415         return set_property (&self->priv->imdb_id, imdb_id);
416 }
417
418 gboolean
419 mvs_tmdb_movie_set_language (MvsTmdbMovie *self, const gchar *language)
420 {
421         g_return_val_if_fail (MVS_TMDB_MOVIE (self), FALSE);
422         return set_property (&self->priv->language, language);
423 }
424
425 gboolean
426 mvs_tmdb_movie_set_last_modified (MvsTmdbMovie *self,
427                                   const gchar *last_modified)
428 {
429         g_return_val_if_fail (MVS_TMDB_MOVIE (self), FALSE);
430         return set_property (&self->priv->last_modified, last_modified);
431 }
432
433 gboolean
434 mvs_tmdb_movie_set_name (MvsTmdbMovie *self, const gchar *name)
435 {
436         g_return_val_if_fail (MVS_TMDB_MOVIE (self), FALSE);
437         return set_property (&self->priv->name, name);
438 }
439
440 gboolean
441 mvs_tmdb_movie_set_overview (MvsTmdbMovie *self, const gchar *overview)
442 {
443         g_return_val_if_fail (MVS_TMDB_MOVIE (self), FALSE);
444         return set_property (&self->priv->overview, overview);
445 }
446
447 gboolean
448 mvs_tmdb_movie_set_popularity (MvsTmdbMovie *self, const gchar *popularity)
449 {
450         g_return_val_if_fail (MVS_TMDB_MOVIE (self), FALSE);
451         return set_property (&self->priv->popularity, popularity);
452 }
453
454 gboolean
455 mvs_tmdb_movie_set_rating (MvsTmdbMovie *self, const gchar *rating)
456 {
457         g_return_val_if_fail (MVS_TMDB_MOVIE (self), FALSE);
458         return set_property (&self->priv->rating, rating);
459 }
460
461 gboolean
462 mvs_tmdb_movie_set_released (MvsTmdbMovie *self, const gchar *released)
463 {
464         g_return_val_if_fail (MVS_TMDB_MOVIE (self), FALSE);
465         return set_property (&self->priv->released, released);
466 }
467
468 gboolean
469 mvs_tmdb_movie_set_score (MvsTmdbMovie *self, const gchar *score)
470 {
471         g_return_val_if_fail (MVS_TMDB_MOVIE (self), FALSE);
472         return set_property (&self->priv->score, score);
473 }
474
475 gboolean
476 mvs_tmdb_movie_set_translated (MvsTmdbMovie *self, const gchar *translated)
477 {
478         g_return_val_if_fail (MVS_TMDB_MOVIE (self), FALSE);
479         return set_property (&self->priv->translated, translated);
480 }
481
482 gboolean
483 mvs_tmdb_movie_set_type (MvsTmdbMovie *self, const gchar *type)
484 {
485         g_return_val_if_fail (MVS_TMDB_MOVIE (self), FALSE);
486         return set_property (&self->priv->type, type);
487 }
488
489 gboolean
490 mvs_tmdb_movie_set_url (MvsTmdbMovie *self, const gchar *url)
491 {
492         g_return_val_if_fail (MVS_TMDB_MOVIE (self), FALSE);
493         return set_property (&self->priv->url, url);
494 }