LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - admincontrols.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 118 0.0 %
Date: 2014-04-14 Functions: 0 25 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10