[anjuta/system-db-refactor] language-support-cpp-java: Load files for packages asynchronous



commit 7784aa38364411b66ad37f2fbbe89e57e60ef3d2
Author: Johannes Schmid <jhs gnome org>
Date:   Mon Jan 31 00:04:51 2011 +0100

    language-support-cpp-java: Load files for packages asynchronous

 plugins/language-support-cpp-java/Makefile.am      |    4 +-
 .../cpp-package-scanner.c                          |  212 ++++++++++++++
 .../cpp-package-scanner.h                          |   62 +++++
 plugins/language-support-cpp-java/cpp-packages.c   |  290 ++++++++++++--------
 plugins/language-support-cpp-java/cpp-packages.h   |   69 ++++--
 plugins/language-support-cpp-java/plugin.c         |   13 +-
 plugins/language-support-cpp-java/plugin.h         |    4 +
 7 files changed, 515 insertions(+), 139 deletions(-)
---
diff --git a/plugins/language-support-cpp-java/Makefile.am b/plugins/language-support-cpp-java/Makefile.am
index 2d4fb7f..fe5024c 100644
--- a/plugins/language-support-cpp-java/Makefile.am
+++ b/plugins/language-support-cpp-java/Makefile.am
@@ -55,7 +55,9 @@ libanjuta_language_cpp_java_la_SOURCES = \
 	cpp-java-indentation.c \
 	cpp-java-indentation.h \
 	cpp-packages.c \
-	cpp-packages.h 
+	cpp-packages.h \
+	cpp-package-scanner.h \
+	cpp-package-scanner.c
 
 libanjuta_language_cpp_java_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
 
