LCOV - code coverage report
Current view: top level - framework/source/classes - droptargetlistener.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 10 94 10.6 %
Date: 2012-08-25 Functions: 3 13 23.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 12 196 6.1 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <classes/droptargetlistener.hxx>
      30                 :            : #include <threadhelp/readguard.hxx>
      31                 :            : #include <threadhelp/writeguard.hxx>
      32                 :            : #include <targets.h>
      33                 :            : #include <services.h>
      34                 :            : 
      35                 :            : #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
      36                 :            : #include <com/sun/star/frame/XDispatch.hpp>
      37                 :            : #include <com/sun/star/frame/XDispatchProvider.hpp>
      38                 :            : #include <com/sun/star/beans/PropertyValue.hpp>
      39                 :            : #include <com/sun/star/util/URLTransformer.hpp>
      40                 :            : #include <com/sun/star/util/XURLTransformer.hpp>
      41                 :            : 
      42                 :            : #include <svtools/transfer.hxx>
      43                 :            : #include <unotools/localfilehelper.hxx>
      44                 :            : #include <sot/filelist.hxx>
      45                 :            : #include <comphelper/componentcontext.hxx>
      46                 :            : 
      47                 :            : #include <osl/file.hxx>
      48                 :            : #include <vcl/svapp.hxx>
      49                 :            : 
      50                 :            : namespace framework
      51                 :            : {
      52                 :            : 
      53                 :       1749 : DropTargetListener::DropTargetListener( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory,
      54                 :            :                                         const css::uno::Reference< css::frame::XFrame >&              xFrame  )
      55                 :       1749 :         : ThreadHelpBase  ( &Application::GetSolarMutex() )
      56                 :            :         , m_xFactory      ( xFactory                      )
      57                 :            :         , m_xTargetFrame  ( xFrame                        )
      58 [ +  - ][ +  - ]:       1749 :         , m_pFormats      ( new DataFlavorExVector        )
         [ +  - ][ +  - ]
      59                 :            : {
      60                 :       1749 : }
      61                 :            : 
      62                 :            : // -----------------------------------------------------------------------------
      63                 :            : 
      64 [ +  - ][ +  - ]:       1658 : DropTargetListener::~DropTargetListener()
      65                 :            : {
      66 [ +  - ][ +  - ]:       1658 :     m_xTargetFrame = css::uno::WeakReference< css::frame::XFrame >();
                 [ +  - ]
      67         [ +  - ]:       1658 :     m_xFactory     = css::uno::Reference< css::lang::XMultiServiceFactory >();
      68         [ +  - ]:       1658 :     delete m_pFormats;
      69                 :       1658 :     m_pFormats = NULL;
      70         [ -  + ]:       3316 : }
      71                 :            : 
      72                 :            : // -----------------------------------------------------------------------------
      73                 :            : 
      74                 :          0 : void SAL_CALL DropTargetListener::disposing( const css::lang::EventObject& ) throw( css::uno::RuntimeException )
      75                 :            : {
      76         [ #  # ]:          0 :     m_xTargetFrame = css::uno::WeakReference< css::frame::XFrame >();
      77         [ #  # ]:          0 :     m_xFactory     = css::uno::Reference< css::lang::XMultiServiceFactory >();
      78                 :          0 : }
      79                 :            : 
      80                 :            : // -----------------------------------------------------------------------------
      81                 :            : 
      82                 :          0 : void SAL_CALL DropTargetListener::drop( const css::datatransfer::dnd::DropTargetDropEvent& dtde ) throw( css::uno::RuntimeException )
      83                 :            : {
      84                 :          0 :     const sal_Int8 nAction = dtde.DropAction;
      85                 :            : 
      86                 :            :     try
      87                 :            :     {
      88         [ #  # ]:          0 :         if ( css::datatransfer::dnd::DNDConstants::ACTION_NONE != nAction )
      89                 :            :         {
      90         [ #  # ]:          0 :             TransferableDataHelper aHelper( dtde.Transferable );
      91                 :          0 :             sal_Bool bFormatFound = sal_False;
      92         [ #  # ]:          0 :             FileList aFileList;
      93                 :            : 
      94                 :            :             // at first check filelist format
      95 [ #  # ][ #  # ]:          0 :             if ( aHelper.GetFileList( SOT_FORMAT_FILE_LIST, aFileList ) )
      96                 :            :             {
      97         [ #  # ]:          0 :                 sal_uLong i, nCount = aFileList.Count();
      98         [ #  # ]:          0 :                 for ( i = 0; i < nCount; ++i )
      99 [ #  # ][ #  # ]:          0 :                     implts_OpenFile( aFileList.GetFile(i) );
                 [ #  # ]
     100                 :          0 :                 bFormatFound = sal_True;
     101                 :            :             }
     102                 :            : 
     103                 :            :             // then, if necessary, the file format
     104         [ #  # ]:          0 :             String aFilePath;
     105 [ #  # ][ #  # ]:          0 :             if ( !bFormatFound && aHelper.GetString( SOT_FORMAT_FILE, aFilePath ) )
         [ #  # ][ #  # ]
     106 [ #  # ][ #  # ]:          0 :                 implts_OpenFile( aFilePath );
         [ #  # ][ #  # ]
                 [ #  # ]
     107                 :            :         }
     108 [ #  # ][ #  # ]:          0 :         dtde.Context->dropComplete( css::datatransfer::dnd::DNDConstants::ACTION_NONE != nAction );
     109                 :            :     }
     110                 :          0 :     catch( const ::com::sun::star::uno::Exception& )
     111                 :            :     {
     112                 :            :     }
     113                 :          0 : }
     114                 :            : 
     115                 :            : // -----------------------------------------------------------------------------
     116                 :            : 
     117                 :          0 : void SAL_CALL DropTargetListener::dragEnter( const css::datatransfer::dnd::DropTargetDragEnterEvent& dtdee ) throw( css::uno::RuntimeException )
     118                 :            : {
     119                 :            :     try
     120                 :            :     {
     121         [ #  # ]:          0 :         implts_BeginDrag( dtdee.SupportedDataFlavors );
     122                 :            :     }
     123                 :          0 :     catch( const ::com::sun::star::uno::Exception& )
     124                 :            :     {
     125                 :            :     }
     126                 :            : 
     127                 :          0 :     dragOver( dtdee );
     128         [ #  # ]:          0 : }
     129                 :            : 
     130                 :            : // -----------------------------------------------------------------------------
     131                 :            : 
     132                 :          0 : void SAL_CALL DropTargetListener::dragExit( const css::datatransfer::dnd::DropTargetEvent& ) throw( css::uno::RuntimeException )
     133                 :            : {
     134                 :            :     try
     135                 :            :     {
     136         [ #  # ]:          0 :         implts_EndDrag();
     137                 :            :     }
     138                 :          0 :     catch( const ::com::sun::star::uno::Exception& )
     139                 :            :     {
     140                 :            :     }
     141         [ #  # ]:          0 : }
     142                 :            : 
     143                 :            : // -----------------------------------------------------------------------------
     144                 :            : 
     145                 :          0 : void SAL_CALL DropTargetListener::dragOver( const css::datatransfer::dnd::DropTargetDragEvent& dtde ) throw( css::uno::RuntimeException )
     146                 :            : {
     147                 :            :     try
     148                 :            :     {
     149         [ #  # ]:          0 :         sal_Bool bAccept = ( implts_IsDropFormatSupported( SOT_FORMAT_FILE ) ||
     150 [ #  # ][ #  # ]:          0 :                              implts_IsDropFormatSupported( SOT_FORMAT_FILE_LIST ) );
                 [ #  # ]
     151                 :            : 
     152         [ #  # ]:          0 :         if ( !bAccept )
     153 [ #  # ][ #  # ]:          0 :             dtde.Context->rejectDrag();
     154                 :            :         else
     155 [ #  # ][ #  # ]:          0 :             dtde.Context->acceptDrag( css::datatransfer::dnd::DNDConstants::ACTION_COPY );
     156                 :            :     }
     157                 :          0 :     catch( const ::com::sun::star::uno::Exception& )
     158                 :            :     {
     159                 :            :     }
     160         [ #  # ]:          0 : }
     161                 :            : 
     162                 :            : // -----------------------------------------------------------------------------
     163                 :            : 
     164                 :          0 : void SAL_CALL DropTargetListener::dropActionChanged( const css::datatransfer::dnd::DropTargetDragEvent& ) throw( css::uno::RuntimeException )
     165                 :            : {
     166                 :          0 : }
     167                 :            : 
     168                 :          0 : void DropTargetListener::implts_BeginDrag( const css::uno::Sequence< css::datatransfer::DataFlavor >& rSupportedDataFlavors )
     169                 :            : {
     170                 :            :     /* SAFE { */
     171         [ #  # ]:          0 :     WriteGuard aWriteLock(m_aLock);
     172                 :          0 :     m_pFormats->clear();
     173         [ #  # ]:          0 :     TransferableDataHelper::FillDataFlavorExVector(rSupportedDataFlavors,*m_pFormats);
     174 [ #  # ][ #  # ]:          0 :     aWriteLock.unlock();
     175                 :            :     /* } SAFE */
     176                 :          0 : }
     177                 :            : 
     178                 :          0 : void DropTargetListener::implts_EndDrag()
     179                 :            : {
     180                 :            :     /* SAFE { */
     181         [ #  # ]:          0 :     WriteGuard aWriteLock(m_aLock);
     182                 :          0 :     m_pFormats->clear();
     183 [ #  # ][ #  # ]:          0 :     aWriteLock.unlock();
     184                 :            :     /* } SAFE */
     185                 :          0 : }
     186                 :            : 
     187                 :          0 : sal_Bool DropTargetListener::implts_IsDropFormatSupported( SotFormatStringId nFormat )
     188                 :            : {
     189                 :            :     /* SAFE { */
     190         [ #  # ]:          0 :     ReadGuard aReadLock(m_aLock);
     191                 :          0 :     DataFlavorExVector::iterator aIter( m_pFormats->begin() ), aEnd( m_pFormats->end() );
     192                 :          0 :     sal_Bool bRet = sal_False;
     193                 :            : 
     194 [ #  # ][ #  # ]:          0 :     while ( aIter != aEnd )
     195                 :            :     {
     196 [ #  # ][ #  # ]:          0 :         if ( nFormat == (*aIter++).mnSotId )
     197                 :            :         {
     198                 :          0 :             bRet = sal_True;
     199                 :          0 :             aIter = aEnd;
     200                 :            :         }
     201                 :            :     }
     202         [ #  # ]:          0 :     aReadLock.unlock();
     203                 :            :     /* } SAFE */
     204                 :            : 
     205         [ #  # ]:          0 :     return bRet;
     206                 :            : }
     207                 :            : 
     208                 :          0 : void DropTargetListener::implts_OpenFile( const String& rFilePath )
     209                 :            : {
     210                 :          0 :     rtl::OUString aFileURL;
     211 [ #  # ][ #  # ]:          0 :     if ( !::utl::LocalFileHelper::ConvertPhysicalNameToURL( rFilePath, aFileURL ) )
                 [ #  # ]
     212         [ #  # ]:          0 :         aFileURL = rFilePath;
     213                 :            : 
     214                 :          0 :     ::osl::FileStatus aStatus( osl_FileStatus_Mask_FileURL );
     215                 :          0 :     ::osl::DirectoryItem aItem;
     216 [ #  # ][ #  # ]:          0 :     if( ::osl::FileBase::E_None == ::osl::DirectoryItem::get( aFileURL, aItem ) &&
         [ #  # ][ #  # ]
     217         [ #  # ]:          0 :         ::osl::FileBase::E_None == aItem.getFileStatus( aStatus ) )
     218         [ #  # ]:          0 :             aFileURL = aStatus.getFileURL();
     219                 :            : 
     220                 :            :     // open file
     221                 :            :     /* SAFE { */
     222         [ #  # ]:          0 :     ReadGuard aReadLock(m_aLock);
     223 [ #  # ][ #  # ]:          0 :     css::uno::Reference< css::frame::XFrame >         xTargetFrame( m_xTargetFrame.get(), css::uno::UNO_QUERY );
     224 [ #  # ][ #  # ]:          0 :     css::uno::Reference< css::util::XURLTransformer > xParser     ( css::util::URLTransformer::create(::comphelper::ComponentContext(m_xFactory).getUNOContext()) );
         [ #  # ][ #  # ]
     225         [ #  # ]:          0 :     aReadLock.unlock();
     226                 :            :     /* } SAFE */
     227 [ #  # ][ #  # ]:          0 :     if (xTargetFrame.is() && xParser.is())
                 [ #  # ]
     228                 :            :     {
     229                 :          0 :         css::util::URL aURL;
     230                 :          0 :         aURL.Complete = aFileURL;
     231 [ #  # ][ #  # ]:          0 :         xParser->parseStrict(aURL);
     232                 :            : 
     233         [ #  # ]:          0 :         css::uno::Reference < css::frame::XDispatchProvider > xProvider( xTargetFrame, css::uno::UNO_QUERY );
     234 [ #  # ][ #  # ]:          0 :         css::uno::Reference< css::frame::XDispatch > xDispatcher = xProvider->queryDispatch( aURL, SPECIALTARGET_DEFAULT, 0 );
                 [ #  # ]
     235         [ #  # ]:          0 :         if ( xDispatcher.is() )
     236 [ #  # ][ #  # ]:          0 :             xDispatcher->dispatch( aURL, css::uno::Sequence < css::beans::PropertyValue >() );
         [ #  # ][ #  # ]
     237 [ #  # ][ #  # ]:          0 :     }
     238                 :          0 : }
     239                 :            : 
     240                 :            : }
     241                 :            : 
     242                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10