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 "admincontrols.hxx"
22 : : #include "admincontrols.hrc"
23 : : #include "dbu_dlg.hrc"
24 : : #include "dsitems.hxx"
25 : : #include "moduledbu.hxx"
26 : :
27 : : #include <svl/eitem.hxx>
28 : : #include <svl/stritem.hxx>
29 : : #include <svl/intitem.hxx>
30 : :
31 : : //........................................................................
32 : : namespace dbaui
33 : : {
34 : : //........................................................................
35 : :
36 : : //====================================================================
37 : : //= TextResetOperatorEventFilter
38 : : //====================================================================
39 [ # # ]: 0 : class TextResetOperatorEventFilter : public ::svt::IWindowEventFilter
40 : : {
41 : : public:
42 : 0 : TextResetOperatorEventFilter()
43 : 0 : {
44 : 0 : }
45 : :
46 : : // IWindowEventFilter
47 : 0 : virtual bool payAttentionTo( const VclWindowEvent& _rEvent ) const
48 : : {
49 : 0 : return ( _rEvent.GetId() == VCLEVENT_WINDOW_ENABLED )
50 : 0 : || ( _rEvent.GetId() == VCLEVENT_WINDOW_DISABLED )
51 [ # # ]: 0 : || ( _rEvent.GetId() == VCLEVENT_EDIT_MODIFY );
[ # # # # ]
52 : : }
53 : : };
54 : :
55 : : //====================================================================
56 : : //= TextResetOperator
57 : : //====================================================================
58 [ # # ][ # # ]: 0 : class TextResetOperator :public ::svt::IWindowOperator
[ # # ]
59 : : {
60 : : public:
61 : 0 : TextResetOperator( const String& _rDisabledText )
62 [ # # ][ # # ]: 0 : :m_sDisabledText( _rDisabledText )
63 : : {
64 : 0 : }
65 : :
66 : : // IWindowOperator
67 : : virtual void operateOn( const VclWindowEvent& _rTrigger, Window& _rOperateOn ) const;
68 : :
69 : : private:
70 : : const String m_sDisabledText;
71 : : String m_sUserText;
72 : : sal_Bool m_bLastKnownEnabledState;
73 : : };
74 : :
75 : : //--------------------------------------------------------------------
76 : 0 : void TextResetOperator::operateOn( const VclWindowEvent& _rTrigger, Window& _rOperateOn ) const
77 : : {
78 : : OSL_ENSURE( _rTrigger.GetWindow() == &_rOperateOn, "TextResetOperator::operateOn: you're misusing this implementation!" );
79 : :
80 [ # # # # : 0 : switch ( _rTrigger.GetId() )
# ]
81 : : {
82 : : case 0:
83 : : // initial call
84 [ # # ]: 0 : const_cast< TextResetOperator* >( this )->m_sUserText = _rTrigger.GetWindow()->GetText();
85 : 0 : break;
86 : :
87 : : case VCLEVENT_EDIT_MODIFY:
88 [ # # ]: 0 : if ( _rTrigger.GetWindow()->IsEnabled() )
89 [ # # ]: 0 : const_cast< TextResetOperator* >( this )->m_sUserText = _rTrigger.GetWindow()->GetText();
90 : 0 : break;
91 : :
92 : : case VCLEVENT_WINDOW_ENABLED:
93 : 0 : _rOperateOn.SetText( m_sUserText );
94 : 0 : break;
95 : :
96 : : case VCLEVENT_WINDOW_DISABLED:
97 : 0 : _rOperateOn.SetText( m_sDisabledText );
98 : 0 : break;
99 : :
100 : : default:
101 : : OSL_FAIL( "TextResetOperator::operateOn: unexpected event ID!" );
102 : : // all those IDs should have been filtered out by payAttentionTo
103 : 0 : break;
104 : : }
105 : 0 : }
106 : :
107 : : //====================================================================
108 : : //= TextResetOperatorController
109 : : //====================================================================
110 [ # # ]: 0 : class TextResetOperatorController_Base
111 : : {
112 : : protected:
113 : 0 : TextResetOperatorController_Base( const String& _rDisabledText )
114 [ # # ]: 0 : :m_pEventFilter( new TextResetOperatorEventFilter )
115 [ # # ][ # # ]: 0 : ,m_pOperator( new TextResetOperator( _rDisabledText ) )
[ # # ]
116 : : {
117 : 0 : }
118 : :
119 : 0 : inline ::svt::PWindowEventFilter getEventFilter() const { return m_pEventFilter; }
120 : 0 : inline ::svt::PWindowOperator getOperator() const { return m_pOperator; }
121 : :
122 : : private:
123 : : ::svt::PWindowEventFilter m_pEventFilter;
124 : : ::svt::PWindowOperator m_pOperator;
125 : : };
126 : :
127 [ # # ][ # # ]: 0 : class TextResetOperatorController :public TextResetOperatorController_Base
128 : : ,public ::svt::DialogController
129 : : {
130 : : public:
131 : 0 : TextResetOperatorController( Window& _rObservee, const String& _rDisabledText )
132 : : :TextResetOperatorController_Base( _rDisabledText )
133 [ # # ][ # # ]: 0 : ,::svt::DialogController( _rObservee, getEventFilter(), getOperator() )
[ # # ][ # # ]
[ # # ]
134 : : {
135 [ # # ]: 0 : addDependentWindow( _rObservee );
136 : 0 : }
137 : : };
138 : :
139 : : //====================================================================
140 : : //= MySQLNativeSettings
141 : : //====================================================================
142 : : //--------------------------------------------------------------------
143 : 0 : MySQLNativeSettings::MySQLNativeSettings( Window& _rParent, const Link& _rControlModificationLink )
144 : 0 : :Control( &_rParent, ModuleRes( RID_MYSQL_NATIVE_SETTINGS ).SetAutoRelease( sal_False ) )
145 : : ,m_aDatabaseNameLabel ( this, ModuleRes( FT_MYSQL_DATABASE_NAME ) )
146 : : ,m_aDatabaseName ( this, ModuleRes( ED_MYSQL_DATABASE_NAME ) )
147 : : ,m_aHostPortRadio ( this, ModuleRes( RB_MYSQL_HOST_PORT ) )
148 : : ,m_aSocketRadio ( this, ModuleRes( RB_MYSQL_SOCKET ) )
149 : : ,m_aNamedPipeRadio ( this, ModuleRes( RB_MYSQL_NAMED_PIPE ) )
150 : : ,m_aHostNameLabel ( this, ModuleRes( FT_COMMON_HOST_NAME ) )
151 : : ,m_aHostName ( this, ModuleRes( ED_COMMON_HOST_NAME ) )
152 : : ,m_aPortLabel ( this, ModuleRes( FT_COMMON_PORT ) )
153 : : ,m_aPort ( this, ModuleRes( NF_COMMON_PORT ) )
154 : : ,m_aDefaultPort ( this, ModuleRes( FT_COMMON_PORT_DEFAULT ) )
155 : : ,m_aSocket ( this, ModuleRes( ED_MYSQL_SOCKET ) )
156 [ # # ][ # # ]: 0 : ,m_aNamedPipe ( this, ModuleRes( ED_MYSQL_NAMED_PIPE ) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
157 : : {
158 [ # # ]: 0 : FreeResource();
159 : :
160 : 0 : m_aDatabaseName.SetModifyHdl( _rControlModificationLink );
161 : 0 : m_aHostName.SetModifyHdl( _rControlModificationLink );
162 : 0 : m_aPort.SetModifyHdl( _rControlModificationLink );
163 : 0 : m_aNamedPipe.SetModifyHdl( _rControlModificationLink );
164 : 0 : m_aSocketRadio.SetToggleHdl( _rControlModificationLink );
165 : 0 : m_aNamedPipeRadio.SetToggleHdl( _rControlModificationLink );
166 : :
167 [ # # ]: 0 : m_aControlDependencies.enableOnRadioCheck( m_aHostPortRadio, m_aHostNameLabel, m_aHostName, m_aPortLabel, m_aPort, m_aDefaultPort );
168 [ # # ]: 0 : m_aControlDependencies.enableOnRadioCheck( m_aSocketRadio, m_aSocket );
169 [ # # ]: 0 : m_aControlDependencies.enableOnRadioCheck( m_aNamedPipeRadio, m_aNamedPipe );
170 : :
171 : : m_aControlDependencies.addController( ::svt::PDialogController(
172 [ # # ]: 0 : new TextResetOperatorController( m_aHostName, rtl::OUString("localhost") )
173 [ # # ][ # # ]: 0 : ) );
[ # # ][ # # ]
[ # # ][ # # ]
174 : :
175 : : // sockets are available on Unix systems only, named pipes only on Windows
176 : : #ifdef UNX
177 [ # # ]: 0 : m_aNamedPipeRadio.Hide();
178 [ # # ]: 0 : m_aNamedPipe.Hide();
179 : : #else
180 : : m_aSocketRadio.Hide();
181 : : m_aSocket.Hide();
182 : : #endif
183 : 0 : }
184 : :
185 : : //--------------------------------------------------------------------
186 [ # # ][ # # ]: 0 : MySQLNativeSettings::~MySQLNativeSettings()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
187 : : {
188 [ # # ]: 0 : }
189 : :
190 : : //--------------------------------------------------------------------
191 : 0 : void MySQLNativeSettings::fillControls( ::std::vector< ISaveValueWrapper* >& _rControlList )
192 : : {
193 [ # # ][ # # ]: 0 : _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aDatabaseName ) );
194 [ # # ][ # # ]: 0 : _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aHostName ) );
195 [ # # ][ # # ]: 0 : _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aPort ) );
196 [ # # ][ # # ]: 0 : _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aSocket ) );
197 [ # # ][ # # ]: 0 : _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aNamedPipe ) );
198 : 0 : }
199 : :
200 : : //--------------------------------------------------------------------
201 : 0 : void MySQLNativeSettings::fillWindows( ::std::vector< ISaveValueWrapper* >& _rControlList )
202 : : {
203 [ # # ][ # # ]: 0 : _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aDatabaseNameLabel ) );
204 [ # # ][ # # ]: 0 : _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aHostNameLabel ) );
205 [ # # ][ # # ]: 0 : _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aPortLabel ) );
206 [ # # ][ # # ]: 0 : _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aDefaultPort ) );
207 [ # # ][ # # ]: 0 : _rControlList.push_back( new ODisableWrapper< RadioButton >( &m_aSocketRadio ) );
208 [ # # ][ # # ]: 0 : _rControlList.push_back( new ODisableWrapper< RadioButton >( &m_aNamedPipeRadio ) );
209 : 0 : }
210 : :
211 : : //--------------------------------------------------------------------
212 : 0 : sal_Bool MySQLNativeSettings::FillItemSet( SfxItemSet& _rSet )
213 : : {
214 : 0 : sal_Bool bChangedSomething = sal_False;
215 : :
216 [ # # ]: 0 : OGenericAdministrationPage::fillString( _rSet, &m_aHostName, DSID_CONN_HOSTNAME, bChangedSomething );
217 [ # # ]: 0 : OGenericAdministrationPage::fillString( _rSet, &m_aDatabaseName, DSID_DATABASENAME, bChangedSomething );
218 [ # # ]: 0 : OGenericAdministrationPage::fillInt32 ( _rSet, &m_aPort, DSID_MYSQL_PORTNUMBER, bChangedSomething );
219 : : #ifdef UNX
220 [ # # ]: 0 : OGenericAdministrationPage::fillString( _rSet, &m_aSocket, DSID_CONN_SOCKET, bChangedSomething );
221 : : #else
222 : : OGenericAdministrationPage::fillString( _rSet, &m_aNamedPipe, DSID_NAMED_PIPE, bChangedSomething );
223 : : #endif
224 : :
225 : 0 : return bChangedSomething;
226 : : }
227 : :
228 : : //--------------------------------------------------------------------
229 : 0 : void MySQLNativeSettings::implInitControls(const SfxItemSet& _rSet )
230 : : {
231 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET( _rSet, pInvalid, SfxBoolItem, DSID_INVALID_SELECTION, sal_True );
232 [ # # ][ # # ]: 0 : bool bValid = !pInvalid || !pInvalid->GetValue();
233 [ # # ]: 0 : if ( !bValid )
234 : 0 : return;
235 : :
236 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET( _rSet, pDatabaseName, SfxStringItem, DSID_DATABASENAME, sal_True );
237 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET( _rSet, pHostName, SfxStringItem, DSID_CONN_HOSTNAME, sal_True );
238 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET( _rSet, pPortNumber, SfxInt32Item, DSID_MYSQL_PORTNUMBER, sal_True );
239 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET( _rSet, pSocket, SfxStringItem, DSID_CONN_SOCKET, sal_True );
240 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET( _rSet, pNamedPipe, SfxStringItem, DSID_NAMED_PIPE, sal_True );
241 : :
242 [ # # ]: 0 : m_aDatabaseName.SetText( pDatabaseName->GetValue() );
243 [ # # ]: 0 : m_aDatabaseName.ClearModifyFlag();
244 : :
245 [ # # ]: 0 : m_aHostName.SetText( pHostName->GetValue() );
246 [ # # ]: 0 : m_aHostName.ClearModifyFlag();
247 : :
248 [ # # ]: 0 : m_aPort.SetValue( pPortNumber->GetValue() );
249 [ # # ]: 0 : m_aPort.ClearModifyFlag();
250 : :
251 [ # # ]: 0 : m_aSocket.SetText( pSocket->GetValue() );
252 [ # # ]: 0 : m_aSocket.ClearModifyFlag();
253 : :
254 [ # # ]: 0 : m_aNamedPipe.SetText( pNamedPipe->GetValue() );
255 [ # # ]: 0 : m_aNamedPipe.ClearModifyFlag();
256 : :
257 : : // if a socket (on Unix) or a pipe name (on Windows) is given, this is preferred over
258 : : // the port
259 : : #ifdef UNX
260 : 0 : RadioButton& rSocketPipeRadio = m_aSocketRadio;
261 : 0 : const SfxStringItem* pSocketPipeItem = pSocket;
262 : : #else
263 : : RadioButton& rSocketPipeRadio = m_aNamedPipeRadio;
264 : : const SfxStringItem* pSocketPipeItem = pNamedPipe;
265 : : #endif
266 [ # # ]: 0 : String sSocketPipe( pSocketPipeItem->GetValue() );
267 [ # # ]: 0 : if ( sSocketPipe.Len() > 0 )
268 [ # # ]: 0 : rSocketPipeRadio.Check();
269 : : else
270 [ # # ][ # # ]: 0 : m_aHostPortRadio.Check();
271 : : }
272 : :
273 : : //--------------------------------------------------------------------
274 : 0 : bool MySQLNativeSettings::canAdvance() const
275 : : {
276 [ # # ]: 0 : if ( m_aDatabaseName.GetText().Len() == 0 )
277 : 0 : return false;
278 : :
279 [ # # # # : 0 : if ( m_aHostPortRadio.IsChecked()
# # ][ # # ]
280 [ # # ][ # # ]: 0 : && ( ( m_aHostName.GetText().Len() == 0 )
[ # # ]
281 [ # # ][ # # ]: 0 : || ( m_aPort.GetText().Len() == 0 )
[ # # ][ # # ]
282 : : )
283 : : )
284 : 0 : return false;
285 : :
286 : : #ifdef UNX
287 [ # # # # ]: 0 : if ( ( m_aSocketRadio.IsChecked() )
[ # # ]
288 [ # # ][ # # ]: 0 : && ( m_aSocket.GetText().Len() == 0 )
[ # # ]
289 : : )
290 : : #else
291 : : if ( ( m_aNamedPipeRadio.IsChecked() )
292 : : && ( m_aNamedPipe.GetText().Len() == 0 )
293 : : )
294 : : #endif
295 : 0 : return false;
296 : :
297 : 0 : return true;
298 : : }
299 : :
300 : : //........................................................................
301 : : } // namespace dbaui
302 : : //........................................................................
303 : :
304 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|