[anjuta/cxxparser] symbol-db: renamed function symbol_db_engine_add_new_files () to _full ()



commit b14e1869987168c70a99ffaa48f8b347e5f9e33b
Author: Massimo Corà <mcora src gnome org>
Date:   Mon Jul 27 00:18:32 2009 +0200

    symbol-db: renamed function symbol_db_engine_add_new_files () to _full ()
    
    Created a new, yet untested, symbol_db_engine_add_new_files () which should take care of
    creating a GPtrArray of languages, given a IAnjutaLanguage instance.

 plugins/symbol-db/benchmark/benchmark.c   |    2 +-
 plugins/symbol-db/plugin.c                |    6 +-
 plugins/symbol-db/symbol-db-engine-core.c |   74 ++++++++++++++++++++++++++++-
 plugins/symbol-db/symbol-db-engine-core.h |   26 ++++++++--
 plugins/symbol-db/symbol-db-system.c      |    2 +-
 5 files changed, 99 insertions(+), 11 deletions(-)
---
diff --git a/plugins/symbol-db/benchmark/benchmark.c b/plugins/symbol-db/benchmark/benchmark.c
index 2d1dcc5..5f6804a 100644
--- a/plugins/symbol-db/benchmark/benchmark.c
+++ b/plugins/symbol-db/benchmark/benchmark.c
@@ -57,7 +57,7 @@ int main (int argc, char** argv)
 	g_signal_connect (G_OBJECT (engine), "single-file-scan-end",
 		  G_CALLBACK (on_single_file_scan_end), files);
 	
-	symbol_db_engine_add_new_files (engine, root_dir, files, languages, TRUE);	
+	symbol_db_engine_add_new_files_full (engine, root_dir, files, languages, TRUE);	
 	
 	gtk_main();
 	
