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