LCOV - code coverage report
Current view: top level - libreoffice/svtools/source/dialogs - ServerDetailsControls.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 218 0.5 %
Date: 2012-12-27 Functions: 2 35 5.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             :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4             :  *
       5             :  * The contents of this file are subject to the Mozilla Public License Version
       6             :  * 1.1 (the "License"); you may not use this file except in compliance with
       7             :  * the License or as specified alternatively below. You may obtain a copy of
       8             :  * the License at http://www.mozilla.org/MPL/
       9             :  *
      10             :  * Software distributed under the License is distributed on an "AS IS" basis,
      11             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12             :  * for the specific language governing rights and limitations under the
      13             :  * License.
      14             :  *
      15             :  * Major Contributor(s):
      16             :  * [ Copyright (C) 2012 SUSE <cbosdonnat@suse.com> (initial developer) ]
      17             :  *
      18             :  * All Rights Reserved.
      19             :  *
      20             :  * For minor contributions see the git repository.
      21             :  *
      22             :  * Alternatively, the contents of this file may be used under the terms of
      23             :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24             :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25             :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26             :  * instead of those above.
      27             :  */
      28             : 
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : #include <com/sun/star/task/InteractionHandler.hpp>
      31             : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
      32             : #include <com/sun/star/ucb/XContentAccess.hpp>
      33             : #include <com/sun/star/sdbc/XResultSet.hpp>
      34             : #include <com/sun/star/sdbc/XRow.hpp>
      35             : 
      36             : #include <comphelper/processfactory.hxx>
      37             : #include <officecfg/Office/Common.hxx>
      38             : #include <rtl/uri.hxx>
      39             : #include <ucbhelper/content.hxx>
      40             : #include <ucbhelper/commandenvironment.hxx>
      41             : 
      42             : #include "PlaceEditDialog.hxx"
      43             : #include "ServerDetailsControls.hxx"
      44             : 
      45             : using namespace std;
      46             : using namespace com::sun::star::lang;
      47             : using namespace com::sun::star::sdbc;
      48             : using namespace com::sun::star::task;
      49             : using namespace com::sun::star::ucb;
      50             : using namespace com::sun::star::uno;
      51             : 
      52           0 : DetailsContainer::DetailsContainer( VclBuilderContainer* pBuilder, const rtl::OString& rFrame )
      53             : {
      54           0 :     pBuilder->get( m_pFrame, rFrame );
      55           0 : }
      56             : 
      57           0 : DetailsContainer::~DetailsContainer( )
      58             : {
      59           0 : }
      60             : 
      61           0 : void DetailsContainer::show( bool bShow )
      62             : {
      63           0 :     m_pFrame->Show( bShow );
      64           0 : }
      65             : 
      66           0 : INetURLObject DetailsContainer::getUrl( )
      67             : {
      68             :     // Don't use that class directly: make it smarter by subclassing it.
      69           0 :     return INetURLObject( );
      70             : }
      71             : 
      72           0 : bool DetailsContainer::setUrl( const INetURLObject& )
      73             : {
      74             :     // That class doesn't contain any logic... it defers the dirty work
      75             :     // to the sub classes.
      76           0 :     return false;
      77             : }
      78             : 
      79           0 : void DetailsContainer::notifyChange( )
      80             : {
      81           0 :     m_aChangeHdl.Call( this );
      82           0 : }
      83             : 
      84           0 : IMPL_LINK( DetailsContainer, ValueChangeHdl, void *, EMPTYARG )
      85             : {
      86           0 :     notifyChange( );
      87           0 :     return 0;
      88             : }
      89             : 
      90           0 : HostDetailsContainer::HostDetailsContainer( VclBuilderContainer* pBuilder, sal_uInt16 nPort, rtl::OUString sScheme ) :
      91             :     DetailsContainer( pBuilder, "HostDetails" ),
      92             :     m_nDefaultPort( nPort ),
      93           0 :     m_sScheme( sScheme )
      94             : {
      95           0 :     pBuilder->get( m_pEDHost, "host" );
      96           0 :     m_pEDHost->SetModifyHdl( LINK( this, DetailsContainer, ValueChangeHdl ) );
      97             : 
      98           0 :     pBuilder->get( m_pEDPort, "port" );
      99           0 :     m_pEDPort->SetModifyHdl( LINK( this, DetailsContainer, ValueChangeHdl ) );
     100             : 
     101           0 :     pBuilder->get( m_pEDPath, "path" );
     102           0 :     m_pEDPath->SetModifyHdl( LINK( this, DetailsContainer, ValueChangeHdl ) );
     103             : 
     104           0 :     show( false );
     105           0 : }
     106             : 
     107           0 : void HostDetailsContainer::show( bool bShow )
     108             : {
     109           0 :     DetailsContainer::show( bShow );
     110           0 :     if ( bShow )
     111           0 :         m_pEDPort->SetValue( m_nDefaultPort );
     112           0 : }
     113             : 
     114           0 : INetURLObject HostDetailsContainer::getUrl( )
     115             : {
     116           0 :     rtl::OUString sHost = rtl::OUString( m_pEDHost->GetText() ).trim( );
     117           0 :     sal_Int64 nPort = m_pEDPort->GetValue();
     118           0 :     rtl::OUString sPath = rtl::OUString( m_pEDPath->GetText() ).trim( );
     119             : 
     120           0 :     rtl::OUString sUrl;
     121           0 :     if ( !sHost.isEmpty( ) )
     122             :     {
     123           0 :         sUrl = m_sScheme + "://" + sHost;
     124           0 :         if ( nPort != m_nDefaultPort )
     125           0 :             sUrl += ":" + rtl::OUString::valueOf( nPort );
     126           0 :         if ( !sPath.isEmpty( ) )
     127           0 :             if ( sPath.indexOf( '/' ) != 0 )
     128           0 :                 sUrl += "/";
     129           0 :             sUrl += sPath;
     130             :     }
     131             : 
     132           0 :     return INetURLObject( sUrl );
     133             : }
     134             : 
     135           0 : bool HostDetailsContainer::setUrl( const INetURLObject& rUrl )
     136             : {
     137           0 :     bool bSuccess = false;
     138             : 
     139           0 :     bSuccess = verifyScheme( INetURLObject::GetScheme( rUrl.GetProtocol( ) ) );
     140             : 
     141           0 :     if ( bSuccess )
     142             :     {
     143           0 :         m_pEDHost->SetText( rUrl.GetHost( ) );
     144           0 :         m_pEDPort->SetValue( rUrl.GetPort( ) );
     145           0 :         m_pEDPath->SetText( rUrl.GetURLPath() );
     146             :     }
     147             : 
     148           0 :     return bSuccess;
     149             : }
     150             : 
     151           0 : bool HostDetailsContainer::verifyScheme( const rtl::OUString& sScheme )
     152             : {
     153           0 :     return sScheme.equals( m_sScheme + "://" );
     154             : }
     155             : 
     156           0 : DavDetailsContainer::DavDetailsContainer( VclBuilderContainer* pBuilder ) :
     157           0 :     HostDetailsContainer( pBuilder, 80, "http" )
     158             : {
     159           0 :     pBuilder->get( m_pCBDavs, "webdavs" );
     160           0 :     m_pCBDavs->SetToggleHdl( LINK( this, DavDetailsContainer, ToggledDavsHdl ) );
     161             : 
     162           0 :     show( false );
     163           0 : }
     164             : 
     165           0 : void DavDetailsContainer::show( bool bShow )
     166             : {
     167           0 :     HostDetailsContainer::show( bShow );
     168             : 
     169           0 :     m_pCBDavs->Show( bShow );
     170             : 
     171           0 :     if ( bShow )
     172           0 :         m_pCBDavs->Check( false );
     173           0 : }
     174             : 
     175           0 : bool DavDetailsContainer::verifyScheme( const rtl::OUString& rScheme )
     176             : {
     177           0 :     bool bValid = false;
     178           0 :     if ( rScheme.equals( "http://" ) )
     179             :     {
     180           0 :         bValid = true;
     181           0 :         m_pCBDavs->Check( false );
     182             :     }
     183           0 :     else if ( rScheme.equals( "https://" ) )
     184             :     {
     185           0 :         bValid = true;
     186           0 :         m_pCBDavs->Check( true );
     187             :     }
     188           0 :     return bValid;
     189             : }
     190             : 
     191           0 : IMPL_LINK( DavDetailsContainer, ToggledDavsHdl, CheckBox*, pCheckBox )
     192             : {
     193             :     // Change default port if needed
     194           0 :     sal_Bool bCheckedDavs = pCheckBox->IsChecked();
     195           0 :     if ( m_pEDPort->GetValue() == 80 && bCheckedDavs == sal_True)
     196           0 :         m_pEDPort->SetValue( 443 );
     197           0 :     else if ( m_pEDPort->GetValue() == 443 && bCheckedDavs == sal_False )
     198           0 :         m_pEDPort->SetValue( 80 );
     199             : 
     200           0 :     rtl::OUString sScheme( "http" );
     201           0 :     if ( bCheckedDavs )
     202           0 :         sScheme = "https";
     203           0 :     setScheme( sScheme );
     204             : 
     205           0 :     notifyChange( );
     206             : 
     207           0 :     return 0;
     208             : }
     209             : 
     210           0 : SmbDetailsContainer::SmbDetailsContainer( VclBuilderContainer* pBuilder ) :
     211           0 :     DetailsContainer( pBuilder, "SmbDetails" )
     212             : {
     213           0 :     pBuilder->get( m_pEDHost, "smbHost" );
     214           0 :     m_pEDHost->SetModifyHdl( LINK( this, DetailsContainer, ValueChangeHdl ) );
     215             : 
     216           0 :     pBuilder->get( m_pEDShare, "smbShare" );
     217           0 :     m_pEDShare->SetModifyHdl( LINK( this, DetailsContainer, ValueChangeHdl ) );
     218             : 
     219           0 :     pBuilder->get( m_pEDPath, "smbPath" );
     220           0 :     m_pEDPath->SetModifyHdl( LINK( this, DetailsContainer, ValueChangeHdl ) );
     221             : 
     222           0 :     show( false );
     223           0 : }
     224             : 
     225           0 : INetURLObject SmbDetailsContainer::getUrl( )
     226             : {
     227           0 :     rtl::OUString sHost = rtl::OUString( m_pEDHost->GetText() ).trim( );
     228           0 :     rtl::OUString sShare = rtl::OUString( m_pEDShare->GetText() ).trim( );
     229           0 :     rtl::OUString sPath = rtl::OUString(  m_pEDPath->GetText() ).trim( );
     230             : 
     231           0 :     rtl::OUString sUrl;
     232           0 :     if ( !sHost.isEmpty( ) )
     233             :     {
     234           0 :         sUrl = "smb://" + sHost + "/";
     235           0 :         if ( !sShare.isEmpty( ) )
     236           0 :             sUrl += sShare;
     237           0 :         if ( !sPath.isEmpty( ) )
     238           0 :             if ( sPath.indexOf( '/' ) != 0 )
     239           0 :                 sUrl += "/";
     240           0 :             sUrl += sPath;
     241             :     }
     242             : 
     243           0 :     return INetURLObject( sUrl );
     244             : }
     245             : 
     246           0 : bool SmbDetailsContainer::setUrl( const INetURLObject& rUrl )
     247             : {
     248           0 :     bool bSuccess =  rUrl.GetProtocol() == INET_PROT_SMB;
     249             : 
     250           0 :     if ( bSuccess )
     251             :     {
     252           0 :         rtl::OUString sShare = rUrl.getName( 0 );
     253           0 :         rtl::OUString sFullPath = rUrl.GetURLPath( );
     254           0 :         rtl::OUString sPath;
     255           0 :         if ( sFullPath.getLength( ) > sShare.getLength( ) )
     256             :         {
     257           0 :             sal_Int32 nPos = sShare.getLength( );
     258           0 :             if ( nPos != 0 )
     259           0 :                 ++nPos;
     260           0 :             sPath = sFullPath.copy( nPos );
     261             :         }
     262             : 
     263           0 :         m_pEDHost->SetText( rUrl.GetHost( ) );
     264           0 :         m_pEDShare->SetText( sShare );
     265           0 :         m_pEDPath->SetText( sPath );
     266             :     }
     267             : 
     268           0 :     return bSuccess;
     269             : }
     270             : 
     271           0 : CmisDetailsContainer::CmisDetailsContainer( VclBuilderContainer* pBuilder ) :
     272             :     DetailsContainer( pBuilder, "CmisDetails" ),
     273             :     m_sUsername( ),
     274             :     m_xCmdEnv( ),
     275             :     m_aServerTypesURLs( ),
     276             :     m_aRepoIds( ),
     277           0 :     m_sRepoId( )
     278             : {
     279           0 :     Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
     280             :     Reference< XInteractionHandler > xGlobalInteractionHandler(
     281           0 :         InteractionHandler::createWithParent(xContext, 0), UNO_QUERY );
     282           0 :     m_xCmdEnv = new ucbhelper::CommandEnvironment( xGlobalInteractionHandler, Reference< XProgressHandler >() );
     283             : 
     284           0 :     pBuilder->get( m_pLBServerType, "serverType" );
     285           0 :     m_pLBServerType->SetSelectHdl( LINK( this, CmisDetailsContainer, SelectServerTypeHdl ) );
     286             : 
     287           0 :     pBuilder->get( m_pEDBinding, "binding" );
     288           0 :     m_pEDBinding->SetModifyHdl( LINK( this, DetailsContainer, ValueChangeHdl ) );
     289             : 
     290           0 :     pBuilder->get( m_pLBRepository, "repositories" );
     291           0 :     m_pLBRepository->SetSelectHdl( LINK( this, CmisDetailsContainer, SelectRepoHdl ) );
     292             : 
     293           0 :     pBuilder->get( m_pBTRepoRefresh, "repositoriesRefresh" );
     294           0 :     m_pBTRepoRefresh->SetClickHdl( LINK( this, CmisDetailsContainer, RefreshReposHdl ) );
     295             : 
     296           0 :     pBuilder->get( m_pEDPath, "cmisPath" );
     297           0 :     m_pEDPath->SetModifyHdl( LINK( this, DetailsContainer, ValueChangeHdl ) );
     298             : 
     299           0 :     show( false );
     300             : 
     301             :     // Load the ServerType entries
     302           0 :     Sequence< ::rtl::OUString > aTypesUrlsList( officecfg::Office::Common::Misc::CmisServersUrls::get( xContext ) );
     303           0 :     Sequence< ::rtl::OUString > aTypesNamesList( officecfg::Office::Common::Misc::CmisServersNames::get( xContext ) );
     304           0 :     for ( sal_Int32 i = 0; i < aTypesUrlsList.getLength( ) && aTypesNamesList.getLength( ); ++i )
     305             :     {
     306           0 :         m_pLBServerType->InsertEntry( aTypesNamesList[i] );
     307           0 :         m_aServerTypesURLs.push_back( aTypesUrlsList[i] );
     308           0 :     }
     309           0 : }
     310             : 
     311           0 : INetURLObject CmisDetailsContainer::getUrl( )
     312             : {
     313           0 :     rtl::OUString sBindingUrl = rtl::OUString( m_pEDBinding->GetText() ).trim( );
     314           0 :     rtl::OUString sPath = rtl::OUString( m_pEDPath->GetText() ).trim( );
     315             : 
     316           0 :     rtl::OUString sUrl;
     317           0 :     if ( !sBindingUrl.isEmpty( ) && !m_sRepoId.isEmpty() )
     318             :     {
     319             :         rtl::OUString sEncodedBinding = rtl::Uri::encode(
     320           0 :                 sBindingUrl + "#" + m_sRepoId,
     321             :                 rtl_UriCharClassRelSegment,
     322             :                 rtl_UriEncodeKeepEscapes,
     323           0 :                 RTL_TEXTENCODING_UTF8 );
     324           0 :         sUrl = "vnd.libreoffice.cmis://" + sEncodedBinding;
     325             :     }
     326           0 :     sUrl += sPath;
     327             : 
     328           0 :     return INetURLObject( sUrl );
     329             : }
     330             : 
     331           0 : bool CmisDetailsContainer::setUrl( const INetURLObject& rUrl )
     332             : {
     333           0 :     bool bSuccess =  rUrl.GetProtocol() == INET_PROT_CMIS;
     334             : 
     335           0 :     if ( bSuccess )
     336             :     {
     337           0 :         rtl::OUString sBindingUrl;
     338           0 :         rtl::OUString sRepositoryId;
     339             : 
     340           0 :         rtl::OUString sDecodedHost = rUrl.GetHost( INetURLObject::DECODE_WITH_CHARSET );
     341           0 :         INetURLObject aHostUrl( sDecodedHost );
     342           0 :         sBindingUrl = aHostUrl.GetURLNoMark( );
     343           0 :         sRepositoryId = aHostUrl.GetMark( );
     344             : 
     345           0 :         m_pEDBinding->SetText( sBindingUrl );
     346           0 :         m_pEDPath->SetText( rUrl.GetURLPath() );
     347             :     }
     348           0 :     return bSuccess;
     349             : }
     350             : 
     351           0 : void CmisDetailsContainer::setUsername( const rtl::OUString& rUsername )
     352             : {
     353           0 :     m_sUsername = rtl::OUString( rUsername );
     354           0 : }
     355             : 
     356           0 : void CmisDetailsContainer::selectRepository( )
     357             : {
     358             :     // Get the repo ID and call the Change listener
     359           0 :     sal_uInt16 nPos = m_pLBRepository->GetSelectEntryPos( );
     360           0 :     m_sRepoId = m_aRepoIds[nPos];
     361             : 
     362           0 :     notifyChange( );
     363           0 : }
     364             : 
     365           0 : IMPL_LINK( CmisDetailsContainer, SelectServerTypeHdl, void *, EMPTYARG  )
     366             : {
     367             :     // Set a sample URL for the server
     368           0 :     sal_uInt16 nId = m_pLBServerType->GetSelectEntryPos( );
     369           0 :     m_pEDBinding->SetText( m_aServerTypesURLs[nId] );
     370           0 :     return 0;
     371             : }
     372             : 
     373           0 : IMPL_LINK( CmisDetailsContainer, RefreshReposHdl, void *, EMPTYARG  )
     374             : {
     375           0 :     rtl::OUString sBindingUrl = rtl::OUString( m_pEDBinding->GetText() ).trim( );
     376             : 
     377             :     // Clean the listbox
     378           0 :     m_pLBRepository->Clear( );
     379           0 :     m_aRepoIds.clear( );
     380             : 
     381             :     // Compute the URL
     382           0 :     rtl::OUString sUrl;
     383           0 :     if ( !sBindingUrl.isEmpty( ) )
     384             :     {
     385             :         rtl::OUString sEncodedBinding = rtl::Uri::encode(
     386             :                 sBindingUrl,
     387             :                 rtl_UriCharClassRelSegment,
     388             :                 rtl_UriEncodeKeepEscapes,
     389           0 :                 RTL_TEXTENCODING_UTF8 );
     390           0 :         sUrl = "vnd.libreoffice.cmis://" + sEncodedBinding;
     391             :     }
     392             : 
     393             :     // Get the Content
     394           0 :     ::ucbhelper::Content aCnt( sUrl, m_xCmdEnv, comphelper::getProcessComponentContext() );
     395           0 :     Sequence< rtl::OUString > aProps( 1 );
     396           0 :     aProps[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Title" ) );
     397             : 
     398             :     try
     399             :     {
     400           0 :         Reference< XResultSet > xResultSet( aCnt.createCursor( aProps ), UNO_QUERY_THROW );
     401           0 :         Reference< XContentAccess > xAccess( xResultSet, UNO_QUERY_THROW );
     402           0 :         while ( xResultSet->next() )
     403             :         {
     404           0 :             rtl::OUString sURL = xAccess->queryContentIdentifierString( );
     405           0 :             INetURLObject aURL( sURL );
     406           0 :             rtl::OUString sId = aURL.GetURLPath( INetURLObject::DECODE_WITH_CHARSET );
     407           0 :             sId = sId.copy( 1 );
     408           0 :             m_aRepoIds.push_back( sId );
     409             : 
     410           0 :             Reference< XRow > xRow( xResultSet, UNO_QUERY );
     411           0 :             rtl::OUString sName = xRow->getString( 1 );
     412           0 :             m_pLBRepository->InsertEntry( sName );
     413           0 :         }
     414             :     }
     415           0 :     catch ( const Exception& )
     416             :     {
     417             :     }
     418             : 
     419             :     // Auto-select the first one
     420           0 :     if ( m_pLBRepository->GetEntryCount( ) > 0 )
     421             :     {
     422           0 :         m_pLBRepository->SelectEntryPos( 0 );
     423           0 :         selectRepository( );
     424             :     }
     425             : 
     426           0 :     return 0;
     427             : }
     428             : 
     429           0 : IMPL_LINK( CmisDetailsContainer, SelectRepoHdl, void *, EMPTYARG  )
     430             : {
     431           0 :     selectRepository( );
     432           0 :     return 0;
     433         108 : }
     434             : 
     435             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10