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:
parent
d681cca399
commit
f14cd1ad62
@ -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,70 +192,88 @@ bool MSWorksCalcImportFilter::doImportDocument(weld::Window* pParent,
|
||||
std::string fileEncoding;
|
||||
if (needEncoding)
|
||||
{
|
||||
OUString title, encoding;
|
||||
switch (creator)
|
||||
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
|
||||
{
|
||||
case libwps::WPS_MSWORKS:
|
||||
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;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
writerperfect::WPFTEncodingDialog aDlg(pParent, title, encoding);
|
||||
if (aDlg.run() == RET_OK)
|
||||
OUString title;
|
||||
switch (creator)
|
||||
{
|
||||
if (!aDlg.GetEncoding().isEmpty())
|
||||
fileEncoding = aDlg.GetEncoding().toUtf8().getStr();
|
||||
case libwps::WPS_MSWORKS:
|
||||
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;
|
||||
if (confidence == libwps::WPS_CONFIDENCE_SUPPORTED_ENCRYPTION)
|
||||
{
|
||||
// try to ask for a password
|
||||
try
|
||||
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
|
||||
{
|
||||
SfxPasswordDialog aPasswdDlg(pParent);
|
||||
aPasswdDlg.SetMinLen(1);
|
||||
if (!aPasswdDlg.run())
|
||||
// ok, ask the user for a password
|
||||
try
|
||||
{
|
||||
SfxPasswordDialog aPasswdDlg(pParent);
|
||||
aPasswdDlg.SetMinLen(1);
|
||||
if (!aPasswdDlg.run())
|
||||
return false;
|
||||
OUString aPasswd = aPasswdDlg.GetPassword();
|
||||
aUtf8Passwd = OUStringToOString(aPasswd, RTL_TEXTENCODING_UTF8);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return false;
|
||||
OUString aPasswd = aPasswdDlg.GetPassword();
|
||||
aUtf8Passwd = OUStringToOString(aPasswd, RTL_TEXTENCODING_UTF8);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return libwps::WPS_OK
|
||||
|
@ -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)
|
||||
{
|
||||
if ((kind == libwps::WPS_TEXT) && (confidence == libwps::WPS_CONFIDENCE_EXCELLENT)
|
||||
&& needEncoding)
|
||||
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, encoding;
|
||||
OUString title;
|
||||
|
||||
switch (creator)
|
||||
{
|
||||
@ -67,21 +73,25 @@ bool MSWorksImportFilter::doImportDocument(weld::Window* pParent,
|
||||
break;
|
||||
}
|
||||
|
||||
writerperfect::WPFTEncodingDialog aDlg(pParent, title, encoding);
|
||||
if (aDlg.run() == RET_OK)
|
||||
fileEncoding = encoding.toUtf8().getStr(); // set default to the proposed encoding
|
||||
try
|
||||
{
|
||||
if (!aDlg.GetEncoding().isEmpty())
|
||||
fileEncoding = aDlg.GetEncoding().toUtf8().getStr();
|
||||
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 (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
|
||||
== libwps::WPSDocument::parse(&rInput, &rGenerator, "", fileEncoding.c_str());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user