anjuta r4575 - in trunk: . plugins/symbol-db



Author: mcora
Date: Mon Jan 12 00:00:00 2009
New Revision: 4575
URL: http://svn.gnome.org/viewvc/anjuta?rev=4575&view=rev

Log:
	* plugins/symbol-db/plugin.c
	(on_editor_buffer_symbols_update_timeout),
	(do_check_languages_count), (on_project_root_added),
	(on_scan_end_manager):
	* plugins/symbol-db/symbol-db-engine-core.c (sdb_engine_init),
	(symbol_db_engine_remove_file):
	* plugins/symbol-db/symbol-db-engine-priv.h:
	* plugins/symbol-db/symbol-db-engine-queries.c
	(symbol_db_engine_get_languages_count),
	(symbol_db_engine_is_language_used):
	* plugins/symbol-db/symbol-db-engine-queries.h:
	fixed #548910. 
	Hide the Global tab in case only C-files are used in a project.
	Enable it instead with 2+ different languages.

Modified:
   trunk/ChangeLog
   trunk/plugins/symbol-db/plugin.c
   trunk/plugins/symbol-db/symbol-db-engine-core.c
   trunk/plugins/symbol-db/symbol-db-engine-priv.h
   trunk/plugins/symbol-db/symbol-db-engine-queries.c
   trunk/plugins/symbol-db/symbol-db-engine-queries.h

Modified: trunk/plugins/symbol-db/plugin.c
==============================================================================
--- trunk/plugins/symbol-db/plugin.c	(original)
+++ trunk/plugins/symbol-db/plugin.c	Mon Jan 12 00:00:00 2009
@@ -304,8 +304,7 @@
 		return TRUE;
 	
 	seconds_elapsed = g_timer_elapsed (sdb_plugin->update_timer, NULL);
-	
-	/* DEBUG_PRINT ("seconds_elapsed  %f", seconds_elapsed ); */
+
 	if (seconds_elapsed < TIMEOUT_SECONDS_AFTER_LAST_TIP)
 		return TRUE;
 		
@@ -1491,6 +1490,41 @@
 	}
 }
 
+/**
+ * Check the number of languages used by a project and then enable/disable the 
+ * global tab in case there's only C files.
+ */
+static void
+do_check_languages_count (SymbolDBPlugin *symbol_db)
+{
+	gint count;
+	
+	count = symbol_db_engine_get_languages_count (symbol_db->sdbe_project);
+	
+	/* is only C used? */
+	if (count == 1)
+	{
+		if (symbol_db_engine_is_language_used (symbol_db->sdbe_project, 
+											   "C") == TRUE)
+		{
+			/* hide the global tab and disable the receiving of signals */
+			symbol_db_view_recv_signals_from_engine (SYMBOL_DB_VIEW (
+													symbol_db->dbv_view_tree),
+													 symbol_db->sdbe_project,
+													 FALSE);
+			
+			gtk_widget_hide (symbol_db->scrolled_global);
+		}
+	}
+	else 
+	{
+			symbol_db_view_recv_signals_from_engine (SYMBOL_DB_VIEW (
+													 symbol_db->dbv_view_tree),
+													 symbol_db->sdbe_project,
+													 TRUE);
+			gtk_widget_show (symbol_db->scrolled_global);
+	}
+}
 
 static void
 do_check_offline_files_changed (SymbolDBPlugin *sdb_plugin)
@@ -1642,11 +1676,13 @@
 	IAnjutaProjectManager *pm;
 	SymbolDBPlugin *sdb_plugin;
 	const gchar *root_uri;
+	gchar *root_dir;
+	GFile *gfile;
 	
 	sdb_plugin = ANJUTA_PLUGIN_SYMBOL_DB (plugin);
 
 	/*
-	 * The Globals thing
+	 * The Global System symbols thing
 	 */
 
 	/* is the global db connected? */	
@@ -1669,7 +1705,7 @@
 	}
 	
 	
-	/* hide it. Default system tags thing: we'll import after abort even 
+	/* Hide the progress bar. Default system tags thing: we'll import after abort even 
 	 * if the preferences says not to automatically scan the packages.
 	 */
 	gtk_widget_hide (sdb_plugin->progress_bar_system);
@@ -1683,7 +1719,7 @@
 		/* we simulate a project-import-end signal received */
 		do_import_system_sources (sdb_plugin);		
 	}
