summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
Diffstat (limited to 'sc')
-rw-r--r--sc/CppunitTest_sc_ucalc.mk4
-rw-r--r--sc/Library_sc.mk5
-rw-r--r--sc/inc/orcushandler.hxx47
-rw-r--r--sc/source/core/tool/orcushandler.cxx166
-rw-r--r--sc/source/ui/docshell/docsh.cxx16
-rw-r--r--sc/source/ui/inc/docsh.hxx1
6 files changed, 239 insertions, 0 deletions
diff --git a/sc/CppunitTest_sc_ucalc.mk b/sc/CppunitTest_sc_ucalc.mk
index 817bec0ec594..6710f8a523f7 100644
--- a/sc/CppunitTest_sc_ucalc.mk
+++ b/sc/CppunitTest_sc_ucalc.mk
@@ -43,6 +43,10 @@ ifeq ($(ENABLE_TELEPATHY),TRUE)
$(eval $(call gb_CppunitTest_use_libraries,sc_ucalc,tubes))
endif
+$(eval $(call gb_CppunitTest_use_externals,sc_ucalc,\
+ orcus \
+))
+
$(eval $(call gb_CppunitTest_use_libraries,sc_ucalc, \
avmedia \
basegfx \
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 345c7b5a0303..f83ba546a5b1 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -90,6 +90,10 @@ $(eval $(call gb_Library_use_libraries,sc,\
$(gb_STDLIBS) \
))
+$(eval $(call gb_Library_use_externals,sc,\
+ orcus \
+))
+
$(eval $(call gb_Library_add_exception_objects,sc,\
sc/source/core/data/attarray \
sc/source/core/data/attrib \
@@ -210,6 +214,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
sc/source/core/tool/navicfg \
sc/source/core/tool/odffmap \
sc/source/core/tool/optutil \
+ sc/source/core/tool/orcushandler \
sc/source/core/tool/parclass \
sc/source/core/tool/printopt \
sc/source/core/tool/prnsave \
diff --git a/sc/inc/orcushandler.hxx b/sc/inc/orcushandler.hxx
new file mode 100644
index 000000000000..8ed04a4fc591
--- /dev/null
+++ b/sc/inc/orcushandler.hxx
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2012 Kohei Yoshida <kohei.yoshida@suse.com>
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#ifndef __SC_ORCUSHANDLER_HXX__
+#define __SC_ORCUSHANDLER_HXX__
+
+#include "rtl/ustring.hxx"
+
+class ScDocument;
+
+/**
+ * Collection of orcus filter wrappers.
+ */
+class ScOrcusFilters
+{
+public:
+ static bool importCSV(ScDocument& rDoc, const rtl::OUString& rPath);
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/tool/orcushandler.cxx b/sc/source/core/tool/orcushandler.cxx
new file mode 100644
index 000000000000..2fa5e890d180
--- /dev/null
+++ b/sc/source/core/tool/orcushandler.cxx
@@ -0,0 +1,166 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2012 Kohei Yoshida <kohei.yoshida@suse.com>
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include "orcushandler.hxx"
+#include "document.hxx"
+
+#include "tools/urlobj.hxx"
+
+#include <orcus/model/interface.hpp>
+#include <orcus/orcus_csv.hpp>
+
+#include <boost/ptr_container/ptr_vector.hpp>
+
+using orcus::model::row_t;
+using orcus::model::col_t;
+using orcus::model::formula_grammar_t;
+
+namespace {
+
+class ScOrcusSheet;
+
+class ScOrcusFactory : public orcus::model::iface::factory
+{
+ ScDocument& mrDoc;
+ boost::ptr_vector<ScOrcusSheet> maSheets;
+
+public:
+ ScOrcusFactory(ScDocument& rDoc);
+
+ virtual orcus::model::iface::sheet* append_sheet(const char *sheet_name, size_t sheet_name_length);
+ virtual orcus::model::iface::shared_strings* get_shared_strings();
+ virtual orcus::model::iface::styles* get_styles();
+};
+
+class ScOrcusSheet : public orcus::model::iface::sheet
+{
+ ScDocument& mrDoc;
+ SCTAB mnTab;
+public:
+ ScOrcusSheet(ScDocument& rDoc, SCTAB nTab);
+
+ virtual void set_auto(row_t row, col_t col, const char* p, size_t n);
+ virtual void set_format(row_t row, col_t col, size_t xf_index);
+ virtual void set_formula(row_t row, col_t col, formula_grammar_t grammar, const char* p, size_t n);
+ virtual void set_formula_result(row_t row, col_t col, const char* p, size_t n);
+ virtual void set_shared_formula(
+ row_t row, col_t col, formula_grammar_t grammar, size_t sindex,
+ const char* p_formula, size_t n_formula, const char* p_range, size_t n_range);
+ virtual void set_shared_formula(row_t row, col_t col, size_t sindex);
+ virtual void set_string(row_t row, col_t col, size_t sindex);
+ virtual void set_value(row_t row, col_t col, double value);
+};
+
+ScOrcusFactory::ScOrcusFactory(ScDocument& rDoc) : mrDoc(rDoc) {}
+
+orcus::model::iface::sheet* ScOrcusFactory::append_sheet(const char* sheet_name, size_t sheet_name_length)
+{
+ OUString aTabName(sheet_name, sheet_name_length, RTL_TEXTENCODING_UTF8);
+ if (!mrDoc.InsertTab(SC_TAB_APPEND, aTabName))
+ return NULL;
+
+ SCTAB nTab = mrDoc.GetTableCount() - 1;
+ maSheets.push_back(new ScOrcusSheet(mrDoc, nTab));
+ return &maSheets.back();
+}
+
+orcus::model::iface::shared_strings* ScOrcusFactory::get_shared_strings()
+{
+ // We don't support it yet.
+ return NULL;
+}
+
+orcus::model::iface::styles* ScOrcusFactory::get_styles()
+{
+ // We don't support it yet.
+ return NULL;
+}
+
+ScOrcusSheet::ScOrcusSheet(ScDocument& rDoc, SCTAB nTab) :
+ mrDoc(rDoc), mnTab(nTab) {}
+
+void ScOrcusSheet::set_auto(row_t row, col_t col, const char* p, size_t n)
+{
+ OUString aVal(p, n, RTL_TEXTENCODING_UTF8);
+ mrDoc.SetString(col, row, mnTab, aVal);
+}
+
+void ScOrcusSheet::set_format(row_t /*row*/, col_t /*col*/, size_t /*xf_index*/)
+{
+}
+
+void ScOrcusSheet::set_formula(
+ row_t /*row*/, col_t /*col*/, formula_grammar_t /*grammar*/, const char* /*p*/, size_t /*n*/)
+{
+}
+
+void ScOrcusSheet::set_formula_result(row_t /*row*/, col_t /*col*/, const char* /*p*/, size_t /*n*/)
+{
+}
+
+void ScOrcusSheet::set_shared_formula(
+ row_t /*row*/, col_t /*col*/, formula_grammar_t /*grammar*/, size_t /*sindex*/,
+ const char* /*p_formula*/, size_t /*n_formula*/, const char* /*p_range*/, size_t /*n_range*/)
+{
+}
+
+void ScOrcusSheet::set_shared_formula(row_t /*row*/, col_t /*col*/, size_t /*sindex*/)
+{
+}
+
+void ScOrcusSheet::set_string(row_t /*row*/, col_t /*col*/, size_t /*sindex*/)
+{
+}
+
+void ScOrcusSheet::set_value(row_t /*row*/, col_t /*col*/, double /*value*/)
+{
+}
+
+} // anonymous namespace
+
+bool ScOrcusFilters::importCSV(ScDocument& rDoc, const OUString& rPath)
+{
+ ScOrcusFactory aFactory(rDoc);
+ INetURLObject aURL(rPath);
+ const char* path = rtl::OUStringToOString(aURL.getFSysPath(INetURLObject::FSYS_UNX), RTL_TEXTENCODING_UTF8).getStr();
+
+ try
+ {
+ orcus::orcus_csv filter(&aFactory);
+ filter.read_file(path);
+ }
+ catch (const std::exception&)
+ {
+ rDoc.InsertTab(SC_TAB_APPEND, OUString("Foo"));
+ rDoc.SetString(0, 0, 0, "Failed to load!!!");
+ return false;
+ }
+ return true;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index 184800397abf..94e51030b299 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -112,6 +112,8 @@
#include "cellsuno.hxx"
#include "dpobject.hxx"
#include "markdata.hxx"
+#include "orcushandler.hxx"
+
#ifdef ENABLE_TELEPATHY
#include "sccollaboration.hxx"
#endif
@@ -1497,6 +1499,20 @@ sal_Bool ScDocShell::ConvertFrom( SfxMedium& rMedium )
return bRet;
}
+bool ScDocShell::LoadExternal(SfxMedium& rMed, const OUString& rProvider)
+{
+ if (rProvider == "orcus")
+ {
+ if (!ScOrcusFilters::importCSV(aDocument, rMed.GetName()))
+ return false;
+
+ FinishedLoading(SFX_LOADED_MAINDOCUMENT | SFX_LOADED_IMAGES);
+ return true;
+ }
+
+ return false;
+}
+
ScDocShell::PrepareSaveGuard::PrepareSaveGuard( ScDocShell& rDocShell )
: mrDocShell( rDocShell)
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index 6b0f926403be..1efff933c57f 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -212,6 +212,7 @@ public:
virtual sal_Bool Load( SfxMedium& rMedium );
virtual sal_Bool LoadFrom( SfxMedium& rMedium );
virtual sal_Bool ConvertFrom( SfxMedium &rMedium );
+ virtual bool LoadExternal(SfxMedium& rMedium, const rtl::OUString& rProvider);
virtual sal_Bool Save();
virtual sal_Bool SaveAs( SfxMedium& rMedium );
virtual sal_Bool ConvertTo( SfxMedium &rMedium );