Add initial version of MilkAuth, to manage the authentication with the server.
[milk] / src / milk-task.c
1 /*
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.
6  *
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.
11  *
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
16  *
17  * Authors: Travis Reitter <treitter@gmail.com>
18  */
19
20 #include <config.h>
21
22 #include <glib.h>
23 #include <glib/gi18n.h>
24 #include <gtk/gtk.h>
25 #include <hildon/hildon.h>
26
27 #include "milk-task.h"
28
29 G_DEFINE_TYPE (MilkTask, milk_task, G_TYPE_OBJECT);
30
31 /* less expensive than G_TYPE_INSTANCE_GET_PRIVATE */
32 #define MILK_TASK_PRIVATE(o) ((MILK_TASK ((o)))->priv)
33
34 struct _MilkTaskPrivate
35 {
36         char *id;
37         gint priority;
38         char *title;
39 };
40
41 enum {
42         PROP_ID = 1,
43         PROP_TITLE,
44         PROP_PRIORITY,
45 };
46
47
48 static void
49 task_set_id (MilkTask   *task,
50              const char *id)
51 {
52         MilkTaskPrivate *priv;
53
54         g_return_if_fail (MILK_IS_TASK (task));
55         g_return_if_fail (id && !g_str_equal (id, ""));
56
57         priv = MILK_TASK_PRIVATE (task);
58         g_free (priv->id);
59         priv->id = g_strdup (id);
60 }
61
62 void
63 milk_task_set_title (MilkTask   *task,
64                      const char *title)
65 {
66         MilkTaskPrivate *priv;
67
68         g_return_if_fail (MILK_IS_TASK (task));
69
70         priv = MILK_TASK_PRIVATE (task);
71         g_free (priv->title);
72         priv->title = g_strdup (title);
73 }
74
75 void
76 milk_task_set_priority (MilkTask *task,
77                         gint      priority)
78 {
79         MilkTaskPrivate *priv;
80
81         g_return_if_fail (MILK_IS_TASK (task));
82         /* FIXME: set constraints on the allowed priority values */
83
84         priv = MILK_TASK_PRIVATE (task);
85         priv->priority = priority;
86 }
87
88 static void
89 milk_task_get_property (GObject    *object,
90                         guint       property_id,
91                         GValue     *value,
92                         GParamSpec *pspec)
93 {
94         MilkTaskPrivate *priv = MILK_TASK_PRIVATE (object);
95
96         switch (property_id)
97         {
98                 case PROP_ID:
99                         g_value_set_string (value, priv->id);
100                 break;
101
102                 case PROP_TITLE:
103                         g_value_set_string (value, priv->title);
104                 break;
105
106                 case PROP_PRIORITY:
107                         g_value_set_int (value, priv->priority);
108                 break;
109
110                 default:
111                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id,
112                                         pspec);
113         }
114 }
115
116 static void
117 milk_task_set_property (GObject      *object,
118                         guint         property_id,
119                         const GValue *value,
120                         GParamSpec   *pspec)
121 {
122         MilkTaskPrivate *priv;
123         MilkTask *task;
124
125         task = MILK_TASK (object);
126         priv = MILK_TASK_PRIVATE (task);
127
128         switch (property_id)
129         {
130                 case PROP_ID:
131                         task_set_id (task, g_value_get_string (value));
132                 break;
133
134                 case PROP_TITLE:
135                         milk_task_set_title (task, g_value_get_string (value));
136                 break;
137
138                 case PROP_PRIORITY:
139                         milk_task_set_priority (task, g_value_get_int (value));
140                 break;
141
142                 default:
143                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id,
144                                         pspec);
145         }
146 }
147
148 static void
149 milk_task_finalize (GObject *object)
150 {
151         MilkTaskPrivate *priv = MILK_TASK_PRIVATE (object);
152
153         g_free (priv->id);
154         g_free (priv->title);
155 }
156
157 static void
158 milk_task_class_init (MilkTaskClass *klass)
159 {
160         GObjectClass *object_class = G_OBJECT_CLASS (klass);
161
162         g_type_class_add_private (klass, sizeof (MilkTaskPrivate));
163
164         object_class->get_property = milk_task_get_property;
165         object_class->set_property = milk_task_set_property;
166         object_class->finalize = milk_task_finalize;
167
168         g_object_class_install_property
169                 (object_class,
170                  PROP_ID,
171                  g_param_spec_string
172                          ("id",
173                           "Task ID",
174                           "A globally-unique identifier for the task.",
175                           "invalid-ID",
176                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
177                           G_PARAM_STATIC_STRINGS));
178
179         g_object_class_install_property
180                 (object_class,
181                  PROP_TITLE,
182                  g_param_spec_string
183                          ("title",
184                           "Task title",
185                           "The description of the task to be performed.",
186                           "Untitled Task",
187                           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
188
189         g_object_class_install_property
190                 (object_class,
191                  PROP_PRIORITY,
192                  g_param_spec_int
193                          ("priority",
194                           "Task priority",
195                           "The user-valued priority of the task.",
196                           0, G_MAXINT, 0,
197                           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
198 }
199
200 static void
201 milk_task_init (MilkTask *self)
202 {
203         MilkTaskPrivate *priv;
204
205         self->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (
206                         self, MILK_TYPE_TASK, MilkTaskPrivate);
207 }
208
209 MilkTask*
210 milk_task_new (const char *id,
211                const char *title,
212                gint priority)
213 {
214         return g_object_new (
215                         MILK_TYPE_TASK,
216                         "id", id,
217                         "title", title,
218                         "priority", priority,
219                         NULL);
220 }