1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "ConnectionPage.hxx"
31 #include "DbAdminImpl.hxx"
32 #include "DriverSettings.hxx"
33 #include "adminpages.hxx"
34 #include "dbadmin.hrc"
35 #include "dbadmin.hxx"
36 #include "dbu_dlg.hrc"
37 #include <svl/stritem.hxx>
38 #include <svl/eitem.hxx>
39 #include <svl/intitem.hxx>
40 #include "dbustrings.hrc"
41 #include "dsitems.hxx"
42 #include "dsnItem.hxx"
43 #include "localresaccess.hxx"
44 #include "optionalboolitem.hxx"
45 #include "propertysetitem.hxx"
46 #include "stringlistitem.hxx"
48 #include <unotools/confignode.hxx>
49 #include <vcl/msgbox.hxx>
51 //.........................................................................
54 //.........................................................................
55 using namespace com::sun::star::uno
;
56 using namespace com::sun::star::sdbc
;
57 using namespace com::sun::star::lang
;
58 using namespace com::sun::star::util
;
59 using namespace com::sun::star::beans
;
60 using namespace com::sun::star::container
;
62 //=========================================================================
64 //=========================================================================
65 DBG_NAME(ODbAdminDialog
)
66 //-------------------------------------------------------------------------
67 ODbAdminDialog::ODbAdminDialog(Window
* _pParent
69 , const Reference
< XMultiServiceFactory
>& _rxORB
71 :SfxTabDialog(_pParent
, ModuleRes(DLG_DATABASE_ADMINISTRATION
), _pItems
)
72 ,m_bApplied(sal_False
)
73 ,m_bUIEnabled( sal_True
)
74 ,m_nMainPageID( PAGE_CONNECTION
)
76 DBG_CTOR(ODbAdminDialog
,NULL
);
78 m_pImpl
= ::std::auto_ptr
<ODbDataSourceAdministrationHelper
>(new ODbDataSourceAdministrationHelper(_rxORB
,this,this));
80 // add the initial tab page
81 AddTabPage( m_nMainPageID
, String( ModuleRes( STR_PAGETITLE_GENERAL
) ), OConnectionTabPage::Create
, NULL
);
83 // remove the reset button - it's meaning is much too ambiguous in this dialog
85 // no local resources needed anymore
89 //-------------------------------------------------------------------------
90 ODbAdminDialog::~ODbAdminDialog()
95 DBG_DTOR(ODbAdminDialog
,NULL
);
97 //-------------------------------------------------------------------------
98 short ODbAdminDialog::Ok()
102 return ( AR_LEAVE_MODIFIED
== implApplyChanges() ) ? RET_OK
: RET_CANCEL
;
103 // TODO : AR_ERROR is not handled correctly, we always close the dialog here
106 //-------------------------------------------------------------------------
107 void ODbAdminDialog::PageCreated(sal_uInt16 _nId
, SfxTabPage
& _rPage
)
109 // register ourself as modified listener
110 static_cast<OGenericAdministrationPage
&>(_rPage
).SetServiceFactory(m_pImpl
->getORB());
111 static_cast<OGenericAdministrationPage
&>(_rPage
).SetAdminDialog(this,this);
114 Window
*pWin
= GetViewWindow();
118 SfxTabDialog::PageCreated(_nId
, _rPage
);
121 // -----------------------------------------------------------------------------
122 void ODbAdminDialog::addDetailPage(sal_uInt16 _nPageId
, sal_uInt16 _nTextId
, CreateTabPage _pCreateFunc
)
124 // open our own resource block, as the page titles are strings local to this block
125 LocalResourceAccess
aDummy(DLG_DATABASE_ADMINISTRATION
, RSC_TABDIALOG
);
127 AddTabPage(_nPageId
, String(ModuleRes(_nTextId
)), _pCreateFunc
, NULL
);
128 m_aCurrentDetailPages
.push(_nPageId
);
131 //-------------------------------------------------------------------------
132 void ODbAdminDialog::impl_selectDataSource(const ::com::sun::star::uno::Any
& _aDataSourceName
)
134 m_pImpl
->setDataSourceOrName(_aDataSourceName
);
135 Reference
< XPropertySet
> xDatasource
= m_pImpl
->getCurrentDataSource();
136 impl_resetPages( xDatasource
);
138 DbuTypeCollectionItem
* pCollectionItem
= PTR_CAST(DbuTypeCollectionItem
, getOutputSet()->GetItem(DSID_TYPECOLLECTION
));
139 ::dbaccess::ODsnTypeCollection
* pCollection
= pCollectionItem
->getCollection();
140 ::dbaccess::DATASOURCE_TYPE eType
= pCollection
->determineType(getDatasourceType(*getOutputSet()));
142 // and insert the new ones
145 case ::dbaccess::DST_DBASE
:
146 addDetailPage(PAGE_DBASE
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateDbase
);
149 case ::dbaccess::DST_ADO
:
150 addDetailPage(PAGE_ADO
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateAdo
);
153 case ::dbaccess::DST_FLAT
:
154 addDetailPage(PAGE_TEXT
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateText
);
157 case ::dbaccess::DST_ODBC
:
158 addDetailPage(PAGE_ODBC
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateODBC
);
161 case ::dbaccess::DST_MYSQL_ODBC
:
162 addDetailPage(PAGE_MYSQL_ODBC
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateMySQLODBC
);
165 case ::dbaccess::DST_MYSQL_JDBC
:
166 addDetailPage(PAGE_MYSQL_JDBC
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateMySQLJDBC
);
169 case ::dbaccess::DST_ORACLE_JDBC
:
170 addDetailPage(PAGE_ORACLE_JDBC
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateOracleJDBC
);
173 case ::dbaccess::DST_LDAP
:
174 addDetailPage(PAGE_LDAP
,STR_PAGETITLE_ADVANCED
,ODriversSettings::CreateLDAP
);
176 case ::dbaccess::DST_USERDEFINE1
: /// first user defined driver
177 case ::dbaccess::DST_USERDEFINE2
:
178 case ::dbaccess::DST_USERDEFINE3
:
179 case ::dbaccess::DST_USERDEFINE4
:
180 case ::dbaccess::DST_USERDEFINE5
:
181 case ::dbaccess::DST_USERDEFINE6
:
182 case ::dbaccess::DST_USERDEFINE7
:
183 case ::dbaccess::DST_USERDEFINE8
:
184 case ::dbaccess::DST_USERDEFINE9
:
185 case ::dbaccess::DST_USERDEFINE10
:
187 LocalResourceAccess
aDummy(DLG_DATABASE_ADMINISTRATION
, RSC_TABDIALOG
);
188 String
aTitle(ModuleRes(STR_PAGETITLE_ADVANCED
));
189 AddTabPage(PAGE_USERDRIVER
, aTitle
, ODriversSettings::CreateUser
, 0, sal_False
, 1);
190 m_aCurrentDetailPages
.push(PAGE_USERDRIVER
);
198 //-------------------------------------------------------------------------
199 void ODbAdminDialog::impl_resetPages(const Reference
< XPropertySet
>& _rxDatasource
)
201 // the selection is valid if and only if we have a datasource now
202 GetInputSetImpl()->Put(SfxBoolItem(DSID_INVALID_SELECTION
, !_rxDatasource
.is()));
203 // (sal_False tells the tab pages to disable and reset all their controls, which is different
204 // from "just set them to readonly")
209 SetUpdateMode(sal_False
);
211 // remove all items which relate to indirect properties from the input set
212 // (without this, the following may happen: select an arbitrary data source where some indirect properties
213 // are set. Select another data source of the same type, where the indirect props are not set (yet). Then,
214 // the indirect property values of the first ds are shown in the second ds ...)
215 const ODbDataSourceAdministrationHelper::MapInt2String
& rMap
= m_pImpl
->getIndirectProperties();
216 for ( ODbDataSourceAdministrationHelper::ConstMapInt2StringIterator aIndirect
= rMap
.begin();
217 aIndirect
!= rMap
.end();
220 GetInputSetImpl()->ClearItem( (sal_uInt16
)aIndirect
->first
);
222 // extract all relevant data from the property set of the data source
223 m_pImpl
->translateProperties(_rxDatasource
, *GetInputSetImpl());
225 // propagate this set as our new input set and reset the example set
226 SetInputSet(GetInputSetImpl());
228 pExampleSet
= new SfxItemSet(*GetInputSetImpl());
230 // special case: MySQL Native does not have the generic PAGE_CONNECTION page
232 DbuTypeCollectionItem
* pCollectionItem
= PTR_CAST(DbuTypeCollectionItem
, getOutputSet()->GetItem(DSID_TYPECOLLECTION
));
233 ::dbaccess::ODsnTypeCollection
* pCollection
= pCollectionItem
->getCollection();
234 if ( pCollection
->determineType(getDatasourceType( *pExampleSet
)) == ::dbaccess::DST_MYSQL_NATIVE
)
236 LocalResourceAccess
aDummy(DLG_DATABASE_ADMINISTRATION
, RSC_TABDIALOG
);
237 AddTabPage( PAGE_MYSQL_NATIVE
, String( ModuleRes( STR_PAGETITLE_CONNECTION
) ), ODriversSettings::CreateMySQLNATIVE
, NULL
);
238 RemoveTabPage( PAGE_CONNECTION
);
239 m_nMainPageID
= PAGE_MYSQL_NATIVE
;
242 ShowPage( m_nMainPageID
);
243 SfxTabPage
* pConnectionPage
= GetTabPage( m_nMainPageID
);
244 if ( pConnectionPage
)
245 pConnectionPage
->Reset(*GetInputSetImpl());
246 // if this is NULL, the page has not been created yet, which means we're called before the
247 // dialog was displayed (probably from inside the ctor)
249 SetUpdateMode(sal_True
);
251 // -----------------------------------------------------------------------------
252 void ODbAdminDialog::setTitle(const ::rtl::OUString
& _sTitle
)
256 //-------------------------------------------------------------------------
257 void ODbAdminDialog::enableConfirmSettings( bool _bEnable
)
261 //-------------------------------------------------------------------------
262 sal_Bool
ODbAdminDialog::saveDatasource()
264 return PrepareLeaveCurrentPage();
266 //-------------------------------------------------------------------------
267 ODbAdminDialog::ApplyResult
ODbAdminDialog::implApplyChanges()
269 if (!PrepareLeaveCurrentPage())
270 { // the page did not allow us to leave
274 if ( !m_pImpl
->saveChanges(*pExampleSet
) )
278 ShowPage(GetCurPageId());
279 // This does the usual ActivatePage, so the pages can save their current status.
280 // This way, next time they're asked what has changed since now and here, they really
281 // can compare with the status they have _now_ (not the one they had before this apply call).
283 m_bApplied
= sal_True
;
285 return AR_LEAVE_MODIFIED
;
287 //-------------------------------------------------------------------------
288 void ODbAdminDialog::selectDataSource(const ::com::sun::star::uno::Any
& _aDataSourceName
)
290 impl_selectDataSource(_aDataSourceName
);
293 // -----------------------------------------------------------------------------
294 const SfxItemSet
* ODbAdminDialog::getOutputSet() const
296 return GetExampleSet();
298 // -----------------------------------------------------------------------------
299 SfxItemSet
* ODbAdminDialog::getWriteOutputSet()
303 // -----------------------------------------------------------------------------
304 ::std::pair
< Reference
<XConnection
>,sal_Bool
> ODbAdminDialog::createConnection()
306 return m_pImpl
->createConnection();
308 // -----------------------------------------------------------------------------
309 Reference
< XMultiServiceFactory
> ODbAdminDialog::getORB() const
311 return m_pImpl
->getORB();
313 // -----------------------------------------------------------------------------
314 Reference
< XDriver
> ODbAdminDialog::getDriver()
316 return m_pImpl
->getDriver();
318 // -----------------------------------------------------------------------------
319 ::rtl::OUString
ODbAdminDialog::getDatasourceType(const SfxItemSet
& _rSet
) const
321 return m_pImpl
->getDatasourceType(_rSet
);
323 // -----------------------------------------------------------------------------
324 void ODbAdminDialog::clearPassword()
326 m_pImpl
->clearPassword();
328 //-------------------------------------------------------------------------
329 SfxItemSet
* ODbAdminDialog::createItemSet(SfxItemSet
*& _rpSet
, SfxItemPool
*& _rpPool
, SfxPoolItem
**& _rppDefaults
, ::dbaccess::ODsnTypeCollection
* _pTypeCollection
)
331 // just to be sure ....
336 const ::rtl::OUString
sFilterAll( "%", 1, RTL_TEXTENCODING_ASCII_US
);
337 // create and initialize the defaults
338 _rppDefaults
= new SfxPoolItem
*[DSID_LAST_ITEM_ID
- DSID_FIRST_ITEM_ID
+ 1];
339 SfxPoolItem
** pCounter
= _rppDefaults
; // want to modify this without affecting the out param _rppDefaults
340 *pCounter
++ = new SfxStringItem(DSID_NAME
, String());
341 *pCounter
++ = new SfxStringItem(DSID_ORIGINALNAME
, String());
342 *pCounter
++ = new SfxStringItem(DSID_CONNECTURL
, String());
343 *pCounter
++ = new OStringListItem(DSID_TABLEFILTER
, Sequence
< ::rtl::OUString
>(&sFilterAll
, 1));
344 *pCounter
++ = new DbuTypeCollectionItem(DSID_TYPECOLLECTION
, _pTypeCollection
);
345 *pCounter
++ = new SfxBoolItem(DSID_INVALID_SELECTION
, sal_False
);
346 *pCounter
++ = new SfxBoolItem(DSID_READONLY
, sal_False
);
347 *pCounter
++ = new SfxStringItem(DSID_USER
, String());
348 *pCounter
++ = new SfxStringItem(DSID_PASSWORD
, String());
349 *pCounter
++ = new SfxStringItem(DSID_ADDITIONALOPTIONS
, String());
350 *pCounter
++ = new SfxStringItem(DSID_CHARSET
, String());
351 *pCounter
++ = new SfxBoolItem(DSID_PASSWORDREQUIRED
, sal_False
);
352 *pCounter
++ = new SfxBoolItem(DSID_SHOWDELETEDROWS
, sal_False
);
353 *pCounter
++ = new SfxBoolItem(DSID_ALLOWLONGTABLENAMES
, sal_False
);
354 *pCounter
++ = new SfxStringItem(DSID_JDBCDRIVERCLASS
, String());
355 *pCounter
++ = new SfxStringItem(DSID_FIELDDELIMITER
, ',');
356 *pCounter
++ = new SfxStringItem(DSID_TEXTDELIMITER
, '"');
357 *pCounter
++ = new SfxStringItem(DSID_DECIMALDELIMITER
, '.');
358 *pCounter
++ = new SfxStringItem(DSID_THOUSANDSDELIMITER
, String());
359 *pCounter
++ = new SfxStringItem(DSID_TEXTFILEEXTENSION
, String::CreateFromAscii("txt"));
360 *pCounter
++ = new SfxBoolItem(DSID_TEXTFILEHEADER
, sal_True
);
361 *pCounter
++ = new SfxBoolItem(DSID_PARAMETERNAMESUBST
, sal_False
);
362 *pCounter
++ = new SfxInt32Item(DSID_CONN_PORTNUMBER
, 8100);
363 *pCounter
++ = new SfxBoolItem(DSID_SUPPRESSVERSIONCL
, sal_False
);
364 *pCounter
++ = new OPropertySetItem(DSID_DATASOURCE_UNO
);
365 *pCounter
++ = new SfxBoolItem(DSID_CONN_SHUTSERVICE
, sal_False
);
366 *pCounter
++ = new SfxInt32Item(DSID_CONN_DATAINC
, 20);
367 *pCounter
++ = new SfxInt32Item(DSID_CONN_CACHESIZE
, 20);
368 *pCounter
++ = new SfxStringItem(DSID_CONN_CTRLUSER
, String());
369 *pCounter
++ = new SfxStringItem(DSID_CONN_CTRLPWD
, String());
370 *pCounter
++ = new SfxBoolItem(DSID_USECATALOG
, sal_False
);
371 *pCounter
++ = new SfxStringItem(DSID_CONN_HOSTNAME
, String());
372 *pCounter
++ = new SfxStringItem(DSID_CONN_LDAP_BASEDN
, String());
373 *pCounter
++ = new SfxInt32Item(DSID_CONN_LDAP_PORTNUMBER
, 389);
374 *pCounter
++ = new SfxInt32Item(DSID_CONN_LDAP_ROWCOUNT
, 100);
375 *pCounter
++ = new SfxBoolItem(DSID_SQL92CHECK
, sal_False
);
376 *pCounter
++ = new SfxStringItem(DSID_AUTOINCREMENTVALUE
, String());
377 *pCounter
++ = new SfxStringItem(DSID_AUTORETRIEVEVALUE
, String());
378 *pCounter
++ = new SfxBoolItem(DSID_AUTORETRIEVEENABLED
, sal_False
);
379 *pCounter
++ = new SfxBoolItem(DSID_APPEND_TABLE_ALIAS
, sal_False
);
380 *pCounter
++ = new SfxInt32Item(DSID_MYSQL_PORTNUMBER
, 3306);
381 *pCounter
++ = new SfxBoolItem(DSID_IGNOREDRIVER_PRIV
, sal_True
);
382 *pCounter
++ = new SfxInt32Item(DSID_BOOLEANCOMPARISON
, 0);
383 *pCounter
++ = new SfxInt32Item(DSID_ORACLE_PORTNUMBER
, 1521);
384 *pCounter
++ = new SfxBoolItem(DSID_ENABLEOUTERJOIN
, sal_True
);
385 *pCounter
++ = new SfxBoolItem(DSID_CATALOG
, sal_True
);
386 *pCounter
++ = new SfxBoolItem(DSID_SCHEMA
, sal_True
);
387 *pCounter
++ = new SfxBoolItem(DSID_INDEXAPPENDIX
, sal_True
);
388 *pCounter
++ = new SfxBoolItem(DSID_CONN_LDAP_USESSL
, sal_False
);
389 *pCounter
++ = new SfxStringItem(DSID_DOCUMENT_URL
, String());
390 *pCounter
++ = new SfxBoolItem(DSID_DOSLINEENDS
, sal_False
);
391 *pCounter
++ = new SfxStringItem(DSID_DATABASENAME
, String());
392 *pCounter
++ = new SfxBoolItem(DSID_AS_BEFORE_CORRNAME
, sal_True
);
393 *pCounter
++ = new SfxBoolItem(DSID_CHECK_REQUIRED_FIELDS
, sal_True
);
394 *pCounter
++ = new SfxBoolItem(DSID_IGNORECURRENCY
, sal_False
);
395 *pCounter
++ = new SfxStringItem(DSID_CONN_SOCKET
, String());
396 *pCounter
++ = new SfxBoolItem(DSID_ESCAPE_DATETIME
, sal_True
);
397 *pCounter
++ = new SfxStringItem(DSID_NAMED_PIPE
, String());
398 *pCounter
++ = new OptionalBoolItem( DSID_PRIMARY_KEY_SUPPORT
);
399 *pCounter
++ = new SfxInt32Item(DSID_MAX_ROW_SCAN
, 100);
400 *pCounter
++ = new SfxBoolItem( DSID_RESPECTRESULTSETTYPE
,sal_False
);
403 static SfxItemInfo
const aItemInfos
[DSID_LAST_ITEM_ID
- DSID_FIRST_ITEM_ID
+ 1] =
468 OSL_ENSURE(sizeof(aItemInfos
)/sizeof(aItemInfos
[0]) == DSID_LAST_ITEM_ID
,"Invalid Ids!");
469 _rpPool
= new SfxItemPool(String::CreateFromAscii("DSAItemPool"), DSID_FIRST_ITEM_ID
, DSID_LAST_ITEM_ID
,
470 aItemInfos
, _rppDefaults
);
471 _rpPool
->FreezeIdRanges();
473 // and, finally, the set
474 _rpSet
= new SfxItemSet(*_rpPool
, sal_True
);
478 //-------------------------------------------------------------------------
479 void ODbAdminDialog::destroyItemSet(SfxItemSet
*& _rpSet
, SfxItemPool
*& _rpPool
, SfxPoolItem
**& _rppDefaults
)
481 // _first_ delete the set (refering the pool)
491 _rpPool
->ReleaseDefaults(sal_True
);
492 // the "true" means delete the items, too
493 SfxItemPool::Free(_rpPool
);
497 // reset the defaults ptr
499 // no need to explicitly delete the defaults, this has been done by the ReleaseDefaults
502 //.........................................................................
504 //.........................................................................
506 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */