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