[anjuta/system-db-refactor: 11/12] language-support-cpp-java: Initial (sync) version of package querying



commit 6787a13123c63dc36c53cbdd03de9a44bb718173
Author: Johannes Schmid <jhs gnome org>
Date:   Thu Jan 27 00:20:18 2011 +0100

    language-support-cpp-java: Initial (sync) version of package querying

 plugins/language-support-cpp-java/Makefile.am    |    4 +-
 plugins/language-support-cpp-java/cpp-packages.c |  155 ++++++++++++++++++++++
 plugins/language-support-cpp-java/cpp-packages.h |   28 ++++
 plugins/language-support-cpp-java/plugin.c       |    4 +
 4 files changed, 190 insertions(+), 1 deletions(-)
---
diff --git a/plugins/language-support-cpp-java/Makefile.am b/plugins/language-support-cpp-java/Makefile.am
index fe7eb86..2d4fb7f 100644
--- a/plugins/language-support-cpp-java/Makefile.am
+++ b/plugins/language-support-cpp-java/Makefile.am
@@ -53,7 +53,9 @@ libanjuta_language_cpp_java_la_SOURCES = \
 	cpp-java-utils.c \
 	cpp-java-utils.h \
 	cpp-java-indentation.c \
-	cpp-java-indentation.h 
+	cpp-java-indentation.h \
+	cpp-packages.c \
+	cpp-packages.h 
 
 libanjuta_language_cpp_java_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
 
