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 "advancedsettings.hxx"
21 : #include "advancedsettingsdlg.hxx"
22 : #include "moduledbu.hxx"
23 : #include "dsitems.hxx"
24 : #include "DbAdminImpl.hxx"
25 : #include "DriverSettings.hxx"
26 : #include "optionalboolitem.hxx"
27 : #include "dbu_resource.hrc"
28 : #include "dbu_dlg.hrc"
29 :
30 : #include <svl/eitem.hxx>
31 : #include <svl/intitem.hxx>
32 : #include <svl/stritem.hxx>
33 :
34 : #include <vcl/msgbox.hxx>
35 :
36 : namespace dbaui
37 : {
38 :
39 : using ::com::sun::star::uno::Reference;
40 : using ::com::sun::star::lang::XMultiServiceFactory;
41 : using ::com::sun::star::uno::Any;
42 : using ::com::sun::star::uno::XComponentContext;
43 : using ::com::sun::star::uno::UNO_QUERY_THROW;
44 : using ::com::sun::star::beans::XPropertySet;
45 : using ::com::sun::star::sdbc::XConnection;
46 : using ::com::sun::star::sdbc::XDriver;
47 :
48 : // SpecialSettingsPage
49 0 : struct BooleanSettingDesc
50 : {
51 : CheckBox** ppControl; // the dialog's control which displays this setting
52 : OString sControlId; // the widget name of the control in the .ui
53 : sal_uInt16 nItemId; // the ID of the item (in an SfxItemSet) which corresponds to this setting
54 : bool bInvertedDisplay; // true if and only if the checkbox is checked when the item is sal_False, and vice versa
55 : };
56 :
57 : // SpecialSettingsPage
58 0 : SpecialSettingsPage::SpecialSettingsPage( vcl::Window* pParent, const SfxItemSet& _rCoreAttrs, const DataSourceMetaData& _rDSMeta )
59 : : OGenericAdministrationPage(pParent, "SpecialSettingsPage",
60 : "dbaccess/ui/specialsettingspage.ui", _rCoreAttrs)
61 : , m_pIsSQL92Check( NULL )
62 : , m_pAppendTableAlias( NULL )
63 : , m_pAsBeforeCorrelationName( NULL )
64 : , m_pEnableOuterJoin( NULL )
65 : , m_pIgnoreDriverPrivileges( NULL )
66 : , m_pParameterSubstitution( NULL )
67 : , m_pSuppressVersionColumn( NULL )
68 : , m_pCatalog( NULL )
69 : , m_pSchema( NULL )
70 : , m_pIndexAppendix( NULL )
71 : , m_pDosLineEnds( NULL )
72 : , m_pCheckRequiredFields( NULL )
73 : , m_pIgnoreCurrency(NULL)
74 : , m_pEscapeDateTime(NULL)
75 : , m_pPrimaryKeySupport(NULL)
76 : , m_pRespectDriverResultSetType(NULL)
77 : , m_pBooleanComparisonModeLabel( NULL )
78 : , m_pBooleanComparisonMode( NULL )
79 : , m_pMaxRowScanLabel( NULL )
80 : , m_pMaxRowScan( NULL )
81 : , m_aControlDependencies()
82 : , m_aBooleanSettings()
83 0 : , m_bHasBooleanComparisonMode( _rDSMeta.getFeatureSet().has( DSID_BOOLEANCOMPARISON ) )
84 0 : , m_bHasMaxRowScan( _rDSMeta.getFeatureSet().has( DSID_MAX_ROW_SCAN ) )
85 : {
86 0 : impl_initBooleanSettings();
87 :
88 0 : const FeatureSet& rFeatures( _rDSMeta.getFeatureSet() );
89 : // create all the check boxes for the boolean settings
90 0 : for ( BooleanSettingDescs::const_iterator setting = m_aBooleanSettings.begin();
91 0 : setting != m_aBooleanSettings.end();
92 : ++setting
93 : )
94 : {
95 0 : sal_uInt16 nItemId = setting->nItemId;
96 0 : if ( rFeatures.has( nItemId ) )
97 : {
98 0 : get((*setting->ppControl), setting->sControlId);
99 0 : (*setting->ppControl)->SetClickHdl( getControlModifiedLink() );
100 :
101 : // check whether this must be a tristate check box
102 0 : const SfxPoolItem& rItem = _rCoreAttrs.Get( nItemId );
103 0 : if ( rItem.ISA( OptionalBoolItem ) )
104 0 : (*setting->ppControl)->EnableTriState( true );
105 : }
106 : }
107 :
108 0 : if ( m_pAsBeforeCorrelationName && m_pAppendTableAlias )
109 : // make m_pAsBeforeCorrelationName depend on m_pAppendTableAlias
110 0 : m_aControlDependencies.enableOnCheckMark( *m_pAppendTableAlias, *m_pAsBeforeCorrelationName );
111 :
112 : // create the controls for the boolean comparison mode
113 0 : if ( m_bHasBooleanComparisonMode )
114 : {
115 0 : get(m_pBooleanComparisonModeLabel, "comparisonft");
116 0 : get(m_pBooleanComparisonMode, "comparison");
117 0 : m_pBooleanComparisonMode->SetDropDownLineCount( 4 );
118 0 : m_pBooleanComparisonMode->SetSelectHdl( getControlModifiedLink() );
119 0 : m_pBooleanComparisonModeLabel->Show();
120 0 : m_pBooleanComparisonMode->Show();
121 : }
122 : // create the controls for the max row scan
123 0 : if ( m_bHasMaxRowScan )
124 : {
125 0 : get(m_pMaxRowScanLabel, "rowsft");
126 0 : get(m_pMaxRowScan, "rows");
127 0 : m_pMaxRowScan->SetModifyHdl(getControlModifiedLink());
128 0 : m_pMaxRowScan->SetUseThousandSep(false);
129 0 : m_pMaxRowScanLabel->Show();
130 0 : m_pMaxRowScan->Show();
131 : }
132 0 : }
133 :
134 0 : SpecialSettingsPage::~SpecialSettingsPage()
135 : {
136 0 : m_aControlDependencies.clear();
137 0 : }
138 :
139 0 : void SpecialSettingsPage::impl_initBooleanSettings()
140 : {
141 : OSL_PRECOND( m_aBooleanSettings.empty(), "SpecialSettingsPage::impl_initBooleanSettings: called twice!" );
142 :
143 : // for easier maintenance, write the table in this form, then copy it to m_aBooleanSettings
144 : BooleanSettingDesc aSettings[] = {
145 : { &m_pIsSQL92Check, "usesql92", DSID_SQL92CHECK, false },
146 : { &m_pAppendTableAlias, "append", DSID_APPEND_TABLE_ALIAS, false },
147 : { &m_pAsBeforeCorrelationName, "useas", DSID_AS_BEFORE_CORRNAME, false },
148 : { &m_pEnableOuterJoin, "useoj", DSID_ENABLEOUTERJOIN, false },
149 : { &m_pIgnoreDriverPrivileges, "ignoreprivs", DSID_IGNOREDRIVER_PRIV, false },
150 : { &m_pParameterSubstitution, "replaceparams", DSID_PARAMETERNAMESUBST, false },
151 : { &m_pSuppressVersionColumn, "displayver", DSID_SUPPRESSVERSIONCL, true },
152 : { &m_pCatalog, "usecatalogname", DSID_CATALOG, false },
153 : { &m_pSchema, "useschemaname", DSID_SCHEMA, false },
154 : { &m_pIndexAppendix, "createindex", DSID_INDEXAPPENDIX, false },
155 : { &m_pDosLineEnds, "eol", DSID_DOSLINEENDS, false },
156 : { &m_pIgnoreCurrency, "inputchecks", DSID_IGNORECURRENCY, false },
157 : { &m_pCheckRequiredFields, "ignorecurrency", DSID_CHECK_REQUIRED_FIELDS, false },
158 : { &m_pEscapeDateTime, "useodbcliterals", DSID_ESCAPE_DATETIME, false },
159 : { &m_pPrimaryKeySupport, "primarykeys", DSID_PRIMARY_KEY_SUPPORT, false },
160 : { &m_pRespectDriverResultSetType, "resulttype", DSID_RESPECTRESULTSETTYPE, false },
161 : { NULL, "", 0, false }
162 0 : };
163 :
164 0 : for ( const BooleanSettingDesc* pCopy = aSettings; pCopy->nItemId != 0; ++pCopy )
165 : {
166 0 : m_aBooleanSettings.push_back( *pCopy );
167 0 : }
168 0 : }
169 :
170 0 : void SpecialSettingsPage::fillWindows( ::std::vector< ISaveValueWrapper* >& _rControlList )
171 : {
172 0 : if ( m_bHasBooleanComparisonMode )
173 : {
174 0 : _rControlList.push_back( new ODisableWrapper< FixedText >( m_pBooleanComparisonModeLabel ) );
175 : }
176 0 : if ( m_bHasMaxRowScan )
177 : {
178 0 : _rControlList.push_back( new ODisableWrapper< FixedText >( m_pMaxRowScanLabel ) );
179 : }
180 0 : }
181 :
182 0 : void SpecialSettingsPage::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList)
183 : {
184 0 : for ( BooleanSettingDescs::const_iterator setting = m_aBooleanSettings.begin();
185 0 : setting != m_aBooleanSettings.end();
186 : ++setting
187 : )
188 : {
189 0 : if ( *setting->ppControl )
190 : {
191 0 : _rControlList.push_back( new OSaveValueWrapper< CheckBox >( *setting->ppControl ) );
192 : }
193 : }
194 :
195 0 : if ( m_bHasBooleanComparisonMode )
196 0 : _rControlList.push_back( new OSaveValueWrapper< ListBox >( m_pBooleanComparisonMode ) );
197 0 : if ( m_bHasMaxRowScan )
198 0 : _rControlList.push_back(new OSaveValueWrapper<NumericField>(m_pMaxRowScan));
199 0 : }
200 :
201 0 : void SpecialSettingsPage::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue)
202 : {
203 : // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
204 : bool bValid, bReadonly;
205 0 : getFlags( _rSet, bValid, bReadonly );
206 :
207 0 : if ( !bValid )
208 : {
209 0 : OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue);
210 0 : return;
211 : }
212 :
213 : // the boolean items
214 0 : for ( BooleanSettingDescs::const_iterator setting = m_aBooleanSettings.begin();
215 0 : setting != m_aBooleanSettings.end();
216 : ++setting
217 : )
218 : {
219 0 : if ( !*setting->ppControl )
220 0 : continue;
221 :
222 0 : ::boost::optional< bool > aValue(false);
223 0 : aValue.reset();
224 :
225 0 : SFX_ITEMSET_GET( _rSet, pItem, SfxPoolItem, setting->nItemId, true );
226 0 : if (const SfxBoolItem *pBoolItem = PTR_CAST(SfxBoolItem, pItem))
227 : {
228 0 : aValue.reset( pBoolItem->GetValue() );
229 : }
230 0 : else if (const OptionalBoolItem *pOptionalItem = PTR_CAST(OptionalBoolItem, pItem))
231 : {
232 0 : aValue = pOptionalItem->GetFullValue();
233 : }
234 : else
235 : OSL_FAIL( "SpecialSettingsPage::implInitControls: unknown boolean item type!" );
236 :
237 0 : if ( !aValue )
238 : {
239 0 : (*setting->ppControl)->SetState( TRISTATE_INDET );
240 : }
241 : else
242 : {
243 0 : bool bValue = *aValue;
244 0 : if ( setting->bInvertedDisplay )
245 0 : bValue = !bValue;
246 0 : (*setting->ppControl)->Check( bValue );
247 : }
248 0 : }
249 :
250 : // the non-boolean items
251 0 : if ( m_bHasBooleanComparisonMode )
252 : {
253 0 : SFX_ITEMSET_GET( _rSet, pBooleanComparison, SfxInt32Item, DSID_BOOLEANCOMPARISON, true );
254 0 : m_pBooleanComparisonMode->SelectEntryPos( static_cast< sal_uInt16 >( pBooleanComparison->GetValue() ) );
255 : }
256 :
257 0 : if ( m_bHasMaxRowScan )
258 : {
259 0 : SFX_ITEMSET_GET(_rSet, pMaxRowScan, SfxInt32Item, DSID_MAX_ROW_SCAN, true);
260 0 : m_pMaxRowScan->SetValue(pMaxRowScan->GetValue());
261 : }
262 :
263 0 : OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue);
264 : }
265 :
266 0 : bool SpecialSettingsPage::FillItemSet( SfxItemSet* _rSet )
267 : {
268 0 : bool bChangedSomething = false;
269 :
270 : // the boolean items
271 0 : for ( BooleanSettingDescs::const_iterator setting = m_aBooleanSettings.begin();
272 0 : setting != m_aBooleanSettings.end();
273 : ++setting
274 : )
275 : {
276 0 : if ( !*setting->ppControl )
277 0 : continue;
278 0 : fillBool( *_rSet, *setting->ppControl, setting->nItemId, bChangedSomething, setting->bInvertedDisplay );
279 : }
280 :
281 : // the non-boolean items
282 0 : if ( m_bHasBooleanComparisonMode )
283 : {
284 0 : if ( m_pBooleanComparisonMode->IsValueChangedFromSaved() )
285 : {
286 0 : _rSet->Put( SfxInt32Item( DSID_BOOLEANCOMPARISON, m_pBooleanComparisonMode->GetSelectEntryPos() ) );
287 0 : bChangedSomething = true;
288 : }
289 : }
290 0 : if ( m_bHasMaxRowScan )
291 : {
292 0 : fillInt32(*_rSet,m_pMaxRowScan,DSID_MAX_ROW_SCAN,bChangedSomething);
293 : }
294 0 : return bChangedSomething;
295 : }
296 :
297 : // GeneratedValuesPage
298 0 : GeneratedValuesPage::GeneratedValuesPage( vcl::Window* pParent, const SfxItemSet& _rCoreAttrs )
299 : : OGenericAdministrationPage(pParent, "GeneratedValuesPage",
300 0 : "dbaccess/ui/generatedvaluespage.ui", _rCoreAttrs)
301 : {
302 0 : get(m_pAutoFrame, "GeneratedValuesPage");
303 0 : get(m_pAutoRetrievingEnabled, "autoretrieve");
304 0 : get(m_pAutoIncrementLabel, "statementft");
305 0 : get(m_pAutoIncrement, "statement");
306 0 : get(m_pAutoRetrievingLabel, "queryft");
307 0 : get(m_pAutoRetrieving, "query");
308 :
309 0 : m_pAutoRetrievingEnabled->SetClickHdl( getControlModifiedLink() );
310 0 : m_pAutoIncrement->SetModifyHdl( getControlModifiedLink() );
311 0 : m_pAutoRetrieving->SetModifyHdl( getControlModifiedLink() );
312 :
313 : m_aControlDependencies.enableOnCheckMark( *m_pAutoRetrievingEnabled,
314 0 : *m_pAutoIncrementLabel, *m_pAutoIncrement, *m_pAutoRetrievingLabel, *m_pAutoRetrieving );
315 0 : }
316 :
317 0 : GeneratedValuesPage::~GeneratedValuesPage()
318 : {
319 0 : m_aControlDependencies.clear();
320 0 : }
321 :
322 0 : void GeneratedValuesPage::fillWindows( ::std::vector< ISaveValueWrapper* >& _rControlList )
323 : {
324 0 : _rControlList.push_back( new ODisableWrapper< VclFrame >( m_pAutoFrame ) );
325 0 : }
326 :
327 0 : void GeneratedValuesPage::fillControls( ::std::vector< ISaveValueWrapper* >& _rControlList )
328 : {
329 0 : _rControlList.push_back( new OSaveValueWrapper< CheckBox >( m_pAutoRetrievingEnabled ) );
330 0 : _rControlList.push_back( new OSaveValueWrapper< Edit >( m_pAutoIncrement ) );
331 0 : _rControlList.push_back( new OSaveValueWrapper< Edit >( m_pAutoRetrieving ) );
332 0 : }
333 :
334 0 : void GeneratedValuesPage::implInitControls( const SfxItemSet& _rSet, bool _bSaveValue )
335 : {
336 : // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
337 : bool bValid, bReadonly;
338 0 : getFlags(_rSet, bValid, bReadonly);
339 :
340 : // collect the items
341 0 : SFX_ITEMSET_GET(_rSet, pAutoIncrementItem, SfxStringItem, DSID_AUTOINCREMENTVALUE, true);
342 0 : SFX_ITEMSET_GET(_rSet, pAutoRetrieveValueItem, SfxStringItem, DSID_AUTORETRIEVEVALUE, true);
343 0 : SFX_ITEMSET_GET(_rSet, pAutoRetrieveEnabledItem, SfxBoolItem, DSID_AUTORETRIEVEENABLED, true);
344 :
345 : // forward the values to the controls
346 0 : if (bValid)
347 : {
348 0 : bool bEnabled = pAutoRetrieveEnabledItem->GetValue();
349 0 : m_pAutoRetrievingEnabled->Check( bEnabled );
350 :
351 0 : m_pAutoIncrement->SetText( pAutoIncrementItem->GetValue() );
352 0 : m_pAutoIncrement->ClearModifyFlag();
353 0 : m_pAutoRetrieving->SetText( pAutoRetrieveValueItem->GetValue() );
354 0 : m_pAutoRetrieving->ClearModifyFlag();
355 : }
356 0 : OGenericAdministrationPage::implInitControls( _rSet, _bSaveValue );
357 0 : }
358 :
359 0 : bool GeneratedValuesPage::FillItemSet(SfxItemSet* _rSet)
360 : {
361 0 : bool bChangedSomething = false;
362 :
363 0 : fillString( *_rSet, m_pAutoIncrement, DSID_AUTOINCREMENTVALUE, bChangedSomething );
364 0 : fillBool( *_rSet, m_pAutoRetrievingEnabled, DSID_AUTORETRIEVEENABLED, bChangedSomething );
365 0 : fillString( *_rSet, m_pAutoRetrieving, DSID_AUTORETRIEVEVALUE, bChangedSomething );
366 :
367 0 : return bChangedSomething;
368 : }
369 :
370 : // AdvancedSettingsDialog
371 0 : AdvancedSettingsDialog::AdvancedSettingsDialog( vcl::Window* _pParent, SfxItemSet* _pItems,
372 : const Reference< XComponentContext >& _rxContext, const Any& _aDataSourceName )
373 : : SfxTabDialog(_pParent, "AdvancedSettingsDialog",
374 0 : "dbaccess/ui/advancedsettingsdialog.ui", _pItems)
375 : {
376 0 : m_pImpl.reset(new ODbDataSourceAdministrationHelper(_rxContext,_pParent,this));
377 0 : m_pImpl->setDataSourceOrName(_aDataSourceName);
378 0 : Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
379 0 : m_pImpl->translateProperties(xDatasource, *_pItems);
380 0 : SetInputSet(_pItems);
381 : // propagate this set as our new input set and reset the example set
382 0 : delete pExampleSet;
383 0 : pExampleSet = new SfxItemSet(*GetInputSetImpl());
384 :
385 0 : const OUString eType = dbaui::ODbDataSourceAdministrationHelper::getDatasourceType(*_pItems);
386 :
387 0 : DataSourceMetaData aMeta( eType );
388 0 : const FeatureSet& rFeatures( aMeta.getFeatureSet() );
389 :
390 : // auto-generated values?
391 0 : if (rFeatures.supportsGeneratedValues())
392 0 : AddTabPage("generated", ODriversSettings::CreateGeneratedValuesPage, NULL);
393 : else
394 0 : RemoveTabPage("generated");
395 :
396 : // any "special settings"?
397 0 : if (rFeatures.supportsAnySpecialSetting())
398 0 : AddTabPage("special", ODriversSettings::CreateSpecialSettingsPage, NULL);
399 : else
400 0 : RemoveTabPage("special");
401 :
402 : // remove the reset button - it's meaning is much too ambiguous in this dialog
403 0 : RemoveResetButton();
404 0 : }
405 :
406 0 : AdvancedSettingsDialog::~AdvancedSettingsDialog()
407 : {
408 0 : SetInputSet(NULL);
409 0 : DELETEZ(pExampleSet);
410 0 : }
411 :
412 12 : bool AdvancedSettingsDialog::doesHaveAnyAdvancedSettings( const OUString& _sURL )
413 : {
414 12 : DataSourceMetaData aMeta( _sURL );
415 12 : const FeatureSet& rFeatures( aMeta.getFeatureSet() );
416 12 : if ( rFeatures.supportsGeneratedValues() || rFeatures.supportsAnySpecialSetting() )
417 12 : return true;
418 0 : return false;
419 : }
420 :
421 0 : short AdvancedSettingsDialog::Execute()
422 : {
423 0 : short nRet = SfxTabDialog::Execute();
424 0 : if ( nRet == RET_OK )
425 : {
426 0 : pExampleSet->Put(*GetOutputItemSet());
427 0 : m_pImpl->saveChanges(*pExampleSet);
428 : }
429 0 : return nRet;
430 : }
431 :
432 0 : void AdvancedSettingsDialog::PageCreated(sal_uInt16 _nId, SfxTabPage& _rPage)
433 : {
434 : // register ourself as modified listener
435 0 : static_cast<OGenericAdministrationPage&>(_rPage).SetServiceFactory( getORB() );
436 0 : static_cast<OGenericAdministrationPage&>(_rPage).SetAdminDialog(this,this);
437 :
438 0 : vcl::Window *pWin = GetViewWindow();
439 0 : if(pWin)
440 0 : pWin->Invalidate();
441 :
442 0 : SfxTabDialog::PageCreated(_nId, _rPage);
443 0 : }
444 :
445 0 : const SfxItemSet* AdvancedSettingsDialog::getOutputSet() const
446 : {
447 0 : return pExampleSet;
448 : }
449 :
450 0 : SfxItemSet* AdvancedSettingsDialog::getWriteOutputSet()
451 : {
452 0 : return pExampleSet;
453 : }
454 :
455 0 : ::std::pair< Reference< XConnection >, sal_Bool > AdvancedSettingsDialog::createConnection()
456 : {
457 0 : return m_pImpl->createConnection();
458 : }
459 :
460 0 : Reference< XComponentContext > AdvancedSettingsDialog::getORB() const
461 : {
462 0 : return m_pImpl->getORB();
463 : }
464 :
465 0 : Reference< XDriver > AdvancedSettingsDialog::getDriver()
466 : {
467 0 : return m_pImpl->getDriver();
468 : }
469 :
470 0 : OUString AdvancedSettingsDialog::getDatasourceType(const SfxItemSet& _rSet) const
471 : {
472 0 : return dbaui::ODbDataSourceAdministrationHelper::getDatasourceType(_rSet);
473 : }
474 :
475 0 : void AdvancedSettingsDialog::clearPassword()
476 : {
477 0 : m_pImpl->clearPassword();
478 0 : }
479 :
480 0 : void AdvancedSettingsDialog::setTitle(const OUString& _sTitle)
481 : {
482 0 : SetText(_sTitle);
483 0 : }
484 :
485 0 : void AdvancedSettingsDialog::enableConfirmSettings( bool _bEnable )
486 : {
487 : (void)_bEnable;
488 0 : }
489 :
490 0 : bool AdvancedSettingsDialog::saveDatasource()
491 : {
492 0 : return PrepareLeaveCurrentPage();
493 : }
494 :
495 72 : } // namespace dbaui
496 :
497 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|