Updated Swedish translation
[anjuta.git] / plugins / symbol-db / symbol-db-engine-utils.c
blob68b3c856ac73b0ebc3667c625f246ab1a7fbc65c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * anjuta
4 * Copyright (C) Massimo Cora' 2007-2008 <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/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;
34 * extern declarations
36 extern const GdaStatement *
37 sdb_engine_get_statement_by_query_id (SymbolDBEngine * dbe, static_query_type query_id);
40 * implementation starts here
43 gint
44 symbol_db_glist_compare_func (gconstpointer a, gconstpointer b)
46 return g_strcmp0 ((const gchar*)a, (const gchar*)b);
49 gint
50 symbol_db_gtree_compare_func (gconstpointer a, gconstpointer b, gpointer user_data)
52 return GPOINTER_TO_INT(a) - GPOINTER_TO_INT(b);
55 gchar*
56 symbol_db_util_get_full_local_path (SymbolDBEngine *dbe, const gchar* file)
58 SymbolDBEnginePriv *priv;
59 g_return_val_if_fail (dbe != NULL, NULL);
61 priv = dbe->priv;
62 return g_build_filename (priv->project_directory, file, NULL);
65 const gchar*
66 symbol_db_util_get_file_db_path (SymbolDBEngine *dbe, const gchar* full_local_file_path)
68 SymbolDBEnginePriv *priv;
69 g_return_val_if_fail (dbe != NULL, NULL);
70 g_return_val_if_fail (full_local_file_path != NULL, NULL);
72 priv = dbe->priv;
74 g_return_val_if_fail (priv->project_directory != NULL, NULL);
76 if (priv->db_directory == NULL ||
77 strlen (priv->project_directory) >= strlen (full_local_file_path))
79 return NULL;
82 return full_local_file_path + strlen (priv->project_directory);
85 GPtrArray *
86 symbol_db_util_get_files_with_zero_symbols (SymbolDBEngine *dbe)
88 SymbolDBEnginePriv *priv;
89 GdaDataModel *data_model;
90 GPtrArray *files_to_scan;
91 const GdaStatement *stmt;
92 gint i, num_rows = 0;
94 g_return_val_if_fail (dbe != NULL, NULL);
95 priv = dbe->priv;
97 SDB_LOCK(priv);
99 if ((stmt = sdb_engine_get_statement_by_query_id (dbe,
100 PREP_QUERY_GET_ALL_FROM_FILE_WHERE_NOT_IN_SYMBOLS))
101 == NULL)
103 SDB_UNLOCK(priv);
104 return NULL;
107 data_model = gda_connection_statement_execute_select (priv->db_connection,
108 (GdaStatement*)stmt,
109 NULL, NULL);
111 if (!GDA_IS_DATA_MODEL (data_model) ||
112 (num_rows = gda_data_model_get_n_rows (GDA_DATA_MODEL (data_model))) <= 0)
114 if (data_model != NULL)
115 g_object_unref (data_model);
116 SDB_UNLOCK(priv);
117 return NULL;
120 /* initialize the array */
121 files_to_scan = g_ptr_array_new_with_free_func (g_free);
123 /* we can now scan each filename entry to check the last modification time. */
124 for (i = 0; i < num_rows; i++)
126 const GValue *value;
127 const gchar *file_name;
128 gchar *file_abs_path = NULL;
130 if ((value =
131 gda_data_model_get_value_at (data_model,
132 gda_data_model_get_column_index(data_model, "db_file_path"),
133 i, NULL)) == NULL)
135 continue;
138 /* build abs path. */
139 file_name = g_value_get_string (value);
140 file_abs_path = symbol_db_util_get_full_local_path (dbe, file_name);
141 g_ptr_array_add (files_to_scan, file_abs_path);
144 g_object_unref (data_model);
146 SDB_UNLOCK(priv);
148 return files_to_scan;
151 #define CREATE_SYM_ICON(N, F) \
152 pix_file = anjuta_res_get_pixmap_file (F); \
153 g_hash_table_insert (pixbufs_hash, \
154 N, \
155 gdk_pixbuf_new_from_file (pix_file, NULL)); \
156 g_free (pix_file);
158 static void
159 sdb_util_load_symbol_pixbufs (void)
161 gchar *pix_file;
163 if (pixbufs_hash != NULL)
165 /* we already have loaded it */
166 return;
169 pixbufs_hash = g_hash_table_new (g_str_hash, g_str_equal);
171 CREATE_SYM_ICON ("class", "element-class-16.png");
172 CREATE_SYM_ICON ("enum", "element-enumeration-16.png");
173 CREATE_SYM_ICON ("enumerator", "element-enumeration-16.png");
174 CREATE_SYM_ICON ("function", "element-method-16.png");
175 CREATE_SYM_ICON ("method", "element-method-16.png");
176 CREATE_SYM_ICON ("interface", "element-interface-16.png");
177 CREATE_SYM_ICON ("macro", "element-event-16.png");
178 CREATE_SYM_ICON ("namespace", "element-namespace-16.png");
179 CREATE_SYM_ICON ("none", "element-literal-16.png");
180 CREATE_SYM_ICON ("struct", "element-structure-16.png");
181 CREATE_SYM_ICON ("typedef", "element-literal-16.png");
182 CREATE_SYM_ICON ("union", "element-structure-16.png");
183 CREATE_SYM_ICON ("variable", "element-literal-16.png");
184 CREATE_SYM_ICON ("prototype", "element-interface-16.png");
186 CREATE_SYM_ICON ("privateclass", "element-class-16.png");
187 CREATE_SYM_ICON ("privateenum", "element-enumeration-16.png");
188 CREATE_SYM_ICON ("privatefield", "element-event-16.png");
189 CREATE_SYM_ICON ("privatefunction", "element-method-private-16.png");
190 CREATE_SYM_ICON ("privateinterface", "element-interface-private-16.png");
191 CREATE_SYM_ICON ("privatemember", "element-property-private-16.png");
192 CREATE_SYM_ICON ("privatemethod", "element-method-private-16.png");
193 CREATE_SYM_ICON ("privateproperty", "element-property-private-16.png");
194 CREATE_SYM_ICON ("privatestruct", "element-structure-16.png");
195 CREATE_SYM_ICON ("privateprototype", "element-interface-private-16.png");
197 CREATE_SYM_ICON ("protectedclass", "element-class-16.png");
198 CREATE_SYM_ICON ("protectedenum", "element-enumeration-16.png");
199 CREATE_SYM_ICON ("protectedfield", "element-event-16.png");
200 CREATE_SYM_ICON ("protectedfunction", "element-method-protected-16.png");
201 CREATE_SYM_ICON ("protectedmember", "element-property-protected-16.png");
202 CREATE_SYM_ICON ("protectedmethod", "element-method-protected-16.png");
203 CREATE_SYM_ICON ("protectedproperty", "element-property-protected-16.png");
204 CREATE_SYM_ICON ("protectedprototype","element-interface-protected-16.png");
206 CREATE_SYM_ICON ("publicclass", "element-class-16.png");
207 CREATE_SYM_ICON ("publicenum", "element-enumeration-16.png");
208 CREATE_SYM_ICON ("publicfunction", "element-method-public-16.png");
209 CREATE_SYM_ICON ("publicmember", "element-property-public-16.png");
210 CREATE_SYM_ICON ("publicmethod", "element-method-public-16.png");
211 CREATE_SYM_ICON ("publicproperty", "element-property-public-16.png");
212 CREATE_SYM_ICON ("publicstruct", "element-structure-16.png");
213 CREATE_SYM_ICON ("publicprototype", "element-interface-public-16.png");
215 /* special icon */
216 CREATE_SYM_ICON ("othersvars", "element-event-16.png");
217 CREATE_SYM_ICON ("globalglobal", "element-event-16.png");
220 const GdkPixbuf*
221 symbol_db_util_get_pixbuf (const gchar *node_type, const gchar *node_access)
223 gchar *search_node;
224 GdkPixbuf *pix;
225 if (!pixbufs_hash)
227 /* lazy loading */
228 sdb_util_load_symbol_pixbufs ();
231 /*DEBUG_PRINT ("symbol_db_view_get_pixbuf: node_type %s node_access %s",
232 node_type, node_access);*/
234 /* is there a better/quicker method to retrieve pixbufs? */
235 if (node_type != NULL && node_access != NULL)
237 search_node = g_strdup_printf ("%s%s", node_access, node_type);
239 else if (node_type != NULL)
241 /* we will not free search_node gchar, so casting here is ok. */
242 search_node = (gchar*)node_type;
244 else {
245 search_node = "othersvars";
247 pix = GDK_PIXBUF (g_hash_table_lookup (pixbufs_hash, search_node));
249 if (node_type != NULL && node_access != NULL)
251 g_free (search_node);
254 if (pix == NULL)
256 DEBUG_PRINT ("symbol_db_view_get_pixbuf (): no pixbuf for %s %s",
257 node_type, node_access);
260 return pix;