Branch data 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 : :
21 : : #include "adminpages.hxx"
22 : : #include "dbadmin.hrc"
23 : : #include "dbadmin.hxx"
24 : : #include "dbu_dlg.hrc"
25 : : #include <svl/stritem.hxx>
26 : : #include <svl/eitem.hxx>
27 : : #include <svl/intitem.hxx>
28 : : #include "dbustrings.hrc"
29 : : #include "dsitems.hxx"
30 : : #include "dsselect.hxx"
31 : : #include "localresaccess.hxx"
32 : : #include "odbcconfig.hxx"
33 : : #include "optionalboolitem.hxx"
34 : : #include "sqlmessage.hxx"
35 : :
36 : : #include <osl/file.hxx>
37 : : #include <vcl/accel.hxx>
38 : : #include <vcl/button.hxx>
39 : : #include <vcl/edit.hxx>
40 : : #include <vcl/field.hxx>
41 : : #include <vcl/lstbox.hxx>
42 : : #include <vcl/msgbox.hxx>
43 : :
44 : : #include <algorithm>
45 : : #include <stdlib.h>
46 : :
47 : : //.........................................................................
48 : : namespace dbaui
49 : : {
50 : : //.........................................................................
51 : :
52 : : using namespace ::com::sun::star::uno;
53 : : using namespace ::com::sun::star::sdbc;
54 : : using namespace ::com::sun::star::beans;
55 : : using namespace ::com::sun::star::lang;
56 : : using namespace ::dbtools;
57 : : using namespace ::svt;
58 : :
59 : 0 : ISaveValueWrapper::~ISaveValueWrapper()
60 : : {
61 [ # # ]: 0 : }
62 : :
63 : : //=========================================================================
64 : : //= OGenericAdministrationPage
65 : : //=========================================================================
66 : : DBG_NAME(OGenericAdministrationPage)
67 : : //-------------------------------------------------------------------------
68 : 0 : OGenericAdministrationPage::OGenericAdministrationPage(Window* _pParent, const ResId& _rId, const SfxItemSet& _rAttrSet)
69 : : :SfxTabPage(_pParent, _rId, _rAttrSet)
70 : : ,m_abEnableRoadmap(sal_False)
71 : : ,m_pAdminDialog(NULL)
72 : : ,m_pItemSetHelper(NULL)
73 [ # # ]: 0 : ,m_pFT_HeaderText(NULL)
74 : : {
75 : : DBG_CTOR(OGenericAdministrationPage,NULL);
76 : :
77 : 0 : SetExchangeSupport(sal_True);
78 : 0 : }
79 : :
80 : : //-------------------------------------------------------------------------
81 : 0 : OGenericAdministrationPage::~OGenericAdministrationPage()
82 : : {
83 [ # # ][ # # ]: 0 : DELETEZ(m_pFT_HeaderText);
84 : :
85 : : DBG_DTOR(OGenericAdministrationPage,NULL);
86 [ # # ]: 0 : }
87 : :
88 : : //-------------------------------------------------------------------------
89 : 0 : int OGenericAdministrationPage::DeactivatePage(SfxItemSet* _pSet)
90 : : {
91 [ # # ]: 0 : if (_pSet)
92 : : {
93 [ # # ]: 0 : if (!prepareLeave())
94 : 0 : return KEEP_PAGE;
95 : 0 : FillItemSet(*_pSet);
96 : : }
97 : :
98 : 0 : return LEAVE_PAGE;
99 : : }
100 : :
101 : : //-------------------------------------------------------------------------
102 : 0 : void OGenericAdministrationPage::Reset(const SfxItemSet& _rCoreAttrs)
103 : : {
104 : 0 : implInitControls(_rCoreAttrs, sal_False);
105 : 0 : }
106 : : //-------------------------------------------------------------------------
107 : 0 : void OGenericAdministrationPage::ActivatePage()
108 : : {
109 : 0 : TabPage::ActivatePage();
110 : : OSL_ENSURE(m_pItemSetHelper,"NO ItemSetHelper set!");
111 [ # # ]: 0 : if ( m_pItemSetHelper )
112 : 0 : ActivatePage(*m_pItemSetHelper->getOutputSet());
113 : 0 : }
114 : : //-------------------------------------------------------------------------
115 : 0 : void OGenericAdministrationPage::ActivatePage(const SfxItemSet& _rSet)
116 : : {
117 : 0 : implInitControls(_rSet, sal_True);
118 : 0 : }
119 : :
120 : : // -----------------------------------------------------------------------
121 : 0 : void OGenericAdministrationPage::getFlags(const SfxItemSet& _rSet, sal_Bool& _rValid, sal_Bool& _rReadonly)
122 : : {
123 : 0 : SFX_ITEMSET_GET(_rSet, pInvalid, SfxBoolItem, DSID_INVALID_SELECTION, sal_True);
124 [ # # ][ # # ]: 0 : _rValid = !pInvalid || !pInvalid->GetValue();
125 : 0 : SFX_ITEMSET_GET(_rSet, pReadonly, SfxBoolItem, DSID_READONLY, sal_True);
126 [ # # ][ # # ]: 0 : _rReadonly = !_rValid || (pReadonly && pReadonly->GetValue());
[ # # ]
127 : 0 : }
128 : :
129 : :
130 : : // -----------------------------------------------------------------------
131 : 0 : IMPL_LINK_NOARG(OGenericAdministrationPage, OnControlModified)
132 : : {
133 : 0 : callModifiedHdl();
134 : 0 : return 0L;
135 : : }
136 : : // -----------------------------------------------------------------------
137 : 0 : sal_Bool OGenericAdministrationPage::getSelectedDataSource(::rtl::OUString& _sReturn,::rtl::OUString& _sCurr)
138 : : {
139 : : // collect all ODBC data source names
140 [ # # ]: 0 : StringBag aOdbcDatasources;
141 [ # # ]: 0 : OOdbcEnumeration aEnumeration;
142 [ # # ]: 0 : if (!aEnumeration.isLoaded())
143 : : {
144 : : // show an error message
145 [ # # ]: 0 : LocalResourceAccess aLocRes( PAGE_GENERAL, RSC_TABPAGE );
146 [ # # ][ # # ]: 0 : String sError(ModuleRes(STR_COULDNOTLOAD_ODBCLIB));
147 [ # # ][ # # ]: 0 : sError.SearchAndReplaceAscii("#lib#", aEnumeration.getLibraryName());
[ # # ]
148 [ # # ]: 0 : ErrorBox aDialog(this, WB_OK, sError);
149 [ # # ]: 0 : aDialog.Execute();
150 [ # # ][ # # ]: 0 : return sal_False;
[ # # ]
151 : : }
152 : : else
153 : : {
154 [ # # ]: 0 : aEnumeration.getDatasourceNames(aOdbcDatasources);
155 : : // execute the select dialog
156 [ # # ][ # # ]: 0 : ODatasourceSelectDialog aSelector(GetParent(), aOdbcDatasources);
157 [ # # ]: 0 : if (!_sCurr.isEmpty())
158 [ # # ][ # # ]: 0 : aSelector.Select(_sCurr);
[ # # ]
159 [ # # ][ # # ]: 0 : if ( RET_OK == aSelector.Execute() )
160 [ # # ][ # # ]: 0 : _sReturn = aSelector.GetSelected();
[ # # ][ # # ]
161 : : }
162 [ # # ]: 0 : return sal_True;
163 : : }
164 : :
165 : : // -----------------------------------------------------------------------
166 : 0 : void OGenericAdministrationPage::implInitControls(const SfxItemSet& _rSet, sal_Bool _bSaveValue)
167 : : {
168 : : // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa)
169 : : sal_Bool bValid, bReadonly;
170 [ # # ]: 0 : getFlags(_rSet, bValid, bReadonly);
171 : :
172 [ # # ]: 0 : ::std::vector< ISaveValueWrapper* > aControlList;
173 [ # # ]: 0 : if ( _bSaveValue )
174 : : {
175 [ # # ]: 0 : fillControls(aControlList);
176 [ # # ]: 0 : ::std::for_each(aControlList.begin(),aControlList.end(),TSaveValueWrapperFunctor());
177 : : }
178 : :
179 [ # # ]: 0 : if ( bReadonly )
180 : : {
181 [ # # ]: 0 : fillWindows(aControlList);
182 [ # # ]: 0 : ::std::for_each(aControlList.begin(),aControlList.end(),TDisableWrapperFunctor());
183 : : }
184 : :
185 [ # # ]: 0 : ::std::for_each(aControlList.begin(),aControlList.end(),TDeleteWrapperFunctor());
186 : 0 : aControlList.clear();
187 : 0 : }
188 : :
189 : : // -----------------------------------------------------------------------
190 : 0 : void OGenericAdministrationPage::initializePage()
191 : : {
192 : : OSL_ENSURE(m_pItemSetHelper,"NO ItemSetHelper set!");
193 [ # # ]: 0 : if ( m_pItemSetHelper )
194 : 0 : Reset(*m_pItemSetHelper->getOutputSet());
195 : 0 : }
196 : : // -----------------------------------------------------------------------
197 : 0 : sal_Bool OGenericAdministrationPage::commitPage( ::svt::WizardTypes::CommitPageReason )
198 : : {
199 : 0 : return sal_True;
200 : : }
201 : : // -----------------------------------------------------------------------
202 : 0 : bool OGenericAdministrationPage::canAdvance() const
203 : : {
204 : 0 : return true;
205 : : }
206 : : // -----------------------------------------------------------------------
207 : 0 : void OGenericAdministrationPage::fillBool( SfxItemSet& _rSet, CheckBox* _pCheckBox, sal_uInt16 _nID, sal_Bool& _bChangedSomething, bool _bRevertValue )
208 : : {
209 [ # # ][ # # ]: 0 : if ( (_pCheckBox != NULL ) && ( _pCheckBox->GetState() != _pCheckBox->GetSavedValue() ) )
[ # # ]
210 : : {
211 : 0 : sal_Bool bValue = _pCheckBox->IsChecked();
212 [ # # ]: 0 : if ( _bRevertValue )
213 : 0 : bValue = !bValue;
214 : :
215 [ # # ]: 0 : if ( _pCheckBox->IsTriStateEnabled() )
216 : : {
217 [ # # ]: 0 : OptionalBoolItem aValue( _nID );
218 [ # # ]: 0 : if ( _pCheckBox->GetState() != STATE_DONTKNOW )
219 [ # # ]: 0 : aValue.SetValue( bValue );
220 [ # # ][ # # ]: 0 : _rSet.Put( aValue );
221 : : }
222 : : else
223 [ # # ]: 0 : _rSet.Put( SfxBoolItem( _nID, bValue ) );
224 : :
225 : 0 : _bChangedSomething = sal_True;
226 : : }
227 : 0 : }
228 : : // -----------------------------------------------------------------------
229 : 0 : void OGenericAdministrationPage::fillInt32(SfxItemSet& _rSet,NumericField* _pEdit,sal_uInt16 _nID,sal_Bool& _bChangedSomething)
230 : : {
231 [ # # ][ # # ]: 0 : if( (_pEdit != NULL) && (_pEdit->GetValue() != _pEdit->GetSavedValue().ToInt32()) )
[ # # ]
232 : : {
233 [ # # ]: 0 : _rSet.Put(SfxInt32Item(_nID, static_cast<sal_Int32>(_pEdit->GetValue())));
234 : 0 : _bChangedSomething = sal_True;
235 : : }
236 : 0 : }
237 : : // -----------------------------------------------------------------------
238 : 0 : void OGenericAdministrationPage::fillString(SfxItemSet& _rSet,Edit* _pEdit,sal_uInt16 _nID,sal_Bool& _bChangedSomething)
239 : : {
240 [ # # ][ # # ]: 0 : if( (_pEdit != NULL) && (_pEdit->GetText() != _pEdit->GetSavedValue()) )
[ # # ][ # # ]
[ # # ]
[ # # # # ]
241 : : {
242 [ # # ][ # # ]: 0 : _rSet.Put(SfxStringItem(_nID, _pEdit->GetText()));
[ # # ]
243 : 0 : _bChangedSomething = sal_True;
244 : : }
245 : 0 : }
246 : :
247 : 0 : void OGenericAdministrationPage::SetControlFontWeight(Window* _pWindow, FontWeight _eWeight)
248 : : {
249 [ # # ]: 0 : Font aFont = _pWindow->GetControlFont();
250 [ # # ]: 0 : aFont.SetWeight( _eWeight );
251 [ # # ][ # # ]: 0 : _pWindow->SetControlFont( aFont );
252 : 0 : }
253 : :
254 : : // -----------------------------------------------------------------------
255 : 0 : IMPL_LINK(OGenericAdministrationPage, OnTestConnectionClickHdl, PushButton*, /*_pButton*/)
256 : : {
257 : : OSL_ENSURE(m_pAdminDialog,"No Admin dialog set! ->GPF");
258 : 0 : sal_Bool bSuccess = sal_False;
259 [ # # ]: 0 : if ( m_pAdminDialog )
260 : : {
261 : 0 : m_pAdminDialog->saveDatasource();
262 : 0 : OGenericAdministrationPage::implInitControls(*m_pItemSetHelper->getOutputSet(), sal_True);
263 : 0 : sal_Bool bShowMessage = sal_True;
264 : : try
265 : : {
266 [ # # ]: 0 : ::std::pair< Reference<XConnection>,sal_Bool> xConnection = m_pAdminDialog->createConnection();
267 : 0 : bShowMessage = xConnection.second;
268 : 0 : bSuccess = xConnection.first.is();
269 [ # # ][ # # ]: 0 : ::comphelper::disposeComponent(xConnection.first);
[ # # ]
270 : : }
271 : 0 : catch(Exception&)
272 : : {
273 : : }
274 [ # # ]: 0 : if ( bShowMessage )
275 : : {
276 : 0 : OSQLMessageBox::MessageType eImage = OSQLMessageBox::Info;
277 [ # # ][ # # ]: 0 : String aMessage,sTitle;
278 [ # # ][ # # ]: 0 : sTitle = String (ModuleRes(STR_CONNECTION_TEST));
[ # # ][ # # ]
279 [ # # ]: 0 : if ( bSuccess )
280 : : {
281 [ # # ][ # # ]: 0 : aMessage = String(ModuleRes(STR_CONNECTION_SUCCESS));
[ # # ][ # # ]
282 : : }
283 : : else
284 : : {
285 : 0 : eImage = OSQLMessageBox::Error;
286 [ # # ][ # # ]: 0 : aMessage = String(ModuleRes(STR_CONNECTION_NO_SUCCESS));
[ # # ][ # # ]
287 : : }
288 [ # # ]: 0 : OSQLMessageBox aMsg( this, sTitle, aMessage, WB_OK, eImage );
289 [ # # ][ # # ]: 0 : aMsg.Execute();
[ # # ][ # # ]
290 : : }
291 [ # # ]: 0 : if ( !bSuccess )
292 : 0 : m_pAdminDialog->clearPassword();
293 : : }
294 : 0 : return 0L;
295 : : }
296 : :
297 : 0 : void OGenericAdministrationPage::SetHeaderText( sal_uInt16 _nFTResId, sal_uInt16 _StringResId)
298 : : {
299 [ # # ][ # # ]: 0 : delete(m_pFT_HeaderText);
300 [ # # ][ # # ]: 0 : m_pFT_HeaderText = new FixedText(this, ModuleRes(_nFTResId));
[ # # ]
301 [ # # ][ # # ]: 0 : String sHeaderText = String(ModuleRes(_StringResId));
302 [ # # ]: 0 : m_pFT_HeaderText->SetText(sHeaderText);
303 [ # # ][ # # ]: 0 : SetControlFontWeight(m_pFT_HeaderText);
304 : 0 : }
305 : :
306 : : //=========================================================================
307 : : //= LayoutHelper
308 : : //=========================================================================
309 : : //-------------------------------------------------------------------------
310 : 0 : void LayoutHelper::positionBelow( const Control& _rReference, Control& _rControl, const ControlRelation _eRelation,
311 : : const long _nIndentAppFont )
312 : : {
313 [ # # ]: 0 : Point aReference = _rReference.GetPosPixel();
314 [ # # ]: 0 : aReference.Y() += _rReference.GetSizePixel().Height();
315 : :
316 [ # # ]: 0 : const Window* pConverter = _rControl.GetParent();
317 [ # # ][ # # ]: 0 : Size aOffset = pConverter->LogicToPixel( Size( _nIndentAppFont, ( _eRelation == RelatedControls ? 3 : 6 ) ), MAP_APPFONT );
[ # # ][ # # ]
318 : :
319 : 0 : Point aControlPos( aReference.X() + aOffset.Width(), aReference.Y() + aOffset.Height() );
320 [ # # ]: 0 : _rControl.SetPosPixel( aControlPos );
321 : 0 : }
322 : :
323 : : //-------------------------------------------------------------------------
324 : 0 : void LayoutHelper::fitSizeRightAligned( PushButton& io_button )
325 : : {
326 [ # # ]: 0 : const Point aOldPos = io_button.GetPosPixel();
327 [ # # ]: 0 : const Size aOldSize = io_button.GetSizePixel();
328 [ # # ]: 0 : const Size aMinSize( io_button.CalcMinimumSize() );
329 [ # # ]: 0 : if ( aMinSize.Width() > aOldSize.Width() )
330 : : {
331 : : io_button.SetPosSizePixel(
332 : 0 : aOldPos.X() + aOldSize.Width() - aMinSize.Width(),
333 : : 0,
334 : : aMinSize.Width(),
335 : : 0,
336 : : WINDOW_POSSIZE_X | WINDOW_POSSIZE_WIDTH
337 [ # # ]: 0 : );
338 : : }
339 : 0 : }
340 : :
341 : : //.........................................................................
342 : : } // namespace dbaui
343 : : //.........................................................................
344 : :
345 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|