diff --git a/plugins/language-support-cpp-java/cpp-package-scanner.c b/plugins/language-support-cpp-java/cpp-package-scanner.c
new file mode 100644
index 0000000..cb10bd7
--- /dev/null
+++ b/plugins/language-support-cpp-java/cpp-package-scanner.c
@@ -0,0 +1,212 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * anjuta
+ * Copyright (C) Johannes Schmid 2011 <jhs Obelix>
+ * 
+ * anjuta 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 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * anjuta 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-package-scanner.h"
+#include <libanjuta/anjuta-utils.h>
+#include <libanjuta/anjuta-pkg-config.h>
+#include <gio/gio.h>
+
+enum
+{
+	PROP_0,
+	PROP_PACKAGE,
+	PROP_VERSION	
+};
+
+G_DEFINE_TYPE (CppPackageScanner, cpp_package_scanner, ANJUTA_TYPE_ASYNC_COMMAND);
+
+static void
+cpp_package_scanner_init (CppPackageScanner *object)
+{
+	object->files = NULL;
+}
+
+static void
+cpp_package_scanner_finalize (GObject *object)
+{
+	CppPackageScanner* scanner = CPP_PACKAGE_SCANNER (object);
+	g_free (scanner->package);
+	g_free (scanner->version);
+	anjuta_util_glist_strings_free (scanner->files);
+	
+	G_OBJECT_CLASS (cpp_package_scanner_parent_class)->finalize (object);
+}
+
+static void
+cpp_package_scanner_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+	CppPackageScanner* scanner;
+
+	g_return_if_fail (CPP_IS_PACKAGE_SCANNER (object));
+
+	scanner = CPP_PACKAGE_SCANNER(object);
+
+	switch (prop_id)
+	{
+	case PROP_PACKAGE:
+		scanner->package = g_value_dup_string (value);
+		break;
+	case PROP_VERSION:
+		scanner->version = g_value_dup_string (value);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+cpp_package_scanner_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+	CppPackageScanner* scanner;
+
+	g_return_if_fail (CPP_IS_PACKAGE_SCANNER (object));
+
+	scanner = CPP_PACKAGE_SCANNER(object);
+	
+	switch (prop_id)
+	{
+		case PROP_PACKAGE:
+			g_value_set_string (value, scanner->package);
+			break;
+		case PROP_VERSION:
+			g_value_set_string (value, scanner->version);
+			break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+cpp_package_scanner_list_files (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)
+			{
+				cpp_package_scanner_list_files (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 guint
+cpp_package_scanner_run (AnjutaCommand* command)
+{
+	CppPackageScanner* scanner = CPP_PACKAGE_SCANNER (command);
+	GList* dirs = anjuta_pkg_config_get_directories (scanner->package, TRUE, NULL);
+	GList* dir;
+
+	g_message ("Scanning package: %s", scanner->package);
+	
+	for (dir = dirs; dir != NULL; dir = g_list_next (dir))
+	{
+		GFile* file = g_file_new_for_path (dir->data);
+		cpp_package_scanner_list_files (&scanner->files, file);
+	}
+	anjuta_util_glist_strings_free (dirs);
+	return 0;
+}
+
+static void
+cpp_package_scanner_class_init (CppPackageScannerClass *klass)
+{
+	GObjectClass* object_class = G_OBJECT_CLASS (klass);
+	AnjutaCommandClass* command_class = ANJUTA_COMMAND_CLASS (klass);
+
+	object_class->finalize = cpp_package_scanner_finalize;
+	object_class->set_property = cpp_package_scanner_set_property;
+	object_class->get_property = cpp_package_scanner_get_property;
+
+	g_object_class_install_property (object_class,
+	                                 PROP_PACKAGE,
+	                                 g_param_spec_string ("package",
+	                                                      "package",
+	                                                      "Name of the package",
+	                                                      NULL, 
+	                                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+	g_object_class_install_property (object_class,
+	                                 PROP_VERSION,
+	                                 g_param_spec_string ("version",
+	                                                      "version",
+	                                                      "Version of the package",
+	                                                      NULL, 
+	                                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+
+	command_class->run = cpp_package_scanner_run;
+}
+
+
+AnjutaCommand*
+cpp_package_scanner_new (const gchar* package, const gchar* version)
+{
+	GObject* object =
+		g_object_new (CPP_TYPE_PACKAGE_SCANNER,
+		              "package", package,
+		              "version", version,
+		              NULL);
+
+	return ANJUTA_COMMAND (object);
+}
+
+const gchar* 
+cpp_package_scanner_get_package (CppPackageScanner* scanner)
+{
+	return scanner->package;
+}
+const gchar* 
+cpp_package_scanner_get_version (CppPackageScanner* scanner)
+{
+	return scanner->version;
+}
+
+GList*
+cpp_package_scanner_get_files (CppPackageScanner* scanner)
+{
+	return scanner->files;
+}
diff --git a/plugins/language-support-cpp-java/cpp-package-scanner.h b/plugins/language-support-cpp-java/cpp-package-scanner.h
new file mode 100644
index 0000000..62fa1b6
--- /dev/null
+++ b/plugins/language-support-cpp-java/cpp-package-scanner.h
@@ -0,0 +1,62 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
+/*
+ * anjuta
+ * Copyright (C) Johannes Schmid 2011 <jhs Obelix>
+ * 
+ * anjuta 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 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * anjuta 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_PACKAGE_SCANNER_H_
+#define _CPP_PACKAGE_SCANNER_H_
+
+#include <libanjuta/anjuta-async-command.h>
+
+G_BEGIN_DECLS
+
+#define CPP_TYPE_PACKAGE_SCANNER             (cpp_package_scanner_get_type ())
+#define CPP_PACKAGE_SCANNER(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), CPP_TYPE_PACKAGE_SCANNER, CppPackageScanner))
+#define CPP_PACKAGE_SCANNER_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), CPP_TYPE_PACKAGE_SCANNER, CppPackageScannerClass))
+#define CPP_IS_PACKAGE_SCANNER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CPP_TYPE_PACKAGE_SCANNER))
+#define CPP_IS_PACKAGE_SCANNER_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), CPP_TYPE_PACKAGE_SCANNER))
+#define CPP_PACKAGE_SCANNER_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), CPP_TYPE_PACKAGE_SCANNER, CppPackageScannerClass))
+
+typedef struct _CppPackageScannerClass CppPackageScannerClass;
+typedef struct _CppPackageScanner CppPackageScanner;
+
+struct _CppPackageScannerClass
+{
+	AnjutaAsyncCommandClass parent_class;
+
+};
+
+struct _CppPackageScanner
+{
+	AnjutaAsyncCommand parent_instance;
+
+	gchar* package;
+	gchar* version;
+	GList* files;
+
+};
+
+GType cpp_package_scanner_get_type (void) G_GNUC_CONST;
+AnjutaCommand* cpp_package_scanner_new (const gchar* package, const gchar* version);
+const gchar* cpp_package_scanner_get_package (CppPackageScanner* scanner);
+const gchar* cpp_package_scanner_get_version (CppPackageScanner* scanner);
+GList* cpp_package_scanner_get_files (CppPackageScanner* scanner);
+
+
+G_END_DECLS
+
+#endif /* _CPP_PACKAGE_SCANNER_H_ */
diff --git a/plugins/language-support-cpp-java/cpp-packages.c b/plugins/language-support-cpp-java/cpp-packages.c
index cf971be..4ec75ee 100644
--- a/plugins/language-support-cpp-java/cpp-packages.c
+++ b/plugins/language-support-cpp-java/cpp-packages.c
@@ -1,30 +1,36 @@
 /* -*- 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
+ * anjuta
+ * Copyright (C) Johannes Schmid 2011 <jhs Obelix>
+ * 
+ * anjuta 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 3 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/>.
+ * 
+ * anjuta 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 "cpp-package-scanner.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>
 
+enum
+{
+	PROP_0,
+	PROP_PLUGIN
+};
+
 typedef struct
 {
 	gchar* pkg;
@@ -47,156 +53,214 @@ pkg_data_free (PackageData* data)
 	g_free (data);
 }
 
-static void
-list_all_children (GList **children, GFile *dir)
+
+G_DEFINE_TYPE (CppPackages, cpp_packages, G_TYPE_OBJECT);
+
+static GList*
+cpp_packages_activate_package (IAnjutaSymbolManager* sm, const gchar* pkg,
+                               GList** packages_to_add)
 {
-	GFileEnumerator *list;
-					
-	list = g_file_enumerate_children (dir,
-	    G_FILE_ATTRIBUTE_STANDARD_NAME,
-	    G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
-	    NULL,
-	    NULL);
-
-	if (list != NULL)
+	gchar* name = g_strdup (pkg);
+	gchar* version;
+	gchar* c;
+
+	/* Clean package name */
+	for (c = name; *c != '\0'; c++)
 	{
-		GFileInfo *info;
-		
-		while ((info = g_file_enumerator_next_file (list, NULL, NULL)) != NULL)
+		if (g_ascii_isspace (*c))
 		{
-			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);
+			*c = '\0';
+			break;
 		}
-		g_file_enumerator_close (list, NULL, NULL);
-		g_object_unref (list);
 	}
-}
 
-static void
-cpp_packages_add_package (IAnjutaSymbolManager* sm,
-                          const gchar* pkg,
-                          const gchar* version)
-{
-	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))
+	version = anjuta_pkg_config_get_version (name);
+	if (!version)
 	{
-		GFile* file = g_file_new_for_path (dir->data);
-		list_all_children (&children, file);
+		g_free (name);
+		return *packages_to_add;
 	}
-	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 GList*
-cpp_packages_activate_package (IAnjutaSymbolManager* sm, const gchar* pkg, const gchar* version, 
-                               GList** packages_to_add)
-{
-	g_message ("Activate package: %s", pkg);
+	
 	/* Only query each package once */
 	if (g_list_find_custom (*packages_to_add,
-	                        pkg, (GCompareFunc) pkg_data_compare))
+	                        name, (GCompareFunc) pkg_data_compare))
 		return *packages_to_add;
-	if (!ianjuta_symbol_manager_activate_package (sm, pkg, version, NULL))
+	if (!ianjuta_symbol_manager_activate_package (sm, name, version, NULL))
 	{
-		GList* deps = anjuta_pkg_config_list_dependencies (pkg, NULL);
+		GList* deps = anjuta_pkg_config_list_dependencies (name, NULL);
 		GList* dep;
 		PackageData* data = g_new0 (PackageData, 1);
 		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, packages_to_add);
-			g_free (dep_version);
+			cpp_packages_activate_package (sm, dep->data, packages_to_add);
 		}
 		anjuta_util_glist_strings_free (deps);
-		data->pkg = g_strdup(pkg);
+		data->pkg = g_strdup (name);
 		data->version = g_strdup (version);
 		*packages_to_add = g_list_prepend (*packages_to_add,
 		                                   data);
 	}
+	g_free (name);
 	return *packages_to_add;
 }
 
 static void
-cpp_packages_load_real (AnjutaShell* shell, GError* error, IAnjutaProjectManager* pm)
+on_package_ready (AnjutaCommand* command,
+                  gint return_code,
+                  IAnjutaSymbolManager* sm)
+{
+	CppPackageScanner* scanner = CPP_PACKAGE_SCANNER (command);
+	if (g_list_length (cpp_package_scanner_get_files (scanner)))
+	{
+		g_message ("Adding package: %s", cpp_package_scanner_get_package (scanner));
+		ianjuta_symbol_manager_add_package (sm,
+		                                    cpp_package_scanner_get_package (scanner),
+		                                    cpp_package_scanner_get_version (scanner),
+		                                    cpp_package_scanner_get_files (scanner),
+		                                    NULL);
+	}
+	g_object_unref (command);
+}
+
+static void
+cpp_packages_load_real (CppPackages* packages, GError* error, IAnjutaProjectManager* pm)
 {
 	IAnjutaSymbolManager* sm =
-		anjuta_shell_get_interface (shell, IAnjutaSymbolManager, NULL);		
-	GList* packages;
+		anjuta_shell_get_interface (packages->plugin->shell, IAnjutaSymbolManager, NULL);		
+	GList* pkgs;
 	GList* pkg;
 	GList* packages_to_add = NULL;
-
-	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))
+	pkgs = ianjuta_project_manager_get_packages (pm, NULL);
+	for (pkg = pkgs; 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, &packages_to_add);
-		}
-		g_free (version);
+		cpp_packages_activate_package (sm, pkg->data, &packages_to_add);
 	}
