コード例 #1
1
ファイル: gog-object-xml.c プロジェクト: GNOME/goffice
static void
gog_object_write_property_sax (GogObject const *obj, GParamSpec *pspec, GsfXMLOut *output)
{
	GObject *val_obj;
	GType    prop_type = G_PARAM_SPEC_VALUE_TYPE (pspec);
	GValue	 value = { 0 };

	g_value_init (&value, prop_type);
	g_object_get_property (G_OBJECT (obj), pspec->name, &value);

	/* No need to save default values */
	if (((pspec->flags & GOG_PARAM_POSITION) &&
	     gog_object_is_default_position_flags (obj, pspec->name)) ||
	    (!(pspec->flags & GOG_PARAM_FORCE_SAVE) &&
	     !(pspec->flags & GOG_PARAM_POSITION) &&
	     g_param_value_defaults (pspec, &value))) {
		g_value_unset (&value);
		return;
	}

	switch (G_TYPE_FUNDAMENTAL (prop_type)) {
	case G_TYPE_CHAR:
	case G_TYPE_UCHAR:
	case G_TYPE_BOOLEAN:
	case G_TYPE_INT:
	case G_TYPE_UINT:
	case G_TYPE_LONG:
	case G_TYPE_ULONG:
	case G_TYPE_ENUM:
	case G_TYPE_FLAGS: {
		GValue str = { 0 };
		g_value_init (&str, G_TYPE_STRING);
		g_value_transform (&value, &str);
		gsf_xml_out_start_element (output, "property");
		gsf_xml_out_add_cstr_unchecked (output, "name", pspec->name);
		gsf_xml_out_add_cstr (output, NULL, g_value_get_string (&str));
		gsf_xml_out_end_element (output); /* </property> */
		g_value_unset (&str);
		break;
	}

	case G_TYPE_FLOAT:
	case G_TYPE_DOUBLE: {
		GValue vd = { 0 };
		GString *str = g_string_new (NULL);

		g_value_init (&vd, G_TYPE_DOUBLE);
		g_value_transform (&value, &vd);
		go_dtoa (str, "!g", g_value_get_double (&vd));
		g_value_unset (&vd);

		gsf_xml_out_start_element (output, "property");
		gsf_xml_out_add_cstr_unchecked (output, "name", pspec->name);
		gsf_xml_out_add_cstr (output, NULL, str->str);
		gsf_xml_out_end_element (output); /* </property> */
		g_string_free (str, TRUE);
		break;
	}

	case G_TYPE_STRING: {
		char const *str = g_value_get_string (&value);
		if (str != NULL) {
			gsf_xml_out_start_element (output, "property");
			gsf_xml_out_add_cstr_unchecked (output, "name", pspec->name);
			gsf_xml_out_add_cstr (output, NULL, str);
			gsf_xml_out_end_element (output); /* </property> */
		}
		break;
	}

	case G_TYPE_OBJECT:
		val_obj = g_value_get_object (&value);
		if (val_obj != NULL) {
			if (GO_IS_PERSIST (val_obj)) {
				gsf_xml_out_start_element (output, "property");
				gsf_xml_out_add_cstr_unchecked (output, "name", pspec->name);
				go_persist_sax_save (GO_PERSIST (val_obj), output);
				gsf_xml_out_end_element (output); /* </property> */
			} else
				g_warning ("How are we supposed to persist this ??");
		}
		break;

	default:
		g_warning ("I could not persist property \"%s\", since type \"%s\" is unhandled.",
			   g_param_spec_get_name (pspec), g_type_name (G_TYPE_FUNDAMENTAL(prop_type)));
	}
	g_value_unset (&value);
}
コード例 #2
0
ファイル: gnm-so-path.c プロジェクト: nzinfo/gnumeric
static void
gnm_so_path_write_xml_sax (SheetObject const *so, GsfXMLOut *output,
			   G_GNUC_UNUSED GnmConventions const *convs)
{
	GnmSOPath const *sop = GNM_SO_PATH (so);
	char *svg;

	if (sop->text != NULL && *(sop->text) != '\0') {
		gsf_xml_out_add_cstr (output, "Label", sop->text);
		if (sop->markup != NULL) {
			GOFormat *fmt = go_format_new_markup	(sop->markup, TRUE);
			gsf_xml_out_add_cstr (output, "LabelFormat",
					      go_format_as_XL (fmt));
			go_format_unref (fmt);
		}
	}
	if (sop->path) {
		svg = go_path_to_svg (sop->path);
		gsf_xml_out_add_cstr (output, "Path", svg);
		g_free (svg);
	} else if (sop->paths) {
		unsigned i;
		for (i = 0; i < sop->paths->len; i++) {
			gsf_xml_out_start_element (output, "Path");
			svg = go_path_to_svg ((GOPath *) g_ptr_array_index (sop->paths, i));
			gsf_xml_out_add_cstr (output, "Path", svg);
			g_free (svg);
			gsf_xml_out_end_element (output); /* </Path> */
		}
	}

	gsf_xml_out_start_element (output, "Style");
	go_persist_sax_save (GO_PERSIST (sop->style), output);
	gsf_xml_out_end_element (output); /* </Style> */
}
コード例 #3
0
ファイル: gog-object-xml.c プロジェクト: GNOME/goffice
void
gog_object_write_xml_sax (GogObject const *obj, GsfXMLOut *output, gpointer user)
{
	guint	     n;
	GParamSpec **props;
	GSList	    *ptr;

	g_return_if_fail (GOG_IS_OBJECT (obj));

	gsf_xml_out_start_element (output, "GogObject");

	/* Primary details */
	if (obj->role != NULL) {
		if (strcmp (obj->role->id, GOG_BACKPLANE_NEW_ROLE_NAME) == 0)
			gsf_xml_out_add_cstr (output, "role", GOG_BACKPLANE_OLD_ROLE_NAME);
		else
			gsf_xml_out_add_cstr (output, "role", obj->role->id);
	}
	if (obj->explicitly_typed_role || obj->role == NULL)
		gsf_xml_out_add_cstr (output, "type", G_OBJECT_TYPE_NAME (obj));

	/* properties */
	props = g_object_class_list_properties (G_OBJECT_GET_CLASS (obj), &n);
	while (n-- > 0)
		if (props[n]->flags & GO_PARAM_PERSISTENT)
			gog_object_write_property_sax (obj, props[n], output);

	g_free (props);

	if (GO_IS_PERSIST (obj))	/* anything special for this class */
		go_persist_sax_save (GO_PERSIST (obj), output);
	if (GOG_IS_DATASET (obj))	/* convenience to save data */
		gog_dataset_sax_save (GOG_DATASET (obj), output, user);

	/* the children */
	for (ptr = obj->children; ptr != NULL ; ptr = ptr->next)
		gog_object_write_xml_sax (ptr->data, output, user);

	gsf_xml_out_end_element (output); /* </GogObject> */
}