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