-	g_list_free (packages);
+	g_list_free (pkgs);
 	for (pkg = packages_to_add; pkg != NULL; pkg = g_list_next (pkg))
 	{
 		PackageData* pkg_data = pkg->data;
-		cpp_packages_add_package (sm, pkg_data->pkg, pkg_data->version);
+		AnjutaCommand* command =
+			cpp_package_scanner_new (pkg_data->pkg, pkg_data->version);
+		g_signal_connect (command, "command-finished",
+		                  G_CALLBACK (on_package_ready), sm);
+		anjuta_command_queue_push (packages->queue, command);
 	}
 	g_list_foreach (packages_to_add, (GFunc) pkg_data_free, NULL);
 	g_list_free (packages_to_add);
+
+	anjuta_command_queue_start (packages->queue);
 }
 
 void 
-cpp_packages_load (CppJavaPlugin* plugin)
+cpp_packages_load (CppPackages* packages)
 {
-	static gboolean init = FALSE;
-	AnjutaShell* shell = ANJUTA_PLUGIN (plugin)->shell;
 	IAnjutaProjectManager* pm =
-		anjuta_shell_get_interface (shell, IAnjutaProjectManager, NULL);
+		anjuta_shell_get_interface (packages->plugin->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);
+	g_signal_connect_swapped (pm, "project-loaded", G_CALLBACK (cpp_packages_load_real), packages);
 
 	project = ianjuta_project_manager_get_current_project (pm, NULL);
+	/* Only load the packages if necessary */
 	if (project && ianjuta_project_is_loaded (project, NULL))
 	{
-		cpp_packages_load_real (shell, NULL, pm);
+		gboolean loaded = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (project), "__cpp_packages_loaded"));
+		if (!loaded)
+		{
+			cpp_packages_load_real (packages, NULL, pm);
+			g_object_set_data (G_OBJECT (project), "__cpp_packages_loaded", GINT_TO_POINTER (TRUE));
+		}
 	}		
 }
