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