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 .
20 #include "ConnectionPage.hxx"
21 #include "DbAdminImpl.hxx"
22 #include "DriverSettings.hxx"
23 #include "adminpages.hxx"
24 #include "dbadmin.hxx"
25 #include "dbu_dlg.hrc"
26 #include <svl/stritem.hxx>
27 #include <svl/eitem.hxx>
28 #include <svl/intitem.hxx>
29 #include "dbustrings.hrc"
30 #include "dsitems.hxx"
31 #include "dsnItem.hxx"
32 #include "localresaccess.hxx"
33 #include "optionalboolitem.hxx"
34 #include "propertysetitem.hxx"
35 #include "stringlistitem.hxx"
37 #include <unotools/confignode.hxx>
38 #include <vcl/msgbox.hxx>
42 using namespace com::sun::star::uno
;
43 using namespace com::sun::star::sdbc
;
44 using namespace com::sun::star::lang
;
45 using namespace com::sun::star::util
;
46 using namespace com::sun::star::beans
;
47 using namespace com::sun::star::container
;
50 ODbAdminDialog::ODbAdminDialog(vcl::Window
* _pParent
52 , const Reference
< XComponentContext
>& _rxContext
)
53 : SfxTabDialog(_pParent
, "AdminDialog",
54 "dbaccess/ui/admindialog.ui", _pItems
)
58 m_pImpl
.reset(new ODbDataSourceAdministrationHelper(_rxContext
,this,this));
60 // add the initial tab page
61 m_nMainPageID
= AddTabPage("advanced", OConnectionTabPage::Create
, NULL
);
63 // remove the reset button - it's meaning is much too ambiguous in this dialog
67 ODbAdminDialog::~ODbAdminDialog()
72 void ODbAdminDialog::dispose()
76 SfxTabDialog::dispose();
79 short ODbAdminDialog::Ok()
83 return ( AR_LEAVE_MODIFIED
== implApplyChanges() ) ? RET_OK
: RET_CANCEL
;
84 // TODO : AR_ERROR is not handled correctly, we always close the dialog here
87 void ODbAdminDialog::PageCreated(sal_uInt16 _nId
, SfxTabPage
& _rPage
)
89 // register ourself as modified listener
90 static_cast<OGenericAdministrationPage
&>(_rPage
).SetServiceFactory( getORB() );
91 static_cast<OGenericAdministrationPage
&>(_rPage
).SetAdminDialog(this,this);
93 vcl::Window
*pWin
= GetViewWindow();
97 SfxTabDialog::PageCreated(_nId
, _rPage
);
100 void ODbAdminDialog::addDetailPage(sal_uInt16 _nPageId
, sal_uInt16 _nTextId
, CreateTabPage _pCreateFunc
)
102 AddTabPage(_nPageId
, OUString(ModuleRes(_nTextId
)), _pCreateFunc
, NULL
);
103 m_aCurrentDetailPages
.push(_nPageId
);
106 void ODbAdminDialog::impl_selectDataSource(const ::com::sun::star::uno::Any
& _aDataSourceName
)
108 m_pImpl
->setDataSourceOrName(_aDataSourceName
);
109 Reference
< XPropertySet
> xDatasource
= m_pImpl
->getCurrentDataSource();
110 impl_resetPages( xDatasource
);
112 const DbuTypeCollectionItem
* pCollectionItem
= PTR_CAST(DbuTypeCollectionItem
, getOutputSet()->GetItem(DSID_TYPECOLLECTION
));
113 ::dbaccess::ODsnTypeCollection
* pCollection
= pCollectionItem
->getCollection();
114 ::dbaccess::DATASOURCE_TYPE eType
= pCollection
->determineType(getDatasourceType(*getOutputSet()));
116 // and insert the new ones
119 case ::dbaccess::DST_DBASE
:
120 addDetailPage(PAGE_DBASE
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateDbase
);
123 case ::dbaccess::DST_ADO
:
124 addDetailPage(PAGE_ADO
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateAdo
);
127 case ::dbaccess::DST_FLAT
:
128 addDetailPage(PAGE_TEXT
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateText
);
131 case ::dbaccess::DST_ODBC
:
132 addDetailPage(PAGE_ODBC
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateODBC
);
135 case ::dbaccess::DST_MYSQL_ODBC
:
136 addDetailPage(PAGE_MYSQL_ODBC
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateMySQLODBC
);
139 case ::dbaccess::DST_MYSQL_JDBC
:
140 addDetailPage(PAGE_MYSQL_JDBC
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateMySQLJDBC
);
143 case ::dbaccess::DST_ORACLE_JDBC
:
144 addDetailPage(PAGE_ORACLE_JDBC
, STR_PAGETITLE_ADVANCED
, ODriversSettings::CreateOracleJDBC
);
147 case ::dbaccess::DST_LDAP
:
148 addDetailPage(PAGE_LDAP
,STR_PAGETITLE_ADVANCED
,ODriversSettings::CreateLDAP
);
150 case ::dbaccess::DST_USERDEFINE1
: /// first user defined driver
151 case ::dbaccess::DST_USERDEFINE2
:
152 case ::dbaccess::DST_USERDEFINE3
:
153 case ::dbaccess::DST_USERDEFINE4
:
154 case ::dbaccess::DST_USERDEFINE5
:
155 case ::dbaccess::DST_USERDEFINE6
:
156 case ::dbaccess::DST_USERDEFINE7
:
157 case ::dbaccess::DST_USERDEFINE8
:
158 case ::dbaccess::DST_USERDEFINE9
:
159 case ::dbaccess::DST_USERDEFINE10
:
161 OUString
aTitle(ModuleRes(STR_PAGETITLE_ADVANCED
));
162 AddTabPage(PAGE_USERDRIVER
, aTitle
, ODriversSettings::CreateUser
, 0, false, 1);
163 m_aCurrentDetailPages
.push(PAGE_USERDRIVER
);
171 void ODbAdminDialog::impl_resetPages(const Reference
< XPropertySet
>& _rxDatasource
)
173 // the selection is valid if and only if we have a datasource now
174 GetInputSetImpl()->Put(SfxBoolItem(DSID_INVALID_SELECTION
, !_rxDatasource
.is()));
175 // (sal_False tells the tab pages to disable and reset all their controls, which is different
176 // from "just set them to readonly")
181 SetUpdateMode(false);
183 // remove all items which relate to indirect properties from the input set
184 // (without this, the following may happen: select an arbitrary data source where some indirect properties
185 // are set. Select another data source of the same type, where the indirect props are not set (yet). Then,
186 // the indirect property values of the first ds are shown in the second ds ...)
187 const ODbDataSourceAdministrationHelper::MapInt2String
& rMap
= m_pImpl
->getIndirectProperties();
188 for ( ODbDataSourceAdministrationHelper::MapInt2String::const_iterator aIndirect
= rMap
.begin();
189 aIndirect
!= rMap
.end();
192 GetInputSetImpl()->ClearItem( (sal_uInt16
)aIndirect
->first
);
194 // extract all relevant data from the property set of the data source
195 m_pImpl
->translateProperties(_rxDatasource
, *GetInputSetImpl());
197 // reset the example set
199 pExampleSet
= new SfxItemSet(*GetInputSetImpl());
201 // special case: MySQL Native does not have the generic "advanced" page
203 const DbuTypeCollectionItem
* pCollectionItem
= PTR_CAST(DbuTypeCollectionItem
, getOutputSet()->GetItem(DSID_TYPECOLLECTION
));
204 ::dbaccess::ODsnTypeCollection
* pCollection
= pCollectionItem
->getCollection();
205 if ( pCollection
->determineType(getDatasourceType( *pExampleSet
)) == ::dbaccess::DST_MYSQL_NATIVE
)
207 AddTabPage( PAGE_MYSQL_NATIVE
, OUString( ModuleRes( STR_PAGETITLE_CONNECTION
) ), ODriversSettings::CreateMySQLNATIVE
, NULL
);
208 RemoveTabPage("advanced");
209 m_nMainPageID
= PAGE_MYSQL_NATIVE
;
212 ShowPage( m_nMainPageID
);
213 SfxTabPage
* pConnectionPage
= GetTabPage( m_nMainPageID
);
214 if ( pConnectionPage
)
215 pConnectionPage
->Reset(GetInputSetImpl());
216 // if this is NULL, the page has not been created yet, which means we're called before the
217 // dialog was displayed (probably from inside the ctor)
222 void ODbAdminDialog::setTitle(const OUString
& _sTitle
)
227 void ODbAdminDialog::enableConfirmSettings( bool _bEnable
)
232 bool ODbAdminDialog::saveDatasource()
234 return PrepareLeaveCurrentPage();
237 ODbAdminDialog::ApplyResult
ODbAdminDialog::implApplyChanges()
239 if (!PrepareLeaveCurrentPage())
240 { // the page did not allow us to leave
244 if ( !m_pImpl
->saveChanges(*pExampleSet
) )
248 ShowPage(GetCurPageId());
249 // This does the usual ActivatePage, so the pages can save their current status.
250 // This way, next time they're asked what has changed since now and here, they really
251 // can compare with the status they have _now_ (not the one they had before this apply call).
255 return AR_LEAVE_MODIFIED
;
258 void ODbAdminDialog::selectDataSource(const ::com::sun::star::uno::Any
& _aDataSourceName
)
260 impl_selectDataSource(_aDataSourceName
);
263 const SfxItemSet
* ODbAdminDialog::getOutputSet() const
265 return GetExampleSet();
268 SfxItemSet
* ODbAdminDialog::getWriteOutputSet()
273 ::std::pair
< Reference
<XConnection
>,sal_Bool
> ODbAdminDialog::createConnection()
275 return m_pImpl
->createConnection();
278 Reference
< XComponentContext
> ODbAdminDialog::getORB() const
280 return m_pImpl
->getORB();
283 Reference
< XDriver
> ODbAdminDialog::getDriver()
285 return m_pImpl
->getDriver();
288 OUString
ODbAdminDialog::getDatasourceType(const SfxItemSet
& _rSet
) const
290 return dbaui::ODbDataSourceAdministrationHelper::getDatasourceType(_rSet
);
293 void ODbAdminDialog::clearPassword()
295 m_pImpl
->clearPassword();
298 SfxItemSet
* ODbAdminDialog::createItemSet(SfxItemSet
*& _rpSet
, SfxItemPool
*& _rpPool
, SfxPoolItem
**& _rppDefaults
, ::dbaccess::ODsnTypeCollection
* _pTypeCollection
)
300 // just to be sure ....
305 const OUString
sFilterAll( "%", 1, RTL_TEXTENCODING_ASCII_US
);
306 // create and initialize the defaults
307 _rppDefaults
= new SfxPoolItem
*[DSID_LAST_ITEM_ID
- DSID_FIRST_ITEM_ID
+ 1];
308 SfxPoolItem
** pCounter
= _rppDefaults
; // want to modify this without affecting the out param _rppDefaults
309 *pCounter
++ = new SfxStringItem(DSID_NAME
, OUString());
310 *pCounter
++ = new SfxStringItem(DSID_ORIGINALNAME
, OUString());
311 *pCounter
++ = new SfxStringItem(DSID_CONNECTURL
, OUString());
312 *pCounter
++ = new OStringListItem(DSID_TABLEFILTER
, Sequence
< OUString
>(&sFilterAll
, 1));
313 *pCounter
++ = new DbuTypeCollectionItem(DSID_TYPECOLLECTION
, _pTypeCollection
);
314 *pCounter
++ = new SfxBoolItem(DSID_INVALID_SELECTION
, false);
315 *pCounter
++ = new SfxBoolItem(DSID_READONLY
, false);
316 *pCounter
++ = new SfxStringItem(DSID_USER
, OUString());
317 *pCounter
++ = new SfxStringItem(DSID_PASSWORD
, OUString());
318 *pCounter
++ = new SfxStringItem(DSID_ADDITIONALOPTIONS
, OUString());
319 *pCounter
++ = new SfxStringItem(DSID_CHARSET
, OUString());
320 *pCounter
++ = new SfxBoolItem(DSID_PASSWORDREQUIRED
, false);
321 *pCounter
++ = new SfxBoolItem(DSID_SHOWDELETEDROWS
, false);
322 *pCounter
++ = new SfxBoolItem(DSID_ALLOWLONGTABLENAMES
, false);
323 *pCounter
++ = new SfxStringItem(DSID_JDBCDRIVERCLASS
, OUString());
324 *pCounter
++ = new SfxStringItem(DSID_FIELDDELIMITER
, OUString(','));
325 *pCounter
++ = new SfxStringItem(DSID_TEXTDELIMITER
, OUString('"'));
326 *pCounter
++ = new SfxStringItem(DSID_DECIMALDELIMITER
, OUString('.'));
327 *pCounter
++ = new SfxStringItem(DSID_THOUSANDSDELIMITER
, OUString());
328 *pCounter
++ = new SfxStringItem(DSID_TEXTFILEEXTENSION
, OUString("txt"));
329 *pCounter
++ = new SfxBoolItem(DSID_TEXTFILEHEADER
, true);
330 *pCounter
++ = new SfxBoolItem(DSID_PARAMETERNAMESUBST
, false);
331 *pCounter
++ = new SfxInt32Item(DSID_CONN_PORTNUMBER
, 8100);
332 *pCounter
++ = new SfxBoolItem(DSID_SUPPRESSVERSIONCL
, false);
333 *pCounter
++ = new OPropertySetItem(DSID_DATASOURCE_UNO
);
334 *pCounter
++ = new SfxBoolItem(DSID_CONN_SHUTSERVICE
, false);
335 *pCounter
++ = new SfxInt32Item(DSID_CONN_DATAINC
, 20);
336 *pCounter
++ = new SfxInt32Item(DSID_CONN_CACHESIZE
, 20);
337 *pCounter
++ = new SfxStringItem(DSID_CONN_CTRLUSER
, OUString());
338 *pCounter
++ = new SfxStringItem(DSID_CONN_CTRLPWD
, OUString());
339 *pCounter
++ = new SfxBoolItem(DSID_USECATALOG
, false);
340 *pCounter
++ = new SfxStringItem(DSID_CONN_HOSTNAME
, OUString());
341 *pCounter
++ = new SfxStringItem(DSID_CONN_LDAP_BASEDN
, OUString());
342 *pCounter
++ = new SfxInt32Item(DSID_CONN_LDAP_PORTNUMBER
, 389);
343 *pCounter
++ = new SfxInt32Item(DSID_CONN_LDAP_ROWCOUNT
, 100);
344 *pCounter
++ = new SfxBoolItem(DSID_SQL92CHECK
, false);
345 *pCounter
++ = new SfxStringItem(DSID_AUTOINCREMENTVALUE
, OUString());
346 *pCounter
++ = new SfxStringItem(DSID_AUTORETRIEVEVALUE
, OUString());
347 *pCounter
++ = new SfxBoolItem(DSID_AUTORETRIEVEENABLED
, false);
348 *pCounter
++ = new SfxBoolItem(DSID_APPEND_TABLE_ALIAS
, false);
349 *pCounter
++ = new SfxInt32Item(DSID_MYSQL_PORTNUMBER
, 3306);
350 *pCounter
++ = new SfxBoolItem(DSID_IGNOREDRIVER_PRIV
, true);
351 *pCounter
++ = new SfxInt32Item(DSID_BOOLEANCOMPARISON
, 0);
352 *pCounter
++ = new SfxInt32Item(DSID_ORACLE_PORTNUMBER
, 1521);
353 *pCounter
++ = new SfxBoolItem(DSID_ENABLEOUTERJOIN
, true);
354 *pCounter
++ = new SfxBoolItem(DSID_CATALOG
, true);
355 *pCounter
++ = new SfxBoolItem(DSID_SCHEMA
, true);
356 *pCounter
++ = new SfxBoolItem(DSID_INDEXAPPENDIX
, true);
357 *pCounter
++ = new SfxBoolItem(DSID_CONN_LDAP_USESSL
, false);
358 *pCounter
++ = new SfxStringItem(DSID_DOCUMENT_URL
, OUString());
359 *pCounter
++ = new SfxBoolItem(DSID_DOSLINEENDS
, false);
360 *pCounter
++ = new SfxStringItem(DSID_DATABASENAME
, OUString());
361 *pCounter
++ = new SfxBoolItem(DSID_AS_BEFORE_CORRNAME
, true);
362 *pCounter
++ = new SfxBoolItem(DSID_CHECK_REQUIRED_FIELDS
, true);
363 *pCounter
++ = new SfxBoolItem(DSID_IGNORECURRENCY
, false);
364 *pCounter
++ = new SfxStringItem(DSID_CONN_SOCKET
, OUString());
365 *pCounter
++ = new SfxBoolItem(DSID_ESCAPE_DATETIME
, true);
366 *pCounter
++ = new SfxStringItem(DSID_NAMED_PIPE
, OUString());
367 *pCounter
++ = new OptionalBoolItem( DSID_PRIMARY_KEY_SUPPORT
);
368 *pCounter
++ = new SfxInt32Item(DSID_MAX_ROW_SCAN
, 100);
369 *pCounter
++ = new SfxBoolItem( DSID_RESPECTRESULTSETTYPE
,false );
372 static SfxItemInfo
const aItemInfos
[DSID_LAST_ITEM_ID
- DSID_FIRST_ITEM_ID
+ 1] =
374 {0,SfxItemPoolFlags::NONE
},
375 {0,SfxItemPoolFlags::NONE
},
376 {0,SfxItemPoolFlags::NONE
},
377 {0,SfxItemPoolFlags::NONE
},
378 {0,SfxItemPoolFlags::NONE
},
379 {0,SfxItemPoolFlags::NONE
},
380 {0,SfxItemPoolFlags::NONE
},
381 {0,SfxItemPoolFlags::NONE
},
382 {0,SfxItemPoolFlags::NONE
},
383 {0,SfxItemPoolFlags::NONE
},
384 {0,SfxItemPoolFlags::NONE
},
385 {0,SfxItemPoolFlags::NONE
},
386 {0,SfxItemPoolFlags::NONE
},
387 {0,SfxItemPoolFlags::NONE
},
388 {0,SfxItemPoolFlags::NONE
},
389 {0,SfxItemPoolFlags::NONE
},
390 {0,SfxItemPoolFlags::NONE
},
391 {0,SfxItemPoolFlags::NONE
},
392 {0,SfxItemPoolFlags::NONE
},
393 {0,SfxItemPoolFlags::NONE
},
394 {0,SfxItemPoolFlags::NONE
},
395 {0,SfxItemPoolFlags::NONE
},
396 {0,SfxItemPoolFlags::NONE
},
397 {0,SfxItemPoolFlags::NONE
},
398 {0,SfxItemPoolFlags::NONE
},
399 {0,SfxItemPoolFlags::NONE
},
400 {0,SfxItemPoolFlags::NONE
},
401 {0,SfxItemPoolFlags::NONE
},
402 {0,SfxItemPoolFlags::NONE
},
403 {0,SfxItemPoolFlags::NONE
},
404 {0,SfxItemPoolFlags::NONE
},
405 {0,SfxItemPoolFlags::NONE
},
406 {0,SfxItemPoolFlags::NONE
},
407 {0,SfxItemPoolFlags::NONE
},
408 {0,SfxItemPoolFlags::NONE
},
409 {0,SfxItemPoolFlags::NONE
},
410 {0,SfxItemPoolFlags::NONE
},
411 {0,SfxItemPoolFlags::NONE
},
412 {0,SfxItemPoolFlags::NONE
},
413 {0,SfxItemPoolFlags::NONE
},
414 {0,SfxItemPoolFlags::NONE
},
415 {0,SfxItemPoolFlags::NONE
},
416 {0,SfxItemPoolFlags::NONE
},
417 {0,SfxItemPoolFlags::NONE
},
418 {0,SfxItemPoolFlags::NONE
},
419 {0,SfxItemPoolFlags::NONE
},
420 {0,SfxItemPoolFlags::NONE
},
421 {0,SfxItemPoolFlags::NONE
},
422 {0,SfxItemPoolFlags::NONE
},
423 {0,SfxItemPoolFlags::NONE
},
424 {0,SfxItemPoolFlags::NONE
},
425 {0,SfxItemPoolFlags::NONE
},
426 {0,SfxItemPoolFlags::NONE
},
427 {0,SfxItemPoolFlags::NONE
},
428 {0,SfxItemPoolFlags::NONE
},
429 {0,SfxItemPoolFlags::NONE
},
430 {0,SfxItemPoolFlags::NONE
},
431 {0,SfxItemPoolFlags::NONE
},
432 {0,SfxItemPoolFlags::NONE
},
433 {0,SfxItemPoolFlags::NONE
},
434 {0,SfxItemPoolFlags::NONE
}
437 OSL_ENSURE(sizeof(aItemInfos
)/sizeof(aItemInfos
[0]) == DSID_LAST_ITEM_ID
,"Invalid Ids!");
438 _rpPool
= new SfxItemPool(OUString("DSAItemPool"), DSID_FIRST_ITEM_ID
, DSID_LAST_ITEM_ID
,
439 aItemInfos
, _rppDefaults
);
440 _rpPool
->FreezeIdRanges();
442 // and, finally, the set
443 _rpSet
= new SfxItemSet(*_rpPool
, true);
448 void ODbAdminDialog::destroyItemSet(SfxItemSet
*& _rpSet
, SfxItemPool
*& _rpPool
, SfxPoolItem
**& _rppDefaults
)
450 // _first_ delete the set (referring the pool)
460 _rpPool
->ReleaseDefaults(true);
461 // the "true" means delete the items, too
462 SfxItemPool::Free(_rpPool
);
466 // reset the defaults ptr
468 // no need to explicitly delete the defaults, this has been done by the ReleaseDefaults
473 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */