1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "admincontrols.hxx"
21 #include "dbu_dlg.hrc"
22 #include "dsitems.hxx"
23 #include "moduledbu.hxx"
25 #include <svl/eitem.hxx>
26 #include <svl/stritem.hxx>
27 #include <svl/intitem.hxx>
32 // TextResetOperatorEventFilter
33 class TextResetOperatorEventFilter
: public ::svt::IWindowEventFilter
36 TextResetOperatorEventFilter()
41 virtual bool payAttentionTo( const VclWindowEvent
& _rEvent
) const SAL_OVERRIDE
43 return ( _rEvent
.GetId() == VCLEVENT_WINDOW_ENABLED
)
44 || ( _rEvent
.GetId() == VCLEVENT_WINDOW_DISABLED
)
45 || ( _rEvent
.GetId() == VCLEVENT_EDIT_MODIFY
);
50 class TextResetOperator
:public ::svt::IWindowOperator
53 TextResetOperator( const OUString
& _rDisabledText
)
54 :m_sDisabledText( _rDisabledText
)
59 virtual void operateOn( const VclWindowEvent
& _rTrigger
, vcl::Window
& _rOperateOn
) const SAL_OVERRIDE
;
62 const OUString m_sDisabledText
;
66 void TextResetOperator::operateOn( const VclWindowEvent
& _rTrigger
, vcl::Window
& _rOperateOn
) const
68 OSL_ENSURE( _rTrigger
.GetWindow() == &_rOperateOn
, "TextResetOperator::operateOn: you're misusing this implementation!" );
70 switch ( _rTrigger
.GetId() )
74 const_cast< TextResetOperator
* >( this )->m_sUserText
= _rTrigger
.GetWindow()->GetText();
77 case VCLEVENT_EDIT_MODIFY
:
78 if ( _rTrigger
.GetWindow()->IsEnabled() )
79 const_cast< TextResetOperator
* >( this )->m_sUserText
= _rTrigger
.GetWindow()->GetText();
82 case VCLEVENT_WINDOW_ENABLED
:
83 _rOperateOn
.SetText( m_sUserText
);
86 case VCLEVENT_WINDOW_DISABLED
:
87 _rOperateOn
.SetText( m_sDisabledText
);
91 OSL_FAIL( "TextResetOperator::operateOn: unexpected event ID!" );
92 // all those IDs should have been filtered out by payAttentionTo
97 // TextResetOperatorController
98 class TextResetOperatorController_Base
101 TextResetOperatorController_Base( const OUString
& _rDisabledText
)
102 :m_pEventFilter( new TextResetOperatorEventFilter
)
103 ,m_pOperator( new TextResetOperator( _rDisabledText
) )
107 inline ::svt::PWindowEventFilter
getEventFilter() const { return m_pEventFilter
; }
108 inline ::svt::PWindowOperator
getOperator() const { return m_pOperator
; }
111 ::svt::PWindowEventFilter m_pEventFilter
;
112 ::svt::PWindowOperator m_pOperator
;
115 class TextResetOperatorController
:public TextResetOperatorController_Base
116 ,public ::svt::DialogController
119 TextResetOperatorController( vcl::Window
& _rObservee
, const OUString
& _rDisabledText
)
120 :TextResetOperatorController_Base( _rDisabledText
)
121 ,::svt::DialogController( _rObservee
, getEventFilter(), getOperator() )
123 addDependentWindow( _rObservee
);
127 // MySQLNativeSettings
128 MySQLNativeSettings::MySQLNativeSettings( vcl::Window
& _rParent
, const Link
<>& _rControlModificationLink
)
129 :TabPage( &_rParent
, "MysqlNativeSettings", "dbaccess/ui/mysqlnativesettings.ui" )
131 get(m_pDatabaseNameLabel
, "dbnamelabel");
132 get(m_pDatabaseName
, "dbname");
133 get(m_pHostPortRadio
, "hostport");
134 get(m_pSocketRadio
, "socketlabel");
135 get(m_pNamedPipeRadio
, "namedpipelabel");
136 get(m_pHostNameLabel
, "serverlabel");
137 get(m_pHostName
, "server");
138 get(m_pPortLabel
, "portlabel");
139 get(m_pPort
, "port");
140 m_pPort
->SetUseThousandSep(false);
141 get(m_pDefaultPort
, "defaultport");
142 get(m_pSocket
, "socket");
143 get(m_pNamedPipe
, "namedpipe");
145 m_pDatabaseName
->SetModifyHdl( _rControlModificationLink
);
146 m_pHostName
->SetModifyHdl( _rControlModificationLink
);
147 m_pPort
->SetModifyHdl( _rControlModificationLink
);
148 m_pSocket
->SetModifyHdl( _rControlModificationLink
);
149 m_pNamedPipe
->SetModifyHdl( _rControlModificationLink
);
150 m_pSocketRadio
->SetToggleHdl( _rControlModificationLink
);
151 m_pNamedPipeRadio
->SetToggleHdl( _rControlModificationLink
);
153 m_aControlDependencies
.enableOnRadioCheck( *m_pHostPortRadio
, *m_pHostNameLabel
, *m_pHostName
, *m_pPortLabel
, *m_pPort
, *m_pDefaultPort
);
154 m_aControlDependencies
.enableOnRadioCheck( *m_pSocketRadio
, *m_pSocket
);
155 m_aControlDependencies
.enableOnRadioCheck( *m_pNamedPipeRadio
, *m_pNamedPipe
);
157 m_aControlDependencies
.addController( ::svt::PDialogController(
158 new TextResetOperatorController( *m_pHostName
, OUString("localhost") )
161 // sockets are available on Unix systems only, named pipes only on Windows
163 m_pNamedPipeRadio
->Hide();
164 m_pNamedPipe
->Hide();
166 m_pSocketRadio
->Hide();
171 MySQLNativeSettings::~MySQLNativeSettings()
176 void MySQLNativeSettings::dispose()
178 m_pDatabaseNameLabel
.clear();
179 m_pDatabaseName
.clear();
180 m_pHostPortRadio
.clear();
181 m_pSocketRadio
.clear();
182 m_pNamedPipeRadio
.clear();
183 m_pHostNameLabel
.clear();
185 m_pPortLabel
.clear();
187 m_pDefaultPort
.clear();
189 m_pNamedPipe
.clear();
193 void MySQLNativeSettings::fillControls( ::std::vector
< ISaveValueWrapper
* >& _rControlList
)
195 _rControlList
.push_back( new OSaveValueWrapper
< Edit
>( m_pDatabaseName
) );
196 _rControlList
.push_back( new OSaveValueWrapper
< Edit
>( m_pHostName
) );
197 _rControlList
.push_back( new OSaveValueWrapper
< Edit
>( m_pPort
) );
198 _rControlList
.push_back( new OSaveValueWrapper
< Edit
>( m_pSocket
) );
199 _rControlList
.push_back( new OSaveValueWrapper
< Edit
>( m_pNamedPipe
) );
202 void MySQLNativeSettings::fillWindows( ::std::vector
< ISaveValueWrapper
* >& _rControlList
)
204 _rControlList
.push_back( new ODisableWrapper
< FixedText
>( m_pDatabaseNameLabel
) );
205 _rControlList
.push_back( new ODisableWrapper
< FixedText
>( m_pHostNameLabel
) );
206 _rControlList
.push_back( new ODisableWrapper
< FixedText
>( m_pPortLabel
) );
207 _rControlList
.push_back( new ODisableWrapper
< FixedText
>( m_pDefaultPort
) );
208 _rControlList
.push_back( new ODisableWrapper
< RadioButton
>( m_pSocketRadio
) );
209 _rControlList
.push_back( new ODisableWrapper
< RadioButton
>( m_pNamedPipeRadio
) );
212 bool MySQLNativeSettings::FillItemSet( SfxItemSet
* _rSet
)
214 bool bChangedSomething
= false;
216 OGenericAdministrationPage::fillString( *_rSet
, m_pHostName
, DSID_CONN_HOSTNAME
, bChangedSomething
);
217 OGenericAdministrationPage::fillString( *_rSet
, m_pDatabaseName
, DSID_DATABASENAME
, bChangedSomething
);
218 OGenericAdministrationPage::fillInt32 ( *_rSet
, m_pPort
, DSID_MYSQL_PORTNUMBER
, bChangedSomething
);
220 OGenericAdministrationPage::fillString( *_rSet
, m_pSocket
, DSID_CONN_SOCKET
, bChangedSomething
);
222 OGenericAdministrationPage::fillString( *_rSet
, m_pNamedPipe
, DSID_NAMED_PIPE
, bChangedSomething
);
225 return bChangedSomething
;
228 void MySQLNativeSettings::implInitControls(const SfxItemSet
& _rSet
)
230 SFX_ITEMSET_GET( _rSet
, pInvalid
, SfxBoolItem
, DSID_INVALID_SELECTION
, true );
231 bool bValid
= !pInvalid
|| !pInvalid
->GetValue();
235 SFX_ITEMSET_GET( _rSet
, pDatabaseName
, SfxStringItem
, DSID_DATABASENAME
, true );
236 SFX_ITEMSET_GET( _rSet
, pHostName
, SfxStringItem
, DSID_CONN_HOSTNAME
, true );
237 SFX_ITEMSET_GET( _rSet
, pPortNumber
, SfxInt32Item
, DSID_MYSQL_PORTNUMBER
, true );
238 SFX_ITEMSET_GET( _rSet
, pSocket
, SfxStringItem
, DSID_CONN_SOCKET
, true );
239 SFX_ITEMSET_GET( _rSet
, pNamedPipe
, SfxStringItem
, DSID_NAMED_PIPE
, true );
241 m_pDatabaseName
->SetText( pDatabaseName
->GetValue() );
242 m_pDatabaseName
->ClearModifyFlag();
244 m_pHostName
->SetText( pHostName
->GetValue() );
245 m_pHostName
->ClearModifyFlag();
247 m_pPort
->SetValue( pPortNumber
->GetValue() );
248 m_pPort
->ClearModifyFlag();
250 m_pSocket
->SetText( pSocket
->GetValue() );
251 m_pSocket
->ClearModifyFlag();
253 m_pNamedPipe
->SetText( pNamedPipe
->GetValue() );
254 m_pNamedPipe
->ClearModifyFlag();
256 // if a socket (on Unix) or a pipe name (on Windows) is given, this is preferred over
259 RadioButton
& rSocketPipeRadio
= *m_pSocketRadio
;
260 const SfxStringItem
* pSocketPipeItem
= pSocket
;
262 RadioButton
& rSocketPipeRadio
= *m_pNamedPipeRadio
;
263 const SfxStringItem
* pSocketPipeItem
= pNamedPipe
;
265 OUString
sSocketPipe( pSocketPipeItem
->GetValue() );
266 if ( !sSocketPipe
.isEmpty() )
267 rSocketPipeRadio
.Check();
269 m_pHostPortRadio
->Check();
272 bool MySQLNativeSettings::canAdvance() const
274 if ( m_pDatabaseName
->GetText().isEmpty() )
277 if ( m_pHostPortRadio
->IsChecked()
278 && ( ( m_pHostName
->GetText().isEmpty() )
279 || ( m_pPort
->GetText().isEmpty() )
285 if ( ( m_pSocketRadio
->IsChecked() )
286 && ( m_pSocket
->GetText().isEmpty() )
289 if ( ( m_pNamedPipeRadio
->IsChecked() )
290 && ( m_pNamedPipe
->GetText().isEmpty() )
300 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */