diff options
author | osnola <alonso@loria.fr> | 2017-04-02 09:42:59 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2017-04-02 13:42:19 +0200 |
commit | b0067c89e6b2a4e29465d9da9a731ae30a66dce6 (patch) | |
tree | 4f10cbb6eb212c9528e6e3410d4f28b230818f97 /writerperfect/source/calc | |
parent | af45b3d48e3a027c14317db944a8d67de063352f (diff) |
libwps import filter improvements
+ some astyle modifications,
+ add .wk4 and .123 to the list of file extensions,
+ add support to open Lotus files protected by a password.
Change-Id: I94d4afffd73f0999ff2b1958704cb3985fcd0cc9
Diffstat (limited to 'writerperfect/source/calc')
-rw-r--r-- | writerperfect/source/calc/MSWorksCalcImportFilter.cxx | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/writerperfect/source/calc/MSWorksCalcImportFilter.cxx b/writerperfect/source/calc/MSWorksCalcImportFilter.cxx index 94a111ec7127..11881202ad28 100644 --- a/writerperfect/source/calc/MSWorksCalcImportFilter.cxx +++ b/writerperfect/source/calc/MSWorksCalcImportFilter.cxx @@ -16,6 +16,7 @@ #include <com/sun/star/ucb/XContentAccess.hpp> #include <comphelper/processfactory.hxx> #include <cppuhelper/supportsservice.hxx> +#include <sfx2/passwd.hxx> #include <tools/urlobj.hxx> #include <ucbhelper/content.hxx> @@ -90,7 +91,7 @@ public: /*! \brief seeks to a offset position, from actual, beginning or ending position * \return 0 if ok */ - int seek(long , librevenge::RVNG_SEEK_TYPE) override + int seek(long, librevenge::RVNG_SEEK_TYPE) override { return 1; } @@ -191,8 +192,10 @@ bool MSWorksCalcImportFilter::doImportDocument(librevenge::RVNGInputStream &rInp bool needEncoding; const libwps::WPSConfidence confidence = libwps::WPSDocument::isFileFormatSupported(&rInput, kind, creator, needEncoding); + if ((kind != libwps::WPS_SPREADSHEET && kind != libwps::WPS_DATABASE) || (confidence == libwps::WPS_CONFIDENCE_NONE)) + return false; std::string fileEncoding(""); - if ((kind == libwps::WPS_SPREADSHEET || kind == libwps::WPS_DATABASE) && (confidence == libwps::WPS_CONFIDENCE_EXCELLENT) && needEncoding) + if (needEncoding) { OUString title, encoding; if (creator == libwps::WPS_MSWORKS) @@ -232,7 +235,25 @@ bool MSWorksCalcImportFilter::doImportDocument(librevenge::RVNGInputStream &rInp SAL_WARN("writerperfect", "ignoring Exception in MSWorksCalcImportFilter::doImportDocument"); } } - return libwps::WPS_OK == libwps::WPSDocument::parse(&rInput, &rGenerator, "", fileEncoding.c_str()); + OString aUtf8Passwd; + if (confidence==libwps::WPS_CONFIDENCE_SUPPORTED_ENCRYPTION) + { + // try to ask for a password + try + { + ScopedVclPtrInstance< SfxPasswordDialog > aPasswdDlg(nullptr); + aPasswdDlg->SetMinLen(1); + if (!aPasswdDlg->Execute()) + return false; + OUString aPasswd = aPasswdDlg->GetPassword(); + aUtf8Passwd = OUStringToOString(aPasswd, RTL_TEXTENCODING_UTF8); + } + catch (...) + { + return false; + } + } + return libwps::WPS_OK == libwps::WPSDocument::parse(&rInput, &rGenerator, confidence==libwps::WPS_CONFIDENCE_SUPPORTED_ENCRYPTION ? aUtf8Passwd.getStr() : nullptr, fileEncoding.c_str()); } //XExtendedFilterDetection @@ -326,12 +347,12 @@ sal_Bool MSWorksCalcImportFilter::filter(const css::uno::Sequence< css::beans::P structuredInput.addFile(sWM3Name,"WK3"); structuredInput.addFile(sFM3Name,"FM3"); - // If the file is valid and libwps is at least 0.4.4, doImportDocument will convert it. - // If libwps is at most 0.4.3, doImportDocument will fail when checking if the file is supported - // and it is ok to call again doImportDocument with the main input. - // If the file is corrupted beyond all retrieval, doImportDocument will fail two times :-~ - if (this->doImportDocument(structuredInput, exporter, aDescriptor)) - return true; + libwps::WPSKind kind = libwps::WPS_TEXT; + libwps::WPSCreator creator; + bool needEncoding; + const libwps::WPSConfidence confidence = libwps::WPSDocument::isFileFormatSupported(&structuredInput, kind, creator, needEncoding); + if (confidence!=libwps::WPS_CONFIDENCE_NONE) + return this->doImportDocument(structuredInput, exporter, aDescriptor); } } } @@ -350,7 +371,7 @@ bool MSWorksCalcImportFilter::doDetectFormat(librevenge::RVNGInputStream &rInput bool needEncoding; const libwps::WPSConfidence confidence = libwps::WPSDocument::isFileFormatSupported(&rInput, kind, creator, needEncoding); - if ((kind == libwps::WPS_SPREADSHEET || kind == libwps::WPS_DATABASE) && confidence == libwps::WPS_CONFIDENCE_EXCELLENT) + if ((kind == libwps::WPS_SPREADSHEET || kind == libwps::WPS_DATABASE) && confidence != libwps::WPS_CONFIDENCE_NONE) { if (creator == libwps::WPS_MSWORKS) { |