1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "dsnItem.hxx"
21 #include "generalpage.hxx"
22 #include <connectivity/dbexception.hxx>
23 #include "dbu_dlg.hrc"
24 #include "dsitems.hxx"
25 #include "dbustrings.hrc"
26 #include "dbadmin.hxx"
27 #include <sfx2/filedlghelper.hxx>
28 #include <sfx2/docfilt.hxx>
29 #include <vcl/stdtext.hxx>
30 #include "localresaccess.hxx"
31 #include <vcl/msgbox.hxx>
32 #include <svl/stritem.hxx>
33 #include <vcl/waitobj.hxx>
34 #include <com/sun/star/sdbc/XDriverAccess.hpp>
35 #include <com/sun/star/beans/PropertyValue.hpp>
36 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
37 #include <com/sun/star/uno/Sequence.hxx>
38 #include <com/sun/star/container/XNameAccess.hpp>
39 #include "DriverSettings.hxx"
40 #include "UITools.hxx"
41 #include <comphelper/processfactory.hxx>
42 #include <unotools/confignode.hxx>
43 #include <osl/diagnose.h>
47 using namespace ::com::sun::star
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::sdbc
;
50 using namespace ::com::sun::star::beans
;
51 using namespace ::com::sun::star::container
;
54 OGeneralPage::OGeneralPage( vcl::Window
* pParent
, const OUString
& _rUIXMLDescription
, const SfxItemSet
& _rItems
)
55 :OGenericAdministrationPage( pParent
, "PageGeneral", _rUIXMLDescription
, _rItems
)
56 ,m_eNotSupportedKnownType ( ::dbaccess::DST_UNKNOWN
)
57 ,m_pSpecialMessage ( NULL
)
58 ,m_eLastMessage ( smNone
)
59 ,m_bDisplayingInvalid ( false )
60 ,m_bInitTypeList ( true )
61 ,m_pDatasourceType ( NULL
)
62 ,m_pCollection ( NULL
)
64 get( m_pDatasourceType
, "datasourceType" );
65 get( m_pSpecialMessage
, "specialMessage" );
67 // extract the datasource type collection from the item set
68 const DbuTypeCollectionItem
* pCollectionItem
= PTR_CAST(DbuTypeCollectionItem
, _rItems
.GetItem(DSID_TYPECOLLECTION
));
70 m_pCollection
= pCollectionItem
->getCollection();
71 SAL_WARN_IF(!m_pCollection
, "dbaccess", "OGeneralPage::OGeneralPage : really need a DSN type collection !");
74 m_pDatasourceType
->SetSelectHdl(LINK(this, OGeneralPage
, OnDatasourceTypeSelected
));
77 OGeneralPage::~OGeneralPage()
82 void OGeneralPage::dispose()
84 m_pSpecialMessage
.clear();
85 m_pDatasourceType
.clear();
86 OGenericAdministrationPage::dispose();
94 OUString sDisplayName
;
96 DisplayedType( const OUString
& _eType
, const OUString
& _rDisplayName
) : eType( _eType
), sDisplayName( _rDisplayName
) { }
98 typedef ::std::vector
< DisplayedType
> DisplayedTypes
;
100 struct DisplayedTypeLess
: ::std::binary_function
< DisplayedType
, DisplayedType
, bool >
102 bool operator() ( const DisplayedType
& _rLHS
, const DisplayedType
& _rRHS
)
104 return _rLHS
.eType
< _rRHS
.eType
;
109 void OGeneralPage::initializeTypeList()
111 if ( m_bInitTypeList
)
113 m_bInitTypeList
= false;
114 m_pDatasourceType
->Clear();
118 DisplayedTypes aDisplayedTypes
;
120 ::dbaccess::ODsnTypeCollection::TypeIterator aEnd
= m_pCollection
->end();
121 for ( ::dbaccess::ODsnTypeCollection::TypeIterator aTypeLoop
= m_pCollection
->begin();
126 const OUString sURLPrefix
= aTypeLoop
.getURLPrefix();
127 if ( !sURLPrefix
.isEmpty() )
129 OUString sDisplayName
= aTypeLoop
.getDisplayName();
130 if ( m_pDatasourceType
->GetEntryPos( sDisplayName
) == LISTBOX_ENTRY_NOTFOUND
131 && approveDatasourceType( sURLPrefix
, sDisplayName
) )
133 aDisplayedTypes
.push_back( DisplayedTypes::value_type( sURLPrefix
, sDisplayName
) );
137 ::std::sort( aDisplayedTypes
.begin(), aDisplayedTypes
.end(), DisplayedTypeLess() );
138 DisplayedTypes::const_iterator aDisplayEnd
= aDisplayedTypes
.end();
139 for ( DisplayedTypes::const_iterator loop
= aDisplayedTypes
.begin();
143 insertDatasourceTypeEntryData( loop
->eType
, loop
->sDisplayName
);
148 void OGeneralPageWizard::initializeEmbeddedDBList()
150 if ( m_bInitEmbeddedDBList
)
152 m_bInitEmbeddedDBList
= false;
153 m_pEmbeddedDBType
->Clear();
157 DisplayedTypes aDisplayedTypes
;
159 ::dbaccess::ODsnTypeCollection::TypeIterator aEnd
= m_pCollection
->end();
160 for ( ::dbaccess::ODsnTypeCollection::TypeIterator aTypeLoop
= m_pCollection
->begin();
165 const OUString sURLPrefix
= aTypeLoop
.getURLPrefix();
166 if ( !sURLPrefix
.isEmpty() )
168 OUString sDisplayName
= aTypeLoop
.getDisplayName();
169 if ( m_pEmbeddedDBType
->GetEntryPos( sDisplayName
) == LISTBOX_ENTRY_NOTFOUND
170 && dbaccess::ODsnTypeCollection::isEmbeddedDatabase( sURLPrefix
) )
172 aDisplayedTypes
.push_back( DisplayedTypes::value_type( sURLPrefix
, sDisplayName
) );
176 ::std::sort( aDisplayedTypes
.begin(), aDisplayedTypes
.end(), DisplayedTypeLess() );
177 DisplayedTypes::const_iterator aDisplayEnd
= aDisplayedTypes
.end();
178 for ( DisplayedTypes::const_iterator loop
= aDisplayedTypes
.begin();
182 insertEmbeddedDBTypeEntryData( loop
->eType
, loop
->sDisplayName
);
187 void OGeneralPage::setParentTitle(const OUString
&)
191 void OGeneralPage::switchMessage(const OUString
& _sURLPrefix
)
193 SPECIAL_MESSAGE eMessage
= smNone
;
194 if ( _sURLPrefix
.isEmpty()/*_eType == m_eNotSupportedKnownType*/ )
196 eMessage
= smUnsupportedType
;
199 if ( eMessage
!= m_eLastMessage
)
201 sal_uInt16 nResId
= 0;
202 if ( smUnsupportedType
== eMessage
)
203 nResId
= STR_UNSUPPORTED_DATASOURCE_TYPE
;
206 sMessage
= ModuleRes( nResId
);
208 m_pSpecialMessage
->SetText( sMessage
);
209 m_eLastMessage
= eMessage
;
213 void OGeneralPage::onTypeSelected(const OUString
& _sURLPrefix
)
215 // the new URL text as indicated by the selection history
216 implSetCurrentType( _sURLPrefix
);
218 switchMessage(_sURLPrefix
);
220 if ( m_aTypeSelectHandler
.IsSet() )
221 m_aTypeSelectHandler
.Call(this);
224 void OGeneralPage::implInitControls( const SfxItemSet
& _rSet
, bool _bSaveValue
)
226 initializeTypeList();
228 m_pDatasourceType
->SelectEntry( getDatasourceName( _rSet
) );
230 // notify our listener that our type selection has changed (if so)
231 // FIXME: how to detect that it did not changed? (fdo#62937)
232 setParentTitle( m_eCurrentSelection
);
233 onTypeSelected( m_eCurrentSelection
);
235 // a special message for the current page state
236 switchMessage( m_eCurrentSelection
);
238 OGenericAdministrationPage::implInitControls( _rSet
, _bSaveValue
);
241 OUString
OGeneralPageWizard::getEmbeddedDBName( const SfxItemSet
& _rSet
)
243 // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
244 bool bValid
, bReadonly
;
245 getFlags( _rSet
, bValid
, bReadonly
);
247 // if the selection is invalid, disable everything
248 OUString sName
,sConnectURL
;
251 // collect some items and some values
252 SFX_ITEMSET_GET( _rSet
, pNameItem
, SfxStringItem
, DSID_NAME
, true );
253 SFX_ITEMSET_GET( _rSet
, pUrlItem
, SfxStringItem
, DSID_CONNECTURL
, true );
256 sName
= pNameItem
->GetValue();
257 sConnectURL
= pUrlItem
->GetValue();
260 m_eNotSupportedKnownType
= ::dbaccess::DST_UNKNOWN
;
261 implSetCurrentType( OUString() );
263 // compare the DSN prefix with the registered ones
264 OUString sDisplayName
;
266 if (m_pCollection
&& bValid
)
268 implSetCurrentType( m_pCollection
->getEmbeddedDatabase() );
269 sDisplayName
= m_pCollection
->getTypeDisplayName( m_eCurrentSelection
);
272 // select the correct datasource type
273 if ( dbaccess::ODsnTypeCollection::isEmbeddedDatabase( m_eCurrentSelection
)
274 && ( LISTBOX_ENTRY_NOTFOUND
== m_pEmbeddedDBType
->GetEntryPos( sDisplayName
) )
276 { // this indicates it's really a type which is known in general, but not supported on the current platform
277 // show a message saying so
278 // eSpecialMessage = smUnsupportedType;
279 insertEmbeddedDBTypeEntryData( m_eCurrentSelection
, sDisplayName
);
280 // remember this type so we can show the special message again if the user selects this
281 // type again (without changing the data source)
282 m_eNotSupportedKnownType
= m_pCollection
->determineType( m_eCurrentSelection
); // TODO:
288 OUString
OGeneralPage::getDatasourceName( const SfxItemSet
& _rSet
)
290 // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
291 bool bValid
, bReadonly
;
292 getFlags( _rSet
, bValid
, bReadonly
);
294 // if the selection is invalid, disable everything
295 OUString sName
,sConnectURL
;
296 m_bDisplayingInvalid
= !bValid
;
299 // collect some items and some values
300 SFX_ITEMSET_GET( _rSet
, pNameItem
, SfxStringItem
, DSID_NAME
, true );
301 SFX_ITEMSET_GET( _rSet
, pUrlItem
, SfxStringItem
, DSID_CONNECTURL
, true );
304 sName
= pNameItem
->GetValue();
305 sConnectURL
= pUrlItem
->GetValue();
308 m_eNotSupportedKnownType
= ::dbaccess::DST_UNKNOWN
;
309 implSetCurrentType( OUString() );
311 // compare the DSN prefix with the registered ones
312 OUString sDisplayName
;
314 if (m_pCollection
&& bValid
)
316 implSetCurrentType( m_pCollection
->getPrefix( sConnectURL
) );
317 sDisplayName
= m_pCollection
->getTypeDisplayName( m_eCurrentSelection
);
320 // select the correct datasource type
321 if ( approveDatasourceType( m_eCurrentSelection
, sDisplayName
)
322 && ( LISTBOX_ENTRY_NOTFOUND
== m_pDatasourceType
->GetEntryPos( sDisplayName
) )
324 { // this indicates it's really a type which is known in general, but not supported on the current platform
325 // show a message saying so
326 // eSpecialMessage = smUnsupportedType;
327 insertDatasourceTypeEntryData( m_eCurrentSelection
, sDisplayName
);
328 // remember this type so we can show the special message again if the user selects this
329 // type again (without changing the data source)
330 m_eNotSupportedKnownType
= m_pCollection
->determineType( m_eCurrentSelection
);
336 // For the databaseWizard we only have one entry for the MySQL Database,
337 // because we have a separate tabpage to retrieve the respective datasource type
338 // ( ::dbaccess::DST_MYSQL_ODBC || ::dbaccess::DST_MYSQL_JDBC). Therefore we use ::dbaccess::DST_MYSQL_JDBC as a temporary
339 // representative for all MySQl databases)
340 // Also, embedded databases (embedded HSQL, at the moment), are not to appear in the list of
341 // databases to connect to.
342 bool OGeneralPage::approveDatasourceType( const OUString
& _sURLPrefix
, OUString
& _inout_rDisplayName
)
344 return approveDatasourceType( m_pCollection
->determineType(_sURLPrefix
), _inout_rDisplayName
);
347 bool OGeneralPage::approveDatasourceType( ::dbaccess::DATASOURCE_TYPE eType
, OUString
& _inout_rDisplayName
)
349 if ( eType
== ::dbaccess::DST_MYSQL_NATIVE_DIRECT
)
351 // do not display the Connector/OOo driver itself, it is always wrapped via the MySQL-Driver, if
352 // this driver is installed
353 if ( m_pCollection
->hasDriver( "sdbc:mysql:mysqlc:" ) )
354 _inout_rDisplayName
.clear();
357 if ( eType
== ::dbaccess::DST_EMBEDDED_HSQLDB
358 || eType
== ::dbaccess::DST_EMBEDDED_FIREBIRD
)
359 _inout_rDisplayName
.clear();
361 return _inout_rDisplayName
.getLength() > 0;
364 void OGeneralPage::insertDatasourceTypeEntryData(const OUString
& _sType
, const OUString
& sDisplayName
)
366 // insert a (temporary) entry
367 sal_uInt16 nPos
= m_pDatasourceType
->InsertEntry(sDisplayName
);
368 if ( nPos
>= m_aURLPrefixes
.size() )
369 m_aURLPrefixes
.resize(nPos
+1);
370 m_aURLPrefixes
[nPos
] = _sType
;
373 void OGeneralPageWizard::insertEmbeddedDBTypeEntryData(const OUString
& _sType
, const OUString
& sDisplayName
)
375 // insert a (temporary) entry
376 sal_uInt16 nPos
= m_pEmbeddedDBType
->InsertEntry(sDisplayName
);
377 if ( nPos
>= m_aEmbeddedURLPrefixes
.size() )
378 m_aEmbeddedURLPrefixes
.resize(nPos
+1);
379 m_aEmbeddedURLPrefixes
[nPos
] = _sType
;
382 void OGeneralPage::fillWindows(::std::vector
< ISaveValueWrapper
* >& _rControlList
)
384 _rControlList
.push_back( new ODisableWrapper
<FixedText
>( m_pSpecialMessage
) );
387 void OGeneralPage::fillControls(::std::vector
< ISaveValueWrapper
* >& _rControlList
)
389 _rControlList
.push_back( new OSaveValueWrapper
<ListBox
>( m_pDatasourceType
) );
392 void OGeneralPage::implSetCurrentType( const OUString
& _eType
)
394 if ( _eType
== m_eCurrentSelection
)
397 m_eCurrentSelection
= _eType
;
400 void OGeneralPage::Reset(const SfxItemSet
* _rCoreAttrs
)
402 // reset all locale data
403 implSetCurrentType( OUString() );
404 // this ensures that our type selection link will be called, even if the new one is the same as the
406 OGenericAdministrationPage::Reset(_rCoreAttrs
);
409 IMPL_LINK( OGeneralPageWizard
, OnEmbeddedDBTypeSelected
, ListBox
*, _pBox
)
411 // get the type from the entry data
412 sal_uInt16 nSelected
= _pBox
->GetSelectEntryPos();
413 if (nSelected
>= m_aEmbeddedURLPrefixes
.size() )
415 SAL_WARN("dbaccess.ui.OGeneralPage", "Got out-of-range value '" << nSelected
<< "' from the DatasourceType selection ListBox's GetSelectEntryPos(): no corresponding URL prefix");
418 const OUString sURLPrefix
= m_aEmbeddedURLPrefixes
[ nSelected
];
420 setParentTitle( sURLPrefix
);
421 // let the impl method do all the stuff
422 onTypeSelected( sURLPrefix
);
423 // tell the listener we were modified
429 IMPL_LINK( OGeneralPage
, OnDatasourceTypeSelected
, ListBox
*, _pBox
)
431 // get the type from the entry data
432 sal_uInt16 nSelected
= _pBox
->GetSelectEntryPos();
433 if (nSelected
>= m_aURLPrefixes
.size() )
435 SAL_WARN("dbaccess.ui.OGeneralPage", "Got out-of-range value '" << nSelected
<< "' from the DatasourceType selection ListBox's GetSelectEntryPos(): no corresponding URL prefix");
438 const OUString sURLPrefix
= m_aURLPrefixes
[ nSelected
];
440 setParentTitle( sURLPrefix
);
441 // let the impl method do all the stuff
442 onTypeSelected( sURLPrefix
);
443 // tell the listener we were modified
449 // OGeneralPageDialog
450 OGeneralPageDialog::OGeneralPageDialog( vcl::Window
* pParent
, const SfxItemSet
& _rItems
)
451 :OGeneralPage( pParent
, "dbaccess/ui/generalpagedialog.ui", _rItems
)
455 void OGeneralPageDialog::setParentTitle( const OUString
& _sURLPrefix
)
457 const OUString sName
= m_pCollection
->getTypeDisplayName( _sURLPrefix
);
458 if ( m_pAdminDialog
)
460 OUString sMessage
= OUString( ModuleRes( STR_PARENTTITLE_GENERAL
) );
461 m_pAdminDialog
->setTitle( sMessage
.replaceAll( "#", sName
) );
465 void OGeneralPageDialog::implInitControls( const SfxItemSet
& _rSet
, bool _bSaveValue
)
467 OGeneralPage::implInitControls( _rSet
, _bSaveValue
);
469 // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
470 bool bValid
, bReadonly
;
471 getFlags(_rSet
, bValid
, bReadonly
);
473 m_pDatasourceType
->Enable( bValid
);
476 bool OGeneralPageDialog::FillItemSet( SfxItemSet
* _rCoreAttrs
)
478 bool bChangedSomething
= false;
480 sal_uInt16 nEntry
= m_pDatasourceType
->GetSelectEntryPos();
481 OUString sURLPrefix
= m_aURLPrefixes
[ nEntry
];
483 if ( m_pDatasourceType
->IsValueChangedFromSaved() )
485 _rCoreAttrs
->Put( SfxStringItem( DSID_CONNECTURL
, sURLPrefix
) );
486 bChangedSomething
= true;
489 return bChangedSomething
;
492 // OGeneralPageWizard
493 OGeneralPageWizard::OGeneralPageWizard( vcl::Window
* pParent
, const SfxItemSet
& _rItems
)
494 :OGeneralPage( pParent
, "dbaccess/ui/generalpagewizard.ui", _rItems
)
495 ,m_pRB_CreateDatabase ( NULL
)
496 ,m_pRB_OpenExistingDatabase ( NULL
)
497 ,m_pRB_ConnectDatabase ( NULL
)
498 ,m_pFT_EmbeddedDBLabel ( NULL
)
499 ,m_pEmbeddedDBType ( NULL
)
500 ,m_pFT_DocListLabel ( NULL
)
501 ,m_pLB_DocumentList ( NULL
)
502 ,m_pPB_OpenDatabase ( NULL
)
503 ,m_eOriginalCreationMode ( eCreateNew
)
504 ,m_bInitEmbeddedDBList ( true )
506 get( m_pRB_CreateDatabase
, "createDatabase" );
507 get( m_pRB_OpenExistingDatabase
, "openExistingDatabase" );
508 get( m_pRB_ConnectDatabase
, "connectDatabase" );
509 get( m_pFT_EmbeddedDBLabel
, "embeddeddbLabel" );
510 get( m_pEmbeddedDBType
, "embeddeddbList" );
511 get( m_pFT_DocListLabel
, "docListLabel" );
512 get( m_pLB_DocumentList
, "documentList" );
513 get( m_pPB_OpenDatabase
, "openDatabase" );
515 // If no driver for embedded DBs is installed, and no dBase driver, then hide the "Create new database" option
516 sal_Int32 nCreateNewDBIndex
= m_pCollection
->getIndexOf( m_pCollection
->getEmbeddedDatabase() );
517 if ( nCreateNewDBIndex
== -1 )
518 nCreateNewDBIndex
= m_pCollection
->getIndexOf( OUString( "sdbc:dbase:" ) );
519 bool bHideCreateNew
= ( nCreateNewDBIndex
== -1 );
521 // also, if our application policies tell us to hide the option, do it
522 ::utl::OConfigurationTreeRoot
aConfig( ::utl::OConfigurationTreeRoot::createWithComponentContext(
523 ::comphelper::getProcessComponentContext(),
524 OUString( "/org.openoffice.Office.DataAccess/Policies/Features/Base" )
526 bool bAllowCreateLocalDatabase( true );
527 OSL_VERIFY( aConfig
.getNodeValue( "CreateLocalDatabase" ) >>= bAllowCreateLocalDatabase
);
528 if ( !bAllowCreateLocalDatabase
)
529 bHideCreateNew
= true;
531 if ( bHideCreateNew
)
533 m_pRB_CreateDatabase
->Hide();
534 m_pRB_ConnectDatabase
->Check();
537 m_pRB_CreateDatabase
->Check();
540 m_pEmbeddedDBType
->SetSelectHdl(LINK(this, OGeneralPageWizard
, OnEmbeddedDBTypeSelected
));
541 m_pRB_CreateDatabase
->SetClickHdl( LINK( this, OGeneralPageWizard
, OnCreateDatabaseModeSelected
) );
542 m_pRB_ConnectDatabase
->SetClickHdl( LINK( this, OGeneralPageWizard
, OnSetupModeSelected
) );
543 m_pRB_OpenExistingDatabase
->SetClickHdl( LINK( this, OGeneralPageWizard
, OnSetupModeSelected
) );
544 m_pLB_DocumentList
->SetSelectHdl( LINK( this, OGeneralPageWizard
, OnDocumentSelected
) );
545 m_pPB_OpenDatabase
->SetClickHdl( LINK( this, OGeneralPageWizard
, OnOpenDocument
) );
548 OGeneralPageWizard::~OGeneralPageWizard()
553 void OGeneralPageWizard::dispose()
555 m_pRB_CreateDatabase
.clear();
556 m_pRB_OpenExistingDatabase
.clear();
557 m_pRB_ConnectDatabase
.clear();
558 m_pFT_EmbeddedDBLabel
.clear();
559 m_pEmbeddedDBType
.clear();
560 m_pFT_DocListLabel
.clear();
561 m_pLB_DocumentList
.clear();
562 m_pPB_OpenDatabase
.clear();
563 OGeneralPage::dispose();
566 OGeneralPageWizard::CreationMode
OGeneralPageWizard::GetDatabaseCreationMode() const
568 if ( m_pRB_CreateDatabase
->IsChecked() )
570 if ( m_pRB_ConnectDatabase
->IsChecked() )
571 return eConnectExternal
;
572 return eOpenExisting
;
575 void OGeneralPageWizard::GetFocus()
577 OGeneralPage::GetFocus();
578 if ( m_pLB_DocumentList
&& m_pLB_DocumentList
->IsEnabled() )
579 m_pLB_DocumentList
->GrabFocus();
580 else if ( m_pDatasourceType
&& m_pDatasourceType
->IsEnabled() )
581 m_pDatasourceType
->GrabFocus();
584 void OGeneralPageWizard::implInitControls( const SfxItemSet
& _rSet
, bool _bSaveValue
)
586 OGeneralPage::implInitControls( _rSet
, _bSaveValue
);
588 initializeEmbeddedDBList();
589 m_pEmbeddedDBType
->SelectEntry( getEmbeddedDBName( _rSet
) );
591 // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
592 bool bValid
, bReadonly
;
593 getFlags( _rSet
, bValid
, bReadonly
);
595 SetText( OUString() );
597 LayoutHelper::positionBelow( *m_pRB_ConnectDatabase
, *m_pDatasourceType
, RelatedControls
, INDENT_BELOW_RADIO
);
599 if ( !bValid
|| bReadonly
)
601 m_pFT_EmbeddedDBLabel
->Enable( false );
602 m_pDatasourceType
->Enable( false );
603 m_pPB_OpenDatabase
->Enable( false );
604 m_pFT_DocListLabel
->Enable( false );
605 m_pLB_DocumentList
->Enable( false );
609 m_aControlDependencies
.enableOnRadioCheck( *m_pRB_CreateDatabase
, *m_pEmbeddedDBType
, *m_pFT_EmbeddedDBLabel
);
610 m_aControlDependencies
.enableOnRadioCheck( *m_pRB_ConnectDatabase
, *m_pDatasourceType
);
611 m_aControlDependencies
.enableOnRadioCheck( *m_pRB_OpenExistingDatabase
, *m_pPB_OpenDatabase
, *m_pFT_DocListLabel
, *m_pLB_DocumentList
);
614 m_pLB_DocumentList
->SetDropDownLineCount( 20 );
615 if ( m_pLB_DocumentList
->GetEntryCount() )
616 m_pLB_DocumentList
->SelectEntryPos( 0 );
618 m_eOriginalCreationMode
= GetDatabaseCreationMode();
621 OUString
OGeneralPageWizard::getDatasourceName(const SfxItemSet
& _rSet
)
623 // Sets jdbc as the default selected databse on startup.
624 if (m_pRB_CreateDatabase
->IsChecked() )
625 return m_pCollection
->getTypeDisplayName( OUString( "jdbc:" ) );
627 return OGeneralPage::getDatasourceName( _rSet
);
630 bool OGeneralPageWizard::approveDatasourceType( ::dbaccess::DATASOURCE_TYPE eType
, OUString
& _inout_rDisplayName
)
634 case ::dbaccess::DST_MYSQL_JDBC
:
635 _inout_rDisplayName
= "MySQL";
637 case ::dbaccess::DST_MYSQL_ODBC
:
638 case ::dbaccess::DST_MYSQL_NATIVE
:
639 // don't display those, the decision whether the user connects via JDBC/ODBC/C-OOo is made on another
641 _inout_rDisplayName
.clear();
647 return OGeneralPage::approveDatasourceType( eType
, _inout_rDisplayName
);
650 bool OGeneralPageWizard::FillItemSet(SfxItemSet
* _rCoreAttrs
)
652 bool bChangedSomething
= false;
654 bool bCommitTypeSelection
= true;
656 if ( m_pRB_CreateDatabase
->IsChecked() )
658 _rCoreAttrs
->Put( SfxStringItem( DSID_CONNECTURL
, OUString( "sdbc:dbase:" ) ) );
659 bChangedSomething
= true;
660 bCommitTypeSelection
= false;
662 else if ( m_pRB_OpenExistingDatabase
->IsChecked() )
664 if ( m_pRB_OpenExistingDatabase
->IsValueChangedFromSaved() )
665 bChangedSomething
= true;
668 bCommitTypeSelection
= false;
671 if ( bCommitTypeSelection
)
673 sal_uInt16 nEntry
= m_pDatasourceType
->GetSelectEntryPos();
674 OUString sURLPrefix
= m_aURLPrefixes
[nEntry
];
676 if ( m_pDatasourceType
->IsValueChangedFromSaved()
677 || ( GetDatabaseCreationMode() != m_eOriginalCreationMode
)
680 _rCoreAttrs
->Put( SfxStringItem( DSID_CONNECTURL
,sURLPrefix
) );
681 bChangedSomething
= true;
684 implSetCurrentType( sURLPrefix
);
686 return bChangedSomething
;
689 OGeneralPageWizard::DocumentDescriptor
OGeneralPageWizard::GetSelectedDocument() const
691 DocumentDescriptor aDocument
;
692 if ( !m_aBrowsedDocument
.sURL
.isEmpty() )
693 aDocument
= m_aBrowsedDocument
;
696 aDocument
.sURL
= m_pLB_DocumentList
->GetSelectedDocumentURL();
697 aDocument
.sFilter
= m_pLB_DocumentList
->GetSelectedDocumentFilter();
702 IMPL_LINK( OGeneralPageWizard
, OnCreateDatabaseModeSelected
, RadioButton
*, /*_pBox*/ )
704 if ( m_aCreationModeHandler
.IsSet() )
705 m_aCreationModeHandler
.Call( this );
707 OnEmbeddedDBTypeSelected( m_pEmbeddedDBType
);
711 IMPL_LINK( OGeneralPageWizard
, OnSetupModeSelected
, RadioButton
*, /*_pBox*/ )
713 if ( m_aCreationModeHandler
.IsSet() )
714 m_aCreationModeHandler
.Call( this );
715 OnDatasourceTypeSelected(m_pDatasourceType
);
719 IMPL_LINK( OGeneralPageWizard
, OnDocumentSelected
, ListBox
*, /*_pBox*/ )
721 m_aDocumentSelectionHandler
.Call( this );
725 IMPL_LINK( OGeneralPageWizard
, OnOpenDocument
, PushButton
*, /*_pBox*/ )
727 ::sfx2::FileDialogHelper
aFileDlg(
728 ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION
,
729 0, OUString("sdatabase") );
730 const SfxFilter
* pFilter
= getStandardDatabaseFilter();
733 aFileDlg
.SetCurrentFilter(pFilter
->GetUIName());
735 if ( aFileDlg
.Execute() == ERRCODE_NONE
)
737 OUString sPath
= aFileDlg
.GetPath();
738 if ( aFileDlg
.GetCurrentFilter() != pFilter
->GetUIName() || !pFilter
->GetWildcard().Matches(sPath
) )
740 OUString
sMessage(ModuleRes(STR_ERR_USE_CONNECT_TO
));
741 ScopedVclPtrInstance
< InfoBox
> aError(this, sMessage
);
743 m_pRB_ConnectDatabase
->Check();
744 OnSetupModeSelected( m_pRB_ConnectDatabase
);
747 m_aBrowsedDocument
.sURL
= sPath
;
748 m_aBrowsedDocument
.sFilter
.clear();
749 m_aChooseDocumentHandler
.Call( this );
758 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */