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 <config_java.h> 21 #include <core_resource.hxx> 22 #include "detailpages.hxx" 23 #include <sqlmessage.hxx> 24 #include <dsmeta.hxx> 25 #include "advancedsettings.hxx" 26 #include "DbAdminImpl.hxx" 27 #include <dsitems.hxx> 28 #include "dbfindex.hxx" 29 #include "dsnItem.hxx" 30 31 #include <dbu_dlg.hxx> 32 #include <strings.hrc> 33 34 #include <svl/itemset.hxx> 35 #include <svl/stritem.hxx> 36 #include <svl/eitem.hxx> 37 #include <svl/intitem.hxx> 38 #include <vcl/mnemonic.hxx> 39 #include <svl/cjkoptions.hxx> 40 #if HAVE_FEATURE_JAVA 41 #include <jvmaccess/virtualmachine.hxx> 42 #endif 43 #include <connectivity/CommonTools.hxx> 44 #include "DriverSettings.hxx" 45 #include <dbadmin.hxx> 46 47 namespace dbaui 48 { 49 50 using namespace ::com::sun::star::uno; 51 using namespace ::com::sun::star::sdbc; 52 using namespace ::com::sun::star::beans; 53 using namespace ::com::sun::star::lang; 54 using namespace ::com::sun::star::container; 55 using namespace ::dbtools; 56 OCommonBehaviourTabPage(weld::Container * pPage,weld::DialogController * pController,const OUString & rUIXMLDescription,const OString & rId,const SfxItemSet & rCoreAttrs,OCommonBehaviourTabPageFlags nControlFlags)57 OCommonBehaviourTabPage::OCommonBehaviourTabPage(weld::Container* pPage, weld::DialogController* pController, 58 const OUString& rUIXMLDescription, const OString& rId, const SfxItemSet& rCoreAttrs, 59 OCommonBehaviourTabPageFlags nControlFlags) 60 : OGenericAdministrationPage(pPage, pController, rUIXMLDescription, rId, rCoreAttrs) 61 , m_nControlFlags(nControlFlags) 62 { 63 if (m_nControlFlags & OCommonBehaviourTabPageFlags::UseOptions) 64 { 65 m_xOptionsLabel = m_xBuilder->weld_label("optionslabel"); 66 m_xOptionsLabel->show(); 67 m_xOptions = m_xBuilder->weld_entry("options"); 68 m_xOptions->show(); 69 m_xOptions->connect_changed(LINK(this,OGenericAdministrationPage,OnControlEntryModifyHdl)); 70 } 71 72 if (m_nControlFlags & OCommonBehaviourTabPageFlags::UseCharset) 73 { 74 m_xDataConvertLabel = m_xBuilder->weld_label("charsetheader"); 75 m_xDataConvertLabel->show(); 76 m_xCharsetLabel = m_xBuilder->weld_label("charsetlabel"); 77 m_xCharsetLabel->show(); 78 m_xCharset.reset(new CharSetListBox(m_xBuilder->weld_combo_box("charset"))); 79 m_xCharset->show(); 80 m_xCharset->connect_changed(LINK(this, OCommonBehaviourTabPage, CharsetSelectHdl)); 81 } 82 } 83 IMPL_LINK_NOARG(OCommonBehaviourTabPage,CharsetSelectHdl,weld::ComboBox &,void)84 IMPL_LINK_NOARG(OCommonBehaviourTabPage, CharsetSelectHdl, weld::ComboBox&, void) 85 { 86 callModifiedHdl(); 87 } 88 ~OCommonBehaviourTabPage()89 OCommonBehaviourTabPage::~OCommonBehaviourTabPage() 90 { 91 m_xCharset.reset(); 92 } 93 fillWindows(std::vector<std::unique_ptr<ISaveValueWrapper>> & _rControlList)94 void OCommonBehaviourTabPage::fillWindows(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList) 95 { 96 if (m_nControlFlags & OCommonBehaviourTabPageFlags::UseOptions) 97 { 98 _rControlList.emplace_back(new ODisableWidgetWrapper<weld::Label>(m_xOptionsLabel.get())); 99 } 100 101 if (m_nControlFlags & OCommonBehaviourTabPageFlags::UseCharset) 102 { 103 _rControlList.emplace_back(new ODisableWidgetWrapper<weld::Label>(m_xCharsetLabel.get())); 104 } 105 } 106 fillControls(std::vector<std::unique_ptr<ISaveValueWrapper>> & _rControlList)107 void OCommonBehaviourTabPage::fillControls(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList) 108 { 109 if (m_nControlFlags & OCommonBehaviourTabPageFlags::UseOptions) 110 _rControlList.emplace_back(new OSaveValueWidgetWrapper<weld::Entry>(m_xOptions.get())); 111 112 if (m_nControlFlags & OCommonBehaviourTabPageFlags::UseCharset) 113 _rControlList.emplace_back(new OSaveValueWidgetWrapper<weld::ComboBox>(m_xCharset->get_widget())); 114 } 115 implInitControls(const SfxItemSet & _rSet,bool _bSaveValue)116 void OCommonBehaviourTabPage::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue) 117 { 118 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa) 119 bool bValid, bReadonly; 120 getFlags(_rSet, bValid, bReadonly); 121 122 // collect the items 123 const SfxStringItem* pOptionsItem = _rSet.GetItem<SfxStringItem>(DSID_ADDITIONALOPTIONS); 124 const SfxStringItem* pCharsetItem = _rSet.GetItem<SfxStringItem>(DSID_CHARSET); 125 126 // forward the values to the controls 127 if (bValid) 128 { 129 if (m_nControlFlags & OCommonBehaviourTabPageFlags::UseOptions) 130 { 131 m_xOptions->set_text(pOptionsItem->GetValue()); 132 m_xOptions->save_value(); 133 } 134 135 if (m_nControlFlags & OCommonBehaviourTabPageFlags::UseCharset) 136 { 137 m_xCharset->SelectEntryByIanaName( pCharsetItem->GetValue() ); 138 } 139 } 140 OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue); 141 } 142 FillItemSet(SfxItemSet * _rSet)143 bool OCommonBehaviourTabPage::FillItemSet(SfxItemSet* _rSet) 144 { 145 bool bChangedSomething = false; 146 147 if (m_nControlFlags & OCommonBehaviourTabPageFlags::UseOptions) 148 { 149 fillString(*_rSet,m_xOptions.get(),DSID_ADDITIONALOPTIONS,bChangedSomething); 150 } 151 152 if (m_nControlFlags & OCommonBehaviourTabPageFlags::UseCharset) 153 { 154 if ( m_xCharset->StoreSelectedCharSet( *_rSet, DSID_CHARSET ) ) 155 bChangedSomething = true; 156 } 157 158 return bChangedSomething; 159 } 160 161 // ODbaseDetailsPage ODbaseDetailsPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & _rCoreAttrs)162 ODbaseDetailsPage::ODbaseDetailsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& _rCoreAttrs) 163 : OCommonBehaviourTabPage(pPage, pController, "dbaccess/ui/dbasepage.ui", "DbasePage", 164 _rCoreAttrs, OCommonBehaviourTabPageFlags::UseCharset) 165 , m_xShowDeleted(m_xBuilder->weld_check_button("showDelRowsCheckbutton")) 166 , m_xFT_Message(m_xBuilder->weld_label("specMessageLabel")) 167 , m_xIndexes(m_xBuilder->weld_button("indiciesButton")) 168 { 169 m_xIndexes->connect_clicked(LINK(this, ODbaseDetailsPage, OnButtonClicked)); 170 m_xShowDeleted->connect_clicked(LINK(this, ODbaseDetailsPage, OnButtonClicked)); 171 } 172 ~ODbaseDetailsPage()173 ODbaseDetailsPage::~ODbaseDetailsPage() 174 { 175 } 176 CreateDbase(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * _rAttrSet)177 std::unique_ptr<SfxTabPage> ODriversSettings::CreateDbase(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* _rAttrSet) 178 { 179 return std::make_unique<ODbaseDetailsPage>(pPage, pController, *_rAttrSet); 180 } 181 implInitControls(const SfxItemSet & _rSet,bool _bSaveValue)182 void ODbaseDetailsPage::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue) 183 { 184 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa) 185 bool bValid, bReadonly; 186 getFlags(_rSet, bValid, bReadonly); 187 188 // get the DSN string (needed for the index dialog) 189 const SfxStringItem* pUrlItem = _rSet.GetItem<SfxStringItem>(DSID_CONNECTURL); 190 const DbuTypeCollectionItem* pTypesItem = _rSet.GetItem<DbuTypeCollectionItem>(DSID_TYPECOLLECTION); 191 ::dbaccess::ODsnTypeCollection* pTypeCollection = pTypesItem ? pTypesItem->getCollection() : nullptr; 192 if (pTypeCollection && pUrlItem && pUrlItem->GetValue().getLength()) 193 m_sDsn = pTypeCollection->cutPrefix(pUrlItem->GetValue()); 194 195 // get the other relevant items 196 const SfxBoolItem* pDeletedItem = _rSet.GetItem<SfxBoolItem>(DSID_SHOWDELETEDROWS); 197 198 if ( bValid ) 199 { 200 m_xShowDeleted->set_active(pDeletedItem->GetValue()); 201 m_xFT_Message->set_visible(m_xShowDeleted->get_active()); 202 } 203 204 OCommonBehaviourTabPage::implInitControls(_rSet, _bSaveValue); 205 } 206 FillItemSet(SfxItemSet * _rSet)207 bool ODbaseDetailsPage::FillItemSet( SfxItemSet* _rSet ) 208 { 209 bool bChangedSomething = OCommonBehaviourTabPage::FillItemSet(_rSet); 210 211 fillBool(*_rSet, m_xShowDeleted.get(), DSID_SHOWDELETEDROWS, false, bChangedSomething); 212 return bChangedSomething; 213 } 214 IMPL_LINK(ODbaseDetailsPage,OnButtonClicked,weld::Button &,rButton,void)215 IMPL_LINK(ODbaseDetailsPage, OnButtonClicked, weld::Button&, rButton, void) 216 { 217 if (m_xIndexes.get() == &rButton) 218 { 219 ODbaseIndexDialog aIndexDialog(GetFrameWeld(), m_sDsn); 220 aIndexDialog.run(); 221 } 222 else 223 { 224 m_xFT_Message->set_visible(m_xShowDeleted->get_active()); 225 // it was one of the checkboxes -> we count as modified from now on 226 callModifiedHdl(); 227 } 228 } 229 230 // OAdoDetailsPage OAdoDetailsPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rCoreAttrs)231 OAdoDetailsPage::OAdoDetailsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreAttrs) 232 : OCommonBehaviourTabPage(pPage, pController, "dbaccess/ui/autocharsetpage.ui", "AutoCharset", 233 rCoreAttrs, OCommonBehaviourTabPageFlags::UseCharset ) 234 { 235 236 } 237 CreateAdo(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * rAttrSet)238 std::unique_ptr<SfxTabPage> ODriversSettings::CreateAdo(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet) 239 { 240 return std::make_unique<OAdoDetailsPage>(pPage, pController, *rAttrSet); 241 } 242 243 // OOdbcDetailsPage OOdbcDetailsPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rCoreAttrs)244 OOdbcDetailsPage::OOdbcDetailsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreAttrs) 245 : OCommonBehaviourTabPage(pPage, pController, "dbaccess/ui/odbcpage.ui", "ODBC", rCoreAttrs, 246 OCommonBehaviourTabPageFlags::UseCharset | OCommonBehaviourTabPageFlags::UseOptions) 247 , m_xUseCatalog(m_xBuilder->weld_check_button("useCatalogCheckbutton")) 248 { 249 m_xUseCatalog->connect_toggled(LINK(this, OGenericAdministrationPage, OnControlModifiedButtonClick)); 250 } 251 ~OOdbcDetailsPage()252 OOdbcDetailsPage::~OOdbcDetailsPage() 253 { 254 } 255 CreateODBC(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * pAttrSet)256 std::unique_ptr<SfxTabPage> ODriversSettings::CreateODBC(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* pAttrSet) 257 { 258 return std::make_unique<OOdbcDetailsPage>(pPage, pController, *pAttrSet); 259 } 260 FillItemSet(SfxItemSet * _rSet)261 bool OOdbcDetailsPage::FillItemSet( SfxItemSet* _rSet ) 262 { 263 bool bChangedSomething = OCommonBehaviourTabPage::FillItemSet(_rSet); 264 fillBool(*_rSet,m_xUseCatalog.get(),DSID_USECATALOG,false,bChangedSomething); 265 return bChangedSomething; 266 } implInitControls(const SfxItemSet & _rSet,bool _bSaveValue)267 void OOdbcDetailsPage::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue) 268 { 269 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa) 270 bool bValid, bReadonly; 271 getFlags(_rSet, bValid, bReadonly); 272 273 const SfxBoolItem* pUseCatalogItem = _rSet.GetItem<SfxBoolItem>(DSID_USECATALOG); 274 275 if ( bValid ) 276 m_xUseCatalog->set_active(pUseCatalogItem->GetValue()); 277 278 OCommonBehaviourTabPage::implInitControls(_rSet, _bSaveValue); 279 } 280 // OOdbcDetailsPage OUserDriverDetailsPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rCoreAttrs)281 OUserDriverDetailsPage::OUserDriverDetailsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreAttrs) 282 : OCommonBehaviourTabPage(pPage, pController, "dbaccess/ui/userdetailspage.ui", "UserDetailsPage", 283 rCoreAttrs, OCommonBehaviourTabPageFlags::UseCharset | OCommonBehaviourTabPageFlags::UseOptions) 284 , m_xFTHostname(m_xBuilder->weld_label("hostnameft")) 285 , m_xEDHostname(m_xBuilder->weld_entry("hostname")) 286 , m_xPortNumber(m_xBuilder->weld_label("portnumberft")) 287 , m_xNFPortNumber(m_xBuilder->weld_spin_button("portnumber")) 288 , m_xUseCatalog(m_xBuilder->weld_check_button("usecatalog")) 289 { 290 m_xUseCatalog->connect_toggled(LINK(this, OGenericAdministrationPage, OnControlModifiedButtonClick)); 291 } 292 ~OUserDriverDetailsPage()293 OUserDriverDetailsPage::~OUserDriverDetailsPage() 294 { 295 } 296 CreateUser(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * pAttrSet)297 std::unique_ptr<SfxTabPage> ODriversSettings::CreateUser(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* pAttrSet) 298 { 299 return std::make_unique<OUserDriverDetailsPage>(pPage, pController, *pAttrSet); 300 } 301 FillItemSet(SfxItemSet * _rSet)302 bool OUserDriverDetailsPage::FillItemSet( SfxItemSet* _rSet ) 303 { 304 bool bChangedSomething = OCommonBehaviourTabPage::FillItemSet(_rSet); 305 306 fillInt32(*_rSet,m_xNFPortNumber.get(),DSID_CONN_PORTNUMBER,bChangedSomething); 307 fillString(*_rSet,m_xEDHostname.get(),DSID_CONN_HOSTNAME,bChangedSomething); 308 fillBool(*_rSet,m_xUseCatalog.get(),DSID_USECATALOG,false,bChangedSomething); 309 310 return bChangedSomething; 311 } fillControls(std::vector<std::unique_ptr<ISaveValueWrapper>> & _rControlList)312 void OUserDriverDetailsPage::fillControls(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList) 313 { 314 OCommonBehaviourTabPage::fillControls(_rControlList); 315 _rControlList.emplace_back(new OSaveValueWidgetWrapper<weld::Entry>(m_xEDHostname.get())); 316 _rControlList.emplace_back(new OSaveValueWidgetWrapper<weld::ToggleButton>(m_xUseCatalog.get())); 317 _rControlList.emplace_back(new OSaveValueWidgetWrapper<weld::SpinButton>(m_xNFPortNumber.get())); 318 } fillWindows(std::vector<std::unique_ptr<ISaveValueWrapper>> & _rControlList)319 void OUserDriverDetailsPage::fillWindows(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList) 320 { 321 OCommonBehaviourTabPage::fillWindows(_rControlList); 322 _rControlList.emplace_back(new ODisableWidgetWrapper<weld::Label>(m_xFTHostname.get())); 323 _rControlList.emplace_back(new ODisableWidgetWrapper<weld::Label>(m_xPortNumber.get())); 324 } implInitControls(const SfxItemSet & _rSet,bool _bSaveValue)325 void OUserDriverDetailsPage::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue) 326 { 327 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa) 328 bool bValid, bReadonly; 329 getFlags(_rSet, bValid, bReadonly); 330 331 const SfxBoolItem* pUseCatalogItem = _rSet.GetItem<SfxBoolItem>(DSID_USECATALOG); 332 const SfxStringItem* pHostName = _rSet.GetItem<SfxStringItem>(DSID_CONN_HOSTNAME); 333 const SfxInt32Item* pPortNumber = _rSet.GetItem<SfxInt32Item>(DSID_CONN_PORTNUMBER); 334 335 if ( bValid ) 336 { 337 m_xEDHostname->set_text(pHostName->GetValue()); 338 m_xEDHostname->save_value(); 339 340 m_xNFPortNumber->set_value(pPortNumber->GetValue()); 341 m_xNFPortNumber->save_value(); 342 343 m_xUseCatalog->set_active(pUseCatalogItem->GetValue()); 344 } 345 346 OCommonBehaviourTabPage::implInitControls(_rSet, _bSaveValue); 347 } 348 // OMySQLODBCDetailsPage OMySQLODBCDetailsPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rCoreAttrs)349 OMySQLODBCDetailsPage::OMySQLODBCDetailsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreAttrs) 350 : OCommonBehaviourTabPage(pPage, pController, "dbaccess/ui/autocharsetpage.ui", "AutoCharset", 351 rCoreAttrs, OCommonBehaviourTabPageFlags::UseCharset ) 352 { 353 } 354 CreateMySQLODBC(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * pAttrSet)355 std::unique_ptr<SfxTabPage> ODriversSettings::CreateMySQLODBC(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* pAttrSet) 356 { 357 return std::make_unique<OMySQLODBCDetailsPage>(pPage, pController, *pAttrSet); 358 } 359 360 // OMySQLJDBCDetailsPage OGeneralSpecialJDBCDetailsPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rCoreAttrs,sal_uInt16 _nPortId,bool bShowSocket)361 OGeneralSpecialJDBCDetailsPage::OGeneralSpecialJDBCDetailsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreAttrs ,sal_uInt16 _nPortId, bool bShowSocket) 362 : OCommonBehaviourTabPage(pPage, pController, "dbaccess/ui/generalspecialjdbcdetailspage.ui", "GeneralSpecialJDBCDetails", 363 rCoreAttrs, OCommonBehaviourTabPageFlags::UseCharset) 364 , m_nPortId(_nPortId) 365 , m_bUseClass(true) 366 , m_xEDHostname(m_xBuilder->weld_entry("hostNameEntry")) 367 , m_xNFPortNumber(m_xBuilder->weld_spin_button("portNumberSpinbutton")) 368 , m_xFTSocket(m_xBuilder->weld_label("socketLabel")) 369 , m_xEDSocket(m_xBuilder->weld_entry("socketEntry")) 370 , m_xFTDriverClass(m_xBuilder->weld_label("driverClassLabel")) 371 , m_xEDDriverClass(m_xBuilder->weld_entry("jdbcDriverClassEntry")) 372 , m_xTestJavaDriver(m_xBuilder->weld_button("testDriverClassButton")) 373 { 374 const SfxStringItem* pUrlItem = rCoreAttrs.GetItem<SfxStringItem>(DSID_CONNECTURL); 375 const DbuTypeCollectionItem* pTypesItem = rCoreAttrs.GetItem<DbuTypeCollectionItem>(DSID_TYPECOLLECTION); 376 ::dbaccess::ODsnTypeCollection* pTypeCollection = pTypesItem ? pTypesItem->getCollection() : nullptr; 377 if (pTypeCollection && pUrlItem && pUrlItem->GetValue().getLength() ) 378 { 379 m_sDefaultJdbcDriverName = pTypeCollection->getJavaDriverClass(pUrlItem->GetValue()); 380 } 381 if ( m_sDefaultJdbcDriverName.getLength() ) 382 { 383 m_xEDDriverClass->connect_changed(LINK(this,OGenericAdministrationPage,OnControlEntryModifyHdl)); 384 m_xTestJavaDriver->connect_clicked(LINK(this,OGeneralSpecialJDBCDetailsPage,OnTestJavaClickHdl)); 385 } 386 else 387 { 388 m_bUseClass = false; 389 m_xFTDriverClass->hide(); 390 m_xEDDriverClass->hide(); 391 m_xTestJavaDriver->hide(); 392 } 393 394 m_xFTSocket->set_visible(bShowSocket && !m_bUseClass); 395 m_xEDSocket->set_visible(bShowSocket && !m_bUseClass); 396 397 m_xEDHostname->connect_changed(LINK(this,OGenericAdministrationPage,OnControlEntryModifyHdl)); 398 m_xNFPortNumber->connect_value_changed(LINK(this,OGenericAdministrationPage,OnControlSpinButtonModifyHdl)); 399 m_xEDSocket->connect_changed(LINK(this,OGenericAdministrationPage,OnControlEntryModifyHdl)); 400 } 401 ~OGeneralSpecialJDBCDetailsPage()402 OGeneralSpecialJDBCDetailsPage::~OGeneralSpecialJDBCDetailsPage() 403 { 404 } 405 FillItemSet(SfxItemSet * _rSet)406 bool OGeneralSpecialJDBCDetailsPage::FillItemSet( SfxItemSet* _rSet ) 407 { 408 bool bChangedSomething = OCommonBehaviourTabPage::FillItemSet(_rSet); 409 if ( m_bUseClass ) 410 fillString(*_rSet,m_xEDDriverClass.get(),DSID_JDBCDRIVERCLASS,bChangedSomething); 411 fillString(*_rSet,m_xEDHostname.get(),DSID_CONN_HOSTNAME,bChangedSomething); 412 fillString(*_rSet,m_xEDSocket.get(),DSID_CONN_SOCKET,bChangedSomething); 413 fillInt32(*_rSet,m_xNFPortNumber.get(),m_nPortId,bChangedSomething ); 414 415 return bChangedSomething; 416 } implInitControls(const SfxItemSet & _rSet,bool _bSaveValue)417 void OGeneralSpecialJDBCDetailsPage::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue) 418 { 419 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa) 420 bool bValid, bReadonly; 421 getFlags(_rSet, bValid, bReadonly); 422 423 const SfxStringItem* pDrvItem = _rSet.GetItem<SfxStringItem>(DSID_JDBCDRIVERCLASS); 424 const SfxStringItem* pHostName = _rSet.GetItem<SfxStringItem>(DSID_CONN_HOSTNAME); 425 const SfxInt32Item* pPortNumber = _rSet.GetItem<SfxInt32Item>(m_nPortId); 426 const SfxStringItem* pSocket = _rSet.GetItem<SfxStringItem>(DSID_CONN_SOCKET); 427 428 if ( bValid ) 429 { 430 if ( m_bUseClass ) 431 { 432 m_xEDDriverClass->set_text(pDrvItem->GetValue()); 433 m_xEDDriverClass->save_value(); 434 } 435 436 m_xEDHostname->set_text(pHostName->GetValue()); 437 m_xEDHostname->save_value(); 438 439 m_xNFPortNumber->set_value(pPortNumber->GetValue()); 440 m_xNFPortNumber->save_value(); 441 442 m_xEDSocket->set_text(pSocket->GetValue()); 443 m_xEDSocket->save_value(); 444 } 445 446 OCommonBehaviourTabPage::implInitControls(_rSet, _bSaveValue); 447 448 // to get the correct value when saveValue was called by base class 449 if ( m_bUseClass && m_xEDDriverClass->get_text().trim().isEmpty() ) 450 { 451 m_xEDDriverClass->set_text(m_sDefaultJdbcDriverName); 452 m_xEDDriverClass->save_value(); 453 } 454 } IMPL_LINK_NOARG(OGeneralSpecialJDBCDetailsPage,OnTestJavaClickHdl,weld::Button &,void)455 IMPL_LINK_NOARG(OGeneralSpecialJDBCDetailsPage, OnTestJavaClickHdl, weld::Button&, void) 456 { 457 OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF"); 458 OSL_ENSURE(m_bUseClass,"Who called me?"); 459 460 bool bSuccess = false; 461 #if HAVE_FEATURE_JAVA 462 try 463 { 464 if (!m_xEDDriverClass->get_text().trim().isEmpty()) 465 { 466 // TODO change jvmaccess 467 ::rtl::Reference< jvmaccess::VirtualMachine > xJVM = ::connectivity::getJavaVM( m_pAdminDialog->getORB() ); 468 m_xEDDriverClass->set_text(m_xEDDriverClass->get_text().trim()); // fdo#68341 469 bSuccess = ::connectivity::existsJavaClassByName(xJVM,m_xEDDriverClass->get_text()); 470 } 471 } 472 catch(Exception&) 473 { 474 } 475 #endif 476 const char* pMessage = bSuccess ? STR_JDBCDRIVER_SUCCESS : STR_JDBCDRIVER_NO_SUCCESS; 477 const MessageType mt = bSuccess ? MessageType::Info : MessageType::Error; 478 OSQLMessageBox aMsg(GetFrameWeld(), DBA_RES(pMessage), OUString(), MessBoxStyle::Ok | MessBoxStyle::DefaultOk, mt); 479 aMsg.run(); 480 } 481 callModifiedHdl(weld::Widget * pControl)482 void OGeneralSpecialJDBCDetailsPage::callModifiedHdl(weld::Widget* pControl) 483 { 484 if (m_bUseClass && pControl == m_xEDDriverClass.get()) 485 m_xTestJavaDriver->set_sensitive(!m_xEDDriverClass->get_text().trim().isEmpty()); 486 487 // tell the listener we were modified 488 OGenericAdministrationPage::callModifiedHdl(); 489 } 490 491 // MySQLNativePage MySQLNativePage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rCoreAttrs)492 MySQLNativePage::MySQLNativePage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreAttrs) 493 : OCommonBehaviourTabPage(pPage, pController, "dbaccess/ui/mysqlnativepage.ui", "MysqlNativePage", rCoreAttrs, OCommonBehaviourTabPageFlags::UseCharset) 494 , m_xMySQLSettingsContainer(m_xBuilder->weld_widget("MySQLSettingsContainer")) 495 , m_xMySQLSettings(new MySQLNativeSettings(m_xMySQLSettingsContainer.get(), LINK(this,OGenericAdministrationPage,OnControlModified))) 496 , m_xSeparator1(m_xBuilder->weld_label("connectionheader")) 497 , m_xSeparator2(m_xBuilder->weld_label("userheader")) 498 , m_xUserNameLabel(m_xBuilder->weld_label("usernamelabel")) 499 , m_xUserName(m_xBuilder->weld_entry("username")) 500 , m_xPasswordRequired(m_xBuilder->weld_check_button("passwordrequired")) 501 { 502 m_xUserName->connect_changed(LINK(this,OGenericAdministrationPage,OnControlEntryModifyHdl)); 503 } 504 ~MySQLNativePage()505 MySQLNativePage::~MySQLNativePage() 506 { 507 m_xMySQLSettings.reset(); 508 } 509 fillControls(std::vector<std::unique_ptr<ISaveValueWrapper>> & _rControlList)510 void MySQLNativePage::fillControls(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList) 511 { 512 OCommonBehaviourTabPage::fillControls( _rControlList ); 513 m_xMySQLSettings->fillControls( _rControlList ); 514 515 _rControlList.emplace_back(new OSaveValueWidgetWrapper<weld::Entry>(m_xUserName.get())); 516 _rControlList.emplace_back(new OSaveValueWidgetWrapper<weld::ToggleButton>(m_xPasswordRequired.get())); 517 } 518 fillWindows(std::vector<std::unique_ptr<ISaveValueWrapper>> & _rControlList)519 void MySQLNativePage::fillWindows(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList) 520 { 521 OCommonBehaviourTabPage::fillWindows( _rControlList ); 522 m_xMySQLSettings->fillWindows( _rControlList); 523 524 _rControlList.emplace_back(new ODisableWidgetWrapper<weld::Label>(m_xSeparator1.get())); 525 _rControlList.emplace_back(new ODisableWidgetWrapper<weld::Label>(m_xSeparator2.get())); 526 _rControlList.emplace_back(new ODisableWidgetWrapper<weld::Label>(m_xUserNameLabel.get())); 527 } 528 FillItemSet(SfxItemSet * _rSet)529 bool MySQLNativePage::FillItemSet( SfxItemSet* _rSet ) 530 { 531 bool bChangedSomething = OCommonBehaviourTabPage::FillItemSet( _rSet ); 532 533 bChangedSomething |= m_xMySQLSettings->FillItemSet( _rSet ); 534 535 if (m_xUserName->get_value_changed_from_saved()) 536 { 537 _rSet->Put( SfxStringItem( DSID_USER, m_xUserName->get_text() ) ); 538 _rSet->Put( SfxStringItem( DSID_PASSWORD, OUString())); 539 bChangedSomething = true; 540 } 541 fillBool(*_rSet,m_xPasswordRequired.get(),DSID_PASSWORDREQUIRED,false,bChangedSomething); 542 543 return bChangedSomething; 544 } implInitControls(const SfxItemSet & _rSet,bool _bSaveValue)545 void MySQLNativePage::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue) 546 { 547 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa) 548 bool bValid, bReadonly; 549 getFlags(_rSet, bValid, bReadonly); 550 551 m_xMySQLSettings->implInitControls( _rSet ); 552 553 const SfxStringItem* pUidItem = _rSet.GetItem<SfxStringItem>(DSID_USER); 554 const SfxBoolItem* pAllowEmptyPwd = _rSet.GetItem<SfxBoolItem>(DSID_PASSWORDREQUIRED); 555 556 if ( bValid ) 557 { 558 m_xUserName->set_text(pUidItem->GetValue()); 559 m_xUserName->save_value(); 560 m_xPasswordRequired->set_active(pAllowEmptyPwd->GetValue()); 561 } 562 563 OCommonBehaviourTabPage::implInitControls(_rSet, _bSaveValue); 564 } 565 CreateMySQLJDBC(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * _rAttrSet)566 std::unique_ptr<SfxTabPage> ODriversSettings::CreateMySQLJDBC( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* _rAttrSet ) 567 { 568 return std::make_unique<OGeneralSpecialJDBCDetailsPage>(pPage, pController, *_rAttrSet,DSID_MYSQL_PORTNUMBER); 569 } 570 CreateMySQLNATIVE(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * pAttrSet)571 std::unique_ptr<SfxTabPage> ODriversSettings::CreateMySQLNATIVE(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* pAttrSet) 572 { 573 return std::make_unique<MySQLNativePage>(pPage, pController, *pAttrSet); 574 } 575 CreateOracleJDBC(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * _rAttrSet)576 std::unique_ptr<SfxTabPage> ODriversSettings::CreateOracleJDBC(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* _rAttrSet) 577 { 578 return std::make_unique<OGeneralSpecialJDBCDetailsPage>(pPage, pController, *_rAttrSet,DSID_ORACLE_PORTNUMBER, false); 579 } 580 581 // OLDAPDetailsPage OLDAPDetailsPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rCoreAttrs)582 OLDAPDetailsPage::OLDAPDetailsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreAttrs) 583 : OCommonBehaviourTabPage(pPage, pController, "dbaccess/ui/ldappage.ui", "LDAP", 584 rCoreAttrs, OCommonBehaviourTabPageFlags::NONE) 585 , m_xETBaseDN(m_xBuilder->weld_entry("baseDNEntry")) 586 , m_xCBUseSSL(m_xBuilder->weld_check_button("useSSLCheckbutton")) 587 , m_xNFPortNumber(m_xBuilder->weld_spin_button("portNumberSpinbutton")) 588 , m_xNFRowCount(m_xBuilder->weld_spin_button("LDAPRowCountspinbutton")) 589 { 590 m_xETBaseDN->connect_changed(LINK(this,OGenericAdministrationPage,OnControlEntryModifyHdl)); 591 m_xNFPortNumber->connect_value_changed(LINK(this,OGenericAdministrationPage,OnControlSpinButtonModifyHdl)); 592 m_xNFRowCount->connect_value_changed(LINK(this,OGenericAdministrationPage,OnControlSpinButtonModifyHdl)); 593 594 m_iNormalPort = 389; 595 m_iSSLPort = 636; 596 m_xCBUseSSL->connect_toggled(LINK(this, OLDAPDetailsPage, OnCheckBoxClick)); 597 } 598 ~OLDAPDetailsPage()599 OLDAPDetailsPage::~OLDAPDetailsPage() 600 { 601 } 602 CreateLDAP(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * _rAttrSet)603 std::unique_ptr<SfxTabPage> ODriversSettings::CreateLDAP(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* _rAttrSet) 604 { 605 return std::make_unique<OLDAPDetailsPage>(pPage, pController, *_rAttrSet); 606 } 607 FillItemSet(SfxItemSet * _rSet)608 bool OLDAPDetailsPage::FillItemSet( SfxItemSet* _rSet ) 609 { 610 bool bChangedSomething = OCommonBehaviourTabPage::FillItemSet(_rSet); 611 612 fillString(*_rSet,m_xETBaseDN.get(),DSID_CONN_LDAP_BASEDN,bChangedSomething); 613 fillInt32(*_rSet,m_xNFPortNumber.get(),DSID_CONN_LDAP_PORTNUMBER,bChangedSomething); 614 fillInt32(*_rSet,m_xNFRowCount.get(),DSID_CONN_LDAP_ROWCOUNT,bChangedSomething); 615 fillBool(*_rSet,m_xCBUseSSL.get(),DSID_CONN_LDAP_USESSL,false,bChangedSomething); 616 return bChangedSomething; 617 } 618 IMPL_LINK(OLDAPDetailsPage,OnCheckBoxClick,weld::ToggleButton &,rCheckBox,void)619 IMPL_LINK(OLDAPDetailsPage, OnCheckBoxClick, weld::ToggleButton&, rCheckBox, void) 620 { 621 OnControlModifiedButtonClick(rCheckBox); 622 callModifiedHdl(); 623 if (m_xCBUseSSL->get_active()) 624 { 625 m_iNormalPort = m_xNFPortNumber->get_value(); 626 m_xNFPortNumber->set_value(m_iSSLPort); 627 } 628 else 629 { 630 m_iSSLPort = m_xNFPortNumber->get_value(); 631 m_xNFPortNumber->set_value(m_iNormalPort); 632 } 633 } 634 implInitControls(const SfxItemSet & _rSet,bool _bSaveValue)635 void OLDAPDetailsPage::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue) 636 { 637 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa) 638 bool bValid, bReadonly; 639 getFlags(_rSet, bValid, bReadonly); 640 641 const SfxStringItem* pBaseDN = _rSet.GetItem<SfxStringItem>(DSID_CONN_LDAP_BASEDN); 642 const SfxBoolItem* pUseSSL = _rSet.GetItem<SfxBoolItem>(DSID_CONN_LDAP_USESSL); 643 const SfxInt32Item* pPortNumber = _rSet.GetItem<SfxInt32Item>(DSID_CONN_LDAP_PORTNUMBER); 644 const SfxInt32Item* pRowCount = _rSet.GetItem<SfxInt32Item>(DSID_CONN_LDAP_ROWCOUNT); 645 646 if ( bValid ) 647 { 648 m_xETBaseDN->set_text(pBaseDN->GetValue()); 649 m_xNFPortNumber->set_value(pPortNumber->GetValue()); 650 m_xNFRowCount->set_value(pRowCount->GetValue()); 651 m_xCBUseSSL->set_active(pUseSSL->GetValue()); 652 } 653 654 OCommonBehaviourTabPage::implInitControls(_rSet, _bSaveValue); 655 } 656 657 // OTextDetailsPage OTextDetailsPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rCoreAttrs)658 OTextDetailsPage::OTextDetailsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rCoreAttrs) 659 : OCommonBehaviourTabPage(pPage, pController, "dbaccess/ui/emptypage.ui", "EmptyPage", rCoreAttrs, OCommonBehaviourTabPageFlags::NONE) 660 , m_xTextConnectionHelper(new OTextConnectionHelper(m_xContainer.get(), TC_EXTENSION | TC_HEADER | TC_SEPARATORS | TC_CHARSET)) 661 { 662 } 663 ~OTextDetailsPage()664 OTextDetailsPage::~OTextDetailsPage() 665 { 666 m_xTextConnectionHelper.reset(); 667 } 668 CreateText(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * pAttrSet)669 std::unique_ptr<SfxTabPage> ODriversSettings::CreateText(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* pAttrSet) 670 { 671 return std::make_unique<OTextDetailsPage>(pPage, pController, *pAttrSet); 672 } 673 fillControls(std::vector<std::unique_ptr<ISaveValueWrapper>> & _rControlList)674 void OTextDetailsPage::fillControls(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList) 675 { 676 OCommonBehaviourTabPage::fillControls(_rControlList); 677 m_xTextConnectionHelper->fillControls(_rControlList); 678 679 } fillWindows(std::vector<std::unique_ptr<ISaveValueWrapper>> & _rControlList)680 void OTextDetailsPage::fillWindows(std::vector< std::unique_ptr<ISaveValueWrapper> >& _rControlList) 681 { 682 OCommonBehaviourTabPage::fillWindows(_rControlList); 683 m_xTextConnectionHelper->fillWindows(_rControlList); 684 685 } implInitControls(const SfxItemSet & _rSet,bool _bSaveValue)686 void OTextDetailsPage::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue) 687 { 688 // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa) 689 bool bValid, bReadonly; 690 getFlags(_rSet, bValid, bReadonly); 691 692 m_xTextConnectionHelper->implInitControls(_rSet, bValid); 693 OCommonBehaviourTabPage::implInitControls(_rSet, _bSaveValue); 694 } 695 FillItemSet(SfxItemSet * rSet)696 bool OTextDetailsPage::FillItemSet( SfxItemSet* rSet ) 697 { 698 bool bChangedSomething = OCommonBehaviourTabPage::FillItemSet(rSet); 699 bChangedSomething = m_xTextConnectionHelper->FillItemSet(*rSet, bChangedSomething); 700 return bChangedSomething; 701 } 702 prepareLeave()703 bool OTextDetailsPage::prepareLeave() 704 { 705 return m_xTextConnectionHelper->prepareLeave(); 706 } 707 CreateGeneratedValuesPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * _rAttrSet)708 std::unique_ptr<SfxTabPage> ODriversSettings::CreateGeneratedValuesPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* _rAttrSet) 709 { 710 return std::make_unique<GeneratedValuesPage>(pPage, pController, *_rAttrSet); 711 } 712 CreateSpecialSettingsPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * _rAttrSet)713 std::unique_ptr<SfxTabPage> ODriversSettings::CreateSpecialSettingsPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* _rAttrSet) 714 { 715 OUString eType = ODbDataSourceAdministrationHelper::getDatasourceType( *_rAttrSet ); 716 DataSourceMetaData aMetaData( eType ); 717 return std::make_unique<SpecialSettingsPage>(pPage, pController, *_rAttrSet, aMetaData); 718 } 719 } // namespace dbaui 720 721 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 722