From: Travis Reitter Date: Fri, 18 Sep 2009 04:21:04 +0000 (-0700) Subject: Fill in most of the bits of stubs for MilkListStore X-Git-Url: https://vcs.maemo.org/git/?p=milk;a=commitdiff_plain;h=b5fed52f56396e88c4567ce3ef4ec9656edc8c27 Fill in most of the bits of stubs for MilkListStore --- diff --git a/src/Makefile.am b/src/Makefile.am index 4bf330a..2f577bc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,6 +8,8 @@ AM_CFLAGS = \ bin_PROGRAMS = milk milk_SOURCES = \ + milk-list-store.c \ + milk-list-store.h \ milk-main.c \ milk-main.h \ milk-main-window.c \ diff --git a/src/milk-list-store.c b/src/milk-list-store.c new file mode 100644 index 0000000..0fdf7af --- /dev/null +++ b/src/milk-list-store.c @@ -0,0 +1,292 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Travis Reitter + */ + +#include + +#include +#include +#include +#include + +#include "milk-list-store.h" + +static void +milk_list_store_tree_model_init (GtkTreeModelIface *iface); + +G_DEFINE_TYPE_EXTENDED (MilkListStore, + milk_list_store, + G_TYPE_OBJECT, + 0, + G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL, + milk_list_store_tree_model_init)); + +#define MILK_LIST_STORE_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), MILK_TYPE_LIST_STORE, MilkListStorePrivate)) + +#define MILK_LIST_STORE_STAMP_INVALID 0 + +struct _MilkListStorePrivate +{ + gint stamp; + gint node_count; +}; + +static GtkTreeModelFlags +milk_list_store_get_flags (GtkTreeModel *model) +{ + return GTK_TREE_MODEL_LIST_ONLY; +} + +static gint +milk_list_store_get_n_columns (GtkTreeModel *model) +{ + return MILK_LIST_STORE_COLUMN_LAST; +} + +static GType +milk_list_store_get_column_type (GtkTreeModel *model, + gint column) +{ + switch (column) { + case MILK_LIST_STORE_COLUMN_TASK: + /* FIXME: define the MilkTask class */ + return MILK_TYPE_TASK; + + default: + g_warning (G_STRLOC ": invalid column: %d", column); + return G_TYPE_INVALID; + } +} + +static gboolean +milk_list_store_get_iter (GtkTreeModel *model, + GtkTreeIter *iter, + GtkTreePath *path) +{ + g_return_val_if_fail (MILK_IS_LIST_STORE (model), FALSE); + g_return_val_if_fail (iter, FALSE); + g_return_val_if_fail (gtk_tree_path_get_depth (path) == 1, FALSE); + + /* FIXME: implement this */ + g_warning (G_STRLOC ": FIXME: not implemented"); + + return TRUE; +} + +static GtkTreePath* +milk_list_store_get_path (GtkTreeModel *model, + GtkTreeIter *iter) +{ + g_return_val_if_fail (MILK_IS_LIST_STORE (model), NULL); + g_return_val_if_fail (iter, NULL); + + /* FIXME: implement this */ + g_warning (G_STRLOC ": FIXME: not implemented"); + + return NULL; +} + +static void +milk_list_store_get_value (GtkTreeModel *model, + GtkTreeIter *iter, + gint column, + GValue *value) +{ + g_return_if_fail (MILK_IS_LIST_STORE (model)); + g_return_if_fail (iter); + g_return_if_fail (column < 0); + g_return_if_fail (value); + + /* FIXME: implement this */ + g_warning (G_STRLOC ": FIXME: not implemented"); +} + +static gboolean +milk_list_store_iter_next (GtkTreeModel *model, + GtkTreeIter *iter) +{ + g_return_val_if_fail (MILK_IS_LIST_STORE (model), FALSE); + g_return_val_if_fail (iter, FALSE); + + /* FIXME: implement this */ + g_warning (G_STRLOC ": FIXME: not implemented"); + + return TRUE; +} + +static gboolean +milk_list_store_iter_nth_child (GtkTreeModel *model, + GtkTreeIter *iter, + GtkTreeIter *parent, + gint index) +{ + MilkListStorePrivate *priv = MILK_LIST_STORE_PRIVATE (model); + + g_return_val_if_fail (MILK_IS_LIST_STORE (model), FALSE); + g_return_val_if_fail (iter, FALSE); + /* we're one-dimensional */ + g_return_val_if_fail (!parent, FALSE); + g_return_val_if_fail (index < 0, FALSE); + g_return_val_if_fail (index >= priv->node_count, FALSE); + + /* FIXME: implement this */ + g_warning (G_STRLOC ": FIXME: not implemented"); + + return TRUE; +} + +static gboolean +milk_list_store_iter_children (GtkTreeModel *model, + GtkTreeIter *iter, + GtkTreeIter *parent) +{ + /* we're one-dimensional, so this is a degenerate case */ + return milk_list_store_iter_nth_child (model, iter, parent, 0); +} + +static gboolean +milk_list_store_iter_has_child (GtkTreeModel *model, + GtkTreeIter *iter) +{ + g_return_val_if_fail (MILK_IS_LIST_STORE (model), FALSE); + g_return_val_if_fail (iter, FALSE); + + return FALSE; +} + +static gint +milk_list_store_iter_n_children (GtkTreeModel *model, + GtkTreeIter *iter) +{ + MilkListStorePrivate *priv = MILK_LIST_STORE_PRIVATE (model); + + g_return_val_if_fail (MILK_IS_LIST_STORE (model), -1); + g_return_val_if_fail (iter, -1); + + /* we're one-dimensional */ + if (iter) + return 0; + + return priv->node_count; +} + +static gboolean +milk_list_store_iter_parent (GtkTreeModel *model, + GtkTreeIter *iter, + GtkTreeIter *child) +{ + g_return_val_if_fail (MILK_IS_LIST_STORE (model), FALSE); + g_return_val_if_fail (iter, FALSE); + g_return_val_if_fail (child, FALSE); + + return FALSE; +} + +static void +milk_list_store_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + MilkListStorePrivate *priv = MILK_LIST_STORE_PRIVATE (object); + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, + pspec); + } +} + +static void +milk_list_store_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + MilkListStorePrivate *priv = MILK_LIST_STORE_PRIVATE (object); + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, + pspec); + } +} + +static void +milk_list_store_dispose (GObject *object) +{ + MilkListStorePrivate *priv = MILK_LIST_STORE_PRIVATE (object); + + G_OBJECT_CLASS (milk_list_store_parent_class)->dispose (object); +} + +static void +milk_list_store_constructed (GObject* object) +{ + MilkListStore *self = MILK_LIST_STORE (object); + MilkListStorePrivate *priv = MILK_LIST_STORE_PRIVATE (object); + + priv->stamp = MILK_LIST_STORE_STAMP_INVALID + 1; +} + +static void +milk_list_store_class_init (MilkListStoreClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (MilkListStorePrivate)); + + object_class->get_property = milk_list_store_get_property; + object_class->set_property = milk_list_store_set_property; + object_class->constructed = milk_list_store_constructed; + object_class->dispose = milk_list_store_dispose; + + /* FIXME: trigger the signals with gtk_tree_model_row_inserted(), etc. + */ +} + +static void +milk_list_store_init (MilkListStore *self) +{ + self->priv = MILK_LIST_STORE_PRIVATE (self); +} + +static void +milk_list_store_tree_model_init (GtkTreeModelIface *iface) +{ + iface->get_flags = milk_list_store_get_flags; + iface->get_n_columns = milk_list_store_get_n_columns; + iface->get_column_type = milk_list_store_get_column_type; + iface->get_iter = milk_list_store_get_iter; + iface->get_path = milk_list_store_get_path; + iface->get_value = milk_list_store_get_value; + iface->iter_next = milk_list_store_iter_next; + iface->iter_children = milk_list_store_iter_children; + iface->iter_has_child = milk_list_store_iter_has_child; + iface->iter_n_children = milk_list_store_iter_n_children; + iface->iter_nth_child = milk_list_store_iter_nth_child; + iface->iter_parent = milk_list_store_iter_parent; +} + +MilkListStore* +milk_list_store_new () +{ + return g_object_new (MILK_TYPE_LIST_STORE, + NULL); +} diff --git a/src/milk-list-store.h b/src/milk-list-store.h new file mode 100644 index 0000000..c6f73b6 --- /dev/null +++ b/src/milk-list-store.h @@ -0,0 +1,72 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston, MA 02110-1301 USA + * + * Authors: Travis Reitter + */ + +#ifndef _MILK_LIST_STORE_H +#define _MILK_LIST_STORE_H + +G_BEGIN_DECLS + +#define MILK_TYPE_LIST_STORE milk_list_store_get_type() + +#define MILK_LIST_STORE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + MILK_TYPE_LIST_STORE, MilkListStore)) + +#define MILK_LIST_STORE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + MILK_TYPE_LIST_STORE, MilkListStoreClass)) + +#define MILK_IS_LIST_STORE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + MILK_TYPE_LIST_STORE)) + +#define MILK_IS_LIST_STORE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + MILK_TYPE_LIST_STORE)) + +#define MILK_LIST_STORE_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + MILK_TYPE_LIST_STORE, MilkListStoreClass)) + +typedef struct _MilkListStore MilkListStore; +typedef struct _MilkListStoreClass MilkListStoreClass; +typedef struct _MilkListStorePrivate MilkListStorePrivate; + +typedef enum { + MILK_LIST_STORE_COLUMN_TASK, + MILK_LIST_STORE_COLUMN_LAST, +} OssoABookListStoreColumn; + +struct _MilkListStore +{ + GObject parent; + MilkListStorePrivate *priv; +}; + +struct _MilkListStoreClass +{ + GObjectClass parent_class; +}; + +GType milk_list_store_get_type (void); + + +MilkListStore* milk_list_store_new (); + +#endif /* _MILK_LIST_STORE_H */