Branch data 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 "moduledbu.hxx"
21 : : #include "TextConnectionHelper.hxx"
22 : : #include "sqlmessage.hxx"
23 : : #include "dbu_dlg.hrc"
24 : : #include "dbu_resource.hrc"
25 : : #include "AutoControls.hrc"
26 : : #include <svl/itemset.hxx>
27 : : #include <svl/stritem.hxx>
28 : : #include <svl/eitem.hxx>
29 : : #include <svl/intitem.hxx>
30 : : #include "dsitems.hxx"
31 : : #include "dbfindex.hxx"
32 : : #include "dbaccess_helpid.hrc"
33 : : #include "localresaccess.hxx"
34 : : #include <vcl/msgbox.hxx>
35 : : #include <vcl/mnemonic.hxx>
36 : : #include <svl/cjkoptions.hxx>
37 : : #include <jvmaccess/virtualmachine.hxx>
38 : : #include <connectivity/CommonTools.hxx>
39 : : #include "DriverSettings.hxx"
40 : : #include "dbadmin.hxx"
41 : : #include <comphelper/string.hxx>
42 : : #include <comphelper/types.hxx>
43 : : #include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
44 : : #include <com/sun/star/task/XInteractionHandler.hpp>
45 : : #include <svl/filenotation.hxx>
46 : : #include <unotools/localfilehelper.hxx>
47 : : #include <unotools/ucbhelper.hxx>
48 : : #include <ucbhelper/commandenvironment.hxx>
49 : : #include "finteraction.hxx"
50 : : #include "DBSetupConnectionPages.hxx"
51 : : #include <unotools/pathoptions.hxx>
52 : : #include <svtools/roadmapwizard.hxx>
53 : :
54 : : namespace dbaui
55 : : {
56 : : DBG_NAME(OTextConnectionHelper)
57 : :
58 : 0 : OTextConnectionHelper::OTextConnectionHelper( Window* pParent, const short _nAvailableSections )
59 : : :Control( pParent, WB_DIALOGCONTROL )
60 : : ,m_aFTExtensionHeader (this, ModuleRes(FT_AUTOEXTENSIONHEADER))
61 : : ,m_aRBAccessTextFiles (this, ModuleRes(RB_AUTOACCESSCTEXTFILES))
62 : : ,m_aRBAccessCSVFiles (this, ModuleRes(RB_AUTOACCESSCCSVFILES))
63 : : ,m_aRBAccessOtherFiles (this, ModuleRes(RB_AUTOACCESSOTHERS))
64 : : ,m_aETOwnExtension (this, ModuleRes(ET_AUTOOWNEXTENSION))
65 : : ,m_aFTExtensionExample (this, ModuleRes(FT_AUTOOWNEXTENSIONAPPENDIX))
66 : : ,m_aLineFormat (this, ModuleRes(FL_AUTOSEPARATOR2))
67 : : ,m_aFieldSeparatorLabel (this, ModuleRes(FT_AUTOFIELDSEPARATOR))
68 : : ,m_aFieldSeparator (this, ModuleRes(CM_AUTOFIELDSEPARATOR))
69 : : ,m_aTextSeparatorLabel (this, ModuleRes(FT_AUTOTEXTSEPARATOR))
70 : : ,m_aTextSeparator (this, ModuleRes(CM_AUTOTEXTSEPARATOR))
71 : : ,m_aDecimalSeparatorLabel (this, ModuleRes(FT_AUTODECIMALSEPARATOR))
72 : : ,m_aDecimalSeparator (this, ModuleRes(CM_AUTODECIMALSEPARATOR))
73 : : ,m_aThousandsSeparatorLabel (this, ModuleRes(FT_AUTOTHOUSANDSSEPARATOR))
74 : : ,m_aThousandsSeparator (this, ModuleRes(CM_AUTOTHOUSANDSSEPARATOR))
75 : : ,m_aRowHeader (this, ModuleRes(CB_AUTOHEADER))
76 : : ,m_aCharSetHeader (this, ModuleRes(FL_DATACONVERT))
77 : : ,m_aCharSetLabel (this, ModuleRes(FT_CHARSET))
78 : : ,m_aCharSet (this, ModuleRes(LB_CHARSET))
79 : : ,m_aFieldSeparatorList (ModuleRes(STR_AUTOFIELDSEPARATORLIST))
80 : : ,m_aTextSeparatorList (ModuleRes(STR_AUTOTEXTSEPARATORLIST))
81 : : ,m_aTextNone (ModuleRes(STR_AUTOTEXT_FIELD_SEP_NONE))
82 [ # # ][ # # ]: 0 : ,m_nAvailableSections( _nAvailableSections )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
83 : : {
84 : : DBG_CTOR(OTextConnectionHelper,NULL);
85 : :
86 [ # # ][ # # ]: 0 : xub_StrLen nCnt = comphelper::string::getTokenCount(m_aFieldSeparatorList, '\t');
87 : : xub_StrLen i;
88 : :
89 [ # # ]: 0 : for( i = 0 ; i < nCnt ; i += 2 )
90 [ # # ][ # # ]: 0 : m_aFieldSeparator.InsertEntry( m_aFieldSeparatorList.GetToken( i, '\t' ) );
[ # # ]
91 : :
92 [ # # ][ # # ]: 0 : nCnt = comphelper::string::getTokenCount(m_aTextSeparatorList, '\t');
93 [ # # ]: 0 : for( i=0 ; i<nCnt ; i+=2 )
94 [ # # ][ # # ]: 0 : m_aTextSeparator.InsertEntry( m_aTextSeparatorList.GetToken( i, '\t' ) );
[ # # ]
95 [ # # ]: 0 : m_aTextSeparator.InsertEntry(m_aTextNone);
96 : :
97 : : // set the modify handlers
98 [ # # ]: 0 : m_aFieldSeparator.SetUpdateDataHdl(getControlModifiedLink());
99 [ # # ]: 0 : m_aFieldSeparator.SetSelectHdl(getControlModifiedLink());
100 [ # # ]: 0 : m_aTextSeparator.SetUpdateDataHdl(getControlModifiedLink());
101 [ # # ]: 0 : m_aTextSeparator.SetSelectHdl(getControlModifiedLink());
102 [ # # ]: 0 : m_aCharSet.SetSelectHdl(getControlModifiedLink());
103 : :
104 [ # # ]: 0 : m_aFieldSeparator.SetModifyHdl(getControlModifiedLink());
105 [ # # ]: 0 : m_aTextSeparator.SetModifyHdl(getControlModifiedLink());
106 [ # # ]: 0 : m_aDecimalSeparator.SetModifyHdl(getControlModifiedLink());
107 [ # # ]: 0 : m_aThousandsSeparator.SetModifyHdl(getControlModifiedLink());
108 [ # # ]: 0 : m_aETOwnExtension.SetModifyHdl(LINK(this, OTextConnectionHelper, OnEditModified));
109 [ # # ]: 0 : m_aRBAccessTextFiles.SetToggleHdl(LINK(this, OTextConnectionHelper, OnSetExtensionHdl));
110 [ # # ]: 0 : m_aRBAccessCSVFiles.SetToggleHdl(LINK(this, OTextConnectionHelper, OnSetExtensionHdl));
111 [ # # ]: 0 : m_aRBAccessOtherFiles.SetToggleHdl(LINK(this, OTextConnectionHelper, OnSetExtensionHdl));
112 [ # # ]: 0 : m_aRBAccessCSVFiles.Check(sal_True);
113 : :
114 : : struct SectionDescriptor
115 : : {
116 : : short nFlag;
117 : : Window* pFirstControl;
118 : : } aSections[] = {
119 : : { TC_EXTENSION, &m_aFTExtensionHeader },
120 : : { TC_SEPARATORS, &m_aLineFormat },
121 : : { TC_HEADER, &m_aRowHeader },
122 : : { TC_CHARSET, &m_aCharSetHeader },
123 : : { 0, NULL }
124 : 0 : };
125 : :
126 [ # # ]: 0 : for ( size_t section=0; section < sizeof( aSections ) / sizeof( aSections[0] ) - 1; ++section )
127 : : {
128 [ # # ]: 0 : if ( ( m_nAvailableSections & aSections[section].nFlag ) != 0 )
129 : : {
130 : : // the section is visible, no need to do anything here
131 : 0 : continue;
132 : : }
133 : :
134 : 0 : Window* pThisSection = aSections[section].pFirstControl;
135 : 0 : Window* pNextSection = aSections[section+1].pFirstControl;
136 : :
137 : : // hide all elements from this section
138 : 0 : Window* pControl = pThisSection;
139 [ # # ][ # # ]: 0 : while ( ( pControl != pNextSection ) && pControl )
[ # # ]
140 : : {
141 [ # # ]: 0 : Window* pRealWindow = pControl->GetWindow( WINDOW_CLIENT );
142 : : #if OSL_DEBUG_LEVEL > 0
143 : : String sWindowText( pRealWindow->GetText() );
144 : : (void)sWindowText;
145 : : #endif
146 [ # # ]: 0 : pRealWindow->Hide();
147 [ # # ]: 0 : pControl = pControl->GetWindow( WINDOW_NEXT );
148 : : }
149 : :
150 : : // move all controls in following sections up
151 [ # # ]: 0 : if ( !pNextSection )
152 : 0 : continue;
153 [ # # ]: 0 : const long nThisSectionStart = pThisSection->GetPosPixel().Y();
154 [ # # ]: 0 : const long nNextSectionStart = pNextSection->GetPosPixel().Y();
155 : 0 : const long nMoveOffset( nThisSectionStart - nNextSectionStart );
156 [ # # ]: 0 : while ( pControl )
157 : : {
158 [ # # ]: 0 : Point aPos = pControl->GetPosPixel();
159 : 0 : aPos.Move( 0, nMoveOffset );
160 [ # # ]: 0 : pControl->SetPosPixel( aPos );
161 [ # # ]: 0 : pControl = pControl->GetWindow( WINDOW_NEXT );
162 : : }
163 : : }
164 : :
165 [ # # ]: 0 : Rectangle aControlRectUnion;
166 [ # # ][ # # ]: 0 : for ( Window* pControl = aSections[0].pFirstControl;
167 : : pControl != NULL;
168 : : pControl = pControl->GetWindow( WINDOW_NEXT )
169 : : )
170 : : {
171 [ # # ][ # # ]: 0 : aControlRectUnion = aControlRectUnion.Union( Rectangle( pControl->GetPosPixel(), pControl->GetSizePixel() ) );
[ # # ][ # # ]
172 : : }
173 : :
174 : : // need some adjustments to the positions, since the resource-specified
175 : : // positions for the control were relative to *our* parent, while by now
176 : : // the controls have |this| as parent.
177 : :
178 : : // first, move ourself to the upper left of the area occupied by all controls
179 [ # # ]: 0 : SetPosPixel( aControlRectUnion.TopLeft() );
180 : :
181 : : // then, compensate in the control positions, by moving them the up/left
182 [ # # ][ # # ]: 0 : for ( Window* pControl = aSections[0].pFirstControl;
183 : : pControl != NULL;
184 : : pControl = pControl->GetWindow( WINDOW_NEXT )
185 : : )
186 : : {
187 [ # # ]: 0 : Point aPos( pControl->GetPosPixel() );
188 : 0 : aPos.Move( -aControlRectUnion.Left(), -aControlRectUnion.Top() );
189 [ # # ]: 0 : pControl->SetPosPixel( aPos );
190 : :
191 : : // while we are here ... the controls should not have an own background
192 : : // (this would not be needed when our outer dialog were also the parent
193 : : // of the controls)
194 [ # # ]: 0 : pControl->SetBackground();
195 : : }
196 : :
197 : : // now, change our own size so all controls fit
198 [ # # ][ # # ]: 0 : SetSizePixel( aControlRectUnion.GetSize() );
199 : :
200 [ # # ]: 0 : SetBackground();
201 [ # # ]: 0 : Show();
202 : 0 : }
203 : :
204 [ # # ][ # # ]: 0 : OTextConnectionHelper::~OTextConnectionHelper()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
205 : : {
206 : :
207 : : DBG_DTOR(OTextConnectionHelper,NULL);
208 [ # # ]: 0 : }
209 : :
210 : 0 : IMPL_LINK(OTextConnectionHelper, OnControlModified, Control*, /*EMPTYARG*/)
211 : : {
212 : 0 : callModifiedHdl();
213 : 0 : return 0L;
214 : : }
215 : :
216 : 0 : IMPL_LINK(OTextConnectionHelper, OnEditModified, Edit*, /*_pEdit*/)
217 : : {
218 : 0 : m_aGetExtensionHandler.Call(this);
219 : 0 : return 0L;
220 : : }
221 : :
222 : 0 : IMPL_LINK(OTextConnectionHelper, OnSetExtensionHdl, RadioButton*, /*_pRadioButton*/)
223 : : {
224 : 0 : sal_Bool bDoEnable = m_aRBAccessOtherFiles.IsChecked();
225 : 0 : m_aETOwnExtension.Enable(bDoEnable);
226 : 0 : m_aFTExtensionExample.Enable(bDoEnable);
227 : 0 : m_aGetExtensionHandler.Call(this);
228 : 0 : return 0L;
229 : : }
230 : :
231 : 0 : void OTextConnectionHelper::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList)
232 : : {
233 [ # # ][ # # ]: 0 : _rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aFieldSeparator));
234 [ # # ][ # # ]: 0 : _rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aTextSeparator));
235 [ # # ][ # # ]: 0 : _rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aDecimalSeparator));
236 [ # # ][ # # ]: 0 : _rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aThousandsSeparator));
237 [ # # ][ # # ]: 0 : _rControlList.push_back(new OSaveValueWrapper<CheckBox>(&m_aRowHeader));
238 [ # # ][ # # ]: 0 : _rControlList.push_back(new OSaveValueWrapper<ListBox>(&m_aCharSet));
239 : 0 : }
240 : :
241 : 0 : void OTextConnectionHelper::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList)
242 : : {
243 [ # # ][ # # ]: 0 : _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aFieldSeparatorLabel));
244 [ # # ][ # # ]: 0 : _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aTextSeparatorLabel));
245 [ # # ][ # # ]: 0 : _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aDecimalSeparatorLabel));
246 [ # # ][ # # ]: 0 : _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aThousandsSeparatorLabel));
247 [ # # ][ # # ]: 0 : _rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aCharSetHeader));
248 [ # # ][ # # ]: 0 : _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aCharSetLabel));
249 [ # # ][ # # ]: 0 : _rControlList.push_back(new ODisableWrapper<ListBox>(&m_aCharSet));
250 : 0 : }
251 : :
252 : 0 : void OTextConnectionHelper::implInitControls(const SfxItemSet& _rSet, sal_Bool _bValid)
253 : : {
254 [ # # ]: 0 : if ( !_bValid )
255 : 0 : return;
256 : :
257 : 0 : SFX_ITEMSET_GET( _rSet, pDelItem, SfxStringItem, DSID_FIELDDELIMITER, sal_True );
258 : 0 : SFX_ITEMSET_GET( _rSet, pStrItem, SfxStringItem, DSID_TEXTDELIMITER, sal_True );
259 : 0 : SFX_ITEMSET_GET( _rSet, pDecdelItem, SfxStringItem, DSID_DECIMALDELIMITER, sal_True );
260 : 0 : SFX_ITEMSET_GET( _rSet, pThodelItem, SfxStringItem, DSID_THOUSANDSDELIMITER, sal_True );
261 : 0 : SFX_ITEMSET_GET( _rSet, pExtensionItem, SfxStringItem, DSID_TEXTFILEEXTENSION, sal_True );
262 : 0 : SFX_ITEMSET_GET( _rSet, pCharsetItem, SfxStringItem, DSID_CHARSET, sal_True );
263 : :
264 [ # # ]: 0 : if ( ( m_nAvailableSections & TC_EXTENSION ) != 0 )
265 : : {
266 : 0 : m_aOldExtension = pExtensionItem->GetValue();
267 : 0 : SetExtension( m_aOldExtension );
268 : : }
269 : :
270 [ # # ]: 0 : if ( ( m_nAvailableSections & TC_HEADER ) != 0 )
271 : : {
272 : 0 : SFX_ITEMSET_GET( _rSet, pHdrItem, SfxBoolItem, DSID_TEXTFILEHEADER, sal_True );
273 : 0 : m_aRowHeader.Check( pHdrItem->GetValue() );
274 : : }
275 : :
276 [ # # ]: 0 : if ( ( m_nAvailableSections & TC_SEPARATORS ) != 0 )
277 : : {
278 : 0 : SetSeparator( m_aFieldSeparator, m_aFieldSeparatorList, pDelItem->GetValue() );
279 : 0 : SetSeparator( m_aTextSeparator, m_aTextSeparatorList, pStrItem->GetValue() );
280 : 0 : m_aDecimalSeparator.SetText( pDecdelItem->GetValue() );
281 : 0 : m_aThousandsSeparator.SetText( pThodelItem->GetValue() );
282 : : }
283 : :
284 [ # # ]: 0 : if ( ( m_nAvailableSections & TC_CHARSET ) != 0 )
285 : : {
286 : 0 : m_aCharSet.SelectEntryByIanaName( pCharsetItem->GetValue() );
287 : : }
288 : : }
289 : :
290 : 0 : sal_Bool OTextConnectionHelper::prepareLeave()
291 : : {
292 [ # # ]: 0 : LocalResourceAccess aStringResAccess(PAGE_TEXT, RSC_TABPAGE);
293 : : // for accessing the strings which are local to our own resource block
294 [ # # ]: 0 : String sExtension = GetExtension();
295 [ # # ]: 0 : String aErrorText;
296 : 0 : Control* pErrorWin = NULL;
297 [ # # ]: 0 : String aDelText(m_aFieldSeparator.GetText());
298 [ # # ]: 0 : if(!aDelText.Len())
299 : : { // No FieldSeparator
300 [ # # ][ # # ]: 0 : aErrorText = String(ModuleRes(STR_AUTODELIMITER_MISSING));
[ # # ][ # # ]
301 [ # # ][ # # ]: 0 : aErrorText.SearchAndReplaceAscii("#1",m_aFieldSeparatorLabel.GetText());
[ # # ]
302 : 0 : pErrorWin = &m_aFieldSeparator;
303 : : }
304 [ # # ][ # # ]: 0 : else if (!m_aDecimalSeparator.GetText().Len())
[ # # ]
305 : : { // No DecimalSeparator
306 [ # # ][ # # ]: 0 : aErrorText = String(ModuleRes(STR_AUTODELIMITER_MISSING));
[ # # ][ # # ]
307 [ # # ][ # # ]: 0 : aErrorText.SearchAndReplaceAscii("#1",m_aDecimalSeparatorLabel.GetText());
[ # # ]
308 : 0 : pErrorWin = &m_aDecimalSeparator;
309 : : }
310 [ # # ][ # # ]: 0 : else if (m_aTextSeparator.GetText() == m_aFieldSeparator.GetText())
[ # # ][ # # ]
[ # # ][ # # ]
311 : : { // Field and TextSeparator must not be the same
312 [ # # ][ # # ]: 0 : aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER));
[ # # ][ # # ]
313 [ # # ][ # # ]: 0 : aErrorText.SearchAndReplaceAscii("#1",m_aTextSeparatorLabel.GetText());
[ # # ]
314 [ # # ][ # # ]: 0 : aErrorText.SearchAndReplaceAscii("#2",m_aFieldSeparatorLabel.GetText());
[ # # ]
315 : 0 : pErrorWin = &m_aTextSeparator;
316 : : }
317 [ # # ][ # # ]: 0 : else if (m_aDecimalSeparator.GetText() == m_aThousandsSeparator.GetText())
[ # # ][ # # ]
[ # # ][ # # ]
318 : : { // Thousands and DecimalSeparator must not be the same
319 [ # # ][ # # ]: 0 : aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER));
[ # # ][ # # ]
320 [ # # ][ # # ]: 0 : aErrorText.SearchAndReplaceAscii("#1",m_aDecimalSeparatorLabel.GetText());
[ # # ]
321 [ # # ][ # # ]: 0 : aErrorText.SearchAndReplaceAscii("#2",m_aThousandsSeparatorLabel.GetText());
[ # # ]
322 : 0 : pErrorWin = &m_aDecimalSeparator;
323 : : }
324 [ # # ][ # # ]: 0 : else if (m_aFieldSeparator.GetText() == m_aThousandsSeparator.GetText())
[ # # ][ # # ]
[ # # ][ # # ]
325 : : { // Thousands and FieldSeparator must not be the same
326 [ # # ][ # # ]: 0 : aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER));
[ # # ][ # # ]
327 [ # # ][ # # ]: 0 : aErrorText.SearchAndReplaceAscii("#1",m_aFieldSeparatorLabel.GetText());
[ # # ]
328 [ # # ][ # # ]: 0 : aErrorText.SearchAndReplaceAscii("#2",m_aThousandsSeparatorLabel.GetText());
[ # # ]
329 : 0 : pErrorWin = &m_aFieldSeparator;
330 : : }
331 [ # # ][ # # ]: 0 : else if (m_aFieldSeparator.GetText() == m_aDecimalSeparator.GetText())
[ # # ][ # # ]
[ # # ][ # # ]
332 : : { // Tenner and FieldSeparator must not be the same
333 [ # # ][ # # ]: 0 : aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER));
[ # # ][ # # ]
334 [ # # ][ # # ]: 0 : aErrorText.SearchAndReplaceAscii("#1",m_aFieldSeparatorLabel.GetText());
[ # # ]
335 [ # # ][ # # ]: 0 : aErrorText.SearchAndReplaceAscii("#2",m_aDecimalSeparatorLabel.GetText());
[ # # ]
336 : 0 : pErrorWin = &m_aFieldSeparator;
337 : : }
338 [ # # ][ # # ]: 0 : else if (m_aTextSeparator.GetText() == m_aThousandsSeparator.GetText())
[ # # ][ # # ]
[ # # ][ # # ]
339 : : { // Thousands and TextSeparator must not be the same
340 [ # # ][ # # ]: 0 : aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER));
[ # # ][ # # ]
341 [ # # ][ # # ]: 0 : aErrorText.SearchAndReplaceAscii("#1",m_aTextSeparatorLabel.GetText());
[ # # ]
342 [ # # ][ # # ]: 0 : aErrorText.SearchAndReplaceAscii("#2",m_aThousandsSeparatorLabel.GetText());
[ # # ]
343 : 0 : pErrorWin = &m_aTextSeparator;
344 : : }
345 [ # # ][ # # ]: 0 : else if (m_aTextSeparator.GetText() == m_aDecimalSeparator.GetText())
[ # # ][ # # ]
[ # # ][ # # ]
346 : : { // Tenner and TextSeparator must not be the same
347 [ # # ][ # # ]: 0 : aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER));
[ # # ][ # # ]
348 [ # # ][ # # ]: 0 : aErrorText.SearchAndReplaceAscii("#1",m_aTextSeparatorLabel.GetText());
[ # # ]
349 [ # # ][ # # ]: 0 : aErrorText.SearchAndReplaceAscii("#2",m_aDecimalSeparatorLabel.GetText());
[ # # ]
350 : 0 : pErrorWin = &m_aTextSeparator;
351 : : }
352 [ # # ][ # # ]: 0 : else if ((sExtension.Search('*') != STRING_NOTFOUND) || (sExtension.Search('?') != STRING_NOTFOUND))
[ # # ][ # # ]
[ # # ]
353 : : {
354 [ # # ][ # # ]: 0 : aErrorText = String(ModuleRes(STR_AUTONO_WILDCARDS));
[ # # ][ # # ]
355 [ # # ]: 0 : aErrorText.SearchAndReplaceAscii("#1",sExtension);
356 : 0 : pErrorWin = &m_aETOwnExtension;
357 : : }
358 : : else
359 : 0 : return sal_True;
360 [ # # ][ # # ]: 0 : ErrorBox(NULL, WB_OK, MnemonicGenerator::EraseAllMnemonicChars( aErrorText)).Execute();
[ # # ][ # # ]
[ # # ]
361 [ # # ]: 0 : pErrorWin->GrabFocus();
362 [ # # ][ # # ]: 0 : return 0;
[ # # ][ # # ]
363 : : }
364 : :
365 : 0 : sal_Bool OTextConnectionHelper::FillItemSet( SfxItemSet& rSet, const sal_Bool _bChangedSomething )
366 : : {
367 : 0 : sal_Bool bChangedSomething = _bChangedSomething;
368 : :
369 [ # # ]: 0 : if ( ( m_nAvailableSections & TC_EXTENSION ) != 0 )
370 : : {
371 [ # # ]: 0 : String sExtension = GetExtension();
372 [ # # ][ # # ]: 0 : if( !m_aOldExtension.Equals( sExtension ) )
373 : : {
374 [ # # ][ # # ]: 0 : rSet.Put( SfxStringItem( DSID_TEXTFILEEXTENSION, sExtension ) );
[ # # ]
375 : 0 : bChangedSomething = sal_True;
376 [ # # ]: 0 : }
377 : : }
378 : :
379 [ # # ]: 0 : if ( ( m_nAvailableSections & TC_HEADER ) != 0 )
380 : : {
381 [ # # ]: 0 : if( (m_aRowHeader.GetState() != m_aRowHeader.GetSavedValue()) )
382 : : {
383 [ # # ]: 0 : rSet.Put(SfxBoolItem(DSID_TEXTFILEHEADER, m_aRowHeader.IsChecked()));
384 : 0 : bChangedSomething = sal_True;
385 : : }
386 : : }
387 : :
388 [ # # ]: 0 : if ( ( m_nAvailableSections & TC_SEPARATORS ) != 0 )
389 : : {
390 [ # # ][ # # ]: 0 : if( m_aFieldSeparator.GetText() != m_aFieldSeparator.GetSavedValue() )
391 : : {
392 [ # # ][ # # ]: 0 : rSet.Put( SfxStringItem(DSID_FIELDDELIMITER, GetSeparator( m_aFieldSeparator, m_aFieldSeparatorList) ) );
[ # # ]
393 : 0 : bChangedSomething = sal_True;
394 : : }
395 [ # # ][ # # ]: 0 : if( m_aTextSeparator.GetText() != m_aTextSeparator.GetSavedValue() )
396 : : {
397 [ # # ][ # # ]: 0 : rSet.Put( SfxStringItem(DSID_TEXTDELIMITER, GetSeparator( m_aTextSeparator, m_aTextSeparatorList) ) );
[ # # ]
398 : 0 : bChangedSomething = sal_True;
399 : : }
400 : :
401 [ # # ][ # # ]: 0 : if( m_aDecimalSeparator.GetText() != m_aDecimalSeparator.GetSavedValue() )
402 : : {
403 [ # # ][ # # ]: 0 : rSet.Put( SfxStringItem(DSID_DECIMALDELIMITER, m_aDecimalSeparator.GetText().Copy(0, 1) ) );
[ # # ][ # # ]
[ # # ]
404 : 0 : bChangedSomething = sal_True;
405 : : }
406 [ # # ][ # # ]: 0 : if( m_aThousandsSeparator.GetText() != m_aThousandsSeparator.GetSavedValue() )
407 : : {
408 [ # # ][ # # ]: 0 : rSet.Put( SfxStringItem(DSID_THOUSANDSDELIMITER, m_aThousandsSeparator.GetText().Copy(0,1) ) );
[ # # ][ # # ]
[ # # ]
409 : 0 : bChangedSomething = sal_True;
410 : : }
411 : : }
412 : :
413 [ # # ]: 0 : if ( ( m_nAvailableSections & TC_CHARSET ) != 0 )
414 : : {
415 [ # # ]: 0 : if ( m_aCharSet.StoreSelectedCharSet( rSet, DSID_CHARSET ) )
416 : 0 : bChangedSomething = sal_True;
417 : : }
418 : :
419 : 0 : return bChangedSomething;
420 : : }
421 : :
422 : 0 : void OTextConnectionHelper::SetExtension(const String& _rVal)
423 : : {
424 [ # # ]: 0 : if (_rVal.EqualsAscii("txt"))
425 : 0 : m_aRBAccessTextFiles.Check(sal_True);
426 [ # # ]: 0 : else if (_rVal.EqualsAscii( "csv" ))
427 : 0 : m_aRBAccessCSVFiles.Check(sal_True);
428 : : else
429 : : {
430 : 0 : m_aRBAccessOtherFiles.Check(sal_True);
431 : 0 : m_aFTExtensionExample.SetText(_rVal);
432 : : }
433 : 0 : }
434 : :
435 : 0 : String OTextConnectionHelper::GetExtension()
436 : : {
437 : 0 : String sExtension;
438 [ # # ]: 0 : if (m_aRBAccessTextFiles.IsChecked())
439 [ # # ]: 0 : sExtension = rtl::OUString("txt");
440 [ # # ]: 0 : else if (m_aRBAccessCSVFiles.IsChecked())
441 [ # # ]: 0 : sExtension = rtl::OUString("csv");
442 : : else
443 : : {
444 [ # # ][ # # ]: 0 : sExtension = m_aETOwnExtension.GetText();
[ # # ]
445 [ # # ][ # # ]: 0 : if ( comphelper::string::equals(sExtension.GetToken(0,'.'), '*') )
[ # # ][ # # ]
446 [ # # ]: 0 : sExtension.Erase(0,2);
447 : : }
448 : 0 : return sExtension;
449 : : }
450 : :
451 : 0 : String OTextConnectionHelper::GetSeparator( const ComboBox& rBox, const String& rList )
452 : : {
453 : 0 : sal_Unicode nTok = '\t';
454 [ # # ]: 0 : xub_StrLen nPos(rBox.GetEntryPos( rBox.GetText() ));
455 : :
456 [ # # ]: 0 : if( nPos == COMBOBOX_ENTRY_NOTFOUND )
457 [ # # ]: 0 : return rBox.GetText().Copy(0);
458 : :
459 [ # # ][ # # ]: 0 : if ( !( &m_aTextSeparator == &rBox && nPos == (rBox.GetEntryCount()-1) ) )
[ # # ]
460 : : return rtl::OUString(
461 : : static_cast< sal_Unicode >(
462 [ # # ][ # # ]: 0 : rList.GetToken(((nPos*2)+1), nTok ).ToInt32()));
463 : : // somewhat strange ... translates for instance an "32" into " "
464 [ # # ]: 0 : return rtl::OUString();
465 : : }
466 : :
467 : 0 : void OTextConnectionHelper::SetSeparator( ComboBox& rBox, const String& rList, const String& rVal )
468 : : {
469 : 0 : char nTok = '\t';
470 [ # # ]: 0 : xub_StrLen nCnt(comphelper::string::getTokenCount(rList, nTok));
471 : : xub_StrLen i;
472 : :
473 [ # # ]: 0 : for( i=0 ; i<nCnt ; i+=2 )
474 : : {
475 : : rtl::OUString sTVal(
476 : : static_cast< sal_Unicode >(
477 [ # # ][ # # ]: 0 : rList.GetToken( (i+1), nTok ).ToInt32()));
[ # # ]
478 : :
479 [ # # ][ # # ]: 0 : if( sTVal.equals(rVal) )
480 : : {
481 [ # # ][ # # ]: 0 : rBox.SetText( rList.GetToken( i, nTok ) );
[ # # ]
482 : : break;
483 : : }
484 [ # # ]: 0 : }
485 : :
486 [ # # ]: 0 : if ( i >= nCnt )
487 : : {
488 [ # # ][ # # ]: 0 : if ( &m_aTextSeparator == &rBox && !rVal.Len() )
[ # # ]
489 : 0 : rBox.SetText(m_aTextNone);
490 : : else
491 [ # # ]: 0 : rBox.SetText( rVal.Copy(0, 1) );
492 : : }
493 : 0 : }
494 : : }
495 : :
496 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|