2019-02-07 09:12:09 +00:00
|
|
|
|
/* Copyright 2015 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* GTK+ is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU Lesser General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* GLib is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with GTK+; see the file COPYING. If not,
|
|
|
|
|
* see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* Author: Matthias Clasen
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
|
#include <glib/gprintf.h>
|
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
#include "gtkbuilderprivate.h"
|
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
typedef struct Element Element;
|
|
|
|
|
struct Element {
|
|
|
|
|
Element *parent;
|
|
|
|
|
char *element_name;
|
|
|
|
|
char **attribute_names;
|
|
|
|
|
char **attribute_values;
|
|
|
|
|
char *data;
|
|
|
|
|
GList *children;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
free_element (gpointer data)
|
|
|
|
|
{
|
|
|
|
|
Element *element = data;
|
|
|
|
|
g_list_free_full (element->children, free_element);
|
|
|
|
|
g_free (element->element_name);
|
|
|
|
|
g_strfreev (element->attribute_names);
|
|
|
|
|
g_strfreev (element->attribute_values);
|
|
|
|
|
g_free (element->data);
|
|
|
|
|
g_free (element);
|
|
|
|
|
}
|
2019-02-07 09:12:09 +00:00
|
|
|
|
|
|
|
|
|
typedef struct {
|
2019-02-07 12:12:15 +00:00
|
|
|
|
Element *root;
|
|
|
|
|
Element *current;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
GString *value;
|
2019-02-07 12:12:15 +00:00
|
|
|
|
GtkBuilder *builder;
|
2019-02-07 17:24:49 +00:00
|
|
|
|
const char *input_filename;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
char *output_filename;
|
|
|
|
|
FILE *output;
|
2019-02-07 12:12:15 +00:00
|
|
|
|
gboolean convert3to4;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
} MyParserData;
|
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
static void
|
|
|
|
|
start_element (GMarkupParseContext *context,
|
|
|
|
|
const char *element_name,
|
|
|
|
|
const char **attribute_names,
|
|
|
|
|
const char **attribute_values,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
MyParserData *data = user_data;
|
|
|
|
|
Element *elt;
|
|
|
|
|
|
|
|
|
|
elt = g_new0 (Element, 1);
|
|
|
|
|
elt->parent = data->current;
|
|
|
|
|
elt->element_name = g_strdup (element_name);
|
|
|
|
|
elt->attribute_names = g_strdupv ((char **)attribute_names);
|
|
|
|
|
elt->attribute_values = g_strdupv ((char **)attribute_values);
|
|
|
|
|
|
|
|
|
|
if (data->current)
|
|
|
|
|
data->current->children = g_list_append (data->current->children, elt);
|
|
|
|
|
data->current = elt;
|
|
|
|
|
|
|
|
|
|
if (data->root == NULL)
|
|
|
|
|
data->root = elt;
|
|
|
|
|
|
|
|
|
|
g_string_truncate (data->value, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
end_element (GMarkupParseContext *context,
|
|
|
|
|
const char *element_name,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
MyParserData *data = user_data;
|
|
|
|
|
|
|
|
|
|
data->current->data = g_strdup (data->value->str);
|
|
|
|
|
|
|
|
|
|
data->current = data->current->parent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
text (GMarkupParseContext *context,
|
|
|
|
|
const char *text,
|
|
|
|
|
gsize text_len,
|
|
|
|
|
gpointer user_data,
|
|
|
|
|
GError **error)
|
|
|
|
|
{
|
|
|
|
|
MyParserData *data = user_data;
|
|
|
|
|
|
|
|
|
|
if (data->value)
|
|
|
|
|
{
|
|
|
|
|
g_string_append_len (data->value, text, text_len);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GMarkupParser parser = {
|
|
|
|
|
start_element,
|
|
|
|
|
end_element,
|
|
|
|
|
text,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const gchar *
|
|
|
|
|
canonical_boolean_value (MyParserData *data,
|
|
|
|
|
const gchar *string)
|
|
|
|
|
{
|
|
|
|
|
GValue value = G_VALUE_INIT;
|
|
|
|
|
gboolean b = FALSE;
|
|
|
|
|
|
|
|
|
|
if (gtk_builder_value_from_string_type (data->builder, G_TYPE_BOOLEAN, string, &value, NULL))
|
|
|
|
|
b = g_value_get_boolean (&value);
|
|
|
|
|
|
|
|
|
|
return b ? "1" : "0";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* A number of properties unfortunately can't be omitted even
|
|
|
|
|
* if they are nominally set to their default value. In many
|
|
|
|
|
* cases, this is due to subclasses not overriding the default
|
|
|
|
|
* value from the superclass.
|
|
|
|
|
*/
|
|
|
|
|
static gboolean
|
2019-02-08 15:33:11 +00:00
|
|
|
|
needs_explicit_setting (GParamSpec *pspec,
|
|
|
|
|
gboolean packing)
|
2019-02-07 12:12:15 +00:00
|
|
|
|
{
|
|
|
|
|
struct _Prop {
|
|
|
|
|
const char *class;
|
|
|
|
|
const char *property;
|
|
|
|
|
gboolean packing;
|
|
|
|
|
} props[] = {
|
|
|
|
|
{ "GtkAboutDialog", "program-name", 0 },
|
|
|
|
|
{ "GtkCalendar", "year", 0 },
|
|
|
|
|
{ "GtkCalendar", "month", 0 },
|
|
|
|
|
{ "GtkCalendar", "day", 0 },
|
|
|
|
|
{ "GtkPlacesSidebar", "show-desktop", 0 },
|
|
|
|
|
{ "GtkRadioButton", "draw-indicator", 0 },
|
|
|
|
|
{ "GtkGrid", "left-attach", 1 },
|
|
|
|
|
{ "GtkGrid", "top-attach", 1 },
|
|
|
|
|
{ "GtkWidget", "hexpand", 0 },
|
|
|
|
|
{ "GtkWidget", "vexpand", 0 },
|
|
|
|
|
};
|
|
|
|
|
gboolean found;
|
|
|
|
|
gint k;
|
2019-02-08 15:33:11 +00:00
|
|
|
|
const char *class_name;
|
2019-02-07 12:12:15 +00:00
|
|
|
|
|
2019-02-08 15:33:11 +00:00
|
|
|
|
class_name = g_type_name (pspec->owner_type);
|
2019-02-07 12:12:15 +00:00
|
|
|
|
|
|
|
|
|
found = FALSE;
|
|
|
|
|
for (k = 0; k < G_N_ELEMENTS (props); k++)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (class_name, props[k].class) == 0 &&
|
2019-02-08 15:33:11 +00:00
|
|
|
|
strcmp (pspec->name, props[k].property) == 0 &&
|
2019-02-07 12:12:15 +00:00
|
|
|
|
packing == props[k].packing)
|
|
|
|
|
{
|
|
|
|
|
found = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 22:38:29 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
keep_for_rewrite (const char *class_name,
|
|
|
|
|
const char *prop_name,
|
|
|
|
|
gboolean packing)
|
|
|
|
|
{
|
|
|
|
|
struct _Prop {
|
|
|
|
|
const char *class;
|
|
|
|
|
const char *property;
|
|
|
|
|
gboolean packing;
|
|
|
|
|
} props[] = {
|
|
|
|
|
{ "GtkActionBar", "pack-type", 1 },
|
|
|
|
|
{ "GtkHeaderBar", "pack-type", 1 },
|
|
|
|
|
{ "GtkPopoverMenu", "submenu", 1 },
|
2019-03-28 00:03:34 +00:00
|
|
|
|
{ "GtkToolbar", "expand", 1 },
|
|
|
|
|
{ "GtkToolbar", "homogeneous", 1 },
|
2019-03-27 22:38:29 +00:00
|
|
|
|
};
|
|
|
|
|
gboolean found;
|
|
|
|
|
gint k;
|
|
|
|
|
|
|
|
|
|
found = FALSE;
|
|
|
|
|
for (k = 0; k < G_N_ELEMENTS (props); k++)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (class_name, props[k].class) == 0 &&
|
|
|
|
|
strcmp (prop_name, props[k].property) == 0 &&
|
|
|
|
|
packing == props[k].packing)
|
|
|
|
|
{
|
|
|
|
|
found = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
is_pcdata_element (Element *element)
|
|
|
|
|
{
|
|
|
|
|
/* elements that can contain text */
|
|
|
|
|
const char *names[] = {
|
|
|
|
|
"property",
|
|
|
|
|
"attribute",
|
|
|
|
|
"action-widget",
|
|
|
|
|
"pattern",
|
|
|
|
|
"mime-type",
|
|
|
|
|
"col",
|
|
|
|
|
"item",
|
|
|
|
|
NULL,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (g_str_equal (element->element_name, "property") &&
|
|
|
|
|
(g_strv_contains ((const char * const *)element->attribute_names, "bind-source") ||
|
|
|
|
|
g_strv_contains ((const char * const *)element->attribute_names, "bind_source")))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (g_strv_contains (names, element->element_name))
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
is_container_element (Element *element)
|
|
|
|
|
{
|
|
|
|
|
/* elements that just hold a list of things and
|
|
|
|
|
* can be omitted when they have no children
|
|
|
|
|
*/
|
|
|
|
|
const char *names[] = {
|
|
|
|
|
"packing",
|
|
|
|
|
"cell-packing",
|
|
|
|
|
"attributes",
|
|
|
|
|
"action-widgets",
|
|
|
|
|
"patterns",
|
|
|
|
|
"mime-types",
|
|
|
|
|
"attributes",
|
|
|
|
|
"row",
|
2019-02-07 17:24:49 +00:00
|
|
|
|
"items",
|
|
|
|
|
NULL
|
2019-02-07 12:12:15 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (g_strv_contains (names, element->element_name))
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 09:12:09 +00:00
|
|
|
|
static void
|
|
|
|
|
canonicalize_key (gchar *key)
|
|
|
|
|
{
|
|
|
|
|
gchar *p;
|
|
|
|
|
|
|
|
|
|
for (p = key; *p != 0; p++)
|
|
|
|
|
{
|
|
|
|
|
gchar c = *p;
|
|
|
|
|
|
|
|
|
|
/* We may meet something like AtkObject::accessible-name */
|
|
|
|
|
if (c == ':' && ((p > key && p[-1] == ':') || p[1] == ':'))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (c != '-' &&
|
|
|
|
|
(c < '0' || c > '9') &&
|
|
|
|
|
(c < 'A' || c > 'Z') &&
|
|
|
|
|
(c < 'a' || c > 'z'))
|
|
|
|
|
*p = '-';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GParamSpec *
|
|
|
|
|
get_property_pspec (MyParserData *data,
|
|
|
|
|
const gchar *class_name,
|
2019-02-07 12:12:15 +00:00
|
|
|
|
const gchar *property_name,
|
|
|
|
|
gboolean packing,
|
|
|
|
|
gboolean cell_packing)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
GType type;
|
|
|
|
|
GObjectClass *class;
|
|
|
|
|
GParamSpec *pspec;
|
|
|
|
|
gchar *canonical_name;
|
|
|
|
|
|
|
|
|
|
type = g_type_from_name (class_name);
|
|
|
|
|
if (type == G_TYPE_INVALID)
|
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
type = gtk_builder_get_type_from_name (data->builder, class_name);
|
2019-02-07 09:12:09 +00:00
|
|
|
|
if (type == G_TYPE_INVALID)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class = g_type_class_ref (type);
|
|
|
|
|
canonical_name = g_strdup (property_name);
|
|
|
|
|
canonicalize_key (canonical_name);
|
2019-02-07 12:12:15 +00:00
|
|
|
|
if (packing)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
pspec = gtk_container_class_find_child_property (class, canonical_name);
|
2019-02-07 12:12:15 +00:00
|
|
|
|
else if (cell_packing)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
GObjectClass *cell_class;
|
|
|
|
|
|
|
|
|
|
/* We're just assuming that the cell layout is using a GtkCellAreaBox. */
|
|
|
|
|
cell_class = g_type_class_ref (GTK_TYPE_CELL_AREA_BOX);
|
|
|
|
|
pspec = gtk_cell_area_class_find_cell_property (GTK_CELL_AREA_CLASS (cell_class), canonical_name);
|
|
|
|
|
g_type_class_unref (cell_class);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
pspec = g_object_class_find_property (class, canonical_name);
|
|
|
|
|
g_free (canonical_name);
|
|
|
|
|
g_type_class_unref (class);
|
|
|
|
|
|
|
|
|
|
return pspec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
value_is_default (MyParserData *data,
|
2019-02-08 15:33:11 +00:00
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
const gchar *value_string)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
GValue value = { 0, };
|
|
|
|
|
gboolean ret;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
2019-02-08 15:33:11 +00:00
|
|
|
|
if (g_type_is_a (G_PARAM_SPEC_VALUE_TYPE (pspec), G_TYPE_OBJECT))
|
2019-02-07 09:12:09 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!gtk_builder_value_from_string (data->builder, pspec, value_string, &value, &error))
|
|
|
|
|
{
|
2019-02-08 15:33:11 +00:00
|
|
|
|
g_printerr (_("%s: Couldn’t parse value for %s: %s\n"), data->input_filename, pspec->name, error->message);
|
2019-02-07 09:12:09 +00:00
|
|
|
|
g_error_free (error);
|
|
|
|
|
ret = FALSE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
ret = g_param_value_defaults (pspec, &value);
|
|
|
|
|
|
|
|
|
|
g_value_reset (&value);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 22:38:29 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
has_attribute (Element *elt,
|
|
|
|
|
const char *name,
|
|
|
|
|
const char *value)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; elt->attribute_names[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (elt->attribute_names[i], name) == 0 &&
|
|
|
|
|
(value == NULL || strcmp (elt->attribute_values[i], value) == 0))
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 17:14:39 +00:00
|
|
|
|
static const char *
|
|
|
|
|
get_attribute_value (Element *element,
|
|
|
|
|
const char *name)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; element->attribute_names[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
if (g_str_equal (element->attribute_names[i], name))
|
|
|
|
|
return element->attribute_values[i];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
static const char *
|
|
|
|
|
get_class_name (Element *element)
|
|
|
|
|
{
|
|
|
|
|
Element *parent = element->parent;
|
|
|
|
|
|
|
|
|
|
if (g_str_equal (element->element_name, "object"))
|
|
|
|
|
parent = element;
|
|
|
|
|
|
|
|
|
|
if (g_str_equal (parent->element_name, "packing"))
|
|
|
|
|
parent = parent->parent->parent; /* child - object */
|
|
|
|
|
|
|
|
|
|
if (g_str_equal (parent->element_name, "object"))
|
|
|
|
|
{
|
2019-03-27 17:14:39 +00:00
|
|
|
|
return get_attribute_value (parent, "class");
|
2019-02-07 12:12:15 +00:00
|
|
|
|
}
|
|
|
|
|
else if (g_str_equal (parent->element_name, "template"))
|
|
|
|
|
{
|
2019-03-27 17:14:39 +00:00
|
|
|
|
return get_attribute_value (parent, "parent");
|
2019-02-07 12:12:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 09:12:09 +00:00
|
|
|
|
static gboolean
|
2019-02-07 12:12:15 +00:00
|
|
|
|
property_is_boolean (Element *element,
|
|
|
|
|
MyParserData *data)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
GParamSpec *pspec;
|
2019-02-07 12:12:15 +00:00
|
|
|
|
gboolean packing = FALSE;
|
|
|
|
|
const char *class_name;
|
|
|
|
|
const char *property_name;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (g_str_equal (element->parent->element_name, "packing"))
|
|
|
|
|
packing = TRUE;
|
|
|
|
|
|
|
|
|
|
class_name = get_class_name (element);
|
|
|
|
|
property_name = "";
|
|
|
|
|
|
|
|
|
|
for (i = 0; element->attribute_names[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (element->attribute_names[i], "name") == 0)
|
|
|
|
|
property_name = (const gchar *)element->attribute_values[i];
|
|
|
|
|
}
|
2019-02-07 09:12:09 +00:00
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
pspec = get_property_pspec (data, class_name, property_name, packing, FALSE);
|
2019-02-07 09:12:09 +00:00
|
|
|
|
if (pspec)
|
|
|
|
|
return G_PARAM_SPEC_VALUE_TYPE (pspec) == G_TYPE_BOOLEAN;
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
property_can_be_omitted (Element *element,
|
|
|
|
|
MyParserData *data)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
gint i;
|
|
|
|
|
gboolean bound;
|
|
|
|
|
gboolean translatable;
|
2019-02-08 15:33:11 +00:00
|
|
|
|
const char *class_name;
|
|
|
|
|
const char *property_name;
|
|
|
|
|
const char *value_string;
|
2019-02-07 12:12:15 +00:00
|
|
|
|
gboolean packing = FALSE;
|
|
|
|
|
gboolean cell_packing = FALSE;
|
2019-02-08 15:33:11 +00:00
|
|
|
|
GParamSpec *pspec;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
if (g_str_equal (element->parent->element_name, "packing"))
|
|
|
|
|
packing = TRUE;
|
|
|
|
|
if (g_str_equal (element->parent->element_name, "cell-packing"))
|
|
|
|
|
cell_packing = TRUE;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
class_name = get_class_name (element);
|
|
|
|
|
property_name = "";
|
|
|
|
|
value_string = element->data;
|
|
|
|
|
|
|
|
|
|
bound = FALSE;
|
|
|
|
|
translatable = FALSE;
|
|
|
|
|
for (i = 0; element->attribute_names[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (element->attribute_names[i], "bind-source") == 0 ||
|
|
|
|
|
strcmp (element->attribute_names[i], "bind_source") == 0)
|
|
|
|
|
bound = TRUE;
|
|
|
|
|
else if (strcmp (element->attribute_names[i], "translatable") == 0)
|
|
|
|
|
translatable = TRUE;
|
|
|
|
|
else if (strcmp (element->attribute_names[i], "name") == 0)
|
|
|
|
|
property_name = (const gchar *)element->attribute_values[i];
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 22:38:29 +00:00
|
|
|
|
if (keep_for_rewrite (class_name, property_name, packing))
|
2019-03-27 17:14:39 +00:00
|
|
|
|
return FALSE; /* keep, will be rewritten */
|
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
if (translatable)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (bound)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2019-02-08 15:33:11 +00:00
|
|
|
|
pspec = get_property_pspec (data, class_name, property_name, packing, cell_packing);
|
|
|
|
|
|
|
|
|
|
if (pspec == NULL)
|
|
|
|
|
{
|
|
|
|
|
if (packing)
|
|
|
|
|
g_printerr (_("%s: Packing property %s::%s not found\n"), data->input_filename, class_name, property_name);
|
|
|
|
|
else if (cell_packing)
|
|
|
|
|
g_printerr (_("%s: Cell property %s::%s not found\n"), data->input_filename, class_name, property_name);
|
|
|
|
|
else
|
|
|
|
|
g_printerr (_("%s: Property %s::%s not found\n"), data->input_filename, class_name, property_name);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (needs_explicit_setting (pspec, packing))
|
2019-02-07 12:12:15 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
2019-02-08 15:33:11 +00:00
|
|
|
|
return value_is_default (data, pspec, value_string);
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2019-02-07 12:12:15 +00:00
|
|
|
|
property_has_been_removed (Element *element,
|
|
|
|
|
MyParserData *data)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
const gchar *class_name;
|
|
|
|
|
const gchar *property_name;
|
|
|
|
|
gboolean packing = FALSE;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
struct _Prop {
|
|
|
|
|
const char *class;
|
|
|
|
|
const char *property;
|
|
|
|
|
gboolean packing;
|
|
|
|
|
} props[] = {
|
2019-02-07 12:12:15 +00:00
|
|
|
|
{ "GtkActionBar", "position", 1 },
|
|
|
|
|
{ "GtkButtonBox", "secondary", 1 },
|
|
|
|
|
{ "GtkButtonBox", "non-homogeneous", 1 },
|
|
|
|
|
{ "GtkBox", "position", 1 },
|
2019-03-27 17:14:39 +00:00
|
|
|
|
{ "GtkBox", "pack-type", 1 },
|
2019-02-07 12:12:15 +00:00
|
|
|
|
{ "GtkHeaderBar", "position", 1 },
|
|
|
|
|
{ "GtkPopoverMenu", "position", 1 },
|
|
|
|
|
{ "GtkMenu", "left-attach", 1 },
|
|
|
|
|
{ "GtkMenu", "right-attach", 1 },
|
|
|
|
|
{ "GtkMenu", "top-attach", 1 },
|
|
|
|
|
{ "GtkMenu", "bottom-attach", 1 }
|
2019-02-07 09:12:09 +00:00
|
|
|
|
};
|
|
|
|
|
gchar *canonical_name;
|
|
|
|
|
gboolean found;
|
2019-02-07 12:12:15 +00:00
|
|
|
|
gint i, k;
|
|
|
|
|
|
|
|
|
|
if (g_str_equal (element->parent->element_name, "packing"))
|
|
|
|
|
packing = TRUE;
|
|
|
|
|
|
|
|
|
|
class_name = get_class_name (element);
|
|
|
|
|
property_name = "";
|
|
|
|
|
|
|
|
|
|
for (i = 0; element->attribute_names[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp (element->attribute_names[i], "name") == 0)
|
|
|
|
|
property_name = (const gchar *)element->attribute_values[i];
|
|
|
|
|
}
|
2019-02-07 09:12:09 +00:00
|
|
|
|
|
|
|
|
|
canonical_name = g_strdup (property_name);
|
|
|
|
|
g_strdelimit (canonical_name, "_", '-');
|
|
|
|
|
|
|
|
|
|
found = FALSE;
|
2019-02-07 12:12:15 +00:00
|
|
|
|
for (k = 0; k < G_N_ELEMENTS (props); k++)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
if (strcmp (class_name, props[k].class) == 0 &&
|
|
|
|
|
strcmp (canonical_name, props[k].property) == 0 &&
|
2019-02-07 12:12:15 +00:00
|
|
|
|
packing == props[k].packing)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
found = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (canonical_name);
|
|
|
|
|
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
static Element *
|
|
|
|
|
rewrite_stack_child (Element *child, MyParserData *data)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
Element *object = NULL;
|
|
|
|
|
Element *packing = NULL;
|
|
|
|
|
Element *new_object;
|
|
|
|
|
Element *prop;
|
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
|
|
if (!g_str_equal (child->element_name, "child"))
|
|
|
|
|
return child;
|
|
|
|
|
|
|
|
|
|
for (l = child->children; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
Element *elt = l->data;
|
|
|
|
|
if (g_str_equal (elt->element_name, "object"))
|
|
|
|
|
object = elt;
|
|
|
|
|
else if (g_str_equal (elt->element_name, "packing"))
|
|
|
|
|
packing = elt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!packing)
|
|
|
|
|
return child;
|
|
|
|
|
|
|
|
|
|
new_object = g_new0 (Element, 1);
|
|
|
|
|
new_object->element_name = g_strdup ("object");
|
|
|
|
|
new_object->attribute_names = g_new0 (char *, 2);
|
|
|
|
|
new_object->attribute_names[0] = g_strdup ("class");
|
|
|
|
|
new_object->attribute_values = g_new0 (char *, 2);
|
|
|
|
|
new_object->attribute_values[0] = g_strdup ("GtkStackPage");
|
|
|
|
|
new_object->children = packing->children;
|
|
|
|
|
packing->children = NULL;
|
|
|
|
|
|
|
|
|
|
prop = g_new0 (Element, 1);
|
|
|
|
|
prop->element_name = g_strdup ("property");
|
|
|
|
|
prop->attribute_names = g_new0 (char *, 2);
|
|
|
|
|
prop->attribute_names[0] = g_strdup ("name");
|
|
|
|
|
prop->attribute_values = g_new0 (char *, 2);
|
|
|
|
|
prop->attribute_values[0] = g_strdup ("child");
|
|
|
|
|
prop->children = g_list_append (prop->children, object);
|
|
|
|
|
new_object->children = g_list_append (new_object->children, prop);
|
|
|
|
|
|
|
|
|
|
g_list_free (child->children);
|
|
|
|
|
child->children = g_list_append (NULL, new_object);
|
|
|
|
|
|
|
|
|
|
return child;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-02-07 12:12:15 +00:00
|
|
|
|
rewrite_stack (Element *element,
|
|
|
|
|
MyParserData *data)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
GList *l, *new_children;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
new_children = NULL;
|
|
|
|
|
for (l = element->children; l; l = l->next)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
Element *child = l->data;
|
|
|
|
|
new_children = g_list_append (new_children, rewrite_stack_child (child, data));
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
2019-02-07 12:12:15 +00:00
|
|
|
|
|
|
|
|
|
g_list_free (element->children);
|
|
|
|
|
element->children = new_children;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 20:34:54 +00:00
|
|
|
|
static Element *
|
|
|
|
|
rewrite_assistant_child (Element *child, MyParserData *data)
|
|
|
|
|
{
|
|
|
|
|
Element *object = NULL;
|
|
|
|
|
Element *packing = NULL;
|
|
|
|
|
Element *new_object;
|
|
|
|
|
Element *prop;
|
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
|
|
if (!g_str_equal (child->element_name, "child"))
|
|
|
|
|
return child;
|
|
|
|
|
|
|
|
|
|
for (l = child->children; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
Element *elt = l->data;
|
|
|
|
|
if (g_str_equal (elt->element_name, "object"))
|
|
|
|
|
object = elt;
|
|
|
|
|
else if (g_str_equal (elt->element_name, "packing"))
|
|
|
|
|
packing = elt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!packing)
|
|
|
|
|
return child;
|
|
|
|
|
|
|
|
|
|
new_object = g_new0 (Element, 1);
|
|
|
|
|
new_object->element_name = g_strdup ("object");
|
|
|
|
|
new_object->attribute_names = g_new0 (char *, 2);
|
|
|
|
|
new_object->attribute_names[0] = g_strdup ("class");
|
|
|
|
|
new_object->attribute_values = g_new0 (char *, 2);
|
|
|
|
|
new_object->attribute_values[0] = g_strdup ("GtkAssistantPage");
|
|
|
|
|
new_object->children = packing->children;
|
|
|
|
|
packing->children = NULL;
|
|
|
|
|
|
|
|
|
|
prop = g_new0 (Element, 1);
|
|
|
|
|
prop->element_name = g_strdup ("property");
|
|
|
|
|
prop->attribute_names = g_new0 (char *, 2);
|
|
|
|
|
prop->attribute_names[0] = g_strdup ("name");
|
|
|
|
|
prop->attribute_values = g_new0 (char *, 2);
|
|
|
|
|
prop->attribute_values[0] = g_strdup ("child");
|
|
|
|
|
prop->children = g_list_append (prop->children, object);
|
|
|
|
|
new_object->children = g_list_append (new_object->children, prop);
|
|
|
|
|
|
|
|
|
|
g_list_free (child->children);
|
|
|
|
|
child->children = g_list_append (NULL, new_object);
|
|
|
|
|
|
|
|
|
|
return child;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
rewrite_assistant (Element *element,
|
|
|
|
|
MyParserData *data)
|
|
|
|
|
{
|
|
|
|
|
GList *l, *new_children;
|
|
|
|
|
|
|
|
|
|
new_children = NULL;
|
|
|
|
|
for (l = element->children; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
Element *child = l->data;
|
|
|
|
|
new_children = g_list_append (new_children, rewrite_assistant_child (child, data));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_list_free (element->children);
|
|
|
|
|
element->children = new_children;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 03:48:58 +00:00
|
|
|
|
static Element *
|
|
|
|
|
rewrite_notebook_page (Element *child, Element *tab, MyParserData *data)
|
|
|
|
|
{
|
|
|
|
|
Element *object = NULL;
|
|
|
|
|
Element *tab_obj = NULL;
|
|
|
|
|
Element *packing = NULL;
|
|
|
|
|
Element *new_object;
|
|
|
|
|
Element *prop;
|
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
|
|
if (!g_str_equal (child->element_name, "child"))
|
|
|
|
|
return child;
|
|
|
|
|
|
|
|
|
|
if (has_attribute (child, "type", "tab") ||
|
|
|
|
|
has_attribute (child, "type", "action-start") ||
|
|
|
|
|
has_attribute (child, "type", "action-end"))
|
|
|
|
|
return child;
|
|
|
|
|
|
|
|
|
|
for (l = child->children; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
Element *elt = l->data;
|
|
|
|
|
if (g_str_equal (elt->element_name, "object"))
|
|
|
|
|
object = elt;
|
|
|
|
|
else if (g_str_equal (elt->element_name, "packing"))
|
|
|
|
|
packing = elt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!packing && !tab)
|
|
|
|
|
return child;
|
|
|
|
|
|
|
|
|
|
if (tab)
|
|
|
|
|
{
|
|
|
|
|
for (l = tab->children; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
Element *elt = l->data;
|
|
|
|
|
if (g_str_equal (elt->element_name, "object"))
|
|
|
|
|
tab_obj = elt;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new_object = g_new0 (Element, 1);
|
|
|
|
|
new_object->element_name = g_strdup ("object");
|
|
|
|
|
new_object->attribute_names = g_new0 (char *, 2);
|
|
|
|
|
new_object->attribute_names[0] = g_strdup ("class");
|
|
|
|
|
new_object->attribute_values = g_new0 (char *, 2);
|
|
|
|
|
new_object->attribute_values[0] = g_strdup ("GtkNotebookPage");
|
|
|
|
|
if (packing)
|
|
|
|
|
{
|
|
|
|
|
new_object->children = packing->children;
|
|
|
|
|
packing->children = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
prop = g_new0 (Element, 1);
|
|
|
|
|
prop->element_name = g_strdup ("property");
|
|
|
|
|
prop->attribute_names = g_new0 (char *, 2);
|
|
|
|
|
prop->attribute_names[0] = g_strdup ("name");
|
|
|
|
|
prop->attribute_values = g_new0 (char *, 2);
|
|
|
|
|
prop->attribute_values[0] = g_strdup ("child");
|
|
|
|
|
prop->children = g_list_append (prop->children, object);
|
|
|
|
|
new_object->children = g_list_append (new_object->children, prop);
|
|
|
|
|
|
|
|
|
|
if (tab_obj)
|
|
|
|
|
{
|
|
|
|
|
prop = g_new0 (Element, 1);
|
|
|
|
|
prop->element_name = g_strdup ("property");
|
|
|
|
|
prop->attribute_names = g_new0 (char *, 2);
|
|
|
|
|
prop->attribute_names[0] = g_strdup ("name");
|
|
|
|
|
prop->attribute_values = g_new0 (char *, 2);
|
|
|
|
|
prop->attribute_values[0] = g_strdup ("tab");
|
|
|
|
|
prop->children = g_list_append (prop->children, tab_obj);
|
|
|
|
|
new_object->children = g_list_append (new_object->children, prop);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_list_free (child->children);
|
|
|
|
|
child->children = g_list_append (NULL, new_object);
|
|
|
|
|
|
|
|
|
|
return child;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
rewrite_notebook (Element *element,
|
|
|
|
|
MyParserData *data)
|
|
|
|
|
{
|
|
|
|
|
GList *l, *new_children;
|
|
|
|
|
|
|
|
|
|
new_children = NULL;
|
|
|
|
|
for (l = element->children; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
Element *child = l->data;
|
|
|
|
|
Element *tab = l->next ? l->next->data : NULL;
|
|
|
|
|
|
|
|
|
|
if (tab && has_attribute (tab, "type", "tab"))
|
|
|
|
|
{
|
|
|
|
|
new_children = g_list_append (new_children, rewrite_notebook_page (child, tab, data));
|
|
|
|
|
l = l->next; /* skip the tab */
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
new_children = g_list_append (new_children, rewrite_notebook_page (child, NULL, data));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_list_free (element->children);
|
|
|
|
|
element->children = new_children;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 17:14:39 +00:00
|
|
|
|
static void
|
|
|
|
|
rewrite_pack_type_child (Element *element,
|
|
|
|
|
MyParserData *data)
|
|
|
|
|
{
|
|
|
|
|
Element *pack_type = NULL;
|
|
|
|
|
GList *l, *ll;
|
|
|
|
|
|
|
|
|
|
if (!g_str_equal (element->element_name, "child"))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (l = element->children; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
Element *elt = l->data;
|
|
|
|
|
|
|
|
|
|
if (g_str_equal (elt->element_name, "packing"))
|
|
|
|
|
{
|
|
|
|
|
for (ll = elt->children; ll; ll = ll->next)
|
|
|
|
|
{
|
|
|
|
|
Element *elt2 = ll->data;
|
|
|
|
|
|
|
|
|
|
if (g_str_equal (elt2->element_name, "property") &&
|
|
|
|
|
has_attribute (elt2, "name", "pack-type"))
|
|
|
|
|
{
|
|
|
|
|
pack_type = elt2;
|
|
|
|
|
elt->children = g_list_remove (elt->children, pack_type);
|
2019-03-27 22:38:29 +00:00
|
|
|
|
if (elt->children == NULL)
|
|
|
|
|
{
|
|
|
|
|
element->children = g_list_remove (element->children, elt);
|
|
|
|
|
free_element (elt);
|
|
|
|
|
}
|
2019-03-27 17:14:39 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-27 22:38:29 +00:00
|
|
|
|
|
|
|
|
|
if (pack_type)
|
|
|
|
|
break;
|
2019-03-27 17:14:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pack_type)
|
|
|
|
|
{
|
|
|
|
|
char **attnames = g_new0 (char *, g_strv_length (element->attribute_names) + 2);
|
|
|
|
|
char **attvalues = g_new0 (char *, g_strv_length (element->attribute_names) + 2);
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; element->attribute_names[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
attnames[i] = g_strdup (element->attribute_names[i]);
|
|
|
|
|
attvalues[i] = g_strdup (element->attribute_values[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attnames[i] = g_strdup ("type");
|
|
|
|
|
attvalues[i] = g_strdup (pack_type->data);
|
|
|
|
|
|
|
|
|
|
g_strfreev (element->attribute_names);
|
|
|
|
|
g_strfreev (element->attribute_values);
|
|
|
|
|
|
|
|
|
|
element->attribute_names = attnames;
|
|
|
|
|
element->attribute_values = attvalues;
|
|
|
|
|
|
|
|
|
|
free_element (pack_type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
rewrite_pack_type (Element *element,
|
|
|
|
|
MyParserData *data)
|
|
|
|
|
{
|
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
|
|
for (l = element->children; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
Element *elt = l->data;
|
|
|
|
|
if (g_str_equal (elt->element_name, "child"))
|
|
|
|
|
rewrite_pack_type_child (elt, data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 22:38:29 +00:00
|
|
|
|
static void
|
2019-03-28 00:03:34 +00:00
|
|
|
|
rewrite_child_prop_to_prop_child (Element *element,
|
|
|
|
|
MyParserData *data,
|
|
|
|
|
const char *child_prop,
|
|
|
|
|
const char *prop)
|
2019-03-27 22:38:29 +00:00
|
|
|
|
{
|
|
|
|
|
Element *object = NULL;
|
2019-03-28 00:03:34 +00:00
|
|
|
|
Element *replaced = NULL;
|
2019-03-27 22:38:29 +00:00
|
|
|
|
GList *l, *ll;
|
|
|
|
|
|
|
|
|
|
if (!g_str_equal (element->element_name, "child"))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (l = element->children; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
Element *elt = l->data;
|
|
|
|
|
|
|
|
|
|
if (g_str_equal (elt->element_name, "object"))
|
|
|
|
|
object = elt;
|
|
|
|
|
|
|
|
|
|
if (g_str_equal (elt->element_name, "packing"))
|
|
|
|
|
{
|
|
|
|
|
for (ll = elt->children; ll; ll = ll->next)
|
|
|
|
|
{
|
|
|
|
|
Element *elt2 = ll->data;
|
|
|
|
|
|
|
|
|
|
if (g_str_equal (elt2->element_name, "property") &&
|
2019-03-28 00:03:34 +00:00
|
|
|
|
has_attribute (elt2, "name", child_prop))
|
2019-03-27 22:38:29 +00:00
|
|
|
|
{
|
2019-03-28 00:03:34 +00:00
|
|
|
|
replaced = elt2;
|
|
|
|
|
elt->children = g_list_remove (elt->children, replaced);
|
2019-03-27 22:38:29 +00:00
|
|
|
|
if (elt->children == NULL)
|
|
|
|
|
{
|
|
|
|
|
element->children = g_list_remove (element->children, elt);
|
|
|
|
|
free_element (elt);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-28 00:03:34 +00:00
|
|
|
|
if (replaced)
|
2019-03-27 22:38:29 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-28 00:03:34 +00:00
|
|
|
|
if (replaced)
|
2019-03-27 22:38:29 +00:00
|
|
|
|
{
|
|
|
|
|
Element *elt;
|
|
|
|
|
|
|
|
|
|
elt = g_new0 (Element, 1);
|
|
|
|
|
elt->parent = element;
|
|
|
|
|
elt->element_name = g_strdup ("property");
|
|
|
|
|
elt->attribute_names = g_new0 (char *, 2);
|
|
|
|
|
elt->attribute_names[0] = g_strdup ("name");
|
|
|
|
|
elt->attribute_values = g_new0 (char *, 2);
|
2019-03-28 00:03:34 +00:00
|
|
|
|
elt->attribute_values[0] = g_strdup (prop);
|
|
|
|
|
elt->data = g_strdup (replaced->data);
|
2019-03-27 22:38:29 +00:00
|
|
|
|
|
|
|
|
|
object->children = g_list_prepend (object->children, elt);
|
|
|
|
|
|
2019-03-28 00:03:34 +00:00
|
|
|
|
free_element (replaced);
|
2019-03-27 22:38:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
static void
|
2019-03-28 00:03:34 +00:00
|
|
|
|
rewrite_child_prop_to_prop (Element *element,
|
|
|
|
|
MyParserData *data,
|
|
|
|
|
const char *child_prop,
|
|
|
|
|
const char *prop)
|
2019-03-27 22:38:29 +00:00
|
|
|
|
{
|
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
|
|
for (l = element->children; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
Element *elt = l->data;
|
|
|
|
|
if (g_str_equal (elt->element_name, "child"))
|
2019-03-28 00:03:34 +00:00
|
|
|
|
rewrite_child_prop_to_prop_child (elt, data, child_prop, prop);
|
2019-03-27 22:38:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
simplify_element (Element *element,
|
|
|
|
|
MyParserData *data)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
GList *l;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
if (!is_pcdata_element (element))
|
|
|
|
|
g_clear_pointer (&element->data, g_free);
|
|
|
|
|
else if (g_str_equal (element->element_name, "property") &&
|
|
|
|
|
property_is_boolean (element, data))
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
const char *b = canonical_boolean_value (data, element->data);
|
|
|
|
|
g_free (element->data);
|
|
|
|
|
element->data = g_strdup (b);
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
l = element->children;
|
|
|
|
|
while (l)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
GList *next = l->next;
|
|
|
|
|
Element *child = l->data;
|
|
|
|
|
if (simplify_element (child, data))
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
element->children = g_list_remove (element->children, child);
|
|
|
|
|
free_element (child);
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
2019-02-07 12:12:15 +00:00
|
|
|
|
l = next;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
if (is_container_element (element) && element->children == NULL)
|
|
|
|
|
return TRUE;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
if (g_str_equal (element->element_name, "property") &&
|
|
|
|
|
property_can_be_omitted (element, data))
|
|
|
|
|
return TRUE;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
if (data->convert3to4)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
if (g_str_equal (element->element_name, "object") &&
|
|
|
|
|
g_str_equal (get_class_name (element), "GtkStack"))
|
|
|
|
|
rewrite_stack (element, data);
|
2019-02-07 20:34:54 +00:00
|
|
|
|
|
|
|
|
|
if (g_str_equal (element->element_name, "object") &&
|
|
|
|
|
g_str_equal (get_class_name (element), "GtkAssistant"))
|
|
|
|
|
rewrite_assistant (element, data);
|
2019-02-07 12:12:15 +00:00
|
|
|
|
|
2019-02-21 03:48:58 +00:00
|
|
|
|
if (g_str_equal (element->element_name, "object") &&
|
|
|
|
|
g_str_equal (get_class_name (element), "GtkNotebook"))
|
|
|
|
|
rewrite_notebook (element, data);
|
|
|
|
|
|
2019-03-27 17:14:39 +00:00
|
|
|
|
if (g_str_equal (element->element_name, "object") &&
|
|
|
|
|
(g_str_equal (get_class_name (element), "GtkActionBar") ||
|
|
|
|
|
g_str_equal (get_class_name (element), "GtkHeaderBar")))
|
|
|
|
|
rewrite_pack_type (element, data);
|
|
|
|
|
|
2019-03-27 22:38:29 +00:00
|
|
|
|
if (g_str_equal (element->element_name, "object") &&
|
|
|
|
|
g_str_equal (get_class_name (element), "GtkPopoverMenu"))
|
2019-03-28 00:03:34 +00:00
|
|
|
|
rewrite_child_prop_to_prop (element, data, "submenu", "name");
|
|
|
|
|
|
|
|
|
|
if (g_str_equal (element->element_name, "object") &&
|
|
|
|
|
g_str_equal (get_class_name (element), "GtkToolbar"))
|
|
|
|
|
rewrite_child_prop_to_prop (element, data, "expand", "expand-item");
|
|
|
|
|
|
|
|
|
|
if (g_str_equal (element->element_name, "object") &&
|
|
|
|
|
g_str_equal (get_class_name (element), "GtkToolbar"))
|
|
|
|
|
rewrite_child_prop_to_prop (element, data, "homogeneous", "homogeneous");
|
2019-03-27 22:38:29 +00:00
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
if (g_str_equal (element->element_name, "property") &&
|
|
|
|
|
property_has_been_removed (element, data))
|
|
|
|
|
return TRUE;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
2019-02-07 12:12:15 +00:00
|
|
|
|
|
|
|
|
|
return FALSE;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-02-07 12:12:15 +00:00
|
|
|
|
simplify_tree (MyParserData *data)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
simplify_element (data->root, data);
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
static void
|
|
|
|
|
dump_element (Element *element,
|
|
|
|
|
FILE *output,
|
|
|
|
|
int indent)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
g_fprintf (output, "%*s<%s", indent, "", element->element_name);
|
|
|
|
|
if (element->attribute_names[0])
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; element->attribute_names[i]; i++)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
char *escaped = g_markup_escape_text (element->attribute_values[i], -1);
|
|
|
|
|
g_fprintf (output, " %s=\"%s\"", element->attribute_names[i], escaped);
|
|
|
|
|
g_free (escaped);
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-02-07 12:12:15 +00:00
|
|
|
|
if (element->children || element->data)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
g_fprintf (output, ">");
|
2019-02-07 09:12:09 +00:00
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
if (element->children)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
|
|
g_fprintf (output, "\n");
|
|
|
|
|
for (l = element->children; l; l = l->next)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
Element *child = l->data;
|
|
|
|
|
dump_element (child, output, indent + 2);
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
2019-02-07 12:12:15 +00:00
|
|
|
|
g_fprintf (output, "%*s", indent, "");
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2019-02-07 12:12:15 +00:00
|
|
|
|
{
|
|
|
|
|
char *escaped = g_markup_escape_text (element->data, -1);
|
|
|
|
|
g_fprintf (output, "%s", escaped);
|
|
|
|
|
g_free (escaped);
|
|
|
|
|
}
|
|
|
|
|
g_fprintf (output, "</%s>\n", element->element_name);
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
2019-02-07 12:12:15 +00:00
|
|
|
|
else
|
|
|
|
|
g_fprintf (output, "/>\n");
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-02-07 12:12:15 +00:00
|
|
|
|
dump_tree (MyParserData *data)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-07 12:12:15 +00:00
|
|
|
|
dump_element (data->root, data->output, 0);
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 17:24:49 +00:00
|
|
|
|
gboolean
|
|
|
|
|
simplify_file (const char *filename,
|
|
|
|
|
gboolean replace,
|
|
|
|
|
gboolean convert3to4)
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
|
|
|
|
GMarkupParseContext *context;
|
|
|
|
|
gchar *buffer;
|
|
|
|
|
MyParserData data;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
2019-02-07 17:24:49 +00:00
|
|
|
|
data.input_filename = filename;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
data.output_filename = NULL;
|
2019-02-07 17:24:49 +00:00
|
|
|
|
data.convert3to4 = convert3to4;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
|
|
|
|
|
if (replace)
|
|
|
|
|
{
|
|
|
|
|
int fd;
|
|
|
|
|
fd = g_file_open_tmp ("gtk-builder-tool-XXXXXX", &data.output_filename, NULL);
|
|
|
|
|
data.output = fdopen (fd, "w");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
data.output = stdout;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 17:24:49 +00:00
|
|
|
|
if (!g_file_get_contents (filename, &buffer, NULL, &error))
|
2019-02-07 09:12:09 +00:00
|
|
|
|
{
|
2019-02-08 18:24:53 +00:00
|
|
|
|
g_printerr (_("Can’t load “%s”: %s\n"), filename, error->message);
|
2019-02-07 17:24:49 +00:00
|
|
|
|
return FALSE;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
data.root = NULL;
|
|
|
|
|
data.current = NULL;
|
|
|
|
|
data.value = g_string_new ("");
|
2019-02-07 09:12:09 +00:00
|
|
|
|
|
|
|
|
|
context = g_markup_parse_context_new (&parser, G_MARKUP_TREAT_CDATA_AS_TEXT, &data, NULL);
|
|
|
|
|
if (!g_markup_parse_context_parse (context, buffer, -1, &error))
|
|
|
|
|
{
|
2019-02-08 18:24:53 +00:00
|
|
|
|
g_printerr (_("Can’t parse “%s”: %s\n"), filename, error->message);
|
2019-02-07 17:24:49 +00:00
|
|
|
|
return FALSE;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-07 12:12:15 +00:00
|
|
|
|
data.builder = gtk_builder_new ();
|
|
|
|
|
|
|
|
|
|
simplify_tree (&data);
|
|
|
|
|
|
|
|
|
|
dump_tree (&data);
|
|
|
|
|
|
2019-02-07 09:12:09 +00:00
|
|
|
|
fclose (data.output);
|
|
|
|
|
|
|
|
|
|
if (data.output_filename)
|
|
|
|
|
{
|
|
|
|
|
char *content;
|
|
|
|
|
gsize length;
|
|
|
|
|
|
|
|
|
|
if (!g_file_get_contents (data.output_filename, &content, &length, &error))
|
|
|
|
|
{
|
2019-02-08 18:24:53 +00:00
|
|
|
|
g_printerr (_("Failed to read “%s”: %s\n"), data.output_filename, error->message);
|
2019-02-07 17:24:49 +00:00
|
|
|
|
return FALSE;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!g_file_set_contents (data.input_filename, content, length, &error))
|
|
|
|
|
{
|
2019-02-08 18:24:53 +00:00
|
|
|
|
g_printerr (_("Failed to write %s: “%s”\n"), data.input_filename, error->message);
|
2019-02-07 17:24:49 +00:00
|
|
|
|
return FALSE;
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-02-07 17:24:49 +00:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
do_simplify (int *argc,
|
|
|
|
|
const char ***argv)
|
|
|
|
|
{
|
|
|
|
|
gboolean replace = FALSE;
|
|
|
|
|
gboolean convert3to4 = FALSE;
|
|
|
|
|
char **filenames = NULL;
|
|
|
|
|
GOptionContext *ctx;
|
|
|
|
|
const GOptionEntry entries[] = {
|
|
|
|
|
{ "replace", 0, 0, G_OPTION_ARG_NONE, &replace, NULL, NULL },
|
|
|
|
|
{ "3to4", 0, 0, G_OPTION_ARG_NONE, &convert3to4, NULL, NULL },
|
|
|
|
|
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL, NULL },
|
|
|
|
|
{ NULL, }
|
|
|
|
|
};
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
ctx = g_option_context_new (NULL);
|
|
|
|
|
g_option_context_set_help_enabled (ctx, FALSE);
|
|
|
|
|
g_option_context_add_main_entries (ctx, entries, NULL);
|
|
|
|
|
|
|
|
|
|
if (!g_option_context_parse (ctx, argc, (char ***)argv, &error))
|
|
|
|
|
{
|
|
|
|
|
g_printerr ("%s\n", error->message);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_option_context_free (ctx);
|
|
|
|
|
|
|
|
|
|
if (filenames == NULL)
|
|
|
|
|
{
|
|
|
|
|
g_printerr (_("No .ui file specified\n"));
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (g_strv_length (filenames) > 1 && !replace)
|
|
|
|
|
{
|
|
|
|
|
g_printerr (_("Can only simplify a single .ui file without --replace\n"));
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; filenames[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
if (!simplify_file (filenames[i], replace, convert3to4))
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
2019-02-07 09:12:09 +00:00
|
|
|
|
}
|