-		
+	
 	
 	
 	/*
@@ -1694,124 +1730,127 @@
 		
 	g_free (sdb_plugin->project_root_uri);
 	sdb_plugin->project_root_uri = NULL;
-	root_uri = g_value_get_string (value);
-	
-	if (root_uri)
+	if ((root_uri = g_value_get_string (value)) == NULL)
 	{
-		gchar *root_dir;
-		GFile *gfile;
-		gfile = g_file_new_for_uri (root_uri);
+		DEBUG_PRINT ("Warning, root_uri for project is NULL");
+		return;
+	}
+
+	
+	gfile = g_file_new_for_uri (root_uri);
 		
-		root_dir = g_file_get_path (gfile);
-		DEBUG_PRINT ("Symbol-DB: added project root_dir %s, name %s", root_dir, 
-					 name);
+	root_dir = g_file_get_path (gfile);
+	DEBUG_PRINT ("Symbol-DB: added project root_dir %s, name %s", root_dir, 
+				 name);
 		
-		g_object_unref (gfile);
+	g_object_unref (gfile);
 		
-		/* FIXME: where's the project name itself? */
-		DEBUG_PRINT ("FIXME: where's the project name itself? ");
-		sdb_plugin->project_opened = g_strdup (root_dir);
-		
-		if (root_dir)
-		{
-			gboolean needs_sources_scan = FALSE;
-			gboolean project_exist = FALSE;
-			GHashTable* lang_hash;
-			guint id;
-				
-			lang_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, 
-											  sources_array_free);
+	/* FIXME: where's the project name itself? */
+	DEBUG_PRINT ("FIXME: where's the project name itself? using %s", root_dir);
+	sdb_plugin->project_opened = g_strdup (root_dir);
+	
+	if (root_dir)
+	{
+		gboolean needs_sources_scan = FALSE;
+		gboolean project_exist = FALSE;
+		GHashTable* lang_hash;
+		guint id;
+			
+		lang_hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, 
+										  sources_array_free);
 
-			/* is it a fresh-new project? is it an imported project with 
-			 * no 'new' symbol-db database but the 'old' one symbol-browser? 
-			 */
-			if (symbol_db_engine_db_exists (sdb_plugin->sdbe_project, 
-											root_dir) == FALSE)
-			{
-				DEBUG_PRINT ("%s", "Symbol-DB: project does not exist");
-				needs_sources_scan = TRUE;
-				project_exist = FALSE;
-			}
-			else 
-			{
-				project_exist = TRUE;
-			}
+		/* is it a fresh-new project? is it an imported project with 
+		 * no 'new' symbol-db database but the 'old' one symbol-browser? 
+		 */
+		if (symbol_db_engine_db_exists (sdb_plugin->sdbe_project, 
+										root_dir) == FALSE)
+		{
+			DEBUG_PRINT ("Project %s does not exist", root_dir);
+			needs_sources_scan = TRUE;
+			project_exist = FALSE;
+		}
+		else 
+		{
+			project_exist = TRUE;
+		}
 
-			/* we'll use the same values for db_directory and project_directory */
-			DEBUG_PRINT ("opening db %s and project_dir %s", root_dir, root_dir);
-			if (symbol_db_engine_open_db (sdb_plugin->sdbe_project, root_dir, 
+		/* we'll use the same values for db_directory and project_directory */
+		DEBUG_PRINT ("Opening db %s and project_dir %s", root_dir, root_dir);
+		if (symbol_db_engine_open_db (sdb_plugin->sdbe_project, root_dir, 
 										  root_dir) == FALSE)
-			{
-				g_error ("Symbol-DB: error in opening db");
-			}
-
-			/* if project did not exist add a new project */
-			if (project_exist == FALSE)
-			{
-				DEBUG_PRINT ("%s", "Symbol-DB: creating new project.");
-				symbol_db_engine_add_new_project (sdb_plugin->sdbe_project,
-												  NULL,	/* still no workspace logic */
-												  sdb_plugin->project_opened);
-			}
+		{
+			g_error ("*** Error in opening db ***");
+		}
+			
+		/* if project did not exist add a new project */
+		if (project_exist == FALSE)
+		{
+			DEBUG_PRINT ("Creating new project.");
+			symbol_db_engine_add_new_project (sdb_plugin->sdbe_project,
+											  NULL,	/* still no workspace logic */
+											  sdb_plugin->project_opened);
+		}
 
+		/*
+		 * we need an initial import 
+		 */
+		if (needs_sources_scan == TRUE)
+		{
+			DEBUG_PRINT ("Importing sources.");
+			do_import_project_sources (plugin, pm, root_dir);
+		}
+		else	
+		{
 			/*
-			 * we need an initial import 
-			 */
-			if (needs_sources_scan == TRUE)
-			{
-				DEBUG_PRINT ("%s", "Symbol-DB: importing sources...");
-				do_import_project_sources (plugin, pm, root_dir);
-			}
-			else	
-			{
-				/*
-				 * no import needed. But we may have aborted the scan of sources in 
-				 * a previous session..
-				 */				
-				GPtrArray *sources_array = NULL;				
+			 * no import needed. But we may have aborted the scan of sources in 
+			 * a previous session..
+			 */				
+			GPtrArray *sources_array = NULL;				
 				
-				sources_array = 
-					symbol_db_engine_get_files_with_zero_symbols (sdb_plugin->sdbe_project);
+			sources_array = 
+				symbol_db_engine_get_files_with_zero_symbols (sdb_plugin->sdbe_project);
 
-				if (sources_array != NULL && sources_array->len > 0) 
-				{				
-					do_import_project_sources_after_abort (plugin, sources_array);
-					
-					g_ptr_array_foreach (sources_array, (GFunc)g_free, NULL);
-					g_ptr_array_free (sources_array, TRUE);
-				}
+			if (sources_array != NULL && sources_array->len > 0) 
+			{				
+				do_import_project_sources_after_abort (plugin, sources_array);
 				
-				/* check for offline changes */				
-				do_check_offline_files_changed (sdb_plugin);								
-				
-				/* update any files of the project which isn't up-to-date */
-				do_update_project_symbols (sdb_plugin, root_dir);
+				g_ptr_array_foreach (sources_array, (GFunc)g_free, NULL);
+				g_ptr_array_free (sources_array, TRUE);
 			}
-			gtk_progress_bar_set_text (GTK_PROGRESS_BAR (sdb_plugin->progress_bar_project),
-									   _("Populating symbols' db..."));
-			id = g_idle_add ((GSourceFunc) gtk_progress_bar_pulse, 
-							 sdb_plugin->progress_bar_project);
-			gtk_widget_show (sdb_plugin->progress_bar_project);
-			
-			/* open symbol view, the global symbols gtktree */
-			symbol_db_view_open (SYMBOL_DB_VIEW (sdb_plugin->dbv_view_tree),
-								 sdb_plugin->sdbe_project);
-			g_source_remove (id);
-			gtk_widget_hide (sdb_plugin->progress_bar_project);
+				
+			/* check for offline changes */				
+			do_check_offline_files_changed (sdb_plugin);								
+				
+			/* update any files of the project which isn't up-to-date */
+			do_update_project_symbols (sdb_plugin, root_dir);
+		}
+		gtk_progress_bar_set_text (GTK_PROGRESS_BAR (sdb_plugin->progress_bar_project),
+								   _("Populating symbols' db..."));
+		id = g_idle_add ((GSourceFunc) gtk_progress_bar_pulse, 
+						 sdb_plugin->progress_bar_project);
+		gtk_widget_show (sdb_plugin->progress_bar_project);
+		
+		/* open symbol view, the global symbols gtktree */
+		symbol_db_view_open (SYMBOL_DB_VIEW (sdb_plugin->dbv_view_tree),
+							 sdb_plugin->sdbe_project);
+		g_source_remove (id);
+		gtk_widget_hide (sdb_plugin->progress_bar_project);
 
-			/* root dir */
-			sdb_plugin->project_root_dir = root_dir;
+		/* root dir */
+		sdb_plugin->project_root_dir = root_dir;
 			
-			g_hash_table_unref (lang_hash);			
-		}
-		/* this is uri */
-		sdb_plugin->project_root_uri = g_strdup (root_uri);
+		g_hash_table_unref (lang_hash);			
 	}
+	/* this is uri */
+	sdb_plugin->project_root_uri = g_strdup (root_uri);	
 
 	g_signal_connect (G_OBJECT (pm), "element_added",
 					  G_CALLBACK (on_project_element_added), sdb_plugin);
 	g_signal_connect (G_OBJECT (pm), "element_removed",
 					  G_CALLBACK (on_project_element_removed), sdb_plugin);
+
+	/* check for the number of languages used in the opened project. */
+	do_check_languages_count (sdb_plugin);
 }
 
 static void
