Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "dsnItem.hxx"
21 : #include "generalpage.hxx"
22 : #include <connectivity/dbexception.hxx>
23 : #include "dbu_dlg.hrc"
24 : #include "dbadmin.hrc"
25 : #include "dsitems.hxx"
26 : #include "dbustrings.hrc"
27 : #include "dbadmin.hxx"
28 : #include <sfx2/filedlghelper.hxx>
29 : #include <sfx2/docfilt.hxx>
30 : #include <vcl/stdtext.hxx>
31 : #include "localresaccess.hxx"
32 : #include <vcl/msgbox.hxx>
33 : #include <svl/stritem.hxx>
34 : #include <vcl/waitobj.hxx>
35 : #include <com/sun/star/sdbc/XDriverAccess.hpp>
36 : #include <com/sun/star/beans/PropertyValue.hpp>
37 : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
38 : #include <com/sun/star/uno/Sequence.hxx>
39 : #include <com/sun/star/container/XNameAccess.hpp>
40 : #include "DriverSettings.hxx"
41 : #include "UITools.hxx"
42 : #include <comphelper/processfactory.hxx>
43 : #include <unotools/confignode.hxx>
44 : #include <osl/diagnose.h>
45 :
46 : namespace dbaui
47 : {
48 : using namespace ::com::sun::star;
49 : using namespace ::com::sun::star::uno;
50 : using namespace ::com::sun::star::sdbc;
51 : using namespace ::com::sun::star::beans;
52 : using namespace ::com::sun::star::container;
53 :
54 : // OGeneralPage
55 0 : OGeneralPage::OGeneralPage( Window* pParent, const OUString& _rUIXMLDescription, const SfxItemSet& _rItems )
56 : :OGenericAdministrationPage( pParent, "PageGeneral", _rUIXMLDescription, _rItems )
57 : ,m_eNotSupportedKnownType ( ::dbaccess::DST_UNKNOWN )
58 : ,m_pSpecialMessage ( NULL )
59 : ,m_eLastMessage ( smNone )
60 : ,m_bDisplayingInvalid ( sal_False )
61 : ,m_bInitTypeList ( true )
62 : ,m_pDatasourceType ( NULL )
63 0 : ,m_pCollection ( NULL )
64 : {
65 0 : get( m_pDatasourceType, "datasourceType" );
66 0 : get( m_pSpecialMessage, "specialMessage" );
67 :
68 : // extract the datasource type collection from the item set
69 0 : DbuTypeCollectionItem* pCollectionItem = PTR_CAST(DbuTypeCollectionItem, _rItems.GetItem(DSID_TYPECOLLECTION));
70 0 : if (pCollectionItem)
71 0 : m_pCollection = pCollectionItem->getCollection();
72 : SAL_WARN_IF(!m_pCollection, "dbaccess", "OGeneralPage::OGeneralPage : really need a DSN type collection !");
73 :
74 : // do some knittings
75 0 : m_pDatasourceType->SetSelectHdl(LINK(this, OGeneralPage, OnDatasourceTypeSelected));
76 0 : }
77 :
78 0 : OGeneralPage::~OGeneralPage()
79 : {
80 0 : }
81 :
82 : namespace
83 : {
84 0 : struct DisplayedType
85 : {
86 : OUString eType;
87 : OUString sDisplayName;
88 :
89 0 : DisplayedType( const OUString& _eType, const OUString& _rDisplayName ) : eType( _eType ), sDisplayName( _rDisplayName ) { }
90 : };
91 : typedef ::std::vector< DisplayedType > DisplayedTypes;
92 :
93 : struct DisplayedTypeLess : ::std::binary_function< DisplayedType, DisplayedType, bool >
94 : {
95 0 : bool operator() ( const DisplayedType& _rLHS, const DisplayedType& _rRHS )
96 : {
97 0 : return _rLHS.eType < _rRHS.eType;
98 : }
99 : };
100 : }
101 :
102 0 : void OGeneralPage::initializeTypeList()
103 : {
104 0 : if ( m_bInitTypeList )
105 : {
106 0 : m_bInitTypeList = false;
107 0 : m_pDatasourceType->Clear();
108 :
109 0 : if ( m_pCollection )
110 : {
111 0 : DisplayedTypes aDisplayedTypes;
112 :
113 0 : ::dbaccess::ODsnTypeCollection::TypeIterator aEnd = m_pCollection->end();
114 0 : for ( ::dbaccess::ODsnTypeCollection::TypeIterator aTypeLoop = m_pCollection->begin();
115 : aTypeLoop != aEnd;
116 : ++aTypeLoop
117 : )
118 : {
119 0 : const OUString sURLPrefix = aTypeLoop.getURLPrefix();
120 0 : if ( !sURLPrefix.isEmpty() )
121 : {
122 0 : OUString sDisplayName = aTypeLoop.getDisplayName();
123 0 : if ( m_pDatasourceType->GetEntryPos( sDisplayName ) == LISTBOX_ENTRY_NOTFOUND
124 0 : && approveDatasourceType( sURLPrefix, sDisplayName ) )
125 : {
126 0 : aDisplayedTypes.push_back( DisplayedTypes::value_type( sURLPrefix, sDisplayName ) );
127 0 : }
128 : }
129 0 : }
130 0 : ::std::sort( aDisplayedTypes.begin(), aDisplayedTypes.end(), DisplayedTypeLess() );
131 0 : DisplayedTypes::const_iterator aDisplayEnd = aDisplayedTypes.end();
132 0 : for ( DisplayedTypes::const_iterator loop = aDisplayedTypes.begin();
133 : loop != aDisplayEnd;
134 : ++loop
135 : )
136 0 : insertDatasourceTypeEntryData( loop->eType, loop->sDisplayName );
137 : }
138 : }
139 0 : }
140 :
141 0 : void OGeneralPageWizard::initializeEmbeddedDBList()
142 : {
143 0 : if ( m_bInitEmbeddedDBList )
144 : {
145 0 : m_bInitEmbeddedDBList = false;
146 0 : m_pEmbeddedDBType->Clear();
147 :
148 0 : if ( m_pCollection )
149 : {
150 0 : DisplayedTypes aDisplayedTypes;
151 :
152 0 : ::dbaccess::ODsnTypeCollection::TypeIterator aEnd = m_pCollection->end();
153 0 : for ( ::dbaccess::ODsnTypeCollection::TypeIterator aTypeLoop = m_pCollection->begin();
154 : aTypeLoop != aEnd;
155 : ++aTypeLoop
156 : )
157 : {
158 0 : const OUString sURLPrefix = aTypeLoop.getURLPrefix();
159 0 : if ( !sURLPrefix.isEmpty() )
160 : {
161 0 : OUString sDisplayName = aTypeLoop.getDisplayName();
162 0 : if ( m_pEmbeddedDBType->GetEntryPos( sDisplayName ) == LISTBOX_ENTRY_NOTFOUND
163 0 : && m_pCollection->isEmbeddedDatabase( sURLPrefix ) )
164 : {
165 0 : aDisplayedTypes.push_back( DisplayedTypes::value_type( sURLPrefix, sDisplayName ) );
166 0 : }
167 : }
168 0 : }
169 0 : ::std::sort( aDisplayedTypes.begin(), aDisplayedTypes.end(), DisplayedTypeLess() );
170 0 : DisplayedTypes::const_iterator aDisplayEnd = aDisplayedTypes.end();
171 0 : for ( DisplayedTypes::const_iterator loop = aDisplayedTypes.begin();
172 : loop != aDisplayEnd;
173 : ++loop
174 : )
175 0 : insertEmbeddedDBTypeEntryData( loop->eType, loop->sDisplayName );
176 : }
177 : }
178 0 : }
179 :
180 0 : void OGeneralPage::setParentTitle(const OUString&)
181 : {
182 0 : }
183 :
184 0 : void OGeneralPage::switchMessage(const OUString& _sURLPrefix)
185 : {
186 0 : SPECIAL_MESSAGE eMessage = smNone;
187 0 : if ( _sURLPrefix.isEmpty()/*_eType == m_eNotSupportedKnownType*/ )
188 : {
189 0 : eMessage = smUnsupportedType;
190 : }
191 :
192 0 : if ( eMessage != m_eLastMessage )
193 : {
194 0 : sal_uInt16 nResId = 0;
195 0 : if ( smUnsupportedType == eMessage )
196 0 : nResId = STR_UNSUPPORTED_DATASOURCE_TYPE;
197 0 : OUString sMessage;
198 0 : if ( nResId )
199 0 : sMessage = ModuleRes( nResId );
200 :
201 0 : m_pSpecialMessage->SetText( sMessage );
202 0 : m_eLastMessage = eMessage;
203 : }
204 0 : }
205 :
206 0 : void OGeneralPage::onTypeSelected(const OUString& _sURLPrefix)
207 : {
208 : // the new URL text as indicated by the selection history
209 0 : implSetCurrentType( _sURLPrefix );
210 :
211 0 : switchMessage(_sURLPrefix);
212 :
213 0 : if ( m_aTypeSelectHandler.IsSet() )
214 0 : m_aTypeSelectHandler.Call(this);
215 0 : }
216 :
217 0 : void OGeneralPage::implInitControls( const SfxItemSet& _rSet, sal_Bool _bSaveValue )
218 : {
219 0 : initializeTypeList();
220 :
221 0 : m_pDatasourceType->SelectEntry( getDatasourceName( _rSet ) );
222 :
223 : // notify our listener that our type selection has changed (if so)
224 : // FIXME: how to detect that it did not changed? (fdo#62937)
225 0 : setParentTitle( m_eCurrentSelection );
226 0 : onTypeSelected( m_eCurrentSelection );
227 :
228 : // a special message for the current page state
229 0 : switchMessage( m_eCurrentSelection );
230 :
231 0 : OGenericAdministrationPage::implInitControls( _rSet, _bSaveValue );
232 0 : }
233 :
234 0 : OUString OGeneralPageWizard::getEmbeddedDBName( const SfxItemSet& _rSet )
235 : {
236 : // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
237 : sal_Bool bValid, bReadonly;
238 0 : getFlags( _rSet, bValid, bReadonly );
239 :
240 : // if the selection is invalid, disable everything
241 0 : OUString sName,sConnectURL;
242 0 : if ( bValid )
243 : {
244 : // collect some items and some values
245 0 : SFX_ITEMSET_GET( _rSet, pNameItem, SfxStringItem, DSID_NAME, true );
246 0 : SFX_ITEMSET_GET( _rSet, pUrlItem, SfxStringItem, DSID_CONNECTURL, true );
247 : assert( pUrlItem );
248 : assert( pNameItem );
249 0 : sName = pNameItem->GetValue();
250 0 : sConnectURL = pUrlItem->GetValue();
251 : }
252 :
253 0 : m_eNotSupportedKnownType = ::dbaccess::DST_UNKNOWN;
254 0 : implSetCurrentType( OUString() );
255 :
256 : // compare the DSN prefix with the registered ones
257 0 : OUString sDisplayName;
258 :
259 0 : if (m_pCollection && bValid)
260 : {
261 0 : implSetCurrentType( m_pCollection->getEmbeddedDatabase() );
262 0 : sDisplayName = m_pCollection->getTypeDisplayName( m_eCurrentSelection );
263 : }
264 :
265 : // select the correct datasource type
266 0 : if ( m_pCollection->isEmbeddedDatabase( m_eCurrentSelection )
267 0 : && ( LISTBOX_ENTRY_NOTFOUND == m_pEmbeddedDBType->GetEntryPos( sDisplayName ) )
268 : )
269 : { // this indicates it's really a type which is known in general, but not supported on the current platform
270 : // show a message saying so
271 : // eSpecialMessage = smUnsupportedType;
272 0 : insertEmbeddedDBTypeEntryData( m_eCurrentSelection, sDisplayName );
273 : // remember this type so we can show the special message again if the user selects this
274 : // type again (without changing the data source)
275 0 : m_eNotSupportedKnownType = m_pCollection->determineType( m_eCurrentSelection ); // TODO:
276 : }
277 :
278 0 : return sDisplayName;
279 : }
280 :
281 0 : OUString OGeneralPage::getDatasourceName( const SfxItemSet& _rSet )
282 : {
283 : // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
284 : sal_Bool bValid, bReadonly;
285 0 : getFlags( _rSet, bValid, bReadonly );
286 :
287 : // if the selection is invalid, disable everything
288 0 : OUString sName,sConnectURL;
289 0 : m_bDisplayingInvalid = !bValid;
290 0 : if ( bValid )
291 : {
292 : // collect some items and some values
293 0 : SFX_ITEMSET_GET( _rSet, pNameItem, SfxStringItem, DSID_NAME, true );
294 0 : SFX_ITEMSET_GET( _rSet, pUrlItem, SfxStringItem, DSID_CONNECTURL, true );
295 : assert( pUrlItem );
296 : assert( pNameItem );
297 0 : sName = pNameItem->GetValue();
298 0 : sConnectURL = pUrlItem->GetValue();
299 : }
300 :
301 0 : m_eNotSupportedKnownType = ::dbaccess::DST_UNKNOWN;
302 0 : implSetCurrentType( OUString() );
303 :
304 : // compare the DSN prefix with the registered ones
305 0 : OUString sDisplayName;
306 :
307 0 : if (m_pCollection && bValid)
308 : {
309 0 : implSetCurrentType( m_pCollection->getPrefix( sConnectURL ) );
310 0 : sDisplayName = m_pCollection->getTypeDisplayName( m_eCurrentSelection );
311 : }
312 :
313 : // select the correct datasource type
314 0 : if ( approveDatasourceType( m_eCurrentSelection, sDisplayName )
315 0 : && ( LISTBOX_ENTRY_NOTFOUND == m_pDatasourceType->GetEntryPos( sDisplayName ) )
316 : )
317 : { // this indicates it's really a type which is known in general, but not supported on the current platform
318 : // show a message saying so
319 : // eSpecialMessage = smUnsupportedType;
320 0 : insertDatasourceTypeEntryData( m_eCurrentSelection, sDisplayName );
321 : // remember this type so we can show the special message again if the user selects this
322 : // type again (without changing the data source)
323 0 : m_eNotSupportedKnownType = m_pCollection->determineType( m_eCurrentSelection );
324 : }
325 :
326 0 : return sDisplayName;
327 : }
328 :
329 : // For the databaseWizard we only have one entry for the MySQL Database,
330 : // because we have a separate tabpage to retrieve the respective datasource type
331 : // ( ::dbaccess::DST_MYSQL_ODBC || ::dbaccess::DST_MYSQL_JDBC). Therefore we use ::dbaccess::DST_MYSQL_JDBC as a temporary
332 : // representative for all MySQl databases)
333 : // Also, embedded databases (embedded HSQL, at the moment), are not to appear in the list of
334 : // databases to connect to.
335 0 : bool OGeneralPage::approveDatasourceType( const OUString& _sURLPrefix, OUString& _inout_rDisplayName )
336 : {
337 0 : return approveDatasourceType( m_pCollection->determineType(_sURLPrefix), _inout_rDisplayName );
338 : }
339 :
340 0 : bool OGeneralPage::approveDatasourceType( ::dbaccess::DATASOURCE_TYPE eType, OUString& _inout_rDisplayName )
341 : {
342 0 : if ( eType == ::dbaccess::DST_MYSQL_NATIVE_DIRECT )
343 : {
344 : // do not display the Connector/OOo driver itself, it is always wrapped via the MySQL-Driver, if
345 : // this driver is installed
346 0 : if ( m_pCollection->hasDriver( "sdbc:mysql:mysqlc:" ) )
347 0 : _inout_rDisplayName = "";
348 : }
349 :
350 0 : if ( eType == ::dbaccess::DST_EMBEDDED_HSQLDB
351 0 : || eType == ::dbaccess::DST_EMBEDDED_FIREBIRD )
352 0 : _inout_rDisplayName = "";
353 :
354 0 : return _inout_rDisplayName.getLength() > 0;
355 : }
356 :
357 0 : void OGeneralPage::insertDatasourceTypeEntryData(const OUString& _sType, const OUString& sDisplayName)
358 : {
359 : // insert a (temporary) entry
360 0 : sal_uInt16 nPos = m_pDatasourceType->InsertEntry(sDisplayName);
361 0 : if ( nPos >= m_aURLPrefixes.size() )
362 0 : m_aURLPrefixes.resize(nPos+1);
363 0 : m_aURLPrefixes[nPos] = _sType;
364 0 : }
365 :
366 0 : void OGeneralPageWizard::insertEmbeddedDBTypeEntryData(const OUString& _sType, const OUString& sDisplayName)
367 : {
368 : // insert a (temporary) entry
369 0 : sal_uInt16 nPos = m_pEmbeddedDBType->InsertEntry(sDisplayName);
370 0 : if ( nPos >= m_aEmbeddedURLPrefixes.size() )
371 0 : m_aEmbeddedURLPrefixes.resize(nPos+1);
372 0 : m_aEmbeddedURLPrefixes[nPos] = _sType;
373 0 : }
374 :
375 0 : void OGeneralPage::fillWindows(::std::vector< ISaveValueWrapper* >& _rControlList)
376 : {
377 0 : _rControlList.push_back( new ODisableWrapper<FixedText>( m_pSpecialMessage ) );
378 0 : }
379 :
380 0 : void OGeneralPage::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList)
381 : {
382 0 : _rControlList.push_back( new OSaveValueWrapper<ListBox>( m_pDatasourceType ) );
383 0 : }
384 :
385 0 : void OGeneralPage::implSetCurrentType( const OUString& _eType )
386 : {
387 0 : if ( _eType == m_eCurrentSelection )
388 0 : return;
389 :
390 0 : m_eCurrentSelection = _eType;
391 : }
392 :
393 0 : void OGeneralPage::Reset(const SfxItemSet& _rCoreAttrs)
394 : {
395 : // reset all locale data
396 0 : implSetCurrentType( OUString() );
397 : // this ensures that our type selection link will be called, even if the new is is the same as the
398 : // current one
399 0 : OGenericAdministrationPage::Reset(_rCoreAttrs);
400 0 : }
401 :
402 0 : IMPL_LINK( OGeneralPageWizard, OnEmbeddedDBTypeSelected, ListBox*, _pBox )
403 : {
404 : // get the type from the entry data
405 0 : sal_uInt16 nSelected = _pBox->GetSelectEntryPos();
406 0 : if (nSelected >= m_aEmbeddedURLPrefixes.size() )
407 : {
408 : SAL_WARN("dbaccess.ui.OGeneralPage", "Got out-of-range value '" << nSelected << "' from the DatasourceType selection ListBox's GetSelectEntryPos(): no corresponding URL prefix");
409 0 : return 0L;
410 : }
411 0 : const OUString sURLPrefix = m_aEmbeddedURLPrefixes[ nSelected ];
412 :
413 0 : setParentTitle( sURLPrefix );
414 : // let the impl method do all the stuff
415 0 : onTypeSelected( sURLPrefix );
416 : // tell the listener we were modified
417 0 : callModifiedHdl();
418 : // outta here
419 0 : return 0L;
420 : }
421 :
422 0 : IMPL_LINK( OGeneralPage, OnDatasourceTypeSelected, ListBox*, _pBox )
423 : {
424 : // get the type from the entry data
425 0 : sal_uInt16 nSelected = _pBox->GetSelectEntryPos();
426 0 : if (nSelected >= m_aURLPrefixes.size() )
427 : {
428 : SAL_WARN("dbaccess.ui.OGeneralPage", "Got out-of-range value '" << nSelected << "' from the DatasourceType selection ListBox's GetSelectEntryPos(): no corresponding URL prefix");
429 0 : return 0L;
430 : }
431 0 : const OUString sURLPrefix = m_aURLPrefixes[ nSelected ];
432 :
433 0 : setParentTitle( sURLPrefix );
434 : // let the impl method do all the stuff
435 0 : onTypeSelected( sURLPrefix );
436 : // tell the listener we were modified
437 0 : callModifiedHdl();
438 : // outta here
439 0 : return 0L;
440 : }
441 :
442 : // OGeneralPageDialog
443 0 : OGeneralPageDialog::OGeneralPageDialog( Window* pParent, const SfxItemSet& _rItems )
444 0 : :OGeneralPage( pParent, "dbaccess/ui/generalpagedialog.ui", _rItems )
445 : {
446 0 : }
447 :
448 0 : void OGeneralPageDialog::setParentTitle( const OUString& _sURLPrefix )
449 : {
450 0 : const OUString sName = m_pCollection->getTypeDisplayName( _sURLPrefix );
451 0 : if ( m_pAdminDialog )
452 : {
453 0 : OUString sMessage = OUString( ModuleRes( STR_PARENTTITLE_GENERAL ) );
454 0 : m_pAdminDialog->setTitle( sMessage.replaceAll( "#", sName ) );
455 0 : }
456 0 : }
457 :
458 0 : void OGeneralPageDialog::implInitControls( const SfxItemSet& _rSet, sal_Bool _bSaveValue )
459 : {
460 0 : OGeneralPage::implInitControls( _rSet, _bSaveValue );
461 :
462 : // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
463 : sal_Bool bValid, bReadonly;
464 0 : getFlags(_rSet, bValid, bReadonly );
465 :
466 0 : m_pDatasourceType->Enable( bValid );
467 0 : }
468 :
469 0 : bool OGeneralPageDialog::FillItemSet( SfxItemSet& _rCoreAttrs )
470 : {
471 0 : sal_Bool bChangedSomething = sal_False;
472 :
473 0 : sal_uInt16 nEntry = m_pDatasourceType->GetSelectEntryPos();
474 0 : OUString sURLPrefix = m_aURLPrefixes[ nEntry ];
475 :
476 0 : if ( m_pDatasourceType->GetSavedValue() != nEntry )
477 : {
478 0 : _rCoreAttrs.Put( SfxStringItem( DSID_CONNECTURL, sURLPrefix ) );
479 0 : bChangedSomething = sal_True;
480 : }
481 :
482 0 : return bChangedSomething;
483 : }
484 :
485 : // OGeneralPageWizard
486 0 : OGeneralPageWizard::OGeneralPageWizard( Window* pParent, const SfxItemSet& _rItems )
487 : :OGeneralPage( pParent, "dbaccess/ui/generalpagewizard.ui", _rItems )
488 : ,m_pFT_HeaderText ( NULL )
489 : ,m_pFT_HelpText ( NULL )
490 : ,m_pRB_CreateDatabase ( NULL )
491 : ,m_pRB_OpenExistingDatabase ( NULL )
492 : ,m_pRB_ConnectDatabase ( NULL )
493 : ,m_pFT_EmbeddedDBLabel ( NULL )
494 : ,m_pEmbeddedDBType ( NULL )
495 : ,m_pFT_DocListLabel ( NULL )
496 : ,m_pLB_DocumentList ( NULL )
497 : ,m_pPB_OpenDatabase ( NULL )
498 : ,m_eOriginalCreationMode ( eCreateNew )
499 0 : ,m_bInitEmbeddedDBList ( true )
500 : {
501 0 : get( m_pFT_HeaderText, "headerText" );
502 0 : get( m_pFT_HelpText, "helpText" );
503 0 : get( m_pRB_CreateDatabase, "createDatabase" );
504 0 : get( m_pRB_OpenExistingDatabase, "openExistingDatabase" );
505 0 : get( m_pRB_ConnectDatabase, "connectDatabase" );
506 0 : get( m_pFT_EmbeddedDBLabel, "embeddeddbLabel" );
507 0 : get( m_pEmbeddedDBType, "embeddeddbList" );
508 0 : get( m_pFT_DocListLabel, "docListLabel" );
509 0 : get( m_pLB_DocumentList, "documentList" );
510 0 : get( m_pPB_OpenDatabase, "openDatabase" );
511 :
512 : // If no driver for embedded DBs is installed, and no dBase driver, then hide the "Create new database" option
513 0 : sal_Int32 nCreateNewDBIndex = m_pCollection->getIndexOf( m_pCollection->getEmbeddedDatabase() );
514 0 : if ( nCreateNewDBIndex == -1 )
515 0 : nCreateNewDBIndex = m_pCollection->getIndexOf( OUString( "sdbc:dbase:" ) );
516 0 : bool bHideCreateNew = ( nCreateNewDBIndex == -1 );
517 :
518 : // also, if our application policies tell us to hide the option, do it
519 : ::utl::OConfigurationTreeRoot aConfig( ::utl::OConfigurationTreeRoot::createWithComponentContext(
520 : ::comphelper::getProcessComponentContext(),
521 : OUString( "/org.openoffice.Office.DataAccess/Policies/Features/Base" )
522 0 : ) );
523 0 : sal_Bool bAllowCreateLocalDatabase( sal_True );
524 0 : OSL_VERIFY( aConfig.getNodeValue( "CreateLocalDatabase" ) >>= bAllowCreateLocalDatabase );
525 0 : if ( !bAllowCreateLocalDatabase )
526 0 : bHideCreateNew = true;
527 :
528 0 : if ( bHideCreateNew )
529 : {
530 0 : m_pRB_CreateDatabase->Hide();
531 0 : m_pRB_ConnectDatabase->Check();
532 : }
533 : else
534 0 : m_pRB_CreateDatabase->Check();
535 :
536 : // do some knittings
537 0 : m_pEmbeddedDBType->SetSelectHdl(LINK(this, OGeneralPageWizard, OnEmbeddedDBTypeSelected));
538 0 : m_pRB_CreateDatabase->SetClickHdl( LINK( this, OGeneralPageWizard, OnCreateDatabaseModeSelected ) );
539 0 : m_pRB_ConnectDatabase->SetClickHdl( LINK( this, OGeneralPageWizard, OnSetupModeSelected ) );
540 0 : m_pRB_OpenExistingDatabase->SetClickHdl( LINK( this, OGeneralPageWizard, OnSetupModeSelected ) );
541 0 : m_pLB_DocumentList->SetSelectHdl( LINK( this, OGeneralPageWizard, OnDocumentSelected ) );
542 0 : m_pPB_OpenDatabase->SetClickHdl( LINK( this, OGeneralPageWizard, OnOpenDocument ) );
543 0 : }
544 :
545 0 : OGeneralPageWizard::CreationMode OGeneralPageWizard::GetDatabaseCreationMode() const
546 : {
547 0 : if ( m_pRB_CreateDatabase->IsChecked() )
548 0 : return eCreateNew;
549 0 : if ( m_pRB_ConnectDatabase->IsChecked() )
550 0 : return eConnectExternal;
551 0 : return eOpenExisting;
552 : }
553 :
554 0 : void OGeneralPageWizard::GetFocus()
555 : {
556 0 : OGeneralPage::GetFocus();
557 0 : if ( m_pLB_DocumentList && m_pLB_DocumentList->IsEnabled() )
558 0 : m_pLB_DocumentList->GrabFocus();
559 0 : else if ( m_pDatasourceType && m_pDatasourceType->IsEnabled() )
560 0 : m_pDatasourceType->GrabFocus();
561 0 : }
562 :
563 0 : void OGeneralPageWizard::implInitControls( const SfxItemSet& _rSet, sal_Bool _bSaveValue )
564 : {
565 0 : OGeneralPage::implInitControls( _rSet, _bSaveValue );
566 :
567 0 : initializeEmbeddedDBList();
568 0 : m_pEmbeddedDBType->SelectEntry( getEmbeddedDBName( _rSet ) );
569 :
570 : // first check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
571 : sal_Bool bValid, bReadonly;
572 0 : getFlags( _rSet, bValid, bReadonly );
573 :
574 0 : SetText( OUString() );
575 :
576 0 : LayoutHelper::positionBelow( *m_pRB_ConnectDatabase, *m_pDatasourceType, RelatedControls, INDENT_BELOW_RADIO );
577 :
578 0 : if ( !bValid || bReadonly )
579 : {
580 0 : m_pFT_EmbeddedDBLabel->Enable( false );
581 0 : m_pDatasourceType->Enable( false );
582 0 : m_pPB_OpenDatabase->Enable( false );
583 0 : m_pFT_DocListLabel->Enable( false );
584 0 : m_pLB_DocumentList->Enable( false );
585 : }
586 : else
587 : {
588 0 : m_aControlDependencies.enableOnRadioCheck( *m_pRB_CreateDatabase, *m_pEmbeddedDBType, *m_pFT_EmbeddedDBLabel );
589 0 : m_aControlDependencies.enableOnRadioCheck( *m_pRB_ConnectDatabase, *m_pDatasourceType );
590 0 : m_aControlDependencies.enableOnRadioCheck( *m_pRB_OpenExistingDatabase, *m_pPB_OpenDatabase, *m_pFT_DocListLabel, *m_pLB_DocumentList );
591 : }
592 :
593 0 : m_pLB_DocumentList->SetDropDownLineCount( 20 );
594 0 : if ( m_pLB_DocumentList->GetEntryCount() )
595 0 : m_pLB_DocumentList->SelectEntryPos( 0 );
596 :
597 0 : m_eOriginalCreationMode = GetDatabaseCreationMode();
598 0 : }
599 :
600 0 : OUString OGeneralPageWizard::getDatasourceName(const SfxItemSet& _rSet)
601 : {
602 : // Sets jdbc as the default selected databse on startup.
603 0 : if (m_pRB_CreateDatabase->IsChecked() )
604 0 : return m_pCollection->getTypeDisplayName( OUString( "jdbc:" ) );
605 :
606 0 : return OGeneralPage::getDatasourceName( _rSet );
607 : }
608 :
609 0 : bool OGeneralPageWizard::approveDatasourceType( ::dbaccess::DATASOURCE_TYPE eType, OUString& _inout_rDisplayName )
610 : {
611 0 : switch ( eType )
612 : {
613 : case ::dbaccess::DST_MYSQL_JDBC:
614 0 : _inout_rDisplayName = "MySQL";
615 0 : break;
616 : case ::dbaccess::DST_MYSQL_ODBC:
617 : case ::dbaccess::DST_MYSQL_NATIVE:
618 : // don't display those, the decision whether the user connects via JDBC/ODBC/C-OOo is made on another
619 : // page
620 0 : _inout_rDisplayName = "";
621 0 : break;
622 : default:
623 0 : break;
624 : }
625 :
626 0 : return OGeneralPage::approveDatasourceType( eType, _inout_rDisplayName );
627 : }
628 :
629 0 : bool OGeneralPageWizard::FillItemSet(SfxItemSet& _rCoreAttrs)
630 : {
631 0 : sal_Bool bChangedSomething = sal_False;
632 :
633 0 : bool bCommitTypeSelection = true;
634 :
635 0 : if ( m_pRB_CreateDatabase->IsChecked() )
636 : {
637 0 : _rCoreAttrs.Put( SfxStringItem( DSID_CONNECTURL, OUString( "sdbc:dbase:" ) ) );
638 0 : bChangedSomething = sal_True;
639 0 : bCommitTypeSelection = false;
640 : }
641 0 : else if ( m_pRB_OpenExistingDatabase->IsChecked() )
642 : {
643 0 : if ( m_pRB_OpenExistingDatabase->GetSavedValue() != m_pRB_OpenExistingDatabase->IsChecked() )
644 0 : bChangedSomething = sal_True;
645 :
646 : // TODO
647 0 : bCommitTypeSelection = false;
648 : }
649 :
650 0 : if ( bCommitTypeSelection )
651 : {
652 0 : sal_uInt16 nEntry = m_pDatasourceType->GetSelectEntryPos();
653 0 : OUString sURLPrefix = m_aURLPrefixes[nEntry];
654 :
655 0 : if ( ( m_pDatasourceType->GetSavedValue() != nEntry )
656 0 : || ( GetDatabaseCreationMode() != m_eOriginalCreationMode )
657 : )
658 : {
659 0 : _rCoreAttrs.Put( SfxStringItem( DSID_CONNECTURL,sURLPrefix ) );
660 0 : bChangedSomething = sal_True;
661 : }
662 : else
663 0 : implSetCurrentType( sURLPrefix );
664 : }
665 0 : return bChangedSomething;
666 : }
667 :
668 0 : OGeneralPageWizard::DocumentDescriptor OGeneralPageWizard::GetSelectedDocument() const
669 : {
670 0 : DocumentDescriptor aDocument;
671 0 : if ( !m_aBrowsedDocument.sURL.isEmpty() )
672 0 : aDocument = m_aBrowsedDocument;
673 : else
674 : {
675 0 : aDocument.sURL = m_pLB_DocumentList->GetSelectedDocumentURL();
676 0 : aDocument.sFilter = m_pLB_DocumentList->GetSelectedDocumentFilter();
677 : }
678 0 : return aDocument;
679 : }
680 :
681 0 : IMPL_LINK( OGeneralPageWizard, OnCreateDatabaseModeSelected, RadioButton*, /*_pBox*/ )
682 : {
683 0 : if ( m_aCreationModeHandler.IsSet() )
684 0 : m_aCreationModeHandler.Call( this );
685 :
686 0 : OnEmbeddedDBTypeSelected( m_pEmbeddedDBType );
687 0 : return 1L;
688 : }
689 :
690 0 : IMPL_LINK( OGeneralPageWizard, OnSetupModeSelected, RadioButton*, /*_pBox*/ )
691 : {
692 0 : if ( m_aCreationModeHandler.IsSet() )
693 0 : m_aCreationModeHandler.Call( this );
694 0 : OnDatasourceTypeSelected(m_pDatasourceType);
695 0 : return 1L;
696 : }
697 :
698 0 : IMPL_LINK( OGeneralPageWizard, OnDocumentSelected, ListBox*, /*_pBox*/ )
699 : {
700 0 : m_aDocumentSelectionHandler.Call( this );
701 0 : return 0L;
702 : }
703 :
704 0 : IMPL_LINK( OGeneralPageWizard, OnOpenDocument, PushButton*, /*_pBox*/ )
705 : {
706 : ::sfx2::FileDialogHelper aFileDlg(
707 : ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION,
708 0 : 0, OUString("sdatabase") );
709 0 : const SfxFilter* pFilter = getStandardDatabaseFilter();
710 0 : if ( pFilter )
711 : {
712 0 : aFileDlg.SetCurrentFilter(pFilter->GetUIName());
713 : }
714 0 : if ( aFileDlg.Execute() == ERRCODE_NONE )
715 : {
716 0 : OUString sPath = aFileDlg.GetPath();
717 0 : if ( aFileDlg.GetCurrentFilter() != pFilter->GetUIName() || !pFilter->GetWildcard().Matches(sPath) )
718 : {
719 0 : OUString sMessage(ModuleRes(STR_ERR_USE_CONNECT_TO));
720 0 : InfoBox aError(this, sMessage);
721 0 : aError.Execute();
722 0 : m_pRB_ConnectDatabase->Check();
723 0 : OnSetupModeSelected( m_pRB_ConnectDatabase );
724 0 : return 0L;
725 : }
726 0 : m_aBrowsedDocument.sURL = sPath;
727 0 : m_aBrowsedDocument.sFilter = "";
728 0 : m_aChooseDocumentHandler.Call( this );
729 0 : return 1L;
730 : }
731 :
732 0 : return 0L;
733 : }
734 :
735 0 : } // namespace dbaui
736 :
737 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|