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