[model] Packaging/docs fixes for model-gtk library



commit ff1e7a2c6f372ed2e2d2b1db9d479d7a39587e7d
Author: Ryan Lortie <desrt desrt ca>
Date:   Fri Mar 12 04:15:22 2010 -0500

    Packaging/docs fixes for model-gtk library

 docs/reference/Makefile.am        |   10 +-
 docs/reference/model-sections.txt |    7 ++
 docs/reference/model.types        |   14 +++
 gtk/.gitignore                    |    2 +
 gtk/Makefile.am                   |   21 +++--
 gtk/fs.vala                       |  173 -------------------------------------
 gtk/mg.vala                       |   25 ------
 gtk/model-gtk.gtk-doc             |   52 +++++++++++
 gtk/model-gtk.vala                |   50 +++++++----
 model/model.vapi                  |    2 +-
 10 files changed, 127 insertions(+), 229 deletions(-)
---
diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am
index 6651e47..00f4a04 100644
--- a/docs/reference/Makefile.am
+++ b/docs/reference/Makefile.am
@@ -2,13 +2,13 @@ include $(srcdir)/gtk-doc.make
 
 DOC_MODULE = model
 DOC_MAIN_SGML_FILE = model-docs.xml
-DOC_SOURCE_DIR = $(top_srcdir)/model
-MKDB_OPTIONS = --output-format=xml
+DOC_SOURCE_DIR = $(top_srcdir)
+MKDB_OPTIONS = --output-format=xml --source-suffixes=c,gtk-doc
 CLEANFILES += *-overrides.txt *-decl*.txt
 INCLUDES = $(gobject_CFLAGS)
