1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "ConnectionPage.hxx"
22 #include "DbAdminImpl.hxx"
23 #include "DriverSettings.hxx"
24 #include "adminpages.hxx"
25 #include "dbadmin.hrc"
26 #include "dbadmin.hxx"
27 #include "dbu_dlg.hrc"
28 #include <svl/stritem.hxx>
29 #include <svl/eitem.hxx>
30 #include <svl/intitem.hxx>
31 #include "dbustrings.hrc"
32 #include "dsitems.hxx"
33 #include "dsnItem.hxx"
34 #include "localresaccess.hxx"
35 #include "optionalboolitem.hxx"
36 #include "propertysetitem.hxx"
37 #include "stringlistitem.hxx"
39 #include <unotools/confignode.hxx>
40 #include <vcl/msgbox.hxx>
42 //.........................................................................
45 //.........................................................................
46 using namespace com::sun::star::uno
;
47 using namespace com::sun::star::sdbc
;
48 using namespace com::sun::star::lang
;
49 using namespace com::sun::star::util
;
50 using namespace com::sun::star::beans
;
51 using namespace com::sun::star::container
;
53 //=========================================================================
55 //=========================================================================
56 DBG_NAME(ODbAdminDialog
)
57 //-------------------------------------------------------------------------
58 ODbAdminDialog::ODbAdminDialog(Window
* _pParent
60 , const Reference
< XComponentContext
>& _rxContext
62 :SfxTabDialog(_pParent
, ModuleRes(DLG_DATABASE_ADMINISTRATION
), _pItems
)
63 ,m_bApplied(sal_False
)
64 ,m_bUIEnabled( sal_True
)
65 ,m_nMainPageID( PAGE_CONNECTION
)
67 DBG_CTOR(ODbAdminDialog
,NULL
);
69 m_pImpl
= ::std::auto_ptr
<ODbDataSourceAdministrationHelper
>(new ODbDataSourceAdministrationHelper(_rxContext
,this,this));
71 // add the initial tab page
72 AddTabPage( m_nMainPageID
, String( ModuleRes( STR_PAGETITLE_GENERAL
) ), OConnectionTabPage::Create
, NULL
);
74 // remove the reset button - it's meaning is much too ambiguous in this dialog
76 // no local resources needed anymore
80 //-------------------------------------------------------------------------
81 ODbAdminDialog::~ODbAdminDialog()
86 DBG_DTOR(ODbAdminDialog
,NULL
);
88 //-------------------------------------------------------------------------
89 short ODbAdminDialog::Ok()
93 return ( AR_LEAVE_MODIFIED
== implApplyChanges() ) ? RET_OK
: RET_CANCEL
;
94 // TODO : AR_ERROR is not handled correctly, we always close the dialog here
97 //-------------------------------------------------------------------------
98 void ODbAdminDialog::PageCreated(sal_uInt16 _nId
, SfxTabPage
& _rPage
)
100 // register ourself as modified listener
101 static_cast<OGenericAdministrationPage
&>(_rPage
).SetServiceFactory( getORB() );
102 static_cast<OGenericAdministrationPage
&>(_rPage
).SetAdminDialog(this,this);
105 Window
*pWin
= GetViewWindow();
109 SfxTabDialog::PageCreated(_nId
, _rPage
);
112 // -----------------------------------------------------------------------------
113 void ODbAdminDialog::addDetailPage(sal_uInt16 _nPageId
, sal_uInt16 _nTextId
, CreateTabPage _pCreateFunc
)
115 // open our own resource block, as the page titles are strings local to this block
116 LocalResourceAccess
aDummy(DLG_DATABASE_ADMINISTRATION
, RSC_TABDIALOG
);
118 AddTabPage(_nPageId
, String(ModuleRes(_nTextId
)), _pCreateFunc
, NULL
);
119 m_aCurrentDetailPages
.push(_nPageId
);
122 //-------------------------------------------------------------------------
123 void ODbAdminDialog::impl_selectDataSource(const ::com::sun::star::uno::Any
& _aDataSourceName
)
125 m_pImpl
->setDataSourceOrName(_aDataSourceName
);
126 Reference
< XPropertySet
> xDatasource
= m_pImpl
->getCurrentDataSource();
127 impl_resetPages( xDatasource
);
129 DbuTypeCollectionItem
* pCollectionItem
= PTR_CAST(DbuTypeCollectionItem
, getOutputSet()->GetItem(DSID_TYPECOLLECTION
));
130 ::dbaccess::ODsnTypeCollection
* pCollection
= pCollectionItem
->getCollection();
131 ::dbaccess::DATASOURCE_TYPE eType
= pCollection
->determineType(getDatasourceType(*getOutputSet()));
133 // and insert the new ones
136 case ::dbaccess::DST_DBASE
:
137 addDetailPage(PAGE_DBASE
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateDbase
);
140 case ::dbaccess::DST_ADO
:
141 addDetailPage(PAGE_ADO
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateAdo
);
144 case ::dbaccess::DST_FLAT
:
145 addDetailPage(PAGE_TEXT
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateText
);
148 case ::dbaccess::DST_ODBC
:
149 addDetailPage(PAGE_ODBC
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateODBC
);
152 case ::dbaccess::DST_MYSQL_ODBC
:
153 addDetailPage(PAGE_MYSQL_ODBC
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateMySQLODBC
);
156 case ::dbaccess::DST_MYSQL_JDBC
:
157 addDetailPage(PAGE_MYSQL_JDBC
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateMySQLJDBC
);
160 case ::dbaccess::DST_ORACLE_JDBC
:
161 addDetailPage(PAGE_ORACLE_JDBC
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateOracleJDBC
);
164 case ::dbaccess::DST_LDAP
:
165 addDetailPage(PAGE_LDAP
,STR_PAGETITLE_ADVANCED
,ODriversSettings::CreateLDAP
);
167 case ::dbaccess::DST_USERDEFINE1
: /// first user defined driver
168 case ::dbaccess::DST_USERDEFINE2
:
169 case ::dbaccess::DST_USERDEFINE3
:
170 case ::dbaccess::DST_USERDEFINE4
:
171 case ::dbaccess::DST_USERDEFINE5
:
172 case ::dbaccess::DST_USERDEFINE6
:
173 case ::dbaccess::DST_USERDEFINE7
:
174 case ::dbaccess::DST_USERDEFINE8
:
175 case ::dbaccess::DST_USERDEFINE9
:
176 case ::dbaccess::DST_USERDEFINE10
:
178 LocalResourceAccess
aDummy(DLG_DATABASE_ADMINISTRATION
, RSC_TABDIALOG
);
179 String
aTitle(ModuleRes(STR_PAGETITLE_ADVANCED
));
180 AddTabPage(PAGE_USERDRIVER
, aTitle
, ODriversSettings::CreateUser
, 0, sal_False
, 1);
181 m_aCurrentDetailPages
.push(PAGE_USERDRIVER
);
189 //-------------------------------------------------------------------------
190 void ODbAdminDialog::impl_resetPages(const Reference
< XPropertySet
>& _rxDatasource
)
192 // the selection is valid if and only if we have a datasource now
193 GetInputSetImpl()->Put(SfxBoolItem(DSID_INVALID_SELECTION
, !_rxDatasource
.is()));
194 // (sal_False tells the tab pages to disable and reset all their controls, which is different
195 // from "just set them to readonly")
200 SetUpdateMode(sal_False
);
202 // remove all items which relate to indirect properties from the input set
203 // (without this, the following may happen: select an arbitrary data source where some indirect properties
204 // are set. Select another data source of the same type, where the indirect props are not set (yet). Then,
205 // the indirect property values of the first ds are shown in the second ds ...)
206 const ODbDataSourceAdministrationHelper::MapInt2String
& rMap
= m_pImpl
->getIndirectProperties();
207 for ( ODbDataSourceAdministrationHelper::ConstMapInt2StringIterator aIndirect
= rMap
.begin();
208 aIndirect
!= rMap
.end();
211 GetInputSetImpl()->ClearItem( (sal_uInt16
)aIndirect
->first
);
213 // extract all relevant data from the property set of the data source
214 m_pImpl
->translateProperties(_rxDatasource
, *GetInputSetImpl());
216 // propagate this set as our new input set and reset the example set
217 SetInputSet(GetInputSetImpl());
219 pExampleSet
= new SfxItemSet(*GetInputSetImpl());
221 // special case: MySQL Native does not have the generic PAGE_CONNECTION page
223 DbuTypeCollectionItem
* pCollectionItem
= PTR_CAST(DbuTypeCollectionItem
, getOutputSet()->GetItem(DSID_TYPECOLLECTION
));
224 ::dbaccess::ODsnTypeCollection
* pCollection
= pCollectionItem
->getCollection();
225 if ( pCollection
->determineType(getDatasourceType( *pExampleSet
)) == ::dbaccess::DST_MYSQL_NATIVE
)
227 LocalResourceAccess
aDummy(DLG_DATABASE_ADMINISTRATION
, RSC_TABDIALOG
);
228 AddTabPage( PAGE_MYSQL_NATIVE
, String( ModuleRes( STR_PAGETITLE_CONNECTION
) ), ODriversSettings::CreateMySQLNATIVE
, NULL
);
229 RemoveTabPage( PAGE_CONNECTION
);
230 m_nMainPageID
= PAGE_MYSQL_NATIVE
;
233 ShowPage( m_nMainPageID
);
234 SfxTabPage
* pConnectionPage
= GetTabPage( m_nMainPageID
);
235 if ( pConnectionPage
)
236 pConnectionPage
->Reset(*GetInputSetImpl());
237 // if this is NULL, the page has not been created yet, which means we're called before the
238 // dialog was displayed (probably from inside the ctor)
240 SetUpdateMode(sal_True
);
242 // -----------------------------------------------------------------------------
243 void ODbAdminDialog::setTitle(const OUString
& _sTitle
)
247 //-------------------------------------------------------------------------
248 void ODbAdminDialog::enableConfirmSettings( bool _bEnable
)
252 //-------------------------------------------------------------------------
253 sal_Bool
ODbAdminDialog::saveDatasource()
255 return PrepareLeaveCurrentPage();
257 //-------------------------------------------------------------------------
258 ODbAdminDialog::ApplyResult
ODbAdminDialog::implApplyChanges()
260 if (!PrepareLeaveCurrentPage())
261 { // the page did not allow us to leave
265 if ( !m_pImpl
->saveChanges(*pExampleSet
) )
269 ShowPage(GetCurPageId());
270 // This does the usual ActivatePage, so the pages can save their current status.
271 // This way, next time they're asked what has changed since now and here, they really
272 // can compare with the status they have _now_ (not the one they had before this apply call).
274 m_bApplied
= sal_True
;
276 return AR_LEAVE_MODIFIED
;
278 //-------------------------------------------------------------------------
279 void ODbAdminDialog::selectDataSource(const ::com::sun::star::uno::Any
& _aDataSourceName
)
281 impl_selectDataSource(_aDataSourceName
);
284 // -----------------------------------------------------------------------------
285 const SfxItemSet
* ODbAdminDialog::getOutputSet() const
287 return GetExampleSet();
289 // -----------------------------------------------------------------------------
290 SfxItemSet
* ODbAdminDialog::getWriteOutputSet()
294 // -----------------------------------------------------------------------------
295 ::std::pair
< Reference
<XConnection
>,sal_Bool
> ODbAdminDialog::createConnection()
297 return m_pImpl
->createConnection();
299 // -----------------------------------------------------------------------------
300 Reference
< XComponentContext
> ODbAdminDialog::getORB() const
302 return m_pImpl
->getORB();
304 // -----------------------------------------------------------------------------
305 Reference
< XDriver
> ODbAdminDialog::getDriver()
307 return m_pImpl
->getDriver();
309 // -----------------------------------------------------------------------------
310 OUString
ODbAdminDialog::getDatasourceType(const SfxItemSet
& _rSet
) const
312 return m_pImpl
->getDatasourceType(_rSet
);
314 // -----------------------------------------------------------------------------
315 void ODbAdminDialog::clearPassword()
317 m_pImpl
->clearPassword();
319 //-------------------------------------------------------------------------
320 SfxItemSet
* ODbAdminDialog::createItemSet(SfxItemSet
*& _rpSet
, SfxItemPool
*& _rpPool
, SfxPoolItem
**& _rppDefaults
, ::dbaccess::ODsnTypeCollection
* _pTypeCollection
)
322 // just to be sure ....
327 const OUString
sFilterAll( "%", 1, RTL_TEXTENCODING_ASCII_US
);
328 // create and initialize the defaults
329 _rppDefaults
= new SfxPoolItem
*[DSID_LAST_ITEM_ID
- DSID_FIRST_ITEM_ID
+ 1];
330 SfxPoolItem
** pCounter
= _rppDefaults
; // want to modify this without affecting the out param _rppDefaults
331 *pCounter
++ = new SfxStringItem(DSID_NAME
, OUString());
332 *pCounter
++ = new SfxStringItem(DSID_ORIGINALNAME
, OUString());
333 *pCounter
++ = new SfxStringItem(DSID_CONNECTURL
, OUString());
334 *pCounter
++ = new OStringListItem(DSID_TABLEFILTER
, Sequence
< OUString
>(&sFilterAll
, 1));
335 *pCounter
++ = new DbuTypeCollectionItem(DSID_TYPECOLLECTION
, _pTypeCollection
);
336 *pCounter
++ = new SfxBoolItem(DSID_INVALID_SELECTION
, sal_False
);
337 *pCounter
++ = new SfxBoolItem(DSID_READONLY
, sal_False
);
338 *pCounter
++ = new SfxStringItem(DSID_USER
, OUString());
339 *pCounter
++ = new SfxStringItem(DSID_PASSWORD
, OUString());
340 *pCounter
++ = new SfxStringItem(DSID_ADDITIONALOPTIONS
, OUString());
341 *pCounter
++ = new SfxStringItem(DSID_CHARSET
, OUString());
342 *pCounter
++ = new SfxBoolItem(DSID_PASSWORDREQUIRED
, sal_False
);
343 *pCounter
++ = new SfxBoolItem(DSID_SHOWDELETEDROWS
, sal_False
);
344 *pCounter
++ = new SfxBoolItem(DSID_ALLOWLONGTABLENAMES
, sal_False
);
345 *pCounter
++ = new SfxStringItem(DSID_JDBCDRIVERCLASS
, OUString());
346 *pCounter
++ = new SfxStringItem(DSID_FIELDDELIMITER
, OUString(','));
347 *pCounter
++ = new SfxStringItem(DSID_TEXTDELIMITER
, OUString('"'));
348 *pCounter
++ = new SfxStringItem(DSID_DECIMALDELIMITER
, OUString('.'));
349 *pCounter
++ = new SfxStringItem(DSID_THOUSANDSDELIMITER
, OUString());
350 *pCounter
++ = new SfxStringItem(DSID_TEXTFILEEXTENSION
, OUString("txt"));
351 *pCounter
++ = new SfxBoolItem(DSID_TEXTFILEHEADER
, sal_True
);
352 *pCounter
++ = new SfxBoolItem(DSID_PARAMETERNAMESUBST
, sal_False
);
353 *pCounter
++ = new SfxInt32Item(DSID_CONN_PORTNUMBER
, 8100);
354 *pCounter
++ = new SfxBoolItem(DSID_SUPPRESSVERSIONCL
, sal_False
);
355 *pCounter
++ = new OPropertySetItem(DSID_DATASOURCE_UNO
);
356 *pCounter
++ = new SfxBoolItem(DSID_CONN_SHUTSERVICE
, sal_False
);
357 *pCounter
++ = new SfxInt32Item(DSID_CONN_DATAINC
, 20);
358 *pCounter
++ = new SfxInt32Item(DSID_CONN_CACHESIZE
, 20);
359 *pCounter
++ = new SfxStringItem(DSID_CONN_CTRLUSER
, OUString());
360 *pCounter
++ = new SfxStringItem(DSID_CONN_CTRLPWD
, OUString());
361 *pCounter
++ = new SfxBoolItem(DSID_USECATALOG
, sal_False
);
362 *pCounter
++ = new SfxStringItem(DSID_CONN_HOSTNAME
, OUString());
363 *pCounter
++ = new SfxStringItem(DSID_CONN_LDAP_BASEDN
, OUString());
364 *pCounter
++ = new SfxInt32Item(DSID_CONN_LDAP_PORTNUMBER
, 389);
365 *pCounter
++ = new SfxInt32Item(DSID_CONN_LDAP_ROWCOUNT
, 100);
366 *pCounter
++ = new SfxBoolItem(DSID_SQL92CHECK
, sal_False
);
367 *pCounter
++ = new SfxStringItem(DSID_AUTOINCREMENTVALUE
, OUString());
368 *pCounter
++ = new SfxStringItem(DSID_AUTORETRIEVEVALUE
, OUString());
369 *pCounter
++ = new SfxBoolItem(DSID_AUTORETRIEVEENABLED
, sal_False
);
370 *pCounter
++ = new SfxBoolItem(DSID_APPEND_TABLE_ALIAS
, sal_False
);
371 *pCounter
++ = new SfxInt32Item(DSID_MYSQL_PORTNUMBER
, 3306);
372 *pCounter
++ = new SfxBoolItem(DSID_IGNOREDRIVER_PRIV
, sal_True
);
373 *pCounter
++ = new SfxInt32Item(DSID_BOOLEANCOMPARISON
, 0);
374 *pCounter
++ = new SfxInt32Item(DSID_ORACLE_PORTNUMBER
, 1521);
375 *pCounter
++ = new SfxBoolItem(DSID_ENABLEOUTERJOIN
, sal_True
);
376 *pCounter
++ = new SfxBoolItem(DSID_CATALOG
, sal_True
);
377 *pCounter
++ = new SfxBoolItem(DSID_SCHEMA
, sal_True
);
378 *pCounter
++ = new SfxBoolItem(DSID_INDEXAPPENDIX
, sal_True
);
379 *pCounter
++ = new SfxBoolItem(DSID_CONN_LDAP_USESSL
, sal_False
);
380 *pCounter
++ = new SfxStringItem(DSID_DOCUMENT_URL
, OUString());
381 *pCounter
++ = new SfxBoolItem(DSID_DOSLINEENDS
, sal_False
);
382 *pCounter
++ = new SfxStringItem(DSID_DATABASENAME
, OUString());
383 *pCounter
++ = new SfxBoolItem(DSID_AS_BEFORE_CORRNAME
, sal_True
);
384 *pCounter
++ = new SfxBoolItem(DSID_CHECK_REQUIRED_FIELDS
, sal_True
);
385 *pCounter
++ = new SfxBoolItem(DSID_IGNORECURRENCY
, sal_False
);
386 *pCounter
++ = new SfxStringItem(DSID_CONN_SOCKET
, OUString());
387 *pCounter
++ = new SfxBoolItem(DSID_ESCAPE_DATETIME
, sal_True
);
388 *pCounter
++ = new SfxStringItem(DSID_NAMED_PIPE
, OUString());
389 *pCounter
++ = new OptionalBoolItem( DSID_PRIMARY_KEY_SUPPORT
);
390 *pCounter
++ = new SfxInt32Item(DSID_MAX_ROW_SCAN
, 100);
391 *pCounter
++ = new SfxBoolItem( DSID_RESPECTRESULTSETTYPE
,sal_False
);
394 static SfxItemInfo
const aItemInfos
[DSID_LAST_ITEM_ID
- DSID_FIRST_ITEM_ID
+ 1] =
459 OSL_ENSURE(sizeof(aItemInfos
)/sizeof(aItemInfos
[0]) == DSID_LAST_ITEM_ID
,"Invalid Ids!");
460 _rpPool
= new SfxItemPool(OUString("DSAItemPool"), DSID_FIRST_ITEM_ID
, DSID_LAST_ITEM_ID
,
461 aItemInfos
, _rppDefaults
);
462 _rpPool
->FreezeIdRanges();
464 // and, finally, the set
465 _rpSet
= new SfxItemSet(*_rpPool
, sal_True
);
469 //-------------------------------------------------------------------------
470 void ODbAdminDialog::destroyItemSet(SfxItemSet
*& _rpSet
, SfxItemPool
*& _rpPool
, SfxPoolItem
**& _rppDefaults
)
472 // _first_ delete the set (refering the pool)
482 _rpPool
->ReleaseDefaults(sal_True
);
483 // the "true" means delete the items, too
484 SfxItemPool::Free(_rpPool
);
488 // reset the defaults ptr
490 // no need to explicitly delete the defaults, this has been done by the ReleaseDefaults
493 //.........................................................................
495 //.........................................................................
497 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */