writerperfect[libwps,tdf#128673]: use the inFilter option in headless mode...

Change-Id: I494360ddb55e39e09edf03aaf0bf6a01dc432f83
Reviewed-on: https://gerrit.libreoffice.org/82595
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
alonso
2019-11-13 14:03:53 +01:00
committed by Noel Grandin
parent d681cca399
commit f14cd1ad62
2 changed files with 100 additions and 71 deletions

View File

@@ -177,7 +177,8 @@ private:
////////////////////////////////////////////////////////////
bool MSWorksCalcImportFilter::doImportDocument(weld::Window* pParent,
librevenge::RVNGInputStream& rInput,
OdsGenerator& rGenerator, utl::MediaDescriptor&)
OdsGenerator& rGenerator,
utl::MediaDescriptor& mediaDescriptor)
{
libwps::WPSKind kind = libwps::WPS_TEXT;
libwps::WPSCreator creator;
@@ -191,7 +192,14 @@ bool MSWorksCalcImportFilter::doImportDocument(weld::Window* pParent,
std::string fileEncoding;
if (needEncoding)
{
OUString title, encoding;
OUString encoding;
// first check if we can find the encoding in the filter options (headless mode)
mediaDescriptor[utl::MediaDescriptor::PROP_FILTEROPTIONS()] >>= encoding;
if (!encoding.isEmpty()) // TODO: check if the encoding string is valid
fileEncoding = encoding.toUtf8().getStr();
else
{
OUString title;
switch (creator)
{
case libwps::WPS_MSWORKS:
@@ -221,6 +229,7 @@ bool MSWorksCalcImportFilter::doImportDocument(weld::Window* pParent,
break;
}
fileEncoding = encoding.toUtf8().getStr(); // set default to the proposed encoding
try
{
writerperfect::WPFTEncodingDialog aDlg(pParent, title, encoding);
@@ -239,10 +248,19 @@ bool MSWorksCalcImportFilter::doImportDocument(weld::Window* pParent,
"ignoring Exception in MSWorksCalcImportFilter::doImportDocument");
}
}
}
OString aUtf8Passwd;
if (confidence == libwps::WPS_CONFIDENCE_SUPPORTED_ENCRYPTION)
{
// try to ask for a password
OUString sPassword;
// now check if we can find the password in the properties
// (just in case, "soffice --headless" adds an option to send password)
mediaDescriptor[utl::MediaDescriptor::PROP_PASSWORD()] >>= sPassword;
if (!sPassword.isEmpty())
aUtf8Passwd = OUStringToOString(sPassword, RTL_TEXTENCODING_UTF8);
else
{
// ok, ask the user for a password
try
{
SfxPasswordDialog aPasswdDlg(pParent);
@@ -257,6 +275,7 @@ bool MSWorksCalcImportFilter::doImportDocument(weld::Window* pParent,
return false;
}
}
}
return libwps::WPS_OK
== libwps::WPSDocument::parse(&rInput, &rGenerator,
confidence == libwps::WPS_CONFIDENCE_SUPPORTED_ENCRYPTION

View File

@@ -31,7 +31,8 @@ static bool handleEmbeddedWKSObject(const librevenge::RVNGBinaryData& data,
bool MSWorksImportFilter::doImportDocument(weld::Window* pParent,
librevenge::RVNGInputStream& rInput,
OdtGenerator& rGenerator, utl::MediaDescriptor&)
OdtGenerator& rGenerator,
utl::MediaDescriptor& mediaDescriptor)
{
libwps::WPSKind kind = libwps::WPS_TEXT;
libwps::WPSCreator creator;
@@ -40,12 +41,17 @@ bool MSWorksImportFilter::doImportDocument(weld::Window* pParent,
= libwps::WPSDocument::isFileFormatSupported(&rInput, kind, creator, needEncoding);
std::string fileEncoding;
try
{
if ((kind == libwps::WPS_TEXT) && (confidence == libwps::WPS_CONFIDENCE_EXCELLENT)
&& needEncoding)
{
OUString title, encoding;
OUString encoding;
// first check if we can find the encoding in the filter options (headless mode)
mediaDescriptor[utl::MediaDescriptor::PROP_FILTEROPTIONS()] >>= encoding;
if (!encoding.isEmpty()) // TODO: check if the encoding string is valid
fileEncoding = encoding.toUtf8().getStr();
else
{
OUString title;
switch (creator)
{
@@ -67,6 +73,9 @@ bool MSWorksImportFilter::doImportDocument(weld::Window* pParent,
break;
}
fileEncoding = encoding.toUtf8().getStr(); // set default to the proposed encoding
try
{
writerperfect::WPFTEncodingDialog aDlg(pParent, title, encoding);
if (aDlg.run() == RET_OK)
{
@@ -77,11 +86,12 @@ bool MSWorksImportFilter::doImportDocument(weld::Window* pParent,
else if (aDlg.hasUserCalledCancel())
return false;
}
}
catch (css::uno::Exception&)
{
TOOLS_WARN_EXCEPTION("writerperfect", "ignoring");
}
}
}
return libwps::WPS_OK
== libwps::WPSDocument::parse(&rInput, &rGenerator, "", fileEncoding.c_str());
}