anjuta r4481 - in trunk: . plugins/class-gen plugins/project-wizard
- From: sgranjoux svn gnome org
- To: svn-commits-list gnome org
- Subject: anjuta r4481 - in trunk: . plugins/class-gen plugins/project-wizard
- Date: Wed, 24 Dec 2008 18:06:10 +0000 (UTC)
Author: sgranjoux
Date: Wed Dec 24 18:06:10 2008
New Revision: 4481
URL: http://svn.gnome.org/viewvc/anjuta?rev=4481&view=rev
Log:
* plugins/project-wizard/plugin.c,
plugins/project-wizard/plugin.h,
plugins/project-wizard/values.c,
plugins/project-wizard/values.h,
plugins/project-wizard/parser.c,
plugins/project-wizard/parser.h,
plugins/project-wizard/autogen.c,
plugins/project-wizard/autogen.h,
plugins/project-wizard/install.c,
plugins/project-wizard/install.h,
plugins/project-wizard/druid.c,
plugins/project-wizard/action.c,
plugins/project-wizard/action.h,
plugins/project-wizard/file.c,
plugins/project-wizard/file.h,
plugins/project-wizard/property.c,
plugins/project-wizard/property.h,
plugins/project-wizard/header.c,
plugins/project-wizard/header.h,
plugins/project-wizard/Makefile.am,
plugins/class-gen/plugin.c,
plugins/class-gen/window.c,
plugins/class-gen/window.h,
plugins/class-gen/element-editor.c,
plugins/class-gen/element-editor.h,
plugins/class-gen/generator.c,
plugins/class-gen/generator.h:
Bug #560857 - Remove deprecated GLib symbols in project wizard
Modified:
trunk/ChangeLog
trunk/plugins/class-gen/element-editor.c
trunk/plugins/class-gen/element-editor.h
trunk/plugins/class-gen/generator.c
trunk/plugins/class-gen/generator.h
trunk/plugins/class-gen/plugin.c
trunk/plugins/class-gen/window.c
trunk/plugins/class-gen/window.h
trunk/plugins/project-wizard/Makefile.am
trunk/plugins/project-wizard/action.c
trunk/plugins/project-wizard/action.h
trunk/plugins/project-wizard/autogen.c
trunk/plugins/project-wizard/autogen.h
trunk/plugins/project-wizard/druid.c
trunk/plugins/project-wizard/file.c
trunk/plugins/project-wizard/file.h
trunk/plugins/project-wizard/header.c
trunk/plugins/project-wizard/header.h
trunk/plugins/project-wizard/install.c
trunk/plugins/project-wizard/install.h
trunk/plugins/project-wizard/parser.c
trunk/plugins/project-wizard/parser.h
trunk/plugins/project-wizard/plugin.c
trunk/plugins/project-wizard/plugin.h
trunk/plugins/project-wizard/property.c
trunk/plugins/project-wizard/property.h
trunk/plugins/project-wizard/values.c
trunk/plugins/project-wizard/values.h
Modified: trunk/plugins/class-gen/element-editor.c
==============================================================================
--- trunk/plugins/class-gen/element-editor.c (original)
+++ trunk/plugins/class-gen/element-editor.c Wed Dec 24 18:06:10 2008
@@ -750,7 +750,7 @@
static void
cg_element_editor_set_valuesv (CgElementEditor *editor,
const gchar *name,
- NPWValueHeap *values,
+ GHashTable *values,
CgElementEditorTransformFunc func,
gpointer user_data,
const gchar **field_names)
@@ -798,7 +798,7 @@
value = npw_value_heap_find_value (values, value_name);
- npw_value_heap_set_value (values, value, value_str->str,
+ npw_value_set_value (value, value_str->str,
NPW_VALID_VALUE);
g_string_set_size (value_str, 0);
@@ -813,7 +813,7 @@
void
cg_element_editor_set_values (CgElementEditor *editor,
const gchar *name,
- NPWValueHeap *values,
+ GHashTable *values,
CgElementEditorTransformFunc func,
gpointer user_data,
...)
@@ -841,7 +841,7 @@
void
cg_element_editor_set_value_count (CgElementEditor *editor,
const gchar *name,
- NPWValueHeap *values,
+ GHashTable *values,
CgElementEditorConditionFunc func,
gpointer user_data)
{
@@ -881,5 +881,5 @@
sprintf (count_str, "%u", count);
value = npw_value_heap_find_value (values, name);
- npw_value_heap_set_value (values, value, count_str, NPW_VALID_VALUE);
+ npw_value_set_value (value, count_str, NPW_VALID_VALUE);
}
Modified: trunk/plugins/class-gen/element-editor.h
==============================================================================
--- trunk/plugins/class-gen/element-editor.h (original)
+++ trunk/plugins/class-gen/element-editor.h Wed Dec 24 18:06:10 2008
@@ -80,7 +80,7 @@
* eventually. */
void cg_element_editor_set_values (CgElementEditor *editor,
const gchar *name,
- NPWValueHeap *values,
+ GHashTable *values,
CgElementEditorTransformFunc func,
gpointer user_data,
...);
@@ -89,7 +89,7 @@
void cg_element_editor_set_value_count (CgElementEditor *editor,
const gchar *name,
- NPWValueHeap *values,
+ GHashTable *values,
CgElementEditorConditionFunc func,
gpointer user_data);
Modified: trunk/plugins/class-gen/generator.c
==============================================================================
--- trunk/plugins/class-gen/generator.c (original)
+++ trunk/plugins/class-gen/generator.c Wed Dec 24 18:06:10 2008
@@ -388,7 +388,7 @@
gboolean
cg_generator_run (CgGenerator *generator,
- NPWValueHeap *values,
+ GHashTable *values,
GError **error)
{
CgGeneratorPrivate *priv;
Modified: trunk/plugins/class-gen/generator.h
==============================================================================
--- trunk/plugins/class-gen/generator.h (original)
+++ trunk/plugins/class-gen/generator.h Wed Dec 24 18:06:10 2008
@@ -63,7 +63,7 @@
const gchar *header_destination,
const gchar *source_destination);
gboolean cg_generator_run (CgGenerator *generator,
- NPWValueHeap *values,
+ GHashTable *values,
GError **error);
const gchar *cg_generator_get_header_template (CgGenerator *generator);
Modified: trunk/plugins/class-gen/plugin.c
==============================================================================
--- trunk/plugins/class-gen/plugin.c (original)
+++ trunk/plugins/class-gen/plugin.c Wed Dec 24 18:06:10 2008
@@ -359,7 +359,7 @@
{
AnjutaClassGenPlugin *plugin;
IAnjutaProjectManager *manager;
- NPWValueHeap *values;
+ GHashTable *values;
NPWValue *value;
GError *error;
gchar *name;
@@ -402,7 +402,7 @@
/* Use basename of the project's root URI as project name. */
name = g_path_get_basename (plugin->top_dir);
value = npw_value_heap_find_value (values, "ProjectName");
- npw_value_heap_set_value (values, value, name, NPW_VALID_VALUE);
+ npw_value_set_value (value, name, NPW_VALID_VALUE);
g_free (name);
}
else
@@ -410,7 +410,7 @@
name = g_path_get_basename (cg_window_get_source_file(
plugin->window));
value = npw_value_heap_find_value (values, "ProjectName");
- npw_value_heap_set_value (values, value, name, NPW_VALID_VALUE);
+ npw_value_set_value (value, name, NPW_VALID_VALUE);
g_free (name);
}
Modified: trunk/plugins/class-gen/window.c
==============================================================================
--- trunk/plugins/class-gen/window.c (original)
+++ trunk/plugins/class-gen/window.c Wed Dec 24 18:06:10 2008
@@ -225,7 +225,7 @@
static void
cg_window_set_heap_value (CgWindow *window,
- NPWValueHeap *values,
+ GHashTable *values,
GType type,
const gchar *name,
const gchar *id)
@@ -242,16 +242,16 @@
{
case G_TYPE_STRING:
text = cg_window_fetch_string (window, id);
- npw_value_heap_set_value (values, value, text, NPW_VALID_VALUE);
+ npw_value_set_value (value, text, NPW_VALID_VALUE);
g_free (text);
break;
case G_TYPE_INT:
int_value = cg_window_fetch_integer (window, id);
sprintf (int_buffer, "%d", int_value);
- npw_value_heap_set_value (values, value, int_buffer, NPW_VALID_VALUE);
+ npw_value_set_value (value, int_buffer, NPW_VALID_VALUE);
break;
case G_TYPE_BOOLEAN:
- npw_value_heap_set_value (values, value,
+ npw_value_set_value (value,
cg_window_fetch_boolean (window, id) ? "1" : "0", NPW_VALID_VALUE);
break;
@@ -865,7 +865,7 @@
return GTK_DIALOG (CG_WINDOW_PRIVATE (window)->window);
}
-NPWValueHeap *
+GHashTable *
cg_window_create_value_heap (CgWindow *window)
{
static const gchar *LICENSES[] = {
@@ -875,7 +875,7 @@
};
CgWindowPrivate *priv;
- NPWValueHeap *values;
+ GHashTable *values;
NPWValue *value;
GError *error;
gint license_index;
@@ -934,10 +934,10 @@
g_free (text);
value = npw_value_heap_find_value (values, "BaseTypePrefix");
- npw_value_heap_set_value (values, value, base_prefix, NPW_VALID_VALUE);
+ npw_value_set_value (value, base_prefix, NPW_VALID_VALUE);
value = npw_value_heap_find_value (values, "BaseTypeSuffix");
- npw_value_heap_set_value (values, value, base_suffix, NPW_VALID_VALUE);
+ npw_value_set_value (value, base_suffix, NPW_VALID_VALUE);
g_free (base_prefix);
g_free (base_suffix);
@@ -1002,17 +1002,17 @@
license_index = cg_window_fetch_integer (window, "license");
value = npw_value_heap_find_value (values, "License");
- npw_value_heap_set_value(values, value, LICENSES[license_index],
+ npw_value_set_value(value, LICENSES[license_index],
NPW_VALID_VALUE);
header_file = g_path_get_basename (cg_window_get_header_file (window));
source_file = g_path_get_basename (cg_window_get_source_file (window));
value = npw_value_heap_find_value (values, "HeaderFile");
- npw_value_heap_set_value (values, value, header_file, NPW_VALID_VALUE);
+ npw_value_set_value (value, header_file, NPW_VALID_VALUE);
value = npw_value_heap_find_value (values, "SourceFile");
- npw_value_heap_set_value (values, value, source_file, NPW_VALID_VALUE);
+ npw_value_set_value (value, source_file, NPW_VALID_VALUE);
g_free (header_file);
g_free (source_file);
Modified: trunk/plugins/class-gen/window.h
==============================================================================
--- trunk/plugins/class-gen/window.h (original)
+++ trunk/plugins/class-gen/window.h Wed Dec 24 18:06:10 2008
@@ -55,7 +55,7 @@
CgWindow *cg_window_new (void);
GtkDialog *cg_window_get_dialog (CgWindow *window);
-NPWValueHeap *cg_window_create_value_heap (CgWindow *window);
+GHashTable *cg_window_create_value_heap (CgWindow *window);
const gchar *cg_window_get_header_template (CgWindow *window);
const gchar *cg_window_get_header_file (CgWindow *window);
Modified: trunk/plugins/project-wizard/Makefile.am
==============================================================================
--- trunk/plugins/project-wizard/Makefile.am (original)
+++ trunk/plugins/project-wizard/Makefile.am Wed Dec 24 18:06:10 2008
@@ -30,7 +30,8 @@
AM_CPPFLAGS = \
$(WARN_CFLAGS) \
$(DEPRECATED_FLAGS) \
- $(LIBANJUTA_CFLAGS)
+ $(LIBANJUTA_CFLAGS) \
+ -DG_LOG_DOMAIN=\"libanjuta-project-wizard\"
libanjuta_project_wizard_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS)
Modified: trunk/plugins/project-wizard/action.c
==============================================================================
--- trunk/plugins/project-wizard/action.c (original)
+++ trunk/plugins/project-wizard/action.c Wed Dec 24 18:06:10 2008
@@ -20,39 +20,17 @@
/*
* Actions data read in .wiz file
- *
- * It's just a list containing all data
*---------------------------------------------------------------------------*/
#include <config.h>
#include "action.h"
-#include <glib.h>
-
-/*---------------------------------------------------------------------------*/
-
-#define STRING_CHUNK_SIZE 256
-
/*---------------------------------------------------------------------------*/
-/* List containing all actions. It includes chunk for strings and actions
- * object, so memory allocation is handled by the list itself */
-
-struct _NPWActionList
-{
- GList* list;
- GStringChunk* string_pool;
- GMemChunk* data_pool;
-};
-
-/* Action object, it includes a pointer on its owner to allocate new data */
-
struct _NPWAction {
NPWActionType type;
gchar* command;
- NPWActionList* owner;
- GList* node;
};
/* Action object
@@ -60,97 +38,54 @@
*---------------------------------------------------------------------------*/
NPWAction*
-npw_action_new (NPWActionList* owner, NPWActionType type)
+npw_action_new_file (const gchar *file)
{
- NPWAction* this;
+ NPWAction* action;
- g_return_val_if_fail (owner != NULL, NULL);
+ g_return_val_if_fail (file != NULL, NULL);
- this = g_chunk_new0(NPWAction, owner->data_pool);
- this->type = type;
- this->owner = owner;
- owner->list = g_list_append (owner->list, this);
- this->node = g_list_last (owner->list);
-
- return this;
-}
+ action = g_slice_new (NPWAction);
+ action->type = NPW_OPEN_ACTION;
+ action->command = g_strdup (file);
-void
-npw_action_free (NPWAction* this)
-{
- /* Memory allocated in string pool and project pool is not free */
+ return action;
}
-NPWActionType
-npw_action_get_type (const NPWAction* this)
+NPWAction*
+npw_action_new_command (const gchar *command)
{
- return this->type;
-}
+ NPWAction* action;
-void
-npw_action_set_command (NPWAction* this, const gchar* command)
-{
- this->command = g_string_chunk_insert (this->owner->string_pool, command);
-}
+ g_return_val_if_fail (command != NULL, NULL);
+
+ action = g_slice_new (NPWAction);
+ action->type = NPW_RUN_ACTION;
+ action->command = g_strdup (command);
-const gchar*
-npw_action_get_command (const NPWAction* this)
-{
- return this->command;
+ return action;
}
void
-npw_action_set_file (NPWAction* this, const gchar* file)
-{
- npw_action_set_command (this, file);
-}
-
-const gchar*
-npw_action_get_file (const NPWAction* this)
+npw_action_free (NPWAction* action)
{
- return npw_action_get_command (this);
+ g_free (action->command);
+ g_slice_free (NPWAction, action);
}
-const NPWAction*
-npw_action_next (const NPWAction* this)
-{
- GList* node = this->node->next;
-
- return node == NULL ? NULL : (NPWAction *)node->data;
-}
-
-
-/* Action list object
- *---------------------------------------------------------------------------*/
-
-NPWActionList*
-npw_action_list_new (void)
+NPWActionType
+npw_action_get_type (const NPWAction* action)
{
- NPWActionList* this;
-
- this = g_new (NPWActionList, 1);
- this->string_pool = g_string_chunk_new (STRING_CHUNK_SIZE);
- this->data_pool = g_mem_chunk_new ("action pool", sizeof (NPWAction), STRING_CHUNK_SIZE * sizeof (NPWAction) / 4, G_ALLOC_ONLY);
- this->list = NULL;
-
- return this;
+ return action->type;
}
-void
-npw_action_list_free (NPWActionList* this)
+const gchar*
+npw_action_get_command (const NPWAction* action)
{
- g_return_if_fail (this != NULL);
-
- g_string_chunk_free (this->string_pool);
- g_mem_chunk_destroy (this->data_pool);
- g_list_free (this->list);
- g_free (this);
+ return action->command;
}
-const NPWAction*
-npw_action_list_first (const NPWActionList* this)
+const gchar*
+npw_action_get_file (const NPWAction* action)
{
- GList* node = g_list_first (this->list);
-
- return node == NULL ? NULL : (NPWAction *)node->data;
+ return action->command;
}
Modified: trunk/plugins/project-wizard/action.h
==============================================================================
--- trunk/plugins/project-wizard/action.h (original)
+++ trunk/plugins/project-wizard/action.h Wed Dec 24 18:06:10 2008
@@ -24,30 +24,19 @@
#include <glib.h>
typedef struct _NPWAction NPWAction;
-typedef struct _NPWActionList NPWActionList;
typedef enum {
NPW_RUN_ACTION,
NPW_OPEN_ACTION
} NPWActionType;
-NPWAction* npw_action_new (NPWActionList* owner, NPWActionType type);
-void npw_action_free (NPWAction* this);
+NPWAction* npw_action_new_file (const gchar *file);
+NPWAction* npw_action_new_command (const gchar *command);
-NPWActionType npw_action_get_type (const NPWAction* this);
+void npw_action_free (NPWAction* action);
-void npw_action_set_command (NPWAction* this, const gchar* command);
-const gchar* npw_action_get_command (const NPWAction* this);
-
-void npw_action_set_file (NPWAction* this, const gchar* command);
-const gchar* npw_action_get_file (const NPWAction* this);
-
-const NPWAction* npw_action_next (const NPWAction* this);
-
-
-NPWActionList* npw_action_list_new (void);
-void npw_action_list_free (NPWActionList* this);
-
-const NPWAction* npw_action_list_first (const NPWActionList* this);
+NPWActionType npw_action_get_type (const NPWAction* action);
+const gchar* npw_action_get_command (const NPWAction* action);
+const gchar* npw_action_get_file (const NPWAction* action);
#endif
Modified: trunk/plugins/project-wizard/autogen.c
==============================================================================
--- trunk/plugins/project-wizard/autogen.c (original)
+++ trunk/plugins/project-wizard/autogen.c Wed Dec 24 18:06:10 2008
@@ -117,19 +117,19 @@
*---------------------------------------------------------------------------*/
static void
-cb_autogen_write_definition (const gchar* name, const gchar* value, NPWValueTag tag, gpointer user_data)
+cb_autogen_write_definition (const gchar* name, NPWValue * node, gpointer user_data)
{
FILE* def = (FILE *)user_data;
- if ((tag & NPW_VALID_VALUE) && (value != NULL))
+ if ((npw_value_get_tag(node) & NPW_VALID_VALUE) && (npw_value_get_value(node) != NULL))
{
- if(value[0] == '{') /* Seems to be a list, so do not quote */
+ if(npw_value_get_value (node)[0] == '{') /* Seems to be a list, so do not quote */
{
- fprintf(def, "%s = %s;\n", name, value);
+ fprintf(def, "%s = %s;\n", name, npw_value_get_value (node));
}
else
{
- gchar *esc_value = g_strescape (value, NULL);
+ gchar *esc_value = g_strescape (npw_value_get_value (node), NULL);
fprintf (def, "%s = \"%s\";\n", name, esc_value);
g_free (esc_value);
}
@@ -137,7 +137,7 @@
}
gboolean
-npw_autogen_write_definition_file (NPWAutogen* this, NPWValueHeap* values)
+npw_autogen_write_definition_file (NPWAutogen* this, GHashTable* values)
{
FILE* def;
@@ -149,7 +149,7 @@
/* Generate definition data for autogen */
fputs ("AutoGen Definitions .;\n",def);
- npw_value_heap_foreach_value (values, cb_autogen_write_definition, def);
+ npw_value_heap_foreach_value (values, (GHFunc)cb_autogen_write_definition, def);
fclose (def);
Modified: trunk/plugins/project-wizard/autogen.h
==============================================================================
--- trunk/plugins/project-wizard/autogen.h (original)
+++ trunk/plugins/project-wizard/autogen.h Wed Dec 24 18:06:10 2008
@@ -34,7 +34,7 @@
NPWAutogen* npw_autogen_new (void);
void npw_autogen_free (NPWAutogen* this);
-gboolean npw_autogen_write_definition_file (NPWAutogen* this, NPWValueHeap* values);
+gboolean npw_autogen_write_definition_file (NPWAutogen* this, GHashTable* values);
gboolean npw_autogen_set_input_file (NPWAutogen* this, const gchar* filename, const gchar* start_marker, const gchar* end_marker);
gboolean npw_autogen_set_output_file (NPWAutogen* this, const gchar* filename);
Modified: trunk/plugins/project-wizard/druid.c
==============================================================================
--- trunk/plugins/project-wizard/druid.c (original)
+++ trunk/plugins/project-wizard/druid.c Wed Dec 24 18:06:10 2008
@@ -93,7 +93,7 @@
{
GtkWidget* dialog;
GtkNotebook* project_book;
- GMemChunk* pool;
+ GList *stuff_list;
GnomeDruid* druid;
const gchar* project_file;
GnomeDruidPage* selection_page;
@@ -106,9 +106,9 @@
guint page;
GQueue* page_list;
- NPWValueHeap* values;
+ GHashTable* values;
NPWPageParser* parser;
- NPWHeaderList* header_list;
+ GList* header_list;
NPWHeader* header;
NPWAutogen* gen;
gboolean busy;
@@ -185,7 +185,7 @@
for (i = 0; (page = g_queue_peek_nth (this->page_list, i)) != NULL; ++i)
{
- npw_page_foreach_property (page, cb_druid_add_summary_property, text);
+ npw_page_foreach_property (page, (GFunc)cb_druid_add_summary_property, text);
}
gnome_druid_page_edge_set_text (GNOME_DRUID_PAGE_EDGE (this->finish_page), text->str);
@@ -230,10 +230,11 @@
/* Add a project in the icon list */
static void
-cb_druid_insert_project_icon (NPWHeader* header, gpointer user_data)
+cb_druid_insert_project_icon (gpointer data, gpointer user_data)
{
- gint idx;
+ NPWHeader *header = (NPWHeader *)data;
GnomeIconList* list = GNOME_ICON_LIST (user_data);
+ gint idx;
idx = gnome_icon_list_append (list, npw_header_get_iconfile (header), _(npw_header_get_name (header)));
gnome_icon_list_set_icon_data (list, idx, header);
@@ -241,7 +242,7 @@
/* Add a page in the project notebook */
static void
-cb_druid_insert_project_page (NPWHeader* header, gpointer user_data)
+cb_druid_insert_project_page (gpointer value, gpointer user_data)
{
NPWDruid* this = (NPWDruid*)user_data;
GladeXML* xml;
@@ -249,11 +250,12 @@
GtkWidget* frame;
GnomeIconList* list;
GtkLabel* desc;
+ GList *template_list = (GList *)value;
const gchar* category;
NPWDruidAndTextBuffer* data;
- category = npw_header_get_category(header);
-
+ category = npw_header_get_category ((NPWHeader *)template_list->data);
+
/* Create new frame according to glade file */
xml = glade_xml_new (GLADE_FILE, PROJECT_SELECTION_FRAME, NULL);
g_return_if_fail (xml != NULL);
@@ -262,11 +264,12 @@
list = GNOME_ICON_LIST (glade_xml_get_widget (xml, PROJECT_SELECTION_LIST));
desc = GTK_LABEL (glade_xml_get_widget (xml, PROJECT_DESCRIPTION));
- npw_header_list_foreach_project_in (this->header_list, category, cb_druid_insert_project_icon, list);
+ g_list_foreach (template_list, cb_druid_insert_project_icon, list);
/* put druid address and corresponding text buffer in one structure
* to pass them to a call back function as an unique pointer */
- data = g_chunk_new (NPWDruidAndTextBuffer, this->pool);
+ data = g_slice_new (NPWDruidAndTextBuffer);
+ this->stuff_list = g_list_prepend (this->stuff_list, data);
data->druid = this;
data->description = desc;
data->header = (NPWHeader*)gnome_icon_list_get_icon_data (list, 0);
@@ -280,7 +283,7 @@
g_return_if_fail (xml != NULL);
label = glade_xml_get_widget (xml, PROJECT_SELECTION_BOOK_LABEL);
g_object_unref (xml);
- gtk_label_set_text (GTK_LABEL(label), category);
+ gtk_label_set_text (GTK_LABEL(label), (const gchar *)category);
gtk_notebook_append_page (this->project_book, frame, label);
}
@@ -297,13 +300,13 @@
this->header_list = npw_header_list_new ();
/* Fill list with all project in directory */
- ok = npw_header_list_readdir (this->header_list, PROJECT_WIZARD_DIRECTORY);
+ ok = npw_header_list_readdir (&this->header_list, PROJECT_WIZARD_DIRECTORY);
#ifdef LOCAL_PROJECT_WIZARD_DIRECTORY
local_dir = g_build_filename (g_get_home_dir(), LOCAL_PROJECT_WIZARD_DIRECTORY, NULL);
#else
local_dir = anjuta_util_get_user_data_file_path ("projects/",NULL);
#endif
- ok = npw_header_list_readdir (this->header_list, local_dir) || ok;
+ ok = npw_header_list_readdir (&this->header_list, local_dir) || ok;
g_free (local_dir);
if (!ok)
{
@@ -313,7 +316,8 @@
/* Add all notebook page */
gtk_notebook_remove_page(this->project_book, 0);
- npw_header_list_foreach_category (this->header_list, cb_druid_insert_project_page, this);
+
+ g_list_foreach (this->header_list, cb_druid_insert_project_page, this);
return TRUE;
}
@@ -403,7 +407,7 @@
/* Add new widget */
data.druid = this;
data.row = 0;
- npw_page_foreach_property (page, cb_druid_add_property, &data);
+ npw_page_foreach_property (page, (GFunc)cb_druid_add_property, &data);
/* Change page only if current is project selection page */
gnome_druid_set_page (this->druid, GNOME_DRUID_PAGE (this->property_page));
@@ -581,7 +585,7 @@
data.modified = FALSE;
data.next = TRUE;
data.parent = GTK_WINDOW (this->dialog);
- npw_page_foreach_property (page, cb_save_valid_property, &data);
+ npw_page_foreach_property (page, (GFunc)cb_save_valid_property, &data);
if (data.modified) npw_druid_remove_following_page (this);
@@ -598,7 +602,7 @@
page = g_queue_peek_nth (this->page_list, this->page - 1);
modified = FALSE;
- npw_page_foreach_property (page, cb_save_old_property, &modified);
+ npw_page_foreach_property (page, (GFunc)cb_save_old_property, &modified);
}
@@ -890,7 +894,7 @@
/* Add default base project directory */
value = npw_value_heap_find_value (this->values, ANJUTA_PROJECT_DIRECTORY_PROPERTY);
s = anjuta_preferences_get (pref, "anjuta.project.directory");
- npw_value_heap_set_value (this->values, value, s == NULL ? "~" : s, NPW_VALID_VALUE);
+ npw_value_set_value (value, s == NULL ? "~" : s, NPW_VALID_VALUE);
g_free (s);
/* Add user name */
@@ -899,11 +903,11 @@
if (!s || strlen(s) == 0)
{
s = (gchar *)g_get_real_name();
- npw_value_heap_set_value (this->values, value, s, NPW_VALID_VALUE);
+ npw_value_set_value (value, s, NPW_VALID_VALUE);
}
else
{
- npw_value_heap_set_value (this->values, value, s, NPW_VALID_VALUE);
+ npw_value_set_value (value, s, NPW_VALID_VALUE);
g_free (s);
}
/* Add Email address */
@@ -916,7 +920,7 @@
s = getenv("USER");
s = g_strconcat(s, "@", getenv("HOSTNAME"), NULL);
}
- npw_value_heap_set_value (this->values, value, s, NPW_VALID_VALUE);
+ npw_value_set_value (value, s, NPW_VALID_VALUE);
g_free (s);
}
@@ -949,8 +953,7 @@
return NULL;
}
- this->pool = g_mem_chunk_new ("druid pool", sizeof(NPWDruidStuff), sizeof(NPWDruidStuff) * 20, G_ALLOC_ONLY);
-
+
/* Get reference on all useful widget */
this->dialog = glade_xml_get_widget (xml, NEW_PROJECT_DIALOG);
gtk_window_set_transient_for (GTK_WINDOW (this->dialog),
@@ -999,6 +1002,12 @@
return this;
}
+static void
+npw_druid_stuff_free (NPWDruidStuff *stuff)
+{
+ g_slice_free (NPWDruidStuff, stuff);
+}
+
void
npw_druid_free (NPWDruid* this)
{
@@ -1018,7 +1027,8 @@
npw_value_heap_free (this->values);
npw_autogen_free (this->gen);
if (this->parser != NULL) npw_page_parser_free (this->parser);
- g_mem_chunk_destroy(this->pool);
+ g_list_foreach (this->stuff_list, (GFunc)npw_druid_stuff_free, NULL);
+ g_list_free (this->stuff_list);
npw_header_list_free (this->header_list);
gtk_widget_destroy (this->dialog);
this->plugin->druid = NULL;
Modified: trunk/plugins/project-wizard/file.c
==============================================================================
--- trunk/plugins/project-wizard/file.c (original)
+++ trunk/plugins/project-wizard/file.c Wed Dec 24 18:06:10 2008
@@ -27,28 +27,13 @@
#include "file.h"
-#include <glib.h>
-
-/*---------------------------------------------------------------------------*/
-
-#define STRING_CHUNK_SIZE 256
-
/*---------------------------------------------------------------------------*/
-struct _NPWFileList
-{
- GNode* list;
- GStringChunk* string_pool;
- GMemChunk* data_pool;
-};
-
struct _NPWFile {
NPWFileType type;
gchar* source;
gchar* destination;
gint attribute;
- NPWFileList* owner;
- GNode* node;
};
typedef enum {
@@ -62,183 +47,105 @@
*---------------------------------------------------------------------------*/
NPWFile*
-npw_file_new (NPWFileList* owner)
+npw_file_new_file (const gchar *destination, const gchar *source)
{
- NPWFile* this;
+ NPWFile *file;
- g_return_val_if_fail (owner, NULL);
+ g_return_val_if_fail (destination && source, NULL);
- this = g_chunk_new0(NPWFile, owner->data_pool);
- this->owner = owner;
- this->node = g_node_append_data (owner->list, this);
- this->attribute = 0;
+ file = g_slice_new(NPWFile);
+ file->type = NPW_FILE;
+ file->destination = g_strdup (destination);
+ file->source = g_strdup (source);
+ file->attribute = 0;
- return this;
+ return file;
}
void
-npw_file_free (NPWFile* this)
+npw_file_free (NPWFile* file)
{
- GNode* node;
-
- node = g_node_find_child (this->owner->list, G_TRAVERSE_ALL, this);
- if (node != NULL)
- {
- g_node_destroy (node);
- /* Memory allocated in string pool and project pool is not free */
- }
-}
-
-void
-npw_file_set_type (NPWFile* this, NPWFileType type)
-{
- this->type = type;
+ g_free (file->destination);
+ g_free (file->source);
+ g_slice_free (NPWFile, file);
}
NPWFileType
-npw_file_get_type (const NPWFile* this)
-{
- return this->type;
-}
-
-void
-npw_file_set_destination (NPWFile* this, const gchar* destination)
+npw_file_get_type (const NPWFile* file)
{
- this->destination = g_string_chunk_insert (this->owner->string_pool, destination);
+ return file->type;
}
const gchar*
-npw_file_get_destination (const NPWFile* this)
-{
- return this->destination;
-}
-
-void
-npw_file_set_source (NPWFile* this, const gchar* source)
+npw_file_get_destination (const NPWFile* file)
{
- this->source = g_string_chunk_insert (this->owner->string_pool, source);
+ return file->destination;
}
const gchar*
-npw_file_get_source (const NPWFile* this)
+npw_file_get_source (const NPWFile* file)
{
- return this->source;
+ return file->source;
}
void
-npw_file_set_execute (NPWFile* this, gboolean value)
+npw_file_set_execute (NPWFile* file, gboolean value)
{
if (value)
{
- this->attribute |= NPW_EXECUTE_FILE;
+ file->attribute |= NPW_EXECUTE_FILE;
}
else
{
- this->attribute &= ~NPW_EXECUTE_FILE;
+ file->attribute &= ~NPW_EXECUTE_FILE;
}
}
gboolean
-npw_file_get_execute (const NPWFile* this)
+npw_file_get_execute (const NPWFile* file)
{
- return this->attribute & NPW_EXECUTE_FILE;
+ return file->attribute & NPW_EXECUTE_FILE;
}
void
-npw_file_set_project (NPWFile* this, gboolean value)
+npw_file_set_project (NPWFile* file, gboolean value)
{
if (value)
{
- this->attribute |= NPW_PROJECT_FILE;
+ file->attribute |= NPW_PROJECT_FILE;
}
else
{
- this->attribute &= ~NPW_PROJECT_FILE;
+ file->attribute &= ~NPW_PROJECT_FILE;
}
}
gboolean
-npw_file_get_project (const NPWFile* this)
+npw_file_get_project (const NPWFile* file)
{
- return this->attribute & NPW_PROJECT_FILE;
+ return file->attribute & NPW_PROJECT_FILE;
}
void
-npw_file_set_autogen (NPWFile* this, NPWFileBooleanValue value)
+npw_file_set_autogen (NPWFile* file, NPWFileBooleanValue value)
{
switch (value)
{
case NPW_FILE_TRUE:
- this->attribute |= NPW_AUTOGEN_FILE | NPW_AUTOGEN_SET;
+ file->attribute |= NPW_AUTOGEN_FILE | NPW_AUTOGEN_SET;
break;
case NPW_FILE_FALSE:
- this->attribute |= NPW_AUTOGEN_SET;
- this->attribute &= ~NPW_AUTOGEN_FILE;
+ file->attribute |= NPW_AUTOGEN_SET;
+ file->attribute &= ~NPW_AUTOGEN_FILE;
break;
case NPW_FILE_DEFAULT:
- this->attribute &= ~(NPW_AUTOGEN_SET | NPW_AUTOGEN_FILE);
+ file->attribute &= ~(NPW_AUTOGEN_SET | NPW_AUTOGEN_FILE);
break;
}
}
NPWFileBooleanValue
-npw_file_get_autogen (const NPWFile* this)
-{
- return this->attribute & NPW_AUTOGEN_SET ? (this->attribute & NPW_AUTOGEN_FILE ? NPW_FILE_TRUE : NPW_FILE_FALSE) : NPW_FILE_DEFAULT;
-}
-
-const NPWFile*
-npw_file_next (const NPWFile* this)
+npw_file_get_autogen (const NPWFile* file)
{
- GNode* node = this->node->next;
-
- return node == NULL ? NULL : (NPWFile *)node->data;
-}
-
-/* File list object
- *---------------------------------------------------------------------------*/
-
-NPWFileList*
-npw_file_list_new (void)
-{
- NPWFileList* this;
-
- this = g_new (NPWFileList, 1);
- this->string_pool = g_string_chunk_new (STRING_CHUNK_SIZE);
- this->data_pool = g_mem_chunk_new ("file pool", sizeof (NPWFile), STRING_CHUNK_SIZE * sizeof (NPWFile) / 4, G_ALLOC_ONLY);
- this->list = g_node_new (NULL);
-
- return this;
-}
-
-void
-npw_file_list_free (NPWFileList* this)
-{
- g_return_if_fail (this != NULL);
-
- g_string_chunk_free (this->string_pool);
- g_mem_chunk_destroy (this->data_pool);
- g_node_destroy (this->list);
- g_free (this);
-}
-
-static void
-cb_file_list_foreach_file (GNode* node, gpointer data)
-{
- ((NPWFileForeachFunc)data)((NPWFile*)node->data);
-}
-
-void
-npw_file_list_foreach_file (const NPWFileList* this, NPWFileForeachFunc func)
-{
- g_node_children_foreach (this->list, G_TRAVERSE_LEAFS, cb_file_list_foreach_file, (gpointer)func);
-}
-
-const NPWFile*
-npw_file_list_first (const NPWFileList* this)
-{
- /* Should work even if first child is NULL (empty list) */
- GNode* node = g_node_first_child (this->list);
-
- return node == NULL ? NULL : (NPWFile *)node->data;
+ return file->attribute & NPW_AUTOGEN_SET ? (file->attribute & NPW_AUTOGEN_FILE ? NPW_FILE_TRUE : NPW_FILE_FALSE) : NPW_FILE_DEFAULT;
}
Modified: trunk/plugins/project-wizard/file.h
==============================================================================
--- trunk/plugins/project-wizard/file.h (original)
+++ trunk/plugins/project-wizard/file.h Wed Dec 24 18:06:10 2008
@@ -37,35 +37,20 @@
NPW_FILE_TRUE = 1
} NPWFileBooleanValue;
-NPWFile* npw_file_new (NPWFileList* owner);
-void npw_file_free (NPWFile* this);
+NPWFile* npw_file_new_file (const gchar *destination, const gchar *source);
+void npw_file_free (NPWFile* file);
-void npw_file_set_type (NPWFile* this, NPWFileType type);
-NPWFileType npw_file_get_type (const NPWFile* this);
+NPWFileType npw_file_get_type (const NPWFile* file);
+const gchar* npw_file_get_destination (const NPWFile* file);
+const gchar* npw_file_get_source (const NPWFile* file);
-void npw_file_set_destination (NPWFile* this, const gchar* destination);
-const gchar* npw_file_get_destination (const NPWFile* this);
+void npw_file_set_execute (NPWFile* file, gboolean value);
+gboolean npw_file_get_execute (const NPWFile* file);
-void npw_file_set_source (NPWFile* this, const gchar* destination);
-const gchar* npw_file_get_source (const NPWFile* this);
+void npw_file_set_project (NPWFile* file, gboolean value);
+gboolean npw_file_get_project (const NPWFile* file);
-void npw_file_set_execute (NPWFile* this, gboolean value);
-gboolean npw_file_get_execute (const NPWFile* this);
-
-void npw_file_set_project (NPWFile* this, gboolean value);
-gboolean npw_file_get_project (const NPWFile* this);
-
-void npw_file_set_autogen (NPWFile* this, NPWFileBooleanValue value);
-NPWFileBooleanValue npw_file_get_autogen (const NPWFile* this);
-
-const NPWFile* npw_file_next (const NPWFile* this);
-
-NPWFileList* npw_file_list_new (void);
-void npw_file_list_free (NPWFileList* this);
-
-typedef void (*NPWFileForeachFunc) (NPWFile* file);
-
-void npw_file_list_foreach_file (const NPWFileList* this, NPWFileForeachFunc func);
-const NPWFile* npw_file_list_first (const NPWFileList* this);
+void npw_file_set_autogen (NPWFile* file, NPWFileBooleanValue value);
+NPWFileBooleanValue npw_file_get_autogen (const NPWFile* file);
#endif
Modified: trunk/plugins/project-wizard/header.c
==============================================================================
--- trunk/plugins/project-wizard/header.c (original)
+++ trunk/plugins/project-wizard/header.c Wed Dec 24 18:06:10 2008
@@ -34,17 +34,6 @@
/*---------------------------------------------------------------------------*/
-#define STRING_CHUNK_SIZE 256
-
-/*---------------------------------------------------------------------------*/
-
-struct _NPWHeaderList
-{
- GNode* list;
- GStringChunk* string_pool;
- GMemChunk* data_pool;
-};
-
struct _NPWHeader {
gchar* name;
gchar* description;
@@ -53,128 +42,116 @@
gchar* filename;
GList* required_programs;
GList* required_packages;
- NPWHeaderList* owner;
- GNode* node;
};
/* Header
*---------------------------------------------------------------------------*/
NPWHeader*
-npw_header_new (NPWHeaderList* owner)
+npw_header_new (void)
{
- NPWHeader* this;
+ NPWHeader* self;
- g_return_val_if_fail (owner, NULL);
+ self = g_slice_new0(NPWHeader);
- this = g_chunk_new0(NPWHeader, owner->data_pool);
- this->owner = owner;
- this->node = g_node_append_data (owner->list, this);
-
- return this;
+ return self;
}
void
-npw_header_free (NPWHeader* this)
+npw_header_free (NPWHeader* self)
{
- GNode* node;
-
- /* Memory allocated in string pool and project pool is not free */
- node = g_node_find (this->owner->list, G_IN_ORDER, G_TRAVERSE_ALL, this);
- if (node != NULL)
- g_node_destroy (node);
- if (this->required_programs)
- g_list_free (this->required_programs);
- if (this->required_packages)
- g_list_free (this->required_packages);
+ g_free (self->name);
+ g_free (self->description);
+ g_free (self->iconfile);
+ g_free (self->category);
+ g_free (self->filename);
+ g_list_free (self->required_programs);
+ g_list_free (self->required_packages);
}
void
-npw_header_set_name (NPWHeader* this, const gchar* name)
+npw_header_set_name (NPWHeader* self, const gchar* name)
{
- this->name = g_string_chunk_insert (this->owner->string_pool, name);
+ self->name = g_strdup (name);
}
const gchar*
-npw_header_get_name (const NPWHeader* this)
+npw_header_get_name (const NPWHeader* self)
{
- return this->name;
+ return self->name;
}
void
-npw_header_set_filename (NPWHeader* this, const gchar* filename)
+npw_header_set_filename (NPWHeader* self, const gchar* filename)
{
- this->filename = g_string_chunk_insert (this->owner->string_pool, filename);
+ self->filename = g_strdup (filename);
}
const gchar*
-npw_header_get_filename (const NPWHeader* this)
+npw_header_get_filename (const NPWHeader* self)
{
- return this->filename;
+ return self->filename;
}
void
-npw_header_set_category (NPWHeader* this, const gchar* category)
+npw_header_set_category (NPWHeader* self, const gchar* category)
{
- npw_header_list_organize(this->owner, category, this);
- this->category = ((NPWHeader *)this->node->parent->data)->category;
+ self->category =g_strdup (category);
}
const gchar*
-npw_header_get_category (const NPWHeader* this)
+npw_header_get_category (const NPWHeader* self)
{
- return this->category;
+ return self->category;
}
void
-npw_header_set_description (NPWHeader* this, const gchar* description)
+npw_header_set_description (NPWHeader* self, const gchar* description)
{
- this->description = g_string_chunk_insert (this->owner->string_pool, description);
+ self->description = g_strdup (description);
}
const gchar*
-npw_header_get_description (const NPWHeader* this)
+npw_header_get_description (const NPWHeader* self)
{
- return this->description;
+ return self->description;
}
void
-npw_header_set_iconfile (NPWHeader* this, const gchar* iconfile)
+npw_header_set_iconfile (NPWHeader* self, const gchar* iconfile)
{
- this->iconfile = g_string_chunk_insert (this->owner->string_pool, iconfile);
+ self->iconfile = g_strdup (iconfile);
}
const gchar*
-npw_header_get_iconfile (const NPWHeader* this)
+npw_header_get_iconfile (const NPWHeader* self)
{
- return this->iconfile;
+ return self->iconfile;
}
void
-npw_header_add_required_program (NPWHeader* this, const gchar* program)
+npw_header_add_required_program (NPWHeader* self, const gchar* program)
{
- this->required_programs =
- g_list_prepend (this->required_programs,
- g_string_chunk_insert (this->owner->string_pool,
- program));
+ self->required_programs =
+ g_list_prepend (self->required_programs,
+ g_strdup (program));
}
void
-npw_header_add_required_package (NPWHeader* this, const gchar* package)
+npw_header_add_required_package (NPWHeader* self, const gchar* package)
{
- this->required_packages =
- g_list_prepend (this->required_packages,
- g_string_chunk_insert (this->owner->string_pool,
- package));
+ self->required_packages =
+ g_list_prepend (self->required_packages,
+ g_strdup(package));
}
GList*
-npw_header_check_required_programs (NPWHeader* this)
+npw_header_check_required_programs (NPWHeader* self)
{
GList *node = NULL;
GList *failed_programs = NULL;
- for (node = this->required_programs; node; node = g_list_next (node))
+ for (node = self->required_programs; node; node = g_list_next (node))
{
if (!anjuta_util_prog_is_installed (node->data, FALSE))
{
@@ -200,11 +177,11 @@
}
GList*
-npw_header_check_required_packages (NPWHeader* this)
+npw_header_check_required_packages (NPWHeader* self)
{
GList *node = NULL;
GList *failed_packages = NULL;
- for (node = this->required_packages; node; node = g_list_next (node))
+ for (node = self->required_packages; node; node = g_list_next (node))
{
if (!package_is_installed (node->data))
{
@@ -214,175 +191,64 @@
return failed_packages;
}
-gboolean
-npw_header_is_leaf(const NPWHeader* this)
-{
- return G_NODE_IS_LEAF(this->node);
-}
-
-
/* Header list
*---------------------------------------------------------------------------*/
-static GNode*
-npw_header_list_find_parent(NPWHeaderList* this, const gchar* category, gboolean create)
+GList*
+npw_header_list_new (void)
{
- GNode* node;
- gint order;
+ GList* list;
- for (node = g_node_first_child(this->list); node != NULL; node = g_node_next_sibling(node))
- {
- const char* s;
-
- s = ((NPWHeader *)node->data)->category;
- if (s != NULL)
- {
- order = g_ascii_strcasecmp (s, category);
- if (order == 0)
- {
- /* Find right category */
- break;
- }
- else if (order > 0)
- {
- if (create == TRUE)
- {
- /* Category doesn't exist create a new node */
- NPWHeader* new_parent;
-
- new_parent = npw_header_new (this);
- new_parent->category = g_string_chunk_insert (this->string_pool, category);
- g_node_unlink (new_parent->node);
- g_node_insert_before (this->list, node, new_parent->node);
- node = new_parent->node;
- }
- else
- {
- node = NULL;
- }
- break;
- }
- }
- }
-
- if (create && (node == NULL))
- {
- NPWHeader* new_parent;
-
- new_parent = npw_header_new (this);
- new_parent->category = g_string_chunk_insert (this->string_pool, category);
- node = new_parent->node;
- }
-
- return node;
+ list = NULL;
+
+ return list;
}
-typedef struct _HeaderListForeachProjectData
-{
- NPWHeaderForeachFunc func;
- gpointer data;
-} HeaderListForeachProjectData;
-
static void
-cb_header_list_foreach_project (GNode* node, gpointer data)
+remove_category (GList *list)
{
- HeaderListForeachProjectData* d = (HeaderListForeachProjectData *)data;
-
- (d->func)((NPWHeader*)node->data, d->data);
+ g_list_foreach (list, (GFunc)npw_header_free, NULL);
+ g_list_free (list);
}
-static gboolean
-npw_header_list_foreach_node (GNode* list, NPWHeaderForeachFunc func, gpointer data, GTraverseFlags flag)
-{
- HeaderListForeachProjectData d;
-
- if (g_node_first_child (list) == NULL) return FALSE;
-
- d.func = func;
- d.data = data;
-
- g_node_children_foreach (list, flag, cb_header_list_foreach_project, &d);
-
- return TRUE;
-}
-
-/*---------------------------------------------------------------------------*/
-
-NPWHeaderList*
-npw_header_list_new (void)
+void
+npw_header_list_free (GList* list)
{
- NPWHeaderList* this;
-
- this = g_new (NPWHeaderList, 1);
- this->string_pool = g_string_chunk_new (STRING_CHUNK_SIZE);
- this->data_pool = g_mem_chunk_new ("project pool", sizeof (NPWHeader), STRING_CHUNK_SIZE * sizeof (NPWHeader) / 4, G_ALLOC_ONLY);
- this->list = g_node_new (NULL);
+ g_return_if_fail (list != NULL);
- return this;
+ g_list_foreach (list, (GFunc)remove_category, NULL);
+ g_list_free (list);
}
-void
-npw_header_list_free (NPWHeaderList* this)
+static gint
+compare_header_name (NPWHeader *a, NPWHeader *b)
{
- g_return_if_fail (this != NULL);
-
- g_string_chunk_free (this->string_pool);
- g_mem_chunk_destroy (this->data_pool);
- g_node_destroy (this->list);
- g_free (this);
+ return g_ascii_strcasecmp (npw_header_get_name (a), npw_header_get_name (b));
}
-void
-npw_header_list_organize(NPWHeaderList* this, const gchar* category, NPWHeader* header)
+GList *
+npw_header_list_insert_header (GList *list, NPWHeader *header)
{
- GNode* parent;
- GNode* node;
- const gchar* name;
-
- /* node without a category stay on top */
- if ((category == NULL) || (*category == '\0')) return;
-
- /* Detach the node */
- g_node_unlink(header->node);
-
- /* Find parent */
- parent = npw_header_list_find_parent(this, category, TRUE);
-
- /* Insert node as a child in alphabetic order*/
- name = npw_header_get_name (header);
- for (node = g_node_first_child(parent); node != NULL; node = g_node_next_sibling(node))
+ GList *node;
+ GList *template_list;
+
+ for (node = g_list_first (list); node != NULL; node = g_list_next (node))
{
- if (g_ascii_strcasecmp (npw_header_get_name ((NPWHeader *)node->data), name) > 0)
+ NPWHeader* first;
+ gint res;
+
+ template_list = (GList *)node->data;
+ first = (NPWHeader *)template_list->data;
+ res = g_ascii_strcasecmp (npw_header_get_category (first), npw_header_get_category (header));
+ if (res > 0) break;
+ if (res == 0)
{
- g_node_insert_before (parent, node, header->node);
- return;
+ node->data = g_list_insert_sorted (template_list, header, (GCompareFunc) compare_header_name);
+ return list;
}
}
- g_node_insert(parent, -1, header->node);
-}
-
-gboolean
-npw_header_list_foreach_project (const NPWHeaderList* this, NPWHeaderForeachFunc func, gpointer data)
-{
- return npw_header_list_foreach_node (this->list, func, data, G_TRAVERSE_LEAFS);
-}
-
-gboolean
-npw_header_list_foreach_project_in (const NPWHeaderList* this, const gchar* category, NPWHeaderForeachFunc func, gpointer data)
-{
- GNode* node;
-
- /* FIXME: const modified has been removed because the find function
- * with TRUE as the third argument could create a parent if it
- * doesn't exist. It could be better to split this function in two */
- node = npw_header_list_find_parent((NPWHeaderList*)this, category, FALSE);
- if (node == NULL) return FALSE;
- return npw_header_list_foreach_node (node, func, data, G_TRAVERSE_LEAFS);
-}
+ template_list = g_list_prepend (NULL, header);
-gboolean
-npw_header_list_foreach_category (const NPWHeaderList* this, NPWHeaderForeachFunc func, gpointer data)
-{
- return npw_header_list_foreach_node (this->list, func, data, G_TRAVERSE_NON_LEAFS);
+ return g_list_insert_before (list, node, template_list);
}
Modified: trunk/plugins/project-wizard/header.h
==============================================================================
--- trunk/plugins/project-wizard/header.h (original)
+++ trunk/plugins/project-wizard/header.h Wed Dec 24 18:06:10 2008
@@ -26,51 +26,41 @@
typedef struct _NPWHeader NPWHeader;
typedef struct _NPWHeaderList NPWHeaderList;
-NPWHeader* npw_header_new (NPWHeaderList* owner);
-void npw_header_free (NPWHeader* this);
+NPWHeader* npw_header_new (void);
+void npw_header_free (NPWHeader* self);
void npw_header_set_name (NPWHeader* this, const gchar* name);
-const gchar* npw_header_get_name (const NPWHeader* this);
+const gchar* npw_header_get_name (const NPWHeader* self);
void npw_header_set_filename (NPWHeader* this, const gchar* filename);
-const gchar* npw_header_get_filename (const NPWHeader* this);
+const gchar* npw_header_get_filename (const NPWHeader* self);
void npw_header_set_category (NPWHeader* this, const gchar* category);
-const gchar* npw_header_get_category(const NPWHeader* this);
+const gchar* npw_header_get_category(const NPWHeader* self);
void npw_header_set_description (NPWHeader* this, const gchar* description);
-const gchar* npw_header_get_description (const NPWHeader* this);
+const gchar* npw_header_get_description (const NPWHeader* self);
void npw_header_set_iconfile (NPWHeader* this, const gchar* confile);
-const gchar* npw_header_get_iconfile (const NPWHeader* this);
+const gchar* npw_header_get_iconfile (const NPWHeader* self);
-void npw_header_add_required_program (NPWHeader* this, const gchar* program);
+void npw_header_add_required_program (NPWHeader* self, const gchar* program);
/* Returns list of missing programs, or NULL if none is missing
* Only the glist should be freed, not the strings within
*/
-GList* npw_header_check_required_programs (NPWHeader* this);
+GList* npw_header_check_required_programs (NPWHeader* self);
-void npw_header_add_required_package (NPWHeader* this, const gchar* package);
+void npw_header_add_required_package (NPWHeader* self, const gchar* package);
/* Returns list of missing packages, or NULL if none is missing
* Only the glist should be freed, not the strings within
*/
-GList* npw_header_check_required_packages (NPWHeader* this);
+GList* npw_header_check_required_packages (NPWHeader* self);
-gboolean npw_header_is_leaf(const NPWHeader* this);
-NPWHeaderList* npw_header_list_new (void);
-
-NPWHeaderList* npw_header_list_new (void);
-void npw_header_list_free (NPWHeaderList* this);
-
-void npw_header_list_organize(NPWHeaderList* this, const gchar* category, NPWHeader* header);
-
-typedef void (*NPWHeaderForeachFunc) (NPWHeader* head, gpointer data);
-
-gboolean npw_header_list_foreach_project (const NPWHeaderList* this, NPWHeaderForeachFunc func, gpointer data);
-gboolean npw_header_list_foreach_project_in (const NPWHeaderList* this, const gchar* category, NPWHeaderForeachFunc func, gpointer data);
-gboolean npw_header_list_foreach_category (const NPWHeaderList* this, NPWHeaderForeachFunc func, gpointer data);
+GList* npw_header_list_new (void);
+void npw_header_list_free (GList* list);
+GList * npw_header_list_insert_header (GList *list, NPWHeader *header);
#endif
Modified: trunk/plugins/project-wizard/install.c
==============================================================================
--- trunk/plugins/project-wizard/install.c (original)
+++ trunk/plugins/project-wizard/install.c Wed Dec 24 18:06:10 2008
@@ -56,12 +56,12 @@
struct _NPWInstall
{
NPWAutogen* gen;
- NPWFileListParser* parser;
- NPWFileList* list;
- const NPWFile* file;
+ NPWFileListParser* file_parser;
+ GList* file_list;
+ GList* current_file;
NPWActionListParser* action_parser;
- NPWActionList* action_list;
- const NPWAction* action;
+ GList* action_list;
+ GList* action;
AnjutaLauncher* launcher;
NPWPlugin* plugin;
const gchar* project_file;
@@ -205,13 +205,14 @@
void npw_install_free (NPWInstall* this)
{
- if (this->parser != NULL)
+ if (this->file_parser != NULL)
{
- npw_file_list_parser_free (this->parser);
+ npw_file_list_parser_free (this->file_parser);
}
- if (this->list != NULL)
+ if (this->file_list != NULL)
{
- npw_file_list_free (this->list);
+ g_list_foreach (this->file_list, (GFunc)npw_file_free, NULL);
+ g_list_free (this->file_list);
}
if (this->action_parser != NULL)
{
@@ -219,7 +220,8 @@
}
if (this->action_list != NULL)
{
- npw_action_list_free (this->action_list);
+ g_list_foreach (this->action_list, (GFunc)npw_action_free, NULL);
+ g_list_free (this->action_list);
}
if (this->launcher != NULL)
{
@@ -233,7 +235,7 @@
gboolean
-npw_install_set_property (NPWInstall* this, NPWValueHeap* values)
+npw_install_set_property (NPWInstall* this, GHashTable* values)
{
npw_autogen_write_definition_file (this->gen, values);
@@ -243,17 +245,17 @@
gboolean
npw_install_set_wizard_file (NPWInstall* this, const gchar* filename)
{
- if (this->list != NULL)
+ if (this->file_list != NULL)
{
- npw_file_list_free (this->list);
+ g_list_foreach (this->file_list, (GFunc)npw_file_free, NULL);
+ g_list_free (this->file_list);
+ this->file_list = NULL;
}
- this->list = npw_file_list_new ();
-
- if (this->parser != NULL)
+ if (this->file_parser != NULL)
{
- npw_file_list_parser_free (this->parser);
+ npw_file_list_parser_free (this->file_parser);
}
- this->parser = npw_file_list_parser_new (this->list, filename);
+ this->file_parser = npw_file_list_parser_new (filename);
npw_autogen_set_input_file (this->gen, filename, "[+","+]");
@@ -275,21 +277,23 @@
for (;;)
{
+ NPWAction *action;
+
if (this->action == NULL)
{
if (this->success)
{
/* Run action on success only */
- this->action = npw_action_list_first (this->action_list);
+ this->action = g_list_first (this->action_list);
}
}
else
{
- this->action = npw_action_next (this->action);
+ this->action = g_list_next (this->action);
}
if (this->action == NULL)
{
- DEBUG_PRINT ("%s", "Project wizard done");
+ DEBUG_PRINT ("Project wizard done");
/* The wizard could have been deactivated when loading the new
* project. Hence, the following check.
*/
@@ -298,7 +302,9 @@
npw_install_free (this);
return;
}
- switch (npw_action_get_type (this->action))
+ action = (NPWAction *)this->action->data;
+
+ switch (npw_action_get_type (action))
{
case NPW_RUN_ACTION:
npw_run_action (this);
@@ -317,7 +323,7 @@
{
NPWInstall* this = (NPWInstall*)data;
- npw_action_list_parser_end_parse (this->action_parser, NULL);
+ this->action_list = npw_action_list_parser_end_parse (this->action_parser, NULL);
on_install_end_install_file (NULL, this);
}
@@ -327,7 +333,7 @@
{
NPWInstall* this = (NPWInstall*)data;
- npw_file_list_parser_parse (this->parser, output, strlen (output), NULL);
+ npw_file_list_parser_parse (this->file_parser, output, strlen (output), NULL);
}
static void
@@ -335,13 +341,22 @@
{
NPWInstall* this = (NPWInstall*)data;
- npw_file_list_parser_end_parse (this->parser, NULL);
+ this->file_list = npw_file_list_parser_end_parse (this->file_parser, NULL);
- this->file = NULL;
+ this->current_file = NULL;
this->project_file = NULL;
- this->action_list = npw_action_list_new ();
- this->action_parser = npw_action_list_parser_new (this->action_list);
+ if (this->action_list != NULL)
+ {
+ g_list_foreach (this->action_list, (GFunc)npw_action_free, NULL);
+ g_list_free (this->action_list);
+ this->action_list = NULL;
+ }
+ if (this->action_parser != NULL)
+ {
+ npw_action_list_parser_free (this->action_parser);
+ }
+ this->action_parser = npw_action_list_parser_new ();
npw_autogen_set_output_callback (this->gen, on_install_read_action_list, this);
npw_autogen_execute (this->gen, on_install_read_all_action_list, this, NULL);
}
@@ -355,28 +370,32 @@
for (;;)
{
- if (this->file == NULL)
+ NPWFile *file;
+
+ if (this->current_file == NULL)
{
- this->file = npw_file_list_first (this->list);
+ this->current_file = g_list_first (this->file_list);
}
else
{
- if (npw_file_get_execute (this->file))
+ NPWFile *file = (NPWFile *)this->current_file->data;
+
+ if (npw_file_get_execute (file))
{
gint previous;
/* Make this file executable */
previous = umask (0666);
- chmod (npw_file_get_destination (this->file), 0777 & ~previous);
+ chmod (npw_file_get_destination (file), 0777 & ~previous);
umask (previous);
}
- if (npw_file_get_project (this->file))
+ if (npw_file_get_project (file))
{
/* Check if project is NULL */
- this->project_file = npw_file_get_destination (this->file);
+ this->project_file = npw_file_get_destination (file);
}
- this->file = npw_file_next (this->file);
+ this->current_file = g_list_next (this->current_file);
}
- if (this->file == NULL)
+ if (this->current_file == NULL)
{
/* IAnjutaFileLoader* loader; */
/* All files have been installed */
@@ -398,13 +417,14 @@
return;
}
- switch (npw_file_get_type (this->file))
+ file = (NPWFile *)this->current_file->data;
+ switch (npw_file_get_type (file))
{
case NPW_FILE:
npw_install_install_file (this);
return;
default:
- g_warning("Unknown file type %d\n", npw_file_get_type (this->file));
+ g_warning("Unknown file type %d\n", npw_file_get_type (file));
break;
}
}
@@ -430,9 +450,11 @@
gchar* msg;
gboolean use_autogen;
gboolean ok = TRUE;
-
- destination = npw_file_get_destination (this->file);
- source = npw_file_get_source (this->file);
+ NPWFile *file = (NPWFile *)this->current_file->data;
+
+
+ destination = npw_file_get_destination (file);
+ source = npw_file_get_source (file);
/* Check if file already exist */
if (g_file_test (destination, G_FILE_TEST_EXISTS))
@@ -446,7 +468,7 @@
}
/* Check if autogen is needed */
- switch (npw_file_get_autogen (this->file))
+ switch (npw_file_get_autogen (file))
{
case NPW_TRUE:
use_autogen = TRUE;
@@ -536,25 +558,28 @@
npw_run_action (NPWInstall* this)
{
gchar *msg;
+ NPWAction *action = (NPWAction *)this->action->data;
+
if (this->launcher == NULL)
{
this->launcher = anjuta_launcher_new ();
}
g_signal_connect (G_OBJECT (this->launcher), "child-exited", G_CALLBACK (on_run_terminated), this);
- msg = g_strconcat (_("Executing: "), npw_action_get_command (this->action), NULL);
+ msg = g_strconcat (_("Executing: "), npw_action_get_command (action), NULL);
npw_plugin_print_view (this->plugin, IANJUTA_MESSAGE_VIEW_TYPE_INFO, msg, "");
- return anjuta_launcher_execute (this->launcher, npw_action_get_command (this->action), on_run_output, this);
+ return anjuta_launcher_execute (this->launcher, npw_action_get_command (action), on_run_output, this);
}
static gboolean
npw_open_action (NPWInstall* this)
{
IAnjutaFileLoader* loader;
+ NPWAction *action = (NPWAction *)this->action->data;
loader = anjuta_shell_get_interface (ANJUTA_PLUGIN (this->plugin)->shell, IAnjutaFileLoader, NULL);
if (loader)
{
- GFile* file = g_file_new_for_path (npw_action_get_file (this->action));
+ GFile* file = g_file_new_for_path (npw_action_get_file (action));
ianjuta_file_loader_load (loader, file, FALSE, NULL);
g_object_unref (file);
Modified: trunk/plugins/project-wizard/install.h
==============================================================================
--- trunk/plugins/project-wizard/install.h (original)
+++ trunk/plugins/project-wizard/install.h Wed Dec 24 18:06:10 2008
@@ -34,7 +34,7 @@
NPWInstall* npw_install_new (struct _NPWPlugin* plugin);
void npw_install_free (NPWInstall* this);
-gboolean npw_install_set_property (NPWInstall* this, NPWValueHeap* values);
+gboolean npw_install_set_property (NPWInstall* this, GHashTable* values);
gboolean npw_install_set_wizard_file (NPWInstall* this, const gchar* filename);
gboolean npw_install_launch (NPWInstall* this);
Modified: trunk/plugins/project-wizard/parser.c
==============================================================================
--- trunk/plugins/project-wizard/parser.c (original)
+++ trunk/plugins/project-wizard/parser.c Wed Dec 24 18:06:10 2008
@@ -32,10 +32,11 @@
#include <string.h>
#include <stdarg.h>
+#include <libanjuta/anjuta-debug.h>
+
/*---------------------------------------------------------------------------*/
#define PROJECT_WIZARD_EXTENSION ".wiz"
-#define STRING_CHUNK_SIZE 256
typedef enum {
NPW_NO_TAG = 0,
@@ -96,13 +97,13 @@
*---------------------------------------------------------------------------*/
gboolean
-npw_header_list_readdir (NPWHeaderList* this, const gchar* path)
+npw_header_list_readdir (GList** list, const gchar* path)
{
GDir* dir;
const gchar* name;
gboolean ok = FALSE;
- g_return_val_if_fail (this != NULL, FALSE);
+ g_return_val_if_fail (list != NULL, FALSE);
g_return_val_if_fail (path != NULL, FALSE);
/* Read all project template files */
@@ -116,14 +117,14 @@
if (g_file_test (filename, G_FILE_TEST_IS_DIR))
{
/* Search recursively in sub directory */
- if (npw_header_list_readdir (this, filename))
+ if (npw_header_list_readdir (list, filename))
{
ok = TRUE;
}
}
else if (g_str_has_suffix (name, PROJECT_WIZARD_EXTENSION))
{
- if (npw_header_list_read (this, filename))
+ if (npw_header_list_read (list, filename))
{
/* Read at least one project file */
ok = TRUE;
@@ -351,7 +352,7 @@
/* Unknown element stack */
guint unknown;
/* List where should be added the header */
- NPWHeaderList* list;
+ GList** list;
/* Current header */
NPWHeader* header;
/* Name of file read */
@@ -382,7 +383,7 @@
switch (tag)
{
case NPW_PROJECT_WIZARD_TAG:
- parser->header = npw_header_new (parser->list);
+ parser->header = npw_header_new ();
npw_header_set_filename (parser->header, parser->filename);
known = TRUE;
break;
@@ -528,6 +529,7 @@
if (npw_header_get_category (parser->header) == NULL)
{
npw_header_set_category (parser->header, text);
+ *parser->list = npw_header_list_insert_header (*parser->list, parser->header);
}
else
{
@@ -560,62 +562,62 @@
};
static NPWHeaderParser*
-npw_header_parser_new (NPWHeaderList* list, const gchar* filename)
+npw_header_parser_new (GList** list, const gchar* filename)
{
- NPWHeaderParser* this;
+ NPWHeaderParser* parser;
g_return_val_if_fail (list != NULL, NULL);
g_return_val_if_fail (filename != NULL, NULL);
- this = g_new0 (NPWHeaderParser, 1);
+ parser = g_new0 (NPWHeaderParser, 1);
- this->type = NPW_HEADER_PARSER;
- this->unknown = 0;
- this->tag[0] = NPW_NO_TAG;
- this->last = this->tag;
- this->list = list;
- this->header = NULL;
- this->filename = g_strdup (filename);
+ parser->type = NPW_HEADER_PARSER;
+ parser->unknown = 0;
+ parser->tag[0] = NPW_NO_TAG;
+ parser->last = parser->tag;
+ parser->list = list;
+ parser->header = NULL;
+ parser->filename = g_strdup (filename);
- this->ctx = g_markup_parse_context_new (&header_markup_parser, 0, this, NULL);
- g_assert (this->ctx != NULL);
+ parser->ctx = g_markup_parse_context_new (&header_markup_parser, 0, parser, NULL);
+ g_assert (parser->ctx != NULL);
- return this;
+ return parser;
}
static void
-npw_header_parser_free (NPWHeaderParser* this)
+npw_header_parser_free (NPWHeaderParser* parser)
{
- g_return_if_fail (this != NULL);
+ g_return_if_fail (parser != NULL);
- g_free (this->filename);
- g_markup_parse_context_free (this->ctx);
- g_free (this);
+ g_free (parser->filename);
+ g_markup_parse_context_free (parser->ctx);
+ g_free (parser);
}
static gboolean
-npw_header_parser_parse (NPWHeaderParser* this, const gchar* text, gssize len, GError** error)
+npw_header_parser_parse (NPWHeaderParser* parser, const gchar* text, gssize len, GError** error)
{
- return g_markup_parse_context_parse (this->ctx, text, len, error);
+ return g_markup_parse_context_parse (parser->ctx, text, len, error);
}
/* Not used
static gboolean
-npw_header_parser_end_parse (NPWHeaderParser* this, GError** error)
+npw_header_parser_end_parse (NPWHeaderParser* parser, GError** error)
{
- return g_markup_parse_context_end_parse (this->ctx, error);
+ return g_markup_parse_context_end_parse (parser->ctx, error);
}*/
gboolean
-npw_header_list_read (NPWHeaderList* this, const gchar* filename)
+npw_header_list_read (GList** list, const gchar* filename)
{
gchar* content;
gsize len;
NPWHeaderParser* parser;
GError* err = NULL;
- g_return_val_if_fail (this != NULL, FALSE);
+ g_return_val_if_fail (list != NULL, FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
if (!g_file_get_contents (filename, &content, &len, &err))
@@ -626,7 +628,7 @@
return FALSE;
}
- parser = npw_header_parser_new (this, filename);
+ parser = npw_header_parser_new (list, filename);
npw_header_parser_parse (parser, content, len, &err);
/* Parse only a part of the file, so need to call parser_end_parse */
@@ -680,14 +682,14 @@
};
static gboolean
-parse_page (NPWPageParser* this,
+parse_page (NPWPageParser* parser,
const gchar** attributes,
const gchar** values)
{
- if (this->count != 0)
+ if (parser->count != 0)
{
/* Skip this page */
- if (this->count > 0) this->count--;
+ if (parser->count > 0) parser->count--;
return FALSE;
}
@@ -699,70 +701,71 @@
switch (parse_attribute (*attributes))
{
case NPW_NAME_ATTRIBUTE:
- npw_page_set_name (this->page, *values);
+ npw_page_set_name (parser->page, *values);
break;
case NPW_LABEL_ATTRIBUTE:
- npw_page_set_label (this->page, *values);
+ npw_page_set_label (parser->page, *values);
break;
case NPW_DESCRIPTION_ATTRIBUTE:
- npw_page_set_description (this->page, *values);
+ npw_page_set_description (parser->page, *values);
break;
default:
- parser_warning (this->ctx, "Unknown page attribute \"%s\"", *attributes);
+ parser_warning (parser->ctx, "Unknown page attribute \"%s\"", *attributes);
break;
}
attributes++;
values++;
}
- this->count--;
+ parser->count--;
return TRUE;
}
}
static gboolean
-parse_property (NPWPageParser* this,
+parse_property (NPWPageParser* parser,
const gchar** attributes,
const gchar** values)
{
- this->property = npw_property_new (this->page);
+ parser->property = npw_property_new ();
+ npw_page_add_property (parser->page, parser->property);
while (*attributes != NULL)
{
switch (parse_attribute (*attributes))
{
case NPW_TYPE_ATTRIBUTE:
- npw_property_set_string_type (this->property, *values);
+ npw_property_set_string_type (parser->property, *values);
break;
case NPW_RESTRICTION_ATTRIBUTE:
- npw_property_set_string_restriction (this->property, *values);
+ npw_property_set_string_restriction (parser->property, *values);
break;
case NPW_NAME_ATTRIBUTE:
- npw_property_set_name (this->property, *values);
+ npw_property_set_name (parser->property, *values, parser->page);
break;
case NPW_LABEL_ATTRIBUTE:
- npw_property_set_label (this->property, *values);
+ npw_property_set_label (parser->property, *values);
break;
case NPW_DESCRIPTION_ATTRIBUTE:
- npw_property_set_description (this->property, *values);
+ npw_property_set_description (parser->property, *values);
break;
case NPW_VALUE_ATTRIBUTE:
- npw_property_set_default (this->property, *values);
+ npw_property_set_default (parser->property, *values);
break;
case NPW_SUMMARY_ATTRIBUTE:
- npw_property_set_summary_option (this->property, parse_boolean_string (*values));
+ npw_property_set_summary_option (parser->property, parse_boolean_string (*values));
break;
case NPW_MANDATORY_ATTRIBUTE:
- npw_property_set_mandatory_option (this->property, parse_boolean_string (*values));
+ npw_property_set_mandatory_option (parser->property, parse_boolean_string (*values));
break;
case NPW_EDITABLE_ATTRIBUTE:
- npw_property_set_editable_option (this->property, parse_boolean_string (*values));
+ npw_property_set_editable_option (parser->property, parse_boolean_string (*values));
break;
case NPW_EXIST_ATTRIBUTE:
- npw_property_set_exist_option (this->property, parse_boolean_string (*values));
+ npw_property_set_exist_option (parser->property, parse_boolean_string (*values));
break;
default:
- parser_warning (this->ctx, "Unknown property attribute \"%s\"", *attributes);
+ parser_warning (parser->ctx, "Unknown property attribute \"%s\"", *attributes);
break;
}
attributes++;
@@ -773,7 +776,7 @@
}
static gboolean
-parse_item (NPWPageParser* this,
+parse_item (NPWPageParser* parser,
const gchar** attributes,
const gchar** values)
{
@@ -791,7 +794,7 @@
label = *values;
break;
default:
- parser_warning (this->ctx, "Unknown item attribute \"%s\"", *attributes);
+ parser_warning (parser->ctx, "Unknown item attribute \"%s\"", *attributes);
break;
}
attributes++;
@@ -800,11 +803,11 @@
if (name == NULL)
{
- parser_warning (this->ctx, "Missing name attribute");
+ parser_warning (parser->ctx, "Missing name attribute");
}
else
{
- npw_property_add_list_item (this->property, name, label == NULL ? name : label);
+ npw_property_add_list_item (parser->property, name, label == NULL ? name : label);
}
return TRUE;
@@ -923,59 +926,59 @@
NPWPageParser*
npw_page_parser_new (NPWPage* page, const gchar* filename, gint count)
{
- NPWPageParser* this;
+ NPWPageParser* parser;
g_return_val_if_fail (page != NULL, NULL);
g_return_val_if_fail (count >= 0, NULL);
- this = g_new (NPWPageParser, 1);
+ parser = g_new (NPWPageParser, 1);
- this->type = NPW_PAGE_PARSER;
+ parser->type = NPW_PAGE_PARSER;
- this->unknown = 0;
- this->tag[0] = NPW_NO_TAG;
- this->last = this->tag;
+ parser->unknown = 0;
+ parser->tag[0] = NPW_NO_TAG;
+ parser->last =parser->tag;
- this->count = count;
- this->page = page;
- this->property = NULL;
+ parser->count = count;
+ parser->page = page;
+ parser->property = NULL;
- this->ctx = g_markup_parse_context_new (&page_markup_parser, 0, this, NULL);
- g_assert (this->ctx != NULL);
+ parser->ctx = g_markup_parse_context_new (&page_markup_parser, 0, parser, NULL);
+ g_assert (parser->ctx != NULL);
- return this;
+ return parser;
}
void
-npw_page_parser_free (NPWPageParser* this)
+npw_page_parser_free (NPWPageParser* parser)
{
- g_return_if_fail (this != NULL);
+ g_return_if_fail (parser != NULL);
- g_markup_parse_context_free (this->ctx);
- g_free (this);
+ g_markup_parse_context_free (parser->ctx);
+ g_free (parser);
}
gboolean
-npw_page_parser_parse (NPWPageParser* this, const gchar* text, gssize len, GError** error)
+npw_page_parser_parse (NPWPageParser* parser, const gchar* text, gssize len, GError** error)
{
- return g_markup_parse_context_parse (this->ctx, text, len, error);
+ return g_markup_parse_context_parse (parser->ctx, text, len, error);
}
gboolean
-npw_page_parser_end_parse (NPWPageParser* this, GError** error)
+npw_page_parser_end_parse (NPWPageParser* parser, GError** error)
{
- return g_markup_parse_context_end_parse (this->ctx, error);
+ return g_markup_parse_context_end_parse (parser->ctx, error);
}
gboolean
-npw_page_read (NPWPage* this, const gchar* filename, gint count)
+npw_page_read (NPWPage* page, const gchar* filename, gint count)
{
gchar* content;
gsize len;
NPWPageParser* parser;
GError* err = NULL;
- g_return_val_if_fail (this != NULL, FALSE);
+ g_return_val_if_fail (page != NULL, FALSE);
g_return_val_if_fail (filename != NULL, FALSE);
g_return_val_if_fail (count < 0, FALSE);
@@ -987,7 +990,7 @@
return FALSE;
}
- parser = npw_page_parser_new (this, filename, count);
+ parser = npw_page_parser_new (page, filename, count);
npw_page_parser_parse (parser, content, len, &err);
if (err == NULL) npw_page_parser_end_parse (parser, &err);
@@ -1011,13 +1014,11 @@
/* Parse content block
*---------------------------------------------------------------------------*/
-#define NPW_FILE_PARSER_DEFAULT_LEVEL 4 /* Default number of nested elements
- * Dynamically allocated (no maximum) */
typedef struct _NPWFileTag
{
NPWTag tag;
- const gchar* destination;
- const gchar* source;
+ gchar* destination;
+ gchar* source;
} NPWFileTag;
struct _NPWFileListParser
@@ -1027,15 +1028,20 @@
GMarkupParseContext* ctx;
/* Known element stack */
GQueue* tag;
- GStringChunk* str_pool;
- GMemChunk* tag_pool;
- NPWFileTag root;
/* Unknown element stack */
guint unknown;
/* Current file list */
- NPWFileList* list;
+ GList* list;
};
+static void
+npw_file_tag_free (NPWFileTag *tag)
+{
+ g_free (tag->destination);
+ g_free (tag->source);
+ g_slice_free (NPWFileTag, tag);
+}
+
/* concatenate two directories names, return value must be freed if
* not equal to path1 or path2 */
@@ -1085,7 +1091,7 @@
}
static void
-parse_directory (NPWFileListParser* this, NPWFileTag* child, const gchar** attributes, const gchar** values)
+parse_directory (NPWFileListParser* parser, NPWFileTag* child, const gchar** attributes, const gchar** values)
{
const gchar* source;
const gchar* destination;
@@ -1107,7 +1113,7 @@
destination = *values;
break;
default:
- parser_warning (this->ctx, "Unknow directory attribute \"%s\"", *attributes);
+ parser_warning (parser->ctx, "Unknow directory attribute \"%s\"", *attributes);
break;
}
attributes++;
@@ -1125,7 +1131,7 @@
}
else if ((source == NULL) && (destination == NULL))
{
- parser_warning (this->ctx, "Missing source or destination attribute");
+ parser_warning (parser->ctx, "Missing source or destination attribute");
child->tag = NPW_NO_TAG;
return;
@@ -1134,34 +1140,45 @@
path = concat_directory (child->source, source);
if (path == NULL)
{
- parser_warning (this->ctx, "Invalid directory source value \"%s\"", source);
+ parser_warning (parser->ctx, "Invalid directory source value \"%s\"", source);
child->tag = NPW_NO_TAG;
return;
}
- if (path != child->source)
+ if (path == source)
+ {
+ g_free (child->source);
+ child->source = g_strdup (path);
+ }
+ else if (path != child->source)
{
- child->source = g_string_chunk_insert (this->str_pool, path);
- if (path != source) g_free (path);
+ g_free (child->source);
+ child->source = path;
}
+
path = concat_directory (child->destination, destination);
if (path == NULL)
{
- parser_warning (this->ctx, "Invalid directory destination value \"%s\"", source);
+ parser_warning (parser->ctx, "Invalid directory destination value \"%s\"", source);
child->tag = NPW_NO_TAG;
return;
}
- if (path != child->destination)
+ if (path == destination)
{
- child->destination = g_string_chunk_insert (this->str_pool, path);
- if (path != destination) g_free (path);
+ g_free (child->destination);
+ child->destination = g_strdup (path);
+ }
+ else if (path != child->destination)
+ {
+ g_free (child->destination);
+ child->destination = path;
}
}
static void
-parse_file (NPWFileListParser* this, NPWFileTag* child, const gchar** attributes, const gchar** values)
+parse_file (NPWFileListParser* parser, NPWFileTag* child, const gchar** attributes, const gchar** values)
{
const gchar* source;
const gchar* destination;
@@ -1202,7 +1219,7 @@
autogen_set = TRUE;
break;
default:
- parser_warning (this->ctx, "Unknow file attribute \"%s\"", *attributes);
+ parser_warning (parser->ctx, "Unknow file attribute \"%s\"", *attributes);
break;
}
attributes++;
@@ -1219,7 +1236,7 @@
}
else if ((source == NULL) && (destination == NULL))
{
- parser_warning (this->ctx, "Missing source or destination attribute");
+ parser_warning (parser->ctx, "Missing source or destination attribute");
child->tag = NPW_NO_TAG;
return;
@@ -1228,24 +1245,22 @@
full_source = concat_directory (child->source, source);
if ((full_source == NULL) || (full_source == child->source))
{
- parser_warning (this->ctx, "Invalid file source value \"%s\"", source);
+ parser_warning (parser->ctx, "Invalid file source value \"%s\"", source);
child->tag = NPW_NO_TAG;
return;
}
full_destination = concat_directory (child->destination, destination);
- if ((full_destination == NULL) || (full_destination == child->source))
+ if ((full_destination == NULL) || (full_destination == child->destination))
{
- parser_warning (this->ctx, "Invalid directory destination value \"%s\"", source);
+ parser_warning (parser->ctx, "Invalid directory destination value \"%s\"", source);
child->tag = NPW_NO_TAG;
return;
}
- file = npw_file_new (this->list);
- npw_file_set_type (file, NPW_FILE);
- npw_file_set_source (file, full_source);
- npw_file_set_destination (file, full_destination);
+ file = npw_file_new_file (full_destination, full_source);
+ parser->list = g_list_prepend (parser->list, file);
npw_file_set_execute (file, execute);
npw_file_set_project (file, project);
if (autogen_set)
@@ -1271,6 +1286,8 @@
NPWFileTag child;
child.tag = NPW_NO_TAG;
+ child.source = NULL;
+ child.destination = NULL;
/* Recognize element */
if (parser->unknown == 0)
@@ -1279,8 +1296,8 @@
tag = parse_tag (name);
parent = g_queue_peek_head (parser->tag);
- child.source = parent->source;
- child.destination = parent->destination;
+ child.source = g_strdup (parent->source);
+ child.destination = g_strdup (parent->destination);
switch (parent->tag)
{
case NPW_NO_TAG:
@@ -1336,12 +1353,14 @@
{
NPWFileTag* new_child;
- new_child = g_chunk_new (NPWFileTag, parser->tag_pool);
+ new_child = g_slice_new (NPWFileTag);
memcpy (new_child, &child, sizeof (child));
g_queue_push_head (parser->tag, new_child);
}
else
{
+ g_free (child.source);
+ g_free (child.destination);
parser->unknown++;
}
}
@@ -1354,6 +1373,7 @@
{
NPWFileListParser* parser = (NPWFileListParser*)data;
+ DEBUG_PRINT("parser_file_end");
if (parser->unknown > 0)
{
/* Pop unknown element */
@@ -1362,7 +1382,7 @@
else if (((NPWFileTag *)g_queue_peek_head (parser->tag))->tag != NPW_NO_TAG)
{
/* Pop known element */
- g_mem_chunk_free (parser->tag_pool, g_queue_pop_head (parser->tag));
+ npw_file_tag_free (g_queue_pop_head (parser->tag));
}
else
{
@@ -1380,99 +1400,67 @@
};
NPWFileListParser*
-npw_file_list_parser_new (NPWFileList* list, const gchar* filename)
+npw_file_list_parser_new (const gchar* filename)
{
- NPWFileListParser* this;
- gchar* path;
+ NPWFileListParser* parser;
+ NPWFileTag* root;
- g_return_val_if_fail (list != NULL, NULL);
g_return_val_if_fail (filename != NULL, NULL);
- this = g_new (NPWFileListParser, 1);
+ parser = g_new (NPWFileListParser, 1);
- this->type = NPW_FILE_PARSER;
+ parser->type = NPW_FILE_PARSER;
- this->unknown = 0;
- this->tag = g_queue_new ();
- this->str_pool = g_string_chunk_new (STRING_CHUNK_SIZE);
- this->tag_pool = g_mem_chunk_new ("file tag pool", sizeof (NPWFileTag), NPW_FILE_PARSER_DEFAULT_LEVEL * sizeof (NPWFileTag) , G_ALLOC_AND_FREE);
- this->root.tag = NPW_NO_TAG;
- this->root.destination = ".";
+ parser->unknown = 0;
+ parser->tag = g_queue_new ();
+ root = g_slice_new0 (NPWFileTag);
+ root->tag = NPW_NO_TAG;
+ root->destination = g_strdup (".");
/* Use .wiz file path as base source directory */
- path = g_path_get_dirname (filename);
- this->root.source = g_string_chunk_insert (this->str_pool, path);
- g_free (path);
- g_queue_push_head (this->tag, &this->root);
+ root->source = g_path_get_dirname (filename);
+ g_queue_push_head (parser->tag, root);
- this->list = list;
+ parser->list = NULL;
- this->ctx = g_markup_parse_context_new (&file_markup_parser, 0, this, NULL);
- g_assert (this->ctx != NULL);
+ parser->ctx = g_markup_parse_context_new (&file_markup_parser, 0, parser, NULL);
+ g_assert (parser->ctx != NULL);
- return this;
+ return parser;
}
void
-npw_file_list_parser_free (NPWFileListParser* this)
+npw_file_list_parser_free (NPWFileListParser* parser)
{
- g_return_if_fail (this != NULL);
+ g_return_if_fail (parser != NULL);
- g_markup_parse_context_free (this->ctx);
- g_string_chunk_free (this->str_pool);
- g_mem_chunk_destroy (this->tag_pool);
- g_queue_free (this->tag);
- g_free (this);
+ g_markup_parse_context_free (parser->ctx);
+ DEBUG_PRINT("parser free");
+ g_queue_foreach (parser->tag, (GFunc)npw_file_tag_free, NULL);
+ DEBUG_PRINT("parser free ok");
+ g_queue_free (parser->tag);
+ g_free (parser);
}
gboolean
-npw_file_list_parser_parse (NPWFileListParser* this, const gchar* text, gssize len, GError** error)
+npw_file_list_parser_parse (NPWFileListParser* parser, const gchar* text, gssize len, GError** error)
{
- return g_markup_parse_context_parse (this->ctx, text, len, error);
+ return g_markup_parse_context_parse (parser->ctx, text, len, error);
}
-gboolean
-npw_file_list_parser_end_parse (NPWFileListParser* this, GError** error)
+GList *
+npw_file_list_parser_end_parse (NPWFileListParser* parser, GError** error)
{
- return g_markup_parse_context_end_parse (this->ctx, error);
-}
-
-gboolean
-npw_file_list_read (NPWFileList* this, const gchar* filename)
-{
- gchar* content;
- gsize len;
- NPWFileListParser* parser;
- GError* err = NULL;
-
- g_return_val_if_fail (this != NULL, FALSE);
- g_return_val_if_fail (filename != NULL, FALSE);
-
- if (!g_file_get_contents (filename, &content, &len, &err))
- {
- g_warning (err->message);
- g_error_free (err);
-
- return FALSE;
- }
-
- parser = npw_file_list_parser_new (this, filename);
-
- npw_file_list_parser_parse (parser, content, len, &err);
- if (err == NULL) npw_file_list_parser_end_parse (parser, &err);
-
- npw_file_list_parser_free (parser);
- g_free (content);
-
- if (err != NULL)
+ GList *list = NULL;
+
+ if (g_markup_parse_context_end_parse (parser->ctx, error))
{
- /* Parsing error */
- g_warning (err->message);
- g_error_free (err);
+ /* Reverse file list */
+ parser->list = g_list_reverse (parser->list);
- return FALSE;
+ list = parser->list;
}
-
- return TRUE;
+
+ return list;
}
/* Parse action block
@@ -1491,11 +1479,11 @@
/* Unknown element stack */
guint unknown;
/* Current action list object */
- NPWActionList* list;
+ GList* list;
};
static gboolean
-parse_run (NPWActionListParser* this, const gchar** attributes, const gchar** values)
+parse_run (NPWActionListParser* parser, const gchar** attributes, const gchar** values)
{
const gchar* command = NULL;
@@ -1507,7 +1495,7 @@
command = *values;
break;
default:
- parser_warning (this->ctx, "Unknown run attribute \"%s\"", *attributes);
+ parser_warning (parser->ctx, "Unknown run attribute \"%s\"", *attributes);
break;
}
attributes++;
@@ -1516,21 +1504,21 @@
if (command == NULL)
{
- parser_warning (this->ctx, "Missing command attribute");
+ parser_warning (parser->ctx, "Missing command attribute");
}
else
{
NPWAction* action;
- action = npw_action_new (this->list, NPW_RUN_ACTION);
- npw_action_set_command (action, command);
+ action = npw_action_new_command (command);
+ parser->list = g_list_prepend (parser->list, action);
}
return TRUE;
}
static gboolean
-parse_open (NPWActionListParser* this, const gchar** attributes, const gchar** values)
+parse_open (NPWActionListParser* parser, const gchar** attributes, const gchar** values)
{
const gchar* file = NULL;
@@ -1542,7 +1530,7 @@
file = *values;
break;
default:
- parser_warning (this->ctx, "Unknown open attribute \"%s\"", *attributes);
+ parser_warning (parser->ctx, "Unknown open attribute \"%s\"", *attributes);
break;
}
attributes++;
@@ -1551,14 +1539,14 @@
if (file == NULL)
{
- parser_warning (this->ctx, "Missing file attribute");
+ parser_warning (parser->ctx, "Missing file attribute");
}
else
{
NPWAction* action;
- action = npw_action_new (this->list, NPW_OPEN_ACTION);
- npw_action_set_file (action, file);
+ action = npw_action_new_file (file);
+ parser->list = g_list_prepend (parser->list, action);
}
return TRUE;
@@ -1659,43 +1647,41 @@
};
NPWActionListParser*
-npw_action_list_parser_new (NPWActionList* list)
+npw_action_list_parser_new (void)
{
- NPWActionListParser* this;
-
- g_return_val_if_fail (list != NULL, NULL);
+ NPWActionListParser* parser;
- this = g_new (NPWActionListParser, 1);
+ parser = g_new (NPWActionListParser, 1);
- this->type = NPW_ACTION_PARSER;
+ parser->type = NPW_ACTION_PARSER;
- this->unknown = 0;
- this->tag[0] = NPW_NO_TAG;
- this->last = this->tag;
+ parser->unknown = 0;
+ parser->tag[0] = NPW_NO_TAG;
+ parser->last = parser->tag;
- this->list = list;
+ parser->list = NULL;
- this->ctx = g_markup_parse_context_new (&action_markup_parser, 0, this, NULL);
- g_assert (this->ctx != NULL);
+ parser->ctx = g_markup_parse_context_new (&action_markup_parser, 0, parser, NULL);
+ g_assert (parser->ctx != NULL);
- return this;
+ return parser;
}
void
-npw_action_list_parser_free (NPWActionListParser* this)
+npw_action_list_parser_free (NPWActionListParser* parser)
{
- g_return_if_fail (this != NULL);
+ g_return_if_fail (parser != NULL);
- g_markup_parse_context_free (this->ctx);
- g_free (this);
+ g_markup_parse_context_free (parser->ctx);
+ g_free (parser);
}
gboolean
-npw_action_list_parser_parse (NPWActionListParser* this, const gchar* text, gssize len, GError** error)
+npw_action_list_parser_parse (NPWActionListParser* parser, const gchar* text, gssize len, GError** error)
{
GError* err = NULL;
- g_markup_parse_context_parse (this->ctx, text, len, &err);
+ g_markup_parse_context_parse (parser->ctx, text, len, &err);
if (err != NULL)
{
g_warning (err->message);
@@ -1704,8 +1690,18 @@
return TRUE;
}
-gboolean
-npw_action_list_parser_end_parse (NPWActionListParser* this, GError** error)
+GList*
+npw_action_list_parser_end_parse (NPWActionListParser* parser, GError** error)
{
- return g_markup_parse_context_end_parse (this->ctx, error);
+ GList *list = NULL;
+
+ if (g_markup_parse_context_end_parse (parser->ctx, error))
+ {
+ /* Reverse file list */
+ parser->list = g_list_reverse (parser->list);
+
+ list = parser->list;
+ }
+
+ return list;
}
Modified: trunk/plugins/project-wizard/parser.h
==============================================================================
--- trunk/plugins/project-wizard/parser.h (original)
+++ trunk/plugins/project-wizard/parser.h Wed Dec 24 18:06:10 2008
@@ -28,39 +28,37 @@
#include "file.h"
#include "action.h"
-gboolean npw_header_list_readdir (NPWHeaderList* this, const gchar* pathname);
+gboolean npw_header_list_readdir (GList** this, const gchar* pathname);
-gboolean npw_header_list_read (NPWHeaderList* this, const gchar* filename);
+gboolean npw_header_list_read (GList** this, const gchar* filename);
typedef struct _NPWPageParser NPWPageParser;
NPWPageParser* npw_page_parser_new (NPWPage* page, const gchar* filename, gint count);
-void npw_page_parser_free (NPWPageParser* this);
+void npw_page_parser_free (NPWPageParser* parser);
-gboolean npw_page_parser_parse (NPWPageParser* this, const gchar* text, gssize len, GError** error);
-gboolean npw_page_parser_end_parse (NPWPageParser* this, GError** error);
+gboolean npw_page_parser_parse (NPWPageParser* parser, const gchar* text, gssize len, GError** error);
+gboolean npw_page_parser_end_parse (NPWPageParser* parser, GError** error);
-gboolean npw_page_read (NPWPage* this, const gchar* filename, gint count);
+gboolean npw_page_read (NPWPage* page, const gchar* filename, gint count);
typedef struct _NPWFileListParser NPWFileListParser;
-NPWFileListParser* npw_file_list_parser_new (NPWFileList* list, const gchar* filename);
-void npw_file_list_parser_free (NPWFileListParser* this);
+NPWFileListParser* npw_file_list_parser_new (const gchar* filename);
+void npw_file_list_parser_free (NPWFileListParser* parser);
-gboolean npw_file_list_parser_parse (NPWFileListParser* this, const gchar* text, gssize len, GError** error);
-gboolean npw_file_list_parser_end_parse (NPWFileListParser* this, GError** error);
-
-gboolean npw_file_list_read (NPWFileList* this, const gchar* filename);
+gboolean npw_file_list_parser_parse (NPWFileListParser* parser, const gchar* text, gssize len, GError** error);
+GList* npw_file_list_parser_end_parse (NPWFileListParser* parser, GError** error);
typedef struct _NPWActionListParser NPWActionListParser;
-NPWActionListParser* npw_action_list_parser_new (NPWActionList* list);
-void npw_action_list_parser_free (NPWActionListParser* this);
+NPWActionListParser* npw_action_list_parser_new (void);
+void npw_action_list_parser_free (NPWActionListParser* parser);
-gboolean npw_action_list_parser_parse (NPWActionListParser* this, const gchar* text, gssize len, GError** error);
-gboolean npw_action_list_parser_end_parse (NPWActionListParser* this, GError** error);
+gboolean npw_action_list_parser_parse (NPWActionListParser* parser, const gchar* text, gssize len, GError** error);
+GList* npw_action_list_parser_end_parse (NPWActionListParser* parser, GError** error);
#endif
Modified: trunk/plugins/project-wizard/plugin.c
==============================================================================
--- trunk/plugins/project-wizard/plugin.c (original)
+++ trunk/plugins/project-wizard/plugin.c Wed Dec 24 18:06:10 2008
@@ -40,11 +40,11 @@
static void
npw_plugin_instance_init (GObject *obj)
{
- NPWPlugin *this = ANJUTA_PLUGIN_NPW (obj);
+ NPWPlugin *plugin = ANJUTA_PLUGIN_NPW (obj);
- this->druid = NULL;
- this->install = NULL;
- this->view = NULL;
+ plugin->druid = NULL;
+ plugin->install = NULL;
+ plugin->view = NULL;
}
/* dispose is used to unref object created with instance_init */
@@ -52,14 +52,14 @@
static void
npw_plugin_dispose (GObject *obj)
{
- NPWPlugin *this = ANJUTA_PLUGIN_NPW (obj);
+ NPWPlugin *plugin = ANJUTA_PLUGIN_NPW (obj);
/* Warning this function could be called several times */
- if (this->view != NULL)
+ if (plugin->view != NULL)
{
- g_object_remove_weak_pointer (G_OBJECT (this->view),
- (gpointer*)(gpointer)&this->view);
- this->view = NULL;
+ g_object_remove_weak_pointer (G_OBJECT (plugin->view),
+ (gpointer*)(gpointer)&plugin->view);
+ plugin->view = NULL;
}
G_OBJECT_CLASS (parent_class)->dispose (obj);
@@ -103,22 +103,22 @@
static void
iwizard_activate (IAnjutaWizard *wiz, GError **err)
{
- NPWPlugin *this = ANJUTA_PLUGIN_NPW (wiz);
+ NPWPlugin *plugin = ANJUTA_PLUGIN_NPW (wiz);
- if (this->install != NULL)
+ if (plugin->install != NULL)
{
/* New project wizard is busy copying project file */
}
- else if (this->druid == NULL)
+ else if (plugin->druid == NULL)
{
/* Create a new project wizard druid */
- npw_druid_new (this);
+ npw_druid_new (plugin);
}
- if (this->druid != NULL)
+ if (plugin->druid != NULL)
{
/* New project wizard druid is waiting for user inputs */
- npw_druid_show (this->druid);
+ npw_druid_show (plugin->druid);
}
}
@@ -139,54 +139,54 @@
static void
on_message_buffer_flush (IAnjutaMessageView *view, const gchar *line,
- NPWPlugin *this)
+ NPWPlugin *plugin)
{
- npw_plugin_print_view (this, IANJUTA_MESSAGE_VIEW_TYPE_NORMAL, line, "");
+ npw_plugin_print_view (plugin, IANJUTA_MESSAGE_VIEW_TYPE_NORMAL, line, "");
}
IAnjutaMessageView*
-npw_plugin_create_view (NPWPlugin* this)
+npw_plugin_create_view (NPWPlugin* plugin)
{
- if (this->view == NULL)
+ if (plugin->view == NULL)
{
IAnjutaMessageManager* man;
- man = anjuta_shell_get_interface (ANJUTA_PLUGIN (this)->shell,
+ man = anjuta_shell_get_interface (ANJUTA_PLUGIN (plugin)->shell,
IAnjutaMessageManager, NULL);
- this->view =
+ plugin->view =
ianjuta_message_manager_add_view (man, _("New Project Assistant"),
ICON_FILE, NULL);
- if (this->view != NULL)
+ if (plugin->view != NULL)
{
- g_signal_connect (G_OBJECT (this->view), "buffer_flushed",
- G_CALLBACK (on_message_buffer_flush), this);
- g_object_add_weak_pointer (G_OBJECT (this->view),
- (gpointer *)(gpointer)&this->view);
+ g_signal_connect (G_OBJECT (plugin->view), "buffer_flushed",
+ G_CALLBACK (on_message_buffer_flush), plugin);
+ g_object_add_weak_pointer (G_OBJECT (plugin->view),
+ (gpointer *)(gpointer)&plugin->view);
}
}
else
{
- ianjuta_message_view_clear (this->view, NULL);
+ ianjuta_message_view_clear (plugin->view, NULL);
}
- return this->view;
+ return plugin->view;
}
void
-npw_plugin_append_view (NPWPlugin* this, const gchar* text)
+npw_plugin_append_view (NPWPlugin* plugin, const gchar* text)
{
- if (this->view)
+ if (plugin->view)
{
- ianjuta_message_view_buffer_append (this->view, text, NULL);
+ ianjuta_message_view_buffer_append (plugin->view, text, NULL);
}
}
void
-npw_plugin_print_view (NPWPlugin* this, IAnjutaMessageViewType type,
+npw_plugin_print_view (NPWPlugin* plugin, IAnjutaMessageViewType type,
const gchar* summary, const gchar* details)
{
- if (this->view)
+ if (plugin->view)
{
- ianjuta_message_view_append (this->view, type, summary, details, NULL);
+ ianjuta_message_view_append (plugin->view, type, summary, details, NULL);
}
}
Modified: trunk/plugins/project-wizard/plugin.h
==============================================================================
--- trunk/plugins/project-wizard/plugin.h (original)
+++ trunk/plugins/project-wizard/plugin.h Wed Dec 24 18:06:10 2008
@@ -48,8 +48,8 @@
AnjutaPluginClass parent_class;
};
-IAnjutaMessageView* npw_plugin_create_view (NPWPlugin* this);
-void npw_plugin_append_view (NPWPlugin* this, const gchar* text);
-void npw_plugin_print_view (NPWPlugin* this, IAnjutaMessageViewType type, const gchar* summary, const gchar* details);
+IAnjutaMessageView* npw_plugin_create_view (NPWPlugin* plugin);
+void npw_plugin_append_view (NPWPlugin* plugin, const gchar* text);
+void npw_plugin_print_view (NPWPlugin* plugin, IAnjutaMessageViewType type, const gchar* summary, const gchar* details);
#endif
Modified: trunk/plugins/project-wizard/property.c
==============================================================================
--- trunk/plugins/project-wizard/property.c (original)
+++ trunk/plugins/project-wizard/property.c Wed Dec 24 18:06:10 2008
@@ -31,7 +31,7 @@
#include <gnome.h>
#include <glib/gi18n.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
+#include <gio/gio.h>
#include <string.h>
#include <stdlib.h>
@@ -42,17 +42,10 @@
/*---------------------------------------------------------------------------*/
-#define STRING_CHUNK_SIZE 256
-
-/*---------------------------------------------------------------------------*/
-
struct _NPWPage
{
- GNode* list;
- GStringChunk* string_pool;
- GMemChunk* data_pool;
- GMemChunk* item_pool;
- NPWValueHeap* value;
+ GList* properties;
+ GHashTable* values;
gchar* name;
gchar* label;
gchar* description;
@@ -67,13 +60,12 @@
gchar* defvalue;
NPWValue* value;
GtkWidget* widget;
- NPWPage* owner;
- GSList* item;
+ GSList* items;
};
struct _NPWItem {
- const gchar* name;
- const gchar* label;
+ gchar* name;
+ gchar* label;
};
static const gchar* NPWPropertyTypeString[] = {
@@ -91,6 +83,29 @@
"filename"
};
+/* Item object
+ *---------------------------------------------------------------------------*/
+
+static NPWItem*
+npw_item_new (const gchar *name, const gchar *label)
+{
+ NPWItem *item;
+
+ item = g_slice_new (NPWItem);
+ item->name = g_strdup (name);
+ item->label = g_strdup (label);
+
+ return item;
+}
+
+static void
+npw_item_free (NPWItem *item)
+{
+ g_free (item->name);
+ g_free (item->label);
+ g_slice_free (NPWItem, item);
+}
+
/* Property object
*---------------------------------------------------------------------------*/
@@ -131,86 +146,78 @@
}
NPWProperty*
-npw_property_new (NPWPage* owner)
+npw_property_new (void)
{
- NPWProperty* this;
-
- g_return_val_if_fail (owner, NULL);
+ NPWProperty* prop;
- this = g_chunk_new0(NPWProperty, owner->data_pool);
- this->owner = owner;
- this->type = NPW_UNKNOWN_PROPERTY;
- this->restriction = NPW_NO_RESTRICTION;
- this->item = NULL;
+ prop = g_slice_new0(NPWProperty);
+ prop->type = NPW_UNKNOWN_PROPERTY;
+ prop->restriction = NPW_NO_RESTRICTION;
/* value is set to NULL */
- g_node_append_data (owner->list, this);
- return this;
+ return prop;
}
void
-npw_property_free (NPWProperty* this)
+npw_property_free (NPWProperty* prop)
{
- GNode* node;
-
- if (this->item != NULL)
+ if (prop->items != NULL)
{
- g_slist_free (this->item);
- }
- node = g_node_find_child (this->owner->list, G_TRAVERSE_ALL, this);
- if (node != NULL)
- {
- g_node_destroy (node);
- /* Memory allocated in string pool and data pool is not free */
+ g_slist_foreach (prop->items, (GFunc)npw_item_free, NULL);
+ g_slist_free (prop->items);
}
+ g_free (prop->label);
+ g_free (prop->description);
+ g_free (prop->defvalue);
+ g_slice_free (NPWProperty, prop);
}
void
-npw_property_set_type (NPWProperty* this, NPWPropertyType type)
+npw_property_set_type (NPWProperty* prop, NPWPropertyType type)
{
- this->type = type;
+ prop->type = type;
}
void
-npw_property_set_string_type (NPWProperty* this, const gchar* type)
+npw_property_set_string_type (NPWProperty* prop, const gchar* type)
{
- npw_property_set_type (this, npw_property_type_from_string (type));
+ npw_property_set_type (prop, npw_property_type_from_string (type));
}
NPWPropertyType
-npw_property_get_type (const NPWProperty* this)
+npw_property_get_type (const NPWProperty* prop)
{
- return this->type;
+ return prop->type;
}
void
-npw_property_set_restriction (NPWProperty* this, NPWPropertyRestriction restriction)
+npw_property_set_restriction (NPWProperty* prop, NPWPropertyRestriction restriction)
{
- this->restriction = restriction;
+ prop->restriction = restriction;
}
void
-npw_property_set_string_restriction (NPWProperty* this, const gchar* restriction)
+npw_property_set_string_restriction (NPWProperty* prop, const gchar* restriction)
{
- npw_property_set_restriction (this, npw_property_restriction_from_string (restriction));
+ npw_property_set_restriction (prop, npw_property_restriction_from_string (restriction));
}
NPWPropertyRestriction
-npw_property_get_restriction (const NPWProperty* this)
+npw_property_get_restriction (const NPWProperty* prop)
{
- return this->restriction;
+ return prop->restriction;
}
gboolean
-npw_property_is_valid_restriction (const NPWProperty* this)
+npw_property_is_valid_restriction (const NPWProperty* prop)
{
const gchar *value;
- switch (this->restriction)
+ switch (prop->restriction)
{
case NPW_FILENAME_RESTRICTION:
- value = npw_property_get_value (this);
+ value = npw_property_get_value (prop);
/* First character should be letters, digit or '_' */
if (value == NULL) return TRUE;
@@ -236,39 +243,39 @@
}
void
-npw_property_set_name (NPWProperty* this, const gchar* name)
+npw_property_set_name (NPWProperty* prop, const gchar* name, NPWPage *page)
{
- this->value = npw_value_heap_find_value (this->owner->value, name);
+ prop->value = npw_value_heap_find_value (page->values, name);
}
const gchar*
-npw_property_get_name (const NPWProperty* this)
+npw_property_get_name (const NPWProperty* prop)
{
- return npw_value_heap_get_name (this->owner->value, this->value);
+ return npw_value_get_name (prop->value);
}
void
-npw_property_set_label (NPWProperty* this, const gchar* label)
+npw_property_set_label (NPWProperty* prop, const gchar* label)
{
- this->label = g_string_chunk_insert (this->owner->string_pool, label);
+ prop->label = g_strdup (label);
}
const gchar*
-npw_property_get_label (const NPWProperty* this)
+npw_property_get_label (const NPWProperty* prop)
{
- return this->label;
+ return prop->label;
}
void
-npw_property_set_description (NPWProperty* this, const gchar* description)
+npw_property_set_description (NPWProperty* prop, const gchar* description)
{
- this->description = g_string_chunk_insert (this->owner->string_pool, description);
+ prop->description = g_strdup (description);
}
const gchar*
-npw_property_get_description (const NPWProperty* this)
+npw_property_get_description (const NPWProperty* prop)
{
- return this->description;
+ return prop->description;
}
static void
@@ -319,14 +326,14 @@
}
GtkWidget*
-npw_property_create_widget (NPWProperty* this)
+npw_property_create_widget (NPWProperty* prop)
{
GtkWidget* widget = NULL;
GtkWidget* entry;
const gchar* value;
- value = npw_property_get_value (this);
- switch (this->type)
+ value = npw_property_get_value (prop);
+ switch (prop->type)
{
case NPW_BOOLEAN_PROPERTY:
entry = gtk_toggle_button_new_with_label (_("No"));
@@ -351,7 +358,7 @@
break;
case NPW_DIRECTORY_PROPERTY:
case NPW_FILE_PROPERTY:
- if ((this->options & NPW_EXIST_SET_OPTION) && !(this->options & NPW_EXIST_OPTION))
+ if ((prop->options & NPW_EXIST_SET_OPTION) && !(prop->options & NPW_EXIST_OPTION))
{
GtkWidget *button;
@@ -364,13 +371,13 @@
gtk_container_add (GTK_CONTAINER (widget), entry);
button = gtk_button_new_from_stock (GTK_STOCK_OPEN);
- g_signal_connect (button, "clicked", G_CALLBACK (cb_browse_button_clicked), this);
+ g_signal_connect (button, "clicked", G_CALLBACK (cb_browse_button_clicked), prop);
gtk_container_add (GTK_CONTAINER (widget), button);
gtk_box_set_child_packing (GTK_BOX (widget), button, FALSE, TRUE, 0, GTK_PACK_END);
}
else
{
- if (this->type == NPW_DIRECTORY_PROPERTY)
+ if (prop->type == NPW_DIRECTORY_PROPERTY)
{
entry = gtk_file_chooser_button_new (_("Choose directory"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
}
@@ -382,9 +389,11 @@
if (value)
{
- gchar* uri = gnome_vfs_make_uri_from_input (value);
+ GFile *file = g_file_parse_name (value);
+ gchar* uri = g_file_get_uri (file);
gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (entry), uri);
g_free (uri);
+ g_object_unref (file);
}
}
break;
@@ -398,7 +407,7 @@
gboolean get_value = FALSE;
entry = gtk_combo_box_entry_new_text ();
- for (node = this->item; node != NULL; node = node->next)
+ for (node = prop->items; node != NULL; node = node->next)
{
gtk_combo_box_append_text (GTK_COMBO_BOX (entry), _(((NPWItem *)node->data)->label));
if ((value != NULL) && !get_value && (strcmp (value, ((NPWItem *)node->data)->name) == 0))
@@ -407,7 +416,7 @@
get_value = TRUE;
}
}
- if (!(this->options & NPW_EDITABLE_OPTION))
+ if (!(prop->options & NPW_EDITABLE_OPTION))
{
gtk_editable_set_editable (GTK_EDITABLE (GTK_BIN (entry)->child), FALSE);
}
@@ -417,29 +426,29 @@
default:
return NULL;
}
- this->widget = entry;
+ prop->widget = entry;
return widget == NULL ? entry : widget;
}
void
-npw_property_set_widget (NPWProperty* this, GtkWidget* widget)
+npw_property_set_widget (NPWProperty* prop, GtkWidget* widget)
{
- this->widget = widget;
+ prop->widget = widget;
}
GtkWidget*
-npw_property_get_widget (const NPWProperty* this)
+npw_property_get_widget (const NPWProperty* prop)
{
- return this->widget;
+ return prop->widget;
}
void
-npw_property_set_default (NPWProperty* this, const gchar* value)
+npw_property_set_default (NPWProperty* prop, const gchar* value)
{
/* Check if the default property is valid */
- if (value && (this->options & NPW_EXIST_SET_OPTION) && !(this->options & NPW_EXIST_OPTION))
+ if (value && (prop->options & NPW_EXIST_SET_OPTION) && !(prop->options & NPW_EXIST_OPTION))
{
gchar *expand_value = anjuta_util_shell_expand (value);
/* a file or directory with the same name shouldn't exist */
@@ -456,8 +465,7 @@
sprintf(buffer,"%s%d",value, i);
if (!g_file_test (buffer, G_FILE_TEST_EXISTS)) break;
}
- this->defvalue = g_string_chunk_insert (this->owner->string_pool, buffer);
- g_free (buffer);
+ prop->defvalue = buffer;
g_free (expand_value);
return;
@@ -466,58 +474,58 @@
}
/* This function could be used with value = defvalue to only check
* the default property */
- if (this->defvalue != value)
+ if (prop->defvalue != value)
{
- this->defvalue = (value == NULL) ? NULL : g_string_chunk_insert (this->owner->string_pool, value);
+ prop->defvalue = (value == NULL) ? NULL : g_strdup (value);
}
}
static gboolean
-npw_property_set_value_from_widget (NPWProperty* this, NPWValueTag tag)
+npw_property_set_value_from_widget (NPWProperty* prop, NPWValueTag tag)
{
gchar* alloc_value = NULL;
const gchar* value = NULL;
gboolean ok;
- switch (this->type)
+ switch (prop->type)
{
case NPW_INTEGER_PROPERTY:
- alloc_value = g_strdup_printf("%d", gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (this->widget)));
+ alloc_value = g_strdup_printf("%d", gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (prop->widget)));
value = alloc_value;
break;
case NPW_BOOLEAN_PROPERTY:
- alloc_value = g_strdup_printf("%d", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (this->widget)));
+ alloc_value = g_strdup_printf("%d", gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (prop->widget)));
value = alloc_value;
break;
case NPW_STRING_PROPERTY:
- value = gtk_entry_get_text (GTK_ENTRY (this->widget));
+ value = gtk_entry_get_text (GTK_ENTRY (prop->widget));
break;
case NPW_DIRECTORY_PROPERTY:
case NPW_FILE_PROPERTY:
- if ((this->options & NPW_EXIST_SET_OPTION) && !(this->options & NPW_EXIST_OPTION))
+ if ((prop->options & NPW_EXIST_SET_OPTION) && !(prop->options & NPW_EXIST_OPTION))
{
/* a GtkEntry is used in this case*/
- value = gtk_entry_get_text (GTK_ENTRY (this->widget));
+ value = gtk_entry_get_text (GTK_ENTRY (prop->widget));
/* Expand ~ and environment variable */
alloc_value = anjuta_util_shell_expand (value);
value = alloc_value;
}
else
{
- alloc_value = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (this->widget));
+ alloc_value = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (prop->widget));
value = alloc_value;
}
break;
case NPW_ICON_PROPERTY:
- alloc_value = gnome_icon_entry_get_filename (GNOME_ICON_ENTRY (this->widget));
+ alloc_value = gnome_icon_entry_get_filename (GNOME_ICON_ENTRY (prop->widget));
value = alloc_value;
break;
case NPW_LIST_PROPERTY:
{
GSList* node;
- value = gtk_entry_get_text (GTK_ENTRY (GTK_BIN (this->widget)->child));
- for (node = this->item; node != NULL; node = node->next)
+ value = gtk_entry_get_text (GTK_ENTRY (GTK_BIN (prop->widget)->child));
+ for (node = prop->items; node != NULL; node = node->next)
{
if (strcmp (value, _(((NPWItem *)node->data)->label)) == 0)
{
@@ -529,227 +537,209 @@
}
default:
/* Hidden property */
- value = this->defvalue;
+ value = prop->defvalue;
break;
}
/* Check and mark default value (will not be saved) */
- if ((value) && (this->defvalue) && (strcmp (value, this->defvalue) == 0))
+ if ((value) && (prop->defvalue) && (strcmp (value, prop->defvalue) == 0))
{
tag |= NPW_DEFAULT_VALUE;
}
- ok = npw_value_heap_set_value (this->owner->value, this->value, value, tag);
+ ok = npw_value_set_value (prop->value, value, tag);
if (alloc_value != NULL) g_free (alloc_value);
return ok;
}
gboolean
-npw_property_update_value_from_widget (NPWProperty* this)
+npw_property_update_value_from_widget (NPWProperty* prop)
{
- return npw_property_set_value_from_widget (this, NPW_VALID_VALUE);
+ return npw_property_set_value_from_widget (prop, NPW_VALID_VALUE);
}
gboolean
-npw_property_save_value_from_widget (NPWProperty* this)
+npw_property_save_value_from_widget (NPWProperty* prop)
{
- return npw_property_set_value_from_widget (this, NPW_OLD_VALUE);
+ return npw_property_set_value_from_widget (prop, NPW_OLD_VALUE);
}
gboolean
-npw_property_remove_value (NPWProperty* this)
+npw_property_remove_value (NPWProperty* prop)
{
- return npw_value_heap_set_value (this->owner->value, this->value, NULL, NPW_EMPTY_VALUE);
+ return npw_value_set_value (prop->value, NULL, NPW_EMPTY_VALUE);
}
const char*
-npw_property_get_value (const NPWProperty* this)
+npw_property_get_value (const NPWProperty* prop)
{
NPWValueTag tag;
- tag = npw_value_heap_get_tag (this->owner->value, this->value);
+ tag = npw_value_get_tag (prop->value);
if ((tag == NPW_EMPTY_VALUE) || (tag & NPW_DEFAULT_VALUE))
{
- return this->defvalue;
+ return prop->defvalue;
}
else
{
/* Only value entered by user could replace default value */
- return npw_value_heap_get_value (this->owner->value, this->value);
+ return npw_value_get_value (prop->value);
}
}
gboolean
-npw_property_add_list_item (NPWProperty* this, const gchar* name, const gchar* label)
+npw_property_add_list_item (NPWProperty* prop, const gchar* name, const gchar* label)
{
NPWItem* item;
- item = g_chunk_new (NPWItem, this->owner->item_pool);
- item->name = g_string_chunk_insert (this->owner->string_pool, name);
- item->label = g_string_chunk_insert (this->owner->string_pool, label);
-
- this->item = g_slist_append (this->item, item);
+ item = npw_item_new (name, label);
+ prop->items = g_slist_append (prop->items, item);
return TRUE;
}
void
-npw_property_set_mandatory_option (NPWProperty* this, gboolean value)
+npw_property_set_mandatory_option (NPWProperty* prop, gboolean value)
{
if (value)
{
- this->options |= NPW_MANDATORY_OPTION;
+ prop->options |= NPW_MANDATORY_OPTION;
}
else
{
- this->options &= ~NPW_MANDATORY_OPTION;
+ prop->options &= ~NPW_MANDATORY_OPTION;
}
}
void
-npw_property_set_summary_option (NPWProperty* this, gboolean value)
+npw_property_set_summary_option (NPWProperty* prop, gboolean value)
{
if (value)
{
- this->options |= NPW_SUMMARY_OPTION;
+ prop->options |= NPW_SUMMARY_OPTION;
}
else
{
- this->options &= ~NPW_SUMMARY_OPTION;
+ prop->options &= ~NPW_SUMMARY_OPTION;
}
}
void
-npw_property_set_editable_option (NPWProperty* this, gboolean value)
+npw_property_set_editable_option (NPWProperty* prop, gboolean value)
{
if (value)
{
- this->options |= NPW_EDITABLE_OPTION;
+ prop->options |= NPW_EDITABLE_OPTION;
}
else
{
- this->options &= ~NPW_EDITABLE_OPTION;
+ prop->options &= ~NPW_EDITABLE_OPTION;
}
}
NPWPropertyOptions
-npw_property_get_options (const NPWProperty* this)
+npw_property_get_options (const NPWProperty* prop)
{
- return this->options;
+ return prop->options;
}
void
-npw_property_set_exist_option (NPWProperty* this, NPWPropertyBooleanValue value)
+npw_property_set_exist_option (NPWProperty* prop, NPWPropertyBooleanValue value)
{
switch (value)
{
case NPW_TRUE:
- this->options |= NPW_EXIST_OPTION | NPW_EXIST_SET_OPTION;
+ prop->options |= NPW_EXIST_OPTION | NPW_EXIST_SET_OPTION;
break;
case NPW_FALSE:
- this->options &= ~NPW_EXIST_OPTION;
- this->options |= NPW_EXIST_SET_OPTION;
- npw_property_set_default (this, this->defvalue);
+ prop->options &= ~NPW_EXIST_OPTION;
+ prop->options |= NPW_EXIST_SET_OPTION;
+ npw_property_set_default (prop, prop->defvalue);
break;
case NPW_DEFAULT:
- this->options &= ~(NPW_EXIST_OPTION | NPW_EXIST_SET_OPTION);
+ prop->options &= ~(NPW_EXIST_OPTION | NPW_EXIST_SET_OPTION);
break;
}
}
NPWPropertyBooleanValue
-npw_property_get_exist_option (const NPWProperty* this)
+npw_property_get_exist_option (const NPWProperty* prop)
{
- return this->options & NPW_EXIST_SET_OPTION ? (this->options & NPW_EXIST_OPTION ? NPW_TRUE : NPW_FALSE) : NPW_DEFAULT;
+ return prop->options & NPW_EXIST_SET_OPTION ? (prop->options & NPW_EXIST_OPTION ? NPW_TRUE : NPW_FALSE) : NPW_DEFAULT;
}
/* Page object = list of properties
*---------------------------------------------------------------------------*/
NPWPage*
-npw_page_new (NPWValueHeap* value)
+npw_page_new (GHashTable* value)
{
- NPWPage* this;
+ NPWPage* page;
- this = g_new0(NPWPage, 1);
- this->string_pool = g_string_chunk_new (STRING_CHUNK_SIZE);
- this->data_pool = g_mem_chunk_new ("property pool", sizeof (NPWProperty), STRING_CHUNK_SIZE * sizeof (NPWProperty) / 4, G_ALLOC_ONLY);
- this->item_pool = g_mem_chunk_new ("item pool", sizeof (NPWItem), STRING_CHUNK_SIZE * sizeof (NPWItem) / 4, G_ALLOC_ONLY);
- this->list = g_node_new (NULL);
- this->value = value;
+ page = g_new0(NPWPage, 1);
+ page->values = value;
- return this;
+ return page;
}
void
-npw_page_free (NPWPage* this)
+npw_page_free (NPWPage* page)
{
- g_return_if_fail (this != NULL);
+ g_return_if_fail (page != NULL);
- g_string_chunk_free (this->string_pool);
- g_mem_chunk_destroy (this->data_pool);
- g_mem_chunk_destroy (this->item_pool);
- g_node_destroy (this->list);
- g_free (this);
+ g_free (page->name);
+ g_free (page->label);
+ g_free (page->description);
+ g_list_foreach (page->properties, (GFunc)npw_property_free, NULL);
+ g_list_free (page->properties);
+ g_free (page);
}
void
-npw_page_set_name (NPWPage* this, const gchar* name)
+npw_page_set_name (NPWPage* page, const gchar* name)
{
- this->name = g_string_chunk_insert (this->string_pool, name);
+ page->name = g_strdup (name);
}
const gchar*
-npw_page_get_name (const NPWPage* this)
+npw_page_get_name (const NPWPage* page)
{
- return this->name;
+ return page->name;
}
void
-npw_page_set_label (NPWPage* this, const gchar* label)
+npw_page_set_label (NPWPage* page, const gchar* label)
{
- this->label = g_string_chunk_insert (this->string_pool, label);
+ page->label = g_strdup (label);
}
const gchar*
-npw_page_get_label (const NPWPage* this)
+npw_page_get_label (const NPWPage* page)
{
- return this->label;
+ return page->label;
}
void
-npw_page_set_description (NPWPage* this, const gchar* description)
+npw_page_set_description (NPWPage* page, const gchar* description)
{
- this->description = g_string_chunk_insert (this->string_pool, description);
+ page->description = g_strdup (description);
}
const gchar*
-npw_page_get_description (const NPWPage* this)
+npw_page_get_description (const NPWPage* page)
{
- return this->description;
+ return page->description;
}
-typedef struct _PageForeachPropertyData
-{
- NPWPropertyForeachFunc func;
- gpointer data;
-} PageForeachPropertyData;
-
-static void
-cb_page_foreach_property (GNode* node, gpointer data)
+void
+npw_page_foreach_property (const NPWPage* page, GFunc func, gpointer data)
{
- PageForeachPropertyData* d = (PageForeachPropertyData *)data;
-
- (d->func)((NPWProperty*)node->data, d->data);
+ g_list_foreach (page->properties, func, data);
}
void
-npw_page_foreach_property (const NPWPage* this, NPWPropertyForeachFunc func, gpointer data)
+npw_page_add_property (NPWPage* page, NPWProperty *prop)
{
- PageForeachPropertyData d;
-
- d.func = func;
- d.data = data;
- g_node_children_foreach (this->list, G_TRAVERSE_LEAFS, cb_page_foreach_property, &d);
+ page->properties = g_list_append (page->properties, prop);
}
Modified: trunk/plugins/project-wizard/property.h
==============================================================================
--- trunk/plugins/project-wizard/property.h (original)
+++ trunk/plugins/project-wizard/property.h Wed Dec 24 18:06:10 2008
@@ -70,63 +70,62 @@
NPW_TRUE = 1
} NPWPropertyBooleanValue;
-NPWProperty* npw_property_new (NPWPage* owner);
-void npw_property_free (NPWProperty* this);
+NPWProperty* npw_property_new (void);
+void npw_property_free (NPWProperty* prop);
-void npw_property_set_type (NPWProperty* this, NPWPropertyType type);
-void npw_property_set_string_type (NPWProperty* this, const gchar* type);
-NPWPropertyType npw_property_get_type (const NPWProperty* this);
+void npw_property_set_type (NPWProperty* prop, NPWPropertyType type);
+void npw_property_set_string_type (NPWProperty* prop, const gchar* type);
+NPWPropertyType npw_property_get_type (const NPWProperty* prop);
-void npw_property_set_restriction (NPWProperty* this, NPWPropertyRestriction restriction);
-void npw_property_set_string_restriction (NPWProperty* this, const gchar* restriction);
-NPWPropertyRestriction npw_property_get_restriction (const NPWProperty* this);
-gboolean npw_property_is_valid_restriction (const NPWProperty* this);
+void npw_property_set_restriction (NPWProperty* prop, NPWPropertyRestriction restriction);
+void npw_property_set_string_restriction (NPWProperty* prop, const gchar* restriction);
+NPWPropertyRestriction npw_property_get_restriction (const NPWProperty* prop);
+gboolean npw_property_is_valid_restriction (const NPWProperty* prop);
-void npw_property_set_name (NPWProperty* this, const gchar* name);
-const gchar* npw_property_get_name (const NPWProperty* this);
+void npw_property_set_name (NPWProperty* prop, const gchar* name, NPWPage *page);
+const gchar* npw_property_get_name (const NPWProperty* prop);
-void npw_property_set_label (NPWProperty* this, const gchar* name);
-const gchar* npw_property_get_label (const NPWProperty* this);
+void npw_property_set_label (NPWProperty* prop, const gchar* name);
+const gchar* npw_property_get_label (const NPWProperty* prop);
-void npw_property_set_description (NPWProperty* this, const gchar* description);
-const gchar* npw_property_get_description (const NPWProperty* this);
+void npw_property_set_description (NPWProperty* prop, const gchar* description);
+const gchar* npw_property_get_description (const NPWProperty* prop);
-GtkWidget* npw_property_create_widget (NPWProperty* this);
-void npw_property_set_widget (NPWProperty* this, GtkWidget* widget);
-GtkWidget* npw_property_get_widget (const NPWProperty* this);
+GtkWidget* npw_property_create_widget (NPWProperty* prop);
+void npw_property_set_widget (NPWProperty* prop, GtkWidget* widget);
+GtkWidget* npw_property_get_widget (const NPWProperty* prop);
-void npw_property_set_default (NPWProperty* this, const gchar* value);
+void npw_property_set_default (NPWProperty* prop, const gchar* value);
-gboolean npw_property_update_value_from_widget (NPWProperty* this);
-gboolean npw_property_save_value_from_widget (NPWProperty* this);
-gboolean npw_property_remove_value (NPWProperty* this);
-const char* npw_property_get_value (const NPWProperty* this);
+gboolean npw_property_update_value_from_widget (NPWProperty* prop);
+gboolean npw_property_save_value_from_widget (NPWProperty* prop);
+gboolean npw_property_remove_value (NPWProperty* prop);
+const char* npw_property_get_value (const NPWProperty* prop);
-gboolean npw_property_add_list_item (NPWProperty* this, const char* name, const gchar* label);
+gboolean npw_property_add_list_item (NPWProperty* prop, const char* name, const gchar* label);
-void npw_property_set_mandatory_option (NPWProperty* this, gboolean value);
-void npw_property_set_summary_option (NPWProperty* this, gboolean value);
-void npw_property_set_editable_option (NPWProperty* this, gboolean value);
-NPWPropertyOptions npw_property_get_options (const NPWProperty* this);
+void npw_property_set_mandatory_option (NPWProperty* prop, gboolean value);
+void npw_property_set_summary_option (NPWProperty* prop, gboolean value);
+void npw_property_set_editable_option (NPWProperty* prop, gboolean value);
+NPWPropertyOptions npw_property_get_options (const NPWProperty* prop);
-void npw_property_set_exist_option (NPWProperty* this, NPWPropertyBooleanValue value);
-NPWPropertyBooleanValue npw_property_get_exist_option (const NPWProperty* this);
+void npw_property_set_exist_option (NPWProperty* prop, NPWPropertyBooleanValue value);
+NPWPropertyBooleanValue npw_property_get_exist_option (const NPWProperty* prop);
-NPWPage* npw_page_new (NPWValueHeap* value);
-void npw_page_free (NPWPage* this);
+NPWPage* npw_page_new (GHashTable* value);
+void npw_page_free (NPWPage* page);
-typedef void (*NPWPropertyForeachFunc) (NPWProperty* head, gpointer data);
+void npw_page_set_name (NPWPage* page, const gchar* name);
+const gchar* npw_page_get_name (const NPWPage* page);
-void npw_page_set_name (NPWPage* this, const gchar* name);
-const gchar* npw_page_get_name (const NPWPage* this);
+void npw_page_set_label (NPWPage* page, const gchar* name);
+const gchar* npw_page_get_label (const NPWPage* page);
-void npw_page_set_label (NPWPage* this, const gchar* name);
-const gchar* npw_page_get_label (const NPWPage* this);
+void npw_page_set_description (NPWPage* page, const gchar* name);
+const gchar* npw_page_get_description (const NPWPage* page);
-void npw_page_set_description (NPWPage* this, const gchar* name);
-const gchar* npw_page_get_description (const NPWPage* this);
-
-void npw_page_foreach_property (const NPWPage* this, NPWPropertyForeachFunc func, gpointer data);
+void npw_page_foreach_property (const NPWPage* page, GFunc func, gpointer data);
+void npw_page_add_property (NPWPage* page, NPWProperty* prop);
#endif
Modified: trunk/plugins/project-wizard/values.c
==============================================================================
--- trunk/plugins/project-wizard/values.c (original)
+++ trunk/plugins/project-wizard/values.c Wed Dec 24 18:06:10 2008
@@ -37,22 +37,6 @@
/*---------------------------------------------------------------------------*/
-#define STRING_CHUNK_SIZE 256
-
-/*---------------------------------------------------------------------------*/
-
-/* This stores all the values. It's basically an hash table with a string
- * and a mem chunk to allocate all memories inside the object.
- * After adding a new property, there is no way to remove it, but you can
- * use the tag to mark it as obsolete */
-
-struct _NPWValueHeap
-{
- GHashTable* hash;
- GStringChunk* string_pool;
- GMemChunk* value_pool;
-};
-
/* One property value, so just a name and a value plus a tag !
* The tag is defined in the header file, but is not really used in this code */
@@ -60,48 +44,49 @@
{
NPWValueTag tag;
const gchar* name;
- const gchar* value;
+ gchar* value;
};
/* Creation and Destruction
*---------------------------------------------------------------------------*/
-static NPWValueHeap*
-npw_value_heap_initialize (NPWValueHeap* this)
+static NPWValue*
+npw_value_new (const gchar *name)
{
- this->string_pool = g_string_chunk_new (STRING_CHUNK_SIZE);
- this->value_pool = g_mem_chunk_new ("value pool", sizeof(NPWValue), (STRING_CHUNK_SIZE / 4) * sizeof(NPWValue), G_ALLOC_ONLY);
- this->hash = g_hash_table_new (g_str_hash, g_str_equal);
-
- return this;
+ NPWValue *value;
+
+ value = g_slice_new (NPWValue);
+ value->tag = NPW_EMPTY_VALUE;
+ value->name = name;
+ value->value = NULL;
+
+ return value;
}
static void
-npw_value_heap_deinitialize (NPWValueHeap* this)
+npw_value_free (NPWValue *value)
{
- g_string_chunk_free (this->string_pool);
- g_mem_chunk_destroy (this->value_pool);
- g_hash_table_destroy (this->hash);
+ g_free (value->value);
+ g_slice_free (NPWValue, value);
}
-
-
-NPWValueHeap*
+
+GHashTable*
npw_value_heap_new (void)
{
- NPWValueHeap* this;
+ GHashTable* hash;
- this = g_new0 (NPWValueHeap, 1);
- return npw_value_heap_initialize (this);
+ hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify)npw_value_free);
+
+ return hash;
}
void
-npw_value_heap_free (NPWValueHeap* this)
+npw_value_heap_free (GHashTable* hash)
{
/* GSList* node; */
- g_return_if_fail (this != NULL);
+ g_return_if_fail (hash != NULL);
- npw_value_heap_deinitialize (this);
- g_free (this);
+ g_hash_table_destroy (hash);
}
/* Find a value or list all values
@@ -110,55 +95,33 @@
/* Return key corresponding to name, create key if it doesn't exist */
NPWValue*
-npw_value_heap_find_value (NPWValueHeap* this, const gchar* name)
+npw_value_heap_find_value (GHashTable* hash, const gchar* name)
{
NPWValue* node;
- if (!g_hash_table_lookup_extended (this->hash, name, NULL, (gpointer)&node))
+ if (!g_hash_table_lookup_extended (hash, name, NULL, (gpointer)&node))
{
gchar* new_name;
- node = g_chunk_new (NPWValue, this->value_pool);
- new_name = g_string_chunk_insert (this->string_pool, name);
- node->name = new_name;
- node->tag = NPW_EMPTY_VALUE;
- node->value = NULL;
- g_hash_table_insert (this->hash, new_name, node);
+ new_name = g_strdup (name);
+ node = npw_value_new (new_name);
+ g_hash_table_insert (hash, new_name, node);
}
return node;
}
-typedef struct _NPWValueHeapForeachValueData
-{
- NPWValueHeapForeachFunc func;
- gpointer data;
-} NPWValueHeapForeachValueData;
-
-static void
-cb_value_heap_foreach_value (gpointer key, gpointer value, gpointer user_data)
-{
- NPWValueHeapForeachValueData* data = (NPWValueHeapForeachValueData *)user_data;
- NPWValue* node = (NPWValue*)value;
-
- (data->func)(node->name, node->value, node->tag, data->data);
-}
-
void
-npw_value_heap_foreach_value (const NPWValueHeap* this, NPWValueHeapForeachFunc func, gpointer user_data)
+npw_value_heap_foreach_value (GHashTable* hash, GHFunc func, gpointer user_data)
{
- NPWValueHeapForeachValueData data;
-
- data.func = func;
- data.data = user_data;
- g_hash_table_foreach (this->hash, cb_value_heap_foreach_value, &data);
+ g_hash_table_foreach (hash, func, user_data);
}
/* Access value attributes
*---------------------------------------------------------------------------*/
const gchar*
-npw_value_heap_get_name (const NPWValueHeap* this, const NPWValue* node)
+npw_value_get_name ( const NPWValue* node)
{
g_return_val_if_fail (node != NULL, NULL);
@@ -168,7 +131,7 @@
/* set new value, return FALSE if value has not changed */
gboolean
-npw_value_heap_set_value (NPWValueHeap* this, NPWValue* node, const gchar* value, NPWValueTag tag)
+npw_value_set_value (NPWValue* node, const gchar* value, NPWValueTag tag)
{
gboolean change = FALSE;
@@ -189,6 +152,7 @@
{
if (node->value != NULL)
{
+ g_free (node->value);
node->value = NULL;
change = TRUE;
}
@@ -197,7 +161,8 @@
{
if ((node->value == NULL) || (strcmp (node->value, value) != 0))
{
- node->value = g_string_chunk_insert (this->string_pool, value);
+ g_free (node->value);
+ node->value = g_strdup (value);
change = TRUE;
}
}
@@ -220,7 +185,7 @@
}
const gchar*
-npw_value_heap_get_value (const NPWValueHeap* this, const NPWValue* node)
+npw_value_get_value (const NPWValue* node)
{
g_return_val_if_fail (node != NULL, NULL);
@@ -228,7 +193,7 @@
}
NPWValueTag
-npw_value_heap_get_tag (const NPWValueHeap* this, const NPWValue* node)
+npw_value_get_tag (const NPWValue* node)
{
g_return_val_if_fail (node != NULL, NPW_EMPTY_VALUE);
Modified: trunk/plugins/project-wizard/values.h
==============================================================================
--- trunk/plugins/project-wizard/values.h (original)
+++ trunk/plugins/project-wizard/values.h Wed Dec 24 18:06:10 2008
@@ -23,7 +23,6 @@
#include <glib.h>
-typedef struct _NPWValueHeap NPWValueHeap;
typedef struct _NPWValue NPWValue;
typedef enum {
@@ -33,19 +32,16 @@
NPW_DEFAULT_VALUE = 1 << 2 /* default value = could be overwritten */
} NPWValueTag;
-NPWValueHeap* npw_value_heap_new (void);
-void npw_value_heap_free (NPWValueHeap* this);
+GHashTable* npw_value_heap_new (void);
+void npw_value_heap_free (GHashTable* hash);
-NPWValue* npw_value_heap_find_value (NPWValueHeap* this, const gchar* name);
+NPWValue* npw_value_heap_find_value (GHashTable* hash, const gchar* name);
+void npw_value_heap_foreach_value (GHashTable* hash, GHFunc func, gpointer user_data);
-gboolean npw_value_heap_set_value (NPWValueHeap* this, NPWValue* node, const gchar* value, NPWValueTag tag);
-const gchar* npw_value_heap_get_value (const NPWValueHeap* this, const NPWValue* node);
-
-const gchar* npw_value_heap_get_name (const NPWValueHeap* this, const NPWValue* node);
-NPWValueTag npw_value_heap_get_tag (const NPWValueHeap* this, const NPWValue* node);
-
-typedef void (*NPWValueHeapForeachFunc) (const gchar* name, const gchar* value, NPWValueTag tag, gpointer user_data);
-void npw_value_heap_foreach_value (const NPWValueHeap* this, NPWValueHeapForeachFunc func, gpointer user_data);
+gboolean npw_value_set_value (NPWValue* node, const gchar* value, NPWValueTag tag);
+const gchar* npw_value_get_value (const NPWValue* node);
+const gchar* npw_value_get_name (const NPWValue* node);
+NPWValueTag npw_value_get_tag (const NPWValue* node);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]