Commit a1c3b8ea authored by Joaquín Cuenca Abela's avatar Joaquín Cuenca Abela

ops... lot of changes... read the changelog.

parent 3e58c96f
2003-08-07 Joaquin Cuenca Abela <e98cuenc@yahoo.com>
* src/glade-catalog.[ch], glade-palette.c: Specify the order in which
the catalogs should appear on the palette (read it from
widgets/glade-palette.xml). Also changed a bit the format of
the catalogs.
* src/glade-parameter.[ch], glade-property-class.[ch], glade-widget-class.[ch],
glade-widget.c, glade-xml-utils.h: Inherit properties specified on a
xml file from a base class to an inherited class. It makes possible
to specify something special for (for instance) GtkWidget, and
make it inherit for each GtkWidget.
* widgets/glade-palette.xml: specify the order of the catalogs.
* widgets/gtkwidget.xml, gtkbox.xml: specify common properties for
gtkwidgets and gtkboxes. Coupled with the above changes, it
makes almost every xml file obsolete.
2003-08-07 Paolo BOrelli <pborelli@katamail.com>
* src/glade-utils.[ch]: remove dependency on glade-project-window.h.
......
......@@ -35,8 +35,10 @@
#include "glade-catalog.h"
#include "glade-widget-class.h"
GList *glade_catalog_list = NULL; /* A list of GladeCatalog items */
GList *widget_class_list = NULL; /* A list of all the GladeWidgetClass objects loaded */
#define GLADE_TAG_PALETTE "GladePalette"
static GList *glade_catalog_list = NULL; /* A list of GladeCatalog items */
static GList *widget_class_list = NULL; /* A list of all the GladeWidgetClass objects loaded */
GList *
glade_catalog_get_widgets (void)
......@@ -44,146 +46,172 @@ glade_catalog_get_widgets (void)
return widget_class_list;
}
static GladeCatalog *
glade_catalog_new (void)
{
GladeCatalog *catalog;
catalog = g_new0 (GladeCatalog, 1);
catalog->names = NULL;
catalog->widgets = NULL;
return catalog;
}
static void
void
glade_catalog_delete (GladeCatalog *catalog)
{
g_return_if_fail (catalog);
g_free (catalog);
}
static GList *
glade_catalog_load_names_from_node (GladeXmlContext *context, GladeXmlNode *node)
{
GladeXmlNode *child;
GList *list;
gchar *name;
if (!glade_xml_node_verify (node, GLADE_TAG_CATALOG))
return NULL;
if (catalog == NULL)
return;
list = NULL;
child = glade_xml_node_get_children (node);
for (; child; child = glade_xml_node_next (child)) {
if (!glade_xml_node_verify (child, GLADE_TAG_GLADE_WIDGET))
return NULL;
name = glade_xml_get_content (child);
if (name == NULL)
return NULL;
list = g_list_prepend (list, name);
}
g_free (catalog->title);
list = g_list_reverse (list);
list = catalog->widget_classes;
while (list != NULL)
{
glade_widget_class_free ((GladeWidgetClass*) list->data);
list = list->next;
}
return list;
g_list_free (catalog->widget_classes);
g_free (catalog);
}
static gboolean
glade_catalog_load_names_from_file (GladeCatalog *catalog, const gchar *file_name)
static GladeCatalog *
glade_catalog_load (const char *base_catalog_filename)
{
GladeXmlContext *context;
GladeXmlNode *root;
GladeXmlDoc *doc;
GladeWidgetClass *widget_class = NULL;
GladeXmlContext *context = NULL;
GladeXmlNode *root = NULL;
GladeXmlNode *widget_node = NULL;
GladeXmlDoc *doc = NULL;
GladeCatalog *catalog = NULL;
char *name = NULL;
char *generic_name = NULL;
char *catalog_filename = NULL;
char *base_filename = NULL;
GList *last_widget_class = NULL;
catalog_filename = g_strdup_printf ("%s%c%s", CATALOGS_DIR, G_DIR_SEPARATOR, base_catalog_filename);
if (catalog_filename == NULL)
{
g_critical ("Not enough memory.");
goto lblError;
}
context = glade_xml_context_new_from_path (file_name, NULL, GLADE_TAG_CATALOG);
/* get the context & root node of the catalog file */
context = glade_xml_context_new_from_path (catalog_filename, NULL, GLADE_TAG_CATALOG);
if (context == NULL)
return FALSE;
{
g_warning ("Impossible to open the catalog [%s].", catalog_filename);
goto lblError;
}
doc = glade_xml_context_get_doc (context);
root = glade_xml_doc_get_root (doc);
catalog->title = glade_xml_get_property_string_required (root, "Title", NULL);
catalog->names = glade_catalog_load_names_from_node (context, root);
glade_xml_context_free (context);
return TRUE;
}
/* allocate the catalog */
catalog = g_new0 (GladeCatalog, 1);
if (catalog == NULL)
{
g_critical ("Not enough memory.");
goto lblError;
}
static GladeCatalog *
glade_catalog_new_from_file (const gchar *file)
{
GladeCatalog *catalog;
last_widget_class = NULL;
catalog = glade_catalog_new ();
/* read the title of this catalog */
catalog->title = glade_xml_get_property_string_required (root, "Title", NULL);
if (!glade_catalog_load_names_from_file (catalog, file)) {
glade_catalog_delete (catalog);
return NULL;
if (!glade_xml_node_verify (root, GLADE_TAG_CATALOG))
{
g_warning ("The root node of [%s] has a name different from %s.", catalog_filename, GLADE_TAG_CATALOG);
goto lblError;
}
return catalog;
}
/* build all the GladeWidgetClass'es associated with this catalog */
widget_node = glade_xml_node_get_children (root);
for (; widget_node != NULL; widget_node = glade_xml_node_next (widget_node))
{
if (!glade_xml_node_verify (widget_node, GLADE_TAG_GLADE_WIDGET))
continue;
GladeCatalog *
glade_catalog_load (const gchar *file_name)
{
GladeWidgetClass *class;
GladeCatalog *catalog;
GList *list;
GList *new_list;
gchar *name;
name = glade_xml_get_property_string_required (widget_node, "name", NULL);
if (name == NULL)
continue;
catalog = glade_catalog_new_from_file (file_name);
if (catalog == NULL)
return NULL;
generic_name = glade_xml_get_property_string (widget_node, "generic_name");
base_filename = glade_xml_get_property_string (widget_node, "filename");
list = catalog->names;
new_list = NULL;
for (; list != NULL; list = list->next) {
name = list->data;
class = glade_widget_class_new_from_name (name);
if (class == NULL) continue;
new_list = g_list_prepend (new_list, class);
widget_class_list = g_list_prepend (widget_class_list, class);
/* We keep a list per catalog (group) and a general list of
* all widgets loaded
*/
}
widget_class = glade_widget_class_new_from_name2 (name, generic_name, base_filename);
if (widget_class)
{
last_widget_class = g_list_append (last_widget_class, widget_class);
catalog->widgets = g_list_reverse (new_list);
if (last_widget_class->next != NULL)
last_widget_class = last_widget_class->next;
else
catalog->widget_classes = last_widget_class;
}
glade_catalog_list = g_list_prepend (glade_catalog_list, catalog);
g_free (name);
g_free (generic_name);
g_free (base_filename);
}
glade_xml_context_free (context);
g_free (catalog_filename);
return catalog;
lblError:
glade_xml_context_free (context);
g_free (catalog_filename);
g_free (catalog);
return NULL;
}
GList *
glade_catalog_load_all (void)
{
GDir *catalogsdir = NULL;
static const char * const filename = CATALOGS_DIR G_DIR_SEPARATOR_S "glade-palette.xml";
GladeXmlContext *context;
GladeXmlNode *root;
GladeXmlNode *xml_catalogs;
GladeXmlDoc *doc;
GList *catalogs = NULL;
GladeCatalog *gcatalog = NULL;
const char *base_filename = NULL;
char *filename = NULL;
GladeCatalog *catalog;
catalogsdir = g_dir_open (CATALOGS_DIR, 0, NULL);
if (!catalogsdir) {
g_warning ("Could not open catalogs from %s\n", CATALOGS_DIR);
context = glade_xml_context_new_from_path (filename, NULL, GLADE_TAG_PALETTE);
if (context == NULL)
{
g_critical ("Unable to open %s.\n", filename);
return NULL;
}
while ((base_filename = g_dir_read_name (catalogsdir)) != NULL) {
filename = g_strdup_printf ("%s/%s", CATALOGS_DIR, base_filename);
gcatalog = glade_catalog_load (filename);
if (gcatalog)
catalogs = g_list_append (catalogs, gcatalog);
g_free (filename);
doc = glade_xml_context_get_doc (context);
root = glade_xml_doc_get_root (doc);
xml_catalogs = glade_xml_node_get_children (root);
while (xml_catalogs != NULL) {
char *name = glade_xml_get_property_string_required (xml_catalogs, "filename", NULL);
if (!strcmp(glade_xml_node_get_name (xml_catalogs), GLADE_TAG_CATALOG))
{
catalog = glade_catalog_load (name);
if (catalog)
catalogs = g_list_append (catalogs, catalog);
else
g_warning ("Unable to open the catalog %s.\n", name);
}
else
g_warning ("The palette file \"glade-palette.xml\" has "
"a node with name %s instead of " GLADE_TAG_CATALOG "\n", name);
xml_catalogs = glade_xml_node_next (xml_catalogs);
g_free (name);
}
g_dir_close (catalogsdir);
glade_xml_context_free (context);
return catalogs;
}
const char *glade_catalog_get_title (GladeCatalog *catalog)
{
g_return_val_if_fail (catalog != NULL, NULL);
return catalog->title;
}
GList *glade_catalog_get_widget_classes (GladeCatalog *catalog)
{
g_return_val_if_fail (catalog != NULL, NULL);
return catalog->widget_classes;
}
......@@ -12,20 +12,14 @@ G_BEGIN_DECLS
struct _GladeCatalog
{
gchar *title; /* Title for this catalog */
GList *names; /* Contains the list of names that we are going
* to try to load. This is basically a memory
* representation of catalog.xml
*/
GList *widgets; /* Contains the list of GladeWidgetClass objects
* that where successfully loaded from disk
*/
GList *widget_classes; /* list of widget classes contained on this catalog */
};
GladeCatalog * glade_catalog_load (const gchar *file_name);
GladeCatalog * glade_catalog_get (void);
void glade_catalog_delete (GladeCatalog *catalog);
GList * glade_catalog_load_all (void);
GList * glade_catalog_get_widgets (void); /* This prolly should be in glade-widget-class.c */
GList *glade_catalog_get_widgets (void); /* This probally should be in glade-widget-class.c */
const char *glade_catalog_get_title (GladeCatalog *catalog);
GList *glade_catalog_get_widget_classes (GladeCatalog *catalog);
G_END_DECLS
......
......@@ -189,7 +189,7 @@ glade_palette_widget_table_create (GladePalette *palette, GladeCatalog *catalog)
gint cols = 4;
gint i;
list = catalog->widgets;
list = glade_catalog_get_widget_classes (catalog);
while (list) {
if (((GladeWidgetClass*) list->data)->in_palette)
......@@ -198,7 +198,7 @@ glade_palette_widget_table_create (GladePalette *palette, GladeCatalog *catalog)
list = list->next;
}
list = catalog->widgets;
list = glade_catalog_get_widget_classes (catalog);
num = g_list_length (list);
rows = (gint)((num_visible - 1)/ cols) + 1;
......
......@@ -100,16 +100,14 @@ glade_parameter_get_string (GList *parameters, const gchar *key, gchar **value)
}
}
static void
void
glade_parameter_free (GladeParameter *parameter)
{
g_return_if_fail (parameter->key);
g_return_if_fail (parameter->value);
if (!parameter)
return;
g_free (parameter->key);
g_free (parameter->value);
parameter->key = NULL;
parameter->value = NULL;
g_free (parameter);
}
......@@ -123,6 +121,21 @@ glade_parameter_new (void)
return parameter;
}
GladeParameter *
glade_parameter_clone (GladeParameter *parameter)
{
GladeParameter *clon;
if (parameter == NULL)
return NULL;
clon = glade_parameter_new ();
clon->key = g_strdup (parameter->key);
clon->value = g_strdup (parameter->value);
return clon;
}
static GladeParameter *
glade_parameter_new_from_node (GladeXmlNode *node)
{
......
......@@ -32,6 +32,8 @@ struct _GladeParameter {
};
GladeParameter * glade_parameter_new (void);
GladeParameter *glade_parameter_clone (GladeParameter *parameter);
void glade_parameter_free (GladeParameter *parameter);
void glade_parameter_get_float (GList *parameters, const gchar *key, gfloat *value);
void glade_parameter_get_integer (GList *parameters, const gchar *key, gint *value);
......
......@@ -48,6 +48,103 @@ typedef struct GladePropertyTypeTable {
/* #warning Implement me. */
#endif
static GladeChoice *
glade_property_class_choice_new_from_value (GEnumValue value)
{
GladeChoice *choice;
choice = glade_choice_new ();
choice->name = g_strdup (value.value_nick);
choice->id = g_strdup (value.value_name);
/*
g_debug(("Choice Id is %s\n", choice->id));
choice->symbol = g_strdup (value.value_name);
*/
choice->value = value.value;
return choice;
}
static GList *
glade_property_class_get_choices_from_spec (GParamSpec *spec)
{
GladeChoice *choice;
GEnumClass *class;
GEnumValue value;
GList *list = NULL;
gint num;
gint i;
class = G_PARAM_SPEC_ENUM (spec)->enum_class;
num = class->n_values;
for (i = 0; i < num; i++) {
value = class->values[i];
choice = glade_property_class_choice_new_from_value (value);
if (choice)
list = g_list_prepend (list, choice);
}
list = g_list_reverse (list);
return list;
}
static GladeChoice *
glade_property_class_choice_clone (GladeChoice *choice)
{
GladeChoice *clon;
clon = glade_choice_new ();
clon->id = g_strdup (choice->id);
clon->name = g_strdup (choice->name);
clon->type = choice->type;
clon->value = choice->value;
return clon;
}
static void
glade_property_class_choice_free (GladeChoice *choice)
{
if (choice == NULL)
return;
g_free (choice->name);
g_free (choice->id);
g_free (choice);
}
#if 0
static gchar *
glade_property_get_default_choice (GParamSpec *spec,
GladePropertyClass *class)
{
GladeChoice *choice = NULL;
GList *list;
gint def;
g_return_val_if_fail (G_IS_PARAM_SPEC_ENUM (spec), NULL);
def = (gint) G_PARAM_SPEC_ENUM (spec)->default_value;
list = class->choices;
for (; list != NULL; list = list->next) {
choice = list->data;
if (choice->value == def)
break;
}
if (list == NULL) {
g_warning ("Could not find the default value for %s\n", spec->nick);
if (class->choices == NULL)
return NULL;
choice = class->choices->data;
}
return g_strdup (choice->symbol);
}
#endif
GladePropertyType
glade_property_type_str_to_enum (const gchar *str)
{
......@@ -138,6 +235,32 @@ glade_query_new_from_node (GladeXmlNode *node)
return query;
}
static GladePropertyQuery *
glade_property_query_clone (GladePropertyQuery *query)
{
GladePropertyQuery *clon;
if (query == NULL)
return NULL;
clon = glade_property_query_new ();
clon->window_title = g_strdup (query->window_title);
clon->question = g_strdup (clon->question);
return clon;
}
static void
glade_property_query_free (GladePropertyQuery *query)
{
if (query == NULL)
return;
g_free (query->window_title);
g_free (query->question);
g_free (query);
}
GladePropertyClass *
glade_property_class_new (void)
{
......@@ -161,12 +284,80 @@ glade_property_class_new (void)
property_class->common = FALSE;
property_class->packing = FALSE;
property_class->get_default = FALSE;
property_class->is_modified = FALSE;
property_class->query = NULL;
property_class->set_function = NULL;
property_class->get_function = NULL;
return property_class;
}
GladePropertyClass *
glade_property_class_clone (GladePropertyClass *property_class)
{
GladePropertyClass *clon;
if (property_class == NULL)
return NULL;
clon = g_new0 (GladePropertyClass, 1);
if (clon == NULL)
{
g_warning ("Out of memory.");
return NULL;
}
memcpy (clon, property_class, sizeof(GladePropertyClass));
clon->id = g_strdup (clon->id);
clon->name = g_strdup (clon->name);
clon->tooltip = g_strdup (clon->tooltip);
if (G_IS_VALUE (property_class->def))
{
clon->def = g_new0 (GValue, 1);
g_value_init (clon->def, G_VALUE_TYPE (property_class->def));
g_value_copy (property_class->def, clon->def);
}
if (clon->parameters)
{
GList *parameter;
clon->parameters = g_list_copy (clon->parameters);
for (parameter = clon->parameters; parameter != NULL; parameter = parameter->next)
parameter->data = glade_parameter_clone ((GladeParameter*) parameter->data);
}
if (clon->choices)
{
GList *choice;
clon->choices = g_list_copy (clon->choices);
for (choice = clon->choices; choice != NULL; choice = choice->next)
choice->data = glade_property_class_choice_clone ((GladeChoice*) choice->data);
}
clon->query = glade_property_query_clone (clon->query);
/* ok, wtf? what is the child member for? */
/* if (clon->child)
clon->child = glade_widget_class_clone (clon->child); */
if (clon->update_signals)
{
GList *signals;
clon->update_signals = g_list_copy (clon->update_signals);
for (signals = clon->update_signals; signals != NULL; signals = signals->next)
signals->data = g_strdup ((const char *) signals->data);
}
return clon;
}
void
glade_property_class_free (GladePropertyClass *class)
{
......@@ -175,11 +366,19 @@ glade_property_class_free (GladePropertyClass *class)
g_return_if_fail (GLADE_IS_PROPERTY_CLASS (class));
g_free (class->name);
g_free (class->id);
g_free (class->tooltip);
g_free (class->name);
g_free (class->def);
g_list_foreach (class->parameters, (GFunc) glade_parameter_free, NULL);
g_list_free (class->parameters);
g_list_foreach (class->choices, (GFunc) glade_property_class_choice_free, NULL);
g_list_free (class->choices);
glade_property_query_free (class->query);
glade_widget_class_free (class->child);
g_list_foreach (class->update_signals, (GFunc) g_free, NULL);
g_list_free (class->update_signals);
g_free (class);
class = NULL;
}
static GladePropertyType
......@@ -285,78 +484,6 @@ glade_property_class_get_default_from_spec (GParamSpec *spec,
return value;
}
static GladeChoice *
glade_property_class_choice_new_from_value (GEnumValue value)
{
GladeChoice *choice;
choice = glade_choice_new ();
choice->name = g_strdup (value.value_nick);
choice->id = g_strdup (value.value_name);
/*
g_debug(("Choice Id is %s\n", choice->id));
choice->symbol = g_strdup (value.value_name);
*/
choice->value = value.value;
return choice;
}
static GList *
glade_property_class_get_choices_from_spec (GParamSpec *spec)
{
GladeChoice *choice;
GEnumClass *class;
GEnumValue value;
GList *list = NULL;
gint num;
gint i;
class = G_PARAM_SPEC_ENUM (spec)->enum_class;
num = class->n_values;
for (i = 0; i < num; i++) {
value = class->values[i];
choice = glade_property_class_choice_new_from_value (value);
if (choice)
list = g_list_prepend (list, choice);
}
list = g_list_reverse (list);
return list;
}
#if 0
static gchar *
glade_property_get_default_choice (GParamSpec *spec,
GladePropertyClass *class)
{
GladeChoice *choice = NULL;
GList *list;
gint def;
g_return_val_if_fail (G_IS_PARAM_SPEC_ENUM (spec), NULL);
def = (gint) G_PARAM_SPEC_ENUM (spec)->default_value;
list = class->choices;
for (; list != NULL; list = list->next) {
choice = list->data;
if (choice->value == def)
break;
}
if (list == NULL) {
g_warning ("Could not find the default value for %s\n", spec->nick);
if (class->choices == NULL)
return NULL;
choice = class->choices->data;
}
return g_strdup (choice->symbol);
}
#endif
gchar *
glade_property_class_make_string_from_gvalue (GladePropertyClass *property_class,
const GValue *value)
......@@ -785,8 +912,7 @@ glade_property_class_update_from_node (GladeXmlNode *node,
gchar *id;
gchar *name;
if (!glade_xml_node_verify (node, GLADE_TAG_PROPERTY))
return;
g_return_if_fail (glade_xml_node_verify (node, GLADE_TAG_PROPERTY));
/* If we have a property like ... Disabled="TRUE"> we should
* remove this property
......@@ -878,7 +1004,8 @@ glade_property_class_update_from_node (GladeXmlNode *node,
pproperty_class->def = gvalue;
glade_property_class_free (*property_class);
*property_class = pproperty_class;
} else {
}
else {
/* If the property is an object Load it */
if (pproperty_class->type == GLADE_PROPERTY_TYPE_OBJECT) {
child = glade_xml_search_child_required (node, GLADE_TAG_GLADE_WIDGET_CLASS);
......@@ -905,6 +1032,9 @@ glade_property_class_update_from_node (GladeXmlNode *node,
}
}
/* we're modifying the default values of this property */
pproperty_class->is_modified = TRUE;