@@ -1888,9 +1927,11 @@
 			gboolean parallel_scan = anjuta_preferences_get_int (symbol_db->prefs, 
 														 PARALLEL_SCAN); 
 			
+			do_check_languages_count (symbol_db);
+			
 			/* check the system population has a parallel fashion or not. */			 
 			if (parallel_scan == FALSE)
-				do_import_system_sources (symbol_db);
+				do_import_system_sources (symbol_db);			
 		}
 			break;			
 			
@@ -1902,11 +1943,13 @@
 		case TASK_ELEMENT_ADDED:
 			DEBUG_PRINT ("received TASK_ELEMENT_ADDED");
 			symbol_db->is_adding_element = FALSE;
+			do_check_languages_count (symbol_db);
 			break;
 			
 		case TASK_OFFLINE_CHANGES:		
 			DEBUG_PRINT ("received TASK_OFFLINE_CHANGES");
 			symbol_db->is_offline_scanning = FALSE;		
+			do_check_languages_count (symbol_db);
 			break;
 			
 		case TASK_PROJECT_UPDATE:		

Modified: trunk/plugins/symbol-db/symbol-db-engine-core.c
==============================================================================
--- trunk/plugins/symbol-db/symbol-db-engine-core.c	(original)
+++ trunk/plugins/symbol-db/symbol-db-engine-core.c	Mon Jan 12 00:00:00 2009
@@ -225,6 +225,11 @@
 									 	SymExtraInfo sym_info, gsize other_parameters,
 										const gchar *sql);
 
+inline gint
+sdb_engine_get_tuple_id_by_unique_name (SymbolDBEngine * dbe, static_query_type qtype,
+										gchar * param_key,
+										GValue * param_value);
+
 /*
  * implementation starts here 
  */
@@ -699,7 +704,7 @@
 /**
  * @return -1 on error. Otherwise the id of tuple.
  */
-static inline gint
+inline gint
 sdb_engine_get_tuple_id_by_unique_name (SymbolDBEngine * dbe, static_query_type qtype,
 										gchar * param_key,
 										GValue * param_value)
@@ -2054,6 +2059,10 @@
 									PREP_QUERY_GET_LANGUAGE_ID_BY_UNIQUE_NAME,
 	 	"SELECT language_id FROM language WHERE language_name = ## /* name:'langname' "
 	 	"type:gchararray */ LIMIT 1");
+
+	STATIC_QUERY_POPULATE_INIT_NODE(sdbe->priv->static_query_list, 
+									PREP_QUERY_GET_LANGUAGE_COUNT,
+	 	"SELECT COUNT(*) FROM language");	
 	
 	/* -- sym type -- */
 	STATIC_QUERY_POPULATE_INIT_NODE(sdbe->priv->static_query_list, 
@@ -5682,7 +5691,7 @@
 		return FALSE;
 	}
 	
-	DEBUG_PRINT ("deleting %s", abs_file);
+	DEBUG_PRINT ("deleting from db %s", abs_file);
 	
 	if ((stmt = sdb_engine_get_statement_by_query_id (dbe, 
 									PREP_QUERY_REMOVE_FILE_BY_PROJECT_NAME)) == NULL)

Modified: trunk/plugins/symbol-db/symbol-db-engine-priv.h
==============================================================================
--- trunk/plugins/symbol-db/symbol-db-engine-priv.h	(original)
+++ trunk/plugins/symbol-db/symbol-db-engine-priv.h	Mon Jan 12 00:00:00 2009
@@ -123,6 +123,7 @@
 	PREP_QUERY_GET_ALL_FROM_FILE_WHERE_NOT_IN_SYMBOLS,
 	PREP_QUERY_LANGUAGE_NEW,
 	PREP_QUERY_GET_LANGUAGE_ID_BY_UNIQUE_NAME,
+	PREP_QUERY_GET_LANGUAGE_COUNT,
 	PREP_QUERY_SYM_TYPE_NEW,
 	PREP_QUERY_GET_SYM_TYPE_ID,	
 	PREP_QUERY_SYM_KIND_NEW,

