LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/desktop/source/app - dispatchwatcher.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 31 313 9.9 %
Date: 2013-07-09 Functions: 8 16 50.0 %
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 <sfx2/docfile.hxx>
      22             : #include <sfx2/docfilt.hxx>
      23             : #include <sfx2/fcontnr.hxx>
      24             : #include "osl/file.hxx"
      25             : #include "sfx2/app.hxx"
      26             : #include <svl/fstathelper.hxx>
      27             : 
      28             : #include "dispatchwatcher.hxx"
      29             : #include <rtl/ustring.hxx>
      30             : #include <tools/string.hxx>
      31             : #include <comphelper/processfactory.hxx>
      32             : #include <comphelper/synchronousdispatch.hxx>
      33             : #include <com/sun/star/util/XCloseable.hpp>
      34             : #include <com/sun/star/util/CloseVetoException.hpp>
      35             : #include <com/sun/star/task/InteractionHandler.hpp>
      36             : #include <com/sun/star/util/URL.hpp>
      37             : #include <com/sun/star/frame/Desktop.hpp>
      38             : #include <com/sun/star/container/XEnumeration.hpp>
      39             : #include <com/sun/star/frame/XFramesSupplier.hpp>
      40             : #include <com/sun/star/frame/XDispatch.hpp>
      41             : #include <com/sun/star/frame/XComponentLoader.hpp>
      42             : #include <com/sun/star/beans/PropertyValue.hpp>
      43             : #include <com/sun/star/view/XPrintable.hpp>
      44             : #include <com/sun/star/frame/XDispatchProvider.hpp>
      45             : #include <com/sun/star/util/URLTransformer.hpp>
      46             : #include <com/sun/star/util/XURLTransformer.hpp>
      47             : #include <com/sun/star/document/MacroExecMode.hpp>
      48             : #include <com/sun/star/document/UpdateDocMode.hpp>
      49             : #include <com/sun/star/frame/XStorable.hpp>
      50             : 
      51             : #include <tools/urlobj.hxx>
      52             : #include <comphelper/mediadescriptor.hxx>
      53             : 
      54             : #include <vector>
      55             : #include <osl/thread.hxx>
      56             : #include <rtl/instance.hxx>
      57             : 
      58             : using namespace ::osl;
      59             : using namespace ::com::sun::star::uno;
      60             : using namespace ::com::sun::star::util;
      61             : using namespace ::com::sun::star::lang;
      62             : using namespace ::com::sun::star::frame;
      63             : using namespace ::com::sun::star::container;
      64             : using namespace ::com::sun::star::beans;
      65             : using namespace ::com::sun::star::view;
      66             : using namespace ::com::sun::star::task;
      67             : 
      68             : namespace desktop
      69             : {
      70             : 
      71             : String GetURL_Impl(
      72             :     const String& rName, boost::optional< OUString > const & cwdUrl );
      73             : 
      74           0 : struct DispatchHolder
      75             : {
      76           0 :     DispatchHolder( const URL& rURL, Reference< XDispatch >& rDispatch ) :
      77           0 :         aURL( rURL ), xDispatch( rDispatch ) {}
      78             : 
      79             :     URL aURL;
      80             :     OUString cwdUrl;
      81             :     Reference< XDispatch > xDispatch;
      82             : };
      83             : 
      84           0 : static String impl_GetFilterFromExt( OUString aUrl, SfxFilterFlags nFlags,
      85             :                                         String aAppl )
      86             : {
      87           0 :     String aFilter;
      88             :     SfxMedium* pMedium = new SfxMedium( aUrl,
      89           0 :                                         STREAM_STD_READ );
      90             : 
      91           0 :     const SfxFilter *pSfxFilter = NULL;
      92           0 :     if( nFlags == SFX_FILTER_EXPORT )
      93             :     {
      94           0 :         SfxFilterMatcher( aAppl ).GuessFilterIgnoringContent( *pMedium, &pSfxFilter, nFlags, 0 );
      95             :     }
      96             :     else
      97             :     {
      98           0 :         SFX_APP()->GetFilterMatcher().GuessFilter( *pMedium, &pSfxFilter, nFlags, 0 );
      99             :     }
     100             : 
     101           0 :     if( pSfxFilter )
     102             :     {
     103           0 :         if (nFlags == SFX_FILTER_EXPORT)
     104           0 :             aFilter = pSfxFilter->GetFilterName();
     105             :         else
     106           0 :             aFilter = pSfxFilter->GetServiceName();
     107             :     }
     108             : 
     109           0 :     delete pMedium;
     110           0 :     return aFilter;
     111             : }
     112           0 : static OUString impl_GuessFilter( OUString aUrlIn, OUString aUrlOut )
     113             : {
     114             :     /* aAppl can also be set to Factory like scalc, swriter... */
     115           0 :     String aAppl;
     116           0 :     aAppl = impl_GetFilterFromExt( aUrlIn, SFX_FILTER_IMPORT, aAppl );
     117           0 :     return  impl_GetFilterFromExt( aUrlOut, SFX_FILTER_EXPORT, aAppl );
     118             : }
     119             : 
     120             : namespace
     121             : {
     122             :     class theWatcherMutex : public rtl::Static<Mutex, theWatcherMutex> {};
     123             : }
     124             : 
     125         102 : Mutex& DispatchWatcher::GetMutex()
     126             : {
     127         102 :     return theWatcherMutex::get();
     128             : }
     129             : 
     130             : // Create or get the dispatch watcher implementation. This implementation must be
     131             : // a singleton to prevent access to the framework after it wants to terminate.
     132          51 : DispatchWatcher* DispatchWatcher::GetDispatchWatcher()
     133             : {
     134          51 :     static Reference< XInterface > xDispatchWatcher;
     135             :     static DispatchWatcher*        pDispatchWatcher = NULL;
     136             : 
     137          51 :     if ( !xDispatchWatcher.is() )
     138             :     {
     139          51 :         ::osl::MutexGuard aGuard( GetMutex() );
     140             : 
     141          51 :         if ( !xDispatchWatcher.is() )
     142             :         {
     143          51 :             pDispatchWatcher = new DispatchWatcher();
     144             : 
     145             :             // We have to hold a reference to ourself forever to prevent our own destruction.
     146          51 :             xDispatchWatcher = static_cast< cppu::OWeakObject *>( pDispatchWatcher );
     147          51 :         }
     148             :     }
     149             : 
     150          51 :     return pDispatchWatcher;
     151             : }
     152             : 
     153             : 
     154          51 : DispatchWatcher::DispatchWatcher()
     155          51 :     : m_nRequestCount(0)
     156             : {
     157          51 : }
     158             : 
     159             : 
     160         102 : DispatchWatcher::~DispatchWatcher()
     161             : {
     162         102 : }
     163             : 
     164             : 
     165          51 : sal_Bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequestsList, bool bNoTerminate )
     166             : {
     167          51 :     Reference< XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
     168             : 
     169          51 :     DispatchList::const_iterator    p;
     170         102 :     std::vector< DispatchHolder >   aDispatches;
     171         102 :     OUString                 aAsTemplateArg( "AsTemplate" );
     172          51 :     sal_Bool                        bSetInputFilter = sal_False;
     173         102 :     OUString                 aForcedInputFilter;
     174             : 
     175          51 :     for ( p = aDispatchRequestsList.begin(); p != aDispatchRequestsList.end(); ++p )
     176             :     {
     177           0 :         const DispatchRequest&  aDispatchRequest = *p;
     178             : 
     179             :         // create parameter array
     180           0 :         sal_Int32 nCount = 4;
     181           0 :         if ( !aDispatchRequest.aPreselectedFactory.isEmpty() )
     182           0 :             nCount++;
     183             : 
     184             :         // Set Input Filter
     185           0 :         if ( aDispatchRequest.aRequestType == REQUEST_INFILTER )
     186             :         {
     187           0 :             bSetInputFilter = sal_True;
     188           0 :             aForcedInputFilter = aDispatchRequest.aURL;
     189           0 :             OfficeIPCThread::RequestsCompleted( 1 );
     190           0 :             continue;
     191             :         }
     192             : 
     193             :         // we need more properties for a print/print to request
     194           0 :         if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
     195           0 :              aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
     196           0 :              aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ||
     197           0 :              aDispatchRequest.aRequestType == REQUEST_CONVERSION)
     198           0 :             nCount++;
     199             : 
     200           0 :         Sequence < PropertyValue > aArgs( nCount );
     201             : 
     202             :         // mark request as user interaction from outside
     203           0 :         aArgs[0].Name = "Referer";
     204           0 :         aArgs[0].Value <<= OUString("private:OpenEvent");
     205             : 
     206           0 :         if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
     207           0 :              aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
     208           0 :              aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ||
     209           0 :              aDispatchRequest.aRequestType == REQUEST_CONVERSION)
     210             :         {
     211           0 :             aArgs[1].Name = "ReadOnly";
     212           0 :             aArgs[2].Name = "OpenNewView";
     213           0 :             aArgs[3].Name = "Hidden";
     214           0 :             aArgs[4].Name = "Silent";
     215             :         }
     216             :         else
     217             :         {
     218             :             Reference < XInteractionHandler2 > xInteraction(
     219           0 :                 InteractionHandler::createWithParent(::comphelper::getProcessComponentContext(), 0) );
     220             : 
     221           0 :             aArgs[1].Name = "InteractionHandler";
     222           0 :             aArgs[1].Value <<= xInteraction;
     223             : 
     224           0 :             sal_Int16 nMacroExecMode = ::com::sun::star::document::MacroExecMode::USE_CONFIG;
     225           0 :             aArgs[2].Name = "MacroExecutionMode";
     226           0 :             aArgs[2].Value <<= nMacroExecMode;
     227             : 
     228           0 :             sal_Int16 nUpdateDoc = ::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG;
     229           0 :             aArgs[3].Name = "UpdateDocMode";
     230           0 :             aArgs[3].Value <<= nUpdateDoc;
     231             :         }
     232             : 
     233           0 :         if ( !aDispatchRequest.aPreselectedFactory.isEmpty() )
     234             :         {
     235           0 :             aArgs[nCount-1].Name = ::comphelper::MediaDescriptor::PROP_DOCUMENTSERVICE();
     236           0 :             aArgs[nCount-1].Value <<= aDispatchRequest.aPreselectedFactory;
     237             :         }
     238             : 
     239           0 :         String aName( GetURL_Impl( aDispatchRequest.aURL, aDispatchRequest.aCwdUrl ) );
     240           0 :         OUString aTarget("_default");
     241             : 
     242           0 :         if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
     243           0 :              aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
     244           0 :              aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ||
     245           0 :              aDispatchRequest.aRequestType == REQUEST_CONVERSION)
     246             :         {
     247             :             // documents opened for printing are opened readonly because they must be opened as a new document and this
     248             :             // document could be open already
     249           0 :             aArgs[1].Value <<= sal_True;
     250             : 
     251             :             // always open a new document for printing, because it must be disposed afterwards
     252           0 :             aArgs[2].Value <<= sal_True;
     253             : 
     254             :             // printing is done in a hidden view
     255           0 :             aArgs[3].Value <<= sal_True;
     256             : 
     257             :             // load document for printing without user interaction
     258           0 :             aArgs[4].Value <<= sal_True;
     259             : 
     260             :             // hidden documents should never be put into open tasks
     261           0 :             aTarget = "_blank";
     262             :         }
     263             :         // load the document ... if they are loadable!
     264             :         // Otherwise try to dispatch it ...
     265           0 :         Reference < XPrintable > xDoc;
     266           0 :         if(
     267           0 :             ( aName.CompareToAscii( ".uno"  , 4 ) == COMPARE_EQUAL )  ||
     268           0 :             ( aName.CompareToAscii( "slot:" , 5 ) == COMPARE_EQUAL )  ||
     269           0 :             ( aName.CompareToAscii( "macro:", 6 ) == COMPARE_EQUAL )  ||
     270           0 :             ( aName.CompareToAscii("vnd.sun.star.script", 19) == COMPARE_EQUAL)
     271             :           )
     272             :         {
     273             :             // Attention: URL must be parsed full. Otherwise some detections on it will fail!
     274             :             // It doesnt matter, if parser isn't available. Because; We try loading of URL then ...
     275           0 :             URL             aURL ;
     276           0 :             aURL.Complete = aName;
     277             : 
     278           0 :             Reference < XDispatch >         xDispatcher ;
     279           0 :             Reference < XURLTransformer >   xParser     ( URLTransformer::create(::comphelper::getProcessComponentContext()) );
     280             : 
     281           0 :             if( xParser.is() == sal_True )
     282           0 :                 xParser->parseStrict( aURL );
     283             : 
     284           0 :             xDispatcher = xDesktop->queryDispatch( aURL, OUString(), 0 );
     285             : 
     286           0 :             if( xDispatcher.is() == sal_True )
     287             :             {
     288             :                 {
     289           0 :                     ::osl::ClearableMutexGuard aGuard( GetMutex() );
     290             :                     // Remember request so we can find it in statusChanged!
     291           0 :                     m_aRequestContainer.insert( DispatchWatcherHashMap::value_type( aURL.Complete, (sal_Int32)1 ) );
     292           0 :                     m_nRequestCount++;
     293             :                 }
     294             : 
     295             :                 // Use local vector to store dispatcher because we have to fill our request container before
     296             :                 // we can dispatch. Otherwise it would be possible that statusChanged is called before we dispatched all requests!!
     297           0 :                 aDispatches.push_back( DispatchHolder( aURL, xDispatcher ));
     298           0 :             }
     299             :         }
     300           0 :         else if ( ( aName.CompareToAscii( "service:"  , 8 ) == COMPARE_EQUAL ) )
     301             :         {
     302             :             // TODO: the dispatch has to be done for loadComponentFromURL as well. Please ask AS for more details.
     303           0 :             URL             aURL ;
     304           0 :             aURL.Complete = aName;
     305             : 
     306           0 :             Reference < XDispatch >         xDispatcher ;
     307           0 :             Reference < XURLTransformer >   xParser     ( URLTransformer::create(::comphelper::getProcessComponentContext()) );
     308             : 
     309           0 :             if( xParser.is() == sal_True )
     310           0 :                 xParser->parseStrict( aURL );
     311             : 
     312           0 :             xDispatcher = xDesktop->queryDispatch( aURL, OUString(), 0 );
     313             : 
     314           0 :             if( xDispatcher.is() == sal_True )
     315             :             {
     316             :                 try
     317             :                 {
     318             :                     // We have to be listener to catch errors during dispatching URLs.
     319             :                     // Otherwise it would be possible to have an office running without an open
     320             :                     // window!!
     321           0 :                     Sequence < PropertyValue > aArgs2(1);
     322           0 :                     aArgs2[0].Name    = "SynchronMode";
     323           0 :                     aArgs2[0].Value <<= sal_True;
     324           0 :                     Reference < XNotifyingDispatch > xDisp( xDispatcher, UNO_QUERY );
     325           0 :                     if ( xDisp.is() )
     326           0 :                         xDisp->dispatchWithNotification( aURL, aArgs2, DispatchWatcher::GetDispatchWatcher() );
     327             :                     else
     328           0 :                         xDispatcher->dispatch( aURL, aArgs2 );
     329             :                 }
     330           0 :                 catch (const ::com::sun::star::uno::Exception&)
     331             :                 {
     332           0 :                     OUString aMsg = "Desktop::OpenDefault() IllegalArgumentException while calling XNotifyingDispatch: ";
     333           0 :                     OSL_FAIL( OUStringToOString(aMsg, RTL_TEXTENCODING_ASCII_US).getStr());
     334             :                 }
     335           0 :             }
     336             :         }
     337             :         else
     338             :         {
     339           0 :             INetURLObject aObj( aName );
     340           0 :             if ( aObj.GetProtocol() == INET_PROT_PRIVATE )
     341           0 :                 aTarget = "_default";
     342             : 
     343             :             // Set "AsTemplate" argument according to request type
     344           0 :             if ( aDispatchRequest.aRequestType == REQUEST_FORCENEW ||
     345           0 :                  aDispatchRequest.aRequestType == REQUEST_FORCEOPEN     )
     346             :             {
     347           0 :                 sal_Int32 nIndex = aArgs.getLength();
     348           0 :                 aArgs.realloc( nIndex+1 );
     349           0 :                 aArgs[nIndex].Name = aAsTemplateArg;
     350           0 :                 if ( aDispatchRequest.aRequestType == REQUEST_FORCENEW )
     351           0 :                     aArgs[nIndex].Value <<= sal_True;
     352             :                 else
     353           0 :                     aArgs[nIndex].Value <<= sal_False;
     354             :             }
     355             : 
     356             :             // if we are called in viewmode, open document read-only
     357           0 :             if(aDispatchRequest.aRequestType == REQUEST_VIEW) {
     358           0 :                 sal_Int32 nIndex = aArgs.getLength();
     359           0 :                 aArgs.realloc(nIndex+1);
     360           0 :                 aArgs[nIndex].Name = "ReadOnly";
     361           0 :                 aArgs[nIndex].Value <<= sal_True;
     362             :             }
     363             : 
     364             :             // if we are called with -start set Start in mediadescriptor
     365           0 :             if(aDispatchRequest.aRequestType == REQUEST_START) {
     366           0 :                 sal_Int32 nIndex = aArgs.getLength();
     367           0 :                 aArgs.realloc(nIndex+1);
     368           0 :                 aArgs[nIndex].Name = "StartPresentation";
     369           0 :                 aArgs[nIndex].Value <<= sal_True;
     370             :             }
     371             : 
     372             :             // Force input filter, if possible
     373           0 :             if( bSetInputFilter )
     374             :             {
     375           0 :                 sal_Int32 nIndex = aArgs.getLength();
     376           0 :                 aArgs.realloc(nIndex+1);
     377           0 :                 aArgs[nIndex].Name = "FilterName";
     378           0 :                 aArgs[nIndex].Value <<= aForcedInputFilter;
     379             :             }
     380             : 
     381             :             // This is a synchron loading of a component so we don't have to deal with our statusChanged listener mechanism.
     382             :             try
     383             :             {
     384           0 :                 xDoc = Reference < XPrintable >( ::comphelper::SynchronousDispatch::dispatch( xDesktop, aName, aTarget, 0, aArgs ), UNO_QUERY );
     385             :             }
     386           0 :             catch (const ::com::sun::star::lang::IllegalArgumentException& iae)
     387             :             {
     388             :                 OUString aMsg = "Dispatchwatcher IllegalArgumentException while calling loadComponentFromURL: "
     389           0 :                     + iae.Message;
     390           0 :                 OSL_FAIL( OUStringToOString(aMsg, RTL_TEXTENCODING_ASCII_US).getStr());
     391             :             }
     392           0 :             catch (const com::sun::star::io::IOException& ioe)
     393             :             {
     394             :                 OUString aMsg = "Dispatchwatcher IOException while calling loadComponentFromURL: "
     395           0 :                     + ioe.Message;
     396           0 :                 OSL_FAIL( OUStringToOString(aMsg, RTL_TEXTENCODING_ASCII_US).getStr());
     397             :             }
     398           0 :             if ( aDispatchRequest.aRequestType == REQUEST_OPEN ||
     399           0 :                  aDispatchRequest.aRequestType == REQUEST_VIEW ||
     400           0 :                  aDispatchRequest.aRequestType == REQUEST_START ||
     401           0 :                  aDispatchRequest.aRequestType == REQUEST_FORCEOPEN ||
     402           0 :                  aDispatchRequest.aRequestType == REQUEST_FORCENEW      )
     403             :             {
     404             :                 // request is completed
     405           0 :                 OfficeIPCThread::RequestsCompleted( 1 );
     406             :             }
     407           0 :             else if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
     408           0 :                       aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
     409           0 :                       aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ||
     410           0 :                       aDispatchRequest.aRequestType == REQUEST_CONVERSION )
     411             :             {
     412           0 :                 if ( xDoc.is() )
     413             :                 {
     414           0 :                     if ( aDispatchRequest.aRequestType == REQUEST_CONVERSION ) {
     415           0 :                         Reference< XStorable > xStorable( xDoc, UNO_QUERY );
     416           0 :                         if ( xStorable.is() ) {
     417           0 :                             OUString aParam = aDispatchRequest.aPrinterName;
     418           0 :                             sal_Int32 nPathIndex =  aParam.lastIndexOf( ';' );
     419           0 :                             sal_Int32 nFilterIndex = aParam.indexOf( ':' );
     420           0 :                             if( nPathIndex < nFilterIndex )
     421           0 :                                 nFilterIndex = -1;
     422           0 :                             OUString aFilterOut=aParam.copy( nPathIndex+1 );
     423           0 :                             OUString aFilter;
     424           0 :                             OUString aFilterExt;
     425           0 :                             sal_Bool bGuess = sal_False;
     426             : 
     427           0 :                             if( nFilterIndex >= 0 )
     428             :                             {
     429           0 :                                 aFilter = aParam.copy( nFilterIndex+1, nPathIndex-nFilterIndex-1 );
     430           0 :                                 aFilterExt = aParam.copy( 0, nFilterIndex );
     431             :                             }
     432             :                             else
     433             :                             {
     434             :                                 // Guess
     435           0 :                                 bGuess = sal_True;
     436           0 :                                 aFilterExt = aParam.copy( 0, nPathIndex );
     437             :                             }
     438           0 :                             INetURLObject aOutFilename( aObj );
     439           0 :                             aOutFilename.SetExtension( aFilterExt );
     440           0 :                             FileBase::getFileURLFromSystemPath( aFilterOut, aFilterOut );
     441           0 :                             OUString aOutFile = aFilterOut+
     442           0 :                                                      "/" +
     443           0 :                                                      aOutFilename.getName();
     444             : 
     445           0 :                             if ( bGuess )
     446             :                             {
     447           0 :                                 aFilter = impl_GuessFilter( aName, aOutFile );
     448             :                             }
     449             : 
     450           0 :                             Sequence<PropertyValue> conversionProperties( 2 );
     451           0 :                             conversionProperties[0].Name = "Overwrite";
     452           0 :                             conversionProperties[0].Value <<= sal_True;
     453             : 
     454           0 :                             conversionProperties[1].Name = "FilterName";
     455           0 :                             conversionProperties[1].Value <<= aFilter;
     456             : 
     457           0 :                             OUString aTempName;
     458           0 :                             FileBase::getSystemPathFromFileURL( aName, aTempName );
     459           0 :                             OString aSource8 = OUStringToOString ( aTempName, RTL_TEXTENCODING_UTF8 );
     460           0 :                             FileBase::getSystemPathFromFileURL( aOutFile, aTempName );
     461           0 :                             OString aTargetURL8 = OUStringToOString(aTempName, RTL_TEXTENCODING_UTF8 );
     462             :                             printf("convert %s -> %s using %s\n", aSource8.getStr(), aTargetURL8.getStr(),
     463           0 :                                    OUStringToOString( aFilter, RTL_TEXTENCODING_UTF8 ).getStr());
     464           0 :                             if( FStatHelper::IsDocument(aOutFile) )
     465           0 :                                 printf("Overwriting: %s\n",OUStringToOString( aTempName, RTL_TEXTENCODING_UTF8 ).getStr() );
     466             :                             try
     467             :                             {
     468           0 :                                 xStorable->storeToURL( aOutFile, conversionProperties );
     469             :                             }
     470           0 :                             catch (const Exception&)
     471             :                             {
     472           0 :                                 fprintf( stderr, "Error: Please reverify input parameters...\n" );
     473           0 :                             }
     474           0 :                         }
     475           0 :                     } else if ( aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ) {
     476           0 :                         OUString aParam = aDispatchRequest.aPrinterName;
     477           0 :                         sal_Int32 nPathIndex =  aParam.lastIndexOf( ';' );
     478             : 
     479           0 :                         OUString aFilterOut;
     480           0 :                         OUString aPrinterName;
     481           0 :                         if( nPathIndex != -1 )
     482           0 :                             aFilterOut=aParam.copy( nPathIndex+1 );
     483           0 :                         if( nPathIndex != 0 )
     484           0 :                             aPrinterName=aParam.copy( 0, nPathIndex );
     485             : 
     486           0 :                         INetURLObject aOutFilename( aObj );
     487           0 :                         aOutFilename.SetExtension( "ps" );
     488           0 :                         FileBase::getFileURLFromSystemPath( aFilterOut, aFilterOut );
     489           0 :                         OUString aOutFile = aFilterOut+
     490           0 :                             "/" +
     491           0 :                             aOutFilename.getName();
     492             : 
     493           0 :                         OUString aTempName;
     494           0 :                         FileBase::getSystemPathFromFileURL( aName, aTempName );
     495           0 :                         OString aSource8 = OUStringToOString ( aTempName, RTL_TEXTENCODING_UTF8 );
     496           0 :                         FileBase::getSystemPathFromFileURL( aOutFile, aTempName );
     497           0 :                         OString aTargetURL8 = OUStringToOString(aTempName, RTL_TEXTENCODING_UTF8 );
     498             :                         printf("print %s -> %s using %s\n", aSource8.getStr(), aTargetURL8.getStr(),
     499           0 :                                aPrinterName.isEmpty() ?
     500           0 :                                                      "<default_printer>" : OUStringToOString( aPrinterName, RTL_TEXTENCODING_UTF8 ).getStr() );
     501             : 
     502             :                         // create the custom printer, if given
     503           0 :                         Sequence < PropertyValue > aPrinterArgs( 1 );
     504           0 :                         if( !aPrinterName.isEmpty() )
     505             :                         {
     506           0 :                             aPrinterArgs[0].Name = "Name";
     507           0 :                             aPrinterArgs[0].Value <<= aPrinterName;
     508           0 :                             xDoc->setPrinter( aPrinterArgs );
     509             :                         }
     510             : 
     511             :                         // print ( also without user interaction )
     512           0 :                         aPrinterArgs.realloc(2);
     513           0 :                         aPrinterArgs[0].Name = "FileName";
     514           0 :                         aPrinterArgs[0].Value <<= aOutFile;
     515           0 :                         aPrinterArgs[1].Name = "Wait";
     516           0 :                         aPrinterArgs[1].Value <<= ( sal_Bool ) sal_True;
     517           0 :                         xDoc->print( aPrinterArgs );
     518             :                     } else {
     519           0 :                         if ( aDispatchRequest.aRequestType == REQUEST_PRINTTO )
     520             :                         {
     521             :                             // create the printer
     522           0 :                             Sequence < PropertyValue > aPrinterArgs( 1 );
     523           0 :                             aPrinterArgs[0].Name = "Name";
     524           0 :                             aPrinterArgs[0].Value <<= OUString( aDispatchRequest.aPrinterName );
     525           0 :                             xDoc->setPrinter( aPrinterArgs );
     526             :                         }
     527             : 
     528             :                         // print ( also without user interaction )
     529           0 :                         Sequence < PropertyValue > aPrinterArgs( 1 );
     530           0 :                         aPrinterArgs[0].Name = "Wait";
     531           0 :                         aPrinterArgs[0].Value <<= ( sal_Bool ) sal_True;
     532           0 :                         xDoc->print( aPrinterArgs );
     533             :                     }
     534             :                 }
     535             :                 else
     536             :                 {
     537             :                     // place error message here ...
     538             :                 }
     539             : 
     540             :                 // remove the document
     541             :                 try
     542             :                 {
     543           0 :                     Reference < XCloseable > xClose( xDoc, UNO_QUERY );
     544           0 :                     if ( xClose.is() )
     545           0 :                         xClose->close( sal_True );
     546             :                     else
     547             :                     {
     548           0 :                         Reference < XComponent > xComp( xDoc, UNO_QUERY );
     549           0 :                         if ( xComp.is() )
     550           0 :                             xComp->dispose();
     551           0 :                     }
     552             :                 }
     553           0 :                 catch (const com::sun::star::util::CloseVetoException&)
     554             :                 {
     555             :                 }
     556             : 
     557             :                 // request is completed
     558           0 :                 OfficeIPCThread::RequestsCompleted( 1 );
     559           0 :             }
     560             :         }
     561           0 :     }
     562             : 
     563          51 :     if ( !aDispatches.empty() )
     564             :     {
     565             :         // Execute all asynchronous dispatches now after we placed them into our request container!
     566           0 :         Sequence < PropertyValue > aArgs( 2 );
     567           0 :         aArgs[0].Name = "Referer";
     568           0 :         aArgs[0].Value <<= OUString("private:OpenEvent");
     569           0 :         aArgs[1].Name = "SynchronMode";
     570           0 :         aArgs[1].Value <<= sal_True;
     571             : 
     572           0 :         for ( sal_uInt32 n = 0; n < aDispatches.size(); n++ )
     573             :         {
     574           0 :             Reference< XDispatch > xDispatch = aDispatches[n].xDispatch;
     575           0 :             Reference < XNotifyingDispatch > xDisp( xDispatch, UNO_QUERY );
     576           0 :             if ( xDisp.is() )
     577           0 :                 xDisp->dispatchWithNotification( aDispatches[n].aURL, aArgs, this );
     578             :             else
     579             :             {
     580           0 :                 ::osl::ClearableMutexGuard aGuard( GetMutex() );
     581           0 :                 m_nRequestCount--;
     582           0 :                 aGuard.clear();
     583           0 :                 xDispatch->dispatch( aDispatches[n].aURL, aArgs );
     584             :             }
     585           0 :         }
     586             :     }
     587             : 
     588         102 :     ::osl::ClearableMutexGuard aGuard( GetMutex() );
     589          51 :     bool bEmpty = (m_nRequestCount == 0);
     590          51 :     aGuard.clear();
     591             : 
     592             :     // No more asynchronous requests?
     593             :     // The requests are removed from the request container after they called back to this
     594             :     // implementation via statusChanged!!
     595          51 :     if ( bEmpty && !bNoTerminate /*m_aRequestContainer.empty()*/ )
     596             :     {
     597             :         // We have to check if we have an open task otherwise we have to shutdown the office.
     598           0 :         aGuard.clear();
     599           0 :         Reference< XElementAccess > xList( xDesktop->getFrames(), UNO_QUERY );
     600             : 
     601           0 :         if ( !xList->hasElements() )
     602             :         {
     603             :             // We don't have any task open so we have to shutdown ourself!!
     604           0 :             return xDesktop->terminate();
     605           0 :         }
     606             :     }
     607             : 
     608         102 :     return sal_False;
     609             : }
     610             : 
     611             : 
     612           0 : void SAL_CALL DispatchWatcher::disposing( const ::com::sun::star::lang::EventObject& )
     613             : throw(::com::sun::star::uno::RuntimeException)
     614             : {
     615           0 : }
     616             : 
     617             : 
     618           0 : void SAL_CALL DispatchWatcher::dispatchFinished( const DispatchResultEvent& ) throw( RuntimeException )
     619             : {
     620           0 :     osl::ClearableMutexGuard aGuard( GetMutex() );
     621           0 :     sal_Int16 nCount = --m_nRequestCount;
     622           0 :     aGuard.clear();
     623           0 :     OfficeIPCThread::RequestsCompleted( 1 );
     624           0 :     if ( !nCount && !OfficeIPCThread::AreRequestsPending() )
     625             :     {
     626             :         // We have to check if we have an open task otherwise we have to shutdown the office.
     627           0 :         Reference< XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
     628           0 :         Reference< XElementAccess > xList( xDesktop->getFrames(), UNO_QUERY );
     629             : 
     630           0 :         if ( !xList->hasElements() )
     631             :         {
     632             :             // We don't have any task open so we have to shutdown ourself!!
     633           0 :             xDesktop->terminate();
     634           0 :         }
     635           0 :     }
     636           0 : }
     637             : 
     638         249 : }
     639             : 
     640             : 
     641             : 
     642             : 
     643             : 
     644             : 
     645             : 
     646             : 
     647             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10