[gitg/vala] Added libgitg-gtk



commit eb586c855cf9330ac6a143371608ff58a7bc5d36
Author: Jesse van den Kieboom <jesse vandenkieboom epfl ch>
Date:   Sun Apr 15 14:57:30 2012 +0200

    Added libgitg-gtk

 Makefile.am                            |    2 +-
 configure.ac                           |   11 +-
 libgitg-gtk/Makefile.am                |   72 ++++++++
 libgitg-gtk/gitg-gtk-commit-model.vala |  305 ++++++++++++++++++++++++++++++++
 libgitg-gtk/libgitg-gtk-1.0.pc.in      |   11 ++
 5 files changed, 398 insertions(+), 3 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 9ef7d1b..b16b440 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,7 @@
 
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
 
-SUBDIRS = libgitg gitg data po tests tools
+SUBDIRS = libgitg libgitg-gtk gitg data po tests tools
 
 DISTCLEANFILES = \
 	intltool-extract \
diff --git a/configure.ac b/configure.ac
index 7762563..82d8c5e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -196,7 +196,10 @@ GITG_PLUGIN_LIBDIR="$libdir/gitg/plugins"
 AC_SUBST(GITG_PLUGIN_LIBDIR)
 
 GITG_PLUGIN_CFLAGS="$GITG_CFLAGS"
-GITG_PLUGIN_LIBS="$GITG_LIBS"
+GITG_PLUGIN_LIBS="$GITG_LIBS 					\
+	\$(top_builddir)/libgitg/libgitg-1.0.la 		\
+	\$(top_builddir)/libgitg-ext/libgitg-ext-1.0.la 	\
+	\$(top_builddir)/libgitg-gtk/libgitg-gtk-1.0.la"
 
 AC_SUBST(GITG_PLUGIN_CFLAGS)
 AC_SUBST(GITG_PLUGIN_LIBS)
@@ -204,9 +207,11 @@ AC_SUBST(GITG_PLUGIN_LIBS)
 GITG_PLUGIN_LIBTOOL_FLAGS="-module -avoid-version"
 AC_SUBST(GITG_PLUGIN_LIBTOOL_FLAGS)
 
-GITG_PLUGIN_VALAFLAGS="--pkg GitgExt-1.0		\
+GITG_PLUGIN_VALAFLAGS="			\
+	--pkg GitgExt-1.0		\
 	--pkg Ggit-1.0 			\
 	--pkg Gitg-1.0			\
+	--pkg GitgGtk-1.0		\
 	--pkg gio-2.0			\
 	--pkg gtk+-3.0			\
 	--pkg libpeas-1.0		\
