[Libreoffice-commits] core.git: Branch 'libreoffice-6-4' - writerperfect/source

alonso (via logerrit) logerrit at kemper.freedesktop.org
Mon Jan 20 15:59:56 UTC 2020


 writerperfect/source/calc/MSWorksCalcImportFilter.cxx |  127 ++++++++++--------
 writerperfect/source/writer/MSWorksImportFilter.cxx   |   42 +++--
 2 files changed, 99 insertions(+), 70 deletions(-)

New commits:
commit 5fc07374dc00f1c35839cb3f2b9fb712a88272e6
Author:     alonso <laurent.alonso at inria.fr>
AuthorDate: Wed Nov 13 14:03:53 2019 +0100
Commit:     Xisco Faulí <xiscofauli at libreoffice.org>
CommitDate: Mon Jan 20 16:59:02 2020 +0100

    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 at collabora.co.uk>
    (cherry picked from commit f14cd1ad62e6f17f2a1e56a7d4dfb8fad8d5375e)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87076
    Reviewed-by: Xisco Faulí <xiscofauli at libreoffice.org>

diff --git a/writerperfect/source/calc/MSWorksCalcImportFilter.cxx b/writerperfect/source/calc/MSWorksCalcImportFilter.cxx
index 0ed1903172e1..d001b84a79d5 100644
--- a/writerperfect/source/calc/MSWorksCalcImportFilter.cxx
+++ b/writerperfect/source/calc/MSWorksCalcImportFilter.cxx
@@ -174,7 +174,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;
@@ -188,70 +189,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;
-        }
+            OUString title;
+            switch (creator)
+            {
+                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)
+            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 (...)
+            {
+                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
diff --git a/writerperfect/source/writer/MSWorksImportFilter.cxx b/writerperfect/source/writer/MSWorksImportFilter.cxx
index 61b79d698da1..2adec49cfeba 100644
--- a/writerperfect/source/writer/MSWorksImportFilter.cxx
+++ b/writerperfect/source/writer/MSWorksImportFilter.cxx
@@ -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());
 }


More information about the Libreoffice-commits mailing list