diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-04-11 12:13:05 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2013-04-13 01:54:39 -0400 |
commit | 3fc45b3f5841cc61efc74057f6956c4a1426382e (patch) | |
tree | c23931ad79fca4eb4d8949eabf0f8990cbeeec72 | |
parent | eb878bf1659f12036e85a3b636c041976863152f (diff) |
Show progress indicator during document import via orcus.
Change-Id: I74e2b8299455753d4663f344506912302317b681
-rw-r--r-- | sc/inc/orcusfilters.hxx | 9 | ||||
-rw-r--r-- | sc/source/filter/inc/orcusfiltersimpl.hxx | 8 | ||||
-rw-r--r-- | sc/source/filter/inc/orcusinterface.hxx | 19 | ||||
-rw-r--r-- | sc/source/filter/orcus/interface.cxx | 56 | ||||
-rw-r--r-- | sc/source/filter/orcus/orcusfiltersimpl.cxx | 45 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh.cxx | 8 |
6 files changed, 123 insertions, 22 deletions
diff --git a/sc/inc/orcusfilters.hxx b/sc/inc/orcusfilters.hxx index ab09d8cdb680..62c97591ee5a 100644 --- a/sc/inc/orcusfilters.hxx +++ b/sc/inc/orcusfilters.hxx @@ -17,6 +17,7 @@ class SvTreeListBox; struct ScOrcusXMLTreeParam; struct ScOrcusImportXMLParam; class ScOrcusXMLContext; +class SfxMedium; /** * Collection of orcus filter wrappers. @@ -26,13 +27,13 @@ class ScOrcusFilters public: virtual ~ScOrcusFilters() {} - virtual bool importCSV(ScDocument& rDoc, const OUString& rPath) const = 0; + virtual bool importCSV(ScDocument& rDoc, SfxMedium& rMedium) const = 0; - virtual bool importGnumeric(ScDocument& rDoc, const OUString& rPath) const = 0; + virtual bool importGnumeric(ScDocument& rDoc, SfxMedium& rMedium) const = 0; - virtual bool importXLSX(ScDocument& rDoc, const OUString& rPath) const = 0; + virtual bool importXLSX(ScDocument& rDoc, SfxMedium& rMedium) const = 0; - virtual bool importODS(ScDocument& rDoc, const OUString& rPath) const = 0; + virtual bool importODS(ScDocument& rDoc, SfxMedium& rMedium) const = 0; /** * Create a context for XML file. The context object stores session diff --git a/sc/source/filter/inc/orcusfiltersimpl.hxx b/sc/source/filter/inc/orcusfiltersimpl.hxx index e07cd19d39e1..0db7f6a79b39 100644 --- a/sc/source/filter/inc/orcusfiltersimpl.hxx +++ b/sc/source/filter/inc/orcusfiltersimpl.hxx @@ -20,10 +20,10 @@ class ScOrcusFiltersImpl : public ScOrcusFilters public: static OString toSystemPath(const OUString& rPath); - virtual bool importCSV(ScDocument& rDoc, const OUString& rPath) const; - virtual bool importGnumeric(ScDocument& rDoc, const OUString& rPath) const; - virtual bool importXLSX(ScDocument& rDoc, const OUString& rPath) const; - virtual bool importODS(ScDocument& rDoc, const OUString& rPath) const; + virtual bool importCSV(ScDocument& rDoc, SfxMedium& rMedium) const; + virtual bool importGnumeric(ScDocument& rDoc, SfxMedium& rMedium) const; + virtual bool importXLSX(ScDocument& rDoc, SfxMedium& rMedium) const; + virtual bool importODS(ScDocument& rDoc, SfxMedium& rMedium) const; virtual ScOrcusXMLContext* createXMLContext(ScDocument& rDoc, const OUString& rPath) const; }; diff --git a/sc/source/filter/inc/orcusinterface.hxx b/sc/source/filter/inc/orcusinterface.hxx index 05ebc6d552f6..862a4cb944a0 100644 --- a/sc/source/filter/inc/orcusinterface.hxx +++ b/sc/source/filter/inc/orcusinterface.hxx @@ -26,6 +26,12 @@ class ScOrcusSheet; class ScOrcusFactory; class ScRangeData; +namespace com { namespace sun { namespace star { namespace task { + +class XStatusIndicator; + +}}}} + class ScOrcusGlobalSettings : public orcus::spreadsheet::iface::import_global_settings { ScDocument& mrDoc; @@ -64,6 +70,11 @@ class ScOrcusSheet : public orcus::spreadsheet::iface::import_sheet typedef std::map<size_t, ScRangeData*> SharedFormulaContainer; SharedFormulaContainer maSharedFormulas; + + int mnCellCount; + + void cellInserted(); + public: ScOrcusSheet(ScDocument& rDoc, SCTAB nTab, ScOrcusFactory& rFactory); @@ -190,6 +201,10 @@ class ScOrcusFactory : public orcus::spreadsheet::iface::import_factory boost::ptr_vector<ScOrcusSheet> maSheets; ScOrcusStyles maStyles; + int mnProgress; + + com::sun::star::uno::Reference<com::sun::star::task::XStatusIndicator> mxStatusIndicator; + public: ScOrcusFactory(ScDocument& rDoc); @@ -204,6 +219,10 @@ public: size_t addString(const OUString& rStr); void pushStringCell(const ScAddress& rPos, size_t nStrIndex); + + void incrementProgress(); + + void setStatusIndicator(const com::sun::star::uno::Reference<com::sun::star::task::XStatusIndicator>& rIndicator); }; #endif diff --git a/sc/source/filter/orcus/interface.cxx b/sc/source/filter/orcus/interface.cxx index 07bc1b2927b0..1e3fb18a474d 100644 --- a/sc/source/filter/orcus/interface.cxx +++ b/sc/source/filter/orcus/interface.cxx @@ -16,10 +16,15 @@ #include "stringutil.hxx" #include "globalnames.hxx" #include "docoptio.hxx" +#include "globstr.hrc" #include "formula/token.hxx" #include "tools/datetime.hxx" +#include <com/sun/star/task/XStatusIndicator.hpp> + +using namespace com::sun::star; + using orcus::spreadsheet::row_t; using orcus::spreadsheet::col_t; using orcus::spreadsheet::formula_grammar_t; @@ -39,7 +44,8 @@ ScOrcusFactory::StringCellCache::StringCellCache(const ScAddress& rPos, size_t n ScOrcusFactory::ScOrcusFactory(ScDocument& rDoc) : mrDoc(rDoc), maGlobalSettings(mrDoc), - maSharedStrings(*this) {} + maSharedStrings(*this), + mnProgress(0) {} orcus::spreadsheet::iface::import_sheet* ScOrcusFactory::append_sheet(const char* sheet_name, size_t sheet_name_length) { @@ -113,6 +119,9 @@ void ScOrcusFactory::finalize() mrDoc.SetString(it->maPos, maStrings[it->mnIndex], &aParam); } + + if (mxStatusIndicator.is()) + mxStatusIndicator->end(); } size_t ScOrcusFactory::appendString(const OUString& rStr) @@ -139,13 +148,48 @@ void ScOrcusFactory::pushStringCell(const ScAddress& rPos, size_t nStrIndex) maStringCells.push_back(StringCellCache(rPos, nStrIndex)); } +void ScOrcusFactory::incrementProgress() +{ + if (!mxStatusIndicator.is()) + // Status indicator object not set. + return; + + // For now, we'll hard-code the progress range to be 100, and stops at 99 + // in all cases. + + if (!mnProgress) + mxStatusIndicator->start(ScGlobal::GetRscString(STR_LOAD_DOC), 100); + + if (mnProgress == 99) + return; + + ++mnProgress; + mxStatusIndicator->setValue(mnProgress); +} + +void ScOrcusFactory::setStatusIndicator(const uno::Reference<task::XStatusIndicator>& rIndicator) +{ + mxStatusIndicator = rIndicator; +} + ScOrcusSheet::ScOrcusSheet(ScDocument& rDoc, SCTAB nTab, ScOrcusFactory& rFactory) : - mrDoc(rDoc), mnTab(nTab), mrFactory(rFactory) {} + mrDoc(rDoc), mnTab(nTab), mrFactory(rFactory), mnCellCount(0) {} + +void ScOrcusSheet::cellInserted() +{ + ++mnCellCount; + if (mnCellCount == 100000) + { + mrFactory.incrementProgress(); + mnCellCount = 0; + } +} 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); + cellInserted(); } void ScOrcusSheet::set_string(row_t row, col_t col, size_t sindex) @@ -156,16 +200,19 @@ void ScOrcusSheet::set_string(row_t row, col_t col, size_t sindex) // implement true shared strings in Calc core. mrFactory.pushStringCell(ScAddress(col, row, mnTab), sindex); + cellInserted(); } void ScOrcusSheet::set_value(row_t row, col_t col, double value) { mrDoc.SetValue( col, row, mnTab, value ); + cellInserted(); } void ScOrcusSheet::set_bool(row_t row, col_t col, bool value) { mrDoc.SetValue(col, row, mnTab, value ? 1.0 : 0.0); + cellInserted(); } void ScOrcusSheet::set_date_time( @@ -189,6 +236,7 @@ void ScOrcusSheet::set_date_time( fTime /= DATE_TIME_FACTOR; mrDoc.SetValue(col, row, mnTab, nDateDiff + fTime); + cellInserted(); } void ScOrcusSheet::set_format(row_t /*row*/, col_t /*col*/, size_t /*xf_index*/) @@ -225,6 +273,7 @@ void ScOrcusSheet::set_formula( OUString aFormula(p, n, RTL_TEXTENCODING_UTF8); formula::FormulaGrammar::Grammar eGrammar = getCalcGrammarFromOrcus( grammar ); mrDoc.SetFormula(ScAddress(col,row,mnTab), aFormula, eGrammar); + cellInserted(); } void ScOrcusSheet::set_formula_result(row_t row, col_t col, const char* p, size_t n) @@ -257,6 +306,7 @@ void ScOrcusSheet::set_shared_formula( ScTokenArray aArr; aArr.AddToken( formula::FormulaIndexToken( ocName, pSharedFormula->GetIndex() ) ); mrDoc.SetFormula(ScAddress(col,row,mnTab), aArr); + cellInserted(); } } @@ -277,6 +327,7 @@ void ScOrcusSheet::set_shared_formula( ScTokenArray aArr; aArr.AddToken( formula::FormulaIndexToken( ocName, pSharedFormula->GetIndex() ) ); mrDoc.SetFormula(ScAddress(col,row,mnTab), aArr); + cellInserted(); } } @@ -289,6 +340,7 @@ void ScOrcusSheet::set_shared_formula(row_t row, col_t col, size_t sindex) ScTokenArray aArr; aArr.AddToken( formula::FormulaIndexToken( ocName, pSharedFormula->GetIndex() ) ); mrDoc.SetFormula(ScAddress(col,row,mnTab), aArr); + cellInserted(); } void ScOrcusSheet::set_array_formula( diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx index 7ef1310c4793..c9213d6e2631 100644 --- a/sc/source/filter/orcus/orcusfiltersimpl.cxx +++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx @@ -13,6 +13,10 @@ #include "document.hxx" #include "tools/urlobj.hxx" +#include "sfx2/docfile.hxx" +#include "sfx2/frame.hxx" +#include "sfx2/sfxsids.hrc" +#include "svl/itemset.hxx" #include <orcus/spreadsheet/import_interface.hpp> #include <orcus/orcus_csv.hpp> @@ -21,22 +25,44 @@ #include <orcus/orcus_ods.hpp> #include <orcus/global.hpp> +#include <com/sun/star/task/XStatusIndicator.hpp> + #ifdef WNT #define SYSTEM_PATH INetURLObject::FSYS_DOS #else #define SYSTEM_PATH INetURLObject::FSYS_UNX #endif +using namespace com::sun::star; + +namespace { + +uno::Reference<task::XStatusIndicator> getStatusIndicator(SfxMedium& rMedium) +{ + uno::Reference<task::XStatusIndicator> xStatusIndicator; + SfxItemSet* pSet = rMedium.GetItemSet(); + if (pSet) + { + const SfxUnoAnyItem* pItem = static_cast<const SfxUsrAnyItem*>(pSet->GetItem(SID_PROGRESS_STATUSBAR_CONTROL)); + if (pItem) + xStatusIndicator.set(pItem->GetValue(), uno::UNO_QUERY); + } + return xStatusIndicator; +} + +} + OString ScOrcusFiltersImpl::toSystemPath(const OUString& rPath) { INetURLObject aURL(rPath); return OUStringToOString(aURL.getFSysPath(SYSTEM_PATH), RTL_TEXTENCODING_UTF8); } -bool ScOrcusFiltersImpl::importCSV(ScDocument& rDoc, const OUString& rPath) const +bool ScOrcusFiltersImpl::importCSV(ScDocument& rDoc, SfxMedium& rMedium) const { ScOrcusFactory aFactory(rDoc); - OString aSysPath = toSystemPath(rPath); + aFactory.setStatusIndicator(getStatusIndicator(rMedium)); + OString aSysPath = toSystemPath(rMedium.GetName()); const char* path = aSysPath.getStr(); try @@ -53,10 +79,11 @@ bool ScOrcusFiltersImpl::importCSV(ScDocument& rDoc, const OUString& rPath) cons return true; } -bool ScOrcusFiltersImpl::importGnumeric(ScDocument& rDoc, const OUString& rPath) const +bool ScOrcusFiltersImpl::importGnumeric(ScDocument& rDoc, SfxMedium& rMedium) const { ScOrcusFactory aFactory(rDoc); - OString aSysPath = toSystemPath(rPath); + aFactory.setStatusIndicator(getStatusIndicator(rMedium)); + OString aSysPath = toSystemPath(rMedium.GetName()); const char* path = aSysPath.getStr(); try @@ -73,10 +100,11 @@ bool ScOrcusFiltersImpl::importGnumeric(ScDocument& rDoc, const OUString& rPath) return true; } -bool ScOrcusFiltersImpl::importXLSX(ScDocument& rDoc, const OUString& rPath) const +bool ScOrcusFiltersImpl::importXLSX(ScDocument& rDoc, SfxMedium& rMedium) const { ScOrcusFactory aFactory(rDoc); - OString aSysPath = toSystemPath(rPath); + aFactory.setStatusIndicator(getStatusIndicator(rMedium)); + OString aSysPath = toSystemPath(rMedium.GetName()); const char* path = aSysPath.getStr(); try @@ -93,10 +121,11 @@ bool ScOrcusFiltersImpl::importXLSX(ScDocument& rDoc, const OUString& rPath) con return true; } -bool ScOrcusFiltersImpl::importODS(ScDocument& rDoc, const OUString& rPath) const +bool ScOrcusFiltersImpl::importODS(ScDocument& rDoc, SfxMedium& rMedium) const { ScOrcusFactory aFactory(rDoc); - OString aSysPath = toSystemPath(rPath); + aFactory.setStatusIndicator(getStatusIndicator(rMedium)); + OString aSysPath = toSystemPath(rMedium.GetName()); const char* path = aSysPath.getStr(); try diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 0cc10bdd9db6..7b5a38318301 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -1508,22 +1508,22 @@ bool ScDocShell::LoadExternal( SfxMedium& rMed ) const OUString& rFilterName = pFilter->GetName(); if (rFilterName == "gnumeric") { - if (!pOrcus->importGnumeric(aDocument, rMed.GetName())) + if (!pOrcus->importGnumeric(aDocument, rMed)) return false; } else if (rFilterName == "csv") { - if (!pOrcus->importCSV(aDocument, rMed.GetName())) + if (!pOrcus->importCSV(aDocument, rMed)) return false; } else if (rFilterName == "xlsx") { - if (!pOrcus->importXLSX(aDocument, rMed.GetName())) + if (!pOrcus->importXLSX(aDocument, rMed)) return false; } else if (rFilterName == "ods") { - if (!pOrcus->importODS(aDocument, rMed.GetName())) + if (!pOrcus->importODS(aDocument, rMed)) return false; } |