1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) Massimo Cora' 2007 <maxcvs@email.it>
6 * anjuta is free software.
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)
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
;
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
;
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
;
68 sdb_engine_iterator_node_finalize (GObject
*object
)
70 SymbolDBEngineIteratorNode
*dbin
;
71 SymbolDBEngineIteratorNodePriv
*priv
;
73 dbin
= SYMBOL_DB_ENGINE_ITERATOR_NODE (object
);
80 G_OBJECT_CLASS (parent_class
)->finalize (object
);
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
;
93 * Symbol name must be always on column 0
96 symbol_db_engine_iterator_node_get_symbol_id (SymbolDBEngineIteratorNode
*dbin
)
98 SymbolDBEngineIteratorNodePriv
*priv
;
101 g_return_val_if_fail (dbin
!= NULL
, -1);
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
114 symbol_db_engine_iterator_node_get_symbol_name (SymbolDBEngineIteratorNode
*dbin
)
116 SymbolDBEngineIteratorNodePriv
*priv
;
119 g_return_val_if_fail (dbin
!= NULL
, NULL
);
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
132 symbol_db_engine_iterator_node_get_symbol_file_pos (SymbolDBEngineIteratorNode
*dbin
)
134 SymbolDBEngineIteratorNodePriv
*priv
;
137 g_return_val_if_fail (dbin
!= NULL
, -1);
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
150 symbol_db_engine_iterator_node_get_symbol_is_file_scope (SymbolDBEngineIteratorNode
*dbin
)
152 SymbolDBEngineIteratorNodePriv
*priv
;
155 g_return_val_if_fail (dbin
!= NULL
, FALSE
);
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
;
167 * Signature must be always on column 4
170 symbol_db_engine_iterator_node_get_symbol_signature (SymbolDBEngineIteratorNode
*dbin
)
172 SymbolDBEngineIteratorNodePriv
*priv
;
175 g_return_val_if_fail (dbin
!= NULL
, NULL
);
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
;
185 symbol_db_engine_iterator_node_get_symbol_extra_string (SymbolDBEngineIteratorNode
*dbin
,
188 SymbolDBEngineIteratorNodePriv
*priv
;
189 const GValue
*value
= NULL
;
191 g_return_val_if_fail (dbin
!= NULL
, NULL
);
194 if (sym_info
& SYMINFO_FILE_PATH
)
196 value
= gda_data_model_iter_get_value_for_field (priv
->data_iter
,
199 else if (sym_info
& SYMINFO_LANGUAGE
)
201 value
= gda_data_model_iter_get_value_for_field (priv
->data_iter
,
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
,
214 else if (sym_info
& SYMINFO_KIND
)
216 value
= gda_data_model_iter_get_value_for_field (priv
->data_iter
,
219 else if (sym_info
& SYMINFO_TYPE
)
221 value
= gda_data_model_iter_get_value_for_field (priv
->data_iter
,
224 else if (sym_info
& SYMINFO_TYPE_NAME
)
226 value
= gda_data_model_iter_get_value_for_field (priv
->data_iter
,
229 else if (sym_info
& SYMINFO_PROJECT_NAME
)
231 value
= gda_data_model_iter_get_value_for_field (priv
->data_iter
,
234 else if (sym_info
& SYMINFO_FILE_IGNORE
)
236 value
= gda_data_model_iter_get_value_for_field (priv
->data_iter
,
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
;
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
;
259 priv
->sym_type_conversion_hash
= sym_type_conversion_hash
;
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
;
272 priv
->data_iter
= GDA_DATA_MODEL_ITER (data
);
273 if (priv
->uri
!= NULL
)
280 /* IAnjutaSymbol implementation */
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
);
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
);
303 isymbol_get_extra_info_string (IAnjutaSymbol
*isymbol
, IAnjutaSymbolField sym_info
,
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
);
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
;
324 file_path
= symbol_db_engine_iterator_node_get_symbol_extra_string (s
,
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
);
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
);
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
,
364 symbol_db_engine_iterator_node_get_symbol_extra_string (s
,
368 static IAnjutaSymbolType
369 isymbol_get_sym_type (IAnjutaSymbol
*isymbol
, GError
**err
)
371 SymbolDBEngineIteratorNode
*s
;
372 SymbolDBEngineIteratorNodePriv
*priv
;
373 const gchar
* type_str
;
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
);
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
,
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
);