Files
libreoffice/desktop/source/app/dispatchwatcher.cxx

680 lines
29 KiB
C++
Raw Normal View History

/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_desktop.hxx"
#include <sfx2/docfile.hxx>
#include <sfx2/docfilt.hxx>
#include <sfx2/fcontnr.hxx>
#include "osl/file.hxx"
#include <svl/fstathelper.hxx>
#include "dispatchwatcher.hxx"
#include <rtl/ustring.hxx>
#include <tools/string.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/synchronousdispatch.hxx>
#include <com/sun/star/util/XCloseable.hpp>
#include <com/sun/star/util/CloseVetoException.hpp>
2002-03-18 12:12:57 +00:00
#include <com/sun/star/task/XInteractionHandler.hpp>
#include <com/sun/star/util/URL.hpp>
#include <com/sun/star/frame/XDesktop.hpp>
#include <com/sun/star/container/XEnumeration.hpp>
#include <com/sun/star/frame/XFramesSupplier.hpp>
#include <com/sun/star/frame/XDispatch.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/view/XPrintable.hpp>
#include <com/sun/star/frame/XDispatchProvider.hpp>
#include <com/sun/star/util/XURLTransformer.hpp>
#include <com/sun/star/document/MacroExecMode.hpp>
2002-07-17 13:27:39 +00:00
#include <com/sun/star/document/UpdateDocMode.hpp>
#include <com/sun/star/frame/XStorable.hpp>
2001-11-28 10:26:26 +00:00
#include <tools/urlobj.hxx>
#include <comphelper/mediadescriptor.hxx>
2001-11-28 10:26:26 +00:00
#include <vector>
#include <osl/thread.hxx>
using ::rtl::OUString;
using namespace ::osl;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::view;
namespace desktop
{
String GetURL_Impl(
const String& rName, boost::optional< rtl::OUString > const & cwdUrl );
struct DispatchHolder
{
DispatchHolder( const URL& rURL, Reference< XDispatch >& rDispatch ) :
aURL( rURL ), xDispatch( rDispatch ) {}
URL aURL;
rtl::OUString cwdUrl;
Reference< XDispatch > xDispatch;
};
static String impl_GetFilterFromExt( OUString aUrl, SfxFilterFlags nFlags,
String aAppl )
{
String aFilter;
SfxMedium* pMedium = new SfxMedium( aUrl,
STREAM_STD_READ, FALSE );
const SfxFilter *pSfxFilter = NULL;
SfxFilterMatcher aMatcher;
if( nFlags == SFX_FILTER_EXPORT )
aMatcher = SfxFilterMatcher( aAppl );
aMatcher.GuessFilterIgnoringContent( *pMedium, &pSfxFilter, nFlags, 0 );
if( pSfxFilter )
aFilter = ( nFlags == SFX_FILTER_EXPORT ) ? pSfxFilter->GetFilterName() :
pSfxFilter->GetServiceName();
delete pMedium;
return aFilter;
}
static OUString impl_GuessFilter( OUString aUrlIn, OUString aUrlOut )
{
/* aAppl can also be set to Factory like scalc, swriter... */
String aAppl;
aAppl = impl_GetFilterFromExt( aUrlIn, SFX_FILTER_IMPORT, aAppl );
return impl_GetFilterFromExt( aUrlOut, SFX_FILTER_EXPORT, aAppl );
}
Mutex* DispatchWatcher::pWatcherMutex = NULL;
Mutex& DispatchWatcher::GetMutex()
{
if ( !pWatcherMutex )
{
::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
if ( !pWatcherMutex )
pWatcherMutex = new osl::Mutex();
}
return *pWatcherMutex;
}
// Create or get the dispatch watcher implementation. This implementation must be
// a singleton to prevent access to the framework after it wants to terminate.
DispatchWatcher* DispatchWatcher::GetDispatchWatcher()
{
static Reference< XInterface > xDispatchWatcher;
static DispatchWatcher* pDispatchWatcher = NULL;
if ( !xDispatchWatcher.is() )
{
::osl::MutexGuard aGuard( GetMutex() );
if ( !xDispatchWatcher.is() )
{
pDispatchWatcher = new DispatchWatcher();
// We have to hold a reference to ourself forever to prevent our own destruction.
xDispatchWatcher = static_cast< cppu::OWeakObject *>( pDispatchWatcher );
}
}
return pDispatchWatcher;
}
DispatchWatcher::DispatchWatcher()
CWS-TOOLING: integrate CWS fwk116 2009-09-03 Mikhail Voytenko #i101453# write the default values for old entries 2009-09-03 Mikhail Voytenko #i101453# let the new default value be used 2009-09-03 Mikhail Voytenko #i101453# revert the change for xslt-transformation, the duplicate nodes should not be allowed 2009-09-03 Mikhail Voytenko #i101453# allow duplicate nodes for different modules 2009-09-03 Mikhail Voytenko #i101453# fix the special mac installation 2009-09-02 Mikhail Voytenko #i101453# correct the usage of configuration files 2009-09-02 Mikhail Voytenko #i10000# fix warning 2009-09-02 Mikhail Voytenko #i10000# fix warning 2009-09-02 Mikhail Voytenko #i96918# try to open the file for editing always 2009-09-02 Mikhail Voytenko #i51058# remove unused strings 2009-09-02 Mikhail Voytenko #i51058# remove unused strings 2009-09-01 Mikhail Voytenko #i10000# fix typo 2009-08-30 Mikhail Voytenko Rebase on DEV300_m56 2009-08-19 Mikhail Voytenko #i101732# do not generate a transparent bitmap for thumbnail 2009-08-13 Mikhail Voytenko #i101453# do not use system temporary location on Mac 2009-08-13 Mikhail Voytenko #i101453# do not use system temporary location on Mac 2009-08-07 Mikhail Voytenko #i103617# fix warning 2009-07-31 Carsten Driesner #i103924# Fix wrong number of arguments 2009-07-31 Mikhail Voytenko #i101207# integrate the patch 2009-07-31 Mikhail Voytenko #i103783# integrate the patch; get rid of CRLF 2009-07-31 Mikhail Voytenko #i97969# integrate the patch 2009-07-27 Carsten Driesner #i103423# Use correct request count in the ctor. Don't descrease value before checking the request count
2009-09-16 16:17:27 +00:00
: m_nRequestCount(0)
{
}
DispatchWatcher::~DispatchWatcher()
{
}
CWS-TOOLING: integrate CWS vcl97 2008-12-11 20:47:52 +0100 pl r265361 : #i93173# revert change, event listeners on the toolbar can lead to crashes 2008-12-11 17:55:54 +0100 pl r265344 : #i92715# fix some border cases 2008-12-11 16:36:01 +0100 pl r265334 : remove forgotten debug printf 2008-12-11 15:54:25 +0100 pl r265323 : add missing pointer initializer 2008-12-11 14:08:44 +0100 as r265297 : #i86520# dont show start module twice 2008-12-11 12:56:34 +0100 as r265289 : #i86520# dont show start module twice 2008-12-11 12:22:18 +0100 pl r265280 : fix a snafu 2008-12-11 12:15:27 +0100 hdu r265279 : #i96549# change some dbg_assert to dbg_warn 2008-12-11 11:57:22 +0100 pl r265276 : #i86520# startcenter on dock item click for mac 2008-12-11 11:31:47 +0100 pl r265271 : #i96964# fix a wrong condition 2008-12-11 11:21:49 +0100 as r265268 : #i86520# new framework slot for ShowStartModule 2008-12-11 10:17:32 +0100 hdu r265251 : #i97127# use fontconfig fallbacks for psprinting too (thanks CMC!) 2008-12-09 10:18:41 +0100 hdu r265060 : #i96549# workaround MAC_OS_X_VERSION_* macros not defined in older SDKs 2008-12-09 09:39:47 +0100 hdu r265057 : #i89650# workaround bogus device resolutions 2008-12-09 09:14:23 +0100 hdu r265054 : #i96549# set MAC_OS_X_VERSION_MIN_REQUIRED=1040 2008-12-08 19:17:42 +0100 pl r265016 : CWS-TOOLING: rebase CWS vcl97 to trunk@264807 (milestone: DEV300:m37) 2008-12-08 16:06:58 +0100 hdu r265004 : #i96549# set MAC_OS_X_VERSION_MIN_REQUIRED=1040 only for the Aqua port 2008-12-08 12:16:26 +0100 hdu r264988 : #i96549# prepare for MAC_OS_X_VERSION_MIN_REQUIRED>=1050 2008-12-08 11:59:25 +0100 hdu r264982 : #i96549# set MAC_OS_X_VERSION_MIN_REQUIRED=1040 2008-12-04 18:19:43 +0100 pl r264866 : #i86520# install a handler to be called on dock icon clicked 2008-12-03 13:04:32 +0100 pl r264769 : #i96551# on quartz build neither gtk nor cups in psprint is needed 2008-11-26 15:07:07 +0100 hdu r264400 : #i96317# adjust to extented SAL_DISABLE_FC_SUBST semantic 2008-11-21 16:15:31 +0100 pl r264147 : #i94443# generalize focus behavior when a child window becomes invisible 2008-11-21 15:45:03 +0100 pl r264144 : #i96433# improve torn off toolbar behavior 2008-11-21 11:50:01 +0100 pl r264119 : #i90083# improve key event dispatching 2008-11-20 17:28:03 +0100 pl r264076 : #i92715# do not execute app events during document recovery 2008-11-20 15:04:32 +0100 pl r264057 : #i92224# #i93249# more aqua key codes 2008-11-20 14:03:00 +0100 pl r264052 : #i92224# #i93249# remove debug printf 2008-11-20 14:00:29 +0100 pl r264049 : #i92224# #i93249# more aqua key codes 2008-11-20 13:59:34 +0100 pl r264048 : #i92224# #i93249# more aqua key codes 2008-11-20 13:52:38 +0100 pl r264047 : #i92224# #i93249# more aqua key codes 2008-11-19 18:42:17 +0100 pl r264017 : #i93249# support some mac specifc key codes: select to line end/begin 2008-11-19 18:40:26 +0100 pl r264016 : #i93249# support some mac specifc key codes: select to line end/begin 2008-11-19 18:32:31 +0100 pl r264014 : #i92224# support some mac specifc key codes: select to line end/begin 2008-11-19 17:34:50 +0100 pl r264009 : #i92224# some more needed keycodes 2008-11-19 16:11:33 +0100 pl r264003 : #i93249# support some mac specifc key codes 2008-11-19 16:10:31 +0100 pl r264002 : #i93249# support some mac specifc key codes 2008-11-19 15:50:03 +0100 pl r264000 : #i93249# support some mac specifc key codes 2008-11-19 14:17:41 +0100 pl r263993 : #i90015# strip appended parenthese entries from menubar 2008-11-17 18:30:37 +0100 pl r263737 : #i94601# emulate menu functionality for non vcl dialogs 2008-11-17 17:31:12 +0100 pl r263731 : #i95263# set inactive tab color on mac more distinct from the active tab color 2008-11-17 17:13:38 +0100 pl r263729 : #i93173# delete toolbar window in a more stack aware manner
2009-01-02 15:26:18 +00:00
sal_Bool DispatchWatcher::executeDispatchRequests( const DispatchList& aDispatchRequestsList, bool bNoTerminate )
{
Reference< XComponentLoader > xDesktop( ::comphelper::getProcessServiceFactory()->createInstance(
OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")) ),
UNO_QUERY );
DispatchList::const_iterator p;
std::vector< DispatchHolder > aDispatches;
2002-02-26 07:16:22 +00:00
::rtl::OUString aAsTemplateArg( RTL_CONSTASCII_USTRINGPARAM( "AsTemplate"));
sal_Bool bSetInputFilter = sal_False;
::rtl::OUString aForcedInputFilter;
for ( p = aDispatchRequestsList.begin(); p != aDispatchRequestsList.end(); p++ )
{
const DispatchRequest& aDispatchRequest = *p;
// create parameter array
sal_Int32 nCount = 4;
if ( aDispatchRequest.aPreselectedFactory.getLength() )
nCount++;
// Set Input Filter
if ( aDispatchRequest.aRequestType == REQUEST_INFILTER )
{
bSetInputFilter = sal_True;
aForcedInputFilter = aDispatchRequest.aURL;
OfficeIPCThread::RequestsCompleted( 1 );
continue;
}
// we need more properties for a print/print to request
if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ||
aDispatchRequest.aRequestType == REQUEST_CONVERSION)
nCount++;
Sequence < PropertyValue > aArgs( nCount );
// mark request as user interaction from outside
aArgs[0].Name = ::rtl::OUString::createFromAscii("Referer");
aArgs[0].Value <<= ::rtl::OUString::createFromAscii("private:OpenEvent");
if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ||
aDispatchRequest.aRequestType == REQUEST_CONVERSION)
{
aArgs[1].Name = ::rtl::OUString::createFromAscii("ReadOnly");
aArgs[2].Name = ::rtl::OUString::createFromAscii("OpenNewView");
aArgs[3].Name = ::rtl::OUString::createFromAscii("Hidden");
aArgs[4].Name = ::rtl::OUString::createFromAscii("Silent");
}
2002-03-18 12:12:57 +00:00
else
{
Reference < com::sun::star::task::XInteractionHandler > xInteraction(
::comphelper::getProcessServiceFactory()->createInstance( OUString::createFromAscii("com.sun.star.task.InteractionHandler") ),
com::sun::star::uno::UNO_QUERY );
aArgs[1].Name = OUString::createFromAscii( "InteractionHandler" );
aArgs[1].Value <<= xInteraction;
sal_Int16 nMacroExecMode = ::com::sun::star::document::MacroExecMode::USE_CONFIG;
aArgs[2].Name = OUString::createFromAscii( "MacroExecutionMode" );
aArgs[2].Value <<= nMacroExecMode;
2002-07-17 13:27:39 +00:00
sal_Int16 nUpdateDoc = ::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG;
aArgs[3].Name = OUString::createFromAscii( "UpdateDocMode" );
aArgs[3].Value <<= nUpdateDoc;
2002-03-18 12:12:57 +00:00
}
if ( aDispatchRequest.aPreselectedFactory.getLength() )
{
aArgs[nCount-1].Name = ::comphelper::MediaDescriptor::PROP_DOCUMENTSERVICE();
aArgs[nCount-1].Value <<= aDispatchRequest.aPreselectedFactory;
}
String aName( GetURL_Impl( aDispatchRequest.aURL, aDispatchRequest.aCwdUrl ) );
2001-11-28 10:26:26 +00:00
::rtl::OUString aTarget( RTL_CONSTASCII_USTRINGPARAM("_default") );
if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ||
aDispatchRequest.aRequestType == REQUEST_CONVERSION)
{
// documents opened for printing are opened readonly because they must be opened as a new document and this
// document could be open already
aArgs[1].Value <<= sal_True;
// always open a new document for printing, because it must be disposed afterwards
aArgs[2].Value <<= sal_True;
// printing is done in a hidden view
aArgs[3].Value <<= sal_True;
// load document for printing without user interaction
aArgs[4].Value <<= sal_True;
2001-11-28 10:26:26 +00:00
// hidden documents should never be put into open tasks
aTarget = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("_blank") );
}
// load the document ... if they are loadable!
// Otherwise try to dispatch it ...
Reference < XPrintable > xDoc;
if(
( aName.CompareToAscii( ".uno" , 4 ) == COMPARE_EQUAL ) ||
( aName.CompareToAscii( "slot:" , 5 ) == COMPARE_EQUAL ) ||
( aName.CompareToAscii( "macro:", 6 ) == COMPARE_EQUAL ) ||
( aName.CompareToAscii("vnd.sun.star.script", 19) == COMPARE_EQUAL)
)
{
// Attention: URL must be parsed full. Otherwise some detections on it will fail!
// It doesnt matter, if parser isn't available. Because; We try loading of URL then ...
URL aURL ;
aURL.Complete = aName;
Reference < XDispatch > xDispatcher ;
Reference < XDispatchProvider > xProvider ( xDesktop, UNO_QUERY );
Reference < XURLTransformer > xParser ( ::comphelper::getProcessServiceFactory()->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.URLTransformer")) ), ::com::sun::star::uno::UNO_QUERY );
if( xParser.is() == sal_True )
xParser->parseStrict( aURL );
if( xProvider.is() == sal_True )
xDispatcher = xProvider->queryDispatch( aURL, ::rtl::OUString(), 0 );
if( xDispatcher.is() == sal_True )
{
{
::osl::ClearableMutexGuard aGuard( GetMutex() );
// Remember request so we can find it in statusChanged!
m_aRequestContainer.insert( DispatchWatcherHashMap::value_type( aURL.Complete, (sal_Int32)1 ) );
m_nRequestCount++;
}
// Use local vector to store dispatcher because we have to fill our request container before
// we can dispatch. Otherwise it would be possible that statusChanged is called before we dispatched all requests!!
aDispatches.push_back( DispatchHolder( aURL, xDispatcher ));
}
}
else if ( ( aName.CompareToAscii( "service:" , 8 ) == COMPARE_EQUAL ) )
{
// TODO: the dispatch has to be done for loadComponentFromURL as well. Please ask AS for more details.
URL aURL ;
aURL.Complete = aName;
Reference < XDispatch > xDispatcher ;
Reference < XDispatchProvider > xProvider ( xDesktop, UNO_QUERY );
Reference < XURLTransformer > xParser ( ::comphelper::getProcessServiceFactory()->createInstance( OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.URLTransformer")) ), ::com::sun::star::uno::UNO_QUERY );
if( xParser.is() == sal_True )
xParser->parseStrict( aURL );
if( xProvider.is() == sal_True )
xDispatcher = xProvider->queryDispatch( aURL, ::rtl::OUString(), 0 );
if( xDispatcher.is() == sal_True )
{
try
{
// We have to be listener to catch errors during dispatching URLs.
// Otherwise it would be possible to have an office running without an open
// window!!
Sequence < PropertyValue > aArgs2(1);
aArgs2[0].Name = ::rtl::OUString::createFromAscii("SynchronMode");
aArgs2[0].Value <<= sal_True;
Reference < XNotifyingDispatch > xDisp( xDispatcher, UNO_QUERY );
if ( xDisp.is() )
xDisp->dispatchWithNotification( aURL, aArgs2, DispatchWatcher::GetDispatchWatcher() );
else
xDispatcher->dispatch( aURL, aArgs2 );
}
catch ( ::com::sun::star::uno::Exception& )
{
OUString aMsg = OUString::createFromAscii(
"Desktop::OpenDefault() IllegalArgumentException while calling XNotifyingDispatch: ");
OSL_ENSURE( sal_False, OUStringToOString(aMsg, RTL_TEXTENCODING_ASCII_US).getStr());
}
}
}
else
{
2001-11-28 10:26:26 +00:00
INetURLObject aObj( aName );
if ( aObj.GetProtocol() == INET_PROT_PRIVATE )
aTarget = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("_default") );
2001-11-28 10:26:26 +00:00
2002-02-26 07:16:22 +00:00
// Set "AsTemplate" argument according to request type
if ( aDispatchRequest.aRequestType == REQUEST_FORCENEW ||
aDispatchRequest.aRequestType == REQUEST_FORCEOPEN )
{
sal_Int32 nIndex = aArgs.getLength();
aArgs.realloc( nIndex+1 );
aArgs[nIndex].Name = aAsTemplateArg;
if ( aDispatchRequest.aRequestType == REQUEST_FORCENEW )
aArgs[nIndex].Value <<= sal_True;
else
aArgs[nIndex].Value <<= sal_False;
}
// if we are called in viewmode, open document read-only
// #95425#
if(aDispatchRequest.aRequestType == REQUEST_VIEW) {
sal_Int32 nIndex = aArgs.getLength();
aArgs.realloc(nIndex+1);
aArgs[nIndex].Name = OUString::createFromAscii("ReadOnly");
aArgs[nIndex].Value <<= sal_True;
}
// if we are called with -start set Start in mediadescriptor
if(aDispatchRequest.aRequestType == REQUEST_START) {
sal_Int32 nIndex = aArgs.getLength();
aArgs.realloc(nIndex+1);
aArgs[nIndex].Name = OUString::createFromAscii("StartPresentation");
aArgs[nIndex].Value <<= sal_True;
}
// Force input filter, if possible
if( bSetInputFilter )
{
sal_Int32 nIndex = aArgs.getLength();
aArgs.realloc(nIndex+1);
aArgs[nIndex].Name=OUString::createFromAscii("FilterName");
aArgs[nIndex].Value <<= aForcedInputFilter;
}
// This is a synchron loading of a component so we don't have to deal with our statusChanged listener mechanism.
try
{
xDoc = Reference < XPrintable >( ::comphelper::SynchronousDispatch::dispatch( xDesktop, aName, aTarget, 0, aArgs ), UNO_QUERY );
//xDoc = Reference < XPrintable >( xDesktop->loadComponentFromURL( aName, aTarget, 0, aArgs ), UNO_QUERY );
}
catch ( ::com::sun::star::lang::IllegalArgumentException& iae)
{
OUString aMsg = OUString::createFromAscii(
"Dispatchwatcher IllegalArgumentException while calling loadComponentFromURL: ")
+ iae.Message;
OSL_ENSURE( sal_False, OUStringToOString(aMsg, RTL_TEXTENCODING_ASCII_US).getStr());
}
catch (com::sun::star::io::IOException& ioe)
{
OUString aMsg = OUString::createFromAscii(
"Dispatchwatcher IOException while calling loadComponentFromURL: ")
+ ioe.Message;
OSL_ENSURE( sal_False, OUStringToOString(aMsg, RTL_TEXTENCODING_ASCII_US).getStr());
}
2002-02-26 07:16:22 +00:00
if ( aDispatchRequest.aRequestType == REQUEST_OPEN ||
aDispatchRequest.aRequestType == REQUEST_VIEW ||
aDispatchRequest.aRequestType == REQUEST_START ||
2002-02-26 07:16:22 +00:00
aDispatchRequest.aRequestType == REQUEST_FORCEOPEN ||
aDispatchRequest.aRequestType == REQUEST_FORCENEW )
{
// request is completed
OfficeIPCThread::RequestsCompleted( 1 );
}
else if ( aDispatchRequest.aRequestType == REQUEST_PRINT ||
aDispatchRequest.aRequestType == REQUEST_PRINTTO ||
aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ||
aDispatchRequest.aRequestType == REQUEST_CONVERSION )
{
if ( xDoc.is() )
{
if ( aDispatchRequest.aRequestType == REQUEST_CONVERSION ) {
Reference< XStorable > xStorable( xDoc, UNO_QUERY );
if ( xStorable.is() ) {
rtl::OUString aParam = aDispatchRequest.aPrinterName;
sal_Int32 nPathIndex = aParam.lastIndexOfAsciiL( ";", 1 );
sal_Int32 nFilterIndex = aParam.indexOfAsciiL( ":", 1 );
if( nPathIndex < nFilterIndex )
nFilterIndex = -1;
rtl::OUString aFilterOut=aParam.copy( nPathIndex+1 );
rtl::OUString aFilter;
rtl::OUString aFilterExt;
sal_Bool bGuess = sal_False;
if( nFilterIndex >= 0 )
{
aFilter = aParam.copy( nFilterIndex+1, nPathIndex-nFilterIndex-1 );
aFilterExt = aParam.copy( 0, nFilterIndex );
}
else
{
// Guess
bGuess = sal_True;
aFilterExt = aParam.copy( 0, nPathIndex );
}
INetURLObject aOutFilename( aObj );
aOutFilename.SetExtension( aFilterExt );
FileBase::getFileURLFromSystemPath( aFilterOut, aFilterOut );
rtl::OUString aOutFile = aFilterOut+
::rtl::OUString::createFromAscii( "/" )+
aOutFilename.getName();
//FileBase::getFileURLFromSystemPath( aOutFile, aOutFile );
if ( bGuess )
{
aFilter = impl_GuessFilter( aName, aOutFile );
}
Sequence<PropertyValue> conversionProperties( 2 );
conversionProperties[0].Name = ::rtl::OUString::createFromAscii( "Overwrite" );
conversionProperties[0].Value <<= sal_True;
conversionProperties[1].Name = ::rtl::OUString::createFromAscii( "FilterName" );
conversionProperties[1].Value <<= aFilter;
rtl::OUString aTempName;
FileBase::getSystemPathFromFileURL( aName, aTempName );
rtl::OString aSource8 = ::rtl::OUStringToOString ( aTempName, RTL_TEXTENCODING_UTF8 );
FileBase::getSystemPathFromFileURL( aOutFile, aTempName );
rtl::OString aTargetURL8 = ::rtl::OUStringToOString(aTempName, RTL_TEXTENCODING_UTF8 );
printf("convert %s -> %s using %s\n", aSource8.getStr(), aTargetURL8.getStr(),
::rtl::OUStringToOString( aFilter, RTL_TEXTENCODING_UTF8 ).getStr());
if( FStatHelper::IsDocument(aOutFile) )
printf("Overwriting: %s\n",::rtl::OUStringToOString( aTempName, RTL_TEXTENCODING_UTF8 ).getStr() );
try
{
xStorable->storeToURL( aOutFile, conversionProperties );
}
catch ( Exception& )
{
fprintf( stderr, "Error: Please reverify input parameters...\n" );
}
}
} else if ( aDispatchRequest.aRequestType == REQUEST_BATCHPRINT ) {
rtl::OUString aParam = aDispatchRequest.aPrinterName;
sal_Int32 nPathIndex = aParam.lastIndexOfAsciiL( ";", 1 );
rtl::OUString aFilterOut;
rtl::OUString aPrinterName;
if( nPathIndex != -1 )
aFilterOut=aParam.copy( nPathIndex+1 );
if( nPathIndex != 0 )
aPrinterName=aParam.copy( 0, nPathIndex );
INetURLObject aOutFilename( aObj );
aOutFilename.SetExtension( ::rtl::OUString::createFromAscii("ps") );
FileBase::getFileURLFromSystemPath( aFilterOut, aFilterOut );
rtl::OUString aOutFile = aFilterOut+
::rtl::OUString::createFromAscii( "/" )+
aOutFilename.getName();
rtl::OUString aTempName;
FileBase::getSystemPathFromFileURL( aName, aTempName );
rtl::OString aSource8 = ::rtl::OUStringToOString ( aTempName, RTL_TEXTENCODING_UTF8 );
FileBase::getSystemPathFromFileURL( aOutFile, aTempName );
rtl::OString aTargetURL8 = ::rtl::OUStringToOString(aTempName, RTL_TEXTENCODING_UTF8 );
printf("print %s -> %s using %s\n", aSource8.getStr(), aTargetURL8.getStr(),
aPrinterName.getLength() ?
::rtl::OUStringToOString( aPrinterName, RTL_TEXTENCODING_UTF8 ).getStr() : "<default_printer>");
// create the custom printer, if given
Sequence < PropertyValue > aPrinterArgs( 1 );
if( aPrinterName.getLength() )
{
aPrinterArgs[0].Name = ::rtl::OUString::createFromAscii("Name");
aPrinterArgs[0].Value <<= aPrinterName;
xDoc->setPrinter( aPrinterArgs );
}
// print ( also without user interaction )
aPrinterArgs.realloc(2);
aPrinterArgs[0].Name = ::rtl::OUString::createFromAscii("FileName");
aPrinterArgs[0].Value <<= aOutFile;
aPrinterArgs[1].Name = ::rtl::OUString::createFromAscii("Wait");
aPrinterArgs[1].Value <<= ( sal_Bool ) sal_True;
xDoc->print( aPrinterArgs );
} else {
if ( aDispatchRequest.aRequestType == REQUEST_PRINTTO )
{
// create the printer
Sequence < PropertyValue > aPrinterArgs( 1 );
aPrinterArgs[0].Name = ::rtl::OUString::createFromAscii("Name");
aPrinterArgs[0].Value <<= ::rtl::OUString( aDispatchRequest.aPrinterName );
xDoc->setPrinter( aPrinterArgs );
}
// print ( also without user interaction )
Sequence < PropertyValue > aPrinterArgs( 1 );
aPrinterArgs[0].Name = ::rtl::OUString::createFromAscii("Wait");
aPrinterArgs[0].Value <<= ( sal_Bool ) sal_True;
xDoc->print( aPrinterArgs );
}
}
else
{
// place error message here ...
}
// remove the document
try
{
Reference < XCloseable > xClose( xDoc, UNO_QUERY );
if ( xClose.is() )
xClose->close( sal_True );
else
{
Reference < XComponent > xComp( xDoc, UNO_QUERY );
if ( xComp.is() )
xComp->dispose();
}
}
catch ( com::sun::star::util::CloseVetoException& )
{
}
// request is completed
OfficeIPCThread::RequestsCompleted( 1 );
}
}
}
if ( aDispatches.size() > 0 )
{
// Execute all asynchronous dispatches now after we placed them into our request container!
Sequence < PropertyValue > aArgs( 2 );
aArgs[0].Name = ::rtl::OUString::createFromAscii("Referer");
aArgs[0].Value <<= ::rtl::OUString::createFromAscii("private:OpenEvent");
aArgs[1].Name = ::rtl::OUString::createFromAscii("SynchronMode");
aArgs[1].Value <<= sal_True;
for ( sal_uInt32 n = 0; n < aDispatches.size(); n++ )
{
Reference< XDispatch > xDispatch = aDispatches[n].xDispatch;
Reference < XNotifyingDispatch > xDisp( xDispatch, UNO_QUERY );
if ( xDisp.is() )
xDisp->dispatchWithNotification( aDispatches[n].aURL, aArgs, this );
else
{
::osl::ClearableMutexGuard aGuard( GetMutex() );
m_nRequestCount--;
aGuard.clear();
xDispatch->dispatch( aDispatches[n].aURL, aArgs );
}
}
}
::osl::ClearableMutexGuard aGuard( GetMutex() );
CWS-TOOLING: integrate CWS fwk116 2009-09-03 Mikhail Voytenko #i101453# write the default values for old entries 2009-09-03 Mikhail Voytenko #i101453# let the new default value be used 2009-09-03 Mikhail Voytenko #i101453# revert the change for xslt-transformation, the duplicate nodes should not be allowed 2009-09-03 Mikhail Voytenko #i101453# allow duplicate nodes for different modules 2009-09-03 Mikhail Voytenko #i101453# fix the special mac installation 2009-09-02 Mikhail Voytenko #i101453# correct the usage of configuration files 2009-09-02 Mikhail Voytenko #i10000# fix warning 2009-09-02 Mikhail Voytenko #i10000# fix warning 2009-09-02 Mikhail Voytenko #i96918# try to open the file for editing always 2009-09-02 Mikhail Voytenko #i51058# remove unused strings 2009-09-02 Mikhail Voytenko #i51058# remove unused strings 2009-09-01 Mikhail Voytenko #i10000# fix typo 2009-08-30 Mikhail Voytenko Rebase on DEV300_m56 2009-08-19 Mikhail Voytenko #i101732# do not generate a transparent bitmap for thumbnail 2009-08-13 Mikhail Voytenko #i101453# do not use system temporary location on Mac 2009-08-13 Mikhail Voytenko #i101453# do not use system temporary location on Mac 2009-08-07 Mikhail Voytenko #i103617# fix warning 2009-07-31 Carsten Driesner #i103924# Fix wrong number of arguments 2009-07-31 Mikhail Voytenko #i101207# integrate the patch 2009-07-31 Mikhail Voytenko #i103783# integrate the patch; get rid of CRLF 2009-07-31 Mikhail Voytenko #i97969# integrate the patch 2009-07-27 Carsten Driesner #i103423# Use correct request count in the ctor. Don't descrease value before checking the request count
2009-09-16 16:17:27 +00:00
bool bEmpty = (m_nRequestCount == 0);
aGuard.clear();
// No more asynchronous requests?
// The requests are removed from the request container after they called back to this
// implementation via statusChanged!!
CWS-TOOLING: integrate CWS fwk116 2009-09-03 Mikhail Voytenko #i101453# write the default values for old entries 2009-09-03 Mikhail Voytenko #i101453# let the new default value be used 2009-09-03 Mikhail Voytenko #i101453# revert the change for xslt-transformation, the duplicate nodes should not be allowed 2009-09-03 Mikhail Voytenko #i101453# allow duplicate nodes for different modules 2009-09-03 Mikhail Voytenko #i101453# fix the special mac installation 2009-09-02 Mikhail Voytenko #i101453# correct the usage of configuration files 2009-09-02 Mikhail Voytenko #i10000# fix warning 2009-09-02 Mikhail Voytenko #i10000# fix warning 2009-09-02 Mikhail Voytenko #i96918# try to open the file for editing always 2009-09-02 Mikhail Voytenko #i51058# remove unused strings 2009-09-02 Mikhail Voytenko #i51058# remove unused strings 2009-09-01 Mikhail Voytenko #i10000# fix typo 2009-08-30 Mikhail Voytenko Rebase on DEV300_m56 2009-08-19 Mikhail Voytenko #i101732# do not generate a transparent bitmap for thumbnail 2009-08-13 Mikhail Voytenko #i101453# do not use system temporary location on Mac 2009-08-13 Mikhail Voytenko #i101453# do not use system temporary location on Mac 2009-08-07 Mikhail Voytenko #i103617# fix warning 2009-07-31 Carsten Driesner #i103924# Fix wrong number of arguments 2009-07-31 Mikhail Voytenko #i101207# integrate the patch 2009-07-31 Mikhail Voytenko #i103783# integrate the patch; get rid of CRLF 2009-07-31 Mikhail Voytenko #i97969# integrate the patch 2009-07-27 Carsten Driesner #i103423# Use correct request count in the ctor. Don't descrease value before checking the request count
2009-09-16 16:17:27 +00:00
if ( bEmpty && !bNoTerminate /*m_aRequestContainer.empty()*/ )
{
// We have to check if we have an open task otherwise we have to shutdown the office.
Reference< XFramesSupplier > xTasksSupplier( xDesktop, UNO_QUERY );
aGuard.clear();
Reference< XElementAccess > xList( xTasksSupplier->getFrames(), UNO_QUERY );
if ( !xList->hasElements() )
{
// We don't have any task open so we have to shutdown ourself!!
Reference< XDesktop > xDesktop2( xTasksSupplier, UNO_QUERY );
if ( xDesktop2.is() )
return xDesktop2->terminate();
}
}
return sal_False;
}
void SAL_CALL DispatchWatcher::disposing( const ::com::sun::star::lang::EventObject& )
throw(::com::sun::star::uno::RuntimeException)
{
}
void SAL_CALL DispatchWatcher::dispatchFinished( const DispatchResultEvent& ) throw( RuntimeException )
{
osl::ClearableMutexGuard aGuard( GetMutex() );
sal_Int16 nCount = m_nRequestCount;
aGuard.clear();
OfficeIPCThread::RequestsCompleted( 1 );
/*
// Find request in our hash map and remove it as a pending request
DispatchWatcherHashMap::iterator pDispatchEntry = m_aRequestContainer.find( rEvent.FeatureURL.Complete ) ;
if ( pDispatchEntry != m_aRequestContainer.end() )
{
m_aRequestContainer.erase( pDispatchEntry );
aGuard.clear();
OfficeIPCThread::RequestsCompleted( 1 );
}
else
aGuard.clear();
*/
if ( !nCount && !OfficeIPCThread::AreRequestsPending() )
{
// We have to check if we have an open task otherwise we have to shutdown the office.
Reference< XFramesSupplier > xTasksSupplier( ::comphelper::getProcessServiceFactory()->createInstance(
OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.Desktop")) ),
UNO_QUERY );
Reference< XElementAccess > xList( xTasksSupplier->getFrames(), UNO_QUERY );
if ( !xList->hasElements() )
{
// We don't have any task open so we have to shutdown ourself!!
Reference< XDesktop > xDesktop( xTasksSupplier, UNO_QUERY );
if ( xDesktop.is() )
xDesktop->terminate();
}
}
}
}