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