LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sfx2/source/inet - inettbc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 109 1.8 %
Date: 2013-07-09 Functions: 3 16 18.8 %
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 "inettbc.hxx"
      22             : 
      23             : #include <com/sun/star/uno/Any.h>
      24             : #include <com/sun/star/frame/Desktop.hpp>
      25             : #include <com/sun/star/frame/XFramesSupplier.hpp>
      26             : #include <com/sun/star/task/XInteractionHandler.hpp>
      27             : #include <svl/eitem.hxx>
      28             : #include <svl/stritem.hxx>
      29             : #include <unotools/historyoptions.hxx>
      30             : #include <vcl/toolbox.hxx>
      31             : #include <toolkit/helper/vclunohelper.hxx>
      32             : #include <osl/thread.hxx>
      33             : #include <osl/mutex.hxx>
      34             : #include <rtl/ustring.hxx>
      35             : 
      36             : #include <svl/itemset.hxx>
      37             : #include <svl/urihelper.hxx>
      38             : #include <unotools/pathoptions.hxx>
      39             : #include <svtools/asynclink.hxx>
      40             : #include <svtools/inettbc.hxx>
      41             : 
      42             : #include <unotools/localfilehelper.hxx>
      43             : #include <comphelper/processfactory.hxx>
      44             : 
      45             : #include <sfx2/sfx.hrc>
      46             : #include <sfx2/dispatch.hxx>
      47             : #include <sfx2/viewfrm.hxx>
      48             : #include <sfx2/objsh.hxx>
      49             : #include "referers.hxx"
      50             : #include "sfxtypes.hxx"
      51             : #include "helper.hxx"
      52             : 
      53             : using namespace ::com::sun::star::uno;
      54             : using namespace ::com::sun::star::beans;
      55             : using namespace ::com::sun::star::util;
      56             : using namespace ::com::sun::star::frame;
      57             : using namespace ::com::sun::star::task;
      58             : 
      59             : //***************************************************************************
      60             : // SfxURLToolBoxControl_Impl
      61             : //***************************************************************************
      62             : 
      63         133 : SFX_IMPL_TOOLBOX_CONTROL(SfxURLToolBoxControl_Impl,SfxStringItem)
      64             : 
      65           0 : SfxURLToolBoxControl_Impl::SfxURLToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox )
      66             :     : SfxToolBoxControl( nSlotId, nId, rBox ),
      67           0 :     pAccExec( 0 )
      68             : {
      69           0 :     addStatusListener( OUString( ".uno:CurrentURL" ));
      70           0 : }
      71             : 
      72           0 : SfxURLToolBoxControl_Impl::~SfxURLToolBoxControl_Impl()
      73             : {
      74           0 :     delete pAccExec;
      75           0 : }
      76             : 
      77           0 : SvtURLBox* SfxURLToolBoxControl_Impl::GetURLBox() const
      78             : {
      79           0 :     return (SvtURLBox*)GetToolBox().GetItemWindow( GetId() );
      80             : }
      81             : 
      82             : //***************************************************************************
      83             : 
      84           0 : void SfxURLToolBoxControl_Impl::OpenURL( const String& rName, sal_Bool /*bNew*/ ) const
      85             : {
      86           0 :     String aName;
      87           0 :     String aFilter;
      88           0 :     String aOptions;
      89             : 
      90           0 :     INetURLObject aObj( rName );
      91           0 :     if ( aObj.GetProtocol() == INET_PROT_NOT_VALID )
      92             :     {
      93           0 :         String aBaseURL = GetURLBox()->GetBaseURL();
      94           0 :         aName = SvtURLBox::ParseSmart( rName, aBaseURL, SvtPathOptions().GetWorkPath() );
      95             :     }
      96             :     else
      97           0 :         aName = rName;
      98             : 
      99           0 :     if ( !aName.Len() )
     100           0 :         return;
     101             : 
     102           0 :     Reference< XDispatchProvider > xDispatchProvider( getFrameInterface(), UNO_QUERY );
     103           0 :     if ( xDispatchProvider.is() )
     104             :     {
     105           0 :         URL             aTargetURL;
     106           0 :         OUString aTarget( OUString("_default"));
     107             : 
     108           0 :         aTargetURL.Complete = aName;
     109             : 
     110           0 :         getURLTransformer()->parseStrict( aTargetURL );
     111           0 :         Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, aTarget, 0 );
     112           0 :         if ( xDispatch.is() )
     113             :         {
     114           0 :             Sequence< PropertyValue > aArgs( 2 );
     115           0 :             aArgs[0].Name = OUString("Referer");
     116           0 :             aArgs[0].Value = makeAny( OUString(SFX_REFERER_USER ));
     117           0 :             aArgs[1].Name = OUString( "FileName" );
     118           0 :             aArgs[1].Value = makeAny( OUString( aName ));
     119             : 
     120           0 :             if ( aFilter.Len() )
     121             :             {
     122           0 :                 aArgs.realloc( 4 );
     123           0 :                 aArgs[2].Name = OUString("FilterOptions");
     124           0 :                 aArgs[2].Value = makeAny( OUString( aOptions ));
     125           0 :                 aArgs[3].Name = OUString("FilterName");
     126           0 :                 aArgs[3].Value = makeAny( OUString( aFilter ));
     127             :             }
     128             : 
     129           0 :             SfxURLToolBoxControl_Impl::ExecuteInfo* pExecuteInfo = new SfxURLToolBoxControl_Impl::ExecuteInfo;
     130           0 :             pExecuteInfo->xDispatch     = xDispatch;
     131           0 :             pExecuteInfo->aTargetURL    = aTargetURL;
     132           0 :             pExecuteInfo->aArgs         = aArgs;
     133           0 :             Application::PostUserEvent( STATIC_LINK( 0, SfxURLToolBoxControl_Impl, ExecuteHdl_Impl), pExecuteInfo );
     134           0 :         }
     135           0 :     }
     136             : }
     137             : 
     138             : //--------------------------------------------------------------------
     139             : 
     140           0 : IMPL_STATIC_LINK_NOINSTANCE( SfxURLToolBoxControl_Impl, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
     141             : {
     142             :     try
     143             :     {
     144             :         // Asynchronous execution as this can lead to our own destruction!
     145             :         // Framework can recycle our current frame and the layout manager disposes all user interface
     146             :         // elements if a component gets detached from its frame!
     147           0 :         pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
     148             :     }
     149           0 :     catch ( Exception& )
     150             :     {
     151             :     }
     152             : 
     153           0 :     delete pExecuteInfo;
     154           0 :     return 0;
     155             : }
     156             : 
     157             : 
     158           0 : Window* SfxURLToolBoxControl_Impl::CreateItemWindow( Window* pParent )
     159             : {
     160           0 :     SvtURLBox* pURLBox = new SvtURLBox( pParent );
     161           0 :     pURLBox->SetOpenHdl( LINK( this, SfxURLToolBoxControl_Impl, OpenHdl ) );
     162           0 :     pURLBox->SetSelectHdl( LINK( this, SfxURLToolBoxControl_Impl, SelectHdl ) );
     163             : 
     164           0 :     return pURLBox;
     165             : }
     166             : 
     167           0 : IMPL_LINK_NOARG(SfxURLToolBoxControl_Impl, SelectHdl)
     168             : {
     169           0 :     SvtURLBox* pURLBox = GetURLBox();
     170           0 :     String aName( pURLBox->GetURL() );
     171             : 
     172           0 :     if ( !pURLBox->IsTravelSelect() && aName.Len() )
     173           0 :         OpenURL( aName, sal_False );
     174             : 
     175           0 :     return 1L;
     176             : }
     177             : 
     178           0 : IMPL_LINK_NOARG(SfxURLToolBoxControl_Impl, OpenHdl)
     179             : {
     180           0 :     SvtURLBox* pURLBox = GetURLBox();
     181           0 :     OpenURL( pURLBox->GetURL(), pURLBox->IsCtrlOpen() );
     182             : 
     183           0 :     Reference< XDesktop2 > xDesktop = Desktop::create( m_xContext );
     184           0 :     Reference< XFrame > xFrame( xDesktop->getActiveFrame(), UNO_QUERY );
     185           0 :     if ( xFrame.is() )
     186             :     {
     187           0 :         Window* pWin = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
     188           0 :         if ( pWin )
     189             :         {
     190           0 :             pWin->GrabFocus();
     191           0 :             pWin->ToTop( TOTOP_RESTOREWHENMIN );
     192             :         }
     193             :     }
     194             : 
     195           0 :     return 1L;
     196             : }
     197             : 
     198             : //***************************************************************************
     199             : 
     200           0 : void SfxURLToolBoxControl_Impl::StateChanged
     201             : (
     202             :     sal_uInt16              nSID,
     203             :     SfxItemState        eState,
     204             :     const SfxPoolItem*  pState
     205             : )
     206             : {
     207           0 :     if ( nSID == SID_OPENURL )
     208             :     {
     209             :         // Disable URL box if command is disabled
     210           0 :         GetURLBox()->Enable( SFX_ITEM_DISABLED != eState );
     211             :     }
     212             : 
     213           0 :     if ( GetURLBox()->IsEnabled() )
     214             :     {
     215           0 :         if( nSID == SID_FOCUSURLBOX )
     216             :         {
     217           0 :             if ( GetURLBox()->IsVisible() )
     218           0 :                 GetURLBox()->GrabFocus();
     219             :         }
     220           0 :         else if ( !GetURLBox()->IsModified() && SFX_ITEM_AVAILABLE == eState )
     221             :         {
     222           0 :             SvtURLBox* pURLBox = GetURLBox();
     223           0 :             pURLBox->Clear();
     224             : 
     225           0 :             ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > > lList = SvtHistoryOptions().GetList(eHISTORY);
     226           0 :             for (sal_Int32 i=0; i<lList.getLength(); ++i)
     227             :             {
     228           0 :                 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > lProps = lList[i];
     229           0 :                 for (sal_Int32 p=0; p<lProps.getLength(); ++p)
     230             :                 {
     231           0 :                     if (lProps[p].Name != HISTORY_PROPERTYNAME_URL)
     232           0 :                         continue;
     233             : 
     234           0 :                     OUString sURL;
     235           0 :                     if (!(lProps[p].Value>>=sURL) || sURL.isEmpty())
     236           0 :                         continue;
     237             : 
     238           0 :                     INetURLObject aURL    ( sURL );
     239           0 :                     OUString      sMainURL( aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET ) );
     240           0 :                     OUString      sFile;
     241             : 
     242           0 :                     if (::utl::LocalFileHelper::ConvertURLToSystemPath(sMainURL,sFile))
     243           0 :                         pURLBox->InsertEntry(sFile);
     244             :                     else
     245           0 :                         pURLBox->InsertEntry(sMainURL);
     246           0 :                 }
     247           0 :             }
     248             : 
     249           0 :             const SfxStringItem *pURL = PTR_CAST(SfxStringItem,pState);
     250           0 :             String aRep( pURL->GetValue() );
     251           0 :             INetURLObject aURL( aRep );
     252           0 :             INetProtocol eProt = aURL.GetProtocol();
     253           0 :             if ( eProt == INET_PROT_FILE )
     254             :             {
     255           0 :                 pURLBox->SetText( aURL.PathToFileName() );
     256             :             }
     257             :             else
     258           0 :                 pURLBox->SetText( aURL.GetURLNoPass() );
     259             :         }
     260             :     }
     261         408 : }
     262             : 
     263             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10