@@ -244,6 +249,8 @@ AC_CONFIG_FILES([
 Makefile
 libgitg/Makefile
 libgitg/libgitg-1.0.pc
+libgitg-gtk/Makefile
+libgitg-gtk/libgitg-gtk-1.0.pc
 libgitg-ext/Makefile
 libgitg-ext/libgitg-ext-1.0.pc
 gitg/Makefile
diff --git a/libgitg-gtk/Makefile.am b/libgitg-gtk/Makefile.am
new file mode 100644
index 0000000..1972003
--- /dev/null
+++ b/libgitg-gtk/Makefile.am
@@ -0,0 +1,72 @@
+lib_LTLIBRARIES = libgitg-gtk-1.0.la
+
+INCLUDES =								\
+	-I$(top_srcdir)							\
+	-I$(srcdir)							\
+	$(LIBGITG_CFLAGS)						\
+	$(LIBGITG_GTK_CFLAGS)						\
+	$(WARN_CFLAGS)							\
+	-DDATADIR=\""$(datadir)"\"					\
+	-DLIBDIR=\""$(libdir)"\"
+
+libgitg_gtk_1_0_la_LDFLAGS = 		\
+	-export-dynamic -no-undefined -export-symbols-regex "^[^_].*"
+
+libgitg_gtk_1_0_la_LIBADD = 				\
+	$(LIBGITG_LIBS)					\
+	$(LIBGITG_GTK_LIBS)				\
+	$(top_builddir)/libgitg/libgitg-1.0.la
+
+INST_H_FILES =				\
+	libgitg-gtk.h
+
+VALAFLAGS = 				\
+	--pkg Ggit-1.0 			\
+	--pkg Gitg-1.0			\
+	--pkg gtk+-3.0			\
+	--pkg gio-2.0			\
+	--header libgitg-gtk.h		\
+	--includedir libgitg-gtk	\
+	--basedir $(top_srcdir)		\
+	--gir GitgGtk-1.0.gir		\
+	--library libgitg-gtk-1.0
+
+GitgGtk-1.0.gir: libgitg-gtk-1.0.la
+
+VALA_FILES =				\
+	gitg-gtk-commit-list-view.vala	\
+	gitg-gtk-commit-model.vala
+
+# Ignore all warnings for vala code...
+libgitg_gtk_1_0_la_CFLAGS =		\
+	-w
+
+libgitg_gtk_1_0_la_SOURCES = 		\
+	$(VALA_FILES)
+
+headerdir = $(prefix)/include/libgitg-gtk-1.0/libgitg-gtk
+header_DATA = $(INST_H_FILES)
+
+girdir = $(INTROSPECTION_GIRDIR)
+gir_DATA = GitgGtk-1.0.gir
+
+typelibdir = $(INTROSPECTION_TYPELIBDIR)
+typelib_DATA = GitgGtk-1.0.typelib
+
+%.typelib: %.gir
+	$(INTROSPECTION_COMPILER) $(INTROSPECTION_COMPILER_ARGS) --includedir=. -o $@ $<
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = libgitg-gtk-1.0.pc
+
+BUILT_SOURCES = \
+	$(gir_DATA) \
+	libgitg-gtk.h
+
+EXTRA_DIST = $(pkgconfig_DATA)
+CLEANFILES = $(VALA_FILES:.vala=.c)
+
+dist-hook:
+	cd $(distdir); rm -f $(BUILT_SOURCES)
+
+-include $(top_srcdir)/git.mk
diff --git a/libgitg-gtk/gitg-gtk-commit-model.vala b/libgitg-gtk/gitg-gtk-commit-model.vala
new file mode 100644
index 0000000..a9ef278
--- /dev/null
+++ b/libgitg-gtk/gitg-gtk-commit-model.vala
@@ -0,0 +1,305 @@
+namespace GitgGtk
+{
+	public enum CommitModelColumns
+	{
+		SHA1,
+		SUBJECT,
+		MESSAGE,
+		AUTHOR,
+		AUTHOR_NAME,
+		AUTHOR_EMAIL,
+		AUTHOR_DATE,
+		COMMITTER,
+		COMMITTER_NAME,
+		COMMITTER_EMAIL,
+		COMMITTER_DATE,
+		COMMIT,
+		NUM;
+
+		public Type type()
+		{
+			switch (this)
+			{
+				case SHA1:
+				case SUBJECT:
+				case MESSAGE:
+				case COMMITTER:
+				case COMMITTER_NAME:
+				case COMMITTER_EMAIL:
+				case COMMITTER_DATE:
+				case AUTHOR:
+				case AUTHOR_NAME:
+				case AUTHOR_EMAIL:
+				case AUTHOR_DATE:
+					return typeof(string);
+				case COMMIT:
+					return typeof(Gitg.Commit);
+				default:
+				break;
+			}
+
+			return Type.INVALID;
+		}
+	}
+
+	public class CommitModel : Gitg.CommitModel, Gtk.TreeModel
+	{
+		private uint d_size;
+		private int d_stamp;
+
+		public CommitModel(Gitg.Repository repository)
+		{
+			Object(repository: repository);
+		}
+
+		protected override void emit_started()
+		{
+			clear();
+			base.emit_started();
+		}
+
+		private void clear()
+		{
+			// Remove all
+			var path = new Gtk.TreePath.from_indices(d_size);
+
+			while (d_size > 0)
+			{
+				path.down();
+				--d_size;
+
+				row_deleted(path.copy());
+			}
+
+			++d_stamp;
+		}
+
+		protected override void emit_update(uint added)
+		{
+			var path = new Gtk.TreePath.from_indices(d_size);
+
+			Gtk.TreeIter iter = Gtk.TreeIter();
+			iter.stamp = d_stamp;
+
+			for (uint i = 0; i < added; ++i)
+			{
+				iter.user_data = (void *)(ulong)d_size;
+
+				++d_size;
+
+				row_inserted(path.copy(), iter);
+				path.up();
+			}
+
+			base.emit_update(added);
+		}
+
+		public Type get_column_type(int index)
+		{
+			return ((CommitModelColumns)index).type();
+		}
+
+		public Gtk.TreeModelFlags get_flags()
+		{
+			return Gtk.TreeModelFlags.LIST_ONLY |
+			       Gtk.TreeModelFlags.ITERS_PERSIST;
+		}
+
+		public bool get_iter(ref Gtk.TreeIter iter, Gtk.TreePath path)
+		{
+			int[] indices = path.get_indices();
+
+			if (indices.length != 1)
+			{
+				return false;
+			}
+
+			uint index = (uint)indices[0];
+
+			if (index >= d_size)
+			{
+				return false;
+			}
+
+			iter.user_data = (void *)(ulong)index;
+			iter.stamp = d_stamp;
+
+			return true;
+		}
+
+		public int get_n_columns()
+		{
+			return CommitModelColumns.NUM;
+		}
+
+		public Gtk.TreePath? get_path(Gtk.TreeIter iter)
+		{
+			uint id = (uint)(ulong)iter.user_data;
+
+			return_val_if_fail(iter.stamp == d_stamp, null);
+
+			return new Gtk.TreePath.from_indices((int)id);
+		}
+
+		public void get_value(Gtk.TreeIter iter, int column, ref Value val)
+		{
+			return_if_fail(iter.stamp == d_stamp);
+
+			uint idx = (uint)(ulong)iter.user_data;
+			Gitg.Commit? commit = base[idx];
+
+			if (commit == null)
+			{
+				return;
+			}
+
+			switch (column)
+			{
+				case CommitModelColumns.SHA1:
+					val.init(typeof(string));
+					val.set_string(commit.get_id().to_string());
+				break;
+				case CommitModelColumns.SUBJECT:
+					val.init(typeof(string));
+					val.set_string(commit.get_subject());
+				break;
+				case CommitModelColumns.MESSAGE:
+					val.init(typeof(string));
+					val.set_string(commit.get_message());
+				break;
+				case CommitModelColumns.COMMITTER:
+					val.init(typeof(string));
+					val.set_string("%s <%s>".printf(commit.get_committer().get_name(),
+					                                commit.get_committer().get_email()));
+				break;
+				case CommitModelColumns.COMMITTER_NAME:
+					val.init(typeof(string));
+					val.set_string(commit.get_committer().get_name());
+				break;
+				case CommitModelColumns.COMMITTER_EMAIL:
+					val.init(typeof(string));
+					val.set_string(commit.get_committer().get_email());
+				break;
+				case CommitModelColumns.COMMITTER_DATE:
+					val.init(typeof(string));
+					val.set_string(commit.committer_date_for_display);
+				break;
+				case CommitModelColumns.AUTHOR:
+					val.init(typeof(string));
+					val.set_string("%s <%s>".printf(commit.get_author().get_name(),
+					                                commit.get_author().get_email()));
+				break;
+				case CommitModelColumns.AUTHOR_NAME:
+					val.init(typeof(string));
+					val.set_string(commit.get_author().get_name());
+				break;
+				case CommitModelColumns.AUTHOR_EMAIL:
+					val.init(typeof(string));
+					val.set_string(commit.get_author().get_email());
+				break;
+				case CommitModelColumns.AUTHOR_DATE:
+					val.init(typeof(string));
+					val.set_string(commit.author_date_for_display);
+				break;
+				case CommitModelColumns.COMMIT:
+					val.init(typeof(Gitg.Commit));
+					val.set_object(commit);
+				break;
+			}
+		}
+
+		public Gitg.Commit? commit_from_iter(Gtk.TreeIter iter)
+		{
+			return_val_if_fail(iter.stamp == d_stamp, null);
+
+			uint idx = (uint)(ulong)iter.user_data;
+			return base[idx];
+		}
+
+		public Gitg.Commit? commit_from_path(Gtk.TreePath path)
+		{
+			int[] indices = path.get_indices();
+
+			if (indices.length != 1)
+			{
+				return null;
+			}
+
+			return base[(uint)indices[0]];
+		}
+
+		public bool iter_children(ref Gtk.TreeIter iter, Gtk.TreeIter? parent)
+		{
+			if (parent == null)
+			{
+				iter.user_data = (void *)(ulong)0;
+				iter.stamp = d_stamp;
+
+				return true;
+			}
+			else
+			{
+				return_val_if_fail(parent.stamp == d_stamp, false);
+				return false;
+			}
+		}
+
+		public bool iter_has_child(Gtk.TreeIter iter)
+		{
+			return false;
+		}
+
+		public int iter_n_children(Gtk.TreeIter? iter)
+		{
+			if (iter == null)
+			{
+				return (int)d_size;
+			}
+			else
+			{
+				return_val_if_fail(iter.stamp == d_stamp, 0);
+				return 0;
+			}
+		}
+
+		public bool iter_next(ref Gtk.TreeIter iter)
+		{
+			return_val_if_fail(iter.stamp == d_stamp, false);
+
+			uint index = (uint)(ulong)iter.user_data;
+			++index;
+
+			if (index >= d_size)
+			{
+				return false;
+			}
+			else
+			{
+				iter.user_data = (void *)(ulong)index;
+				return true;
+			}
+		}
+
+		public bool iter_nth_child(ref Gtk.TreeIter iter, Gtk.TreeIter? parent, int n)
+		{
+			if (parent != null || (uint)n >= d_size)
+			{
+				return false;
+			}
+
+			iter.user_data = (void *)(ulong)n;
+			iter.stamp = d_stamp;
+
+			return true;
+		}
+
+		public bool iter_parent(ref Gtk.TreeIter parent, Gtk.TreeIter iter)
+		{
+			return_val_if_fail(iter.stamp == d_stamp, false);
+
+			return false;
+		}
+	}
+}
+
+// vi:ts=4
diff --git a/libgitg-gtk/libgitg-gtk-1.0.pc.in b/libgitg-gtk/libgitg-gtk-1.0.pc.in
new file mode 100644
index 0000000..d6110ae
--- /dev/null
+++ b/libgitg-gtk/libgitg-gtk-1.0.pc.in
@@ -0,0 +1,11 @@
+prefix= prefix@
+exec_prefix= exec_prefix@
+libdir= libdir@
+includedir= includedir@
+
+Name: @PACKAGE_NAME@
+Description: gitg gtk library
+Version: @PACKAGE_VERSION@
+Requires: libgit2-glib-1.0 glib-2.0 gobject-2.0 gmodule-2.0 gio-2.0 gio-unix-2.0 gthread-2.0 gtk+-3.0
+Libs: -L${libdir} -lgitg-gtk-1.0
+Cflags: -I${includedir}/libgitg-gtk-1.0



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