static void gsf_open_pkg_write_content_override (GsfOutfileOpenPkg const *open_pkg, char const *base, GsfXMLOut *xml) { GsfOutfileOpenPkg const *child; char *path; GSList *ptr; for (ptr = open_pkg->children ; ptr != NULL ; ptr = ptr->next) { child = ptr->data; if (child->is_dir) { path = g_strconcat (base, gsf_output_name (GSF_OUTPUT (child)), "/", NULL); gsf_open_pkg_write_content_override (child, path, xml); } else { path = g_strconcat (base, gsf_output_name (GSF_OUTPUT (child)), NULL); /* rels files do need content types, the defaults handle them */ if (NULL != child->content_type) { gsf_xml_out_start_element (xml, "Override"); gsf_xml_out_add_cstr (xml, "PartName", path); gsf_xml_out_add_cstr (xml, "ContentType", child->content_type); gsf_xml_out_end_element (xml); /* </Override> */ } } g_free (path); } }
static void gsf_output_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { GsfOutput *output = GSF_OUTPUT (object); /* gsf_off_t is typedef'd to gint64 */ switch (property_id) { case PROP_NAME: g_value_set_string (value, gsf_output_name (output)); break; case PROP_SIZE: g_value_set_int64 (value, gsf_output_size (output)); break; case PROP_CLOSED: g_value_set_boolean (value, gsf_output_is_closed (output)); break; case PROP_POS: g_value_set_int64 (value, gsf_output_tell (output)); break; case PROP_MODTIME: g_value_set_boxed (value, gsf_output_get_modtime (output)); break; case PROP_CONTAINER: g_value_set_object (value, output->container); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
static void gsf_output_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { /* gsf_off_t is typedef'd to gint64 */ switch (property_id) { case PROP_NAME: g_value_set_string (value, gsf_output_name (GSF_OUTPUT (object))); break; case PROP_SIZE: g_value_set_int64 (value, gsf_output_size (GSF_OUTPUT (object))); break; case PROP_POS: g_value_set_int64 (value, gsf_output_tell (GSF_OUTPUT (object))); break; case PROP_CLOSED: g_value_set_boolean (value, gsf_output_is_closed (GSF_OUTPUT (object))); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }
/** * gsf_outfile_open_pkg_relate: * @child: #GsfOutfileOpenPkg * @parent: #GsfOutfileOpenPkg * @type: target type * * Create a relationship between @child and @parent of @type. * * Returns: (transfer none): the relID which the caller does not own * but will live as long as @parent. **/ char const * gsf_outfile_open_pkg_relate (GsfOutfileOpenPkg *child, GsfOutfileOpenPkg *parent, char const *type) { GString *path; int up = -1; GsfOutfile *child_dir, *parent_dir; /* Calculate the path from @child to @parent */ parent_dir = parent->is_dir ? GSF_OUTFILE (parent) : gsf_output_container (GSF_OUTPUT (parent)); do { up++; child_dir = GSF_OUTFILE (child); while (NULL != (child_dir = gsf_output_container (GSF_OUTPUT (child_dir)))) if (child_dir == parent_dir) goto found; /* break out of both loops */ } while (NULL != (parent_dir = gsf_output_container (GSF_OUTPUT (parent_dir)))); found: /* yes prepend is slow, this will never be preformance critical */ path = g_string_new (gsf_output_name (GSF_OUTPUT (child))); child_dir = GSF_OUTFILE (child); while (NULL != (child_dir = gsf_output_container (GSF_OUTPUT (child_dir))) && NULL != gsf_output_name (GSF_OUTPUT (child_dir)) && child_dir != parent_dir) { g_string_prepend_c (path, '/'); g_string_prepend (path, gsf_output_name (GSF_OUTPUT (child_dir))); } while (up--) g_string_prepend (path, "../"); return gsf_outfile_open_pkg_create_rel (parent, g_string_free (path, FALSE), type, FALSE); }
static GObject * gsf_outfile_zip_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_params) { GsfOutfileZip *zip =(GsfOutfileZip *) (parent_class->constructor (type, n_construct_properties, construct_params)); if (!zip->entry_name) { zip->vdir = gsf_vdir_new ("", TRUE, NULL); zip->root_order = g_ptr_array_new (); zip->root = zip; /* The names are the same */ gsf_output_set_name (GSF_OUTPUT (zip), gsf_output_name (zip->sink)); gsf_output_set_container (GSF_OUTPUT (zip), NULL); } return (GObject *)zip; }
static gboolean gsf_outfile_open_pkg_close (GsfOutput *output) { GsfOutfileOpenPkg *open_pkg = GSF_OUTFILE_OPEN_PKG (output); GsfOutput *dir; gboolean res = FALSE; char *rels_name; if (NULL == open_pkg->sink || gsf_output_is_closed (open_pkg->sink)) return TRUE; /* Generate [Content_types].xml when we close the root dir */ if (NULL == gsf_output_name (output)) { GsfOutput *out = gsf_outfile_new_child (GSF_OUTFILE (open_pkg->sink), "[Content_Types].xml", FALSE); GsfXMLOut *xml = gsf_xml_out_new (out); gsf_xml_out_start_element (xml, "Types"); gsf_xml_out_add_cstr_unchecked (xml, "xmlns", "http://schemas.openxmlformats.org/package/2006/content-types"); gsf_open_pkg_write_content_default (xml, "rels", "application/vnd.openxmlformats-package.relationships+xml"); gsf_open_pkg_write_content_default (xml, "xlbin", "application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings"); gsf_open_pkg_write_content_default (xml, "xml", "application/xml"); gsf_open_pkg_write_content_override (open_pkg, "/", xml); gsf_xml_out_end_element (xml); /* </Types> */ g_object_unref (xml); gsf_output_close (out); g_object_unref (out); dir = open_pkg->sink; rels_name = g_strdup (".rels"); } else { res = gsf_output_close (open_pkg->sink); dir = (GsfOutput *)gsf_output_container (open_pkg->sink); rels_name = g_strconcat (gsf_output_name (output), ".rels", NULL); } if (NULL != open_pkg->relations) { GsfOutput *rels; GsfXMLOut *xml; GsfOpenPkgRel *rel; GSList *ptr; dir = gsf_outfile_new_child (GSF_OUTFILE (dir), "_rels", TRUE); rels = gsf_outfile_new_child (GSF_OUTFILE (dir), rels_name, FALSE); xml = gsf_xml_out_new (rels); gsf_xml_out_start_element (xml, "Relationships"); gsf_xml_out_add_cstr_unchecked (xml, "xmlns", "http://schemas.openxmlformats.org/package/2006/relationships"); for (ptr = open_pkg->relations ; ptr != NULL ; ptr = ptr->next) { rel = ptr->data; gsf_xml_out_start_element (xml, "Relationship"); gsf_xml_out_add_cstr (xml, "Id", rel->id); gsf_xml_out_add_cstr (xml, "Type", rel->type); gsf_xml_out_add_cstr (xml, "Target", rel->target); if (rel->is_extern) gsf_xml_out_add_cstr_unchecked (xml, "TargetMode", "External"); gsf_xml_out_end_element (xml); /* </Relationship> */ g_free (rel->id); g_free (rel->type); g_free (rel->target); g_free (rel); } g_slist_free (open_pkg->relations); gsf_xml_out_end_element (xml); /* </Relationships> */ g_object_unref (xml); gsf_output_close (rels); g_object_unref (rels); g_object_unref (dir); } g_free (rels_name); /* close the container */ if (NULL == gsf_output_name (output)) return gsf_output_close (open_pkg->sink); return res; }