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