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

Generated by: LCOV version 1.10