LCOV - code coverage report
Current view: top level - dbaccess/source/ui/dlg - admincontrols.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 145 0.7 %
Date: 2015-06-13 12:38:46 Functions: 2 26 7.7 %
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 "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 :         disposeOnce();
     174           0 :     }
     175             : 
     176           0 :     void MySQLNativeSettings::dispose()
     177             :     {
     178           0 :         m_pDatabaseNameLabel.clear();
     179           0 :         m_pDatabaseName.clear();
     180           0 :         m_pHostPortRadio.clear();
     181           0 :         m_pSocketRadio.clear();
     182           0 :         m_pNamedPipeRadio.clear();
     183           0 :         m_pHostNameLabel.clear();
     184           0 :         m_pHostName.clear();
     185           0 :         m_pPortLabel.clear();
     186           0 :         m_pPort.clear();
     187           0 :         m_pDefaultPort.clear();
     188           0 :         m_pSocket.clear();
     189           0 :         m_pNamedPipe.clear();
     190           0 :         TabPage::dispose();
     191           0 :     }
     192             : 
     193           0 :     void MySQLNativeSettings::fillControls( ::std::vector< ISaveValueWrapper* >& _rControlList )
     194             :     {
     195           0 :         _rControlList.push_back( new OSaveValueWrapper< Edit >( m_pDatabaseName ) );
     196           0 :         _rControlList.push_back( new OSaveValueWrapper< Edit >( m_pHostName ) );
     197           0 :         _rControlList.push_back( new OSaveValueWrapper< Edit >( m_pPort ) );
     198           0 :         _rControlList.push_back( new OSaveValueWrapper< Edit >( m_pSocket ) );
     199           0 :         _rControlList.push_back( new OSaveValueWrapper< Edit >( m_pNamedPipe ) );
     200           0 :     }
     201             : 
     202           0 :     void MySQLNativeSettings::fillWindows( ::std::vector< ISaveValueWrapper* >& _rControlList )
     203             :     {
     204           0 :         _rControlList.push_back( new ODisableWrapper< FixedText >( m_pDatabaseNameLabel ) );
     205           0 :         _rControlList.push_back( new ODisableWrapper< FixedText >( m_pHostNameLabel ) );
     206           0 :         _rControlList.push_back( new ODisableWrapper< FixedText >( m_pPortLabel ) );
     207           0 :         _rControlList.push_back( new ODisableWrapper< FixedText >( m_pDefaultPort ) );
     208           0 :         _rControlList.push_back( new ODisableWrapper< RadioButton >( m_pSocketRadio ) );
     209           0 :         _rControlList.push_back( new ODisableWrapper< RadioButton >( m_pNamedPipeRadio ) );
     210           0 :     }
     211             : 
     212           0 :     bool MySQLNativeSettings::FillItemSet( SfxItemSet* _rSet )
     213             :     {
     214           0 :         bool bChangedSomething = false;
     215             : 
     216           0 :         OGenericAdministrationPage::fillString( *_rSet, m_pHostName,     DSID_CONN_HOSTNAME,    bChangedSomething );
     217           0 :         OGenericAdministrationPage::fillString( *_rSet, m_pDatabaseName, DSID_DATABASENAME,     bChangedSomething );
     218           0 :         OGenericAdministrationPage::fillInt32 ( *_rSet, m_pPort,         DSID_MYSQL_PORTNUMBER, bChangedSomething );
     219             : #ifdef UNX
     220           0 :         OGenericAdministrationPage::fillString( *_rSet, m_pSocket,       DSID_CONN_SOCKET,      bChangedSomething );
     221             : #else
     222             :         OGenericAdministrationPage::fillString( *_rSet, m_pNamedPipe,    DSID_NAMED_PIPE,       bChangedSomething );
     223             : #endif
     224             : 
     225           0 :         return bChangedSomething;
     226             :     }
     227             : 
     228           0 :     void MySQLNativeSettings::implInitControls(const SfxItemSet& _rSet )
     229             :     {
     230           0 :         SFX_ITEMSET_GET( _rSet, pInvalid, SfxBoolItem, DSID_INVALID_SELECTION, 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,      true );
     236           0 :         SFX_ITEMSET_GET( _rSet, pHostName,      SfxStringItem,  DSID_CONN_HOSTNAME,     true );
     237           0 :         SFX_ITEMSET_GET( _rSet, pPortNumber,    SfxInt32Item,   DSID_MYSQL_PORTNUMBER,  true );
     238           0 :         SFX_ITEMSET_GET( _rSet, pSocket,        SfxStringItem,  DSID_CONN_SOCKET,       true );
     239           0 :         SFX_ITEMSET_GET( _rSet, pNamedPipe,     SfxStringItem,  DSID_NAMED_PIPE,       true );
     240             : 
     241           0 :         m_pDatabaseName->SetText( pDatabaseName->GetValue() );
     242           0 :         m_pDatabaseName->ClearModifyFlag();
     243             : 
     244           0 :         m_pHostName->SetText( pHostName->GetValue() );
     245           0 :         m_pHostName->ClearModifyFlag();
     246             : 
     247           0 :         m_pPort->SetValue( pPortNumber->GetValue() );
     248           0 :         m_pPort->ClearModifyFlag();
     249             : 
     250           0 :         m_pSocket->SetText( pSocket->GetValue() );
     251           0 :         m_pSocket->ClearModifyFlag();
     252             : 
     253           0 :         m_pNamedPipe->SetText( pNamedPipe->GetValue() );
     254           0 :         m_pNamedPipe->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_pSocketRadio;
     260           0 :         const SfxStringItem* pSocketPipeItem = pSocket;
     261             : #else
     262             :         RadioButton& rSocketPipeRadio = *m_pNamedPipeRadio;
     263             :         const SfxStringItem* pSocketPipeItem = pNamedPipe;
     264             : #endif
     265           0 :         OUString sSocketPipe( pSocketPipeItem->GetValue() );
     266           0 :         if ( !sSocketPipe.isEmpty() )
     267           0 :             rSocketPipeRadio.Check();
     268             :         else
     269           0 :             m_pHostPortRadio->Check();
     270             :     }
     271             : 
     272           0 :     bool MySQLNativeSettings::canAdvance() const
     273             :     {
     274           0 :         if ( m_pDatabaseName->GetText().isEmpty() )
     275           0 :             return false;
     276             : 
     277           0 :         if  (   m_pHostPortRadio->IsChecked()
     278           0 :             &&  (   ( m_pHostName->GetText().isEmpty() )
     279           0 :                 ||  ( m_pPort->GetText().isEmpty() )
     280             :                 )
     281             :             )
     282           0 :             return false;
     283             : 
     284             : #ifdef UNX
     285           0 :         if  (   ( m_pSocketRadio->IsChecked() )
     286           0 :             &&  ( m_pSocket->GetText().isEmpty() )
     287             :             )
     288             : #else
     289             :         if  (   ( m_pNamedPipeRadio->IsChecked() )
     290             :             &&  ( m_pNamedPipe->GetText().isEmpty() )
     291             :             )
     292             : #endif
     293           0 :             return false;
     294             : 
     295           0 :         return true;
     296             :     }
     297             : 
     298          36 : } // namespace dbaui
     299             : 
     300             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11