diff --git a/plugins/symbol-db/plugin.c b/plugins/symbol-db/plugin.c
index feb92d2..4910205 100644
--- a/plugins/symbol-db/plugin.c
+++ b/plugins/symbol-db/plugin.c
@@ -959,7 +959,7 @@ do_add_new_files (SymbolDBPlugin *sdb_plugin, const GPtrArray *sources_array,
 			continue;
 		
 		gfile_info = g_file_query_info (gfile, 
-										"*", 
+										"standard::content-type", 
 										G_FILE_QUERY_INFO_NONE,
 										NULL,
 										NULL);
@@ -1011,7 +1011,7 @@ do_add_new_files (SymbolDBPlugin *sdb_plugin, const GPtrArray *sources_array,
 		/* ok, we've just tested that the local_filename does exist.
 		 * We can safely add it to the array.
 		 */
-		g_ptr_array_add (languages_array, g_strdup (lang));					
+		g_ptr_array_add (languages_array, g_strdup (lang));
 		g_ptr_array_add (to_scan_array, g_strdup (local_filename));
 		g_object_unref (gfile);
 		g_object_unref (gfile_info);		
@@ -1022,7 +1022,7 @@ do_add_new_files (SymbolDBPlugin *sdb_plugin, const GPtrArray *sources_array,
 	 */
 	if (to_scan_array->len > 0)
 	{		
-		gint proc_id = 	symbol_db_engine_add_new_files (sdb_plugin->sdbe_project, 
+		gint proc_id = 	symbol_db_engine_add_new_files_full (sdb_plugin->sdbe_project, 
 					sdb_plugin->project_opened, to_scan_array, languages_array, 
 														   TRUE);
 		
diff --git a/plugins/symbol-db/symbol-db-engine-core.c b/plugins/symbol-db/symbol-db-engine-core.c
index 281903e..46b3feb 100644
--- a/plugins/symbol-db/symbol-db-engine-core.c
+++ b/plugins/symbol-db/symbol-db-engine-core.c
@@ -3571,9 +3571,81 @@ sdb_engine_get_unique_scan_id (SymbolDBEngine * dbe)
 	SDB_UNLOCK(priv);
 	return ret_id;
 }
+
+/* !!!! FIXME: not yet tested !!!! */
+gint
+symbol_db_engine_add_new_files (SymbolDBEngine *dbe, 
+    							IAnjutaLanguage* lang_manager,
+								const gchar * project_name,
+							    const GPtrArray *sources_array)
+{
+	SymbolDBEnginePriv *priv;
+	GPtrArray *lang_array;
+	gint i;
 	
+	g_return_val_if_fail (dbe != NULL, FALSE);	
+	g_return_val_if_fail (lang_manager != NULL, FALSE);	
+	g_return_val_if_fail (sources_array != NULL, FALSE);
+
+	priv = dbe->priv;
+
+	lang_array = g_ptr_array_new ();
+
+	for (i = 0; i < sources_array->len; i++)
+	{		
+		IAnjutaLanguageId lang_id;
+		GFile *gfile;
+		GFileInfo *gfile_info;	
+		const gchar *file_mime;
+		const gchar *lang;
+		const gchar *local_filename;
+		
+		local_filename = g_ptr_array_index (sources_array, i);			
+		gfile = g_file_new_for_path (local_filename);		
+		gfile_info = g_file_query_info (gfile, 
+										"standard::content-type", 
+										G_FILE_QUERY_INFO_NONE,
+										NULL,
+										NULL);
+		if (gfile_info == NULL)
+		{
+			g_warning ("GFileInfo corresponding to %s was NULL", local_filename);
+			g_object_unref (gfile);
+			continue;
+		}
+		
+		file_mime = g_file_info_get_attribute_string (gfile_info,
+										  G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);										  		
+					
+		lang_id = ianjuta_language_get_from_mime_type (lang_manager, 
+													 file_mime, NULL);
+					
+		if (!lang_id)
+		{
+			g_warning ("Language not found for %s was NULL", local_filename);
+			g_object_unref (gfile);
+			g_object_unref (gfile_info);			
+			continue;
+		}
+				
+		lang = ianjuta_language_get_name (lang_manager, lang_id, NULL);	
+		g_ptr_array_add (lang_array, g_strdup (lang));
+		g_object_unref (gfile);
+		g_object_unref (gfile_info);
+	}
+
+	gint res = symbol_db_engine_add_new_files_full (dbe, project_name, sources_array,
+	    lang_array, TRUE);
+
+	/* free resources */
+	g_ptr_array_foreach (lang_array, (GFunc)g_free, NULL);
+	g_ptr_array_free (lang_array, TRUE);
+
+	return res;
+}
+
 gint
-symbol_db_engine_add_new_files (SymbolDBEngine * dbe, 
+symbol_db_engine_add_new_files_full (SymbolDBEngine * dbe, 
 								const gchar * project_name,
 								const GPtrArray * files_path, 
 								const GPtrArray * languages,
diff --git a/plugins/symbol-db/symbol-db-engine-core.h b/plugins/symbol-db/symbol-db-engine-core.h
index 1043a62..d27ae33 100644
--- a/plugins/symbol-db/symbol-db-engine-core.h
+++ b/plugins/symbol-db/symbol-db-engine-core.h
@@ -28,6 +28,7 @@
 #include <glib-object.h>
 #include <glib.h>
 #include <libanjuta/interfaces/ianjuta-symbol.h>
+#include <libanjuta/interfaces/ianjuta-language.h>
 #include <libanjuta/anjuta-plugin.h>
 #include "symbol-db-engine-iterator.h"
 
@@ -163,8 +164,9 @@ symbol_db_engine_project_exists (SymbolDBEngine *dbe, /*gchar* workspace, */
 /** 
  * Add a group of files of a single language to a project. It will perform also 
  * a symbols scannig/populating of db if scan_symbols is TRUE.
- * This function requires an opened db, i.e. calling before
- * symbol_db_engine_open_db ().
+ * This function requires an opened db, i.e. You must call 
+ * symbol_db_engine_open_db () before.
+ * 
  * @note if some file fails to enter the db the function will return without
  * processing the remaining files.
  * @param project_name something like 'foo_project', or 'helloworld_project'. Can be NULL,
@@ -190,11 +192,25 @@ symbol_db_engine_project_exists (SymbolDBEngine *dbe, /*gchar* workspace, */
  * @return scan process id if insertion is successful, -1 on error.
  */
 gint
+symbol_db_engine_add_new_files_full (SymbolDBEngine *dbe, 
+									const gchar * project_name,
+							    	const GPtrArray *files_path,
+									const GPtrArray *languages,
+									gboolean force_scan);
+
+/**
+ * See symbol_db_engine_add_new_files_full () for doc.
+ * This function adds files to db in a quicker way than 
+ * symbol_db_engine_add_new_files_full because you won't have to specify the
+ * GPtrArray of languages, but it'll try to autodetect them.
+ * When added, the files are forced to be scanned.
+ */
+/* !!!! FIXME: not yet tested !!!! */
+gint
 symbol_db_engine_add_new_files (SymbolDBEngine *dbe, 
+    							IAnjutaLanguage* lang_manager,
 								const gchar * project_name,
-							    const GPtrArray *files_path,
-								const GPtrArray *languages,
-								gboolean force_scan);
+							    const GPtrArray *files_path);
 
 /**
  * Update symbols of the whole project. It scans all file symbols etc. 
diff --git a/plugins/symbol-db/symbol-db-system.c b/plugins/symbol-db/symbol-db-system.c
index b2f6981..df094d9 100644
--- a/plugins/symbol-db/symbol-db-system.c
+++ b/plugins/symbol-db/symbol-db-system.c
@@ -513,7 +513,7 @@ sdb_system_do_engine_scan (SymbolDBSystem *sdbs, EngineScanData *es_data)
 	 * infact to have more references of the same files in different
 	 * packages
 	 */
-	proc_id = symbol_db_engine_add_new_files (priv->sdbe_globals,
+	proc_id = symbol_db_engine_add_new_files_full (priv->sdbe_globals,
 							es_data->special_abort_scan == FALSE ? 
 									es_data->package_name : NULL, 
 							files_to_scan_array,



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