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

Generated by: LCOV version 1.11