Modified: trunk/plugins/symbol-db/symbol-db-engine-queries.c
==============================================================================
--- trunk/plugins/symbol-db/symbol-db-engine-queries.c	(original)
+++ trunk/plugins/symbol-db/symbol-db-engine-queries.c	Mon Jan 12 00:00:00 2009
@@ -46,6 +46,11 @@
 sdb_engine_insert_dyn_query_node_by_id (SymbolDBEngine *dbe, dyn_query_type query_id,
 									 	SymExtraInfo sym_info, gsize other_parameters,
 										const gchar *sql);
+extern inline gint
+sdb_engine_get_tuple_id_by_unique_name (SymbolDBEngine * dbe, static_query_type qtype,
+										gchar * param_key,
+										GValue * param_value);
+
 
 /*
  * implementation starts here 
@@ -2631,3 +2636,84 @@
 												priv->sym_type_conversion_hash,
 												priv->project_directory);	
 }
+
+gint
+symbol_db_engine_get_languages_count (SymbolDBEngine *dbe)
+{
+	SymbolDBEnginePriv *priv;
+	GdaDataModel *data_model;	
+	const GdaStatement *stmt;
+	const GValue *value;
+	gint num_rows = 0;
+	gint ret = -1;
+
+	g_return_val_if_fail (dbe != NULL, -1);
+	priv = dbe->priv;
+	
+	if (priv->mutex)
+		g_mutex_lock (priv->mutex);	
+	
+	if ((stmt = sdb_engine_get_statement_by_query_id (dbe,
+								 PREP_QUERY_GET_LANGUAGE_COUNT))
+		== NULL)
+	{
+		if (priv->mutex)
+			g_mutex_unlock (priv->mutex);
+		return -1;
+	}
+
+	data_model = gda_connection_statement_execute_select (priv->db_connection, 
+														  (GdaStatement*)stmt, 
+														  NULL, NULL);
+	
+	if (!GDA_IS_DATA_MODEL (data_model) ||
+		(num_rows = gda_data_model_get_n_rows (GDA_DATA_MODEL (data_model))) <= 0)
+	{
+		if (data_model != NULL)
+			g_object_unref (data_model);
+		if (priv->mutex)
+			g_mutex_unlock (priv->mutex);
+		return -1;
+	}	
+	
+	if ((value = gda_data_model_get_value_at (data_model, 0, 0, NULL)) != NULL)
+	{
+		ret = g_value_get_int (value);
+	}
+
+	if (data_model)
+		g_object_unref (data_model);
+	
+	if (priv->mutex)
+		g_mutex_unlock (priv->mutex);
+	
+	return ret;	
+}
+
+gboolean
+symbol_db_engine_is_language_used (SymbolDBEngine *dbe,
+								   const gchar *language)
+{
+	gint table_id;
+	GValue *value;
+	SymbolDBEnginePriv *priv;		
+	
+	g_return_val_if_fail (language != NULL, FALSE);
+	
+	priv = dbe->priv;
+
+	MP_LEND_OBJ_STR(priv, value);
+	g_value_set_static_string (value, language);
+
+	/* check for an already existing table with language "name". */
+	if ((table_id = sdb_engine_get_tuple_id_by_unique_name (dbe,
+						PREP_QUERY_GET_LANGUAGE_ID_BY_UNIQUE_NAME,
+						"langname",
+						value)) < 0)
+	{
+		return FALSE;
+	}
+	
+	return TRUE;
+}
+

Modified: trunk/plugins/symbol-db/symbol-db-engine-queries.h
==============================================================================
--- trunk/plugins/symbol-db/symbol-db-engine-queries.h	(original)
+++ trunk/plugins/symbol-db/symbol-db-engine-queries.h	Mon Jan 12 00:00:00 2009
@@ -190,7 +190,7 @@
 									SymExtraInfo sym_info);
 
 /**
- * Gets the files of a project.
+ * Get the files of a project.
  * @param project_name name of project you want to know the files of.
  *        It can be NULL. In that case all the files will be returned.
  */
@@ -198,4 +198,21 @@
 symbol_db_engine_get_files_for_project (SymbolDBEngine *dbe, 
 									const gchar *project_name,
 								 	SymExtraInfo sym_info);
+
+/**
+ * Get the number of languages used in a project.
+ *
+ * @return number of different languages used in the opened project. -1 on error.
+ */
+gint
+symbol_db_engine_get_languages_count (SymbolDBEngine *dbe);
+
+/**
+ *
+ * @return true if the language is used in the opened project.
+ */
+gboolean
+symbol_db_engine_is_language_used (SymbolDBEngine *dbe,
+								   const gchar *language);
+
 #endif



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