-GTKDOC_LIBS = ../../model/libmodel.la
-CFILE_GLOB = $(top_srcdir)/model/*.c
-GFILE_GLOB = $(top_srcdir)/model/*.h
+GTKDOC_LIBS = ../../model/libmodel.la ../../gtk/libmodel-gtk.la
+CFILE_GLOB = $(top_srcdir)/*/*.c
+GFILE_GLOB = $(top_srcdir)/*/*.h
 
 HTML_IMAGES = \
 	$(srcdir)/images/object.png		\
diff --git a/docs/reference/model-sections.txt b/docs/reference/model-sections.txt
index e98cc14..30262a2 100644
--- a/docs/reference/model-sections.txt
+++ b/docs/reference/model-sections.txt
@@ -233,3 +233,10 @@ MODEL_IS_ABSTRACT_SORTED_LIST_CLASS
 MODEL_ABSTRACT_SORTED_LIST_GET_CLASS
 MODEL_ABSTRACT_SORTED_LIST_CLASS
 </SECTION>
+
+<SECTION>
+<FILE>gtktreemodel</FILE>
+<TITLE>ModelGtkTreeModel</TITLE>
+ModelGtkTreeModel
+model_gtk_tree_model_new
+</SECTION>
diff --git a/docs/reference/model.types b/docs/reference/model.types
new file mode 100644
index 0000000..a580d48
--- /dev/null
+++ b/docs/reference/model.types
@@ -0,0 +1,14 @@
+model_object_get_type
+model_reference_get_type
+model_dictionary_get_type
+model_list_get_type
+model_string_get_type
+model_integer_get_type
+model_boolean_get_type
+model_float_get_type
+model_simple_reference_get_type
+model_reference_helper_get_type
+model_simple_dictionary_get_type
+model_simple_list_get_type
+model_abstract_sorted_list_get_type
+model_gtk_tree_model_get_type
diff --git a/gtk/.gitignore b/gtk/.gitignore
index 7ce0e80..59bebb8 100644
--- a/gtk/.gitignore
+++ b/gtk/.gitignore
@@ -1,3 +1,5 @@
 *.stamp
+*.h
 *.c
 model-gtk
+model-gtk.vapi
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 9c6fba4..8227dd5 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1,8 +1,17 @@
-bin_PROGRAMS = model-gtk
+lib_LTLIBRARIES = libmodel-gtk.la
 
-AM_VALAFLAGS = --vapidir ../model --pkg model --pkg gtk+-2.0 --pkg=posix
-AM_CFLAGS = $(gtk_CFLAGS) -I../model -Wno-bad-function-cast
-model_gtk_LDADD = $(gtk_LIBS) ../model/libmodel.la
-
-model_gtk_SOURCES = model-gtk.vala fs.vala mg.vala
+AM_VALAFLAGS = --vapidir $(top_srcdir)/model --pkg model --pkg gtk+-2.0 --pkg=posix --header=model-gtk.h --library=model-gtk --gir=ModelGtk-0.2.gir
+AM_CFLAGS = $(gtk_CFLAGS) -I$(top_srcdir)/model
+libmodel_gtk_la_LIBADD = $(gtk_LIBS) ../model/libmodel.la
+libmodel_gtk_la_SOURCES = model-gtk.vala
 pkgconfig_DATA = model-gtk.pc
+modelinclude_HEADERS = model-gtk.h
+gir_DATA = ModelGtk-0.2.gir
+typelib_DATA = ModelGtk-0.2.typelib
+vapi_DATA = model-gtk.vapi
+
+ModelGtk-0.2.typelib: ModelGtk-0.2.gir libmodel-gtk.la
+	g-ir-compiler -o $@ --shared-library=libmodel $<
+
+EXTRA_DIST = model-gtk.gtk-doc ModelGtk-0.2.gir model-gtk.vapi
+CLEANFILES = *.typelib *.tmp
diff --git a/gtk/model-gtk.gtk-doc b/gtk/model-gtk.gtk-doc
new file mode 100644
index 0000000..45b6d20
--- /dev/null
+++ b/gtk/model-gtk.gtk-doc
@@ -0,0 +1,52 @@
+/**
+ * SECTION:gtktreemodel
+ * @short_description: a wrapper to allow use of libmodel with #GtkTreeView
+ *
+ * #ModelGtkTreeModel is an implementation of #GtkTreeModel designed to be used with the classes of libmodel.
+ *
+ * The sort of data that is usually presented by a #GtkTreeModel is represented with libmodel as a list of
+ * dictionaries.  This class, therefore, provides a wrapper around a list of dictionaries.
+ *
+ * The #ModelGtkTreeModel is given a list of key names for the dictionaries (and their respective types) to make
+ * visible as columns in the #GtkTreeModel.  Each dictionary in the list is then presented as a row in the
+ * #GtkTreeModel, with the attributes from that dictionary used as the columns.
+ *
+ * If the modelled data is of a nested nature (ie: nodes have children) then column 0 of a given row in the
+ * #GtkTreeModel will be the #ModelList containing the children of that row.  #ModelGtkTreeModel uses this
+ * column internally to present nested data in the usual way for #GtkTreeModel.
+ *
+ * There is only one function to call: model_gtk_tree_model_new().  All other access is made through the
+ * #GtkTreeModel API.
+ **/
+
+/**
+ * ModelGtkTreeModel:
+ *
+ * This is an opaque structure.  It must not be accessed.
+ **/
+
+/**
+ * model_gtk_tree_model_new:
+ * @list: a #ModelList
+ * @num_columns: the number of columns to present
+ * @keys: an array of key name strings (of length @num_columns)
+ * @types: an array of #GType values (of length @num_columns)
+ * @list_only: %TRUE if the model does not represent nested data
+ * @returns: a new #ModelGtkTreeModel
+ *
+ * Creates a new #ModelGtkTreeModel for @list.  This object implements the #GtkTreeModel interface.
+ *
+ * @list must be a #ModelList in which each item is a #ModelDictionary.
+ *
+ * The #GtkTreeModel will have @num_columns columns (with the types given in @types) and as many rows as @list
+ * contains dictionaries.  Each dictionary will correspond to one row.
+ *
+ * The @keys array gives the name of the keys on each dictionary that are queried to obtain the contents for
+ * each column in a row.
+ *
+ * If @list_only is %TRUE then a list-only #GtkTreeModel is presented (like #GtkListStore).
+ *
+ * If @list_only is %FALSE then @list represents nested data (like #GtkTreeStore).  In this case, the first item
+ * in the @types array must be %MODEL_TYPE_LIST.  This list must be a list of dictionaries representing the
+ * children of a given dictionary.
+ **/
diff --git a/gtk/model-gtk.vala b/gtk/model-gtk.vala
index cc42ec7..6d2bf0b 100644
--- a/gtk/model-gtk.vala
+++ b/gtk/model-gtk.vala
@@ -1,4 +1,4 @@
-namespace Model {
+namespace ModelGtk {
 	/* The ListTracker is responsible for tracking a Model.List in a way that is convenient for a GtkTreeModel
 	 * implementation.  It attempts to be lazy, minimising work where possible and only sending signals for
 	 * things that an outside observer can know has changed.  For example, if an outside observer knows that the
@@ -82,8 +82,8 @@ namespace Model {
 		/* Weak references to avoid reference cycles.  The parent reference is used for
 		 * Gtk.TreeModel.iter_get_parent() and the model reference is used for emitting signals.
 		 */
-		internal weak Model.DictionaryTracker? parent;
-		internal weak GtkModel model;
+		internal weak DictionaryTracker? parent;
+		internal weak TreeModel model;
 
 		// We hold a reference on the list in order to keep it alive so it will keep sending signals to us.
 		Model.List? source;
@@ -197,7 +197,7 @@ namespace Model {
 			assert (link == null);
 		}
 
-		internal ListTracker (GtkModel model, DictionaryTracker? parent, Model.List? source) {
+		internal ListTracker (TreeModel model, DictionaryTracker? parent, Model.List? source) {
 			this.length_exposed = length_exposed;
 			this.parent = parent;
 			this.source = source;
@@ -417,13 +417,13 @@ namespace Model {
 
 		void setup_references () {
 			var source = siblings.get_dictionary_for_child (this);
-			var model = siblings.model;
+			var keys = siblings.model.get_keys ();
 
-			references = new Model.Reference[model.keys.length];
-			reference_handlers = new ulong[model.keys.length];
+			references = new Model.Reference[keys.length];
+			reference_handlers = new ulong[keys.length];
 
-			for (var i = 0; i < model.keys.length; i++) {
-				references[i] = source.get_reference (model.keys[i]);
+			for (var i = 0; i < keys.length; i++) {
+				references[i] = source.get_reference (keys[i]);
 				reference_handlers[i] = references[i].changed.connect (reference_changed);
 			}
 		}
@@ -446,13 +446,13 @@ namespace Model {
 		}
 	}
 
-	public class GtkModel : GLib.Object, Gtk.TreeModel {
-		internal string[] keys;
+	public class TreeModel : GLib.Object, Gtk.TreeModel {
 		bool list_only;
+		string[] keys;
 		Type[] types;
 
 		ListTracker root;
-		internal int stamp;
+		int stamp;
 
 		GLib.Type get_column_type (int index) {
 			return types[index];
@@ -547,6 +547,10 @@ namespace Model {
 			return dt != null;
 		}
 
+		internal weak string[] get_keys () {
+			return keys;
+		}
+
 		bool iter_children (out Gtk.TreeIter iter, Gtk.TreeIter? parent) {
 			var lt = iter_to_list_tracker (parent);
 			return write_iter (out iter, lt == null ? null : lt.get_child_for_index (0));
@@ -583,15 +587,23 @@ namespace Model {
 		void unref_node (Gtk.TreeIter iter) {
 		}
 
-		public GtkModel (Model.List list, Type[] types, string[] keys, bool list_only) {
-			this.types = types;
-			this.keys = keys;
-			this.list_only = list_only;
-			this.stamp = 23423423;
+		public TreeModel (Model.List list, int num_columns,
+		                  [CCode (array_length = false)] string **keys,
+		                  [CCode (array_length = false)] Type *types,
+		                  bool list_only) {
+			assert (list_only || (num_columns > 0 && types[0] == typeof (Model.List)));
 
-			this.root = new ListTracker (this, null, list);
+			weak Type[] mytypes = (Type[]) types;
+			mytypes.length = num_columns;
+			this.types = mytypes;
 
-			assert (types.length == keys.length);
+			weak string[] mykeys = (string[]) keys;
+			mykeys.length = num_columns;
+			this.keys = mykeys;
+
+			this.root = new ListTracker (this, null, list);
+			this.stamp = (int) Random.next_int ();
+			this.list_only = list_only;
 		}
 	}
 }
diff --git a/model/model.vapi b/model/model.vapi
index afe6900..664a83b 100644
--- a/model/model.vapi
+++ b/model/model.vapi
@@ -1,4 +1,4 @@
-[CCode (cheader_filename = "model-implementation.h")]
+[CCode (cheader_filename = "model-implementation.h", gir_namespace = "Model", gir_version = "0.2")]
 namespace Model {
   public abstract class Object : GLib.Object { }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]