1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3*cdf0e10cSrcweir  *
4*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
5*cdf0e10cSrcweir  *
6*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
7*cdf0e10cSrcweir  *
8*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
9*cdf0e10cSrcweir  *
10*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
11*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
12*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
13*cdf0e10cSrcweir  *
14*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
15*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
18*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
19*cdf0e10cSrcweir  *
20*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
21*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
22*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
23*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
24*cdf0e10cSrcweir  *
25*cdf0e10cSrcweir ************************************************************************/
26*cdf0e10cSrcweir 
27*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
28*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include "admincontrols.hxx"
31*cdf0e10cSrcweir #include "admincontrols.hrc"
32*cdf0e10cSrcweir #include "dbu_dlg.hrc"
33*cdf0e10cSrcweir #include "dsitems.hxx"
34*cdf0e10cSrcweir #include "moduledbu.hxx"
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <svl/eitem.hxx>
37*cdf0e10cSrcweir #include <svl/stritem.hxx>
38*cdf0e10cSrcweir #include <svl/intitem.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir //........................................................................
41*cdf0e10cSrcweir namespace dbaui
42*cdf0e10cSrcweir {
43*cdf0e10cSrcweir //........................................................................
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir 	//====================================================================
46*cdf0e10cSrcweir 	//= TextResetOperatorEventFilter
47*cdf0e10cSrcweir 	//====================================================================
48*cdf0e10cSrcweir     class TextResetOperatorEventFilter : public ::svt::IWindowEventFilter
49*cdf0e10cSrcweir     {
50*cdf0e10cSrcweir     public:
51*cdf0e10cSrcweir         TextResetOperatorEventFilter()
52*cdf0e10cSrcweir         {
53*cdf0e10cSrcweir         }
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir         // IWindowEventFilter
56*cdf0e10cSrcweir         virtual bool payAttentionTo( const VclWindowEvent& _rEvent ) const
57*cdf0e10cSrcweir         {
58*cdf0e10cSrcweir             return  ( _rEvent.GetId() == VCLEVENT_WINDOW_ENABLED )
59*cdf0e10cSrcweir                 ||  ( _rEvent.GetId() == VCLEVENT_WINDOW_DISABLED )
60*cdf0e10cSrcweir                 ||  ( _rEvent.GetId() == VCLEVENT_EDIT_MODIFY );
61*cdf0e10cSrcweir         }
62*cdf0e10cSrcweir     };
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir 	//====================================================================
65*cdf0e10cSrcweir 	//= TextResetOperator
66*cdf0e10cSrcweir 	//====================================================================
67*cdf0e10cSrcweir     class TextResetOperator :public ::svt::IWindowOperator
68*cdf0e10cSrcweir     {
69*cdf0e10cSrcweir     public:
70*cdf0e10cSrcweir         TextResetOperator( const String& _rDisabledText )
71*cdf0e10cSrcweir             :m_sDisabledText( _rDisabledText )
72*cdf0e10cSrcweir         {
73*cdf0e10cSrcweir         }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir         // IWindowOperator
76*cdf0e10cSrcweir         virtual void operateOn( const VclWindowEvent& _rTrigger, Window& _rOperateOn ) const;
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir     private:
79*cdf0e10cSrcweir         const String    m_sDisabledText;
80*cdf0e10cSrcweir               String    m_sUserText;
81*cdf0e10cSrcweir               sal_Bool      m_bLastKnownEnabledState;
82*cdf0e10cSrcweir     };
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 	//--------------------------------------------------------------------
85*cdf0e10cSrcweir     void TextResetOperator::operateOn( const VclWindowEvent& _rTrigger, Window& _rOperateOn ) const
86*cdf0e10cSrcweir     {
87*cdf0e10cSrcweir         OSL_ENSURE( _rTrigger.GetWindow() == &_rOperateOn, "TextResetOperator::operateOn: you're misusing this implementation!" );
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir         switch ( _rTrigger.GetId() )
90*cdf0e10cSrcweir         {
91*cdf0e10cSrcweir         case 0:
92*cdf0e10cSrcweir             // initial call
93*cdf0e10cSrcweir             const_cast< TextResetOperator* >( this )->m_sUserText = _rTrigger.GetWindow()->GetText();
94*cdf0e10cSrcweir             break;
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir         case VCLEVENT_EDIT_MODIFY:
97*cdf0e10cSrcweir             if ( _rTrigger.GetWindow()->IsEnabled() )
98*cdf0e10cSrcweir                 const_cast< TextResetOperator* >( this )->m_sUserText = _rTrigger.GetWindow()->GetText();
99*cdf0e10cSrcweir             break;
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir         case VCLEVENT_WINDOW_ENABLED:
102*cdf0e10cSrcweir             _rOperateOn.SetText( m_sUserText );
103*cdf0e10cSrcweir             break;
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir         case VCLEVENT_WINDOW_DISABLED:
106*cdf0e10cSrcweir             _rOperateOn.SetText( m_sDisabledText );
107*cdf0e10cSrcweir             break;
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir         default:
110*cdf0e10cSrcweir             OSL_ENSURE( false, "TextResetOperator::operateOn: unexpected event ID!" );
111*cdf0e10cSrcweir             // all those IDs should have been filtered out by payAttentionTo
112*cdf0e10cSrcweir             break;
113*cdf0e10cSrcweir         }
114*cdf0e10cSrcweir     }
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 	//====================================================================
117*cdf0e10cSrcweir 	//= TextResetOperatorController
118*cdf0e10cSrcweir 	//====================================================================
119*cdf0e10cSrcweir     class TextResetOperatorController_Base
120*cdf0e10cSrcweir     {
121*cdf0e10cSrcweir     protected:
122*cdf0e10cSrcweir         TextResetOperatorController_Base( const String& _rDisabledText )
123*cdf0e10cSrcweir             :m_pEventFilter( new TextResetOperatorEventFilter )
124*cdf0e10cSrcweir             ,m_pOperator( new TextResetOperator( _rDisabledText ) )
125*cdf0e10cSrcweir         {
126*cdf0e10cSrcweir         }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir         inline ::svt::PWindowEventFilter getEventFilter() const   { return m_pEventFilter; }
129*cdf0e10cSrcweir         inline ::svt::PWindowOperator    getOperator() const      { return m_pOperator; }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     private:
132*cdf0e10cSrcweir         ::svt::PWindowEventFilter   m_pEventFilter;
133*cdf0e10cSrcweir         ::svt::PWindowOperator      m_pOperator;
134*cdf0e10cSrcweir     };
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir     class TextResetOperatorController   :public TextResetOperatorController_Base
137*cdf0e10cSrcweir                                 ,public ::svt::DialogController
138*cdf0e10cSrcweir     {
139*cdf0e10cSrcweir     public:
140*cdf0e10cSrcweir         TextResetOperatorController( Window& _rObservee, const String& _rDisabledText )
141*cdf0e10cSrcweir             :TextResetOperatorController_Base( _rDisabledText )
142*cdf0e10cSrcweir             ,::svt::DialogController( _rObservee, getEventFilter(), getOperator() )
143*cdf0e10cSrcweir         {
144*cdf0e10cSrcweir             addDependentWindow( _rObservee );
145*cdf0e10cSrcweir         }
146*cdf0e10cSrcweir     };
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 	//====================================================================
149*cdf0e10cSrcweir 	//= MySQLNativeSettings
150*cdf0e10cSrcweir 	//====================================================================
151*cdf0e10cSrcweir 	//--------------------------------------------------------------------
152*cdf0e10cSrcweir     MySQLNativeSettings::MySQLNativeSettings( Window& _rParent, const Link& _rControlModificationLink )
153*cdf0e10cSrcweir         :Control( &_rParent, ModuleRes( RID_MYSQL_NATIVE_SETTINGS ).SetAutoRelease( sal_False ) )
154*cdf0e10cSrcweir         ,m_aDatabaseNameLabel	( this, ModuleRes( FT_MYSQL_DATABASE_NAME ) )
155*cdf0e10cSrcweir 		,m_aDatabaseName	    ( this, ModuleRes( ED_MYSQL_DATABASE_NAME ) )
156*cdf0e10cSrcweir         ,m_aHostPortRadio       ( this, ModuleRes( RB_MYSQL_HOST_PORT ) )
157*cdf0e10cSrcweir         ,m_aSocketRadio		    ( this, ModuleRes( RB_MYSQL_SOCKET ) )
158*cdf0e10cSrcweir         ,m_aNamedPipeRadio		( this, ModuleRes( RB_MYSQL_NAMED_PIPE ) )
159*cdf0e10cSrcweir         ,m_aHostNameLabel		( this, ModuleRes( FT_COMMON_HOST_NAME ) )
160*cdf0e10cSrcweir 		,m_aHostName		    ( this, ModuleRes( ED_COMMON_HOST_NAME ) )
161*cdf0e10cSrcweir 		,m_aPortLabel	        ( this, ModuleRes( FT_COMMON_PORT ) )
162*cdf0e10cSrcweir 		,m_aPort	            ( this, ModuleRes( NF_COMMON_PORT ) )
163*cdf0e10cSrcweir         ,m_aDefaultPort         ( this, ModuleRes( FT_COMMON_PORT_DEFAULT ) )
164*cdf0e10cSrcweir 		,m_aSocket		        ( this, ModuleRes( ED_MYSQL_SOCKET ) )
165*cdf0e10cSrcweir 		,m_aNamedPipe		    ( this, ModuleRes( ED_MYSQL_NAMED_PIPE ) )
166*cdf0e10cSrcweir     {
167*cdf0e10cSrcweir         FreeResource();
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir         m_aDatabaseName.SetModifyHdl( _rControlModificationLink );
170*cdf0e10cSrcweir         m_aHostName.SetModifyHdl( _rControlModificationLink );
171*cdf0e10cSrcweir         m_aPort.SetModifyHdl( _rControlModificationLink );
172*cdf0e10cSrcweir         m_aNamedPipe.SetModifyHdl( _rControlModificationLink );
173*cdf0e10cSrcweir         m_aSocketRadio.SetToggleHdl( _rControlModificationLink );
174*cdf0e10cSrcweir         m_aNamedPipeRadio.SetToggleHdl( _rControlModificationLink );
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir         m_aControlDependencies.enableOnRadioCheck( m_aHostPortRadio, m_aHostNameLabel, m_aHostName, m_aPortLabel, m_aPort, m_aDefaultPort );
177*cdf0e10cSrcweir         m_aControlDependencies.enableOnRadioCheck( m_aSocketRadio, m_aSocket );
178*cdf0e10cSrcweir         m_aControlDependencies.enableOnRadioCheck( m_aNamedPipeRadio, m_aNamedPipe );
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir         m_aControlDependencies.addController( ::svt::PDialogController(
181*cdf0e10cSrcweir             new TextResetOperatorController( m_aHostName, String::CreateFromAscii( "localhost" ) )
182*cdf0e10cSrcweir         ) );
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir         // sockets are available on Unix systems only, named pipes only on Windows
185*cdf0e10cSrcweir #ifdef UNX
186*cdf0e10cSrcweir         m_aNamedPipeRadio.Hide();
187*cdf0e10cSrcweir         m_aNamedPipe.Hide();
188*cdf0e10cSrcweir #else
189*cdf0e10cSrcweir         m_aSocketRadio.Hide();
190*cdf0e10cSrcweir         m_aSocket.Hide();
191*cdf0e10cSrcweir #endif
192*cdf0e10cSrcweir     }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 	//--------------------------------------------------------------------
195*cdf0e10cSrcweir     MySQLNativeSettings::~MySQLNativeSettings()
196*cdf0e10cSrcweir     {
197*cdf0e10cSrcweir     }
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 	//--------------------------------------------------------------------
200*cdf0e10cSrcweir 	void MySQLNativeSettings::fillControls( ::std::vector< ISaveValueWrapper* >& _rControlList )
201*cdf0e10cSrcweir     {
202*cdf0e10cSrcweir         _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aDatabaseName ) );
203*cdf0e10cSrcweir         _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aHostName ) );
204*cdf0e10cSrcweir         _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aPort ) );
205*cdf0e10cSrcweir         _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aSocket ) );
206*cdf0e10cSrcweir         _rControlList.push_back( new OSaveValueWrapper< Edit >( &m_aNamedPipe ) );
207*cdf0e10cSrcweir     }
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 	//--------------------------------------------------------------------
210*cdf0e10cSrcweir 	void MySQLNativeSettings::fillWindows( ::std::vector< ISaveValueWrapper* >& _rControlList )
211*cdf0e10cSrcweir     {
212*cdf0e10cSrcweir         _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aDatabaseNameLabel ) );
213*cdf0e10cSrcweir         _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aHostNameLabel ) );
214*cdf0e10cSrcweir         _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aPortLabel ) );
215*cdf0e10cSrcweir         _rControlList.push_back( new ODisableWrapper< FixedText >( &m_aDefaultPort ) );
216*cdf0e10cSrcweir         _rControlList.push_back( new ODisableWrapper< RadioButton >( &m_aSocketRadio ) );
217*cdf0e10cSrcweir         _rControlList.push_back( new ODisableWrapper< RadioButton >( &m_aNamedPipeRadio ) );
218*cdf0e10cSrcweir     }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 	//--------------------------------------------------------------------
221*cdf0e10cSrcweir     sal_Bool MySQLNativeSettings::FillItemSet( SfxItemSet& _rSet )
222*cdf0e10cSrcweir     {
223*cdf0e10cSrcweir 		sal_Bool bChangedSomething = sal_False;
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir         OGenericAdministrationPage::fillString( _rSet, &m_aHostName,     DSID_CONN_HOSTNAME,    bChangedSomething );
226*cdf0e10cSrcweir         OGenericAdministrationPage::fillString( _rSet, &m_aDatabaseName, DSID_DATABASENAME,     bChangedSomething );
227*cdf0e10cSrcweir         OGenericAdministrationPage::fillInt32 ( _rSet, &m_aPort,         DSID_MYSQL_PORTNUMBER, bChangedSomething );
228*cdf0e10cSrcweir #ifdef UNX
229*cdf0e10cSrcweir         OGenericAdministrationPage::fillString( _rSet, &m_aSocket,       DSID_CONN_SOCKET,      bChangedSomething );
230*cdf0e10cSrcweir #else
231*cdf0e10cSrcweir         OGenericAdministrationPage::fillString( _rSet, &m_aNamedPipe,    DSID_NAMED_PIPE,       bChangedSomething );
232*cdf0e10cSrcweir #endif
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir         return bChangedSomething;
235*cdf0e10cSrcweir     }
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir 	//--------------------------------------------------------------------
238*cdf0e10cSrcweir 	void MySQLNativeSettings::implInitControls(const SfxItemSet& _rSet )
239*cdf0e10cSrcweir     {
240*cdf0e10cSrcweir 		SFX_ITEMSET_GET( _rSet, pInvalid, SfxBoolItem, DSID_INVALID_SELECTION, sal_True );
241*cdf0e10cSrcweir 		bool bValid = !pInvalid || !pInvalid->GetValue();
242*cdf0e10cSrcweir         if ( !bValid )
243*cdf0e10cSrcweir             return;
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir         SFX_ITEMSET_GET( _rSet, pDatabaseName,  SfxStringItem,  DSID_DATABASENAME,      sal_True );
246*cdf0e10cSrcweir         SFX_ITEMSET_GET( _rSet, pHostName,      SfxStringItem,  DSID_CONN_HOSTNAME,     sal_True );
247*cdf0e10cSrcweir         SFX_ITEMSET_GET( _rSet, pPortNumber,    SfxInt32Item,   DSID_MYSQL_PORTNUMBER,  sal_True );
248*cdf0e10cSrcweir         SFX_ITEMSET_GET( _rSet, pSocket,        SfxStringItem,  DSID_CONN_SOCKET,       sal_True );
249*cdf0e10cSrcweir         SFX_ITEMSET_GET( _rSet, pNamedPipe,     SfxStringItem,  DSID_NAMED_PIPE,       sal_True );
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir         m_aDatabaseName.SetText( pDatabaseName->GetValue() );
252*cdf0e10cSrcweir         m_aDatabaseName.ClearModifyFlag();
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir         m_aHostName.SetText( pHostName->GetValue() );
255*cdf0e10cSrcweir         m_aHostName.ClearModifyFlag();
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir         m_aPort.SetValue( pPortNumber->GetValue() );
258*cdf0e10cSrcweir         m_aPort.ClearModifyFlag();
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir         m_aSocket.SetText( pSocket->GetValue() );
261*cdf0e10cSrcweir         m_aSocket.ClearModifyFlag();
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir         m_aNamedPipe.SetText( pNamedPipe->GetValue() );
264*cdf0e10cSrcweir         m_aNamedPipe.ClearModifyFlag();
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir         // if a socket (on Unix) or a pipe name (on Windows) is given, this is preferred over
267*cdf0e10cSrcweir         // the port
268*cdf0e10cSrcweir #ifdef UNX
269*cdf0e10cSrcweir         RadioButton& rSocketPipeRadio = m_aSocketRadio;
270*cdf0e10cSrcweir         const SfxStringItem* pSocketPipeItem = pSocket;
271*cdf0e10cSrcweir #else
272*cdf0e10cSrcweir         RadioButton& rSocketPipeRadio = m_aNamedPipeRadio;
273*cdf0e10cSrcweir         const SfxStringItem* pSocketPipeItem = pNamedPipe;
274*cdf0e10cSrcweir #endif
275*cdf0e10cSrcweir         String sSocketPipe( pSocketPipeItem->GetValue() );
276*cdf0e10cSrcweir         if ( sSocketPipe.Len() > 0 )
277*cdf0e10cSrcweir             rSocketPipeRadio.Check();
278*cdf0e10cSrcweir         else
279*cdf0e10cSrcweir             m_aHostPortRadio.Check();
280*cdf0e10cSrcweir     }
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir     //--------------------------------------------------------------------
283*cdf0e10cSrcweir 	bool MySQLNativeSettings::canAdvance() const
284*cdf0e10cSrcweir     {
285*cdf0e10cSrcweir         if ( m_aDatabaseName.GetText().Len() == 0 )
286*cdf0e10cSrcweir             return false;
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir         if  (   m_aHostPortRadio.IsChecked()
289*cdf0e10cSrcweir             &&  (   ( m_aHostName.GetText().Len() == 0 )
290*cdf0e10cSrcweir                 ||  ( m_aPort.GetText().Len() == 0 )
291*cdf0e10cSrcweir                 )
292*cdf0e10cSrcweir             )
293*cdf0e10cSrcweir             return false;
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir #ifdef UNX
296*cdf0e10cSrcweir         if  (   ( m_aSocketRadio.IsChecked() )
297*cdf0e10cSrcweir             &&  ( m_aSocket.GetText().Len() == 0 )
298*cdf0e10cSrcweir             )
299*cdf0e10cSrcweir #else
300*cdf0e10cSrcweir         if  (   ( m_aNamedPipeRadio.IsChecked() )
301*cdf0e10cSrcweir             &&  ( m_aNamedPipe.GetText().Len() == 0 )
302*cdf0e10cSrcweir             )
303*cdf0e10cSrcweir #endif
304*cdf0e10cSrcweir             return false;
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir         return true;
307*cdf0e10cSrcweir     }
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir //........................................................................
310*cdf0e10cSrcweir } // namespace dbaui
311*cdf0e10cSrcweir //........................................................................
312