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