Fix a Gtk warning when checking path input in the log viewer.
[anjuta-git-plugin.git] / plugins / symbol-db / symbol-db-engine-iterator-node.c
blob6a6e8144998b61b7fbd8b1c12e654a9f1aad3deb
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta
4 * Copyright (C) Massimo Cora' 2007 <maxcvs@email.it>
5 *
6 * anjuta is free software.
7 *
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
11 * any later version.
13 * anjuta is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with anjuta. If not, write to:
20 * The Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02110-1301, USA.
25 #include <libanjuta/interfaces/ianjuta-symbol.h>
26 #include <libanjuta/anjuta-utils.h>
27 #include <libanjuta/anjuta-debug.h>
28 #include <libgnomevfs/gnome-vfs.h>
30 #include "symbol-db-engine-iterator-node.h"
31 #include "symbol-db-engine.h"
32 #include "symbol-db-view.h"
34 struct _SymbolDBEngineIteratorNodePriv
36 GdaDataModelIter *data_iter;
37 const GHashTable *sym_type_conversion_hash;
38 gchar *uri;
41 static GObjectClass* parent_class = NULL;
44 SymbolDBEngineIteratorNode *
45 symbol_db_engine_iterator_node_new (const GdaDataModelIter *data)
47 SymbolDBEngineIteratorNode *s;
48 s = g_object_new (SYMBOL_TYPE_DB_ENGINE_ITERATOR_NODE, NULL);
49 s->priv->data_iter = (GdaDataModelIter *)data;
50 s->priv->uri = NULL;
52 return s;
55 static void
56 sdb_engine_iterator_node_instance_init (SymbolDBEngineIteratorNode *object)
58 SymbolDBEngineIteratorNode *sdbin;
60 sdbin = SYMBOL_DB_ENGINE_ITERATOR_NODE (object);
62 sdbin->priv = g_new0 (SymbolDBEngineIteratorNodePriv, 1);
63 sdbin->priv->sym_type_conversion_hash = NULL;
64 sdbin->priv->uri = NULL;
67 static void
68 sdb_engine_iterator_node_finalize (GObject *object)
70 SymbolDBEngineIteratorNode *dbin;
71 SymbolDBEngineIteratorNodePriv *priv;
73 dbin = SYMBOL_DB_ENGINE_ITERATOR_NODE (object);
74 priv = dbin->priv;
75 if (priv->uri)
76 g_free (priv->uri);
78 g_free (priv);
80 G_OBJECT_CLASS (parent_class)->finalize (object);
83 static void
84 sdb_engine_iterator_node_class_init (SymbolDBEngineIteratorNodeClass *klass)
86 GObjectClass* object_class = G_OBJECT_CLASS (klass);
87 parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
89 object_class->finalize = sdb_engine_iterator_node_finalize;
92 /**
93 * Symbol name must be always on column 0
95 gint
96 symbol_db_engine_iterator_node_get_symbol_id (SymbolDBEngineIteratorNode *dbin)
98 SymbolDBEngineIteratorNodePriv *priv;
99 const GValue* value;
101 g_return_val_if_fail (dbin != NULL, -1);
102 priv = dbin->priv;
104 value = gda_data_model_iter_get_value_at (priv->data_iter, 0);
106 return value != NULL && G_VALUE_HOLDS_INT (value)
107 ? g_value_get_int (value) : -1;
111 * Symbol name must be always on column 1
113 const gchar*
114 symbol_db_engine_iterator_node_get_symbol_name (SymbolDBEngineIteratorNode *dbin)
116 SymbolDBEngineIteratorNodePriv *priv;
117 const GValue* value;
119 g_return_val_if_fail (dbin != NULL, NULL);
120 priv = dbin->priv;
122 value = gda_data_model_iter_get_value_at (priv->data_iter, 1);
124 return value != NULL && G_VALUE_HOLDS_STRING (value)
125 ? g_value_get_string (value) : NULL;
129 * File pos must be always on column 2
131 gint
132 symbol_db_engine_iterator_node_get_symbol_file_pos (SymbolDBEngineIteratorNode *dbin)
134 SymbolDBEngineIteratorNodePriv *priv;
135 const GValue* value;
137 g_return_val_if_fail (dbin != NULL, -1);
138 priv = dbin->priv;
140 value = gda_data_model_iter_get_value_at (priv->data_iter, 2);
142 return value != NULL && G_VALUE_HOLDS_INT (value)
143 ? g_value_get_int (value) : -1;
147 * 'Is File Scope' must be always on column 3
149 gboolean
150 symbol_db_engine_iterator_node_get_symbol_is_file_scope (SymbolDBEngineIteratorNode *dbin)
152 SymbolDBEngineIteratorNodePriv *priv;
153 const GValue* value;
155 g_return_val_if_fail (dbin != NULL, FALSE);
156 priv = dbin->priv;
158 value = gda_data_model_iter_get_value_at (priv->data_iter, 3);
160 if (value != NULL && G_VALUE_HOLDS_INT (value))
161 return g_value_get_int (value) == 1 ? TRUE : FALSE;
163 return FALSE;
167 * Signature must be always on column 4
169 const gchar*
170 symbol_db_engine_iterator_node_get_symbol_signature (SymbolDBEngineIteratorNode *dbin)
172 SymbolDBEngineIteratorNodePriv *priv;
173 const GValue* value;
175 g_return_val_if_fail (dbin != NULL, NULL);
176 priv = dbin->priv;
178 value = gda_data_model_iter_get_value_at (priv->data_iter, 4);
180 return value != NULL && G_VALUE_HOLDS_STRING (value)
181 ? g_value_get_string (value) : NULL;
184 const gchar*
185 symbol_db_engine_iterator_node_get_symbol_extra_string (SymbolDBEngineIteratorNode *dbin,
186 gint sym_info)
188 SymbolDBEngineIteratorNodePriv *priv;
189 const GValue *value = NULL;
191 g_return_val_if_fail (dbin != NULL, NULL);
192 priv = dbin->priv;
194 if (sym_info & SYMINFO_FILE_PATH)
196 value = gda_data_model_iter_get_value_for_field (priv->data_iter,
197 "file_path");
199 else if (sym_info & SYMINFO_LANGUAGE)
201 value = gda_data_model_iter_get_value_for_field (priv->data_iter,
202 "language_name");
204 else if (sym_info & SYMINFO_IMPLEMENTATION)
206 value = gda_data_model_iter_get_value_for_field (priv->data_iter,
207 "implementation_name");
209 else if (sym_info & SYMINFO_ACCESS)
211 value = gda_data_model_iter_get_value_for_field (priv->data_iter,
212 "access_name");
214 else if (sym_info & SYMINFO_KIND)
216 value = gda_data_model_iter_get_value_for_field (priv->data_iter,
217 "kind_name");
219 else if (sym_info & SYMINFO_TYPE)
221 value = gda_data_model_iter_get_value_for_field (priv->data_iter,
222 "type_type");
224 else if (sym_info & SYMINFO_TYPE_NAME)
226 value = gda_data_model_iter_get_value_for_field (priv->data_iter,
227 "type_name");
229 else if (sym_info & SYMINFO_PROJECT_NAME)
231 value = gda_data_model_iter_get_value_for_field (priv->data_iter,
232 "project_name");
234 else if (sym_info & SYMINFO_FILE_IGNORE)
236 value = gda_data_model_iter_get_value_for_field (priv->data_iter,
237 "file_ignore_type");
239 else if (sym_info & SYMINFO_FILE_INCLUDE)
241 value = gda_data_model_iter_get_value_for_field (priv->data_iter,
242 "file_include_type");
245 return value != NULL && G_VALUE_HOLDS_STRING (value)
246 ? g_value_get_string (value) : NULL;
249 void
250 symbol_db_engine_iterator_node_set_conversion_hash (SymbolDBEngineIteratorNode *dbin,
251 const GHashTable *sym_type_conversion_hash)
253 g_return_if_fail (dbin != NULL);
254 g_return_if_fail (SYMBOL_IS_DB_ENGINE_ITERATOR_NODE (dbin));
256 SymbolDBEngineIteratorNodePriv *priv;
258 priv = dbin->priv;
259 priv->sym_type_conversion_hash = sym_type_conversion_hash;
262 void
263 symbol_db_engine_iterator_node_set_data (SymbolDBEngineIteratorNode *dbin,
264 const GdaDataModelIter *data)
266 g_return_if_fail (dbin != NULL);
267 g_return_if_fail (SYMBOL_IS_DB_ENGINE_ITERATOR_NODE (dbin));
269 SymbolDBEngineIteratorNodePriv *priv;
271 priv = dbin->priv;
272 priv->data_iter = GDA_DATA_MODEL_ITER (data);
273 if (priv->uri != NULL)
275 g_free (priv->uri);
276 priv->uri = NULL;
280 /* IAnjutaSymbol implementation */
281 static const gchar*
282 isymbol_get_name (IAnjutaSymbol *isymbol, GError **err)
284 SymbolDBEngineIteratorNode *s;
286 g_return_val_if_fail (SYMBOL_IS_DB_ENGINE_ITERATOR (isymbol), NULL);
287 s = SYMBOL_DB_ENGINE_ITERATOR_NODE (isymbol);
289 return symbol_db_engine_iterator_node_get_symbol_name (s);
292 static const gchar*
293 isymbol_get_args (IAnjutaSymbol *isymbol, GError **err)
295 SymbolDBEngineIteratorNode *s;
297 g_return_val_if_fail (SYMBOL_IS_DB_ENGINE_ITERATOR (isymbol), NULL);
298 s = SYMBOL_DB_ENGINE_ITERATOR_NODE (isymbol);
299 return symbol_db_engine_iterator_node_get_symbol_signature (s);
302 static const gchar*
303 isymbol_get_extra_info_string (IAnjutaSymbol *isymbol, IAnjutaSymbolField sym_info,
304 GError **err)
306 SymbolDBEngineIteratorNode *s;
308 g_return_val_if_fail (SYMBOL_IS_DB_ENGINE_ITERATOR (isymbol), NULL);
309 s = SYMBOL_DB_ENGINE_ITERATOR_NODE (isymbol);
310 return symbol_db_engine_iterator_node_get_symbol_extra_string (s, sym_info);
313 static GFile*
314 isymbol_get_file (IAnjutaSymbol *isymbol, GError **err)
316 SymbolDBEngineIteratorNode *s;
318 g_return_val_if_fail (SYMBOL_IS_DB_ENGINE_ITERATOR (isymbol), NULL);
319 s = SYMBOL_DB_ENGINE_ITERATOR_NODE (isymbol);
320 if (s->priv->uri == NULL)
322 const gchar* file_path;
323 GFile* file;
324 file_path = symbol_db_engine_iterator_node_get_symbol_extra_string (s,
325 SYMINFO_FILE_PATH);
326 file = g_file_new_for_path (file_path);
327 s->priv->uri = g_file_get_uri (file);
328 g_object_unref (file);
330 return g_file_new_for_uri (s->priv->uri);
333 static gulong
334 isymbol_get_line (IAnjutaSymbol *isymbol, GError **err)
336 SymbolDBEngineIteratorNode *s;
338 g_return_val_if_fail (SYMBOL_IS_DB_ENGINE_ITERATOR (isymbol), 0);
339 s = SYMBOL_DB_ENGINE_ITERATOR_NODE (isymbol);
340 return symbol_db_engine_iterator_node_get_symbol_file_pos (s);
343 static gboolean
344 isymbol_is_local (IAnjutaSymbol *isymbol, GError **err)
346 SymbolDBEngineIteratorNode *s;
348 g_return_val_if_fail (SYMBOL_IS_DB_ENGINE_ITERATOR (isymbol), FALSE);
349 s = SYMBOL_DB_ENGINE_ITERATOR_NODE (isymbol);
350 return symbol_db_engine_iterator_node_get_symbol_is_file_scope (s);
353 static const GdkPixbuf*
354 isymbol_get_icon (IAnjutaSymbol *isymbol, GError **err)
356 SymbolDBEngineIteratorNode *s;
358 g_return_val_if_fail (SYMBOL_IS_DB_ENGINE_ITERATOR (isymbol), FALSE);
359 s = SYMBOL_DB_ENGINE_ITERATOR_NODE (isymbol);
361 return symbol_db_view_get_pixbuf (
362 symbol_db_engine_iterator_node_get_symbol_extra_string (s,
363 SYMINFO_TYPE),
364 symbol_db_engine_iterator_node_get_symbol_extra_string (s,
365 SYMINFO_ACCESS));
368 static IAnjutaSymbolType
369 isymbol_get_sym_type (IAnjutaSymbol *isymbol, GError **err)
371 SymbolDBEngineIteratorNode *s;
372 SymbolDBEngineIteratorNodePriv *priv;
373 const gchar* type_str;
374 gint type;
376 g_return_val_if_fail (SYMBOL_IS_DB_ENGINE_ITERATOR (isymbol),
377 IANJUTA_SYMBOL_TYPE_UNDEF);
378 s = SYMBOL_DB_ENGINE_ITERATOR_NODE (isymbol);
380 priv = s->priv;
382 type_str = symbol_db_engine_iterator_node_get_symbol_extra_string (s,
383 IANJUTA_SYMBOL_FIELD_TYPE);
384 if (type_str == NULL)
385 return IANJUTA_SYMBOL_TYPE_UNDEF;
387 type = (IAnjutaSymbolType)g_hash_table_lookup ((GHashTable*)priv->sym_type_conversion_hash,
388 type_str);
390 return type;
393 static void
394 isymbol_iface_init (IAnjutaSymbolIface *iface)
396 iface->get_file = isymbol_get_file;
397 iface->get_name = isymbol_get_name;
398 iface->get_line = isymbol_get_line;
399 iface->get_sym_type = isymbol_get_sym_type;
400 iface->is_local = isymbol_is_local;
401 iface->get_args = isymbol_get_args;
402 iface->get_extra_info_string = isymbol_get_extra_info_string;
403 iface->get_icon = isymbol_get_icon;
406 ANJUTA_TYPE_BEGIN (SymbolDBEngineIteratorNode, sdb_engine_iterator_node, G_TYPE_OBJECT);
407 ANJUTA_TYPE_ADD_INTERFACE (isymbol, IANJUTA_TYPE_SYMBOL);
408 ANJUTA_TYPE_END;