Commit 52a2d296 authored by Tristan Van Berkom's avatar Tristan Van Berkom

Fixed broken resource pool & wrote some doc. Now save the "<required


	* src/glade-project.c: Fixed broken resource pool & wrote some doc.
	  Now save the "<required lib="..."/> catalog requirements to the
	  glade file and complain when loading glade files that demand
	  unavailable catalogs.

	* src/glade-widget-class.[ch]: Added widget_class->catalog

	* src/glade-catalog.[ch]: Added glade_catalog_is_loaded (), call
	  gwc_new with catname arg.

	* src/glade-parser.c: Added glade_util_ui_message error messaging
	  when having errors loading glade files.

	* src/glade-project-window.c: Removed redundant error message.
parent 5454ab45
......@@ -2,6 +2,23 @@
* configure.in: Added pt_BR to ALL_LINGUAS.
2006-01-23 Tristan Van Berkom <tvb@gnome.org>
* src/glade-project.c: Fixed broken resource pool & wrote some doc.
Now save the "<required lib="..."/> catalog requirements to the
glade file and complain when loading glade files that demand
unavailable catalogs.
* src/glade-widget-class.[ch]: Added widget_class->catalog
* src/glade-catalog.[ch]: Added glade_catalog_is_loaded (), call
gwc_new with catname arg.
* src/glade-parser.c: Added glade_util_ui_message error messaging
when having errors loading glade files.
* src/glade-project-window.c: Removed redundant error message.
2006-01-22 Tristan Van Berkom <tvb@gnome.org>
* src/glade-editor-property.c: Fixed nasty segfault when
......
......@@ -76,7 +76,9 @@ static gboolean catalog_load_group (GladeCatalog *catalog,
void widget_group_free (GladeWidgetGroup *group);
/* List of catalog names successfully loaded.
*/
static GList *loaded_catalogs = NULL;
static GladeCatalog *
catalog_open (const gchar *filename)
......@@ -112,6 +114,7 @@ catalog_open (const gchar *filename)
catalog = g_new0 (GladeCatalog, 1);
catalog->context = context;
catalog->name = glade_xml_get_property_string (root, GLADE_TAG_NAME);
loaded_catalogs = g_list_prepend (loaded_catalogs, g_strdup (catalog->name));
if (!catalog->name)
{
......@@ -240,7 +243,7 @@ catalog_load_classes (GladeCatalog *catalog, GladeXmlNode *widgets_node)
continue;
widget_class = glade_widget_class_new
(node, catalog->library,
(node, catalog->name, catalog->library,
catalog->domain ? catalog->domain : catalog->library);
catalog->widget_classes = g_list_prepend (catalog->widget_classes,
......@@ -463,4 +466,13 @@ glade_widget_group_get_widget_classes (GladeWidgetGroup *group)
return group->widget_classes;
}
gboolean
glade_catalog_is_loaded (const gchar *name)
{
GList *l;
g_return_val_if_fail (name != NULL, FALSE);
for (l = loaded_catalogs; l; l = l->next)
if (!strcmp (name, (gchar *)l->data))
return TRUE;
return FALSE;
}
......@@ -47,6 +47,8 @@ LIBGLADEUI_API GList * glade_widget_group_get_widget_classes (GladeWidgetG
LIBGLADEUI_API void glade_widget_group_free (GladeWidgetGroup *group);
LIBGLADEUI_API gboolean glade_catalog_is_loaded (const gchar *name);
G_END_DECLS
#endif /* __GLADE_CATALOG_H__ */
......@@ -1175,7 +1175,9 @@ glade_parser_parse_file(const gchar *file, const gchar *domain)
GladeParseState state = { 0 };
if (!g_file_test(file, G_FILE_TEST_IS_REGULAR)) {
g_warning("could not find glade file '%s'", file);
glade_util_ui_message (glade_default_app_get_window (),
GLADE_UI_ERROR,
_("Couldnt find glade file %s"), file);
return NULL;
}
......@@ -1186,13 +1188,17 @@ glade_parser_parse_file(const gchar *file, const gchar *domain)
state.domain = textdomain(NULL);
if (xmlSAXUserParseFile(&glade_parser, &state, file) < 0) {
g_warning("document not well formed");
glade_util_ui_message (glade_default_app_get_window (),
GLADE_UI_ERROR,
_("Errors parsing glade file %s"), file);
if (state.interface)
glade_interface_destroy (state.interface);
return NULL;
}
if (state.state != PARSER_FINISH) {
g_warning("did not finish in PARSER_FINISH state");
glade_util_ui_message (glade_default_app_get_window (),
GLADE_UI_ERROR,
_("Errors parsing glade file %s"), file);
if (state.interface)
glade_interface_destroy(state.interface);
return NULL;
......
......@@ -1493,13 +1493,8 @@ glade_project_window_open_project (GladeProjectWindow *gpw, const gchar *path)
return;
}
project = glade_project_open (path);
if (!project)
{
glade_util_ui_message (gpw->priv->window, GLADE_UI_ERROR,
_("Could not open project."));
if ((project = glade_project_open (path)) == NULL)
return;
}
gpw_recent_project_add (gpw, project->path);
gpw_recent_project_config_save (gpw);
......
......@@ -27,6 +27,7 @@
#include <string.h>
#include <stdlib.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include <glib/gstdio.h>
#include "glade.h"
......@@ -40,6 +41,7 @@
#include "glade-utils.h"
#include "glade-id-allocator.h"
#include "glade-app.h"
#include "glade-catalog.h"
static void glade_project_class_init (GladeProjectClass *class);
static void glade_project_init (GladeProject *project);
......@@ -335,7 +337,8 @@ glade_project_on_widget_notify (GladeWidget *widget, GParamSpec *arg, GladeProje
static void
gp_sync_resources (GladeProject *project,
GladeProject *prev_project,
GladeWidget *gwidget)
GladeWidget *gwidget,
gboolean remove)
{
GList *prop_list, *l;
GladeProperty *property;
......@@ -351,22 +354,31 @@ gp_sync_resources (GladeProject *project,
if (property->class->resource)
{
GValue value = { 0, };
if (remove)
{
glade_project_set_resource (project, property, NULL);
continue;
}
glade_property_get_value (property, &value);
resource = glade_property_class_make_string_from_gvalue
(property->class, &value);
full_resource = glade_project_resource_fullpath
(prev_project ? prev_project : project, resource);
if ((resource = glade_property_class_make_string_from_gvalue
(property->class, &value)) != NULL)
{
full_resource = glade_project_resource_fullpath
(prev_project ? prev_project : project, resource);
/* Use a full path here so that the current
* working directory isnt used.
*/
glade_project_set_resource (project,
property,
full_resource);
g_free (resource);
g_free (full_resource);
/* Use a full path here so that the current
* working directory isnt used.
*/
glade_project_set_resource (project,
property,
full_resource);
g_free (full_resource);
g_free (resource);
}
g_value_unset (&value);
}
}
......@@ -376,7 +388,8 @@ gp_sync_resources (GladeProject *project,
static void
glade_project_sync_resources_for_widget (GladeProject *project,
GladeProject *prev_project,
GladeWidget *gwidget)
GladeWidget *gwidget,
gboolean remove)
{
GList *children, *l;
GladeWidget *gchild;
......@@ -388,35 +401,13 @@ glade_project_sync_resources_for_widget (GladeProject *project,
if ((gchild =
glade_widget_get_from_gobject (l->data)) != NULL)
glade_project_sync_resources_for_widget
(project, prev_project, gchild);
(project, prev_project, gchild, remove);
if (children)
g_list_free (children);
gp_sync_resources (project, prev_project, gwidget);
}
static void
glade_project_sync_resources (GladeProject *project,
GladeProject *old_project)
{
GList *list;
GladeWidget *gwidget;
g_return_if_fail (GLADE_IS_PROJECT (project));
for (list = project->objects; list; list = list->next)
{
if ((gwidget = glade_widget_get_from_gobject (list->data)) != NULL)
{
gp_sync_resources (project,
old_project ? old_project : project,
gwidget);
}
else g_critical ("Project object found without glade widget wrapper");
}
gp_sync_resources (project, prev_project, gwidget, remove);
}
/**
* glade_project_add_object:
* @project: the #GladeProject the widget is added to
......@@ -484,7 +475,7 @@ glade_project_add_object (GladeProject *project,
/* Call this once at the end for every recursive call */
if (--reentrancy_count == 0)
glade_project_sync_resources_for_widget
(project, old_project, gwidget);
(project, old_project, gwidget, FALSE);
}
/**
......@@ -614,7 +605,7 @@ glade_project_remove_object (GladeProject *project, GObject *object)
/* Call this once at the end for every recursive call */
if (--reentrancy_count == 0)
glade_project_sync_resources (project, NULL);
glade_project_sync_resources_for_widget (project, NULL, gwidget, TRUE);
}
/**
......@@ -736,7 +727,7 @@ glade_project_is_selected (GladeProject *project,
* @project: a #GladeProject
* @emit_signal: whether or not to emit a signal indication a selection change
*
* TODO: write me
* Clears @project's selection chain
*
* If @emit_signal is %TRUE, calls glade_project_selection_changed().
*/
......@@ -759,10 +750,11 @@ glade_project_selection_clear (GladeProject *project, gboolean emit_signal)
/**
* glade_project_selection_remove:
* @project: a #GladeProject
* @widget:
* @emit_signal: whether or not to emit a signal indication a selection change
* @object: a #GObject in @project
* @emit_signal: whether or not to emit a signal
* indicating a selection change
*
* TODO: write me
* Removes @object from the selection chain of @project
*
* If @emit_signal is %TRUE, calls glade_project_selection_changed().
*/
......@@ -787,10 +779,11 @@ glade_project_selection_remove (GladeProject *project,
/**
* glade_project_selection_add:
* @project: a #GladeProject
* @widget:
* @emit_signal: whether or not to emit a signal indication a selection change
* @object: a #GObject in @project
* @emit_signal: whether or not to emit a signal indicating
* a selection change
*
* TODO: write me
* Adds @object to the selection chain of @project
*
* If @emit_signal is %TRUE, calls glade_project_selection_changed().
*/
......@@ -816,10 +809,11 @@ glade_project_selection_add (GladeProject *project,
/**
* glade_project_selection_set:
* @project: a #GladeProject
* @widget:
* @emit_signal: whether or not to emit a signal indication a selection change
* @object: a #GObject in @project
* @emit_signal: whether or not to emit a signal
* indicating a selection change
*
* TODO: write me
* Set the selection in @project to @object
*
* If @emit_signal is %TRUE, calls glade_project_selection_changed().
*/
......@@ -857,6 +851,37 @@ glade_project_selection_get (GladeProject *project)
return project->selection;
}
static GList *
glade_project_required_libs (GladeProject *project)
{
GList *required = NULL, *l, *ll;
GladeWidget *gwidget;
gboolean listed;
for (l = project->objects; l; l = l->next)
{
gwidget = glade_widget_get_from_gobject (l->data);
g_assert (gwidget);
if (gwidget->widget_class->catalog)
{
listed = FALSE;
for (ll = required; ll; ll = ll->next)
if (!strcmp ((gchar *)ll->data,
gwidget->widget_class->catalog))
{
listed = TRUE;
break;
}
if (!listed)
required = g_list_prepend
(required, gwidget->widget_class->catalog);
}
}
return required;
}
/**
* glade_project_write:
* @project: a #GladeProject
......@@ -865,14 +890,27 @@ glade_project_selection_get (GladeProject *project)
* project and its contents
*/
static GladeInterface *
glade_project_write (const GladeProject *project)
glade_project_write (GladeProject *project)
{
GladeInterface *interface;
GList *list, *tops = NULL;
guint i;
GladeInterface *interface;
GList *required, *list, *tops = NULL;
gchar **strv = NULL;
guint i;
interface = glade_interface_new ();
if ((required = glade_project_required_libs (project)) != NULL)
{
strv = g_malloc0 (g_list_length (required) * sizeof (char *));
for (i = 0, list = required; list; i++, list = list->next)
strv[i] = g_strdup (list->data);
g_list_free (required);
interface->n_requires = g_list_length (required);
interface->requires = strv;
}
for (i = 0, list = project->objects; list; list = list->next)
{
GladeWidget *widget;
......@@ -911,14 +949,44 @@ glade_project_set_changed_to_false_idle (gpointer data)
return FALSE;
}
static gboolean
loadable_interface (GladeInterface *interface, const gchar *path)
{
GString *string = g_string_new (NULL);
gboolean loadable = TRUE;
guint i;
/* Check for required plugins here
*/
for (i = 0; i < interface->n_requires; i++)
if (!glade_catalog_is_loaded (interface->requires[i]))
{
g_string_append (string, interface->requires[i]);
loadable = FALSE;
}
if (loadable == FALSE)
glade_util_ui_message (glade_default_app_get_window(),
GLADE_UI_ERROR,
_("Failed to load %s, the following required "
"catalogs are unavailable: %s"),
path, string->str);
g_string_free (string, TRUE);
return loadable;
}
static GladeProject *
glade_project_new_from_interface (GladeInterface *interface, const gchar *path)
{
GladeProject *project;
GladeWidget *widget;
GladeWidget *widget;
guint i;
g_return_val_if_fail (interface != NULL, NULL);
g_return_val_if_fail (path != NULL, NULL);
if (loadable_interface (interface, path) == FALSE)
return NULL;
project = glade_project_new (FALSE);
......@@ -930,9 +998,6 @@ glade_project_new_from_interface (GladeInterface *interface, const gchar *path)
project->selection = NULL;
project->objects = NULL;
if (interface->n_requires)
g_warning ("We currently do not support projects requiring additional libs");
for (i = 0; i < interface->n_toplevels; ++i)
{
widget = glade_widget_read ((gpointer)project, interface->toplevels[i]);
......@@ -995,28 +1060,26 @@ glade_project_fix_object_props (GladeProject *project)
GladeProject *
glade_project_open (const gchar *path)
{
GladeProject *project;
GladeProject *project = NULL;
GladeInterface *interface;
g_return_val_if_fail (path != NULL, NULL);
interface = glade_parser_parse_file (path, NULL);
if (!interface)
return NULL;
project = glade_project_new_from_interface (interface, path);
glade_interface_destroy (interface);
/* Now we have to loop over all the object properties
* and fix'em all ('cause they probably weren't found)
*/
glade_project_fix_object_props (project);
/* Resources have to be bookkept after the load.
*/
glade_project_sync_resources (project, NULL);
if ((interface =
glade_parser_parse_file (path, NULL)) != NULL)
{
if ((project =
glade_project_new_from_interface (interface,
path)) != NULL)
{
/* Now we have to loop over all the object properties
* and fix'em all ('cause they probably weren't found)
*/
glade_project_fix_object_props (project);
}
glade_interface_destroy (interface);
}
return project;
}
......@@ -1078,7 +1141,6 @@ glade_project_save (GladeProject *project, const gchar *path, GError **error)
ret = glade_interface_dump_full (interface, path, error);
glade_interface_destroy (interface);
canonical_path = glade_util_canonical_path (path);
if (strcmp (canonical_path, project->path))
......
......@@ -94,6 +94,7 @@ glade_widget_class_free (GladeWidgetClass *widget_class)
g_free (widget_class->generic_name);
g_free (widget_class->name);
g_free (widget_class->catalog);
g_list_foreach (widget_class->properties, (GFunc) glade_property_class_free, NULL);
g_list_free (widget_class->properties);
......@@ -961,7 +962,10 @@ glade_widget_class_load_library (const gchar *library_name)
}
GladeWidgetClass *
glade_widget_class_new (GladeXmlNode *class_node, const gchar *library, const gchar *domain)
glade_widget_class_new (GladeXmlNode *class_node,
const gchar *catname,
const gchar *library,
const gchar *domain)
{
GladeWidgetClass *widget_class;
gchar *name, *generic_name, *ptr;
......@@ -1025,8 +1029,12 @@ glade_widget_class_new (GladeXmlNode *class_node, const gchar *library, const gc
widget_class->generic_name = generic_name;
widget_class->palette_name = title;
widget_class->in_palette = title ? TRUE : FALSE;
widget_class->type = glade_util_get_type_from_name (name);
/* Dont mention gtk+ as a required lib in the generated glade file */
if (strcmp (catname, "gtk+"))
widget_class->catalog = g_strdup (catname);
widget_class->type = glade_util_get_type_from_name (name);
if (widget_class->type == 0)
{
glade_widget_class_free (widget_class);
......
......@@ -71,6 +71,10 @@ struct _GladeWidgetClass
gchar *name; /* Name of the widget, for example GtkButton */
gchar *catalog; /* The name of the widget catalog this class
* was declared by.
*/
GdkPixbuf *icon; /* The GdkPixbuf icon for the widget */
gchar *generic_name; /* Use to generate names of new widgets, for
......@@ -171,6 +175,7 @@ struct _GladeWidgetClassSignal
};
LIBGLADEUI_API GladeWidgetClass *glade_widget_class_new (GladeXmlNode *class_node,
const gchar *catname,
const gchar *library,
const gchar *domain);
LIBGLADEUI_API void glade_widget_class_free (GladeWidgetClass *widget_class);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment