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

Generated by: LCOV version 1.10