1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b3f79822SAndrew Rist * distributed with this work for additional information
6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10*b3f79822SAndrew Rist *
11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist *
13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17*b3f79822SAndrew Rist * specific language governing permissions and limitations
18*b3f79822SAndrew Rist * under the License.
19*b3f79822SAndrew Rist *
20*b3f79822SAndrew Rist *************************************************************/
21*b3f79822SAndrew Rist
22*b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
30cdf0e10cSrcweir #include <tools/urlobj.hxx>
31cdf0e10cSrcweir #include <vcl/msgbox.hxx>
32cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include "editutil.hxx"
35cdf0e10cSrcweir #include "filtuno.hxx"
36cdf0e10cSrcweir #include "miscuno.hxx"
37cdf0e10cSrcweir #include "unoguard.hxx"
38cdf0e10cSrcweir #include "scdll.hxx"
39cdf0e10cSrcweir #include "imoptdlg.hxx"
40cdf0e10cSrcweir #include "asciiopt.hxx"
41cdf0e10cSrcweir #include "docsh.hxx"
42cdf0e10cSrcweir #include "globstr.hrc"
43cdf0e10cSrcweir
44cdf0e10cSrcweir
45cdf0e10cSrcweir #include "sc.hrc" //CHINA001
46cdf0e10cSrcweir #include "scabstdlg.hxx" //CHINA001
47cdf0e10cSrcweir #include "i18npool/lang.h"
48cdf0e10cSrcweir
49cdf0e10cSrcweir #include <memory>
50cdf0e10cSrcweir
51cdf0e10cSrcweir using namespace ::com::sun::star;
52cdf0e10cSrcweir using ::rtl::OUStringBuffer;
53cdf0e10cSrcweir
54cdf0e10cSrcweir //------------------------------------------------------------------------
55cdf0e10cSrcweir
56cdf0e10cSrcweir #define SCFILTEROPTIONSOBJ_SERVICE "com.sun.star.ui.dialogs.FilterOptionsDialog"
57cdf0e10cSrcweir #define SCFILTEROPTIONSOBJ_IMPLNAME "com.sun.star.comp.Calc.FilterOptionsDialog"
58cdf0e10cSrcweir
SC_SIMPLE_SERVICE_INFO(ScFilterOptionsObj,SCFILTEROPTIONSOBJ_IMPLNAME,SCFILTEROPTIONSOBJ_SERVICE)59cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScFilterOptionsObj, SCFILTEROPTIONSOBJ_IMPLNAME, SCFILTEROPTIONSOBJ_SERVICE )
60cdf0e10cSrcweir
61cdf0e10cSrcweir #define SC_UNONAME_FILENAME "URL"
62cdf0e10cSrcweir #define SC_UNONAME_FILTERNAME "FilterName"
63cdf0e10cSrcweir #define SC_UNONAME_FILTEROPTIONS "FilterOptions"
64cdf0e10cSrcweir #define SC_UNONAME_INPUTSTREAM "InputStream"
65cdf0e10cSrcweir
66cdf0e10cSrcweir //------------------------------------------------------------------------
67cdf0e10cSrcweir
68cdf0e10cSrcweir ScFilterOptionsObj::ScFilterOptionsObj() :
69cdf0e10cSrcweir bExport( sal_False )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir }
72cdf0e10cSrcweir
~ScFilterOptionsObj()73cdf0e10cSrcweir ScFilterOptionsObj::~ScFilterOptionsObj()
74cdf0e10cSrcweir {
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
77cdf0e10cSrcweir // stuff for exService_...
78cdf0e10cSrcweir
ScFilterOptionsObj_CreateInstance(const uno::Reference<lang::XMultiServiceFactory> &)79cdf0e10cSrcweir uno::Reference<uno::XInterface> SAL_CALL ScFilterOptionsObj_CreateInstance(
80cdf0e10cSrcweir const uno::Reference<lang::XMultiServiceFactory>& )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir ScUnoGuard aGuard;
83cdf0e10cSrcweir ScDLL::Init();
84cdf0e10cSrcweir return (::cppu::OWeakObject*) new ScFilterOptionsObj;
85cdf0e10cSrcweir }
86cdf0e10cSrcweir
getImplementationName_Static()87cdf0e10cSrcweir rtl::OUString ScFilterOptionsObj::getImplementationName_Static()
88cdf0e10cSrcweir {
89cdf0e10cSrcweir return rtl::OUString::createFromAscii( SCFILTEROPTIONSOBJ_IMPLNAME );
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
getSupportedServiceNames_Static()92cdf0e10cSrcweir uno::Sequence<rtl::OUString> ScFilterOptionsObj::getSupportedServiceNames_Static()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir uno::Sequence<rtl::OUString> aRet(1);
95cdf0e10cSrcweir rtl::OUString* pArray = aRet.getArray();
96cdf0e10cSrcweir pArray[0] = rtl::OUString::createFromAscii( SCFILTEROPTIONSOBJ_SERVICE );
97cdf0e10cSrcweir return aRet;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
100cdf0e10cSrcweir // XPropertyAccess
101cdf0e10cSrcweir
getPropertyValues()102cdf0e10cSrcweir uno::Sequence<beans::PropertyValue> SAL_CALL ScFilterOptionsObj::getPropertyValues() throw(uno::RuntimeException)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir uno::Sequence<beans::PropertyValue> aRet(1);
105cdf0e10cSrcweir beans::PropertyValue* pArray = aRet.getArray();
106cdf0e10cSrcweir
107cdf0e10cSrcweir pArray[0].Name = rtl::OUString::createFromAscii( SC_UNONAME_FILTEROPTIONS );
108cdf0e10cSrcweir pArray[0].Value <<= aFilterOptions;
109cdf0e10cSrcweir
110cdf0e10cSrcweir return aRet;
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
setPropertyValues(const uno::Sequence<beans::PropertyValue> & aProps)113cdf0e10cSrcweir void SAL_CALL ScFilterOptionsObj::setPropertyValues( const uno::Sequence<beans::PropertyValue>& aProps )
114cdf0e10cSrcweir throw(beans::UnknownPropertyException, beans::PropertyVetoException,
115cdf0e10cSrcweir lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
116cdf0e10cSrcweir {
117cdf0e10cSrcweir const beans::PropertyValue* pPropArray = aProps.getConstArray();
118cdf0e10cSrcweir long nPropCount = aProps.getLength();
119cdf0e10cSrcweir for (long i = 0; i < nPropCount; i++)
120cdf0e10cSrcweir {
121cdf0e10cSrcweir const beans::PropertyValue& rProp = pPropArray[i];
122cdf0e10cSrcweir String aPropName(rProp.Name);
123cdf0e10cSrcweir
124cdf0e10cSrcweir if ( aPropName.EqualsAscii( SC_UNONAME_FILENAME ) )
125cdf0e10cSrcweir rProp.Value >>= aFileName;
126cdf0e10cSrcweir else if ( aPropName.EqualsAscii( SC_UNONAME_FILTERNAME ) )
127cdf0e10cSrcweir rProp.Value >>= aFilterName;
128cdf0e10cSrcweir else if ( aPropName.EqualsAscii( SC_UNONAME_FILTEROPTIONS ) )
129cdf0e10cSrcweir rProp.Value >>= aFilterOptions;
130cdf0e10cSrcweir else if ( aPropName.EqualsAscii( SC_UNONAME_INPUTSTREAM ) )
131cdf0e10cSrcweir rProp.Value >>= xInputStream;
132cdf0e10cSrcweir }
133cdf0e10cSrcweir }
134cdf0e10cSrcweir
135cdf0e10cSrcweir // XExecutableDialog
136cdf0e10cSrcweir
setTitle(const::rtl::OUString &)137cdf0e10cSrcweir void SAL_CALL ScFilterOptionsObj::setTitle( const ::rtl::OUString& /* aTitle */ ) throw(uno::RuntimeException)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir // not used
140cdf0e10cSrcweir }
141cdf0e10cSrcweir
execute()142cdf0e10cSrcweir sal_Int16 SAL_CALL ScFilterOptionsObj::execute() throw(uno::RuntimeException)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
145cdf0e10cSrcweir
146cdf0e10cSrcweir String aFilterString( aFilterName );
147cdf0e10cSrcweir
148cdf0e10cSrcweir ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
149cdf0e10cSrcweir DBG_ASSERT(pFact, "ScAbstractFactory create fail!");
150cdf0e10cSrcweir
151cdf0e10cSrcweir if ( !bExport && aFilterString == ScDocShell::GetAsciiFilterName() )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir // ascii import is special...
154cdf0e10cSrcweir
155cdf0e10cSrcweir INetURLObject aURL( aFileName );
156cdf0e10cSrcweir String aExt(aURL.getExtension());
157cdf0e10cSrcweir String aPrivDatName(aURL.getName());
158cdf0e10cSrcweir sal_Unicode cAsciiDel;
159cdf0e10cSrcweir if (aExt.EqualsIgnoreCaseAscii("CSV"))
160cdf0e10cSrcweir cAsciiDel = ',';
161cdf0e10cSrcweir else
162cdf0e10cSrcweir cAsciiDel = '\t';
163cdf0e10cSrcweir
164cdf0e10cSrcweir SvStream* pInStream = NULL;
165cdf0e10cSrcweir if ( xInputStream.is() )
166cdf0e10cSrcweir pInStream = utl::UcbStreamHelper::CreateStream( xInputStream );
167cdf0e10cSrcweir
168cdf0e10cSrcweir //CHINA001 ScImportAsciiDlg* pDlg = new ScImportAsciiDlg( NULL, aPrivDatName, pInStream, cAsciiDel );
169cdf0e10cSrcweir AbstractScImportAsciiDlg* pDlg = pFact->CreateScImportAsciiDlg( NULL, aPrivDatName, pInStream, RID_SCDLG_ASCII, cAsciiDel);
170cdf0e10cSrcweir DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
171cdf0e10cSrcweir if ( pDlg->Execute() == RET_OK )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir ScAsciiOptions aOptions;
174cdf0e10cSrcweir pDlg->GetOptions( aOptions );
175cdf0e10cSrcweir pDlg->SaveParameters();
176cdf0e10cSrcweir aFilterOptions = aOptions.WriteToString();
177cdf0e10cSrcweir nRet = ui::dialogs::ExecutableDialogResults::OK;
178cdf0e10cSrcweir }
179cdf0e10cSrcweir delete pDlg;
180cdf0e10cSrcweir delete pInStream;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir else if ( aFilterString == ScDocShell::GetWebQueryFilterName() || aFilterString == ScDocShell::GetHtmlFilterName() )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir if (bExport)
185cdf0e10cSrcweir nRet = ui::dialogs::ExecutableDialogResults::OK; // export HTML without dialog
186cdf0e10cSrcweir else
187cdf0e10cSrcweir {
188cdf0e10cSrcweir // HTML import.
189cdf0e10cSrcweir ::std::auto_ptr<AbstractScTextImportOptionsDlg> pDlg(
190cdf0e10cSrcweir pFact->CreateScTextImportOptionsDlg(NULL, RID_SCDLG_TEXT_IMPORT_OPTIONS));
191cdf0e10cSrcweir
192cdf0e10cSrcweir if (pDlg->Execute() == RET_OK)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir LanguageType eLang = pDlg->GetLanguageType();
195cdf0e10cSrcweir OUStringBuffer aBuf;
196cdf0e10cSrcweir
197cdf0e10cSrcweir aBuf.append(String::CreateFromInt32(static_cast<sal_Int32>(eLang)));
198cdf0e10cSrcweir aBuf.append(sal_Unicode(' '));
199cdf0e10cSrcweir aBuf.append(pDlg->IsDateConversionSet() ? sal_Unicode('1') : sal_Unicode('0'));
200cdf0e10cSrcweir aFilterOptions = aBuf.makeStringAndClear();
201cdf0e10cSrcweir nRet = ui::dialogs::ExecutableDialogResults::OK;
202cdf0e10cSrcweir }
203cdf0e10cSrcweir }
204cdf0e10cSrcweir }
205cdf0e10cSrcweir else
206cdf0e10cSrcweir {
207cdf0e10cSrcweir sal_Bool bMultiByte = sal_True;
208cdf0e10cSrcweir sal_Bool bDBEnc = sal_False;
209cdf0e10cSrcweir sal_Bool bAscii = sal_False;
210cdf0e10cSrcweir
211cdf0e10cSrcweir sal_Unicode cStrDel = '"';
212cdf0e10cSrcweir sal_Unicode cAsciiDel = ';';
213cdf0e10cSrcweir rtl_TextEncoding eEncoding = RTL_TEXTENCODING_DONTKNOW;
214cdf0e10cSrcweir
215cdf0e10cSrcweir String aTitle;
216cdf0e10cSrcweir
217cdf0e10cSrcweir if ( aFilterString == ScDocShell::GetAsciiFilterName() )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir // ascii export (import is handled above)
220cdf0e10cSrcweir
221cdf0e10cSrcweir INetURLObject aURL( aFileName );
222cdf0e10cSrcweir String aExt(aURL.getExtension());
223cdf0e10cSrcweir if (aExt.EqualsIgnoreCaseAscii("CSV"))
224cdf0e10cSrcweir cAsciiDel = ',';
225cdf0e10cSrcweir else
226cdf0e10cSrcweir cAsciiDel = '\t';
227cdf0e10cSrcweir
228cdf0e10cSrcweir aTitle = ScGlobal::GetRscString( STR_EXPORT_ASCII );
229cdf0e10cSrcweir bAscii = sal_True;
230cdf0e10cSrcweir }
231cdf0e10cSrcweir else if ( aFilterString == ScDocShell::GetLotusFilterName() )
232cdf0e10cSrcweir {
233cdf0e10cSrcweir // lotus is only imported
234cdf0e10cSrcweir DBG_ASSERT( !bExport, "Filter Options for Lotus Export is not implemented" );
235cdf0e10cSrcweir
236cdf0e10cSrcweir aTitle = ScGlobal::GetRscString( STR_IMPORT_LOTUS );
237cdf0e10cSrcweir eEncoding = RTL_TEXTENCODING_IBM_437;
238cdf0e10cSrcweir }
239cdf0e10cSrcweir else if ( aFilterString == ScDocShell::GetDBaseFilterName() )
240cdf0e10cSrcweir {
241cdf0e10cSrcweir if ( bExport )
242cdf0e10cSrcweir {
243cdf0e10cSrcweir // dBase export
244cdf0e10cSrcweir aTitle = ScGlobal::GetRscString( STR_EXPORT_DBF );
245cdf0e10cSrcweir }
246cdf0e10cSrcweir else
247cdf0e10cSrcweir {
248cdf0e10cSrcweir // dBase import
249cdf0e10cSrcweir aTitle = ScGlobal::GetRscString( STR_IMPORT_DBF );
250cdf0e10cSrcweir }
251cdf0e10cSrcweir // common for dBase import/export
252cdf0e10cSrcweir eEncoding = RTL_TEXTENCODING_IBM_850;
253cdf0e10cSrcweir bDBEnc = sal_True;
254cdf0e10cSrcweir }
255cdf0e10cSrcweir else if ( aFilterString == ScDocShell::GetDifFilterName() )
256cdf0e10cSrcweir {
257cdf0e10cSrcweir if ( bExport )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir // DIF export
260cdf0e10cSrcweir aTitle = ScGlobal::GetRscString( STR_EXPORT_DIF );
261cdf0e10cSrcweir }
262cdf0e10cSrcweir else
263cdf0e10cSrcweir {
264cdf0e10cSrcweir // DIF import
265cdf0e10cSrcweir aTitle = ScGlobal::GetRscString( STR_IMPORT_DIF );
266cdf0e10cSrcweir }
267cdf0e10cSrcweir // common for DIF import/export
268cdf0e10cSrcweir eEncoding = RTL_TEXTENCODING_MS_1252;
269cdf0e10cSrcweir }
270cdf0e10cSrcweir
271cdf0e10cSrcweir ScImportOptions aOptions( cAsciiDel, cStrDel, eEncoding);
272cdf0e10cSrcweir //CHINA001 ScImportOptionsDlg* pDlg = new ScImportOptionsDlg( NULL, bAscii,
273cdf0e10cSrcweir //CHINA001 &aOptions, &aTitle, bMultiByte, bDBEnc,
274cdf0e10cSrcweir //CHINA001 !bExport );
275cdf0e10cSrcweir //CHINA001
276cdf0e10cSrcweir
277cdf0e10cSrcweir AbstractScImportOptionsDlg* pDlg = pFact->CreateScImportOptionsDlg( NULL, RID_SCDLG_IMPORTOPT,
278cdf0e10cSrcweir bAscii, &aOptions, &aTitle, bMultiByte, bDBEnc,
279cdf0e10cSrcweir !bExport);
280cdf0e10cSrcweir DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
281cdf0e10cSrcweir if ( pDlg->Execute() == RET_OK )
282cdf0e10cSrcweir {
283cdf0e10cSrcweir pDlg->GetImportOptions( aOptions );
284cdf0e10cSrcweir if ( bAscii )
285cdf0e10cSrcweir aFilterOptions = aOptions.BuildString();
286cdf0e10cSrcweir else
287cdf0e10cSrcweir aFilterOptions = aOptions.aStrFont;
288cdf0e10cSrcweir nRet = ui::dialogs::ExecutableDialogResults::OK;
289cdf0e10cSrcweir }
290cdf0e10cSrcweir delete pDlg;
291cdf0e10cSrcweir }
292cdf0e10cSrcweir
293cdf0e10cSrcweir xInputStream.clear(); // don't hold the stream longer than necessary
294cdf0e10cSrcweir
295cdf0e10cSrcweir return nRet;
296cdf0e10cSrcweir }
297cdf0e10cSrcweir
298cdf0e10cSrcweir // XImporter
299cdf0e10cSrcweir
setTargetDocument(const uno::Reference<lang::XComponent> &)300cdf0e10cSrcweir void SAL_CALL ScFilterOptionsObj::setTargetDocument( const uno::Reference<lang::XComponent>& /* xDoc */ )
301cdf0e10cSrcweir throw(lang::IllegalArgumentException, uno::RuntimeException)
302cdf0e10cSrcweir {
303cdf0e10cSrcweir bExport = sal_False;
304cdf0e10cSrcweir }
305cdf0e10cSrcweir
306cdf0e10cSrcweir // XExporter
307cdf0e10cSrcweir
setSourceDocument(const uno::Reference<lang::XComponent> &)308cdf0e10cSrcweir void SAL_CALL ScFilterOptionsObj::setSourceDocument( const uno::Reference<lang::XComponent>& /* xDoc */ )
309cdf0e10cSrcweir throw(lang::IllegalArgumentException, uno::RuntimeException)
310cdf0e10cSrcweir {
311cdf0e10cSrcweir bExport = sal_True;
312cdf0e10cSrcweir }
313cdf0e10cSrcweir
314