LCOV - code coverage report
Current view: top level - svtools/source/dialogs - PlaceEditDialog.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 1 99 1.0 %
Date: 2014-04-14 Functions: 2 19 10.5 %
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             : 
      10             : #include <svtools/PlaceEditDialog.hxx>
      11             : #include <svtools/ServerDetailsControls.hxx>
      12             : 
      13             : #include <officecfg/Office/Common.hxx>
      14             : #include <svtools/svtresid.hxx>
      15             : #include <vcl/msgbox.hxx>
      16             : 
      17             : using namespace boost;
      18             : 
      19           0 : PlaceEditDialog::PlaceEditDialog( Window* pParent ) :
      20             :     ModalDialog( pParent, "PlaceEditDialog", "svt/ui/placeedit.ui" ),
      21           0 :     m_pCurrentDetails( )
      22             : {
      23           0 :     get( m_pEDServerName, "name" );
      24           0 :     get( m_pLBServerType, "type" );
      25           0 :     get( m_pEDUsername, "login" );
      26           0 :     get( m_pBTOk, "ok" );
      27           0 :     get( m_pBTCancel, "cancel" );
      28           0 :     get( m_pBTDelete, "delete" );
      29             : 
      30           0 :     m_pBTOk->SetClickHdl( LINK( this, PlaceEditDialog, OKHdl) );
      31           0 :     m_pBTOk->Enable( false );
      32             : 
      33           0 :     m_pEDServerName->SetModifyHdl( LINK( this, PlaceEditDialog, EditHdl) );
      34             : 
      35             :     // This constructor is called when user request a place creation, so
      36             :     // delete button is hidden.
      37           0 :     m_pBTDelete->Hide();
      38             : 
      39           0 :     m_pLBServerType->SetSelectHdl( LINK( this, PlaceEditDialog, SelectTypeHdl ) );
      40           0 :     m_pEDUsername->SetModifyHdl( LINK( this, PlaceEditDialog, EditUsernameHdl ) );
      41             : 
      42           0 :     InitDetails( );
      43           0 : }
      44             : 
      45           0 : PlaceEditDialog::PlaceEditDialog( Window* pParent, const boost::shared_ptr<Place>& pPlace ) :
      46             :     ModalDialog( pParent, "PlaceEditDialog", "svt/ui/placeedit.ui" ),
      47           0 :     m_pCurrentDetails( )
      48             : {
      49           0 :     get( m_pEDServerName, "name" );
      50           0 :     get( m_pLBServerType, "type" );
      51           0 :     get( m_pEDUsername, "login" );
      52           0 :     get( m_pBTOk, "ok" );
      53           0 :     get( m_pBTCancel, "cancel" );
      54           0 :     get( m_pBTDelete, "delete" );
      55             : 
      56           0 :     m_pBTOk->SetClickHdl( LINK( this, PlaceEditDialog, OKHdl) );
      57           0 :     m_pBTDelete->SetClickHdl ( LINK( this, PlaceEditDialog, DelHdl) );
      58             : 
      59           0 :     m_pEDServerName->SetModifyHdl( LINK( this, PlaceEditDialog, EditHdl) );
      60           0 :     m_pLBServerType->SetSelectHdl( LINK( this, PlaceEditDialog, SelectTypeHdl ) );
      61             : 
      62           0 :     InitDetails( );
      63             : 
      64           0 :     m_pEDServerName->SetText( pPlace->GetName() );
      65             : 
      66             :     // Fill the boxes with the URL parts
      67           0 :     bool bSuccess = false;
      68           0 :     for ( size_t i = 0 ; i < m_aDetailsContainers.size( ) && !bSuccess; ++i )
      69             :     {
      70           0 :         INetURLObject& rUrl = pPlace->GetUrlObject( );
      71           0 :         bSuccess = m_aDetailsContainers[i]->setUrl( rUrl );
      72           0 :         if ( bSuccess )
      73             :         {
      74           0 :             m_pLBServerType->SelectEntryPos( i );
      75           0 :             SelectTypeHdl( m_pLBServerType );
      76             : 
      77             :             // Fill the Username field
      78           0 :             if ( rUrl.HasUserData( ) )
      79           0 :                 m_pEDUsername->SetText( rUrl.GetUser( ) );
      80             :         }
      81             :     }
      82           0 : }
      83             : 
      84           0 : PlaceEditDialog::~PlaceEditDialog()
      85             : {
      86           0 : }
      87             : 
      88           0 : OUString PlaceEditDialog::GetServerUrl()
      89             : {
      90           0 :     OUString sUrl;
      91           0 :     if ( m_pCurrentDetails.get( ) )
      92             :     {
      93           0 :         INetURLObject aUrl = m_pCurrentDetails->getUrl();
      94           0 :         OUString sUsername = OUString( m_pEDUsername->GetText( ) ).trim( );
      95           0 :         if ( !sUsername.isEmpty( ) )
      96           0 :             aUrl.SetUser( sUsername );
      97           0 :         if ( !aUrl.HasError( ) )
      98           0 :             sUrl = aUrl.GetMainURL( INetURLObject::NO_DECODE );
      99             :     }
     100             : 
     101           0 :     return sUrl;
     102             : }
     103             : 
     104           0 : boost::shared_ptr<Place> PlaceEditDialog::GetPlace()
     105             : {
     106           0 :     boost::shared_ptr<Place> newPlace( new Place( m_pEDServerName->GetText(), GetServerUrl(), true ) );
     107           0 :     return newPlace;
     108             : }
     109             : 
     110           0 : void PlaceEditDialog::InitDetails( )
     111             : {
     112             :     // Create WebDAV / FTP / SSH details control
     113           0 :     shared_ptr< DetailsContainer > pDavDetails( new DavDetailsContainer( this ) );
     114           0 :     pDavDetails->setChangeHdl( LINK( this, PlaceEditDialog, EditHdl ) );
     115           0 :     m_aDetailsContainers.push_back( pDavDetails );
     116             : 
     117           0 :     shared_ptr< DetailsContainer > pFtpDetails( new HostDetailsContainer( this, 21, "ftp" ) );
     118           0 :     pFtpDetails->setChangeHdl( LINK( this, PlaceEditDialog, EditHdl ) );
     119           0 :     m_aDetailsContainers.push_back( pFtpDetails );
     120             : 
     121           0 :     shared_ptr< DetailsContainer > pSshDetails( new HostDetailsContainer( this, 22, "ssh" ) );
     122           0 :     pSshDetails->setChangeHdl( LINK( this, PlaceEditDialog, EditHdl ) );
     123           0 :     m_aDetailsContainers.push_back( pSshDetails );
     124             : 
     125             :     // Create Windows Share control
     126           0 :     shared_ptr< DetailsContainer > pSmbDetails( new SmbDetailsContainer( this ) );
     127           0 :     pSmbDetails->setChangeHdl( LINK( this, PlaceEditDialog, EditHdl ) );
     128           0 :     m_aDetailsContainers.push_back( pSmbDetails );
     129             : 
     130             :     // Create CMIS control
     131           0 :     shared_ptr< DetailsContainer > pCmisDetails( new CmisDetailsContainer( this ) );
     132           0 :     pCmisDetails->setChangeHdl( LINK( this, PlaceEditDialog, EditHdl ) );
     133           0 :     m_aDetailsContainers.push_back( pCmisDetails );
     134             : 
     135             :     // Set default to first value
     136           0 :     m_pLBServerType->SelectEntryPos( 0 );
     137           0 :     SelectTypeHdl( m_pLBServerType );
     138           0 : }
     139             : 
     140           0 : IMPL_LINK ( PlaceEditDialog,  OKHdl, Button *, EMPTYARG )
     141             : {
     142           0 :     EndDialog( RET_OK );
     143           0 :     return 1;
     144             : }
     145             : 
     146           0 : IMPL_LINK ( PlaceEditDialog, DelHdl, Button *, EMPTYARG )
     147             : {
     148             :     // ReUsing existing symbols...
     149           0 :     EndDialog( RET_NO );
     150           0 :     return 1;
     151             : }
     152             : 
     153           0 : IMPL_LINK ( PlaceEditDialog, EditHdl, void *, EMPTYARG )
     154             : {
     155           0 :     OUString sUrl = GetServerUrl( );
     156           0 :     OUString sName = OUString( m_pEDServerName->GetText() ).trim( );
     157           0 :     m_pBTOk->Enable( !sName.isEmpty( ) && !sUrl.isEmpty( ) );
     158           0 :     return 1;
     159             : }
     160             : 
     161           0 : IMPL_LINK ( PlaceEditDialog, EditUsernameHdl, void *, EMPTYARG )
     162             : {
     163           0 :     for ( std::vector< boost::shared_ptr< DetailsContainer > >::iterator it = m_aDetailsContainers.begin( );
     164           0 :             it != m_aDetailsContainers.end( ); ++it )
     165             :     {
     166           0 :         ( *it )->setUsername( OUString( m_pEDUsername->GetText() ) );
     167             :     }
     168           0 :     return 1;
     169             : }
     170             : 
     171           0 : IMPL_LINK( PlaceEditDialog, SelectTypeHdl, void*, EMPTYARG )
     172             : {
     173           0 :     if ( m_pCurrentDetails.get( ) )
     174           0 :         m_pCurrentDetails->show( false );
     175             : 
     176           0 :     sal_uInt16 nPos = m_pLBServerType->GetSelectEntryPos( );
     177           0 :     m_pCurrentDetails = m_aDetailsContainers[nPos];
     178             : 
     179           0 :     m_pCurrentDetails->show( true );
     180             : 
     181           0 :     SetSizePixel(GetOptimalSize());
     182           0 :     return 0;
     183           3 : }
     184             : 
     185             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10