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