[anjuta/symbol-db-model: 4/4] symbol-db: Added global symbols model



commit bc0c8e05d933f5b277677680df55b4f715742916
Author: Naba Kumar <naba gnome org>
Date:   Fri Mar 12 01:46:34 2010 +0200

    symbol-db: Added global symbols model

 plugins/symbol-db/symbol-db-model-global.c |  248 ++++++++++++++++++++++++++++
 plugins/symbol-db/symbol-db-model-global.h |   60 +++++++
 2 files changed, 308 insertions(+), 0 deletions(-)
---
diff --git a/plugins/symbol-db/symbol-db-model-global.c b/plugins/symbol-db/symbol-db-model-global.c
new file mode 100644
index 0000000..34fcf07
--- /dev/null
+++ b/plugins/symbol-db/symbol-db-model-global.c
@@ -0,0 +1,248 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * symbol-db-model-global.c
+ * Copyright (C) Naba Kumar 2010 <naba gnome org>
+ * 
+ * anjuta 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 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * anjuta 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "symbol-db-engine.h"
+#include "symbol-db-model-global.h"
+
+typedef struct _SymbolDBModelGlobalPriv SymbolDBModelGlobalPriv;
+struct _SymbolDBModelGlobalPriv
+{
+	SymbolDBEngine* dbe;
+};
+
+#define GET_PRIV(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
+						SYMBOL_DB_TYPE_MODEL_GLOBAL, \
+						SymbolDBModelGlobalPriv))
+enum {
+	DATA_COL_SYMBOL_ID,
+	DATA_COL_SYMBOL_NAME,
+	DATA_N_COLS
+};
+
+enum
+{
+	PROP_0,
+	PROP_SYMBOL_DB_ENGINE
+};
+
+G_DEFINE_TYPE (SymbolDBModelGlobal, symbol_db_model_global, G_TYPE_OBJECT);
+
+static gint
+symbol_db_model_global_get_n_children (SymbolDBModel *model, gint tree_level,
+                                       GValue column_values[])
+{
+	SymbolDBModelGlobalPriv *priv;
+	SymbolDBEngineIterator *iter;
+	gint n_children;
+	gint symbol_id;
+	
+	g_return_val_if_fail (SYMBOL_DB_IS_MODEL_GLOBAL (model), 0);
+	priv = GET_PRIV (model);
+	
+	switch (tree_level)
+	{
+		case 0:
+			iter = symbol_db_engine_get_global_members_filtered (priv->dbe, 
+					                                             SYMTYPE_CLASS|
+			                                                     SYMTYPE_ENUM|
+			                                                     SYMTYPE_STRUCT|
+			                                                     SYMTYPE_TYPEDEF|
+			                                                     SYMTYPE_FUNCTION|
+			                                                     SYMTYPE_ENUMERATOR|
+			                                                     SYMTYPE_MACRO|
+			                                                     SYMTYPE_MACRO_WITH_ARG|
+			                                                     SYMTYPE_UNION,
+					                                             TRUE, 
+					                                             TRUE, 
+					                                             -1,
+					                                             -1,
+					                                             SYMINFO_SIMPLE);
+			break;
+		case 1:
+			symbol_id = g_value_get_int (&column_values[DATA_COL_SYMBOL_ID]);
+			iter = symbol_db_engine_get_scope_members_by_symbol_id (priv->dbe,
+			                                                        symbol_id,
+			                                                        -1,
+			                                                        -1,
+			                                                        SYMINFO_SIMPLE);
+			break;
+		default:
+			return 0; /* FIXME */
+	}
+	if (!iter)
+		return 0;
+	n_children = symbol_db_engine_iterator_get_n_items (iter);
+	g_object_unref (iter);
+	return n_children;
+}
+
+static GdaDataModel*
+symbol_db_model_global_get_children (SymbolDBModel *model, gint tree_level,
+                                     GValue column_values[], gint offset,
+                                     gint limit)
+{
+	SymbolDBModelGlobalPriv *priv;
+	SymbolDBEngineIterator *iter;
+	GdaDataModel *data_model;
+	gint symbol_id;
+
+	g_return_val_if_fail (SYMBOL_DB_IS_MODEL_GLOBAL (model), 0);
+	priv = GET_PRIV (model);
+	
+	switch (tree_level)
+	{
+		case 0:
+			iter = symbol_db_engine_get_global_members_filtered (priv->dbe,
+					                                             SYMTYPE_CLASS |
+			                                                     SYMTYPE_ENUM |
+			                                                     SYMTYPE_STRUCT |
+			                                                     SYMTYPE_TYPEDEF |
+			                                                     SYMTYPE_FUNCTION |
+			                                                     SYMTYPE_ENUMERATOR |
+			                                                     SYMTYPE_MACRO |
+			                                                     SYMTYPE_MACRO_WITH_ARG |
+			                                                     SYMTYPE_UNION,
+					                                             TRUE, 
+					                                             TRUE, 
+					                                             limit,
+					                                             offset,
+					                                             SYMINFO_SIMPLE |
+					                                             SYMINFO_ACCESS |
+					                                             SYMINFO_KIND);
+			g_message ("Retrieving data: %d to %d", offset, offset + limit);
+			break;
+		case 1:
+			symbol_id = g_value_get_int (&column_values[DATA_COL_SYMBOL_ID]);
+			iter = symbol_db_engine_get_scope_members_by_symbol_id (priv->dbe,
+			                                                        symbol_id,
+			                                                        -1,
+			                                                        -1,
+			                                                        SYMINFO_SIMPLE);
+			break;
+		default:
+			return NULL;
+	}
+	data_model = (GdaDataModel*)symbol_db_engine_iterator_get_datamodel (iter);
+	g_object_ref (data_model);
+	g_object_unref (iter);
+	return data_model;
+}
+
+static void
+symbol_db_model_global_init (SymbolDBModelGlobal *object)
+{
+	SymbolDBModelGlobalPriv *priv;
+	GType types[] = {G_TYPE_INT, GDK_TYPE_PIXBUF, G_TYPE_STRING};
+	gint data_cols[] = {DATA_COL_SYMBOL_ID, -1, DATA_COL_SYMBOL_NAME};
+	
+	g_return_if_fail (SYMBOL_DB_IS_MODEL_GLOBAL (object));
+	priv = GET_PRIV (object);
+	
+	priv->dbe = NULL;
+	symbol_db_model_set_columns (SYMBOL_DB_MODEL (object), 3, types, data_cols);
+}
+
+static void
+symbol_db_model_global_finalize (GObject *object)
+{
+	SymbolDBModelGlobalPriv *priv;
+
+	g_return_if_fail (SYMBOL_DB_IS_MODEL_GLOBAL (object));
+	priv = GET_PRIV (object);
+	
+	if (priv->dbe)
+		g_object_unref (priv->dbe);
+	G_OBJECT_CLASS (symbol_db_model_global_parent_class)->finalize (object);
+}
+
+static void
+symbol_db_model_global_set_property (GObject *object, guint prop_id,
+                                     const GValue *value, GParamSpec *pspec)
+{
+	SymbolDBModelGlobalPriv *priv;
+
+	g_return_if_fail (SYMBOL_DB_IS_MODEL_GLOBAL (object));
+	priv = GET_PRIV (object);
+	
+	switch (prop_id)
+	{
+	case PROP_SYMBOL_DB_ENGINE:
+		if (priv->dbe)
+			g_object_unref (priv->dbe);
+		priv->dbe = g_value_dup_object (value);
+		/* TODO: Reset model */
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+symbol_db_model_global_get_property (GObject *object, guint prop_id,
+                                     GValue *value, GParamSpec *pspec)
+{
+	SymbolDBModelGlobalPriv *priv;
+
+	g_return_if_fail (SYMBOL_DB_IS_MODEL_GLOBAL (object));
+	priv = GET_PRIV (object);
+	
+	switch (prop_id)
+	{
+	case PROP_SYMBOL_DB_ENGINE:
+		g_value_set_object (value, priv->dbe);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+symbol_db_model_global_class_init (SymbolDBModelGlobalClass *klass)
+{
+	GObjectClass* object_class = G_OBJECT_CLASS (klass);
+	SymbolDBModelClass* parent_class = SYMBOL_DB_MODEL_CLASS (klass);
+
+	g_type_class_add_private (klass, sizeof (SymbolDBModelGlobalPriv));
+
+	object_class->finalize = symbol_db_model_global_finalize;
+	object_class->set_property = symbol_db_model_global_set_property;
+	object_class->get_property = symbol_db_model_global_get_property;
+
+	parent_class->get_n_children = symbol_db_model_global_get_n_children;
+	parent_class->get_children =  symbol_db_model_global_get_children;
+	
+	g_object_class_install_property (object_class,
+	                                 PROP_SYMBOL_DB_ENGINE,
+	                                 g_param_spec_object ("symbol-db-engine",
+	                                                      "Symbol DB Engine",
+	                                                      "Symbol DB Engine instance used to make queries",
+	                                                      SYMBOL_TYPE_DB_ENGINE,
+	                                                      G_PARAM_READABLE |
+	                                                      G_PARAM_WRITABLE |
+	                                                      G_PARAM_CONSTRUCT_ONLY));
+}
+
+GtkTreeModel*
+symbol_db_model_global_new (SymbolDBEngine* dbe)
+{
+	return GTK_TREE_MODEL (g_object_new (SYMBOL_DB_TYPE_MODEL_GLOBAL,
+	                                     "symbol-db-engine", dbe));
+}
diff --git a/plugins/symbol-db/symbol-db-model-global.h b/plugins/symbol-db/symbol-db-model-global.h
new file mode 100644
index 0000000..dddb376
--- /dev/null
+++ b/plugins/symbol-db/symbol-db-model-global.h
@@ -0,0 +1,60 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * symbol-db-model-global.h
+ * Copyright (C) Naba Kumar 2010 <naba gnome org>
+ * 
+ * anjuta 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 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * anjuta 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _SYMBOL_DB_MODEL_GLOBAL_H_
+#define _SYMBOL_DB_MODEL_GLOBAL_H_
+
+#include <glib-object.h>
+#include "symbol-db-model.h"
+
+G_BEGIN_DECLS
+
+#define SYMBOL_DB_TYPE_MODEL_GLOBAL             (symbol_db_model_global_get_type ())
+#define SYMBOL_DB_MODEL_GLOBAL(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), SYMBOL_DB_TYPE_MODEL_GLOBAL, SymbolDBModelGlobal))
+#define SYMBOL_DB_MODEL_GLOBAL_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), SYMBOL_DB_TYPE_MODEL_GLOBAL, SymbolDBModelGlobalClass))
+#define SYMBOL_DB_IS_MODEL_GLOBAL(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SYMBOL_DB_TYPE_MODEL_GLOBAL))
+#define SYMBOL_DB_IS_MODEL_GLOBAL_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), SYMBOL_DB_TYPE_MODEL_GLOBAL))
+#define SYMBOL_DB_MODEL_GLOBAL_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), SYMBOL_DB_TYPE_MODEL_GLOBAL, SymbolDBModelGlobalClass))
+
+typedef struct _SymbolDBModelGlobalClass SymbolDBModelGlobalClass;
+typedef struct _SymbolDBModelGlobal SymbolDBModelGlobal;
+
+enum {
+	SYMBOL_DB_MODEL_GLOBAL_COL_SYMBOL_ID,
+	SYMBOL_DB_MODEL_GLOBAL_COL_PIXBUF,
+	SYMBOL_DB_MODEL_GLOBAL_COL_LABEL,
+	SYMBOL_DB_MODEL_GLOBAL_COL_N_COLS
+};
+
+struct _SymbolDBModelGlobalClass
+{
+	SymbolDBModelClass parent_class;
+};
+
+struct _SymbolDBModelGlobal
+{
+	SymbolDBModel parent_instance;
+};
+
+GType symbol_db_model_global_get_type (void) G_GNUC_CONST;
+GtkTreeModel* symbol_db_model_global_new (SymbolDBEngine* dbe);
+
+G_END_DECLS
+
+#endif /* _SYMBOL_DB_MODEL_GLOBAL_H_ */



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