LCOV - code coverage report
Current view: top level - fpicker/source/office - asyncfilepicker.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 64 1.6 %
Date: 2015-06-13 12:38:46 Functions: 2 9 22.2 %
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 "asyncfilepicker.hxx"
      22             : #include "iodlg.hxx"
      23             : #include "svtools/fileview.hxx"
      24             : #include <tools/debug.hxx>
      25             : 
      26             : #include <boost/scoped_ptr.hpp>
      27             : 
      28             : 
      29             : namespace svt
      30             : {
      31           0 :     AsyncPickerAction::AsyncPickerAction( SvtFileDialog* _pDialog, SvtFileView* _pView, const Action _eAction )
      32             :         :m_eAction  ( _eAction )
      33             :         ,m_pView    ( _pView   )
      34             :         ,m_pDialog  ( _pDialog )
      35           0 :         ,m_bRunning ( false    )
      36             :     {
      37             :         DBG_ASSERT( m_pDialog, "AsyncPickerAction::AsyncPickerAction: invalid dialog!" );
      38             :         DBG_ASSERT( m_pView, "AsyncPickerAction::AsyncPickerAction: invalid view!" );
      39           0 :     }
      40             : 
      41             : 
      42           0 :     AsyncPickerAction::~AsyncPickerAction()
      43             :     {
      44           0 :     }
      45             : 
      46             : 
      47           0 :     void AsyncPickerAction::cancel()
      48             :     {
      49             :         DBG_TESTSOLARMUTEX();
      50             :             // if this asserts, we'd need to have an own mutex per instance
      51             : 
      52             :         OSL_ENSURE( m_bRunning, "AsyncPickerAction::cancel: not running" );
      53           0 :         if ( m_pView )
      54           0 :             m_pView->CancelRunningAsyncAction();
      55           0 :     }
      56             : 
      57             : 
      58           0 :     void AsyncPickerAction::execute(
      59             :         const OUString& _rURL,
      60             :         const OUString& _rFilter,
      61             :         sal_Int32 _nMinTimeout,
      62             :         sal_Int32 _nMaxTimeout,
      63             :         const OUStringList& rBlackList )
      64             :     {
      65             :         DBG_TESTSOLARMUTEX();
      66             :             // if this asserts, we'd need to have an own mutex per instance
      67             : 
      68           0 :         sal_Int32 nMinTimeout = _nMinTimeout;
      69           0 :         sal_Int32 nMaxTimeout = _nMaxTimeout;
      70             :         // normalizations
      71           0 :         if ( nMinTimeout < 0 )
      72             :             // if negative, this is considered as "do it synchronously"
      73           0 :             nMinTimeout = 0;
      74           0 :         else if ( nMinTimeout < 1000 )
      75           0 :             nMinTimeout = 1000;
      76           0 :         if ( nMaxTimeout <= nMinTimeout )
      77           0 :             nMaxTimeout = nMinTimeout + 30000;
      78             : 
      79           0 :         boost::scoped_ptr< FileViewAsyncAction > pActionDescriptor;
      80           0 :         if ( nMinTimeout )
      81             :         {
      82           0 :             pActionDescriptor.reset( new FileViewAsyncAction );
      83           0 :             pActionDescriptor->nMinTimeout = nMinTimeout;
      84           0 :             pActionDescriptor->nMaxTimeout = nMaxTimeout;
      85           0 :             pActionDescriptor->aFinishHandler = LINK( this, AsyncPickerAction, OnActionDone );
      86             :         }
      87             : 
      88           0 :         FileViewResult eResult = eFailure;
      89           0 :         m_sURL = _rURL;
      90           0 :         switch ( m_eAction )
      91             :         {
      92             :         case ePrevLevel:
      93           0 :             eResult = m_pView->PreviousLevel( pActionDescriptor.get() );
      94           0 :             break;
      95             : 
      96             :         case eOpenURL:
      97           0 :             eResult = m_pView->Initialize( _rURL, _rFilter, pActionDescriptor.get(), rBlackList );
      98           0 :             break;
      99             : 
     100             :         case eExecuteFilter:
     101             :             // preserve the filename (FS: why?)
     102           0 :             m_sFileName = m_pDialog->getCurrentFileText();
     103             :             // execute the new filter
     104           0 :             eResult = m_pView->ExecuteFilter( _rFilter, pActionDescriptor.get() );
     105           0 :             break;
     106             : 
     107             :         default:
     108             :             OSL_FAIL( "AsyncPickerAction::execute: unknown action!" );
     109           0 :             break;
     110             :         }
     111             : 
     112           0 :         acquire();
     113           0 :         if ( ( eResult == eSuccess ) || ( eResult == eFailure ) )
     114             :         {
     115             :             // the handler is only called if the action could not be finished within
     116             :             // the given minimum time period. In case of success, we need to call it
     117             :             // explicitly
     118           0 :             OnActionDone( reinterpret_cast< void* >( eResult ) );
     119             :         }
     120           0 :         else if ( eResult == eStillRunning )
     121             :         {
     122           0 :             m_bRunning = true;
     123           0 :             m_pDialog->onAsyncOperationStarted();
     124           0 :         }
     125           0 :     }
     126             : 
     127             : 
     128           0 :     IMPL_LINK( AsyncPickerAction, OnActionDone, void*, pEmptyArg )
     129             :     {
     130             :         DBG_TESTSOLARMUTEX();
     131             :             // if this asserts, we'd need to have an own mutex per instance
     132             : 
     133           0 :         FileViewResult eResult = static_cast< FileViewResult >( reinterpret_cast< sal_IntPtr >( pEmptyArg ) );
     134             :         OSL_ENSURE( eStillRunning != eResult, "AsyncPickerAction::OnActionDone: invalid result!" );
     135             : 
     136             :         // release once (since we acquired in |execute|), but keep alive until the
     137             :         // end of the method
     138           0 :         ::rtl::Reference< AsyncPickerAction > xKeepAlive( this );
     139           0 :         release();
     140             : 
     141           0 :         m_pDialog->onAsyncOperationFinished();
     142           0 :         m_bRunning = true;
     143             : 
     144           0 :         if ( eFailure == eResult )
     145             :             // TODO: do we need some kind of cleanup here?
     146           0 :             return 0L;
     147             : 
     148           0 :         if ( eTimeout == eResult )
     149             :         {
     150           0 :             SvtFileDialog::displayIOException( m_sURL, ::com::sun::star::ucb::IOErrorCode_CANT_READ );
     151           0 :             return 0L;
     152             :         }
     153             : 
     154             :         OSL_ENSURE( eSuccess == eResult, "AsyncPickerAction::OnActionDone: what else valid results are there?" );
     155             : 
     156           0 :         switch ( m_eAction )
     157             :         {
     158             :         case ePrevLevel:
     159             :         case eOpenURL:
     160           0 :             m_pDialog->UpdateControls( m_pView->GetViewURL() );
     161           0 :             break;
     162             : 
     163             :         case eExecuteFilter:
     164             :             // restore the filename
     165           0 :             m_pView->SetNoSelection();
     166           0 :             m_pDialog->setCurrentFileText( m_sFileName, true );
     167             : 
     168             :             // notify listeners
     169           0 :             m_pDialog->FilterSelect();
     170           0 :             break;
     171             : 
     172             :         default:
     173             :             OSL_FAIL( "AsyncPickerAction::OnActionDone: unknown action!" );
     174           0 :             break;
     175             :         }
     176             : 
     177           0 :         return 1L;
     178             :     }
     179             : 
     180             : 
     181           3 : } // namespace svt
     182             : 
     183             : 
     184             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11