LCOV - code coverage report
Current view: top level - writerperfect/source/calc - MSWorksCalcImportFilter.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 37 58 63.8 %
Date: 2015-06-13 12:38:46 Functions: 8 9 88.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* MSWorksCalcImportFilter: Sets up the filter, and calls DocumentCollector
       3             :  * to do the actual filtering
       4             :  *
       5             :  * This file is part of the LibreOffice project.
       6             :  *
       7             :  * This Source Code Form is subject to the terms of the Mozilla Public
       8             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       9             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
      10             :  */
      11             : 
      12             : #include <com/sun/star/uno/Reference.h>
      13             : #include <cppuhelper/supportsservice.hxx>
      14             : 
      15             : #include <libwps/libwps.h>
      16             : 
      17             : #include "WPFTEncodingDialog.hxx"
      18             : #include "MSWorksCalcImportFilter.hxx"
      19             : 
      20             : using com::sun::star::uno::Sequence;
      21             : using com::sun::star::uno::Reference;
      22             : using com::sun::star::uno::Any;
      23             : using com::sun::star::uno::XInterface;
      24             : using com::sun::star::uno::Exception;
      25             : using com::sun::star::uno::RuntimeException;
      26             : using com::sun::star::uno::XComponentContext;
      27             : 
      28           4 : bool MSWorksCalcImportFilter::doImportDocument(librevenge::RVNGInputStream &rInput, OdsGenerator &rGenerator, utl::MediaDescriptor &)
      29             : {
      30           4 :     libwps::WPSKind kind = libwps::WPS_TEXT;
      31             :     libwps::WPSCreator creator;
      32             :     bool needEncoding;
      33           4 :     const libwps::WPSConfidence confidence = libwps::WPSDocument::isFileFormatSupported(&rInput, kind, creator, needEncoding);
      34             : 
      35           4 :     std::string fileEncoding("");
      36           4 :     if ((kind == libwps::WPS_SPREADSHEET || kind == libwps::WPS_DATABASE) && (confidence == libwps::WPS_CONFIDENCE_EXCELLENT) && needEncoding)
      37             :     {
      38           4 :         OUString title, encoding;
      39           2 :         if (creator == libwps::WPS_MSWORKS)
      40             :         {
      41           2 :             title="Import MsWorks files(libwps)";
      42           2 :             encoding="CP850";
      43             :         }
      44           0 :         else if (creator == libwps::WPS_LOTUS)
      45             :         {
      46           0 :             title="Import Lotus files(libwps)";
      47           0 :             encoding="CP437";
      48             :         }
      49           0 :         else if (creator == libwps::WPS_SYMPHONY)
      50             :         {
      51           0 :             title="Import Symphony files(libwps)";
      52           0 :             encoding="CP437";
      53             :         }
      54             :         else
      55             :         {
      56           0 :             title="Import Quattro Pro files(libwps)";
      57           0 :             encoding="CP437";
      58             :         }
      59             :         try
      60             :         {
      61           2 :             const ScopedVclPtrInstance<writerperfect::WPFTEncodingDialog> pDlg(title, encoding);
      62           0 :             if (pDlg->Execute() == RET_OK)
      63             :             {
      64           0 :                 if (!pDlg->GetEncoding().isEmpty())
      65           0 :                     fileEncoding=pDlg->GetEncoding().toUtf8().getStr();
      66             :             }
      67             :             // we can fail because we are in headless mode, the user has cancelled conversion, ...
      68           0 :             else if (pDlg->hasUserCalledCancel())
      69           0 :                 return false;
      70             :         }
      71           2 :         catch (css::uno::Exception &e)
      72             :         {
      73             :             SAL_WARN("writerperfect", "ignoring Exception " << e.Message);
      74           2 :         }
      75             :     }
      76           4 :     return libwps::WPS_OK == libwps::WPSDocument::parse(&rInput, &rGenerator, "", fileEncoding.c_str());
      77             : }
      78             : 
      79         265 : bool MSWorksCalcImportFilter::doDetectFormat(librevenge::RVNGInputStream &rInput, OUString &rTypeName)
      80             : {
      81         265 :     libwps::WPSKind kind = libwps::WPS_TEXT;
      82             :     libwps::WPSCreator creator;
      83             :     bool needEncoding;
      84         265 :     const libwps::WPSConfidence confidence = libwps::WPSDocument::isFileFormatSupported(&rInput, kind, creator, needEncoding);
      85             : 
      86         265 :     if ((kind == libwps::WPS_SPREADSHEET || kind == libwps::WPS_DATABASE) && confidence == libwps::WPS_CONFIDENCE_EXCELLENT)
      87             :     {
      88           4 :         if (creator == libwps::WPS_MSWORKS)
      89             :         {
      90           4 :             rTypeName = "calc_MS_Works_Document";
      91           4 :             return true;
      92             :         }
      93           0 :         if (creator == libwps::WPS_LOTUS || creator == libwps::WPS_SYMPHONY)
      94             :         {
      95           0 :             rTypeName = "calc_WPS_Lotus_Document";
      96           0 :             return true;
      97             :         }
      98           0 :         if (creator == libwps::WPS_QUATTRO_PRO)
      99             :         {
     100           0 :             rTypeName = "calc_WPS_QPro_Document";
     101           0 :             return true;
     102             :         }
     103             :     }
     104             : 
     105         261 :     return false;
     106             : }
     107             : 
     108           4 : void MSWorksCalcImportFilter::doRegisterHandlers(OdsGenerator &)
     109             : {
     110           4 : }
     111             : 
     112          19 : OUString MSWorksCalcImportFilter_getImplementationName()
     113             : throw (RuntimeException)
     114             : {
     115          19 :     return OUString("com.sun.star.comp.Calc.MSWorksCalcImportFilter");
     116             : }
     117             : 
     118           7 : Sequence< OUString > SAL_CALL MSWorksCalcImportFilter_getSupportedServiceNames()
     119             : throw (RuntimeException)
     120             : {
     121           7 :     Sequence < OUString > aRet(2);
     122           7 :     OUString *pArray = aRet.getArray();
     123           7 :     pArray[0] =  "com.sun.star.document.ImportFilter";
     124           7 :     pArray[1] =  "com.sun.star.document.ExtendedTypeDetection";
     125           7 :     return aRet;
     126             : }
     127             : #undef SERVICE_NAME2
     128             : #undef SERVICE_NAME1
     129             : 
     130         263 : Reference< XInterface > SAL_CALL MSWorksCalcImportFilter_createInstance(const Reference< XComponentContext > &rContext)
     131             : throw(Exception)
     132             : {
     133         263 :     return static_cast<cppu::OWeakObject *>(new MSWorksCalcImportFilter(rContext));
     134             : }
     135             : 
     136             : // XServiceInfo
     137           1 : OUString SAL_CALL MSWorksCalcImportFilter::getImplementationName()
     138             : throw (RuntimeException, std::exception)
     139             : {
     140           1 :     return MSWorksCalcImportFilter_getImplementationName();
     141             : }
     142           0 : sal_Bool SAL_CALL MSWorksCalcImportFilter::supportsService(const OUString &rServiceName)
     143             : throw (RuntimeException, std::exception)
     144             : {
     145           0 :     return cppu::supportsService(this, rServiceName);
     146             : }
     147           1 : Sequence< OUString > SAL_CALL MSWorksCalcImportFilter::getSupportedServiceNames()
     148             : throw (RuntimeException, std::exception)
     149             : {
     150           1 :     return MSWorksCalcImportFilter_getSupportedServiceNames();
     151             : }
     152             : 
     153             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11