Commit b7d98012 authored by Tristan Van Berkom's avatar Tristan Van Berkom

Added version macros


	* gladeui/glade-xml-utils.h: Added version macros

	* plugins/gtk+/gtk+.xml.in: Added version 2.14

	* gladeui/glade-project.c: Now glade loads and saves requires
	  metadata as comments at the toplevel in libglade and older versions
	  of gtk+ that dont recognize versioning (i.e. gtk+ < 2.14) (bug 536310)


svn path=/trunk/; revision=1910
parent 3e9cc04c
......@@ -118,7 +118,15 @@
* src/glade-window.c: Fixed projects menu bug (bug 532156, fix by
Pavel Kostyuchenko).
* gladeui/glade-xml-utils.h: Added version macros
* plugins/gtk+/gtk+.xml.in: Added version 2.14
* gladeui/glade-project.c: Now glade loads and saves requires
metadata as comments at the toplevel in libglade and older versions
of gtk+ that dont recognize versioning (i.e. gtk+ < 2.14) (bug 536310)
2008-09-15 Juan Pablo Ugarte <juanpablougarte@gmail.com>
* plugins/gtk+/glade-gtk.c, plugins/gtk+/gtk+.xml.in:
......
......@@ -1071,6 +1071,35 @@ glade_project_fix_object_props (GladeProject *project)
}
}
static gchar *
glade_project_read_requires_from_comment (GladeXmlNode *comment,
gint *major,
gint *minor)
{
gint maj, min;
gchar *value, buffer[256];
gchar *required_lib = NULL;
if (!glade_xml_node_is_comment (comment))
return FALSE;
value = glade_xml_get_content (comment);
if (value && !strncmp ("interface-requires", value, strlen ("interface-requires")))
{
if (sscanf (value, "interface-requires %s %d.%d", buffer, &maj, &min) == 3)
{
if (major) *major = maj;
if (minor) *minor = min;
required_lib = g_strdup (buffer);
}
}
g_free (value);
return required_lib;
}
static gboolean
glade_project_read_requires (GladeProject *project,
GladeXmlNode *root_node,
......@@ -1079,67 +1108,48 @@ glade_project_read_requires (GladeProject *project,
GString *string = g_string_new (NULL);
GladeXmlNode *node;
gchar *required_lib;
gchar *required_lib = NULL;
gboolean loadable = TRUE;
gint major, minor;
for (node = glade_xml_node_get_children (root_node);
node; node = glade_xml_node_next (node))
for (node = glade_xml_node_get_children_with_comments (root_node);
node; node = glade_xml_node_next_with_comments (node))
{
/* Skip non "requires" tags */
if (!glade_xml_node_verify_silent (node, GLADE_XML_TAG_REQUIRES))
if (!(glade_xml_node_verify_silent (node, GLADE_XML_TAG_REQUIRES) ||
(required_lib =
glade_project_read_requires_from_comment (node, &major, &minor))))
continue;
if ((required_lib =
glade_xml_get_property_string_required (node, GLADE_XML_TAG_LIB,
NULL)) != NULL)
if (!required_lib)
{
/* Dont mention gtk+ as a required lib in
* the generated glade file
*/
if (!glade_catalog_is_loaded (required_lib))
{
if (!loadable)
g_string_append (string, ", ");
g_string_append (string, required_lib);
loadable = FALSE;
}
else if (glade_xml_get_property_version (node,
GLADE_XML_TAG_VERSION,
&major, &minor))
glade_project_set_target_version
(project, required_lib, major, minor);
g_free (required_lib);
required_lib =
glade_xml_get_property_string_required (node, GLADE_XML_TAG_LIB,
NULL);
glade_xml_get_property_version (node, GLADE_XML_TAG_VERSION,
&major, &minor);
}
}
if (!required_lib) continue;
/* We use a different tag to save target version metadata in libglade files */
for (node = glade_xml_node_get_children (root_node);
node; node = glade_xml_node_next (node))
{
/* Skip non "requires" tags */
if (!glade_xml_node_verify_silent (node, GLADE_XML_TAG_REQUIRES_LIBGLADE_EXTRA))
continue;
if ((required_lib =
glade_xml_get_property_string_required (node, GLADE_XML_TAG_LIB,
NULL)) != NULL)
/* Dont mention gtk+ as a required lib in
* the generated glade file
*/
if (!glade_catalog_is_loaded (required_lib))
{
if (glade_xml_get_property_version (node,
GLADE_XML_TAG_VERSION,
&major, &minor))
glade_project_set_target_version
(project, required_lib, major, minor);
if (!loadable)
g_string_append (string, ", ");
g_free (required_lib);
g_string_append (string, required_lib);
loadable = FALSE;
}
else
glade_project_set_target_version
(project, required_lib, major, minor);
g_free (required_lib);
}
if (!loadable)
glade_util_ui_message (glade_app_get_window(),
GLADE_UI_ERROR, NULL,
......@@ -2422,28 +2432,17 @@ glade_project_update_comment (GladeProject *project)
g_strfreev (lines);
}
static GladeXmlContext *
glade_project_write (GladeProject *project)
static void
glade_project_write_required_libs (GladeProject *project,
GladeXmlContext *context,
GladeXmlNode *root)
{
GladeProjectFormat fmt;
GladeXmlContext *context;
GladeXmlDoc *doc;
GladeXmlNode *root, *req_node, *comment_node;
GladeXmlNode *req_node;
GList *required, *list;
gint major, minor;
gchar *version;
doc = glade_xml_doc_new ();
context = glade_xml_context_new (doc, NULL);
root = glade_xml_node_new (context, GLADE_XML_TAG_PROJECT (project->priv->format));
glade_xml_doc_set_root (doc, root);
glade_project_update_comment (project);
/* comment_node = glade_xml_node_new_comment (context, project->priv->comment); */
/* XXX Need to append this to the doc ! not the ROOT !
glade_xml_node_append_child (root, comment_node); */
fmt = glade_project_get_format (project);
if ((required = glade_project_required_libs (project)) != NULL)
......@@ -2460,12 +2459,23 @@ glade_project_write (GladeProject *project)
(fmt == GLADE_PROJECT_FORMAT_LIBGLADE &&
strcmp ("gtk+", (gchar *)list->data)))
{
req_node = glade_xml_node_new (context, GLADE_XML_TAG_REQUIRES);
glade_xml_node_append_child (root, req_node);
glade_xml_node_set_property_string (req_node,
GLADE_XML_TAG_LIB,
(gchar *)list->data);
if (GLADE_GTKBUILDER_HAS_VERSIONING (major, minor))
{
req_node = glade_xml_node_new (context, GLADE_XML_TAG_REQUIRES);
glade_xml_node_append_child (root, req_node);
glade_xml_node_set_property_string (req_node,
GLADE_XML_TAG_LIB,
(gchar *)list->data);
}
else
{
gchar *comment =
g_strdup_printf ("interface-requires %s %s",
(gchar *)list->data, version);
req_node = glade_xml_node_new_comment (context, comment);
glade_xml_node_append_child (root, req_node);
g_free (comment);
}
if (fmt != GLADE_PROJECT_FORMAT_LIBGLADE)
glade_xml_node_set_property_string
......@@ -2475,17 +2485,11 @@ glade_project_write (GladeProject *project)
/* Add extra metadata for libglade */
if (fmt == GLADE_PROJECT_FORMAT_LIBGLADE)
{
req_node = glade_xml_node_new
(context, GLADE_XML_TAG_REQUIRES_LIBGLADE_EXTRA);
gchar *comment = g_strdup_printf ("interface-requires %s %s",
(gchar *)list->data, version);
req_node = glade_xml_node_new_comment (context, comment);
glade_xml_node_append_child (root, req_node);
glade_xml_node_set_property_string (req_node,
GLADE_XML_TAG_LIB,
(gchar *)list->data);
glade_xml_node_set_property_string (req_node,
GLADE_XML_TAG_VERSION,
version);
g_free (comment);
}
g_free (version);
......@@ -2494,6 +2498,29 @@ glade_project_write (GladeProject *project)
g_list_free (required);
}
}
static GladeXmlContext *
glade_project_write (GladeProject *project)
{
GladeXmlContext *context;
GladeXmlDoc *doc;
GladeXmlNode *root, *comment_node;
GList *list;
doc = glade_xml_doc_new ();
context = glade_xml_context_new (doc, NULL);
root = glade_xml_node_new (context, GLADE_XML_TAG_PROJECT (project->priv->format));
glade_xml_doc_set_root (doc, root);
glade_project_update_comment (project);
/* comment_node = glade_xml_node_new_comment (context, project->priv->comment); */
/* XXX Need to append this to the doc ! not the ROOT !
glade_xml_node_append_child (root, comment_node); */
glade_project_write_required_libs (project, context, root);
/* Any automatically generated stuff goes here */
glade_project_generate_nodes (project, context, root);
......
......@@ -28,15 +28,20 @@ typedef struct _GladeXmlDoc GladeXmlDoc;
((type == GLADE_PROJECT_FORMAT_LIBGLADE) ? \
GLADE_XML_TAG_LIBGLADE_WIDGET : GLADE_XML_TAG_BUILDER_WIDGET)
/* Used for catalog tags and attributes */
#define GLADE_GTKBUILDER_VERSIONING_BASE_MAJOR 2
#define GLADE_GTKBUILDER_VERSIONING_BASE_MINOR 14
#define GLADE_GTKBUILDER_HAS_VERSIONING(maj, min) \
((maj) >= GLADE_GTKBUILDER_VERSIONING_BASE_MAJOR && \
(min) >= GLADE_GTKBUILDER_VERSIONING_BASE_MINOR)
/* Used for catalog tags and attributes */
#define GLADE_XML_TAG_LIBGLADE_PROJECT "glade-interface"
#define GLADE_XML_TAG_BUILDER_PROJECT "interface"
#define GLADE_XML_TAG_LIBGLADE_WIDGET "widget"
#define GLADE_XML_TAG_BUILDER_WIDGET "object"
#define GLADE_XML_TAG_VERSION "version"
#define GLADE_XML_TAG_REQUIRES_LIBGLADE_EXTRA "requires-version"
#define GLADE_XML_TAG_REQUIRES "requires"
#define GLADE_XML_TAG_LIB "lib"
#define GLADE_XML_TAG_PROPERTY "property"
......
<glade-catalog name="gtk+"
version="2.12"
targetable="2.10,2.8"
version="2.14"
targetable="2.10,2.8,2.12"
icon-prefix="gtk"
library="gladegtk"
domain="glade3"
......
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