1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "dsnItem.hxx" 32*cdf0e10cSrcweir #include "generalpage.hxx" 33*cdf0e10cSrcweir #include <connectivity/dbexception.hxx> 34*cdf0e10cSrcweir #include "dbu_dlg.hrc" 35*cdf0e10cSrcweir #include "dbadmin.hrc" 36*cdf0e10cSrcweir #include "dsitems.hxx" 37*cdf0e10cSrcweir #include "dbustrings.hrc" 38*cdf0e10cSrcweir #include "dbadmin.hxx" 39*cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx> 40*cdf0e10cSrcweir #include <sfx2/docfilt.hxx> 41*cdf0e10cSrcweir #include <vcl/stdtext.hxx> 42*cdf0e10cSrcweir #include "localresaccess.hxx" 43*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 44*cdf0e10cSrcweir #include <svl/stritem.hxx> 45*cdf0e10cSrcweir #include <vcl/waitobj.hxx> 46*cdf0e10cSrcweir #include <com/sun/star/sdbc/XDriverAccess.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 49*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 50*cdf0e10cSrcweir #include "DriverSettings.hxx" 51*cdf0e10cSrcweir #include "UITools.hxx" 52*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 53*cdf0e10cSrcweir #include <unotools/confignode.hxx> 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir //......................................................................... 56*cdf0e10cSrcweir namespace dbaui 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir //......................................................................... 59*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 60*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 61*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 62*cdf0e10cSrcweir using namespace ::com::sun::star::container; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir //========================================================================= 65*cdf0e10cSrcweir //= OGeneralPage 66*cdf0e10cSrcweir //========================================================================= 67*cdf0e10cSrcweir //------------------------------------------------------------------------- 68*cdf0e10cSrcweir OGeneralPage::OGeneralPage(Window* pParent, const SfxItemSet& _rItems, sal_Bool _bDBWizardMode) 69*cdf0e10cSrcweir :OGenericAdministrationPage(pParent, ModuleRes(PAGE_GENERAL), _rItems) 70*cdf0e10cSrcweir ,m_aFTHeaderText (this, ModuleRes(FT_GENERALHEADERTEXT)) 71*cdf0e10cSrcweir ,m_aFTHelpText (this, ModuleRes(FT_GENERALHELPTEXT)) 72*cdf0e10cSrcweir ,m_aFT_DatasourceTypeHeader (this, ModuleRes(FT_DATASOURCEHEADER)) 73*cdf0e10cSrcweir ,m_aRB_CreateDatabase (this, ModuleRes(RB_CREATEDBDATABASE)) 74*cdf0e10cSrcweir ,m_aRB_OpenDocument (this, ModuleRes(RB_OPENEXISTINGDOC)) 75*cdf0e10cSrcweir ,m_aRB_GetExistingDatabase (this, ModuleRes(RB_GETEXISTINGDATABASE)) 76*cdf0e10cSrcweir ,m_aFT_DocListLabel (this, ModuleRes(FT_DOCLISTLABEL)) 77*cdf0e10cSrcweir ,m_pLB_DocumentList ( new OpenDocumentListBox( this, "com.sun.star.sdb.OfficeDatabaseDocument", ModuleRes( LB_DOCUMENTLIST ) ) ) 78*cdf0e10cSrcweir ,m_aPB_OpenDocument (this, "com.sun.star.sdb.OfficeDatabaseDocument", ModuleRes(PB_OPENDOCUMENT)) 79*cdf0e10cSrcweir ,m_aTypePreLabel (this, ModuleRes(FT_DATASOURCETYPE_PRE)) 80*cdf0e10cSrcweir ,m_aDatasourceTypeLabel (this, ModuleRes(FT_DATATYPE)) 81*cdf0e10cSrcweir ,m_pDatasourceType ( new ListBox(this, ModuleRes(LB_DATATYPE))) 82*cdf0e10cSrcweir ,m_aFTDataSourceAppendix (this, ModuleRes(FT_DATATYPEAPPENDIX)) 83*cdf0e10cSrcweir ,m_aTypePostLabel (this, ModuleRes(FT_DATASOURCETYPE_POST)) 84*cdf0e10cSrcweir ,m_aSpecialMessage (this, ModuleRes(FT_SPECIAL_MESSAGE)) 85*cdf0e10cSrcweir ,m_DBWizardMode (_bDBWizardMode) 86*cdf0e10cSrcweir ,m_sMySQLEntry (ModuleRes(STR_MYSQLENTRY)) 87*cdf0e10cSrcweir ,m_eOriginalCreationMode (eCreateNew) 88*cdf0e10cSrcweir ,m_pCollection (NULL) 89*cdf0e10cSrcweir ,m_eNotSupportedKnownType ( ::dbaccess::DST_UNKNOWN) 90*cdf0e10cSrcweir ,m_eLastMessage (smNone) 91*cdf0e10cSrcweir ,m_bDisplayingInvalid (sal_False) 92*cdf0e10cSrcweir ,m_bUserGrabFocus (sal_True) 93*cdf0e10cSrcweir ,m_bInitTypeList (true) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir // fill the listbox with the UI descriptions for the possible types 96*cdf0e10cSrcweir // and remember the respective DSN prefixes 97*cdf0e10cSrcweir FreeResource(); 98*cdf0e10cSrcweir // extract the datasource type collection from the item set 99*cdf0e10cSrcweir DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _rItems.GetItem(DSID_TYPECOLLECTION)); 100*cdf0e10cSrcweir if (pCollectionItem) 101*cdf0e10cSrcweir m_pCollection = pCollectionItem->getCollection(); 102*cdf0e10cSrcweir DBG_ASSERT(m_pCollection, "OGeneralPage::OGeneralPage : really need a DSN type collection !"); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir // If no driver for embedded DBs is installed, and no dBase driver, then hide the "Create new database" option 105*cdf0e10cSrcweir sal_Int32 nCreateNewDBIndex = m_pCollection->getIndexOf( m_pCollection->getEmbeddedDatabase() ); 106*cdf0e10cSrcweir if ( nCreateNewDBIndex == -1 ) 107*cdf0e10cSrcweir nCreateNewDBIndex = m_pCollection->getIndexOf( ::rtl::OUString::createFromAscii( "sdbc:dbase:" ) ); 108*cdf0e10cSrcweir bool bHideCreateNew = ( nCreateNewDBIndex == -1 ); 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir // also, if our application policies tell us to hide the option, do it 111*cdf0e10cSrcweir ::utl::OConfigurationTreeRoot aConfig( ::utl::OConfigurationTreeRoot::createWithServiceFactory( 112*cdf0e10cSrcweir ::comphelper::getProcessServiceFactory(), 113*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.DataAccess/Policies/Features/Base" ) ) 114*cdf0e10cSrcweir ) ); 115*cdf0e10cSrcweir sal_Bool bAllowCreateLocalDatabase( sal_True ); 116*cdf0e10cSrcweir OSL_VERIFY( aConfig.getNodeValue( "CreateLocalDatabase" ) >>= bAllowCreateLocalDatabase ); 117*cdf0e10cSrcweir if ( !bAllowCreateLocalDatabase ) 118*cdf0e10cSrcweir bHideCreateNew = true; 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir if ( bHideCreateNew ) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir m_aRB_CreateDatabase.Hide(); 123*cdf0e10cSrcweir Window* pWindowsToMove[] = { 124*cdf0e10cSrcweir &m_aRB_OpenDocument, &m_aRB_GetExistingDatabase, &m_aFT_DocListLabel, m_pLB_DocumentList.get(), 125*cdf0e10cSrcweir &m_aPB_OpenDocument, &m_aDatasourceTypeLabel, m_pDatasourceType.get(), &m_aFTDataSourceAppendix, 126*cdf0e10cSrcweir &m_aTypePostLabel 127*cdf0e10cSrcweir }; 128*cdf0e10cSrcweir const long nOffset = m_aRB_OpenDocument.GetPosPixel().Y() - m_aRB_CreateDatabase.GetPosPixel().Y(); 129*cdf0e10cSrcweir for ( size_t i=0; i < sizeof( pWindowsToMove ) / sizeof( pWindowsToMove[0] ); ++i ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir Point aPos( pWindowsToMove[i]->GetPosPixel() ); 132*cdf0e10cSrcweir aPos.Y() -= nOffset; 133*cdf0e10cSrcweir pWindowsToMove[i]->SetPosPixel( aPos ); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir if ( bHideCreateNew ) 138*cdf0e10cSrcweir m_aRB_GetExistingDatabase.Check(); 139*cdf0e10cSrcweir else 140*cdf0e10cSrcweir m_aRB_CreateDatabase.Check(); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir // do some knittings 143*cdf0e10cSrcweir m_pDatasourceType->SetSelectHdl(LINK(this, OGeneralPage, OnDatasourceTypeSelected)); 144*cdf0e10cSrcweir m_aRB_CreateDatabase.SetClickHdl(LINK(this, OGeneralPage, OnSetupModeSelected)); 145*cdf0e10cSrcweir m_aRB_GetExistingDatabase.SetClickHdl(LINK(this, OGeneralPage, OnSetupModeSelected)); 146*cdf0e10cSrcweir m_aRB_OpenDocument.SetClickHdl(LINK(this, OGeneralPage, OnSetupModeSelected)); 147*cdf0e10cSrcweir m_pLB_DocumentList->SetSelectHdl( LINK( this, OGeneralPage, OnDocumentSelected ) ); 148*cdf0e10cSrcweir m_aPB_OpenDocument.SetClickHdl( LINK( this, OGeneralPage, OnOpenDocument ) ); 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir //------------------------------------------------------------------------- 152*cdf0e10cSrcweir OGeneralPage::~OGeneralPage() 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir m_pDatasourceType.reset( NULL ); 155*cdf0e10cSrcweir m_pLB_DocumentList.reset( NULL ); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir //------------------------------------------------------------------------- 159*cdf0e10cSrcweir namespace 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir struct DisplayedType 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir ::rtl::OUString eType; 164*cdf0e10cSrcweir String sDisplayName; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir DisplayedType( const ::rtl::OUString& _eType, const String& _rDisplayName ) : eType( _eType ), sDisplayName( _rDisplayName ) { } 167*cdf0e10cSrcweir }; 168*cdf0e10cSrcweir typedef ::std::vector< DisplayedType > DisplayedTypes; 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir struct DisplayedTypeLess : ::std::binary_function< DisplayedType, DisplayedType, bool > 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir bool operator() ( const DisplayedType& _rLHS, const DisplayedType& _rRHS ) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir return _rLHS.eType < _rRHS.eType; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir }; 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir //------------------------------------------------------------------------- 180*cdf0e10cSrcweir void OGeneralPage::initializeTypeList() 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir if ( m_bInitTypeList ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir m_bInitTypeList = false; 185*cdf0e10cSrcweir m_pDatasourceType->Clear(); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir if ( m_pCollection ) 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir DisplayedTypes aDisplayedTypes; 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir ::dbaccess::ODsnTypeCollection::TypeIterator aEnd = m_pCollection->end(); 192*cdf0e10cSrcweir for ( ::dbaccess::ODsnTypeCollection::TypeIterator aTypeLoop = m_pCollection->begin(); 193*cdf0e10cSrcweir aTypeLoop != aEnd; 194*cdf0e10cSrcweir ++aTypeLoop 195*cdf0e10cSrcweir ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir const ::rtl::OUString sURLPrefix = aTypeLoop.getURLPrefix(); 198*cdf0e10cSrcweir if ( sURLPrefix.getLength() ) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir String sDisplayName = aTypeLoop.getDisplayName(); 201*cdf0e10cSrcweir if ( m_pDatasourceType->GetEntryPos( sDisplayName ) == LISTBOX_ENTRY_NOTFOUND 202*cdf0e10cSrcweir && approveDataSourceType( sURLPrefix, sDisplayName ) ) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir aDisplayedTypes.push_back( DisplayedTypes::value_type( sURLPrefix, sDisplayName ) ); 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir ::std::sort( aDisplayedTypes.begin(), aDisplayedTypes.end(), DisplayedTypeLess() ); 209*cdf0e10cSrcweir DisplayedTypes::const_iterator aDisplayEnd = aDisplayedTypes.end(); 210*cdf0e10cSrcweir for ( DisplayedTypes::const_iterator loop = aDisplayedTypes.begin(); 211*cdf0e10cSrcweir loop != aDisplayEnd; 212*cdf0e10cSrcweir ++loop 213*cdf0e10cSrcweir ) 214*cdf0e10cSrcweir insertDatasourceTypeEntryData( loop->eType, loop->sDisplayName ); 215*cdf0e10cSrcweir } // if ( m_pCollection ) 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir //------------------------------------------------------------------------- 222*cdf0e10cSrcweir void OGeneralPage::setParentTitle(const ::rtl::OUString& _sURLPrefix) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir if (!m_DBWizardMode) 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir const String sName = m_pCollection->getTypeDisplayName(_sURLPrefix); 227*cdf0e10cSrcweir if ( m_pAdminDialog ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir LocalResourceAccess aStringResAccess( PAGE_GENERAL, RSC_TABPAGE ); 230*cdf0e10cSrcweir String sMessage = String(ModuleRes(STR_PARENTTITLE)); 231*cdf0e10cSrcweir sMessage.SearchAndReplaceAscii("#",sName); 232*cdf0e10cSrcweir m_pAdminDialog->setTitle(sMessage); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir //------------------------------------------------------------------------- 238*cdf0e10cSrcweir OGeneralPage::CreationMode OGeneralPage::GetDatabaseCreationMode() const 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir if ( m_aRB_CreateDatabase.IsChecked() ) 241*cdf0e10cSrcweir return eCreateNew; 242*cdf0e10cSrcweir if ( m_aRB_GetExistingDatabase.IsChecked() ) 243*cdf0e10cSrcweir return eConnectExternal; 244*cdf0e10cSrcweir return eOpenExisting; 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir //------------------------------------------------------------------------- 248*cdf0e10cSrcweir void OGeneralPage::GetFocus() 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir OGenericAdministrationPage::GetFocus(); 251*cdf0e10cSrcweir if ( m_pLB_DocumentList.get() && m_pLB_DocumentList->IsEnabled() ) 252*cdf0e10cSrcweir m_pLB_DocumentList->GrabFocus(); 253*cdf0e10cSrcweir else if (m_pDatasourceType.get() && m_pDatasourceType->IsEnabled()) 254*cdf0e10cSrcweir m_pDatasourceType->GrabFocus(); 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir //------------------------------------------------------------------------- 258*cdf0e10cSrcweir void OGeneralPage::switchMessage(const ::rtl::OUString& _sURLPrefix) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir SPECIAL_MESSAGE eMessage = smNone; 261*cdf0e10cSrcweir if ( !_sURLPrefix.getLength()/*_eType == m_eNotSupportedKnownType*/ ) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir eMessage = smUnsupportedType; 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir if ( eMessage != m_eLastMessage ) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir sal_uInt16 nResId = 0; 270*cdf0e10cSrcweir if ( smUnsupportedType == eMessage ) 271*cdf0e10cSrcweir nResId = STR_UNSUPPORTED_DATASOURCE_TYPE; 272*cdf0e10cSrcweir String sMessage; 273*cdf0e10cSrcweir if ( nResId ) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir LocalResourceAccess aStringResAccess( PAGE_GENERAL, RSC_TABPAGE ); 276*cdf0e10cSrcweir sMessage = String(ModuleRes(nResId)); 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir m_aSpecialMessage.SetText(sMessage); 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir m_eLastMessage = eMessage; 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir //------------------------------------------------------------------------- 285*cdf0e10cSrcweir void OGeneralPage::onTypeSelected(const ::rtl::OUString& _sURLPrefix) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir // the the new URL text as indicated by the selection history 288*cdf0e10cSrcweir implSetCurrentType( _sURLPrefix ); 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir switchMessage(_sURLPrefix); 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir if ( m_aTypeSelectHandler.IsSet() ) 293*cdf0e10cSrcweir m_aTypeSelectHandler.Call(this); 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir //------------------------------------------------------------------------- 297*cdf0e10cSrcweir void OGeneralPage::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue) 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir initializeTypeList(); 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa) 302*cdf0e10cSrcweir sal_Bool bValid, bReadonly; 303*cdf0e10cSrcweir getFlags(_rSet, bValid, bReadonly); 304*cdf0e10cSrcweir if (m_DBWizardMode) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir m_aTypePreLabel.Hide(); 307*cdf0e10cSrcweir m_aTypePostLabel.Hide(); 308*cdf0e10cSrcweir m_aSpecialMessage.Hide(); 309*cdf0e10cSrcweir SetControlFontWeight(&m_aFTHeaderText); 310*cdf0e10cSrcweir SetText(String()); 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir LayoutHelper::positionBelow( m_aRB_GetExistingDatabase, *m_pDatasourceType, RelatedControls, INDENT_BELOW_RADIO ); 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir if ( !bValid || bReadonly ) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir m_aDatasourceTypeLabel.Enable( false ); 317*cdf0e10cSrcweir m_pDatasourceType->Enable( false ); 318*cdf0e10cSrcweir m_aFTDataSourceAppendix.Enable( false ); 319*cdf0e10cSrcweir m_aPB_OpenDocument.Enable( false ); 320*cdf0e10cSrcweir m_aFT_DocListLabel.Enable( false ); 321*cdf0e10cSrcweir m_pLB_DocumentList->Enable( false ); 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir else 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir m_aControlDependencies.enableOnRadioCheck( m_aRB_GetExistingDatabase, m_aDatasourceTypeLabel, *m_pDatasourceType, m_aFTDataSourceAppendix ); 326*cdf0e10cSrcweir m_aControlDependencies.enableOnRadioCheck( m_aRB_OpenDocument, m_aPB_OpenDocument, m_aFT_DocListLabel, *m_pLB_DocumentList ); 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir m_pLB_DocumentList->SetDropDownLineCount( 20 ); 330*cdf0e10cSrcweir if ( m_pLB_DocumentList->GetEntryCount() ) 331*cdf0e10cSrcweir m_pLB_DocumentList->SelectEntryPos( 0 ); 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir m_aDatasourceTypeLabel.Hide(); 334*cdf0e10cSrcweir m_aFTDataSourceAppendix.Hide(); 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir m_eOriginalCreationMode = GetDatabaseCreationMode(); 337*cdf0e10cSrcweir } 338*cdf0e10cSrcweir else 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir m_aFT_DatasourceTypeHeader.Hide(); 341*cdf0e10cSrcweir m_aRB_CreateDatabase.Hide(); 342*cdf0e10cSrcweir m_aRB_GetExistingDatabase.Hide(); 343*cdf0e10cSrcweir m_aRB_OpenDocument.Hide(); 344*cdf0e10cSrcweir m_aPB_OpenDocument.Hide(); 345*cdf0e10cSrcweir m_aFT_DocListLabel.Hide(); 346*cdf0e10cSrcweir m_pLB_DocumentList->Hide(); 347*cdf0e10cSrcweir m_aFTHeaderText.Hide(); 348*cdf0e10cSrcweir m_aFTHelpText.Hide(); 349*cdf0e10cSrcweir m_aTypePreLabel.Enable(bValid); 350*cdf0e10cSrcweir m_aTypePostLabel.Enable(bValid); 351*cdf0e10cSrcweir m_aDatasourceTypeLabel.Enable(bValid); 352*cdf0e10cSrcweir m_pDatasourceType->Enable(bValid); 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir // if the selection is invalid, disable evrything 355*cdf0e10cSrcweir String sName,sConnectURL; 356*cdf0e10cSrcweir m_bDisplayingInvalid = !bValid; 357*cdf0e10cSrcweir if ( bValid ) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir // collect some items and some values 360*cdf0e10cSrcweir SFX_ITEMSET_GET(_rSet, pNameItem, SfxStringItem, DSID_NAME, sal_True); 361*cdf0e10cSrcweir SFX_ITEMSET_GET(_rSet, pUrlItem, SfxStringItem, DSID_CONNECTURL, sal_True); 362*cdf0e10cSrcweir DBG_ASSERT(pUrlItem, "OGeneralPage::implInitControls : missing the type attribute !"); 363*cdf0e10cSrcweir DBG_ASSERT(pNameItem, "OGeneralPage::implInitControls : missing the type attribute !"); 364*cdf0e10cSrcweir sName = pNameItem->GetValue(); 365*cdf0e10cSrcweir sConnectURL = pUrlItem->GetValue(); 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir ::rtl::OUString eOldSelection = m_eCurrentSelection; 369*cdf0e10cSrcweir m_eNotSupportedKnownType = ::dbaccess::DST_UNKNOWN; 370*cdf0e10cSrcweir implSetCurrentType( ::rtl::OUString() ); 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir // compare the DSN prefix with the registered ones 373*cdf0e10cSrcweir String sDisplayName; 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir if (m_pCollection && bValid) 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir implSetCurrentType( m_pCollection->getPrefix(sConnectURL) ); 378*cdf0e10cSrcweir sDisplayName = m_pCollection->getTypeDisplayName(m_eCurrentSelection); 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir // select the correct datasource type 382*cdf0e10cSrcweir if ( approveDataSourceType( m_eCurrentSelection, sDisplayName ) 383*cdf0e10cSrcweir && ( LISTBOX_ENTRY_NOTFOUND == m_pDatasourceType->GetEntryPos( sDisplayName ) ) 384*cdf0e10cSrcweir ) 385*cdf0e10cSrcweir { // this indicates it's really a type which is known in general, but not supported on the current platform 386*cdf0e10cSrcweir // show a message saying so 387*cdf0e10cSrcweir // eSpecialMessage = smUnsupportedType; 388*cdf0e10cSrcweir insertDatasourceTypeEntryData(m_eCurrentSelection, sDisplayName); 389*cdf0e10cSrcweir // remember this type so we can show the special message again if the user selects this 390*cdf0e10cSrcweir // type again (without changing the data source) 391*cdf0e10cSrcweir m_eNotSupportedKnownType = m_pCollection->determineType(m_eCurrentSelection); 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir if (m_aRB_CreateDatabase.IsChecked() && m_DBWizardMode) 395*cdf0e10cSrcweir sDisplayName = m_pCollection->getTypeDisplayName( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("jdbc:"))); 396*cdf0e10cSrcweir m_pDatasourceType->SelectEntry(sDisplayName); 397*cdf0e10cSrcweir 398*cdf0e10cSrcweir // notify our listener that our type selection has changed (if so) 399*cdf0e10cSrcweir if ( eOldSelection != m_eCurrentSelection ) 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir setParentTitle(m_eCurrentSelection); 402*cdf0e10cSrcweir onTypeSelected(m_eCurrentSelection); 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir // a special message for the current page state 406*cdf0e10cSrcweir switchMessage(m_eCurrentSelection); 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue); 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir // For the databaseWizard we only have one entry for the MySQL Database, 413*cdf0e10cSrcweir // because we have a seperate tabpage to retrieve the respective datasource type 414*cdf0e10cSrcweir // ( ::dbaccess::DST_MYSQL_ODBC || ::dbaccess::DST_MYSQL_JDBC). Therefore we use ::dbaccess::DST_MYSQL_JDBC as a temporary 415*cdf0e10cSrcweir // representative for all MySQl databases) 416*cdf0e10cSrcweir // Also, embedded databases (embedded HSQL, at the moment), are not to appear in the list of 417*cdf0e10cSrcweir // databases to connect to. 418*cdf0e10cSrcweir bool OGeneralPage::approveDataSourceType( const ::rtl::OUString& _sURLPrefix, String& _inout_rDisplayName ) 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir const ::dbaccess::DATASOURCE_TYPE eType = m_pCollection->determineType(_sURLPrefix); 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir if ( m_DBWizardMode ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir switch ( eType ) 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir case ::dbaccess::DST_MYSQL_JDBC: 427*cdf0e10cSrcweir _inout_rDisplayName = m_sMySQLEntry; 428*cdf0e10cSrcweir break; 429*cdf0e10cSrcweir case ::dbaccess::DST_MYSQL_ODBC: 430*cdf0e10cSrcweir case ::dbaccess::DST_MYSQL_NATIVE: 431*cdf0e10cSrcweir // don't display those, the decision whether the user connects via JDBC/ODBC/C-OOo is made on another 432*cdf0e10cSrcweir // page 433*cdf0e10cSrcweir _inout_rDisplayName = String(); 434*cdf0e10cSrcweir break; 435*cdf0e10cSrcweir default: 436*cdf0e10cSrcweir break; 437*cdf0e10cSrcweir } 438*cdf0e10cSrcweir } 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir if ( eType == ::dbaccess::DST_MYSQL_NATIVE_DIRECT ) 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir // do not display the Connector/OOo driver itself, it is always wrapped via the MySQL-Driver, if 443*cdf0e10cSrcweir // this driver is installed 444*cdf0e10cSrcweir if ( m_pCollection->hasDriver( "sdbc:mysql:mysqlc:" ) ) 445*cdf0e10cSrcweir _inout_rDisplayName = String(); 446*cdf0e10cSrcweir } 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir if ( eType == ::dbaccess::DST_EMBEDDED_HSQLDB ) 449*cdf0e10cSrcweir _inout_rDisplayName = String(); 450*cdf0e10cSrcweir 451*cdf0e10cSrcweir return _inout_rDisplayName.Len() > 0; 452*cdf0e10cSrcweir } 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir // ----------------------------------------------------------------------- 456*cdf0e10cSrcweir void OGeneralPage::insertDatasourceTypeEntryData(const ::rtl::OUString& _sType, String sDisplayName) 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir // insert a (temporary) entry 459*cdf0e10cSrcweir sal_uInt16 nPos = m_pDatasourceType->InsertEntry(sDisplayName); 460*cdf0e10cSrcweir if ( nPos >= m_aURLPrefixes.size() ) 461*cdf0e10cSrcweir m_aURLPrefixes.resize(nPos+1); 462*cdf0e10cSrcweir m_aURLPrefixes[nPos] = _sType; 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir // ----------------------------------------------------------------------- 466*cdf0e10cSrcweir void OGeneralPage::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList) 467*cdf0e10cSrcweir { 468*cdf0e10cSrcweir _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aTypePreLabel)); 469*cdf0e10cSrcweir _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aDatasourceTypeLabel)); 470*cdf0e10cSrcweir _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aTypePostLabel)); 471*cdf0e10cSrcweir _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aSpecialMessage)); 472*cdf0e10cSrcweir _rControlList.push_back(new ODisableWrapper<FixedText>(&m_aFTDataSourceAppendix)); 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir // ----------------------------------------------------------------------- 475*cdf0e10cSrcweir void OGeneralPage::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList) 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir _rControlList.push_back(new OSaveValueWrapper<ListBox>(m_pDatasourceType.get())); 478*cdf0e10cSrcweir } 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir //------------------------------------------------------------------------- 481*cdf0e10cSrcweir SfxTabPage* OGeneralPage::Create(Window* _pParent, const SfxItemSet& _rAttrSet, sal_Bool _bWizardMode) 482*cdf0e10cSrcweir { 483*cdf0e10cSrcweir return ( new OGeneralPage( _pParent, _rAttrSet, _bWizardMode ) ); 484*cdf0e10cSrcweir } 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir //------------------------------------------------------------------------- 487*cdf0e10cSrcweir void OGeneralPage::implSetCurrentType( const ::rtl::OUString& _eType ) 488*cdf0e10cSrcweir { 489*cdf0e10cSrcweir if ( _eType == m_eCurrentSelection ) 490*cdf0e10cSrcweir return; 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir m_eCurrentSelection = _eType; 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir 495*cdf0e10cSrcweir //------------------------------------------------------------------------- 496*cdf0e10cSrcweir void OGeneralPage::Reset(const SfxItemSet& _rCoreAttrs) 497*cdf0e10cSrcweir { 498*cdf0e10cSrcweir // reset all locale data 499*cdf0e10cSrcweir implSetCurrentType( ::rtl::OUString() ); 500*cdf0e10cSrcweir // this ensures that our type selection link will be called, even if the new is is the same as the 501*cdf0e10cSrcweir // current one 502*cdf0e10cSrcweir OGenericAdministrationPage::Reset(_rCoreAttrs); 503*cdf0e10cSrcweir } 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir //------------------------------------------------------------------------- 506*cdf0e10cSrcweir sal_Bool OGeneralPage::FillItemSet(SfxItemSet& _rCoreAttrs) 507*cdf0e10cSrcweir { 508*cdf0e10cSrcweir sal_Bool bChangedSomething = sal_False; 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir bool bCommitTypeSelection = true; 511*cdf0e10cSrcweir if ( m_DBWizardMode ) 512*cdf0e10cSrcweir { 513*cdf0e10cSrcweir if ( m_aRB_CreateDatabase.IsChecked() ) 514*cdf0e10cSrcweir { 515*cdf0e10cSrcweir _rCoreAttrs.Put(SfxStringItem(DSID_CONNECTURL, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:dbase:")))); 516*cdf0e10cSrcweir bChangedSomething = sal_True; 517*cdf0e10cSrcweir bCommitTypeSelection = false; 518*cdf0e10cSrcweir } 519*cdf0e10cSrcweir else if ( m_aRB_OpenDocument.IsChecked() ) 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir if ( m_aRB_OpenDocument.GetSavedValue() != m_aRB_OpenDocument.IsChecked() ) 522*cdf0e10cSrcweir bChangedSomething = sal_True; 523*cdf0e10cSrcweir 524*cdf0e10cSrcweir // TODO 525*cdf0e10cSrcweir bCommitTypeSelection = false; 526*cdf0e10cSrcweir } 527*cdf0e10cSrcweir } 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir if ( bCommitTypeSelection ) 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir sal_uInt16 nEntry = m_pDatasourceType->GetSelectEntryPos(); 532*cdf0e10cSrcweir ::rtl::OUString sURLPrefix = m_aURLPrefixes[nEntry]; 533*cdf0e10cSrcweir if (m_DBWizardMode) 534*cdf0e10cSrcweir { 535*cdf0e10cSrcweir if ( ( m_pDatasourceType->GetSavedValue() != nEntry ) 536*cdf0e10cSrcweir || ( GetDatabaseCreationMode() != m_eOriginalCreationMode ) 537*cdf0e10cSrcweir ) 538*cdf0e10cSrcweir { 539*cdf0e10cSrcweir _rCoreAttrs.Put(SfxStringItem(DSID_CONNECTURL,sURLPrefix )); 540*cdf0e10cSrcweir bChangedSomething = sal_True; 541*cdf0e10cSrcweir } 542*cdf0e10cSrcweir else 543*cdf0e10cSrcweir implSetCurrentType(sURLPrefix); 544*cdf0e10cSrcweir } 545*cdf0e10cSrcweir else 546*cdf0e10cSrcweir { 547*cdf0e10cSrcweir if ( m_pDatasourceType->GetSavedValue() != nEntry) 548*cdf0e10cSrcweir { 549*cdf0e10cSrcweir _rCoreAttrs.Put(SfxStringItem(DSID_CONNECTURL, sURLPrefix)); 550*cdf0e10cSrcweir bChangedSomething = sal_True; 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir } 553*cdf0e10cSrcweir } 554*cdf0e10cSrcweir return bChangedSomething; 555*cdf0e10cSrcweir } 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir //------------------------------------------------------------------------- 558*cdf0e10cSrcweir IMPL_LINK(OGeneralPage, OnDatasourceTypeSelected, ListBox*, _pBox) 559*cdf0e10cSrcweir { 560*cdf0e10cSrcweir // get the type from the entry data 561*cdf0e10cSrcweir sal_Int16 nSelected = _pBox->GetSelectEntryPos(); 562*cdf0e10cSrcweir const ::rtl::OUString sURLPrefix = m_aURLPrefixes[nSelected]; 563*cdf0e10cSrcweir 564*cdf0e10cSrcweir setParentTitle(sURLPrefix); 565*cdf0e10cSrcweir // let the impl method do all the stuff 566*cdf0e10cSrcweir onTypeSelected(sURLPrefix); 567*cdf0e10cSrcweir // tell the listener we were modified 568*cdf0e10cSrcweir callModifiedHdl(); 569*cdf0e10cSrcweir // outta here 570*cdf0e10cSrcweir return 0L; 571*cdf0e10cSrcweir } 572*cdf0e10cSrcweir 573*cdf0e10cSrcweir //------------------------------------------------------------------------- 574*cdf0e10cSrcweir OGeneralPage::DocumentDescriptor OGeneralPage::GetSelectedDocument() const 575*cdf0e10cSrcweir { 576*cdf0e10cSrcweir DocumentDescriptor aDocument; 577*cdf0e10cSrcweir if ( m_aBrowsedDocument.sURL.Len() ) 578*cdf0e10cSrcweir aDocument = m_aBrowsedDocument; 579*cdf0e10cSrcweir else 580*cdf0e10cSrcweir { 581*cdf0e10cSrcweir aDocument.sURL = m_pLB_DocumentList->GetSelectedDocumentURL(); 582*cdf0e10cSrcweir aDocument.sFilter = m_pLB_DocumentList->GetSelectedDocumentFilter(); 583*cdf0e10cSrcweir } 584*cdf0e10cSrcweir return aDocument; 585*cdf0e10cSrcweir } 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir //------------------------------------------------------------------------- 588*cdf0e10cSrcweir IMPL_LINK(OGeneralPage, OnSetupModeSelected, RadioButton*, /*_pBox*/) 589*cdf0e10cSrcweir { 590*cdf0e10cSrcweir if ( m_aCreationModeHandler.IsSet() ) 591*cdf0e10cSrcweir m_aCreationModeHandler.Call(this); 592*cdf0e10cSrcweir return 1L; 593*cdf0e10cSrcweir } 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir //------------------------------------------------------------------------- 596*cdf0e10cSrcweir IMPL_LINK(OGeneralPage, OnDocumentSelected, ListBox*, /*_pBox*/) 597*cdf0e10cSrcweir { 598*cdf0e10cSrcweir m_aDocumentSelectionHandler.Call( this ); 599*cdf0e10cSrcweir return 0L; 600*cdf0e10cSrcweir } 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir //------------------------------------------------------------------------- 603*cdf0e10cSrcweir IMPL_LINK(OGeneralPage, OnOpenDocument, PushButton*, /*_pBox*/) 604*cdf0e10cSrcweir { 605*cdf0e10cSrcweir ::sfx2::FileDialogHelper aFileDlg( WB_OPEN, ::String::CreateFromAscii("sdatabase") ); 606*cdf0e10cSrcweir const SfxFilter* pFilter = getStandardDatabaseFilter(); 607*cdf0e10cSrcweir if ( pFilter ) 608*cdf0e10cSrcweir { 609*cdf0e10cSrcweir // aFileDlg.AddFilter(pFilter->GetUIName(),pFilter->GetDefaultExtension()); 610*cdf0e10cSrcweir aFileDlg.SetCurrentFilter(pFilter->GetUIName()); 611*cdf0e10cSrcweir } 612*cdf0e10cSrcweir if ( aFileDlg.Execute() == ERRCODE_NONE ) 613*cdf0e10cSrcweir { 614*cdf0e10cSrcweir String sPath = aFileDlg.GetPath(); 615*cdf0e10cSrcweir if ( aFileDlg.GetCurrentFilter() != pFilter->GetUIName() || !pFilter->GetWildcard().Matches(sPath) ) 616*cdf0e10cSrcweir { 617*cdf0e10cSrcweir String sMessage(ModuleRes(STR_ERR_USE_CONNECT_TO)); 618*cdf0e10cSrcweir InfoBox aError(this, sMessage); 619*cdf0e10cSrcweir aError.Execute(); 620*cdf0e10cSrcweir m_aRB_GetExistingDatabase.Check(); 621*cdf0e10cSrcweir OnSetupModeSelected(&m_aRB_GetExistingDatabase); 622*cdf0e10cSrcweir return 0L; 623*cdf0e10cSrcweir } 624*cdf0e10cSrcweir m_aBrowsedDocument.sURL = sPath; 625*cdf0e10cSrcweir m_aBrowsedDocument.sFilter = String(); 626*cdf0e10cSrcweir m_aChooseDocumentHandler.Call( this ); 627*cdf0e10cSrcweir return 1L; 628*cdf0e10cSrcweir } 629*cdf0e10cSrcweir 630*cdf0e10cSrcweir return 0L; 631*cdf0e10cSrcweir } 632*cdf0e10cSrcweir 633*cdf0e10cSrcweir //......................................................................... 634*cdf0e10cSrcweir } // namespace dbaui 635*cdf0e10cSrcweir //......................................................................... 636*cdf0e10cSrcweir 637