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 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_dbaccess.hxx" 26 27 #include "dbwizsetup.hxx" 28 #include "dsmeta.hxx" 29 #include "DBSetupConnectionPages.hxx" 30 #include "dbadminsetup.hrc" 31 #include "dbu_dlg.hrc" 32 #include "dsitems.hxx" 33 #include "dsnItem.hxx" 34 35 #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX 36 #include <unotools/pathoptions.hxx> 37 #endif 38 #ifndef _SFXSTRITEM_HXX 39 #include <svl/stritem.hxx> 40 #endif 41 #ifndef _SFXENUMITEM_HXX 42 #include <svl/eitem.hxx> 43 #endif 44 #ifndef _SFXINTITEM_HXX 45 #include <svl/intitem.hxx> 46 #endif 47 #ifndef _SV_MSGBOX_HXX 48 #include <vcl/msgbox.hxx> 49 #endif 50 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC 51 #include "dbustrings.hrc" 52 #endif 53 #ifndef _DBAUI_ADMINPAGES_HXX_ 54 #include "adminpages.hxx" 55 #endif 56 #ifndef _SFX_DOCFILT_HACK_HXX 57 #include <sfx2/docfilt.hxx> 58 #endif 59 #ifndef _UNOTOOLS_UCBHELPER_HXX 60 #include <unotools/ucbhelper.hxx> 61 #endif 62 #ifndef _DBAUI_GENERALPAGE_HXX_ 63 #include "generalpage.hxx" 64 #endif 65 #ifndef _DBAUI_LOCALRESACCESS_HXX_ 66 #include "localresaccess.hxx" 67 #endif 68 #ifndef _DBAUI_STRINGLISTITEM_HXX_ 69 #include "stringlistitem.hxx" 70 #endif 71 #ifndef _DBAUI_PROPERTYSETITEM_HXX_ 72 #include "propertysetitem.hxx" 73 #endif 74 #ifndef _UNOTOOLS_CONFIGNODE_HXX_ 75 #include <unotools/confignode.hxx> 76 #endif 77 #ifndef _DBAUI_DBADMINIMPL_HXX_ 78 #include "DbAdminImpl.hxx" 79 #endif 80 #ifndef _DBA_DBACCESS_HELPID_HRC_ 81 #include "dbaccess_helpid.hrc" 82 #endif 83 #ifndef DBAUI_CONNECTIONPAGESETUP_HXX 84 #include "ConnectionPageSetup.hxx" 85 #endif 86 #ifndef DBAUI_TOOLS_HXX 87 #include "UITools.hxx" 88 #endif 89 #ifndef _DBAUI_DBADMIN_HRC_ 90 #include "dbadmin.hrc" 91 #endif 92 #ifndef DBAUI_ASYNCRONOUSLINK_HXX 93 #include "AsyncronousLink.hxx" 94 #endif 95 #ifndef _FILEDLGHELPER_HXX 96 #include <sfx2/filedlghelper.hxx> 97 #endif 98 #include <cppuhelper/exc_hlp.hxx> 99 100 /** === begin UNO includes === **/ 101 #ifndef _COM_SUN_STAR_FRAME_XSTORABLE_HPP_ 102 #include <com/sun/star/frame/XStorable.hpp> 103 #endif 104 #ifndef _COM_SUN_STAR_UNO_XNAMINGSERVICE_HPP_ 105 #include <com/sun/star/uno/XNamingService.hpp> 106 #endif 107 #ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_ 108 #include <com/sun/star/sdbcx/XTablesSupplier.hpp> 109 #endif 110 #ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_ 111 #include <com/sun/star/sdbc/XDataSource.hpp> 112 #endif 113 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_ 114 #include <com/sun/star/container/XNameAccess.hpp> 115 #endif 116 #ifndef _COM_SUN_STAR_SDB_XDOCUMENTDATASOURCE_HPP_ 117 #include <com/sun/star/sdb/XDocumentDataSource.hpp> 118 #endif 119 #ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_ 120 #include <com/sun/star/frame/FrameSearchFlag.hpp> 121 #endif 122 #ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_ 123 #include <com/sun/star/frame/XComponentLoader.hpp> 124 #endif 125 #ifndef _COM_SUN_STAR_FRAME_XMODEL_HPP_ 126 #include <com/sun/star/frame/XModel.hpp> 127 #endif 128 #ifndef _COM_SUN_STAR_UCB_XSIMPLEFILEACCESS_HPP_ 129 #include <com/sun/star/ucb/XSimpleFileAccess.hpp> 130 #endif 131 #ifndef _COM_SUN_STAR_TASK_XJOBEXECUTOR_HPP_ 132 #include <com/sun/star/task/XJobExecutor.hpp> 133 #endif 134 #ifndef _COM_SUN_STAR_LANG_XINITIALIZATION_HPP_ 135 #include <com/sun/star/lang/XInitialization.hpp> 136 #endif 137 #ifndef _COM_SUN_STAR_SDB_COMMANDTYPE_HPP_ 138 #include <com/sun/star/sdb/CommandType.hpp> 139 #endif 140 #ifndef _COM_SUN_STAR_UCB_INTERACTIVEIOEXCEPTION_HPP_ 141 #include <com/sun/star/ucb/InteractiveIOException.hpp> 142 #endif 143 #ifndef _COM_SUN_STAR_IO_IOEXCEPTION_HPP_ 144 #include <com/sun/star/io/IOException.hpp> 145 #endif 146 #ifndef _COM_SUN_STAR_FRAME_XTERMINATELISTENER_HPP_ 147 #include <com/sun/star/frame/XTerminateListener.hpp> 148 #endif 149 #ifndef _COM_SUN_STAR_FRAME_XDESKTOP_HPP_ 150 #include <com/sun/star/frame/XDesktop.hpp> 151 #endif 152 #ifndef _COM_SUN_STAR_SDBC_XDRIVERACCESS_HPP_ 153 #include <com/sun/star/sdbc/XDriverAccess.hpp> 154 #endif 155 #ifndef _COM_SUN_STAR_DOCUMENT_MACROEXECMODE_HPP_ 156 #include <com/sun/star/document/MacroExecMode.hpp> 157 #endif 158 #include <com/sun/star/ucb/IOErrorCode.hpp> 159 #include <com/sun/star/task/XInteractionHandler2.hpp> 160 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> 161 162 163 /** === end UNO includes === **/ 164 165 #include <svl/filenotation.hxx> 166 #include <comphelper/interaction.hxx> 167 #include <comphelper/namedvaluecollection.hxx> 168 #include <comphelper/sequenceashashmap.hxx> 169 #include <tools/diagnose_ex.h> 170 #include <connectivity/DriversConfig.hxx> 171 172 #include <memory> 173 174 175 //......................................................................... 176 namespace dbaui 177 { 178 //......................................................................... 179 using namespace dbtools; 180 using namespace svt; 181 using namespace com::sun::star; 182 using namespace com::sun::star::uno; 183 using namespace com::sun::star::sdbc; 184 using namespace com::sun::star::sdbcx; 185 using namespace com::sun::star::task; 186 using namespace com::sun::star::lang; 187 using namespace com::sun::star::io; 188 using namespace com::sun::star::util; 189 using namespace com::sun::star::beans; 190 using namespace com::sun::star::container; 191 using namespace com::sun::star::frame; 192 using namespace com::sun::star::ucb; 193 using namespace ::com::sun::star::sdb; 194 using namespace ::com::sun::star::document; 195 using namespace ::comphelper; 196 using namespace ::cppu; 197 198 #define START_PAGE 0 199 #define CONNECTION_PAGE 1 200 201 202 203 204 //#define DBASE_PATH 1 205 //#define TEXT_PATH 2 206 //#define MSACCESS_PATH 3 207 //#define LDAP_PATH 4 208 //#define ADABAS_PATH 5 209 //#define ADO_PATH 6 210 //#define JDBC_PATH 7 211 //#define ORACLE_PATH 8 212 //#define MYSQL_JDBC_PATH 9 213 //#define MYSQL_ODBC_PATH 10 214 //#define ODBC_PATH 11 215 //#define SPREADSHEET_PATH 12 216 //#define OUTLOOKEXP_PATH 13 217 //#define OUTLOOK_PATH 14 218 //#define MOZILLA_PATH 15 219 //#define EVOLUTION_PATH 16 220 //#define EVOLUTION_PATH_GROUPWISE 17 221 //#define EVOLUTION_PATH_LDAP 18 222 //#define KAB_PATH 19 223 //#define MACAB_PATH 20 224 //#define THUNDERBIRD_PATH 21 225 //#define CREATENEW_PATH 22 226 //#define USERDEFINED_PATH 23 227 //#define OPEN_DOC_PATH 24 228 //#define MSACCESS2007_PATH 25 229 //#define MYSQL_NATIVE_PATH 26 230 231 OFinalDBPageSetup* pFinalPage; 232 233 234 235 DBG_NAME(ODbTypeWizDialogSetup) 236 //========================================================================= 237 //= ODbTypeWizDialogSetup 238 //========================================================================= 239 //------------------------------------------------------------------------- 240 ODbTypeWizDialogSetup::ODbTypeWizDialogSetup(Window* _pParent 241 ,SfxItemSet* _pItems 242 ,const Reference< XMultiServiceFactory >& _rxORB 243 ,const ::com::sun::star::uno::Any& _aDataSourceName 244 ) 245 :svt::RoadmapWizard( _pParent, ModuleRes(DLG_DATABASE_WIZARD), 246 WZB_NEXT | WZB_PREVIOUS | WZB_FINISH | WZB_CANCEL | WZB_HELP ) 247 248 , m_pOutSet(NULL) 249 , m_bResetting(sal_False) 250 , m_bApplied(sal_False) 251 , m_bUIEnabled( sal_True ) 252 , m_bIsConnectable( sal_False) 253 , m_sRM_IntroText(ModuleRes(STR_PAGETITLE_INTROPAGE)) 254 , m_sRM_dBaseText(ModuleRes(STR_PAGETITLE_DBASE)) 255 , m_sRM_TextText(ModuleRes(STR_PAGETITLE_TEXT)) 256 , m_sRM_MSAccessText(ModuleRes(STR_PAGETITLE_MSACCESS)) 257 , m_sRM_LDAPText(ModuleRes(STR_PAGETITLE_LDAP)) 258 , m_sRM_ADABASText(ModuleRes(STR_PAGETITLE_ADABAS)) 259 , m_sRM_ADOText(ModuleRes(STR_PAGETITLE_ADO)) 260 , m_sRM_JDBCText(ModuleRes(STR_PAGETITLE_JDBC)) 261 , m_sRM_MySQLNativePageTitle(ModuleRes(STR_PAGETITLE_MYSQL_NATIVE)) 262 , m_pGeneralPage( NULL ) 263 , m_pMySQLIntroPage(NULL) 264 , m_pCollection( NULL ) 265 { 266 DBG_CTOR(ODbTypeWizDialogSetup,NULL); 267 // no local resources needed anymore 268 m_sRM_MySQLText = String(ModuleRes(STR_PAGETITLE_MYSQL)); 269 m_sRM_OracleText = String(ModuleRes(STR_PAGETITLE_ORACLE)); 270 m_sRM_ODBCText = String(ModuleRes(STR_PAGETITLE_ODBC)); 271 m_sRM_SpreadSheetText = String(ModuleRes(STR_PAGETITLE_SPREADSHEET)); 272 m_sRM_AuthentificationText = String(ModuleRes(STR_PAGETITLE_AUTHENTIFICATION)); 273 m_sRM_FinalText = String(ModuleRes(STR_PAGETITLE_FINAL)); 274 m_sWorkPath = SvtPathOptions().GetWorkPath(); 275 pFinalPage = NULL; 276 // extract the datasource type collection from the item set 277 DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _pItems->GetItem(DSID_TYPECOLLECTION)); 278 if (pCollectionItem) 279 m_pCollection = pCollectionItem->getCollection(); 280 281 DBG_ASSERT(m_pCollection, "ODbTypeWizDialogSetup::ODbTypeWizDialogSetup : really need a DSN type collection !"); 282 283 FreeResource(); 284 285 m_pImpl = ::std::auto_ptr<ODbDataSourceAdministrationHelper>(new ODbDataSourceAdministrationHelper(_rxORB,this,this)); 286 m_pImpl->setDataSourceOrName(_aDataSourceName); 287 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource(); 288 m_pOutSet = new SfxItemSet( *_pItems->GetPool(), _pItems->GetRanges() ); 289 290 m_pImpl->translateProperties(xDatasource, *m_pOutSet); 291 // eType = m_pImpl->getDatasourceType(*m_pOutSet); 292 293 SetPageSizePixel(LogicToPixel(::Size(WIZARD_PAGE_X, WIZARD_PAGE_Y), MAP_APPFONT)); 294 ShowButtonFixedLine(sal_True); 295 defaultButton(WZB_NEXT); 296 enableButtons(WZB_FINISH, sal_True); 297 enableAutomaticNextButtonState(); 298 299 ::dbaccess::ODsnTypeCollection::TypeIterator aIter = m_pCollection->begin(); 300 ::dbaccess::ODsnTypeCollection::TypeIterator aEnd = m_pCollection->end(); 301 for(PathId i = 1;aIter != aEnd;++aIter,++i) 302 { 303 const ::rtl::OUString sURLPrefix = aIter.getURLPrefix(); 304 svt::RoadmapWizardTypes::WizardPath aPath; 305 aPath.push_back(PAGE_DBSETUPWIZARD_INTRO); 306 m_pCollection->fillPageIds(sURLPrefix,aPath); 307 aPath.push_back(PAGE_DBSETUPWIZARD_AUTHENTIFICATION); 308 aPath.push_back(PAGE_DBSETUPWIZARD_FINAL); 309 310 declareAuthDepPath(sURLPrefix,i,aPath); 311 } 312 313 svt::RoadmapWizardTypes::WizardPath aPath; 314 aPath.push_back(PAGE_DBSETUPWIZARD_INTRO); 315 declarePath( static_cast<PathId>(m_pCollection->size()+1), aPath); 316 317 m_pPrevPage->SetHelpId(HID_DBWIZ_PREVIOUS); 318 m_pNextPage->SetHelpId(HID_DBWIZ_NEXT); 319 m_pCancel->SetHelpId(HID_DBWIZ_CANCEL); 320 m_pFinish->SetHelpId(HID_DBWIZ_FINISH); 321 m_pHelp->SetUniqueId(UID_DBWIZ_HELP); 322 SetRoadmapInteractive( sal_True ); 323 ActivatePage(); 324 } 325 326 void ODbTypeWizDialogSetup::declareAuthDepPath( const ::rtl::OUString& _sURL, PathId _nPathId, const svt::RoadmapWizardTypes::WizardPath& _rPaths) 327 { 328 bool bHasAuthentication = DataSourceMetaData::getAuthentication( _sURL ) != AuthNone; 329 330 // collect the elements of the path 331 WizardPath aPath; 332 333 svt::RoadmapWizardTypes::WizardPath::const_iterator aIter = _rPaths.begin(); 334 svt::RoadmapWizardTypes::WizardPath::const_iterator aEnd = _rPaths.end(); 335 for(;aIter != aEnd;++aIter) 336 { 337 if ( bHasAuthentication || ( *aIter != PAGE_DBSETUPWIZARD_AUTHENTIFICATION ) ) 338 aPath.push_back( *aIter ); 339 } // for(;aIter != aEnd;++aIter) 340 341 // call base method 342 ::svt::RoadmapWizard::declarePath( _nPathId, aPath ); 343 } 344 345 String ODbTypeWizDialogSetup::getStateDisplayName( WizardState _nState ) const 346 { 347 String sRoadmapItem; 348 switch( _nState ) 349 { 350 case PAGE_DBSETUPWIZARD_INTRO: 351 sRoadmapItem = m_sRM_IntroText; 352 break; 353 354 case PAGE_DBSETUPWIZARD_DBASE: 355 sRoadmapItem = m_sRM_dBaseText; 356 break; 357 case PAGE_DBSETUPWIZARD_ADO: 358 sRoadmapItem = m_sRM_ADOText; 359 break; 360 case PAGE_DBSETUPWIZARD_TEXT: 361 sRoadmapItem = m_sRM_TextText; 362 break; 363 case PAGE_DBSETUPWIZARD_MSACCESS: 364 sRoadmapItem = m_sRM_MSAccessText; 365 break; 366 case PAGE_DBSETUPWIZARD_LDAP: 367 sRoadmapItem = m_sRM_LDAPText; 368 break; 369 case PAGE_DBSETUPWIZARD_ADABAS: 370 sRoadmapItem = m_sRM_ADABASText; 371 break; 372 case PAGE_DBSETUPWIZARD_JDBC: 373 sRoadmapItem = m_sRM_JDBCText; 374 break; 375 case PAGE_DBSETUPWIZARD_ORACLE: 376 sRoadmapItem = m_sRM_OracleText; 377 break; 378 case PAGE_DBSETUPWIZARD_MYSQL_INTRO: 379 sRoadmapItem = m_sRM_MySQLText; 380 break; 381 case PAGE_DBSETUPWIZARD_MYSQL_JDBC: 382 sRoadmapItem = m_sRM_JDBCText; 383 break; 384 case PAGE_DBSETUPWIZARD_MYSQL_NATIVE: 385 sRoadmapItem = m_sRM_MySQLNativePageTitle; 386 break; 387 case PAGE_DBSETUPWIZARD_MYSQL_ODBC: 388 sRoadmapItem = m_sRM_ODBCText; 389 break; 390 case PAGE_DBSETUPWIZARD_ODBC: 391 sRoadmapItem = m_sRM_ODBCText; 392 break; 393 case PAGE_DBSETUPWIZARD_SPREADSHEET: 394 sRoadmapItem = m_sRM_SpreadSheetText; 395 break; 396 case PAGE_DBSETUPWIZARD_AUTHENTIFICATION: 397 sRoadmapItem = m_sRM_AuthentificationText; 398 break; 399 case PAGE_DBSETUPWIZARD_USERDEFINED: 400 { 401 LocalResourceAccess aDummy(DLG_DATABASE_ADMINISTRATION, RSC_TABDIALOG); 402 sRoadmapItem = String(ModuleRes(STR_PAGETITLE_CONNECTION)); 403 } 404 break; 405 case PAGE_DBSETUPWIZARD_FINAL: 406 sRoadmapItem = m_sRM_FinalText; 407 break; 408 default: 409 break; 410 } 411 return sRoadmapItem; 412 } 413 414 //------------------------------------------------------------------------- 415 ODbTypeWizDialogSetup::~ODbTypeWizDialogSetup() 416 { 417 delete m_pOutSet; 418 DBG_DTOR(ODbTypeWizDialogSetup,NULL); 419 } 420 421 //------------------------------------------------------------------------- 422 IMPL_LINK(ODbTypeWizDialogSetup, OnTypeSelected, OGeneralPage*, /*_pTabPage*/) 423 { 424 activateDatabasePath(); 425 return 1L; 426 } 427 428 void lcl_removeUnused(const ::comphelper::NamedValueCollection& _aOld,const ::comphelper::NamedValueCollection& _aNew,::comphelper::NamedValueCollection& _rDSInfo) 429 { 430 _rDSInfo.merge(_aNew,true); 431 uno::Sequence< beans::NamedValue > aOldValues = _aOld.getNamedValues(); 432 const beans::NamedValue* pIter = aOldValues.getConstArray(); 433 const beans::NamedValue* pEnd = pIter + aOldValues.getLength(); 434 for(;pIter != pEnd;++pIter) 435 { 436 if ( !_aNew.has(pIter->Name) ) 437 { 438 _rDSInfo.remove(pIter->Name); 439 } 440 } 441 } 442 // ----------------------------------------------------------------------------- 443 void DataSourceInfoConverter::convert(const ::dbaccess::ODsnTypeCollection* _pCollection,const ::rtl::OUString& _sOldURLPrefix,const ::rtl::OUString& _sNewURLPrefix,const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _xDatasource) 444 { 445 if ( _pCollection->getPrefix(_sOldURLPrefix) == _pCollection->getPrefix(_sNewURLPrefix) ) 446 return ; 447 uno::Sequence< beans::PropertyValue> aInfo; 448 _xDatasource->getPropertyValue(PROPERTY_INFO) >>= aInfo; 449 ::comphelper::NamedValueCollection aDS(aInfo); 450 451 ::connectivity::DriversConfig aDriverConfig(m_xFactory); 452 453 const ::comphelper::NamedValueCollection& aOldProperties = aDriverConfig.getProperties(_sOldURLPrefix); 454 const ::comphelper::NamedValueCollection& aNewProperties = aDriverConfig.getProperties(_sNewURLPrefix); 455 lcl_removeUnused(aOldProperties,aNewProperties,aDS); 456 457 aDS >>= aInfo; 458 _xDatasource->setPropertyValue(PROPERTY_INFO,uno::makeAny(aInfo)); 459 } 460 //------------------------------------------------------------------------- 461 void ODbTypeWizDialogSetup::activateDatabasePath() 462 { 463 switch ( m_pGeneralPage->GetDatabaseCreationMode() ) 464 { 465 case OGeneralPage::eCreateNew: 466 { 467 sal_Int32 nCreateNewDBIndex = m_pCollection->getIndexOf( m_pCollection->getEmbeddedDatabase() ); 468 if ( nCreateNewDBIndex == -1 ) 469 nCreateNewDBIndex = m_pCollection->getIndexOf( ::rtl::OUString::createFromAscii( "sdbc:dbase:" ) ); 470 OSL_ENSURE( nCreateNewDBIndex != -1, "ODbTypeWizDialogSetup::activateDatabasePath: the GeneralPage should have prevented this!" ); 471 activatePath( static_cast< PathId >( nCreateNewDBIndex + 1 ), sal_True ); 472 473 enableState(PAGE_DBSETUPWIZARD_FINAL, sal_True ); 474 enableButtons( WZB_FINISH, sal_True); 475 } 476 break; 477 case OGeneralPage::eConnectExternal: 478 { 479 ::rtl::OUString sOld = m_sURL; 480 DataSourceInfoConverter aConverter(getORB()); 481 m_sURL = m_pGeneralPage->GetSelectedType(); 482 aConverter.convert(m_pCollection,sOld,m_sURL,m_pImpl->getCurrentDataSource()); 483 ::dbaccess::DATASOURCE_TYPE eType = VerifyDataSourceType(m_pCollection->determineType(m_sURL)); 484 if (eType == ::dbaccess::DST_UNKNOWN) 485 eType = m_pCollection->determineType(m_sOldURL); 486 487 activatePath( static_cast<PathId>(m_pCollection->getIndexOf(m_sURL) + 1), sal_True); 488 updateTypeDependentStates(); 489 } 490 break; 491 case OGeneralPage::eOpenExisting: 492 { 493 activatePath( static_cast<PathId>(m_pCollection->size() + 1), sal_True ); 494 enableButtons( WZB_FINISH, m_pGeneralPage->GetSelectedDocument().sURL.Len() != 0 ); 495 } 496 break; 497 default: 498 DBG_ERROR( "ODbTypeWizDialogSetup::activateDatabasePath: unknown creation mode!" ); 499 } 500 501 enableButtons( WZB_NEXT, m_pGeneralPage->GetDatabaseCreationMode() != OGeneralPage::eOpenExisting ); 502 // TODO: this should go into the base class. Point is, we activate a path whose *last* 503 // step is also the current one. The base class should automatically disable 504 // the Next button in such a case. However, not for this patch ... 505 } 506 507 //------------------------------------------------------------------------- 508 void ODbTypeWizDialogSetup::updateTypeDependentStates() 509 { 510 sal_Bool bDoEnable = sal_False; 511 sal_Bool bIsConnectionRequired = IsConnectionUrlRequired(); 512 if (!bIsConnectionRequired) 513 { 514 bDoEnable = sal_True; 515 } 516 else if ( m_sURL == m_sOldURL ) 517 { 518 bDoEnable = m_bIsConnectable; 519 } 520 enableState(PAGE_DBSETUPWIZARD_AUTHENTIFICATION, bDoEnable); 521 enableState(PAGE_DBSETUPWIZARD_FINAL, bDoEnable ); 522 enableButtons( WZB_FINISH, bDoEnable); 523 } 524 525 526 //------------------------------------------------------------------------- 527 sal_Bool ODbTypeWizDialogSetup::IsConnectionUrlRequired() 528 { 529 return m_pCollection->isConnectionUrlRequired(m_sURL); 530 } 531 532 //------------------------------------------------------------------------- 533 void ODbTypeWizDialogSetup::resetPages(const Reference< XPropertySet >& _rxDatasource) 534 { 535 // remove all items which relate to indirect properties from the input set 536 // (without this, the following may happen: select an arbitrary data source where some indirect properties 537 // are set. Select another data source of the same type, where the indirect props are not set (yet). Then, 538 // the indirect property values of the first ds are shown in the second ds ...) 539 const ODbDataSourceAdministrationHelper::MapInt2String& rMap = m_pImpl->getIndirectProperties(); 540 for ( ODbDataSourceAdministrationHelper::ConstMapInt2StringIterator aIndirect = rMap.begin(); 541 aIndirect != rMap.end(); 542 ++aIndirect 543 ) 544 getWriteOutputSet()->ClearItem( (sal_uInt16)aIndirect->first ); 545 546 // extract all relevant data from the property set of the data source 547 m_pImpl->translateProperties(_rxDatasource, *getWriteOutputSet()); 548 } 549 // ----------------------------------------------------------------------------- 550 const SfxItemSet* ODbTypeWizDialogSetup::getOutputSet() const 551 { 552 return m_pOutSet; 553 } 554 // ----------------------------------------------------------------------------- 555 SfxItemSet* ODbTypeWizDialogSetup::getWriteOutputSet() 556 { 557 return m_pOutSet; 558 } 559 // ----------------------------------------------------------------------------- 560 ::std::pair< Reference<XConnection>,sal_Bool> ODbTypeWizDialogSetup::createConnection() 561 { 562 return m_pImpl->createConnection(); 563 } 564 // ----------------------------------------------------------------------------- 565 Reference< XMultiServiceFactory > ODbTypeWizDialogSetup::getORB() const 566 { 567 return m_pImpl->getORB(); 568 } 569 // ----------------------------------------------------------------------------- 570 Reference< XDriver > ODbTypeWizDialogSetup::getDriver() 571 { 572 return m_pImpl->getDriver(); 573 } 574 575 576 ::dbaccess::DATASOURCE_TYPE ODbTypeWizDialogSetup::VerifyDataSourceType(const ::dbaccess::DATASOURCE_TYPE _DatabaseType) const 577 { 578 ::dbaccess::DATASOURCE_TYPE LocDatabaseType = _DatabaseType; 579 if ((LocDatabaseType == ::dbaccess::DST_MYSQL_JDBC) || (LocDatabaseType == ::dbaccess::DST_MYSQL_ODBC) || (LocDatabaseType == ::dbaccess::DST_MYSQL_NATIVE)) 580 { 581 if (m_pMySQLIntroPage != NULL) 582 { 583 switch( m_pMySQLIntroPage->getMySQLMode() ) 584 { 585 case OMySQLIntroPageSetup::VIA_JDBC: 586 return ::dbaccess::DST_MYSQL_JDBC; 587 case OMySQLIntroPageSetup::VIA_NATIVE: 588 return ::dbaccess::DST_MYSQL_NATIVE; 589 case OMySQLIntroPageSetup::VIA_ODBC: 590 return ::dbaccess::DST_MYSQL_ODBC; 591 } 592 } 593 } 594 return LocDatabaseType; 595 } 596 597 598 599 // ----------------------------------------------------------------------------- 600 ::rtl::OUString ODbTypeWizDialogSetup::getDatasourceType(const SfxItemSet& _rSet) const 601 { 602 ::rtl::OUString sRet = m_pImpl->getDatasourceType(_rSet); 603 if (m_pMySQLIntroPage != NULL && m_pMySQLIntroPage->IsVisible() ) 604 { 605 switch( m_pMySQLIntroPage->getMySQLMode() ) 606 { 607 case OMySQLIntroPageSetup::VIA_JDBC: 608 sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:")); 609 break; 610 case OMySQLIntroPageSetup::VIA_NATIVE: 611 sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:")); 612 break; 613 case OMySQLIntroPageSetup::VIA_ODBC: 614 sRet = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:")); 615 break; 616 } 617 } 618 return sRet; 619 } 620 621 // ----------------------------------------------------------------------------- 622 void ODbTypeWizDialogSetup::clearPassword() 623 { 624 m_pImpl->clearPassword(); 625 } 626 627 // ----------------------------------------------------------------------------- 628 TabPage* ODbTypeWizDialogSetup::createPage(WizardState _nState) 629 { 630 SfxTabPage* pFirstPage; 631 OGenericAdministrationPage* pPage = NULL; 632 switch(_nState) 633 { 634 case PAGE_DBSETUPWIZARD_INTRO: 635 pFirstPage = OGeneralPage::Create(this,*m_pOutSet, sal_True); 636 pPage = static_cast<OGenericAdministrationPage*> (pFirstPage); 637 m_pGeneralPage = static_cast<OGeneralPage*>(pFirstPage); 638 m_pGeneralPage->SetTypeSelectHandler(LINK(this, ODbTypeWizDialogSetup, OnTypeSelected)); 639 m_pGeneralPage->SetCreationModeHandler(LINK( this, ODbTypeWizDialogSetup, OnChangeCreationMode ) ); 640 m_pGeneralPage->SetDocumentSelectionHandler(LINK( this, ODbTypeWizDialogSetup, OnRecentDocumentSelected ) ); 641 m_pGeneralPage->SetChooseDocumentHandler(LINK( this, ODbTypeWizDialogSetup, OnSingleDocumentChosen ) ); 642 break; 643 644 case PAGE_DBSETUPWIZARD_DBASE: 645 pPage = OConnectionTabPageSetup::CreateDbaseTabPage(this,*m_pOutSet); 646 break; 647 648 case PAGE_DBSETUPWIZARD_ADO: 649 pPage = OConnectionTabPageSetup::CreateADOTabPage( this, *m_pOutSet); 650 break; 651 652 case PAGE_DBSETUPWIZARD_TEXT: 653 pPage = OTextConnectionPageSetup::CreateTextTabPage(this,*m_pOutSet); 654 break; 655 656 case PAGE_DBSETUPWIZARD_ODBC: 657 pPage = OConnectionTabPageSetup::CreateODBCTabPage( this, *m_pOutSet); 658 break; 659 660 case PAGE_DBSETUPWIZARD_JDBC: 661 pPage = OJDBCConnectionPageSetup::CreateJDBCTabPage( this, *m_pOutSet); 662 break; 663 664 case PAGE_DBSETUPWIZARD_MYSQL_ODBC: 665 m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:"))))); 666 pPage = OConnectionTabPageSetup::CreateODBCTabPage( this, *m_pOutSet); 667 break; 668 669 case PAGE_DBSETUPWIZARD_MYSQL_JDBC: 670 m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:"))))); 671 pPage = OGeneralSpecialJDBCConnectionPageSetup::CreateMySQLJDBCTabPage( this, *m_pOutSet); 672 break; 673 case PAGE_DBSETUPWIZARD_MYSQL_NATIVE: 674 m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, m_pCollection->getPrefix(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:"))))); 675 pPage = MySQLNativeSetupPage::Create( this, *m_pOutSet); 676 break; 677 678 case PAGE_DBSETUPWIZARD_ORACLE: 679 pPage = OGeneralSpecialJDBCConnectionPageSetup::CreateOracleJDBCTabPage( this, *m_pOutSet); 680 break; 681 682 case PAGE_DBSETUPWIZARD_ADABAS: 683 pPage = OConnectionTabPageSetup::CreateAdabasTabPage( this, *m_pOutSet); 684 break; 685 686 case PAGE_DBSETUPWIZARD_LDAP : 687 pPage = OLDAPConnectionPageSetup::CreateLDAPTabPage(this,*m_pOutSet); 688 break; 689 690 case PAGE_DBSETUPWIZARD_SPREADSHEET: /// first user defined driver 691 pPage = OSpreadSheetConnectionPageSetup::CreateSpreadSheetTabPage(this,*m_pOutSet); 692 break; 693 694 case PAGE_DBSETUPWIZARD_MSACCESS: 695 pPage = OConnectionTabPageSetup::CreateMSAccessTabPage(this,*m_pOutSet); 696 break; 697 case PAGE_DBSETUPWIZARD_MYSQL_INTRO: 698 m_pMySQLIntroPage = OMySQLIntroPageSetup::CreateMySQLIntroTabPage(this,*m_pOutSet); 699 m_pMySQLIntroPage->SetClickHdl(LINK( this, ODbTypeWizDialogSetup, ImplClickHdl ) ); 700 pPage = m_pMySQLIntroPage; 701 break; 702 703 case PAGE_DBSETUPWIZARD_AUTHENTIFICATION: 704 pPage = OAuthentificationPageSetup::CreateAuthentificationTabPage(this,*m_pOutSet); 705 break; 706 707 case PAGE_DBSETUPWIZARD_USERDEFINED: 708 pPage = OConnectionTabPageSetup::CreateUserDefinedTabPage(this,*m_pOutSet); 709 break; 710 711 case PAGE_DBSETUPWIZARD_FINAL: 712 pPage = OFinalDBPageSetup::CreateFinalDBTabPageSetup(this,*m_pOutSet); 713 pFinalPage = static_cast<OFinalDBPageSetup*> (pPage); 714 break; 715 } 716 717 if ((_nState != PAGE_DBSETUPWIZARD_INTRO) && (_nState != PAGE_DBSETUPWIZARD_AUTHENTIFICATION)) 718 { 719 pPage->SetModifiedHandler(LINK( this, ODbTypeWizDialogSetup, ImplModifiedHdl ) ); 720 } 721 722 if ( pPage ) 723 { 724 pPage->SetServiceFactory(m_pImpl->getORB()); 725 pPage->SetAdminDialog(this, this); 726 727 defaultButton( _nState == PAGE_DBSETUPWIZARD_FINAL ? WZB_FINISH : WZB_NEXT ); 728 enableButtons( WZB_FINISH, _nState == PAGE_DBSETUPWIZARD_FINAL ); 729 enableButtons( WZB_NEXT, _nState == PAGE_DBSETUPWIZARD_FINAL ? sal_False : sal_True); 730 pPage->Show(); 731 } 732 return pPage; 733 } 734 735 736 IMPL_LINK(ODbTypeWizDialogSetup, ImplModifiedHdl, OGenericAdministrationPage*, _pConnectionPageSetup) 737 { 738 m_bIsConnectable = _pConnectionPageSetup->GetRoadmapStateValue( ); 739 enableState(PAGE_DBSETUPWIZARD_FINAL, m_bIsConnectable); 740 enableState(PAGE_DBSETUPWIZARD_AUTHENTIFICATION, m_bIsConnectable); 741 if (getCurrentState() == PAGE_DBSETUPWIZARD_FINAL) 742 enableButtons( WZB_FINISH, sal_True); 743 else 744 enableButtons( WZB_FINISH, m_bIsConnectable); 745 enableButtons( WZB_NEXT, m_bIsConnectable && (getCurrentState() != PAGE_DBSETUPWIZARD_FINAL)); 746 return sal_True; 747 } 748 749 750 // ----------------------------------------------------------------------------- 751 IMPL_LINK(ODbTypeWizDialogSetup, ImplClickHdl, OMySQLIntroPageSetup*, _pMySQLIntroPageSetup) 752 { 753 ::rtl::OUString sURLPrefix; 754 switch( _pMySQLIntroPageSetup->getMySQLMode() ) 755 { 756 case OMySQLIntroPageSetup::VIA_ODBC: 757 sURLPrefix = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:odbc:")); 758 break; 759 case OMySQLIntroPageSetup::VIA_JDBC: 760 sURLPrefix = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:jdbc:")); 761 break; 762 case OMySQLIntroPageSetup::VIA_NATIVE: 763 sURLPrefix = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:")); 764 break; 765 } // switch( _pMySQLIntroPageSetup->getMySQLMode() ) 766 activatePath( static_cast<PathId>(m_pCollection->getIndexOf(sURLPrefix) + 1), sal_True); 767 return sal_True; 768 } 769 770 // ----------------------------------------------------------------------------- 771 IMPL_LINK(ODbTypeWizDialogSetup, OnChangeCreationMode, OGeneralPage*, /*_pGeneralPage*/) 772 { 773 activateDatabasePath(); 774 return sal_True; 775 } 776 777 // ----------------------------------------------------------------------------- 778 IMPL_LINK(ODbTypeWizDialogSetup, OnRecentDocumentSelected, OGeneralPage*, /*_pGeneralPage*/) 779 { 780 enableButtons( WZB_FINISH, m_pGeneralPage->GetSelectedDocument().sURL.Len() != 0 ); 781 return 0L; 782 } 783 784 // ----------------------------------------------------------------------------- 785 IMPL_LINK(ODbTypeWizDialogSetup, OnSingleDocumentChosen, OGeneralPage*, /*_pGeneralPage*/) 786 { 787 if ( prepareLeaveCurrentState( eFinish ) ) 788 onFinish(); 789 return 0L; 790 } 791 792 // ----------------------------------------------------------------------------- 793 void ODbTypeWizDialogSetup::enterState(WizardState _nState) 794 { 795 m_sURL = m_pImpl->getDatasourceType(*m_pOutSet); 796 RoadmapWizard::enterState(_nState); 797 switch(_nState) 798 { 799 case PAGE_DBSETUPWIZARD_INTRO: 800 m_sOldURL = m_sURL; 801 break; 802 case PAGE_DBSETUPWIZARD_FINAL: 803 enableButtons( WZB_FINISH, sal_True); 804 if ( pFinalPage ) 805 pFinalPage->enableTableWizardCheckBox(m_pCollection->supportsTableCreation(m_sURL)); 806 break; 807 } 808 } 809 810 //------------------------------------------------------------------------- 811 sal_Bool ODbTypeWizDialogSetup::saveDatasource() 812 { 813 SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(getCurrentState())); 814 if ( pPage ) 815 pPage->FillItemSet(*m_pOutSet); 816 return sal_True; 817 } 818 819 820 // ----------------------------------------------------------------------------- 821 sal_Bool ODbTypeWizDialogSetup::leaveState(WizardState _nState) 822 { 823 if (_nState == PAGE_DBSETUPWIZARD_MYSQL_INTRO) 824 return sal_True; 825 if ( _nState == PAGE_DBSETUPWIZARD_INTRO && m_sURL != m_sOldURL ) 826 { 827 resetPages(m_pImpl->getCurrentDataSource()); 828 } 829 SfxTabPage* pPage = static_cast<SfxTabPage*>(WizardDialog::GetPage(_nState)); 830 return pPage && pPage->DeactivatePage(m_pOutSet) != 0; 831 } 832 833 // ----------------------------------------------------------------------------- 834 void ODbTypeWizDialogSetup::setTitle(const ::rtl::OUString& /*_sTitle*/) 835 { 836 DBG_ERROR( "ODbTypeWizDialogSetup::setTitle: not implemented!" ); 837 // why? 838 } 839 840 //------------------------------------------------------------------------- 841 void ODbTypeWizDialogSetup::enableConfirmSettings( bool _bEnable ) 842 { 843 (void)_bEnable; 844 } 845 846 //------------------------------------------------------------------------- 847 namespace 848 { 849 bool lcl_handle( const Reference< XInteractionHandler2 >& _rxHandler, const Any& _rRequest ) 850 { 851 OInteractionRequest* pRequest = new OInteractionRequest( _rRequest ); 852 Reference < XInteractionRequest > xRequest( pRequest ); 853 OInteractionAbort* pAbort = new OInteractionAbort; 854 pRequest->addContinuation( pAbort ); 855 856 return _rxHandler->handleInteractionRequest( xRequest ); 857 } 858 } 859 860 //------------------------------------------------------------------------- 861 sal_Bool ODbTypeWizDialogSetup::SaveDatabaseDocument() 862 { 863 Reference< XInteractionHandler2 > xHandler( getORB()->createInstance( SERVICE_TASK_INTERACTION_HANDLER ), UNO_QUERY ); 864 try 865 { 866 if (callSaveAsDialog() == sal_True) 867 { 868 m_pImpl->saveChanges(*m_pOutSet); 869 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource(); 870 Reference< XModel > xModel( getDataSourceOrModel( xDatasource ), UNO_QUERY_THROW ); 871 Reference< XStorable > xStore( xModel, UNO_QUERY_THROW ); 872 873 if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eCreateNew ) 874 CreateDatabase(); 875 876 ::comphelper::NamedValueCollection aArgs( xModel->getArgs() ); 877 aArgs.put( "Overwrite", sal_Bool( sal_True ) ); 878 aArgs.put( "InteractionHandler", xHandler ); 879 aArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG ); 880 881 ::rtl::OUString sPath = m_pImpl->getDocumentUrl( *m_pOutSet ); 882 xStore->storeAsURL( sPath, aArgs.getPropertyValues() ); 883 884 if ( !pFinalPage || pFinalPage->IsDatabaseDocumentToBeRegistered() ) 885 RegisterDataSourceByLocation( sPath ); 886 887 return sal_True; 888 } 889 } 890 catch ( const Exception& e ) 891 { 892 Any aError = ::cppu::getCaughtException(); 893 if ( xHandler.is() ) 894 { 895 if ( !lcl_handle( xHandler, aError ) ) 896 { 897 InteractiveIOException aRequest; 898 aRequest.Classification = InteractionClassification_ERROR; 899 if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() ) ) 900 // assume savint the document faile 901 aRequest.Code = IOErrorCode_CANT_WRITE; 902 else 903 aRequest.Code = IOErrorCode_GENERAL; 904 aRequest.Message = e.Message; 905 aRequest.Context = e.Context; 906 lcl_handle( xHandler, makeAny( aRequest ) ); 907 } 908 } 909 } 910 return sal_False; 911 } 912 // ------------------------------------------------------------------------ 913 sal_Bool ODbTypeWizDialogSetup::IsDatabaseDocumentToBeOpened() const 914 { 915 if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting ) 916 return sal_True; 917 918 if ( pFinalPage != NULL ) 919 return pFinalPage->IsDatabaseDocumentToBeOpened(); 920 921 return sal_True; 922 } 923 924 // ------------------------------------------------------------------------ 925 sal_Bool ODbTypeWizDialogSetup::IsTableWizardToBeStarted() const 926 { 927 if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting ) 928 return sal_False; 929 930 if ( pFinalPage != NULL ) 931 return pFinalPage->IsTableWizardToBeStarted(); 932 933 return sal_False; 934 } 935 936 //------------------------------------------------------------------------- 937 ::rtl::OUString ODbTypeWizDialogSetup::getDefaultDatabaseType() const 938 { 939 ::rtl::OUString sEmbeddedURL = m_pCollection->getEmbeddedDatabase(); 940 ::connectivity::DriversConfig aDriverConfig(getORB()); 941 try 942 { 943 if ( !aDriverConfig.getDriverFactoryName(sEmbeddedURL).getLength() || !m_pImpl->getDriver(sEmbeddedURL).is() ) 944 sEmbeddedURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:")); 945 } 946 catch(const Exception&) 947 { 948 sEmbeddedURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:")); 949 } 950 951 return sEmbeddedURL; 952 } 953 954 //------------------------------------------------------------------------- 955 void ODbTypeWizDialogSetup::CreateDatabase() 956 { 957 ::rtl::OUString sUrl; 958 ::rtl::OUString eType = getDefaultDatabaseType(); 959 if ( m_pCollection->isEmbeddedDatabase(eType) ) 960 { 961 sUrl = eType; 962 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource(); 963 OSL_ENSURE(xDatasource.is(),"DataSource is null!"); 964 if ( xDatasource.is() ) 965 xDatasource->setPropertyValue( PROPERTY_INFO, makeAny( m_pCollection->getDefaultDBSettings( eType ) ) ); 966 m_pImpl->translateProperties(xDatasource,*m_pOutSet); 967 } 968 else if ( m_pCollection->isFileSystemBased(eType) ) 969 { 970 Reference< XSimpleFileAccess > xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY); 971 INetURLObject aDBPathURL(m_sWorkPath); 972 aDBPathURL.Append(m_aDocURL.getBase()); 973 createUniqueFolderName(&aDBPathURL); 974 ::rtl::OUString sPrefix = eType; 975 sUrl = aDBPathURL.GetMainURL( INetURLObject::NO_DECODE); 976 xSimpleFileAccess->createFolder(sUrl); 977 //OFileNotation aFileNotation(sUrl); 978 //sUrl = aFileNotation.get(OFileNotation::N_SYSTEM); 979 sUrl = sPrefix.concat(sUrl); 980 } 981 m_pOutSet->Put(SfxStringItem(DSID_CONNECTURL, sUrl)); 982 m_pImpl->saveChanges(*m_pOutSet); 983 } 984 985 //------------------------------------------------------------------------- 986 void ODbTypeWizDialogSetup::RegisterDataSourceByLocation(const ::rtl::OUString& _sPath) 987 { 988 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource(); 989 Reference< XNamingService > xDatabaseContext(getORB()->createInstance(SERVICE_SDB_DATABASECONTEXT), UNO_QUERY); 990 Reference< XNameAccess > xNameAccessDatabaseContext(xDatabaseContext, UNO_QUERY); 991 INetURLObject aURL( _sPath ); 992 ::rtl::OUString sFilename = aURL.getBase( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); 993 ::rtl::OUString sDatabaseName = ::dbtools::createUniqueName(xNameAccessDatabaseContext, sFilename,sal_False); 994 xDatabaseContext->registerObject(sDatabaseName, xDatasource); 995 } 996 997 998 //------------------------------------------------------------------------- 999 sal_Bool ODbTypeWizDialogSetup::callSaveAsDialog() 1000 { 1001 sal_Bool bRet = sal_False; 1002 WinBits nBits(WB_STDMODAL|WB_SAVEAS); 1003 ::sfx2::FileDialogHelper aFileDlg( com::sun::star::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION, static_cast<sal_uInt32>(nBits), this); 1004 const SfxFilter* pFilter = getStandardDatabaseFilter(); 1005 if ( pFilter ) 1006 { 1007 INetURLObject aWorkURL( m_sWorkPath ); 1008 aFileDlg.SetDisplayFolder( aWorkURL.GetMainURL( INetURLObject::NO_DECODE )); 1009 1010 ::rtl::OUString sDefaultName = String( ModuleRes( STR_DATABASEDEFAULTNAME ) ); 1011 ::rtl::OUString sExtension = pFilter->GetDefaultExtension(); 1012 sDefaultName += sExtension.replaceAt( 0, 1, ::rtl::OUString() ); 1013 aWorkURL.Append( sDefaultName ); 1014 sDefaultName = createUniqueFileName( aWorkURL ); 1015 aFileDlg.SetFileName( sDefaultName ); 1016 1017 aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension()); 1018 aFileDlg.SetCurrentFilter(pFilter->GetUIName()); 1019 } 1020 if ( aFileDlg.Execute() == ERRCODE_NONE ) 1021 { 1022 m_aDocURL = INetURLObject(aFileDlg.GetPath()); 1023 1024 if( m_aDocURL.GetProtocol() != INET_PROT_NOT_VALID ) 1025 { 1026 ::rtl::OUString sFileName = m_aDocURL.GetMainURL( INetURLObject::NO_DECODE ); 1027 if ( ::utl::UCBContentHelper::IsDocument(sFileName) ) 1028 ::utl::UCBContentHelper::Kill(sFileName); 1029 m_pOutSet->Put(SfxStringItem(DSID_DOCUMENT_URL, sFileName)); 1030 bRet = sal_True; 1031 } 1032 } 1033 return bRet; 1034 } 1035 1036 //------------------------------------------------------------------------- 1037 void ODbTypeWizDialogSetup::createUniqueFolderName(INetURLObject* pURL) 1038 { 1039 Reference< XSimpleFileAccess > xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY); 1040 :: rtl::OUString sLastSegmentName = pURL->getName(); 1041 sal_Bool bFolderExists = sal_True; 1042 sal_Int32 i = 1; 1043 while (bFolderExists == sal_True) 1044 { 1045 bFolderExists = xSimpleFileAccess->isFolder(pURL->GetMainURL( INetURLObject::NO_DECODE )); 1046 if (bFolderExists == sal_True) 1047 { 1048 i++; 1049 pURL->setName(sLastSegmentName.concat(::rtl::OUString::valueOf(i))); 1050 } 1051 } 1052 } 1053 1054 //------------------------------------------------------------------------- 1055 String ODbTypeWizDialogSetup::createUniqueFileName(const INetURLObject& _rURL) 1056 { 1057 Reference< XSimpleFileAccess > xSimpleFileAccess(getORB()->createInstance(::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" )), UNO_QUERY); 1058 :: rtl::OUString sFilename = _rURL.getName(); 1059 ::rtl::OUString BaseName = _rURL.getBase(); 1060 ::rtl::OUString sExtension = _rURL.getExtension(); 1061 1062 sal_Bool bElementExists = sal_True; 1063 1064 INetURLObject aExistenceCheck( _rURL ); 1065 for ( sal_Int32 i = 1; bElementExists; ) 1066 { 1067 bElementExists = xSimpleFileAccess->exists( aExistenceCheck.GetMainURL( INetURLObject::NO_DECODE ) ); 1068 if ( bElementExists ) 1069 { 1070 aExistenceCheck.setBase( BaseName.concat( ::rtl::OUString::valueOf( i ) ) ); 1071 ++i; 1072 } 1073 } 1074 return aExistenceCheck.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); 1075 } 1076 // ----------------------------------------------------------------------------- 1077 IWizardPageController* ODbTypeWizDialogSetup::getPageController( TabPage* _pCurrentPage ) const 1078 { 1079 OGenericAdministrationPage* pPage = static_cast<OGenericAdministrationPage*>(_pCurrentPage); 1080 return pPage; 1081 } 1082 1083 // ----------------------------------------------------------------------------- 1084 namespace 1085 { 1086 // ............................................................................. 1087 typedef ::cppu::WeakImplHelper1 < XTerminateListener 1088 > AsyncLoader_Base; 1089 class AsyncLoader : public AsyncLoader_Base 1090 { 1091 private: 1092 Reference< XComponentLoader > m_xFrameLoader; 1093 Reference< XDesktop > m_xDesktop; 1094 Reference< XInteractionHandler > m_xInteractionHandler; 1095 ::rtl::OUString m_sURL; 1096 OAsyncronousLink m_aAsyncCaller; 1097 1098 public: 1099 AsyncLoader( const Reference< XMultiServiceFactory >& _rxORB, const ::rtl::OUString& _rURL ); 1100 1101 void doLoadAsync(); 1102 1103 // XTerminateListener 1104 virtual void SAL_CALL queryTermination( const EventObject& Event ) throw (TerminationVetoException, RuntimeException); 1105 virtual void SAL_CALL notifyTermination( const EventObject& Event ) throw (RuntimeException); 1106 // XEventListener 1107 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); 1108 1109 private: 1110 DECL_LINK( OnOpenDocument, void* ); 1111 }; 1112 1113 // ............................................................................. 1114 AsyncLoader::AsyncLoader( const Reference< XMultiServiceFactory >& _rxORB, const ::rtl::OUString& _rURL ) 1115 :m_sURL( _rURL ) 1116 ,m_aAsyncCaller( LINK( this, AsyncLoader, OnOpenDocument ) ) 1117 { 1118 try 1119 { 1120 m_xDesktop.set( _rxORB->createInstance( SERVICE_FRAME_DESKTOP ), UNO_QUERY_THROW ); 1121 m_xFrameLoader.set( m_xDesktop, UNO_QUERY_THROW ); 1122 m_xInteractionHandler.set( 1123 _rxORB->createInstance( 1124 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) ) 1125 ), 1126 UNO_QUERY_THROW ); 1127 } 1128 catch( const Exception& ) 1129 { 1130 DBG_UNHANDLED_EXCEPTION(); 1131 } 1132 } 1133 1134 // ............................................................................. 1135 void AsyncLoader::doLoadAsync() 1136 { 1137 OSL_ENSURE( !m_aAsyncCaller.IsRunning(), "AsyncLoader:doLoadAsync: already running!" ); 1138 1139 acquire(); 1140 try 1141 { 1142 if ( m_xDesktop.is() ) 1143 m_xDesktop->addTerminateListener( this ); 1144 } 1145 catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); } 1146 1147 m_aAsyncCaller.Call( NULL ); 1148 } 1149 1150 // ............................................................................. 1151 IMPL_LINK( AsyncLoader, OnOpenDocument, void*, /*_pEmptyArg*/ ) 1152 { 1153 try 1154 { 1155 if ( m_xFrameLoader.is() ) 1156 { 1157 ::comphelper::NamedValueCollection aLoadArgs; 1158 aLoadArgs.put( "InteractionHandler", m_xInteractionHandler ); 1159 aLoadArgs.put( "MacroExecutionMode", MacroExecMode::USE_CONFIG ); 1160 1161 Sequence< PropertyValue > aLoadArgPV; 1162 aLoadArgs >>= aLoadArgPV; 1163 1164 m_xFrameLoader->loadComponentFromURL( m_sURL, 1165 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ), 1166 FrameSearchFlag::ALL, 1167 aLoadArgPV 1168 ); 1169 } 1170 } 1171 catch( const Exception& ) 1172 { 1173 // do not assert. 1174 // Such an exception happens for instance of the to-be-loaded document does not exist anymore. 1175 } 1176 1177 try 1178 { 1179 if ( m_xDesktop.is() ) 1180 m_xDesktop->removeTerminateListener( this ); 1181 } 1182 catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); } 1183 1184 release(); 1185 return 0L; 1186 } 1187 1188 // ............................................................................. 1189 void SAL_CALL AsyncLoader::queryTermination( const EventObject& /*Event*/ ) throw (TerminationVetoException, RuntimeException) 1190 { 1191 throw TerminationVetoException(); 1192 } 1193 1194 // ............................................................................. 1195 void SAL_CALL AsyncLoader::notifyTermination( const EventObject& /*Event*/ ) throw (RuntimeException) 1196 { 1197 } 1198 // ............................................................................. 1199 void SAL_CALL AsyncLoader::disposing( const EventObject& /*Source*/ ) throw (RuntimeException) 1200 { 1201 } 1202 } 1203 1204 // ----------------------------------------------------------------------------- 1205 sal_Bool ODbTypeWizDialogSetup::onFinish() 1206 { 1207 if ( m_pGeneralPage->GetDatabaseCreationMode() == OGeneralPage::eOpenExisting ) 1208 { 1209 // we're not going to re-use the XModel we have - since the document the user 1210 // wants us to load could be a non-database document. Instead, we asynchronously 1211 // open the selected document. Thus, the wizard's return value is RET_CANCEL, 1212 // which means to not continue loading the database document 1213 if ( !OWizardMachine::Finnish( RET_CANCEL ) ) 1214 return sal_False; 1215 1216 Reference< XComponentLoader > xFrameLoader; 1217 try 1218 { 1219 AsyncLoader* pAsyncLoader = new AsyncLoader( getORB(), m_pGeneralPage->GetSelectedDocument().sURL ); 1220 ::rtl::Reference< AsyncLoader > xKeepAlive( pAsyncLoader ); 1221 pAsyncLoader->doLoadAsync(); 1222 } 1223 catch( const Exception& ) 1224 { 1225 DBG_UNHANDLED_EXCEPTION(); 1226 } 1227 1228 return sal_True; 1229 } 1230 1231 if (getCurrentState() != PAGE_DBSETUPWIZARD_FINAL) 1232 { 1233 skipUntil(PAGE_DBSETUPWIZARD_FINAL); 1234 } 1235 if (getCurrentState() == PAGE_DBSETUPWIZARD_FINAL) 1236 return SaveDatabaseDocument() ? OWizardMachine::onFinish() : sal_False; 1237 else 1238 { 1239 enableButtons( WZB_FINISH, sal_False ); 1240 return sal_False; 1241 } 1242 } 1243 1244 //......................................................................... 1245 } // namespace dbaui 1246 //......................................................................... 1247 1248