LCOV - code coverage report
Current view: top level - sc/source/ui/unoobj - filtuno.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 147 0.0 %
Date: 2014-04-14 Functions: 0 19 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      21             : #include <tools/urlobj.hxx>
      22             : #include <vcl/msgbox.hxx>
      23             : #include <vcl/svapp.hxx>
      24             : #include <unotools/ucbstreamhelper.hxx>
      25             : 
      26             : #include "editutil.hxx"
      27             : #include "filtuno.hxx"
      28             : #include "miscuno.hxx"
      29             : #include "scdll.hxx"
      30             : #include "imoptdlg.hxx"
      31             : #include "asciiopt.hxx"
      32             : #include "docsh.hxx"
      33             : #include "globstr.hrc"
      34             : 
      35             : 
      36             : #include "sc.hrc"
      37             : #include "scabstdlg.hxx"
      38             : #include "i18nlangtag/lang.h"
      39             : 
      40             : #include <optutil.hxx>
      41             : #include <com/sun/star/uno/Any.hxx>
      42             : #include <com/sun/star/uno/Sequence.hxx>
      43             : 
      44             : 
      45             : using namespace ::com::sun::star;
      46             : using namespace rtl;
      47             : using namespace com::sun::star::uno;
      48             : 
      49             : #define SCFILTEROPTIONSOBJ_SERVICE      "com.sun.star.ui.dialogs.FilterOptionsDialog"
      50             : #define SCFILTEROPTIONSOBJ_IMPLNAME     "com.sun.star.comp.Calc.FilterOptionsDialog"
      51             : 
      52           0 : SC_SIMPLE_SERVICE_INFO( ScFilterOptionsObj, SCFILTEROPTIONSOBJ_IMPLNAME, SCFILTEROPTIONSOBJ_SERVICE )
      53             : 
      54             : #define SC_UNONAME_FILENAME         "URL"
      55             : #define SC_UNONAME_FILTERNAME       "FilterName"
      56             : #define SC_UNONAME_FILTEROPTIONS    "FilterOptions"
      57             : #define SC_UNONAME_INPUTSTREAM      "InputStream"
      58             : 
      59             : 
      60             : #define DBF_CHAR_SET                "CharSet"
      61             : #define DBF_SEP_PATH_IMPORT         "Office.Calc/Dialogs/DBFImport"
      62             : #define DBF_SEP_PATH_EXPORT         "Office.Calc/Dialogs/DBFExport"
      63             : 
      64           0 : static void load_CharSet( rtl_TextEncoding &nCharSet, bool bExport )
      65             : {
      66           0 :     Sequence<Any> aValues;
      67             :     const Any *pProperties;
      68           0 :     Sequence<OUString> aNames(1);
      69           0 :     OUString* pNames = aNames.getArray();
      70             :     ScLinkConfigItem aItem( OUString::createFromAscii(
      71           0 :                                 bExport?DBF_SEP_PATH_EXPORT:DBF_SEP_PATH_IMPORT ) );
      72             : 
      73           0 :     pNames[0] = OUString::createFromAscii( DBF_CHAR_SET );
      74           0 :     aValues = aItem.GetProperties( aNames );
      75           0 :     pProperties = aValues.getConstArray();
      76             : 
      77             :     // Default choice
      78           0 :     nCharSet = RTL_TEXTENCODING_IBM_850;
      79             : 
      80           0 :     if( pProperties[0].hasValue() )
      81             :     {
      82           0 :         sal_Int32 nChar = 0;
      83           0 :         pProperties[0] >>= nChar;
      84           0 :         if( nChar >= 0)
      85             :         {
      86           0 :             nCharSet = (rtl_TextEncoding) nChar;
      87             :         }
      88           0 :     }
      89           0 : }
      90             : 
      91           0 : static void save_CharSet( rtl_TextEncoding nCharSet, bool bExport )
      92             : {
      93           0 :     Sequence<Any> aValues;
      94             :     Any *pProperties;
      95           0 :     Sequence<OUString> aNames(1);
      96           0 :     OUString* pNames = aNames.getArray();
      97             :     ScLinkConfigItem aItem( OUString::createFromAscii(
      98           0 :                                 bExport?DBF_SEP_PATH_EXPORT:DBF_SEP_PATH_IMPORT ) );
      99             : 
     100           0 :     pNames[0] = OUString::createFromAscii( DBF_CHAR_SET );
     101           0 :     aValues = aItem.GetProperties( aNames );
     102           0 :     pProperties = aValues.getArray();
     103           0 :     pProperties[0] <<= (sal_Int32) nCharSet;
     104             : 
     105           0 :     aItem.PutProperties(aNames, aValues);
     106           0 : }
     107             : 
     108           0 : ScFilterOptionsObj::ScFilterOptionsObj() :
     109           0 :     bExport( false )
     110             : {
     111           0 : }
     112             : 
     113           0 : ScFilterOptionsObj::~ScFilterOptionsObj()
     114             : {
     115           0 : }
     116             : 
     117             : // stuff for exService_...
     118             : 
     119           0 : uno::Reference<uno::XInterface> SAL_CALL ScFilterOptionsObj_CreateInstance(
     120             :                         const uno::Reference<lang::XMultiServiceFactory>& )
     121             : {
     122           0 :     SolarMutexGuard aGuard;
     123           0 :     ScDLL::Init();
     124           0 :     return (::cppu::OWeakObject*) new ScFilterOptionsObj;
     125             : }
     126             : 
     127           0 : OUString ScFilterOptionsObj::getImplementationName_Static()
     128             : {
     129           0 :     return OUString( SCFILTEROPTIONSOBJ_IMPLNAME );
     130             : }
     131             : 
     132           0 : uno::Sequence<OUString> ScFilterOptionsObj::getSupportedServiceNames_Static()
     133             : {
     134           0 :     uno::Sequence<OUString> aRet(1);
     135           0 :     OUString* pArray = aRet.getArray();
     136           0 :     pArray[0] = OUString( SCFILTEROPTIONSOBJ_SERVICE );
     137           0 :     return aRet;
     138             : }
     139             : 
     140             : // XPropertyAccess
     141             : 
     142           0 : uno::Sequence<beans::PropertyValue> SAL_CALL ScFilterOptionsObj::getPropertyValues() throw(uno::RuntimeException, std::exception)
     143             : {
     144           0 :     uno::Sequence<beans::PropertyValue> aRet(1);
     145           0 :     beans::PropertyValue* pArray = aRet.getArray();
     146             : 
     147           0 :     pArray[0].Name = OUString( SC_UNONAME_FILTEROPTIONS );
     148           0 :     pArray[0].Value <<= aFilterOptions;
     149             : 
     150           0 :     return aRet;
     151             : }
     152             : 
     153           0 : void SAL_CALL ScFilterOptionsObj::setPropertyValues( const uno::Sequence<beans::PropertyValue>& aProps )
     154             :                     throw(beans::UnknownPropertyException, beans::PropertyVetoException,
     155             :                             lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     156             : {
     157           0 :     const beans::PropertyValue* pPropArray = aProps.getConstArray();
     158           0 :     long nPropCount = aProps.getLength();
     159           0 :     for (long i = 0; i < nPropCount; i++)
     160             :     {
     161           0 :         const beans::PropertyValue& rProp = pPropArray[i];
     162           0 :         OUString aPropName(rProp.Name);
     163             : 
     164           0 :         if ( aPropName.equalsAscii( SC_UNONAME_FILENAME ) )
     165           0 :             rProp.Value >>= aFileName;
     166           0 :         else if ( aPropName.equalsAscii( SC_UNONAME_FILTERNAME ) )
     167           0 :             rProp.Value >>= aFilterName;
     168           0 :         else if ( aPropName.equalsAscii( SC_UNONAME_FILTEROPTIONS ) )
     169           0 :             rProp.Value >>= aFilterOptions;
     170           0 :         else if ( aPropName.equalsAscii( SC_UNONAME_INPUTSTREAM ) )
     171           0 :             rProp.Value >>= xInputStream;
     172           0 :     }
     173           0 : }
     174             : 
     175             : // XExecutableDialog
     176             : 
     177           0 : void SAL_CALL ScFilterOptionsObj::setTitle( const OUString& /* aTitle */ ) throw(uno::RuntimeException, std::exception)
     178             : {
     179             :     // not used
     180           0 : }
     181             : 
     182           0 : sal_Int16 SAL_CALL ScFilterOptionsObj::execute() throw(uno::RuntimeException, std::exception)
     183             : {
     184           0 :     sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
     185             : 
     186           0 :     OUString aFilterString( aFilterName );
     187             : 
     188           0 :     ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
     189             :     OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
     190             : 
     191           0 :     if ( !bExport && aFilterString == ScDocShell::GetAsciiFilterName() )
     192             :     {
     193             :         //  ascii import is special...
     194             : 
     195           0 :         INetURLObject aURL( aFileName );
     196           0 :         OUString aPrivDatName(aURL.getName());
     197           0 :         SvStream* pInStream = NULL;
     198           0 :         if ( xInputStream.is() )
     199           0 :             pInStream = utl::UcbStreamHelper::CreateStream( xInputStream );
     200             : 
     201           0 :         AbstractScImportAsciiDlg* pDlg = pFact->CreateScImportAsciiDlg( NULL, aPrivDatName, pInStream, SC_IMPORTFILE);
     202             :         OSL_ENSURE(pDlg, "Dialog create fail!");
     203           0 :         if ( pDlg->Execute() == RET_OK )
     204             :         {
     205           0 :             ScAsciiOptions aOptions;
     206           0 :             pDlg->GetOptions( aOptions );
     207           0 :             pDlg->SaveParameters();
     208           0 :             aFilterOptions = aOptions.WriteToString();
     209           0 :             nRet = ui::dialogs::ExecutableDialogResults::OK;
     210             :         }
     211           0 :         delete pDlg;
     212           0 :         delete pInStream;
     213             :     }
     214           0 :     else if ( aFilterString == ScDocShell::GetWebQueryFilterName() || aFilterString == ScDocShell::GetHtmlFilterName() )
     215             :     {
     216           0 :         if (bExport)
     217           0 :             nRet = ui::dialogs::ExecutableDialogResults::OK;    // export HTML without dialog
     218             :         else
     219             :         {
     220             :             // HTML import.
     221             :             boost::scoped_ptr<AbstractScTextImportOptionsDlg> pDlg(
     222           0 :                 pFact->CreateScTextImportOptionsDlg(NULL));
     223             : 
     224           0 :             if (pDlg->Execute() == RET_OK)
     225             :             {
     226           0 :                 LanguageType eLang = pDlg->GetLanguageType();
     227           0 :                 OUStringBuffer aBuf;
     228             : 
     229           0 :                 aBuf.append(OUString::number(static_cast<sal_Int32>(eLang)));
     230           0 :                 aBuf.append(' ');
     231           0 :                 aBuf.append(pDlg->IsDateConversionSet() ? sal_Unicode('1') : sal_Unicode('0'));
     232           0 :                 aFilterOptions = aBuf.makeStringAndClear();
     233           0 :                 nRet = ui::dialogs::ExecutableDialogResults::OK;
     234           0 :             }
     235             :         }
     236             :     }
     237             :     else
     238             :     {
     239           0 :         sal_Bool bMultiByte = sal_True;
     240           0 :         sal_Bool bDBEnc     = false;
     241           0 :         sal_Bool bAscii     = false;
     242             : 
     243           0 :         sal_Unicode cStrDel = '"';
     244           0 :         sal_Unicode cAsciiDel = ';';
     245           0 :         rtl_TextEncoding eEncoding = RTL_TEXTENCODING_DONTKNOW;
     246             : 
     247           0 :         OUString aTitle;
     248             : 
     249           0 :         if ( aFilterString == ScDocShell::GetAsciiFilterName() )
     250             :         {
     251             :             //  ascii export (import is handled above)
     252             : 
     253           0 :             INetURLObject aURL( aFileName );
     254           0 :             OUString aExt(aURL.getExtension());
     255           0 :             if (aExt.equalsIgnoreAsciiCase("CSV"))
     256           0 :                 cAsciiDel = ',';
     257             :             else
     258           0 :                 cAsciiDel = '\t';
     259             : 
     260           0 :             aTitle = ScGlobal::GetRscString( STR_EXPORT_ASCII );
     261           0 :             bAscii = sal_True;
     262             :         }
     263           0 :         else if ( aFilterString == ScDocShell::GetLotusFilterName() )
     264             :         {
     265             :             //  lotus is only imported
     266             :             OSL_ENSURE( !bExport, "Filter Options for Lotus Export is not implemented" );
     267             : 
     268           0 :             aTitle = ScGlobal::GetRscString( STR_IMPORT_LOTUS );
     269           0 :             eEncoding = RTL_TEXTENCODING_IBM_437;
     270             :         }
     271           0 :         else if ( aFilterString == ScDocShell::GetDBaseFilterName() )
     272             :         {
     273           0 :             if ( bExport )
     274             :             {
     275             :                 //  dBase export
     276           0 :                 aTitle = ScGlobal::GetRscString( STR_EXPORT_DBF );
     277             :             }
     278             :             else
     279             :             {
     280             :                 //  dBase import
     281           0 :                 aTitle = ScGlobal::GetRscString( STR_IMPORT_DBF );
     282             :             }
     283           0 :             load_CharSet( eEncoding, bExport );
     284           0 :             bDBEnc = sal_True;
     285             :         }
     286           0 :         else if ( aFilterString == ScDocShell::GetDifFilterName() )
     287             :         {
     288           0 :             if ( bExport )
     289             :             {
     290             :                 //  DIF export
     291           0 :                 aTitle = ScGlobal::GetRscString( STR_EXPORT_DIF );
     292             :             }
     293             :             else
     294             :             {
     295             :                 //  DIF import
     296           0 :                 aTitle = ScGlobal::GetRscString( STR_IMPORT_DIF );
     297             :             }
     298             :             // common for DIF import/export
     299           0 :             eEncoding = RTL_TEXTENCODING_MS_1252;
     300             :         }
     301             : 
     302           0 :         ScImportOptions aOptions( cAsciiDel, cStrDel, eEncoding);
     303             : 
     304             :         AbstractScImportOptionsDlg* pDlg = pFact->CreateScImportOptionsDlg(NULL,
     305             :                                                                             bAscii, &aOptions, &aTitle, bMultiByte, bDBEnc,
     306           0 :                                                                             !bExport);
     307             :         OSL_ENSURE(pDlg, "Dialog create fail!");
     308           0 :         if ( pDlg->Execute() == RET_OK )
     309             :         {
     310           0 :             pDlg->GetImportOptions( aOptions );
     311           0 :             save_CharSet( aOptions.eCharSet, bExport );
     312           0 :             if ( bAscii )
     313           0 :                 aFilterOptions = aOptions.BuildString();
     314             :             else
     315           0 :                 aFilterOptions = aOptions.aStrFont;
     316           0 :             nRet = ui::dialogs::ExecutableDialogResults::OK;
     317             :         }
     318           0 :         delete pDlg;
     319             :     }
     320             : 
     321           0 :     xInputStream.clear();   // don't hold the stream longer than necessary
     322             : 
     323           0 :     return nRet;
     324             : }
     325             : 
     326             : // XImporter
     327             : 
     328           0 : void SAL_CALL ScFilterOptionsObj::setTargetDocument( const uno::Reference<lang::XComponent>& /* xDoc */ )
     329             :                             throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
     330             : {
     331           0 :     bExport = false;
     332           0 : }
     333             : 
     334             : // XExporter
     335             : 
     336           0 : void SAL_CALL ScFilterOptionsObj::setSourceDocument( const uno::Reference<lang::XComponent>& /* xDoc */ )
     337             :                             throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
     338             : {
     339           0 :     bExport = true;
     340           0 : }
     341             : 
     342             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10