gnumeric r17191 - in trunk: . plugins/openoffice
- From: mortenw svn gnome org
- To: svn-commits-list gnome org
- Subject: gnumeric r17191 - in trunk: . plugins/openoffice
- Date: Thu, 12 Mar 2009 20:18:53 +0000 (UTC)
Author: mortenw
Date: Thu Mar 12 20:18:53 2009
New Revision: 17191
URL: http://svn.gnome.org/viewvc/gnumeric?rev=17191&view=rev
Log:
2009-03-12 Morten Welinder <terra gnome org>
* openoffice-read.c (determine_oo_version): New function factored
out from openoffice_file_open.
(openoffice_file_probe): New function.
Modified:
trunk/NEWS
trunk/plugins/openoffice/ChangeLog
trunk/plugins/openoffice/openoffice-read.c
trunk/plugins/openoffice/plugin.xml.in
Modified: trunk/NEWS
==============================================================================
--- trunk/NEWS (original)
+++ trunk/NEWS Thu Mar 12 20:18:53 2009
@@ -23,6 +23,9 @@
* Fix potential crash for cell comment dialog with multiple views.
[Part of #364291]
+Sum1:
+ * Implement OOO probing. [#574381]
+
--------------------------------------------------------------------------
Gnumeric 1.9.4
Modified: trunk/plugins/openoffice/openoffice-read.c
==============================================================================
--- trunk/plugins/openoffice/openoffice-read.c (original)
+++ trunk/plugins/openoffice/openoffice-read.c Thu Mar 12 20:18:53 2009
@@ -2853,6 +2853,37 @@
return conv;
}
+static OOVer
+determine_oo_version (GsfInfile *zip, OOVer def)
+{
+ char const *header;
+ size_t size;
+ GsfInput *mimetype = gsf_infile_child_by_name (zip, "mimetype");
+ if (!mimetype) {
+ /* Really old versions had no mimetype. Allow that, except
+ in the probe. */
+ return def;
+ }
+
+ /* pick arbitrary size limit of 2k for the mimetype to avoid
+ * potential of any funny business */
+ size = MIN (gsf_input_size (mimetype), 2048);
+ header = gsf_input_read (mimetype, size, NULL);
+ g_object_unref (mimetype);
+
+ if (header) {
+ unsigned ui;
+
+ for (ui = 0 ; ui < G_N_ELEMENTS (OOVersions) ; ui++)
+ if (size == strlen (OOVersions[ui].mime_type) &&
+ !memcmp (OOVersions[ui].mime_type, header, size))
+ return OOVersions[ui].version;
+ }
+
+ return OOO_VER_UNKNOWN;
+}
+
+
void
openoffice_file_open (GOFileOpener const *fo, IOContext *io_context,
WorkbookView *wb_view, GsfInput *input);
@@ -2863,7 +2894,6 @@
GsfXMLInDoc *doc;
GsfInput *content = NULL;
GsfInput *styles = NULL;
- GsfInput *mimetype = NULL;
GsfDocMetaData *meta_data;
GsfInfile *zip;
GnmLocale *locale;
@@ -2880,34 +2910,14 @@
return;
}
- mimetype = gsf_infile_child_by_name (zip, "mimetype");
- if (mimetype != NULL) {
- /* pick arbitrary size limit of 2k for the mimetype to avoid
- * potential of any funny business */
- gsf_off_t size = MIN (gsf_input_size (mimetype), 2048);
- char const *header = gsf_input_read (mimetype, size, NULL);
- unsigned i;
-
- state.ver = OOO_VER_UNKNOWN;
- if (header)
- for (i = 0 ; i < G_N_ELEMENTS (OOVersions) ; i++)
- if (!strncmp (OOVersions[i].mime_type, header, size)) {
- state.ver = OOVersions[i].version;
- break;
- }
- if (state.ver == OOO_VER_UNKNOWN) {
- /* TODO : include the unknown type in the message when
- * we move the error handling into the importer object */
- go_cmd_context_error_import (GO_CMD_CONTEXT (io_context),
- _("Unknown mimetype for openoffice file."));
- g_object_unref (mimetype);
- g_object_unref (zip);
- return;
- }
- g_object_unref (mimetype);
- } else {
- /* OO.o v1.x files did not include mimetype */
- state.ver = OOO_VER_1;
+ state.ver = determine_oo_version (zip, OOO_VER_1);
+ if (state.ver == OOO_VER_UNKNOWN) {
+ /* TODO : include the unknown type in the message when
+ * we move the error handling into the importer object */
+ go_cmd_context_error_import (GO_CMD_CONTEXT (io_context),
+ _("Unknown mimetype for openoffice file."));
+ g_object_unref (zip);
+ return;
}
content = gsf_infile_child_by_name (zip, "content.xml");
@@ -3032,3 +3042,22 @@
gnm_pop_C_locale (locale);
}
+gboolean
+openoffice_file_probe (GOFileOpener const *fo, GsfInput *input, FileProbeLevel pl);
+
+gboolean
+openoffice_file_probe (GOFileOpener const *fo, GsfInput *input, FileProbeLevel pl)
+{
+ GsfInfile *zip;
+ OOVer ver;
+
+ zip = gsf_infile_zip_new (input, NULL);
+ if (zip == NULL)
+ return FALSE;
+
+ ver = determine_oo_version (zip, OOO_VER_UNKNOWN);
+
+ g_object_unref (zip);
+
+ return ver != OOO_VER_UNKNOWN;
+}
Modified: trunk/plugins/openoffice/plugin.xml.in
==============================================================================
--- trunk/plugins/openoffice/plugin.xml.in (original)
+++ trunk/plugins/openoffice/plugin.xml.in Thu Mar 12 20:18:53 2009
@@ -8,7 +8,7 @@
<attribute name="module_file" value="openoffice"/>
</loader>
<services>
- <service type="file_opener" id="openoffice" priority="1" probe="FALSE">
+ <service type="file_opener" id="openoffice" priority="1" probe="TRUE">
<information>
<_description>Open/Star Calc (*.sxc, *.ods)</_description>
</information>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]