Movie Info Provider: Added format property
[maevies] / src / mvs-minfo-provider.c
1 /*
2  * mvs-minfo-provider.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-minfo-provider.h"
20
21 #define TMDB_API_KEY "249e1a42df9bee09fac5e92d3a51396b"
22 #define TMDB_LANGUAGE "en"
23 #define TMDB_FORMAT "xml"
24 #define TMDB_METHOD "Movie.search"
25 #define TMDB_BASE_URL "http://api.themoviedb.org/2.1/%s/%s/%s/%s/%s"
26
27 G_DEFINE_TYPE (MvsMInfoProvider, mvs_minfo_provider, G_TYPE_OBJECT)
28
29 enum {
30         PROP_0,
31         PROP_FORMAT,
32 };
33
34 #define GET_PRIVATE(o) \
35   (G_TYPE_INSTANCE_GET_PRIVATE ((o), MVS_TYPE_MINFO_PROVIDER, MvsMInfoProviderPrivate))
36
37 struct _MvsMInfoProviderPrivate {
38         gchar *format;
39 };
40
41 static void
42 mvs_minfo_provider_get_property (GObject *object, guint property_id,
43                          GValue *value, GParamSpec *pspec)
44 {
45         MvsMInfoProvider *self = MVS_MINFO_PROVIDER (object);
46
47         switch (property_id) {
48         case PROP_FORMAT:
49                 g_value_set_string (value, self->priv->format);
50                 break;
51         default:
52                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
53         }
54 }
55
56 static void
57 mvs_minfo_provider_set_property (GObject *object, guint property_id,
58                          const GValue *value, GParamSpec *pspec)
59 {
60         MvsMInfoProvider *self = MVS_MINFO_PROVIDER (object);
61
62         switch (property_id) {
63         case PROP_FORMAT:
64                 mvs_minfo_provider_set_format (self,
65                                 g_value_get_string (value));
66                 break;
67         default:
68                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
69         }
70 }
71
72 static void
73 mvs_minfo_provider_finalize (GObject *object)
74 {
75         MvsMInfoProvider *self = MVS_MINFO_PROVIDER (object);
76
77         g_free (self->priv->format);
78
79         G_OBJECT_CLASS (mvs_minfo_provider_parent_class)->finalize (object);
80 }
81
82 static void
83 mvs_minfo_provider_class_init (MvsMInfoProviderClass *klass)
84 {
85         GObjectClass *object_class = G_OBJECT_CLASS (klass);
86
87         g_type_class_add_private (klass, sizeof (MvsMInfoProviderPrivate));
88
89         object_class->get_property = mvs_minfo_provider_get_property;
90         object_class->set_property = mvs_minfo_provider_set_property;
91         object_class->finalize = mvs_minfo_provider_finalize;
92
93         g_object_class_install_property
94                 (object_class, PROP_FORMAT,
95                  g_param_spec_string ("format", "The format", "The format",
96                                       TMDB_FORMAT,
97                                       G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
98
99 }
100
101 static void
102 mvs_minfo_provider_init (MvsMInfoProvider *self)
103 {
104         self->priv = GET_PRIVATE (self);
105         self->priv->format = NULL;
106 }
107
108 MvsMInfoProvider*
109 mvs_minfo_provider_new (void)
110 {
111         return g_object_new (MVS_TYPE_MINFO_PROVIDER, NULL);
112 }
113
114 gboolean
115 mvs_minfo_provider_query (MvsMInfoProvider *self,
116                           const gchar *query)
117 {
118         return FALSE;
119 }
120
121 gboolean
122 mvs_minfo_provider_set_format (MvsMInfoProvider *self,
123                                const gchar *format)
124 {
125         g_return_val_if_fail (MVS_IS_MINFO_PROVIDER (self), FALSE);
126
127         g_free (self->priv->format);
128
129         self->priv->format = g_strdup (format);
130
131         return TRUE;
132 }