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:
@@ -177,7 +177,8 @@ private:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool MSWorksCalcImportFilter::doImportDocument(weld::Window* pParent,
|
bool MSWorksCalcImportFilter::doImportDocument(weld::Window* pParent,
|
||||||
librevenge::RVNGInputStream& rInput,
|
librevenge::RVNGInputStream& rInput,
|
||||||
OdsGenerator& rGenerator, utl::MediaDescriptor&)
|
OdsGenerator& rGenerator,
|
||||||
|
utl::MediaDescriptor& mediaDescriptor)
|
||||||
{
|
{
|
||||||
libwps::WPSKind kind = libwps::WPS_TEXT;
|
libwps::WPSKind kind = libwps::WPS_TEXT;
|
||||||
libwps::WPSCreator creator;
|
libwps::WPSCreator creator;
|
||||||
@@ -191,70 +192,88 @@ bool MSWorksCalcImportFilter::doImportDocument(weld::Window* pParent,
|
|||||||
std::string fileEncoding;
|
std::string fileEncoding;
|
||||||
if (needEncoding)
|
if (needEncoding)
|
||||||
{
|
{
|
||||||
OUString title, encoding;
|
OUString encoding;
|
||||||
switch (creator)
|
// 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
|
||||||
{
|
{
|
||||||
case libwps::WPS_MSWORKS:
|
OUString title;
|
||||||
title = WpResId(STR_ENCODING_DIALOG_TITLE_MSWORKS);
|
switch (creator)
|
||||||
encoding = "CP850";
|
|
||||||
break;
|
|
||||||
case libwps::WPS_LOTUS:
|
|
||||||
title = WpResId(STR_ENCODING_DIALOG_TITLE_LOTUS);
|
|
||||||
encoding = "CP437";
|
|
||||||
break;
|
|
||||||
case libwps::WPS_SYMPHONY:
|
|
||||||
title = WpResId(STR_ENCODING_DIALOG_TITLE_SYMPHONY);
|
|
||||||
encoding = "CP437";
|
|
||||||
break;
|
|
||||||
case libwps::WPS_QUATTRO_PRO:
|
|
||||||
title = WpResId(STR_ENCODING_DIALOG_TITLE_QUATTROPRO);
|
|
||||||
encoding = "CP437";
|
|
||||||
break;
|
|
||||||
case libwps::WPS_RESERVED_2:
|
|
||||||
title = WpResId(STR_ENCODING_DIALOG_TITLE_MSMULTIPLAN);
|
|
||||||
encoding = "CP437";
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
SAL_INFO("writerperfect", "unexpected creator: " << creator);
|
|
||||||
title = WpResId(STR_ENCODING_DIALOG_TITLE);
|
|
||||||
encoding = "CP437";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
writerperfect::WPFTEncodingDialog aDlg(pParent, title, encoding);
|
|
||||||
if (aDlg.run() == RET_OK)
|
|
||||||
{
|
{
|
||||||
if (!aDlg.GetEncoding().isEmpty())
|
case libwps::WPS_MSWORKS:
|
||||||
fileEncoding = aDlg.GetEncoding().toUtf8().getStr();
|
title = WpResId(STR_ENCODING_DIALOG_TITLE_MSWORKS);
|
||||||
|
encoding = "CP850";
|
||||||
|
break;
|
||||||
|
case libwps::WPS_LOTUS:
|
||||||
|
title = WpResId(STR_ENCODING_DIALOG_TITLE_LOTUS);
|
||||||
|
encoding = "CP437";
|
||||||
|
break;
|
||||||
|
case libwps::WPS_SYMPHONY:
|
||||||
|
title = WpResId(STR_ENCODING_DIALOG_TITLE_SYMPHONY);
|
||||||
|
encoding = "CP437";
|
||||||
|
break;
|
||||||
|
case libwps::WPS_QUATTRO_PRO:
|
||||||
|
title = WpResId(STR_ENCODING_DIALOG_TITLE_QUATTROPRO);
|
||||||
|
encoding = "CP437";
|
||||||
|
break;
|
||||||
|
case libwps::WPS_RESERVED_2:
|
||||||
|
title = WpResId(STR_ENCODING_DIALOG_TITLE_MSMULTIPLAN);
|
||||||
|
encoding = "CP437";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
SAL_INFO("writerperfect", "unexpected creator: " << creator);
|
||||||
|
title = WpResId(STR_ENCODING_DIALOG_TITLE);
|
||||||
|
encoding = "CP437";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fileEncoding = encoding.toUtf8().getStr(); // set default to the proposed encoding
|
||||||
|
try
|
||||||
|
{
|
||||||
|
writerperfect::WPFTEncodingDialog aDlg(pParent, title, encoding);
|
||||||
|
if (aDlg.run() == RET_OK)
|
||||||
|
{
|
||||||
|
if (!aDlg.GetEncoding().isEmpty())
|
||||||
|
fileEncoding = aDlg.GetEncoding().toUtf8().getStr();
|
||||||
|
}
|
||||||
|
// we can fail because we are in headless mode, the user has cancelled conversion, ...
|
||||||
|
else if (aDlg.hasUserCalledCancel())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
SAL_WARN("writerperfect",
|
||||||
|
"ignoring Exception in MSWorksCalcImportFilter::doImportDocument");
|
||||||
}
|
}
|
||||||
// we can fail because we are in headless mode, the user has cancelled conversion, ...
|
|
||||||
else if (aDlg.hasUserCalledCancel())
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
SAL_WARN("writerperfect",
|
|
||||||
"ignoring Exception in MSWorksCalcImportFilter::doImportDocument");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OString aUtf8Passwd;
|
OString aUtf8Passwd;
|
||||||
if (confidence == libwps::WPS_CONFIDENCE_SUPPORTED_ENCRYPTION)
|
if (confidence == libwps::WPS_CONFIDENCE_SUPPORTED_ENCRYPTION)
|
||||||
{
|
{
|
||||||
// try to ask for a password
|
OUString sPassword;
|
||||||
try
|
// 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
|
||||||
{
|
{
|
||||||
SfxPasswordDialog aPasswdDlg(pParent);
|
// ok, ask the user for a password
|
||||||
aPasswdDlg.SetMinLen(1);
|
try
|
||||||
if (!aPasswdDlg.run())
|
{
|
||||||
|
SfxPasswordDialog aPasswdDlg(pParent);
|
||||||
|
aPasswdDlg.SetMinLen(1);
|
||||||
|
if (!aPasswdDlg.run())
|
||||||
|
return false;
|
||||||
|
OUString aPasswd = aPasswdDlg.GetPassword();
|
||||||
|
aUtf8Passwd = OUStringToOString(aPasswd, RTL_TEXTENCODING_UTF8);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
OUString aPasswd = aPasswdDlg.GetPassword();
|
}
|
||||||
aUtf8Passwd = OUStringToOString(aPasswd, RTL_TEXTENCODING_UTF8);
|
|
||||||
}
|
|
||||||
catch (...)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return libwps::WPS_OK
|
return libwps::WPS_OK
|
||||||
|
@@ -31,7 +31,8 @@ static bool handleEmbeddedWKSObject(const librevenge::RVNGBinaryData& data,
|
|||||||
|
|
||||||
bool MSWorksImportFilter::doImportDocument(weld::Window* pParent,
|
bool MSWorksImportFilter::doImportDocument(weld::Window* pParent,
|
||||||
librevenge::RVNGInputStream& rInput,
|
librevenge::RVNGInputStream& rInput,
|
||||||
OdtGenerator& rGenerator, utl::MediaDescriptor&)
|
OdtGenerator& rGenerator,
|
||||||
|
utl::MediaDescriptor& mediaDescriptor)
|
||||||
{
|
{
|
||||||
libwps::WPSKind kind = libwps::WPS_TEXT;
|
libwps::WPSKind kind = libwps::WPS_TEXT;
|
||||||
libwps::WPSCreator creator;
|
libwps::WPSCreator creator;
|
||||||
@@ -40,12 +41,17 @@ bool MSWorksImportFilter::doImportDocument(weld::Window* pParent,
|
|||||||
= libwps::WPSDocument::isFileFormatSupported(&rInput, kind, creator, needEncoding);
|
= libwps::WPSDocument::isFileFormatSupported(&rInput, kind, creator, needEncoding);
|
||||||
|
|
||||||
std::string fileEncoding;
|
std::string fileEncoding;
|
||||||
try
|
if ((kind == libwps::WPS_TEXT) && (confidence == libwps::WPS_CONFIDENCE_EXCELLENT)
|
||||||
|
&& needEncoding)
|
||||||
{
|
{
|
||||||
if ((kind == libwps::WPS_TEXT) && (confidence == libwps::WPS_CONFIDENCE_EXCELLENT)
|
OUString encoding;
|
||||||
&& needEncoding)
|
// 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, encoding;
|
OUString title;
|
||||||
|
|
||||||
switch (creator)
|
switch (creator)
|
||||||
{
|
{
|
||||||
@@ -67,21 +73,25 @@ bool MSWorksImportFilter::doImportDocument(weld::Window* pParent,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
writerperfect::WPFTEncodingDialog aDlg(pParent, title, encoding);
|
fileEncoding = encoding.toUtf8().getStr(); // set default to the proposed encoding
|
||||||
if (aDlg.run() == RET_OK)
|
try
|
||||||
{
|
{
|
||||||
if (!aDlg.GetEncoding().isEmpty())
|
writerperfect::WPFTEncodingDialog aDlg(pParent, title, encoding);
|
||||||
fileEncoding = aDlg.GetEncoding().toUtf8().getStr();
|
if (aDlg.run() == RET_OK)
|
||||||
|
{
|
||||||
|
if (!aDlg.GetEncoding().isEmpty())
|
||||||
|
fileEncoding = aDlg.GetEncoding().toUtf8().getStr();
|
||||||
|
}
|
||||||
|
// we can fail because we are in headless mode, the user has cancelled conversion, ...
|
||||||
|
else if (aDlg.hasUserCalledCancel())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (css::uno::Exception&)
|
||||||
|
{
|
||||||
|
TOOLS_WARN_EXCEPTION("writerperfect", "ignoring");
|
||||||
}
|
}
|
||||||
// we can fail because we are in headless mode, the user has cancelled conversion, ...
|
|
||||||
else if (aDlg.hasUserCalledCancel())
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (css::uno::Exception&)
|
|
||||||
{
|
|
||||||
TOOLS_WARN_EXCEPTION("writerperfect", "ignoring");
|
|
||||||
}
|
|
||||||
return libwps::WPS_OK
|
return libwps::WPS_OK
|
||||||
== libwps::WPSDocument::parse(&rInput, &rGenerator, "", fileEncoding.c_str());
|
== libwps::WPSDocument::parse(&rInput, &rGenerator, "", fileEncoding.c_str());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user