1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) Massimo Cora' 2007-2008 <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/anjuta-debug.h>
27 #include <libanjuta/resources.h>
28 #include "symbol-db-engine-utils.h"
29 #include "symbol-db-engine-priv.h"
31 static GHashTable
*pixbufs_hash
= NULL
;
36 extern GNUC_INLINE
const GdaStatement
*
37 sdb_engine_get_statement_by_query_id (SymbolDBEngine
* dbe
, static_query_type query_id
);
39 extern GNUC_INLINE
const GdaSet
*
40 sdb_engine_get_query_parameters_list (SymbolDBEngine
*dbe
, static_query_type query_id
);
43 * implementation starts here
47 symbol_db_glist_compare_func (gconstpointer a
, gconstpointer b
)
49 return g_strcmp0 ((const gchar
*)a
, (const gchar
*)b
);
53 symbol_db_gtree_compare_func (gconstpointer a
, gconstpointer b
, gpointer user_data
)
55 return GPOINTER_TO_INT(a
) - GPOINTER_TO_INT(b
);
59 symbol_db_util_get_full_local_path (SymbolDBEngine
*dbe
, const gchar
* file
)
61 SymbolDBEnginePriv
*priv
;
62 g_return_val_if_fail (dbe
!= NULL
, NULL
);
65 return g_build_filename (priv
->project_directory
, file
, NULL
);
69 symbol_db_util_get_file_db_path (SymbolDBEngine
*dbe
, const gchar
* full_local_file_path
)
71 SymbolDBEnginePriv
*priv
;
72 g_return_val_if_fail (dbe
!= NULL
, NULL
);
73 g_return_val_if_fail (full_local_file_path
!= NULL
, NULL
);
77 g_return_val_if_fail (priv
->project_directory
!= NULL
, NULL
);
79 if (priv
->db_directory
== NULL
||
80 strlen (priv
->project_directory
) >= strlen (full_local_file_path
))
85 return full_local_file_path
+ strlen (priv
->project_directory
);
89 symbol_db_util_get_files_with_zero_symbols (SymbolDBEngine
*dbe
)
91 SymbolDBEnginePriv
*priv
;
92 GdaDataModel
*data_model
;
93 GPtrArray
*files_to_scan
;
94 const GdaStatement
*stmt
;
97 g_return_val_if_fail (dbe
!= NULL
, NULL
);
102 if ((stmt
= sdb_engine_get_statement_by_query_id (dbe
,
103 PREP_QUERY_GET_ALL_FROM_FILE_WHERE_NOT_IN_SYMBOLS
))
110 data_model
= gda_connection_statement_execute_select (priv
->db_connection
,
114 if (!GDA_IS_DATA_MODEL (data_model
) ||
115 (num_rows
= gda_data_model_get_n_rows (GDA_DATA_MODEL (data_model
))) <= 0)
117 if (data_model
!= NULL
)
118 g_object_unref (data_model
);
123 /* initialize the array */
124 files_to_scan
= g_ptr_array_new_with_free_func (g_free
);
126 /* we can now scan each filename entry to check the last modification time. */
127 for (i
= 0; i
< num_rows
; i
++)
130 const gchar
*file_name
;
131 gchar
*file_abs_path
= NULL
;
134 gda_data_model_get_value_at (data_model
,
135 gda_data_model_get_column_index(data_model
, "db_file_path"),
141 /* build abs path. */
142 file_name
= g_value_get_string (value
);
143 file_abs_path
= symbol_db_util_get_full_local_path (dbe
, file_name
);
144 g_ptr_array_add (files_to_scan
, file_abs_path
);
147 g_object_unref (data_model
);
151 return files_to_scan
;
154 #define CREATE_SYM_ICON(N, F) \
155 pix_file = anjuta_res_get_pixmap_file (F); \
156 g_hash_table_insert (pixbufs_hash, \
158 gdk_pixbuf_new_from_file (pix_file, NULL)); \
162 sdb_util_load_symbol_pixbufs (void)
166 if (pixbufs_hash
!= NULL
)
168 /* we already have loaded it */
172 pixbufs_hash
= g_hash_table_new (g_str_hash
, g_str_equal
);
174 CREATE_SYM_ICON ("class", "element-class-16.png");
175 CREATE_SYM_ICON ("enum", "element-enumeration-16.png");
176 CREATE_SYM_ICON ("enumerator", "element-enumeration-16.png");
177 CREATE_SYM_ICON ("function", "element-method-16.png");
178 CREATE_SYM_ICON ("method", "element-method-16.png");
179 CREATE_SYM_ICON ("interface", "element-interface-16.png");
180 CREATE_SYM_ICON ("macro", "element-event-16.png");
181 CREATE_SYM_ICON ("namespace", "element-namespace-16.png");
182 CREATE_SYM_ICON ("none", "element-literal-16.png");
183 CREATE_SYM_ICON ("struct", "element-structure-16.png");
184 CREATE_SYM_ICON ("typedef", "element-literal-16.png");
185 CREATE_SYM_ICON ("union", "element-structure-16.png");
186 CREATE_SYM_ICON ("variable", "element-literal-16.png");
187 CREATE_SYM_ICON ("prototype", "element-interface-16.png");
189 CREATE_SYM_ICON ("privateclass", "element-class-16.png");
190 CREATE_SYM_ICON ("privateenum", "element-enumeration-16.png");
191 CREATE_SYM_ICON ("privatefield", "element-event-16.png");
192 CREATE_SYM_ICON ("privatefunction", "element-method-private-16.png");
193 CREATE_SYM_ICON ("privateinterface", "element-interface-private-16.png");
194 CREATE_SYM_ICON ("privatemember", "element-property-private-16.png");
195 CREATE_SYM_ICON ("privatemethod", "element-method-private-16.png");
196 CREATE_SYM_ICON ("privateproperty", "element-property-private-16.png");
197 CREATE_SYM_ICON ("privatestruct", "element-structure-16.png");
198 CREATE_SYM_ICON ("privateprototype", "element-interface-private-16.png");
200 CREATE_SYM_ICON ("protectedclass", "element-class-16.png");
201 CREATE_SYM_ICON ("protectedenum", "element-enumeration-16.png");
202 CREATE_SYM_ICON ("protectedfield", "element-event-16.png");
203 CREATE_SYM_ICON ("protectedfunction", "element-method-protected-16.png");
204 CREATE_SYM_ICON ("protectedmember", "element-property-protected-16.png");
205 CREATE_SYM_ICON ("protectedmethod", "element-method-protected-16.png");
206 CREATE_SYM_ICON ("protectedproperty", "element-property-protected-16.png");
207 CREATE_SYM_ICON ("protectedprototype","element-interface-protected-16.png");
209 CREATE_SYM_ICON ("publicclass", "element-class-16.png");
210 CREATE_SYM_ICON ("publicenum", "element-enumeration-16.png");
211 CREATE_SYM_ICON ("publicfunction", "element-method-public-16.png");
212 CREATE_SYM_ICON ("publicmember", "element-property-public-16.png");
213 CREATE_SYM_ICON ("publicmethod", "element-method-public-16.png");
214 CREATE_SYM_ICON ("publicproperty", "element-property-public-16.png");
215 CREATE_SYM_ICON ("publicstruct", "element-structure-16.png");
216 CREATE_SYM_ICON ("publicprototype", "element-interface-public-16.png");
219 CREATE_SYM_ICON ("othersvars", "element-event-16.png");
220 CREATE_SYM_ICON ("globalglobal", "element-event-16.png");
224 symbol_db_util_get_pixbuf (const gchar
*node_type
, const gchar
*node_access
)
231 sdb_util_load_symbol_pixbufs ();
234 /*DEBUG_PRINT ("symbol_db_view_get_pixbuf: node_type %s node_access %s",
235 node_type, node_access);*/
237 /* is there a better/quicker method to retrieve pixbufs? */
238 if (node_type
!= NULL
&& node_access
!= NULL
)
240 search_node
= g_strdup_printf ("%s%s", node_access
, node_type
);
242 else if (node_type
!= NULL
)
244 /* we will not free search_node gchar, so casting here is ok. */
245 search_node
= (gchar
*)node_type
;
248 search_node
= "othersvars";
250 pix
= GDK_PIXBUF (g_hash_table_lookup (pixbufs_hash
, search_node
));
252 if (node_type
!= NULL
&& node_access
!= NULL
)
254 g_free (search_node
);
259 DEBUG_PRINT ("symbol_db_view_get_pixbuf (): no pixbuf for %s %s",
260 node_type
, node_access
);