summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-12-04 06:50:20 (GMT)
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2012-12-04 07:24:18 (GMT)
commit9c2dfa9b41f82cfa763c500d34fe2a32a075f566 (patch)
tree08e5e74ce3fef619e9b16f396d1d17d3088b1f6a
parentcb9cc446b39cafea018d2492fb4842a94aed7b77 (diff)
activate basic gnumeric support in experimental mode
Please note that this is nothing mroe than a technical demo showing the great opportunities provided by orcus. It only imports some basic objects for now but provides the basis for the future calc filter framework. Change-Id: I6c6fb8d07e33482b2efdcbbe9a0f43224c5aa5a1
-rw-r--r--framework/source/loadenv/loadenv.cxx24
-rw-r--r--sc/inc/orcusfilters.hxx2
-rw-r--r--sc/source/filter/inc/orcusfiltersimpl.hxx1
-rw-r--r--sc/source/filter/inc/orcusinterface.hxx2
-rw-r--r--sc/source/filter/orcus/orcusfiltersimpl.cxx21
-rw-r--r--sc/source/ui/docshell/docsh.cxx2
6 files changed, 48 insertions, 4 deletions
diff --git a/framework/source/loadenv/loadenv.cxx b/framework/source/loadenv/loadenv.cxx
index c676fe4..78bc67c 100644
--- a/framework/source/loadenv/loadenv.cxx
+++ b/framework/source/loadenv/loadenv.cxx
@@ -32,6 +32,9 @@
#include <services.h>
#include <comphelper/interaction.hxx>
#include <framework/interaction.hxx>
+#include <comphelper/processfactory.hxx>
+#include <comphelper/configuration.hxx>
+#include "officecfg/Office/Common.hxx"
#include <com/sun/star/task/ErrorCodeRequest.hpp>
#include <com/sun/star/uno/RuntimeException.hpp>
@@ -703,15 +706,22 @@ LoadEnv::EContentType LoadEnv::classifyContent(const ::rtl::OUString&
namespace {
-#if 1
+#if 0
+// TODO: We will reinstate this function later, so don't remove this!
bool queryOrcusTypeAndFilter(const uno::Sequence<beans::PropertyValue>&, OUString&, OUString&)
{
return false;
}
#else
-// TODO: We will reinstate this function later, so don't remove this!
bool queryOrcusTypeAndFilter(const uno::Sequence<beans::PropertyValue>& rDescriptor, OUString& rType, OUString& rFilter)
{
+ // depending on the experimental mode
+ uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
+ if (!xContext.is() || !officecfg::Office::Common::Misc::ExperimentalMode::get(xContext))
+ {
+ return false;
+ }
+
OUString aURL;
sal_Int32 nSize = rDescriptor.getLength();
for (sal_Int32 i = 0; i < nSize; ++i)
@@ -727,13 +737,21 @@ bool queryOrcusTypeAndFilter(const uno::Sequence<beans::PropertyValue>& rDescrip
if (aURL.isEmpty() || aURL.copy(0,8).equalsIgnoreAsciiCase("private:"))
return false;
- if (aURL.endsWith(".csv"))
+ if(aURL.endsWith(".gnumeric"))
+ {
+ rType = "generic_Text";
+ rFilter = "orcus-gnumeric";
+ return true;
+ }
+#if 0
+ else if (aURL.endsWith(".csv"))
{
// Use .csv as the first test file type.
rType = "generic_Text";
rFilter = "orcus-test-filter";
return true;
}
+#endif
return false;
}
diff --git a/sc/inc/orcusfilters.hxx b/sc/inc/orcusfilters.hxx
index bcf8881..9f3ca13 100644
--- a/sc/inc/orcusfilters.hxx
+++ b/sc/inc/orcusfilters.hxx
@@ -29,6 +29,8 @@ public:
virtual bool importCSV(ScDocument& rDoc, const rtl::OUString& rPath) const = 0;
+ virtual bool importGnumeric(ScDocument& rDoc, const rtl::OUString& rPath) const = 0;
+
/**
* Create a context for XML file. The context object stores session
* information for each unique XML file. You must create a new context
diff --git a/sc/source/filter/inc/orcusfiltersimpl.hxx b/sc/source/filter/inc/orcusfiltersimpl.hxx
index 2238b70..a97a50c 100644
--- a/sc/source/filter/inc/orcusfiltersimpl.hxx
+++ b/sc/source/filter/inc/orcusfiltersimpl.hxx
@@ -21,6 +21,7 @@ public:
static rtl::OString toSystemPath(const rtl::OUString& rPath);
virtual bool importCSV(ScDocument& rDoc, const rtl::OUString& rPath) const;
+ virtual bool importGnumeric(ScDocument& rDoc, const rtl::OUString& rPath) const;
virtual ScOrcusXMLContext* createXMLContext(ScDocument& rDoc, const rtl::OUString& rPath) const;
};
diff --git a/sc/source/filter/inc/orcusinterface.hxx b/sc/source/filter/inc/orcusinterface.hxx
index d800474..2f8380c 100644
--- a/sc/source/filter/inc/orcusinterface.hxx
+++ b/sc/source/filter/inc/orcusinterface.hxx
@@ -17,6 +17,8 @@
#include <boost/ptr_container/ptr_vector.hpp>
+#include <map>
+
class ScDocument;
class ScOrcusSheet;
class ScRangeData;
diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx
index 4e6c98b..ed33cc1 100644
--- a/sc/source/filter/orcus/orcusfiltersimpl.cxx
+++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx
@@ -16,6 +16,7 @@
#include <orcus/spreadsheet/import_interface.hpp>
#include <orcus/orcus_csv.hpp>
+#include <orcus/orcus_gnumeric.hpp>
#include <orcus/global.hpp>
#ifdef WNT
@@ -50,6 +51,26 @@ bool ScOrcusFiltersImpl::importCSV(ScDocument& rDoc, const OUString& rPath) cons
return true;
}
+bool ScOrcusFiltersImpl::importGnumeric(ScDocument& rDoc, const OUString& rPath) const
+{
+ ScOrcusFactory aFactory(rDoc);
+ OString aSysPath = toSystemPath(rPath);
+ const char* path = aSysPath.getStr();
+
+ try
+ {
+ orcus::orcus_gnumeric filter(&aFactory);
+ filter.read_file(path);
+ }
+ catch (const std::exception& e)
+ {
+ SAL_WARN("sc", "Unable to load gnumeric file! " << e.what());
+ return false;
+ }
+
+ return true;
+}
+
ScOrcusXMLContext* ScOrcusFiltersImpl::createXMLContext(ScDocument& rDoc, const rtl::OUString& rPath) const
{
return new ScOrcusXMLContextImpl(rDoc, rPath);
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 2fe4cad..52355d6 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -1426,7 +1426,7 @@ bool ScDocShell::LoadExternal(SfxMedium& rMed, const OUString& rProvider)
if (!pOrcus)
return false;
- if (!pOrcus->importCSV(aDocument, rMed.GetName()))
+ if (!pOrcus->importGnumeric(aDocument, rMed.GetName()))
return false;
FinishedLoading(SFX_LOADED_MAINDOCUMENT | SFX_LOADED_IMAGES);