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 #ifndef DBAUI_CONNECTIONPAGE_HXX 28 #include "ConnectionPage.hxx" 29 #endif 30 #ifndef DBAUI_CONNECTIONPAGE_HRC 31 #include "ConnectionPage.hrc" 32 #endif 33 #ifndef _DBU_DLG_HRC_ 34 #include "dbu_dlg.hrc" 35 #endif 36 #ifndef DBACCESS_DSMETA_HXX 37 #include "dsmeta.hxx" 38 #endif 39 #ifndef _SFXITEMSET_HXX 40 #include <svl/itemset.hxx> 41 #endif 42 #ifndef INCLUDED_SVTOOLS_PATHOPTIONS_HXX 43 #include <unotools/pathoptions.hxx> 44 #endif 45 #ifndef _SFXSTRITEM_HXX 46 #include <svl/stritem.hxx> 47 #endif 48 #ifndef _SFXENUMITEM_HXX 49 #include <svl/eitem.hxx> 50 #endif 51 #ifndef _SFXINTITEM_HXX 52 #include <svl/intitem.hxx> 53 #endif 54 #ifndef INCLUDED_SVTOOLS_MODULEOPTIONS_HXX 55 #include <unotools/moduleoptions.hxx> 56 #endif 57 #ifndef _DBAUI_DATASOURCEITEMS_HXX_ 58 #include "dsitems.hxx" 59 #endif 60 #ifndef _DBA_DBACCESS_HELPID_HRC_ 61 #include "dbaccess_helpid.hrc" 62 #endif 63 #ifndef _DBAUI_LOCALRESACCESS_HXX_ 64 #include "localresaccess.hxx" 65 #endif 66 #ifndef _OSL_PROCESS_H_ 67 #include <osl/process.h> 68 #endif 69 #ifndef _SV_MSGBOX_HXX 70 #include <vcl/msgbox.hxx> 71 #endif 72 #ifndef _FILEDLGHELPER_HXX 73 #include <sfx2/filedlghelper.hxx> 74 #endif 75 #ifndef _DBAUI_DBADMIN_HXX_ 76 #include "dbadmin.hxx" 77 #endif 78 #ifndef _COMPHELPER_TYPES_HXX_ 79 #include <comphelper/types.hxx> 80 #endif 81 #ifndef _VCL_STDTEXT_HXX 82 #include <vcl/stdtext.hxx> 83 #endif 84 #ifndef _DBAUI_SQLMESSAGE_HXX_ 85 #include "sqlmessage.hxx" 86 #endif 87 #ifndef _DBAUI_ODBC_CONFIG_HXX_ 88 #include "odbcconfig.hxx" 89 #endif 90 #ifndef _DBAUI_DSSELECT_HXX_ 91 #include "dsselect.hxx" 92 #endif 93 #ifndef SVTOOLS_FILENOTATION_HXX_ 94 #include <svl/filenotation.hxx> 95 #endif 96 #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC 97 #include "dbustrings.hrc" 98 #endif 99 #ifndef _COM_SUN_STAR_UI_DIALOGS_XFOLDERPICKER_HPP_ 100 #include <com/sun/star/ui/dialogs/XFolderPicker.hpp> 101 #endif 102 #ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ 103 #include <com/sun/star/sdbc/XRow.hpp> 104 #endif 105 #ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_ 106 #include <com/sun/star/awt/XWindow.hpp> 107 #endif 108 // #106016# ------------------------------------ 109 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_ 110 #include <com/sun/star/task/XInteractionHandler.hpp> 111 #endif 112 #ifndef _COM_SUN_STAR_TASK_XPROGRESSHANDLER_HPP_ 113 #include <com/sun/star/ucb/XProgressHandler.hpp> 114 #endif 115 #ifndef _COM_SUN_STAR_SDBC_XCONNECTION_HPP_ 116 #include <com/sun/star/sdbc/XConnection.hpp> 117 #endif 118 #ifndef _COM_SUN_STAR_UI_DIALOGS_EXTENDEDFILEPICKERELEMENTIDS_HPP_ 119 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> 120 #endif 121 #ifndef _COM_SUN_STAR_UI_DIALOGS_XFILEPICKERCONTROLACCESS_HPP_ 122 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp> 123 #endif 124 #ifndef _COM_SUN_STAR_UI_DIALOGS_XFILEPICKER_HPP_ 125 #include <com/sun/star/ui/dialogs/XFilePicker.hpp> 126 #endif 127 #ifndef DBAUI_TOOLS_HXX 128 #include "UITools.hxx" 129 #endif 130 #ifndef _UNOTOOLS_LOCALFILEHELPER_HXX 131 #include <unotools/localfilehelper.hxx> 132 #endif 133 #ifndef _UNOTOOLS_UCBHELPER_HXX 134 #include <unotools/ucbhelper.hxx> 135 #endif 136 #ifndef _UCBHELPER_COMMANDENVIRONMENT_HXX 137 #include <ucbhelper/commandenvironment.hxx> 138 #endif 139 #ifndef DBAUI_FILEPICKER_INTERACTION_HXX 140 #include "finteraction.hxx" 141 #endif 142 #ifndef _CONNECTIVITY_COMMONTOOLS_HXX_ 143 #include <connectivity/CommonTools.hxx> 144 #endif 145 #ifndef _URLOBJ_HXX 146 #include <tools/urlobj.hxx> 147 #endif 148 #ifndef _SFX_DOCFILT_HACK_HXX 149 #include <sfx2/docfilt.hxx> 150 #endif 151 #include "dsnItem.hxx" 152 #if defined(WNT) 153 #define _ADO_DATALINK_BROWSE_ 154 #endif 155 156 #ifdef _ADO_DATALINK_BROWSE_ 157 #if defined( WNT ) 158 #include <tools/prewin.h> 159 #include <windows.h> 160 #include <tools/postwin.h> 161 #endif 162 #ifndef _SV_SYSDATA_HXX 163 #include <vcl/sysdata.hxx> 164 #endif 165 #ifndef _DBAUI_ADO_DATALINK_HXX_ 166 #include "adodatalinks.hxx" 167 #endif 168 #endif //_ADO_DATALINK_BROWSE_ 169 170 #include "AutoControls.hrc" 171 172 //......................................................................... 173 namespace dbaui 174 { 175 //......................................................................... 176 using namespace ::com::sun::star::uno; 177 using namespace ::com::sun::star::ucb; 178 using namespace ::com::sun::star::ui::dialogs; 179 using namespace ::com::sun::star::sdbc; 180 using namespace ::com::sun::star::beans; 181 using namespace ::com::sun::star::lang; 182 using namespace ::com::sun::star::container; 183 using namespace ::dbtools; 184 using namespace ::svt; 185 186 SfxTabPage* OConnectionTabPage::Create( Window* pParent, const SfxItemSet& _rAttrSet ) 187 { 188 return ( new OConnectionTabPage( pParent, _rAttrSet ) ); 189 } 190 //======================================================================== 191 //= OConnectionTabPage 192 //======================================================================== 193 DBG_NAME(OConnectionTabPage) 194 OConnectionTabPage::OConnectionTabPage(Window* pParent, const SfxItemSet& _rCoreAttrs) 195 :OConnectionHelper(pParent, ModuleRes(PAGE_CONNECTION), _rCoreAttrs) 196 ,m_bUserGrabFocus(sal_True) 197 ,m_aFL1(this, ModuleRes(FL_SEPARATOR1)) 198 ,m_aFL2(this, ModuleRes(FL_SEPARATOR2)) 199 ,m_aUserNameLabel(this, ModuleRes(FT_USERNAME)) 200 ,m_aUserName(this, ModuleRes(ET_USERNAME)) 201 ,m_aPasswordRequired(this, ModuleRes(CB_PASSWORD_REQUIRED)) 202 ,m_aFL3(this, ModuleRes(FL_SEPARATOR3)) 203 ,m_aJavaDriverLabel(this, ModuleRes(FT_JDBCDRIVERCLASS)) 204 ,m_aJavaDriver(this, ModuleRes(ET_JDBCDRIVERCLASS)) 205 ,m_aTestJavaDriver(this, ModuleRes(PB_TESTDRIVERCLASS)) 206 ,m_aTestConnection(this, ModuleRes(PB_TESTCONNECTION)) 207 { 208 DBG_CTOR(OConnectionTabPage,NULL); 209 m_aConnectionURL.SetModifyHdl(LINK(this, OConnectionTabPage, OnEditModified)); 210 m_aJavaDriver.SetModifyHdl(getControlModifiedLink()); 211 m_aJavaDriver.SetModifyHdl(LINK(this, OConnectionTabPage, OnEditModified)); 212 m_aUserName.SetModifyHdl(getControlModifiedLink()); 213 m_aPasswordRequired.SetClickHdl(getControlModifiedLink()); 214 215 m_aTestConnection.SetClickHdl(LINK(this,OGenericAdministrationPage,OnTestConnectionClickHdl)); 216 m_aTestJavaDriver.SetClickHdl(LINK(this,OConnectionTabPage,OnTestJavaClickHdl)); 217 218 FreeResource(); 219 220 LayoutHelper::fitSizeRightAligned( m_aTestConnection ); 221 } 222 223 // ----------------------------------------------------------------------- 224 OConnectionTabPage::~OConnectionTabPage() 225 { 226 DBG_DTOR(OConnectionTabPage,NULL); 227 } 228 229 // ----------------------------------------------------------------------- 230 void OConnectionTabPage::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue) 231 { 232 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa) 233 sal_Bool bValid, bReadonly; 234 getFlags(_rSet, bValid, bReadonly); 235 236 m_eType = m_pAdminDialog->getDatasourceType(_rSet); 237 OConnectionHelper::implInitControls( _rSet, _bSaveValue); 238 239 LocalResourceAccess aLocRes( PAGE_CONNECTION, RSC_TABPAGE ); 240 ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(m_eType); 241 switch( eType ) 242 { 243 case ::dbaccess::DST_DBASE: 244 m_aFT_Connection.SetText(String(ModuleRes(STR_DBASE_PATH_OR_FILE))); 245 m_aConnectionURL.SetHelpId(HID_DSADMIN_DBASE_PATH); 246 break; 247 case ::dbaccess::DST_FLAT: 248 m_aFT_Connection.SetText(String(ModuleRes(STR_FLAT_PATH_OR_FILE))); 249 m_aConnectionURL.SetHelpId(HID_DSADMIN_FLAT_PATH); 250 break; 251 case ::dbaccess::DST_CALC: 252 m_aFT_Connection.SetText(String(ModuleRes(STR_CALC_PATH_OR_FILE))); 253 m_aConnectionURL.SetHelpId(HID_DSADMIN_CALC_PATH); 254 break; 255 case ::dbaccess::DST_ADABAS: 256 m_aFT_Connection.SetText(String(ModuleRes(STR_ADABAS_DATABASE_NAME))); 257 m_aConnectionURL.SetHelpId(HID_DSADMIN_ADABAS_DATABASE); 258 break; 259 case ::dbaccess::DST_ADO: 260 m_aFT_Connection.SetText(String(ModuleRes(STR_COMMONURL))); 261 break; 262 case ::dbaccess::DST_MSACCESS: 263 case ::dbaccess::DST_MSACCESS_2007: 264 m_aFT_Connection.SetText(String(ModuleRes(STR_MSACCESS_MDB_FILE))); 265 m_aConnectionURL.SetHelpId(HID_DSADMIN_MSACCESS_MDB_FILE); 266 break; 267 case ::dbaccess::DST_MYSQL_NATIVE: 268 case ::dbaccess::DST_MYSQL_JDBC: 269 m_aFT_Connection.SetText(String(ModuleRes(STR_MYSQL_DATABASE_NAME))); 270 m_aConnectionURL.SetHelpId( HID_DSADMIN_MYSQL_DATABASE ); 271 break; 272 case ::dbaccess::DST_ORACLE_JDBC: 273 m_aFT_Connection.SetText(String(ModuleRes(STR_ORACLE_DATABASE_NAME))); 274 m_aConnectionURL.SetHelpId(HID_DSADMIN_ORACLE_DATABASE); 275 break; 276 case ::dbaccess::DST_MYSQL_ODBC: 277 case ::dbaccess::DST_ODBC: 278 m_aFT_Connection.SetText(String(ModuleRes(STR_NAME_OF_ODBC_DATASOURCE))); 279 m_aConnectionURL.SetHelpId( eType == ::dbaccess::DST_MYSQL_ODBC ? HID_DSADMIN_MYSQL_ODBC_DATASOURCE : HID_DSADMIN_ODBC_DATASOURCE); 280 break; 281 case ::dbaccess::DST_LDAP: 282 m_aFT_Connection.SetText(String(ModuleRes(STR_HOSTNAME))); 283 m_aConnectionURL.SetHelpId( HID_DSADMIN_LDAP_HOSTNAME ); 284 break; 285 case ::dbaccess::DST_MOZILLA: 286 m_aFT_Connection.SetText(String(ModuleRes(STR_MOZILLA_PROFILE_NAME))); 287 m_aConnectionURL.SetHelpId( HID_DSADMIN_MOZILLA_PROFILE_NAME ); 288 break; 289 case ::dbaccess::DST_THUNDERBIRD: 290 m_aFT_Connection.SetText(String(ModuleRes(STR_THUNDERBIRD_PROFILE_NAME))); 291 m_aConnectionURL.SetHelpId( HID_DSADMIN_THUNDERBIRD_PROFILE_NAME ); 292 break; 293 case ::dbaccess::DST_OUTLOOK: 294 case ::dbaccess::DST_OUTLOOKEXP: 295 case ::dbaccess::DST_EVOLUTION: 296 case ::dbaccess::DST_EVOLUTION_GROUPWISE: 297 case ::dbaccess::DST_EVOLUTION_LDAP: 298 case ::dbaccess::DST_KAB: 299 case ::dbaccess::DST_MACAB: 300 m_aFT_Connection.SetText(String(ModuleRes(STR_NO_ADDITIONAL_SETTINGS))); 301 { 302 String sText = m_aFT_Connection.GetText(); 303 sText.SearchAndReplaceAscii("%test",m_aTestConnection.GetText()); 304 String sTemp; 305 sText.SearchAndReplaceAscii("~",sTemp); 306 m_aFT_Connection.SetText(sText); 307 } 308 m_aConnectionURL.Hide(); 309 break; 310 case ::dbaccess::DST_JDBC: 311 default: 312 m_aFT_Connection.SetText(String(ModuleRes(STR_COMMONURL))); 313 break; 314 } 315 316 ; 317 AuthenticationMode eAuthMode( DataSourceMetaData::getAuthentication( m_eType ) ); 318 bool bShowUserAuthenfication = ( eAuthMode != AuthNone ); 319 bool bShowUser = ( eAuthMode == AuthUserPwd ); 320 321 m_aPB_Connection.SetHelpId(HID_DSADMIN_BROWSECONN); 322 m_aFL2.Show( bShowUserAuthenfication ); 323 m_aUserNameLabel.Show( bShowUser && bShowUserAuthenfication ); 324 m_aUserName.Show( bShowUser && bShowUserAuthenfication ); 325 m_aPasswordRequired.Show( bShowUserAuthenfication ); 326 if ( !bShowUser && bShowUserAuthenfication ) 327 m_aPasswordRequired.SetPosPixel(m_aUserNameLabel.GetPosPixel()); 328 329 // collect the items 330 SFX_ITEMSET_GET(_rSet, pUidItem, SfxStringItem, DSID_USER, sal_True); 331 332 SFX_ITEMSET_GET(_rSet, pJdbcDrvItem, SfxStringItem, DSID_JDBCDRIVERCLASS, sal_True); 333 SFX_ITEMSET_GET(_rSet, pUrlItem, SfxStringItem, DSID_CONNECTURL, sal_True); 334 SFX_ITEMSET_GET(_rSet, pAllowEmptyPwd, SfxBoolItem, DSID_PASSWORDREQUIRED, sal_True); 335 336 // forward the values to the controls 337 if ( bValid ) 338 { 339 m_aUserName.SetText(pUidItem->GetValue()); 340 m_aPasswordRequired.Check(pAllowEmptyPwd->GetValue()); 341 342 String sUrl = pUrlItem->GetValue(); 343 setURL( sUrl ); 344 345 const sal_Bool bEnableJDBC = m_pCollection->determineType(m_eType) == ::dbaccess::DST_JDBC; 346 if ( !pJdbcDrvItem->GetValue().Len() ) 347 { 348 String sDefaultJdbcDriverName = m_pCollection->getJavaDriverClass(m_eType); 349 if ( sDefaultJdbcDriverName.Len() ) 350 { 351 m_aJavaDriver.SetText(sDefaultJdbcDriverName); 352 m_aJavaDriver.SetModifyFlag(); 353 } 354 } // if ( !pJdbcDrvItem->GetValue().Len() ) 355 else 356 m_aJavaDriver.SetText(pJdbcDrvItem->GetValue()); 357 358 m_aJavaDriverLabel.Show(bEnableJDBC); 359 m_aJavaDriver.Show(bEnableJDBC); 360 m_aTestJavaDriver.Show(bEnableJDBC); 361 m_aTestJavaDriver.Enable( m_aJavaDriver.GetText().Len() != 0); 362 m_aFL3.Show(bEnableJDBC); 363 364 checkTestConnection(); 365 366 m_aUserName.ClearModifyFlag(); 367 m_aConnectionURL.ClearModifyFlag(); 368 m_aJavaDriver.ClearModifyFlag(); 369 } 370 } 371 // ----------------------------------------------------------------------- 372 void OConnectionTabPage::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList) 373 { 374 _rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aFL1)); 375 376 _rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aFL2)); 377 _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aJavaDriverLabel)); 378 _rControlList.push_back(new ODisableWrapper<PushButton>(&m_aTestJavaDriver)); 379 380 _rControlList.push_back(new ODisableWrapper<FixedLine>(&m_aFL3)); 381 _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aUserNameLabel)); 382 _rControlList.push_back(new ODisableWrapper<PushButton>(&m_aTestConnection)); 383 OConnectionHelper::fillWindows(_rControlList); 384 385 } 386 // ----------------------------------------------------------------------- 387 void OConnectionTabPage::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList) 388 { 389 _rControlList.push_back(new OSaveValueWrapper<Edit>(&m_aJavaDriver)); 390 _rControlList.push_back(new OSaveValueWrapper<Edit>(&m_aUserName)); 391 _rControlList.push_back(new OSaveValueWrapper<CheckBox>(&m_aPasswordRequired)); 392 OConnectionHelper::fillControls(_rControlList); 393 } 394 395 // ----------------------------------------------------------------------- 396 sal_Bool OConnectionTabPage::FillItemSet(SfxItemSet& _rSet) 397 { 398 sal_Bool bChangedSomething = sal_False; 399 400 if (m_aUserName.GetText() != m_aUserName.GetSavedValue()) 401 { 402 _rSet.Put(SfxStringItem(DSID_USER, m_aUserName.GetText())); 403 _rSet.Put(SfxStringItem(DSID_PASSWORD, String())); 404 bChangedSomething = sal_True; 405 } 406 407 fillBool(_rSet,&m_aPasswordRequired,DSID_PASSWORDREQUIRED,bChangedSomething); 408 409 if ( m_pCollection->determineType(m_eType) == ::dbaccess::DST_JDBC ) 410 { 411 fillString(_rSet,&m_aJavaDriver, DSID_JDBCDRIVERCLASS, bChangedSomething); 412 } 413 414 fillString(_rSet,&m_aConnectionURL, DSID_CONNECTURL, bChangedSomething); 415 416 return bChangedSomething; 417 } 418 // ----------------------------------------------------------------------- 419 IMPL_LINK(OConnectionTabPage, OnTestJavaClickHdl, PushButton*, /*_pButton*/) 420 { 421 OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF"); 422 sal_Bool bSuccess = sal_False; 423 try 424 { 425 if ( m_aJavaDriver.GetText().Len() ) 426 { 427 ::rtl::Reference< jvmaccess::VirtualMachine > xJVM = ::connectivity::getJavaVM(m_pAdminDialog->getORB()); 428 bSuccess = ::connectivity::existsJavaClassByName(xJVM,m_aJavaDriver.GetText()); 429 } 430 } 431 catch(Exception&) 432 { 433 } 434 435 sal_uInt16 nMessage = bSuccess ? STR_JDBCDRIVER_SUCCESS : STR_JDBCDRIVER_NO_SUCCESS; 436 OSQLMessageBox aMsg( this, String( ModuleRes( nMessage ) ), String() ); 437 aMsg.Execute(); 438 return 0L; 439 } 440 // ----------------------------------------------------------------------- 441 bool OConnectionTabPage::checkTestConnection() 442 { 443 OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF"); 444 sal_Bool bEnableTestConnection = !m_aConnectionURL.IsVisible() || (m_aConnectionURL.GetTextNoPrefix().Len() != 0); 445 if ( m_pCollection->determineType(m_eType) == ::dbaccess::DST_JDBC ) 446 bEnableTestConnection = bEnableTestConnection && (m_aJavaDriver.GetText().Len() != 0); 447 m_aTestConnection.Enable(bEnableTestConnection); 448 return true; 449 } 450 // ----------------------------------------------------------------------- 451 IMPL_LINK(OConnectionTabPage, OnEditModified, Edit*, _pEdit) 452 { 453 if ( _pEdit == &m_aJavaDriver ) 454 m_aTestJavaDriver.Enable( m_aJavaDriver.GetText().Len() != 0 ); 455 456 checkTestConnection(); 457 // tell the listener we were modified 458 callModifiedHdl(); 459 return 0L; 460 } 461 //......................................................................... 462 } // namespace dbaui 463 //......................................................................... 464 465