1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 // MARKER(update_precomp.py): autogen include statement, do not remove 24 #include "precompiled_dbui.hxx" 25 #ifndef _DBAUI_MODULE_DBU_HXX_ 26 #include "moduledbu.hxx" 27 #endif 28 29 #ifndef DBAUI_TEXTCONNECTIONHELPER_HXX 30 #include "TextConnectionHelper.hxx" 31 #endif 32 33 #ifndef _DBAUI_SQLMESSAGE_HXX_ 34 #include "sqlmessage.hxx" 35 #endif 36 #ifndef _DBU_DLG_HRC_ 37 #include "dbu_dlg.hrc" 38 #endif 39 #ifndef _DBU_RESOURCE_HRC_ 40 #include "dbu_resource.hrc" 41 #endif 42 #include "AutoControlsDef.hrc" 43 44 #ifndef _SFXITEMSET_HXX 45 #include <svl/itemset.hxx> 46 #endif 47 #ifndef _SFXSTRITEM_HXX 48 #include <svl/stritem.hxx> 49 #endif 50 #ifndef _SFXENUMITEM_HXX 51 #include <svl/eitem.hxx> 52 #endif 53 #ifndef _SFXINTITEM_HXX 54 #include <svl/intitem.hxx> 55 #endif 56 #ifndef _DBAUI_DATASOURCEITEMS_HXX_ 57 #include "dsitems.hxx" 58 #endif 59 #ifndef _DBAUI_DBFINDEX_HXX_ 60 #include "dbfindex.hxx" 61 #endif 62 #ifndef _DBA_DBACCESS_HELPID_HRC_ 63 #include "dbaccess_helpid.hrc" 64 #endif 65 #ifndef _DBAUI_LOCALRESACCESS_HXX_ 66 #include "localresaccess.hxx" 67 #endif 68 #ifndef _SV_MSGBOX_HXX 69 #include <vcl/msgbox.hxx> 70 #endif 71 #ifndef _SV_MNEMONIC_HXX 72 #include <vcl/mnemonic.hxx> 73 #endif 74 #ifndef _SVTOOLS_CJKOPTIONS_HXX 75 #include <svl/cjkoptions.hxx> 76 #endif 77 #include <jvmaccess/virtualmachine.hxx> 78 #ifndef _DBAUI_ADASTAT_HXX_ 79 #include "AdabasStat.hxx" 80 #endif 81 #ifndef _CONNECTIVITY_COMMONTOOLS_HXX_ 82 #include <connectivity/CommonTools.hxx> 83 #endif 84 #ifndef DBAUI_DRIVERSETTINGS_HXX 85 #include "DriverSettings.hxx" 86 #endif 87 #ifndef _DBAUI_DBADMIN_HXX_ 88 #include "dbadmin.hxx" 89 #endif 90 #ifndef _COMPHELPER_TYPES_HXX_ 91 #include <comphelper/types.hxx> 92 #endif 93 94 #ifndef _COM_SUN_STAR_UI_DIALOGS_XFOLDERPICKER_HPP_ 95 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp> 96 #endif 97 // #106016# ------------------------------------ 98 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_ 99 #include <com/sun/star/task/XInteractionHandler.hpp> 100 #endif 101 102 #ifndef SVTOOLS_FILENOTATION_HXX_ 103 #include <svl/filenotation.hxx> 104 #endif 105 106 #ifndef _UNOTOOLS_LOCALFILEHELPER_HXX 107 #include <unotools/localfilehelper.hxx> 108 #endif 109 #ifndef _UNOTOOLS_UCBHELPER_HXX 110 #include <unotools/ucbhelper.hxx> 111 #endif 112 #ifndef _UCBHELPER_COMMANDENVIRONMENT_HXX 113 #include <ucbhelper/commandenvironment.hxx> 114 #endif 115 #ifndef DBAUI_FILEPICKER_INTERACTION_HXX 116 #include "finteraction.hxx" 117 #endif 118 #ifndef _CONNECTIVITY_COMMONTOOLS_HXX_ 119 #include <connectivity/CommonTools.hxx> 120 #endif 121 122 #ifndef DBAUI_DBSETUPCONNECTIONPAGES_HXX 123 #include "DBSetupConnectionPages.hxx" 124 #endif 125 126 #ifndef _DBU_DLG_HRC_ 127 #include "dbu_dlg.hrc" 128 #endif 129 130 #ifndef _DBA_DBACCESS_HELPID_HRC_ 131 #include "dbaccess_helpid.hrc" 132 #endif 133 134 #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX 135 #include <unotools/pathoptions.hxx> 136 #endif 137 138 #ifndef SVTOOLS_INC_ROADMAPWIZARD_HXX 139 #include <svtools/roadmapwizard.hxx> 140 #endif 141 142 143 namespace dbaui 144 { 145 146 //======================================================================== 147 //= OTextConnectionPageSetup 148 //======================================================================== 149 DBG_NAME(OTextConnectionHelper) 150 //------------------------------------------------------------------------ 151 OTextConnectionHelper::OTextConnectionHelper( Window* pParent, const short _nAvailableSections ) 152 :Control( pParent, WB_DIALOGCONTROL ) 153 ,m_aFTExtensionHeader (this, ModuleRes(FT_AUTOEXTENSIONHEADER)) 154 ,m_aRBAccessTextFiles (this, ModuleRes(RB_AUTOACCESSCTEXTFILES)) 155 ,m_aRBAccessCSVFiles (this, ModuleRes(RB_AUTOACCESSCCSVFILES)) 156 ,m_aRBAccessOtherFiles (this, ModuleRes(RB_AUTOACCESSOTHERS)) 157 ,m_aETOwnExtension (this, ModuleRes(ET_AUTOOWNEXTENSION)) 158 ,m_aFTExtensionExample (this, ModuleRes(FT_AUTOOWNEXTENSIONAPPENDIX)) 159 ,m_aLineFormat (this, ModuleRes(FL_AUTOSEPARATOR2)) 160 ,m_aFieldSeparatorLabel (this, ModuleRes(FT_AUTOFIELDSEPARATOR)) 161 ,m_aFieldSeparator (this, ModuleRes(CM_AUTOFIELDSEPARATOR)) 162 ,m_aTextSeparatorLabel (this, ModuleRes(FT_AUTOTEXTSEPARATOR)) 163 ,m_aTextSeparator (this, ModuleRes(CM_AUTOTEXTSEPARATOR)) 164 ,m_aDecimalSeparatorLabel (this, ModuleRes(FT_AUTODECIMALSEPARATOR)) 165 ,m_aDecimalSeparator (this, ModuleRes(CM_AUTODECIMALSEPARATOR)) 166 ,m_aThousandsSeparatorLabel (this, ModuleRes(FT_AUTOTHOUSANDSSEPARATOR)) 167 ,m_aThousandsSeparator (this, ModuleRes(CM_AUTOTHOUSANDSSEPARATOR)) 168 ,m_aRowHeader (this, ModuleRes(CB_AUTOHEADER)) 169 ,m_aCharSetHeader (this, ModuleRes(FL_DATACONVERT)) 170 ,m_aCharSetLabel (this, ModuleRes(FT_CHARSET)) 171 ,m_aCharSet (this, ModuleRes(LB_CHARSET)) 172 ,m_aFieldSeparatorList (ModuleRes(STR_AUTOFIELDSEPARATORLIST)) 173 ,m_aTextSeparatorList (ModuleRes(STR_AUTOTEXTSEPARATORLIST)) 174 ,m_aTextNone (ModuleRes(STR_AUTOTEXT_FIELD_SEP_NONE)) 175 ,m_nAvailableSections( _nAvailableSections ) 176 { 177 DBG_CTOR(OTextConnectionHelper,NULL); 178 179 xub_StrLen nCnt = m_aFieldSeparatorList.GetTokenCount( '\t' ); 180 xub_StrLen i; 181 182 for( i = 0 ; i < nCnt ; i += 2 ) 183 m_aFieldSeparator.InsertEntry( m_aFieldSeparatorList.GetToken( i, '\t' ) ); 184 185 nCnt = m_aTextSeparatorList.GetTokenCount( '\t' ); 186 for( i=0 ; i<nCnt ; i+=2 ) 187 m_aTextSeparator.InsertEntry( m_aTextSeparatorList.GetToken( i, '\t' ) ); 188 m_aTextSeparator.InsertEntry(m_aTextNone); 189 190 // set the modify handlers 191 m_aFieldSeparator.SetUpdateDataHdl(getControlModifiedLink()); 192 m_aFieldSeparator.SetSelectHdl(getControlModifiedLink()); 193 m_aTextSeparator.SetUpdateDataHdl(getControlModifiedLink()); 194 m_aTextSeparator.SetSelectHdl(getControlModifiedLink()); 195 m_aCharSet.SetSelectHdl(getControlModifiedLink()); 196 197 m_aFieldSeparator.SetModifyHdl(getControlModifiedLink()); 198 m_aTextSeparator.SetModifyHdl(getControlModifiedLink()); 199 m_aDecimalSeparator.SetModifyHdl(getControlModifiedLink()); 200 m_aThousandsSeparator.SetModifyHdl(getControlModifiedLink()); 201 m_aETOwnExtension.SetModifyHdl(LINK(this, OTextConnectionHelper, OnEditModified)); 202 m_aRBAccessTextFiles.SetToggleHdl(LINK(this, OTextConnectionHelper, OnSetExtensionHdl)); 203 m_aRBAccessCSVFiles.SetToggleHdl(LINK(this, OTextConnectionHelper, OnSetExtensionHdl)); 204 m_aRBAccessOtherFiles.SetToggleHdl(LINK(this, OTextConnectionHelper, OnSetExtensionHdl)); 205 m_aRBAccessCSVFiles.Check(sal_True); 206 207 struct SectionDescriptor 208 { 209 short nFlag; 210 Window* pFirstControl; 211 } aSections[] = { 212 { TC_EXTENSION, &m_aFTExtensionHeader }, 213 { TC_SEPARATORS, &m_aLineFormat }, 214 { TC_HEADER, &m_aRowHeader }, 215 { TC_CHARSET, &m_aCharSetHeader }, 216 { 0, NULL } 217 }; 218 219 for ( size_t section=0; section < sizeof( aSections ) / sizeof( aSections[0] ) - 1; ++section ) 220 { 221 if ( ( m_nAvailableSections & aSections[section].nFlag ) != 0 ) 222 { 223 // the section is visible, no need to do anything here 224 continue; 225 } 226 227 Window* pThisSection = aSections[section].pFirstControl; 228 Window* pNextSection = aSections[section+1].pFirstControl; 229 230 // hide all elements from this section 231 Window* pControl = pThisSection; 232 while ( ( pControl != pNextSection ) && pControl ) 233 { 234 Window* pRealWindow = pControl->GetWindow( WINDOW_CLIENT ); 235 #if OSL_DEBUG_LEVEL > 0 236 String sWindowText( pRealWindow->GetText() ); 237 (void)sWindowText; 238 #endif 239 pRealWindow->Hide(); 240 pControl = pControl->GetWindow( WINDOW_NEXT ); 241 } 242 243 // move all controls in following sections up 244 if ( !pNextSection ) 245 continue; 246 const long nThisSectionStart = pThisSection->GetPosPixel().Y(); 247 const long nNextSectionStart = pNextSection->GetPosPixel().Y(); 248 const long nMoveOffset( nThisSectionStart - nNextSectionStart ); 249 while ( pControl ) 250 { 251 Point aPos = pControl->GetPosPixel(); 252 aPos.Move( 0, nMoveOffset ); 253 pControl->SetPosPixel( aPos ); 254 pControl = pControl->GetWindow( WINDOW_NEXT ); 255 } 256 } 257 258 Rectangle aControlRectUnion; 259 for ( Window* pControl = aSections[0].pFirstControl; 260 pControl != NULL; 261 pControl = pControl->GetWindow( WINDOW_NEXT ) 262 ) 263 { 264 aControlRectUnion = aControlRectUnion.Union( Rectangle( pControl->GetPosPixel(), pControl->GetSizePixel() ) ); 265 } 266 267 // need some adjustments to the positions, since the resource-specified 268 // positions for the control were relative to *our* parent, while by now 269 // the controls have |this| as parent. 270 271 // first, move ourself to the upper left of the area occupied by all controls 272 SetPosPixel( aControlRectUnion.TopLeft() ); 273 274 // then, compensate in the control positions, by moving them the up/left 275 for ( Window* pControl = aSections[0].pFirstControl; 276 pControl != NULL; 277 pControl = pControl->GetWindow( WINDOW_NEXT ) 278 ) 279 { 280 Point aPos( pControl->GetPosPixel() ); 281 aPos.Move( -aControlRectUnion.Left(), -aControlRectUnion.Top() ); 282 pControl->SetPosPixel( aPos ); 283 284 // while we are here ... the controls should not have an own background 285 // (this would not be needed when our outer dialog were also the parent 286 // of the controls) 287 pControl->SetBackground(); 288 } 289 290 // now, change our own size so all controls fit 291 SetSizePixel( aControlRectUnion.GetSize() ); 292 293 SetBackground(); 294 Show(); 295 } 296 297 // ----------------------------------------------------------------------- 298 OTextConnectionHelper::~OTextConnectionHelper() 299 { 300 301 DBG_DTOR(OTextConnectionHelper,NULL); 302 } 303 304 305 // ----------------------------------------------------------------------- 306 IMPL_LINK(OTextConnectionHelper, OnControlModified, Control*, /*EMPTYARG*/) 307 { 308 callModifiedHdl(); 309 return 0L; 310 } 311 312 // ----------------------------------------------------------------------- 313 IMPL_LINK(OTextConnectionHelper, OnEditModified, Edit*, /*_pEdit*/) 314 { 315 m_aGetExtensionHandler.Call(this); 316 return 0L; 317 } 318 319 320 IMPL_LINK(OTextConnectionHelper, OnSetExtensionHdl, RadioButton*, /*_pRadioButton*/) 321 { 322 sal_Bool bDoEnable = m_aRBAccessOtherFiles.IsChecked(); 323 m_aETOwnExtension.Enable(bDoEnable); 324 m_aFTExtensionExample.Enable(bDoEnable); 325 m_aGetExtensionHandler.Call(this); 326 return 0L; 327 } 328 329 330 // ----------------------------------------------------------------------- 331 void OTextConnectionHelper::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList) 332 { 333 _rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aFieldSeparator)); 334 _rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aTextSeparator)); 335 _rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aDecimalSeparator)); 336 _rControlList.push_back(new OSaveValueWrapper<ComboBox>(&m_aThousandsSeparator)); 337 _rControlList.push_back(new OSaveValueWrapper<CheckBox>(&m_aRowHeader)); 338 _rControlList.push_back(new OSaveValueWrapper<ListBox>(&m_aCharSet)); 339 } 340 // ----------------------------------------------------------------------- 341 void OTextConnectionHelper::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList) 342 { 343 _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aFieldSeparatorLabel)); 344 _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aTextSeparatorLabel)); 345 _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aDecimalSeparatorLabel)); 346 _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aThousandsSeparatorLabel)); 347 _rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aCharSetHeader)); 348 _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aCharSetLabel)); 349 _rControlList.push_back(new ODisableWrapper<ListBox>(&m_aCharSet)); 350 } 351 352 // ----------------------------------------------------------------------- 353 void OTextConnectionHelper::implInitControls(const SfxItemSet& _rSet, sal_Bool _bValid) 354 { 355 if ( !_bValid ) 356 return; 357 358 SFX_ITEMSET_GET( _rSet, pDelItem, SfxStringItem, DSID_FIELDDELIMITER, sal_True ); 359 SFX_ITEMSET_GET( _rSet, pStrItem, SfxStringItem, DSID_TEXTDELIMITER, sal_True ); 360 SFX_ITEMSET_GET( _rSet, pDecdelItem, SfxStringItem, DSID_DECIMALDELIMITER, sal_True ); 361 SFX_ITEMSET_GET( _rSet, pThodelItem, SfxStringItem, DSID_THOUSANDSDELIMITER, sal_True ); 362 SFX_ITEMSET_GET( _rSet, pExtensionItem, SfxStringItem, DSID_TEXTFILEEXTENSION, sal_True ); 363 SFX_ITEMSET_GET( _rSet, pCharsetItem, SfxStringItem, DSID_CHARSET, sal_True ); 364 365 if ( ( m_nAvailableSections & TC_EXTENSION ) != 0 ) 366 { 367 m_aOldExtension = pExtensionItem->GetValue(); 368 SetExtension( m_aOldExtension ); 369 } 370 371 if ( ( m_nAvailableSections & TC_HEADER ) != 0 ) 372 { 373 SFX_ITEMSET_GET( _rSet, pHdrItem, SfxBoolItem, DSID_TEXTFILEHEADER, sal_True ); 374 m_aRowHeader.Check( pHdrItem->GetValue() ); 375 } 376 377 if ( ( m_nAvailableSections & TC_SEPARATORS ) != 0 ) 378 { 379 SetSeparator( m_aFieldSeparator, m_aFieldSeparatorList, pDelItem->GetValue() ); 380 SetSeparator( m_aTextSeparator, m_aTextSeparatorList, pStrItem->GetValue() ); 381 m_aDecimalSeparator.SetText( pDecdelItem->GetValue() ); 382 m_aThousandsSeparator.SetText( pThodelItem->GetValue() ); 383 } 384 385 if ( ( m_nAvailableSections & TC_CHARSET ) != 0 ) 386 { 387 m_aCharSet.SelectEntryByIanaName( pCharsetItem->GetValue() ); 388 } 389 } 390 391 392 393 // ----------------------------------------------------------------------- 394 sal_Bool OTextConnectionHelper::prepareLeave() 395 { 396 LocalResourceAccess aStringResAccess(PAGE_TEXT, RSC_TABPAGE); 397 // for accessing the strings which are local to our own resource block 398 String sExtension = GetExtension(); 399 String aErrorText; 400 Control* pErrorWin = NULL; 401 // if (!m_aFieldSeparator.GetText().Len()) 402 // bug (#42168) if this line is compiled under OS2 (in a product environent) 403 // -> use a temporary variable 404 String aDelText(m_aFieldSeparator.GetText()); 405 if(!aDelText.Len()) 406 { // Kein FeldTrenner 407 aErrorText = String(ModuleRes(STR_AUTODELIMITER_MISSING)); 408 aErrorText.SearchAndReplaceAscii("#1",m_aFieldSeparatorLabel.GetText()); 409 pErrorWin = &m_aFieldSeparator; 410 } 411 else if (!m_aDecimalSeparator.GetText().Len()) 412 { // kein Decimaltrenner 413 aErrorText = String(ModuleRes(STR_AUTODELIMITER_MISSING)); 414 aErrorText.SearchAndReplaceAscii("#1",m_aDecimalSeparatorLabel.GetText()); 415 pErrorWin = &m_aDecimalSeparator; 416 } 417 else if (m_aTextSeparator.GetText() == m_aFieldSeparator.GetText()) 418 { // Feld und TextTrenner duerfen nicht gleich sein 419 aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER)); 420 aErrorText.SearchAndReplaceAscii("#1",m_aTextSeparatorLabel.GetText()); 421 aErrorText.SearchAndReplaceAscii("#2",m_aFieldSeparatorLabel.GetText()); 422 pErrorWin = &m_aTextSeparator; 423 } 424 else if (m_aDecimalSeparator.GetText() == m_aThousandsSeparator.GetText()) 425 { // Tausender und DecimalTrenner duerfen nicht gleich sein 426 aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER)); 427 aErrorText.SearchAndReplaceAscii("#1",m_aDecimalSeparatorLabel.GetText()); 428 aErrorText.SearchAndReplaceAscii("#2",m_aThousandsSeparatorLabel.GetText()); 429 pErrorWin = &m_aDecimalSeparator; 430 } 431 else if (m_aFieldSeparator.GetText() == m_aThousandsSeparator.GetText()) 432 { // Tausender und FeldTrenner duerfen nicht gleich sein 433 aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER)); 434 aErrorText.SearchAndReplaceAscii("#1",m_aFieldSeparatorLabel.GetText()); 435 aErrorText.SearchAndReplaceAscii("#2",m_aThousandsSeparatorLabel.GetText()); 436 pErrorWin = &m_aFieldSeparator; 437 } 438 else if (m_aFieldSeparator.GetText() == m_aDecimalSeparator.GetText()) 439 { // Zehner und FeldTrenner duerfen nicht gleich sein 440 aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER)); 441 aErrorText.SearchAndReplaceAscii("#1",m_aFieldSeparatorLabel.GetText()); 442 aErrorText.SearchAndReplaceAscii("#2",m_aDecimalSeparatorLabel.GetText()); 443 pErrorWin = &m_aFieldSeparator; 444 } 445 else if (m_aTextSeparator.GetText() == m_aThousandsSeparator.GetText()) 446 { // Tausender und TextTrenner duerfen nicht gleich sein 447 aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER)); 448 aErrorText.SearchAndReplaceAscii("#1",m_aTextSeparatorLabel.GetText()); 449 aErrorText.SearchAndReplaceAscii("#2",m_aThousandsSeparatorLabel.GetText()); 450 pErrorWin = &m_aTextSeparator; 451 } 452 else if (m_aTextSeparator.GetText() == m_aDecimalSeparator.GetText()) 453 { // Zehner und TextTrenner duerfen nicht gleich sein 454 aErrorText = String(ModuleRes(STR_AUTODELIMITER_MUST_DIFFER)); 455 aErrorText.SearchAndReplaceAscii("#1",m_aTextSeparatorLabel.GetText()); 456 aErrorText.SearchAndReplaceAscii("#2",m_aDecimalSeparatorLabel.GetText()); 457 pErrorWin = &m_aTextSeparator; 458 } 459 else if ((sExtension.Search('*') != STRING_NOTFOUND) || (sExtension.Search('?') != STRING_NOTFOUND)) 460 { 461 aErrorText = String(ModuleRes(STR_AUTONO_WILDCARDS)); 462 aErrorText.SearchAndReplaceAscii("#1",sExtension); 463 pErrorWin = &m_aETOwnExtension; 464 } 465 else 466 return sal_True; 467 ErrorBox(NULL, WB_OK, MnemonicGenerator::EraseAllMnemonicChars( aErrorText)).Execute(); 468 pErrorWin->GrabFocus(); 469 return 0; 470 } 471 472 473 // ----------------------------------------------------------------------- 474 sal_Bool OTextConnectionHelper::FillItemSet( SfxItemSet& rSet, const sal_Bool _bChangedSomething ) 475 { 476 sal_Bool bChangedSomething = _bChangedSomething; 477 478 if ( ( m_nAvailableSections & TC_EXTENSION ) != 0 ) 479 { 480 String sExtension = GetExtension(); 481 if( !m_aOldExtension.Equals( sExtension ) ) 482 { 483 rSet.Put( SfxStringItem( DSID_TEXTFILEEXTENSION, sExtension ) ); 484 bChangedSomething = sal_True; 485 } 486 } 487 488 if ( ( m_nAvailableSections & TC_HEADER ) != 0 ) 489 { 490 if( (m_aRowHeader.GetState() != m_aRowHeader.GetSavedValue()) ) 491 { 492 rSet.Put(SfxBoolItem(DSID_TEXTFILEHEADER, m_aRowHeader.IsChecked())); 493 bChangedSomething = sal_True; 494 } 495 } 496 497 if ( ( m_nAvailableSections & TC_SEPARATORS ) != 0 ) 498 { 499 if( m_aFieldSeparator.GetText() != m_aFieldSeparator.GetSavedValue() ) 500 { 501 rSet.Put( SfxStringItem(DSID_FIELDDELIMITER, GetSeparator( m_aFieldSeparator, m_aFieldSeparatorList) ) ); 502 bChangedSomething = sal_True; 503 } 504 if( m_aTextSeparator.GetText() != m_aTextSeparator.GetSavedValue() ) 505 { 506 rSet.Put( SfxStringItem(DSID_TEXTDELIMITER, GetSeparator( m_aTextSeparator, m_aTextSeparatorList) ) ); 507 bChangedSomething = sal_True; 508 } 509 510 if( m_aDecimalSeparator.GetText() != m_aDecimalSeparator.GetSavedValue() ) 511 { 512 rSet.Put( SfxStringItem(DSID_DECIMALDELIMITER, m_aDecimalSeparator.GetText().Copy(0, 1) ) ); 513 bChangedSomething = sal_True; 514 } 515 if( m_aThousandsSeparator.GetText() != m_aThousandsSeparator.GetSavedValue() ) 516 { 517 rSet.Put( SfxStringItem(DSID_THOUSANDSDELIMITER, m_aThousandsSeparator.GetText().Copy(0,1) ) ); 518 bChangedSomething = sal_True; 519 } 520 } 521 522 if ( ( m_nAvailableSections & TC_CHARSET ) != 0 ) 523 { 524 if ( m_aCharSet.StoreSelectedCharSet( rSet, DSID_CHARSET ) ) 525 bChangedSomething = sal_True; 526 } 527 528 return bChangedSomething; 529 } 530 531 532 void OTextConnectionHelper::SetExtension(const String& _rVal) 533 { 534 if (_rVal.EqualsAscii("txt")) 535 m_aRBAccessTextFiles.Check(sal_True); 536 else if (_rVal.EqualsAscii( "csv" )) 537 m_aRBAccessCSVFiles.Check(sal_True); 538 else 539 { 540 m_aRBAccessOtherFiles.Check(sal_True); 541 m_aFTExtensionExample.SetText(_rVal); 542 } 543 } 544 545 546 String OTextConnectionHelper::GetExtension() 547 { 548 String sExtension; 549 if (m_aRBAccessTextFiles.IsChecked()) 550 sExtension = String::CreateFromAscii("txt"); 551 else if (m_aRBAccessCSVFiles.IsChecked()) 552 sExtension = String::CreateFromAscii("csv"); 553 else 554 { 555 sExtension = m_aETOwnExtension.GetText(); 556 if ( sExtension.GetToken(0,'.').Equals('*') ) 557 sExtension.Erase(0,2); 558 } 559 return sExtension; 560 } 561 562 563 //------------------------------------------------------------------------ 564 String OTextConnectionHelper::GetSeparator( const ComboBox& rBox, const String& rList ) 565 { 566 sal_Unicode nTok = '\t'; 567 xub_StrLen nPos(rBox.GetEntryPos( rBox.GetText() )); 568 569 if( nPos == COMBOBOX_ENTRY_NOTFOUND ) 570 return rBox.GetText().Copy(0); 571 572 if ( !( &m_aTextSeparator == &rBox && nPos == (rBox.GetEntryCount()-1) ) ) 573 return String( 574 static_cast< sal_Unicode >( 575 rList.GetToken(((nPos*2)+1), nTok ).ToInt32())); 576 // somewhat strange ... translates for instance an "32" into " " 577 return String(); 578 } 579 580 //------------------------------------------------------------------------ 581 void OTextConnectionHelper::SetSeparator( ComboBox& rBox, const String& rList, const String& rVal ) 582 { 583 char nTok = '\t'; 584 xub_StrLen nCnt(rList.GetTokenCount( nTok )); 585 xub_StrLen i; 586 587 for( i=0 ; i<nCnt ; i+=2 ) 588 { 589 String sTVal( 590 static_cast< sal_Unicode >( 591 rList.GetToken( (i+1), nTok ).ToInt32())); 592 593 if( sTVal == rVal ) 594 { 595 rBox.SetText( rList.GetToken( i, nTok ) ); 596 break; 597 } 598 } 599 600 if ( i >= nCnt ) 601 { 602 if ( &m_aTextSeparator == &rBox && !rVal.Len() ) 603 rBox.SetText(m_aTextNone); 604 else 605 rBox.SetText( rVal.Copy(0, 1) ); 606 } 607 } 608 609 //......................................................................... 610 } // namespace dbaui 611 //......................................................................... 612