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

Generated by: LCOV version 1.10