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