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