+
+static void
+cpp_packages_init (CppPackages *packages)
+{	
+	packages->queue = anjuta_command_queue_new (ANJUTA_COMMAND_QUEUE_EXECUTE_MANUAL);
+}
+
+static void
+cpp_packages_finalize (GObject* object)
+{
+	CppPackages *packages = CPP_PACKAGES (object);
+	AnjutaShell* shell = packages->plugin->shell;
+	IAnjutaProjectManager* pm =
+		anjuta_shell_get_interface (shell, IAnjutaProjectManager, NULL);
+	
+	g_object_unref (packages->queue);
+	g_signal_handlers_disconnect_by_func (pm, cpp_packages_load_real, packages);
+
+	G_OBJECT_CLASS (cpp_packages_parent_class)->finalize (object);
+}
+
+static void
+cpp_packages_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+	CppPackages* packages;
+	
+	g_return_if_fail (CPP_IS_PACKAGES (object));
+
+	packages = CPP_PACKAGES (object);
+	
+	switch (prop_id)
+	{
+	case PROP_PLUGIN:
+		packages->plugin = ANJUTA_PLUGIN (g_value_get_object (value));
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+cpp_packages_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+	CppPackages* packages;
+	
+	g_return_if_fail (CPP_IS_PACKAGES (object));
+
+	packages = CPP_PACKAGES (object);
+
+	switch (prop_id)
+	{
+	case PROP_PLUGIN:
+		g_value_set_object (value, G_OBJECT (packages->plugin));
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+cpp_packages_class_init (CppPackagesClass *klass)
+{
+	GObjectClass* object_class = G_OBJECT_CLASS (klass);
+
+	object_class->finalize = cpp_packages_finalize;
+	object_class->set_property = cpp_packages_set_property;
+	object_class->get_property = cpp_packages_get_property;
+
+	g_object_class_install_property (object_class,
+	                                 PROP_PLUGIN,
+	                                 g_param_spec_object ("plugin",
+	                                                      "CppJavaPlugin",
+	                                                      "CppJavaPlugin",
+	                                                      ANJUTA_TYPE_PLUGIN,
+	                                                      G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+}
+
+CppPackages*
+cpp_packages_new (AnjutaPlugin* plugin)
+{
+	GObject* object =
+		g_object_new (CPP_TYPE_PACKAGES, 
+		              "plugin", plugin,
+		              NULL);
+	return CPP_PACKAGES (object);
+}
diff --git a/plugins/language-support-cpp-java/cpp-packages.h b/plugins/language-support-cpp-java/cpp-packages.h
index b176b0c..84644bc 100644
--- a/plugins/language-support-cpp-java/cpp-packages.h
+++ b/plugins/language-support-cpp-java/cpp-packages.h
@@ -1,28 +1,57 @@
 /* -*- 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
+ * anjuta
+ * Copyright (C) Johannes Schmid 2011 <jhs Obelix>
+ * 
+ * anjuta 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 3 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/>.
+ * 
+ * anjuta 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
+#ifndef _CPP_PACKAGES_H_
+#define _CPP_PACKAGES_H_
 
-#include "plugin.h"
+#include <libanjuta/anjuta-command-queue.h>
+#include <libanjuta/anjuta-plugin.h>
 
-void cpp_packages_load (CppJavaPlugin* plugin);
+G_BEGIN_DECLS
 
-#endif
+#define CPP_TYPE_PACKAGES             (cpp_packages_get_type ())
+#define CPP_PACKAGES(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), CPP_TYPE_PACKAGES, CppPackages))
+#define CPP_PACKAGES_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), CPP_TYPE_PACKAGES, CppPackagesClass))
+#define CPP_IS_PACKAGES(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CPP_TYPE_PACKAGES))
+#define CPP_IS_PACKAGES_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), CPP_TYPE_PACKAGES))
+#define CPP_PACKAGES_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), CPP_TYPE_PACKAGES, CppPackagesClass))
+
+typedef struct _CppPackagesClass CppPackagesClass;
+typedef struct _CppPackages CppPackages;
+
+struct _CppPackagesClass
+{
+	GObjectClass parent_class;
+};
+
+struct _CppPackages
+{
+	GObject parent_instance;
+
+	AnjutaPlugin* plugin;
+	AnjutaCommandQueue* queue;
+};
+
+GType cpp_packages_get_type (void) G_GNUC_CONST;
+CppPackages* cpp_packages_new (AnjutaPlugin* plugin);
+void cpp_packages_load (CppPackages* packages);
+
+G_END_DECLS
+
+#endif /* _CPP_PACKAGES_H_ */
diff --git a/plugins/language-support-cpp-java/plugin.c b/plugins/language-support-cpp-java/plugin.c
index 3999693..33309d0 100644
--- a/plugins/language-support-cpp-java/plugin.c
+++ b/plugins/language-support-cpp-java/plugin.c
@@ -577,7 +577,10 @@ install_support (CppJavaPlugin *lang_plugin)
 			                  lang_plugin);
 		}
 	}	
-		
+
+	lang_plugin->packages = cpp_packages_new (ANJUTA_PLUGIN (lang_plugin));
+	cpp_packages_load (lang_plugin->packages);
+	
 	lang_plugin->support_installed = TRUE;
 }
 
