Add priority column
[milk] / src / milk-list-store.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-list-store.h"
28
29 static void
30 milk_list_store_tree_model_init (GtkTreeModelIface *iface);
31
32 G_DEFINE_TYPE_EXTENDED (MilkListStore,
33                         milk_list_store,
34                         G_TYPE_OBJECT,
35                         0,
36                         G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL,
37                                                milk_list_store_tree_model_init));
38
39 #define MILK_LIST_STORE_PRIVATE(o) \
40                 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MILK_TYPE_LIST_STORE, MilkListStorePrivate))
41
42 #define MILK_LIST_STORE_STAMP_INVALID 0
43
44 struct _MilkListStorePrivate
45 {
46         gint stamp;
47         gint node_count;
48 };
49
50 static GtkTreeModelFlags
51 milk_list_store_get_flags (GtkTreeModel *model)
52 {
53         return GTK_TREE_MODEL_LIST_ONLY;
54 }
55
56 static gint
57 milk_list_store_get_n_columns (GtkTreeModel *model)
58 {
59         return MILK_LIST_STORE_COLUMN_LAST;
60 }
61
62 static GType
63 milk_list_store_get_column_type (GtkTreeModel *model,
64                                  gint          column)
65 {
66         switch (column) {
67                 case MILK_LIST_STORE_COLUMN_PRIORITY:
68                         return G_TYPE_UINT;
69
70                 case MILK_LIST_STORE_COLUMN_TASK:
71                         /* FIXME: define the MilkTask class */
72                         return MILK_TYPE_TASK;
73
74                 default:
75                         g_warning (G_STRLOC ": invalid column: %d", column);
76                         return G_TYPE_INVALID;
77         }
78 }
79
80 static gboolean
81 milk_list_store_get_iter (GtkTreeModel *model,
82                           GtkTreeIter  *iter,
83                           GtkTreePath  *path)
84 {
85         g_return_val_if_fail (MILK_IS_LIST_STORE (model), FALSE);
86         g_return_val_if_fail (iter, FALSE);
87         g_return_val_if_fail (gtk_tree_path_get_depth (path) == 1, FALSE);
88
89         /* FIXME: implement this */
90         g_warning (G_STRLOC ": FIXME: not implemented");
91
92         return TRUE;
93 }
94
95 static GtkTreePath*
96 milk_list_store_get_path (GtkTreeModel *model,
97                           GtkTreeIter  *iter)
98 {
99         g_return_val_if_fail (MILK_IS_LIST_STORE (model), NULL);
100         g_return_val_if_fail (iter, NULL);
101
102         /* FIXME: implement this */
103         g_warning (G_STRLOC ": FIXME: not implemented");
104
105         return NULL;
106 }
107
108 static void
109 milk_list_store_get_value (GtkTreeModel *model,
110                            GtkTreeIter  *iter,
111                            gint          column,
112                            GValue       *value)
113 {
114         g_return_if_fail (MILK_IS_LIST_STORE (model));
115         g_return_if_fail (iter);
116         g_return_if_fail (column < 0);
117         g_return_if_fail (value);
118
119         /* FIXME: implement this */
120         g_warning (G_STRLOC ": FIXME: not implemented");
121 }
122
123 static gboolean
124 milk_list_store_iter_next (GtkTreeModel *model,
125                            GtkTreeIter  *iter)
126 {
127         g_return_val_if_fail (MILK_IS_LIST_STORE (model), FALSE);
128         g_return_val_if_fail (iter, FALSE);
129
130         /* FIXME: implement this */
131         g_warning (G_STRLOC ": FIXME: not implemented");
132
133         return TRUE;
134 }
135
136 static gboolean
137 milk_list_store_iter_nth_child (GtkTreeModel *model,
138                                 GtkTreeIter  *iter,
139                                 GtkTreeIter  *parent,
140                                 gint          index)
141 {
142         MilkListStorePrivate *priv = MILK_LIST_STORE_PRIVATE (model);
143
144         g_return_val_if_fail (MILK_IS_LIST_STORE (model), FALSE);
145         g_return_val_if_fail (iter, FALSE);
146         /* we're one-dimensional */
147         g_return_val_if_fail (!parent, FALSE);
148         g_return_val_if_fail (index < 0, FALSE);
149         g_return_val_if_fail (index >= priv->node_count, FALSE);
150
151         /* FIXME: implement this */
152         g_warning (G_STRLOC ": FIXME: not implemented");
153
154         return TRUE;
155 }
156
157 static gboolean
158 milk_list_store_iter_children (GtkTreeModel *model,
159                                GtkTreeIter  *iter,
160                                GtkTreeIter  *parent)
161 {
162         /* we're one-dimensional, so this is a degenerate case */
163         return milk_list_store_iter_nth_child (model, iter, parent, 0);
164 }
165
166 static gboolean
167 milk_list_store_iter_has_child (GtkTreeModel *model,
168                                 GtkTreeIter  *iter)
169 {
170         g_return_val_if_fail (MILK_IS_LIST_STORE (model), FALSE);
171         g_return_val_if_fail (iter, FALSE);
172
173         return FALSE;
174 }
175
176 static gint
177 milk_list_store_iter_n_children (GtkTreeModel *model,
178                                  GtkTreeIter  *iter)
179 {
180         MilkListStorePrivate *priv = MILK_LIST_STORE_PRIVATE (model);
181
182         g_return_val_if_fail (MILK_IS_LIST_STORE (model), -1);
183         g_return_val_if_fail (iter, -1);
184
185         /* we're one-dimensional */
186         if (iter)
187                 return 0;
188
189         return priv->node_count;
190 }
191
192 static gboolean
193 milk_list_store_iter_parent (GtkTreeModel *model,
194                              GtkTreeIter  *iter,
195                              GtkTreeIter  *child)
196 {
197         g_return_val_if_fail (MILK_IS_LIST_STORE (model), FALSE);
198         g_return_val_if_fail (iter, FALSE);
199         g_return_val_if_fail (child, FALSE);
200
201         return FALSE;
202 }
203
204 static void
205 milk_list_store_get_property (GObject    *object,
206                                guint       property_id,
207                                GValue     *value,
208                                GParamSpec *pspec)
209 {
210         MilkListStorePrivate *priv = MILK_LIST_STORE_PRIVATE (object);
211         switch (property_id)
212         {
213                 default:
214                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id,
215                                         pspec);
216         }
217 }
218
219 static void
220 milk_list_store_set_property (GObject      *object,
221                                guint         property_id,
222                                const GValue *value,
223                                GParamSpec   *pspec)
224 {
225         MilkListStorePrivate *priv = MILK_LIST_STORE_PRIVATE (object);
226         switch (property_id)
227         {
228                 default:
229                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id,
230                                         pspec);
231         }
232 }
233
234 static void
235 milk_list_store_dispose (GObject *object)
236 {
237         MilkListStorePrivate *priv = MILK_LIST_STORE_PRIVATE (object);
238
239         G_OBJECT_CLASS (milk_list_store_parent_class)->dispose (object);
240 }
241
242 static void
243 milk_list_store_constructed (GObject* object)
244 {
245         MilkListStore *self = MILK_LIST_STORE (object);
246         MilkListStorePrivate *priv = MILK_LIST_STORE_PRIVATE (object);
247
248         priv->stamp = MILK_LIST_STORE_STAMP_INVALID + 1;
249 }
250
251 static void
252 milk_list_store_class_init (MilkListStoreClass *klass)
253 {
254         GObjectClass *object_class = G_OBJECT_CLASS (klass);
255
256         g_type_class_add_private (klass, sizeof (MilkListStorePrivate));
257
258         object_class->get_property = milk_list_store_get_property;
259         object_class->set_property = milk_list_store_set_property;
260         object_class->constructed = milk_list_store_constructed;
261         object_class->dispose = milk_list_store_dispose;
262
263         /* FIXME: trigger the signals with gtk_tree_model_row_inserted(), etc.
264          */
265 }
266
267 static void
268 milk_list_store_init (MilkListStore *self)
269 {
270         self->priv = MILK_LIST_STORE_PRIVATE (self);
271 }
272
273 static void
274 milk_list_store_tree_model_init (GtkTreeModelIface *iface)
275 {
276         iface->get_flags       = milk_list_store_get_flags;
277         iface->get_n_columns   = milk_list_store_get_n_columns;
278         iface->get_column_type = milk_list_store_get_column_type;
279         iface->get_iter        = milk_list_store_get_iter;
280         iface->get_path        = milk_list_store_get_path;
281         iface->get_value       = milk_list_store_get_value;
282         iface->iter_next       = milk_list_store_iter_next;
283         iface->iter_children   = milk_list_store_iter_children;
284         iface->iter_has_child  = milk_list_store_iter_has_child;
285         iface->iter_n_children = milk_list_store_iter_n_children;
286         iface->iter_nth_child  = milk_list_store_iter_nth_child;
287         iface->iter_parent     = milk_list_store_iter_parent;
288 }
289
290 MilkListStore*
291 milk_list_store_new ()
292 {
293         return g_object_new (MILK_TYPE_LIST_STORE,
294                              NULL);
295 }