diff --git a/plugins/language-support-cpp-java/cpp-packages.c b/plugins/language-support-cpp-java/cpp-packages.c
new file mode 100644
index 0000000..4768a9f
--- /dev/null
+++ b/plugins/language-support-cpp-java/cpp-packages.c
@@ -0,0 +1,155 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * cpp-packages.c
+ *
+ * Copyright (C) 2011 - Johannes Schmid
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "cpp-packages.h"
+
+#include <libanjuta/interfaces/ianjuta-project-manager.h>
+#include <libanjuta/interfaces/ianjuta-symbol-manager.h>
+#include <libanjuta/anjuta-pkg-config.h>
+#include <libanjuta/anjuta-debug.h>
+
+static void
+list_all_children (GList **children, GFile *dir)
+{
+	GFileEnumerator *list;
+					
+	list = g_file_enumerate_children (dir,
+	    G_FILE_ATTRIBUTE_STANDARD_NAME,
+	    G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+	    NULL,
+	    NULL);
+
+	if (list != NULL)
+	{
+		GFileInfo *info;
+		
+		while ((info = g_file_enumerator_next_file (list, NULL, NULL)) != NULL)
+		{
+			const gchar *name;
+			GFile *file;
+
+			name = g_file_info_get_name (info);
+			file = g_file_get_child (dir, name);
+			g_object_unref (info);
+
+			if (g_file_query_file_type (file, G_FILE_QUERY_INFO_NONE, NULL) == G_FILE_TYPE_DIRECTORY)
+			{
+				list_all_children (children, file);
+			}
+			else
+			{
+				gchar* filename = g_file_get_path (file);
+				*children = g_list_prepend (*children, filename);
+			}
+			g_object_unref (file);
+		}
+		g_file_enumerator_close (list, NULL, NULL);
+		g_object_unref (list);
+	}
+}
+
+static void
+cpp_packages_activate_package (IAnjutaSymbolManager* sm, const gchar* pkg, const gchar* version)
+{
+	g_message ("Activate package: %s", pkg);
+	if (!ianjuta_symbol_manager_activate_package (sm, pkg, version, NULL))
+	{
+		GList* deps = anjuta_pkg_config_list_dependencies (pkg, NULL);
+		GList* dep;
+		for (dep = deps; dep != NULL; dep = g_list_next (dep))
+		{
+			g_message ("Adding dependency: %s", dep->data);
+			gchar* dep_version =
+				anjuta_pkg_config_get_version (dep->data);
+			if (dep_version)
+				cpp_packages_activate_package (sm, dep->data, dep_version);
+			g_free (dep_version);
+		}
+		anjuta_util_glist_strings_free (deps);
+		GList* dirs = anjuta_pkg_config_get_directories (pkg, TRUE, NULL);
+		GList* dir;
+		GList* children = NULL;
+		for (dir = dirs; dir != NULL; dir = g_list_next (dir))
+		{
+			GFile* file = g_file_new_for_path (dir->data);
+			list_all_children (&children, file);
+		}
+		g_message ("Adding package: %s", pkg);
+		if (children)
+			ianjuta_symbol_manager_add_package (sm, pkg, version, children, NULL);
+		anjuta_util_glist_strings_free (children);
+		anjuta_util_glist_strings_free (dirs);
+	}
+	
+}
+
+static void
+cpp_packages_load_real (AnjutaShell* shell, GError* error, IAnjutaProjectManager* pm)
+{
+	IAnjutaSymbolManager* sm =
+		anjuta_shell_get_interface (shell, IAnjutaSymbolManager, NULL);		
+	GList* packages;
+	GList* pkg;
+
+	g_message ("Project loaded");
+	
+	if (!pm || !sm)
+		return;
+	
+	packages = ianjuta_project_manager_get_packages (pm, NULL);
+	for (pkg = packages; pkg != NULL; pkg = g_list_next (pkg))
+	{
+		gchar* version =
+			anjuta_pkg_config_get_version (pkg->data);
+		if (version)
+		{
+			cpp_packages_activate_package (sm, pkg->data, version);
+		}
+		g_free (version);
+	}
+	g_list_free (packages);
+}
+
+void 
+cpp_packages_load (CppJavaPlugin* plugin)
+{
+	static gboolean init = FALSE;
+	AnjutaShell* shell = ANJUTA_PLUGIN (plugin)->shell;
+	IAnjutaProjectManager* pm =
+		anjuta_shell_get_interface (shell, IAnjutaProjectManager, NULL);
+	IAnjutaProject* project;
+
+	if (init)
+		return;
+	init = TRUE;
+	
+	if (!pm)
+		return;
+
+	g_message ("Connecting signal");
+	
+	g_signal_connect_swapped (pm, "project-loaded", G_CALLBACK (cpp_packages_load_real), shell);
+
+	project = ianjuta_project_manager_get_current_project (pm, NULL);
+	if (project && ianjuta_project_is_loaded (project, NULL))
+	{
+		cpp_packages_load_real (shell, NULL, pm);
+	}		
+}
diff --git a/plugins/language-support-cpp-java/cpp-packages.h b/plugins/language-support-cpp-java/cpp-packages.h
new file mode 100644
index 0000000..b176b0c
--- /dev/null
+++ b/plugins/language-support-cpp-java/cpp-packages.h
@@ -0,0 +1,28 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * cpp-packages.h
+ *
+ * Copyright (C) 2011 - Johannes Schmid
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CPP_PACKAGES_H
+#define CPP_PACKAGES_H
+
+#include "plugin.h"
+
+void cpp_packages_load (CppJavaPlugin* plugin);
+
+#endif
diff --git a/plugins/language-support-cpp-java/plugin.c b/plugins/language-support-cpp-java/plugin.c
index cd01287..3999693 100644
--- a/plugins/language-support-cpp-java/plugin.c
+++ b/plugins/language-support-cpp-java/plugin.c
@@ -42,6 +42,7 @@
 #include "plugin.h"
 #include "cpp-java-utils.h"
 #include "cpp-java-indentation.h"
+#include "cpp-packages.h"
 
 /* Pixmaps */
 #define ANJUTA_PIXMAP_SWAP                "anjuta-swap"
@@ -1031,6 +1032,9 @@ cpp_java_plugin_activate_plugin (AnjutaPlugin *plugin)
 								 on_value_added_current_editor,
 								 on_value_removed_current_editor,
 								 plugin);
+
+	cpp_packages_load (lang_plugin);
+	
 	initialized = FALSE;
 	return TRUE;
 }



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