@@ -614,8 +617,9 @@ uninstall_support (CppJavaPlugin *lang_plugin)
 	                                      on_glade_drop_possible, lang_plugin);
 	g_signal_handlers_disconnect_by_func (lang_plugin->current_editor,
 	                                      on_glade_drop, lang_plugin);
-	
-	
+
+	g_object_unref (lang_plugin->packages);
+	lang_plugin->packages = NULL;
 	lang_plugin->support_installed = FALSE;
 }
 
@@ -1033,8 +1037,6 @@ cpp_java_plugin_activate_plugin (AnjutaPlugin *plugin)
 								 on_value_removed_current_editor,
 								 plugin);
 
-	cpp_packages_load (lang_plugin);
-	
 	initialized = FALSE;
 	return TRUE;
 }
@@ -1091,6 +1093,7 @@ cpp_java_plugin_instance_init (GObject *obj)
 	plugin->uiid = 0;
 	plugin->assist = NULL;
 	plugin->settings = g_settings_new (PREF_SCHEMA);
+	plugin->packages = NULL;
 }
 
 static void
diff --git a/plugins/language-support-cpp-java/plugin.h b/plugins/language-support-cpp-java/plugin.h
index ed9ac3c..0060c5b 100644
--- a/plugins/language-support-cpp-java/plugin.h
+++ b/plugins/language-support-cpp-java/plugin.h
@@ -25,6 +25,7 @@
 #include <libanjuta/interfaces/ianjuta-editor.h>
 #include <libanjuta/interfaces/ianjuta-symbol-manager.h>
 #include "cpp-java-assist.h"
+#include "cpp-packages.h"
 
 extern GType cpp_java_plugin_get_type (GTypeModule *module);
 #define ANJUTA_TYPE_PLUGIN_CPP_JAVA         (cpp_java_plugin_get_type (NULL))
@@ -71,6 +72,9 @@ struct _CppJavaPlugin {
 	CppJavaAssist *assist;
 	CppFileType filetype;
 
+	/* Packages */
+	CppPackages* packages;
+
 	/* Preferences */
 	GtkBuilder* bxml;
 };



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