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

Generated by: LCOV version 1.10