2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License as
4 * published by the Free Software Foundation; either version 2 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * General Public License for more details.
12 * You should have received a copy of the GNU General Public
13 * License along with this program; if not, write to the
14 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
15 * Boston, MA 02110-1301 USA
17 * Authors: Travis Reitter <treitter@gmail.com>
23 #include <glib/gi18n.h>
25 #include <hildon/hildon.h>
27 #include <rtm-glib/rtm-glib.h>
29 #include "milk-auth.h"
31 G_DEFINE_TYPE (MilkAuth, milk_auth, G_TYPE_OBJECT);
33 /* less expensive than G_TYPE_INSTANCE_GET_PRIVATE */
34 #define MILK_AUTH_PRIVATE(o) ((MILK_AUTH ((o)))->priv)
36 #define RTM_API_KEY "81f5c6c904aeafbbc914d9845d250ea8"
37 #define RTM_SHARED_SECRET "b08b15419378f913"
39 struct _MilkAuthPrivate
51 static MilkAuth *default_auth = NULL;
55 milk_auth_get_property (GObject *object,
60 MilkAuthPrivate *priv = MILK_AUTH_PRIVATE (object);
65 g_value_set_string (value, priv->api_key);
68 case PROP_SHARED_SECRET:
69 g_value_set_string (value, priv->shared_secret);
73 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id,
79 milk_auth_set_property (GObject *object,
84 MilkAuthPrivate *priv;
87 auth = MILK_AUTH (object);
88 priv = MILK_AUTH_PRIVATE (auth);
93 priv->api_key = g_value_dup_string (value);
96 case PROP_SHARED_SECRET:
97 priv->shared_secret = g_value_dup_string (value);
101 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id,
107 milk_auth_constructed (GObject *object)
109 MilkAuthPrivate *priv = MILK_AUTH_PRIVATE (object);
111 priv->rtm_glib = rtm_glib_new (priv->api_key, priv->shared_secret);
115 milk_auth_finalize (GObject *object)
117 MilkAuthPrivate *priv = MILK_AUTH_PRIVATE (object);
119 g_object_unref (priv->rtm_glib);
121 g_free (priv->api_key);
122 g_free (priv->shared_secret);
126 milk_auth_class_init (MilkAuthClass *klass)
128 GObjectClass *object_class = G_OBJECT_CLASS (klass);
130 g_type_class_add_private (klass, sizeof (MilkAuthPrivate));
132 object_class->get_property = milk_auth_get_property;
133 object_class->set_property = milk_auth_set_property;
134 object_class->constructed = milk_auth_constructed;
135 object_class->finalize = milk_auth_finalize;
137 /* FIXME: make these read-only */
138 g_object_class_install_property
143 "API authentication key",
144 "Milk's API authentication key.",
146 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
147 G_PARAM_STATIC_STRINGS));
149 g_object_class_install_property
155 "Milk's shared secret with the server.",
157 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
158 G_PARAM_STATIC_STRINGS));
162 milk_auth_init (MilkAuth *self)
164 MilkAuthPrivate *priv;
166 self->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (
167 self, MILK_TYPE_AUTH, MilkAuthPrivate);
171 milk_auth_get_default ()
174 default_auth = g_object_new (MILK_TYPE_AUTH, NULL);