fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / dlg / advancedsettings.cxx
blob2fe318634f13be60a58c20e5f7bd658febf8e00e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "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"
30 #include <svl/eitem.hxx>
31 #include <svl/intitem.hxx>
32 #include <svl/stritem.hxx>
34 #include <vcl/msgbox.hxx>
36 namespace dbaui
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;
48 // SpecialSettingsPage
49 struct BooleanSettingDesc
51 VclPtr<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
57 // SpecialSettingsPage
58 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 , m_bHasBooleanComparisonMode( _rDSMeta.getFeatureSet().has( DSID_BOOLEANCOMPARISON ) )
84 , m_bHasMaxRowScan( _rDSMeta.getFeatureSet().has( DSID_MAX_ROW_SCAN ) )
86 impl_initBooleanSettings();
88 const FeatureSet& rFeatures( _rDSMeta.getFeatureSet() );
89 // create all the check boxes for the boolean settings
90 for ( BooleanSettingDescs::const_iterator setting = m_aBooleanSettings.begin();
91 setting != m_aBooleanSettings.end();
92 ++setting
95 sal_uInt16 nItemId = setting->nItemId;
96 if ( rFeatures.has( nItemId ) )
98 get(*setting->ppControl, setting->sControlId);
99 (*setting->ppControl)->SetClickHdl( getControlModifiedLink() );
100 (*setting->ppControl)->Show();
102 // check whether this must be a tristate check box
103 const SfxPoolItem& rItem = _rCoreAttrs.Get( nItemId );
104 if ( rItem.ISA( OptionalBoolItem ) )
105 (*setting->ppControl)->EnableTriState( true );
109 if ( m_pAsBeforeCorrelationName && m_pAppendTableAlias )
110 // make m_pAsBeforeCorrelationName depend on m_pAppendTableAlias
111 m_aControlDependencies.enableOnCheckMark( *m_pAppendTableAlias, *m_pAsBeforeCorrelationName );
113 // create the controls for the boolean comparison mode
114 if ( m_bHasBooleanComparisonMode )
116 get(m_pBooleanComparisonModeLabel, "comparisonft");
117 get(m_pBooleanComparisonMode, "comparison");
118 m_pBooleanComparisonMode->SetDropDownLineCount( 4 );
119 m_pBooleanComparisonMode->SetSelectHdl( getControlModifiedLink() );
120 m_pBooleanComparisonModeLabel->Show();
121 m_pBooleanComparisonMode->Show();
123 // create the controls for the max row scan
124 if ( m_bHasMaxRowScan )
126 get(m_pMaxRowScanLabel, "rowsft");
127 get(m_pMaxRowScan, "rows");
128 m_pMaxRowScan->SetModifyHdl(getControlModifiedLink());
129 m_pMaxRowScan->SetUseThousandSep(false);
130 m_pMaxRowScanLabel->Show();
131 m_pMaxRowScan->Show();
135 SpecialSettingsPage::~SpecialSettingsPage()
137 disposeOnce();
140 void SpecialSettingsPage::dispose()
142 m_aControlDependencies.clear();
143 m_pIsSQL92Check.clear();
144 m_pAppendTableAlias.clear();
145 m_pAsBeforeCorrelationName.clear();
146 m_pEnableOuterJoin.clear();
147 m_pIgnoreDriverPrivileges.clear();
148 m_pParameterSubstitution.clear();
149 m_pSuppressVersionColumn.clear();
150 m_pCatalog.clear();
151 m_pSchema.clear();
152 m_pIndexAppendix.clear();
153 m_pDosLineEnds.clear();
154 m_pCheckRequiredFields.clear();
155 m_pIgnoreCurrency.clear();
156 m_pEscapeDateTime.clear();
157 m_pPrimaryKeySupport.clear();
158 m_pRespectDriverResultSetType.clear();
159 m_pBooleanComparisonModeLabel.clear();
160 m_pBooleanComparisonMode.clear();
161 m_pMaxRowScanLabel.clear();
162 m_pMaxRowScan.clear();
163 OGenericAdministrationPage::dispose();
166 void SpecialSettingsPage::impl_initBooleanSettings()
168 OSL_PRECOND( m_aBooleanSettings.empty(), "SpecialSettingsPage::impl_initBooleanSettings: called twice!" );
170 // for easier maintenance, write the table in this form, then copy it to m_aBooleanSettings
171 BooleanSettingDesc aSettings[] = {
172 { &m_pIsSQL92Check, "usesql92", DSID_SQL92CHECK, false },
173 { &m_pAppendTableAlias, "append", DSID_APPEND_TABLE_ALIAS, false },
174 { &m_pAsBeforeCorrelationName, "useas", DSID_AS_BEFORE_CORRNAME, false },
175 { &m_pEnableOuterJoin, "useoj", DSID_ENABLEOUTERJOIN, false },
176 { &m_pIgnoreDriverPrivileges, "ignoreprivs", DSID_IGNOREDRIVER_PRIV, false },
177 { &m_pParameterSubstitution, "replaceparams", DSID_PARAMETERNAMESUBST, false },
178 { &m_pSuppressVersionColumn, "displayver", DSID_SUPPRESSVERSIONCL, true },
179 { &m_pCatalog, "usecatalogname", DSID_CATALOG, false },
180 { &m_pSchema, "useschemaname", DSID_SCHEMA, false },
181 { &m_pIndexAppendix, "createindex", DSID_INDEXAPPENDIX, false },
182 { &m_pDosLineEnds, "eol", DSID_DOSLINEENDS, false },
183 { &m_pCheckRequiredFields, "ignorecurrency", DSID_CHECK_REQUIRED_FIELDS, false },
184 { &m_pIgnoreCurrency, "inputchecks", DSID_IGNORECURRENCY, false },
185 { &m_pEscapeDateTime, "useodbcliterals", DSID_ESCAPE_DATETIME, false },
186 { &m_pPrimaryKeySupport, "primarykeys", DSID_PRIMARY_KEY_SUPPORT, false },
187 { &m_pRespectDriverResultSetType, "resulttype", DSID_RESPECTRESULTSETTYPE, false }
190 for ( const BooleanSettingDesc& pCopy : aSettings )
192 m_aBooleanSettings.push_back( pCopy );
196 void SpecialSettingsPage::fillWindows( ::std::vector< ISaveValueWrapper* >& _rControlList )
198 if ( m_bHasBooleanComparisonMode )
200 _rControlList.push_back( new ODisableWrapper< FixedText >( m_pBooleanComparisonModeLabel ) );
202 if ( m_bHasMaxRowScan )
204 _rControlList.push_back( new ODisableWrapper< FixedText >( m_pMaxRowScanLabel ) );
208 void SpecialSettingsPage::fillControls(::std::vector< ISaveValueWrapper* >& _rControlList)
210 for ( BooleanSettingDescs::const_iterator setting = m_aBooleanSettings.begin();
211 setting != m_aBooleanSettings.end();
212 ++setting
215 if ( (*setting->ppControl) )
217 _rControlList.push_back( new OSaveValueWrapper< CheckBox >( *setting->ppControl ) );
221 if ( m_bHasBooleanComparisonMode )
222 _rControlList.push_back( new OSaveValueWrapper< ListBox >( m_pBooleanComparisonMode ) );
223 if ( m_bHasMaxRowScan )
224 _rControlList.push_back(new OSaveValueWrapper<NumericField>(m_pMaxRowScan));
227 void SpecialSettingsPage::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue)
229 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
230 bool bValid, bReadonly;
231 getFlags( _rSet, bValid, bReadonly );
233 if ( !bValid )
235 OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue);
236 return;
239 // the boolean items
240 for ( BooleanSettingDescs::const_iterator setting = m_aBooleanSettings.begin();
241 setting != m_aBooleanSettings.end();
242 ++setting
245 if ( !(*setting->ppControl) )
246 continue;
248 ::boost::optional< bool > aValue(false);
249 aValue.reset();
251 SFX_ITEMSET_GET( _rSet, pItem, SfxPoolItem, setting->nItemId, true );
252 if (const SfxBoolItem *pBoolItem = PTR_CAST(SfxBoolItem, pItem))
254 aValue.reset( pBoolItem->GetValue() );
256 else if (const OptionalBoolItem *pOptionalItem = PTR_CAST(OptionalBoolItem, pItem))
258 aValue = pOptionalItem->GetFullValue();
260 else
261 OSL_FAIL( "SpecialSettingsPage::implInitControls: unknown boolean item type!" );
263 if ( !aValue )
265 (*setting->ppControl)->SetState( TRISTATE_INDET );
267 else
269 bool bValue = *aValue;
270 if ( setting->bInvertedDisplay )
271 bValue = !bValue;
272 (*setting->ppControl)->Check( bValue );
276 // the non-boolean items
277 if ( m_bHasBooleanComparisonMode )
279 SFX_ITEMSET_GET( _rSet, pBooleanComparison, SfxInt32Item, DSID_BOOLEANCOMPARISON, true );
280 m_pBooleanComparisonMode->SelectEntryPos( static_cast< sal_uInt16 >( pBooleanComparison->GetValue() ) );
283 if ( m_bHasMaxRowScan )
285 SFX_ITEMSET_GET(_rSet, pMaxRowScan, SfxInt32Item, DSID_MAX_ROW_SCAN, true);
286 m_pMaxRowScan->SetValue(pMaxRowScan->GetValue());
289 OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue);
292 bool SpecialSettingsPage::FillItemSet( SfxItemSet* _rSet )
294 bool bChangedSomething = false;
296 // the boolean items
297 for ( BooleanSettingDescs::const_iterator setting = m_aBooleanSettings.begin();
298 setting != m_aBooleanSettings.end();
299 ++setting
302 if ( !*setting->ppControl )
303 continue;
304 fillBool( *_rSet, *setting->ppControl, setting->nItemId, bChangedSomething, setting->bInvertedDisplay );
307 // the non-boolean items
308 if ( m_bHasBooleanComparisonMode )
310 if ( m_pBooleanComparisonMode->IsValueChangedFromSaved() )
312 _rSet->Put( SfxInt32Item( DSID_BOOLEANCOMPARISON, m_pBooleanComparisonMode->GetSelectEntryPos() ) );
313 bChangedSomething = true;
316 if ( m_bHasMaxRowScan )
318 fillInt32(*_rSet,m_pMaxRowScan,DSID_MAX_ROW_SCAN,bChangedSomething);
320 return bChangedSomething;
323 // GeneratedValuesPage
324 GeneratedValuesPage::GeneratedValuesPage( vcl::Window* pParent, const SfxItemSet& _rCoreAttrs )
325 : OGenericAdministrationPage(pParent, "GeneratedValuesPage",
326 "dbaccess/ui/generatedvaluespage.ui", _rCoreAttrs)
328 get(m_pAutoFrame, "GeneratedValuesPage");
329 get(m_pAutoRetrievingEnabled, "autoretrieve");
330 get(m_pAutoIncrementLabel, "statementft");
331 get(m_pAutoIncrement, "statement");
332 get(m_pAutoRetrievingLabel, "queryft");
333 get(m_pAutoRetrieving, "query");
335 m_pAutoRetrievingEnabled->SetClickHdl( getControlModifiedLink() );
336 m_pAutoIncrement->SetModifyHdl( getControlModifiedLink() );
337 m_pAutoRetrieving->SetModifyHdl( getControlModifiedLink() );
339 m_aControlDependencies.enableOnCheckMark( *m_pAutoRetrievingEnabled,
340 *m_pAutoIncrementLabel, *m_pAutoIncrement, *m_pAutoRetrievingLabel, *m_pAutoRetrieving );
343 GeneratedValuesPage::~GeneratedValuesPage()
345 disposeOnce();
348 void GeneratedValuesPage::dispose()
350 m_aControlDependencies.clear();
351 m_pAutoFrame.clear();
352 m_pAutoRetrievingEnabled.clear();
353 m_pAutoIncrementLabel.clear();
354 m_pAutoIncrement.clear();
355 m_pAutoRetrievingLabel.clear();
356 m_pAutoRetrieving.clear();
357 OGenericAdministrationPage::dispose();
360 void GeneratedValuesPage::fillWindows( ::std::vector< ISaveValueWrapper* >& _rControlList )
362 _rControlList.push_back( new ODisableWrapper< VclFrame >( m_pAutoFrame ) );
365 void GeneratedValuesPage::fillControls( ::std::vector< ISaveValueWrapper* >& _rControlList )
367 _rControlList.push_back( new OSaveValueWrapper< CheckBox >( m_pAutoRetrievingEnabled ) );
368 _rControlList.push_back( new OSaveValueWrapper< Edit >( m_pAutoIncrement ) );
369 _rControlList.push_back( new OSaveValueWrapper< Edit >( m_pAutoRetrieving ) );
372 void GeneratedValuesPage::implInitControls( const SfxItemSet& _rSet, bool _bSaveValue )
374 // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
375 bool bValid, bReadonly;
376 getFlags(_rSet, bValid, bReadonly);
378 // collect the items
379 SFX_ITEMSET_GET(_rSet, pAutoIncrementItem, SfxStringItem, DSID_AUTOINCREMENTVALUE, true);
380 SFX_ITEMSET_GET(_rSet, pAutoRetrieveValueItem, SfxStringItem, DSID_AUTORETRIEVEVALUE, true);
381 SFX_ITEMSET_GET(_rSet, pAutoRetrieveEnabledItem, SfxBoolItem, DSID_AUTORETRIEVEENABLED, true);
383 // forward the values to the controls
384 if (bValid)
386 bool bEnabled = pAutoRetrieveEnabledItem->GetValue();
387 m_pAutoRetrievingEnabled->Check( bEnabled );
389 m_pAutoIncrement->SetText( pAutoIncrementItem->GetValue() );
390 m_pAutoIncrement->ClearModifyFlag();
391 m_pAutoRetrieving->SetText( pAutoRetrieveValueItem->GetValue() );
392 m_pAutoRetrieving->ClearModifyFlag();
394 OGenericAdministrationPage::implInitControls( _rSet, _bSaveValue );
397 bool GeneratedValuesPage::FillItemSet(SfxItemSet* _rSet)
399 bool bChangedSomething = false;
401 fillString( *_rSet, m_pAutoIncrement, DSID_AUTOINCREMENTVALUE, bChangedSomething );
402 fillBool( *_rSet, m_pAutoRetrievingEnabled, DSID_AUTORETRIEVEENABLED, bChangedSomething );
403 fillString( *_rSet, m_pAutoRetrieving, DSID_AUTORETRIEVEVALUE, bChangedSomething );
405 return bChangedSomething;
408 // AdvancedSettingsDialog
409 AdvancedSettingsDialog::AdvancedSettingsDialog( vcl::Window* _pParent, SfxItemSet* _pItems,
410 const Reference< XComponentContext >& _rxContext, const Any& _aDataSourceName )
411 : SfxTabDialog(_pParent, "AdvancedSettingsDialog",
412 "dbaccess/ui/advancedsettingsdialog.ui", _pItems)
414 m_pImpl.reset(new ODbDataSourceAdministrationHelper(_rxContext,_pParent,this));
415 m_pImpl->setDataSourceOrName(_aDataSourceName);
416 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
417 m_pImpl->translateProperties(xDatasource, *_pItems);
418 SetInputSet(_pItems);
419 // propagate this set as our new input set and reset the example set
420 delete pExampleSet;
421 pExampleSet = new SfxItemSet(*GetInputSetImpl());
423 const OUString eType = dbaui::ODbDataSourceAdministrationHelper::getDatasourceType(*_pItems);
425 DataSourceMetaData aMeta( eType );
426 const FeatureSet& rFeatures( aMeta.getFeatureSet() );
428 // auto-generated values?
429 if (rFeatures.supportsGeneratedValues())
430 AddTabPage("generated", ODriversSettings::CreateGeneratedValuesPage, NULL);
431 else
432 RemoveTabPage("generated");
434 // any "special settings"?
435 if (rFeatures.supportsAnySpecialSetting())
436 AddTabPage("special", ODriversSettings::CreateSpecialSettingsPage, NULL);
437 else
438 RemoveTabPage("special");
440 // remove the reset button - it's meaning is much too ambiguous in this dialog
441 RemoveResetButton();
444 AdvancedSettingsDialog::~AdvancedSettingsDialog()
446 disposeOnce();
449 void AdvancedSettingsDialog::dispose()
451 SetInputSet(NULL);
452 DELETEZ(pExampleSet);
453 SfxTabDialog::dispose();
456 bool AdvancedSettingsDialog::doesHaveAnyAdvancedSettings( const OUString& _sURL )
458 DataSourceMetaData aMeta( _sURL );
459 const FeatureSet& rFeatures( aMeta.getFeatureSet() );
460 if ( rFeatures.supportsGeneratedValues() || rFeatures.supportsAnySpecialSetting() )
461 return true;
462 return false;
465 short AdvancedSettingsDialog::Execute()
467 short nRet = SfxTabDialog::Execute();
468 if ( nRet == RET_OK )
470 pExampleSet->Put(*GetOutputItemSet());
471 m_pImpl->saveChanges(*pExampleSet);
473 return nRet;
476 void AdvancedSettingsDialog::PageCreated(sal_uInt16 _nId, SfxTabPage& _rPage)
478 // register ourself as modified listener
479 static_cast<OGenericAdministrationPage&>(_rPage).SetServiceFactory( getORB() );
480 static_cast<OGenericAdministrationPage&>(_rPage).SetAdminDialog(this,this);
482 vcl::Window *pWin = GetViewWindow();
483 if(pWin)
484 pWin->Invalidate();
486 SfxTabDialog::PageCreated(_nId, _rPage);
489 const SfxItemSet* AdvancedSettingsDialog::getOutputSet() const
491 return pExampleSet;
494 SfxItemSet* AdvancedSettingsDialog::getWriteOutputSet()
496 return pExampleSet;
499 ::std::pair< Reference< XConnection >, sal_Bool > AdvancedSettingsDialog::createConnection()
501 return m_pImpl->createConnection();
504 Reference< XComponentContext > AdvancedSettingsDialog::getORB() const
506 return m_pImpl->getORB();
509 Reference< XDriver > AdvancedSettingsDialog::getDriver()
511 return m_pImpl->getDriver();
514 OUString AdvancedSettingsDialog::getDatasourceType(const SfxItemSet& _rSet) const
516 return dbaui::ODbDataSourceAdministrationHelper::getDatasourceType(_rSet);
519 void AdvancedSettingsDialog::clearPassword()
521 m_pImpl->clearPassword();
524 void AdvancedSettingsDialog::setTitle(const OUString& _sTitle)
526 SetText(_sTitle);
529 void AdvancedSettingsDialog::enableConfirmSettings( bool _bEnable )
531 (void)_bEnable;
534 bool AdvancedSettingsDialog::saveDatasource()
536 return PrepareLeaveCurrentPage();
539 } // namespace dbaui
541 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */