From d26f3acf2874f64fd89c8197163651443d4b1733 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 17 Oct 2012 13:54:31 +0200 Subject: fdo#46808, use service constructor for system::SystemShellExecute --- extensions/source/update/check/updatecheck.cxx | 35 +++++++++----------- framework/inc/dispatch/mailtodispatcher.hxx | 6 ++-- framework/inc/dispatch/systemexec.hxx | 4 +-- framework/inc/services.h | 1 - framework/source/dispatch/mailtodispatcher.cxx | 46 ++++++++++++-------------- framework/source/dispatch/systemexec.cxx | 17 ++++------ 6 files changed, 49 insertions(+), 60 deletions(-) diff --git a/extensions/source/update/check/updatecheck.cxx b/extensions/source/update/check/updatecheck.cxx index c6fb071fd1ed..fcd2d8221ad0 100644 --- a/extensions/source/update/check/updatecheck.cxx +++ b/extensions/source/update/check/updatecheck.cxx @@ -913,9 +913,7 @@ UpdateCheck::install() { osl::MutexGuard aGuard(m_aMutex); - const uno::Reference< c3s::XSystemShellExecute > xShellExecute( - createService( UNISTRING( "com.sun.star.system.SystemShellExecute" ), m_xContext ), - uno::UNO_QUERY ); + const uno::Reference< c3s::XSystemShellExecute > xShellExecute = c3s::SystemShellExecute::create( m_xContext ); try { // Construct install command ?? @@ -927,29 +925,26 @@ UpdateCheck::install() aURL = getReleaseNote(m_aUpdateInfo, 4); storeReleaseNote(2, aURL); - if( xShellExecute.is() ) - { - rtl::OUString aInstallImage(m_aImageName); - osl::FileBase::getSystemPathFromFileURL(aInstallImage, aInstallImage); + rtl::OUString aInstallImage(m_aImageName); + osl::FileBase::getSystemPathFromFileURL(aInstallImage, aInstallImage); - rtl::OUString aParameter; - sal_Int32 nFlags = c3s::SystemShellExecuteFlags::DEFAULTS; + rtl::OUString aParameter; + sal_Int32 nFlags = c3s::SystemShellExecuteFlags::DEFAULTS; #if ( defined LINUX || defined SOLARIS ) - nFlags = 42; - aParameter = getBaseInstallation(); - if( !aParameter.isEmpty() ) - osl::FileBase::getSystemPathFromFileURL(aParameter, aParameter); + nFlags = 42; + aParameter = getBaseInstallation(); + if( !aParameter.isEmpty() ) + osl::FileBase::getSystemPathFromFileURL(aParameter, aParameter); - aParameter += UNISTRING(" &"); + aParameter += UNISTRING(" &"); #endif - rtl::Reference< UpdateCheckConfig > rModel = UpdateCheckConfig::get( m_xContext ); - rModel->clearLocalFileName(); + rtl::Reference< UpdateCheckConfig > rModel = UpdateCheckConfig::get( m_xContext ); + rModel->clearLocalFileName(); - xShellExecute->execute(aInstallImage, aParameter, nFlags); - ShutdownThread *pShutdownThread = new ShutdownThread( m_xContext ); - (void) pShutdownThread; - } + xShellExecute->execute(aInstallImage, aParameter, nFlags); + ShutdownThread *pShutdownThread = new ShutdownThread( m_xContext ); + (void) pShutdownThread; } catch(const uno::Exception&) { m_aUpdateHandler->setErrorMessage( m_aUpdateHandler->getDefaultInstErrMsg() ); } diff --git a/framework/inc/dispatch/mailtodispatcher.hxx b/framework/inc/dispatch/mailtodispatcher.hxx index 91acd5b837de..72ad6396795e 100644 --- a/framework/inc/dispatch/mailtodispatcher.hxx +++ b/framework/inc/dispatch/mailtodispatcher.hxx @@ -76,14 +76,14 @@ class MailToDispatcher : // interfaces private: /// reference to global uno service manager which had created us - css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory; + css::uno::Reference< css::uno::XComponentContext > m_xContext; /* interface */ public: // ctor/dtor - MailToDispatcher( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory ); - virtual ~MailToDispatcher( ); + MailToDispatcher( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); + virtual ~MailToDispatcher( ); // XInterface, XTypeProvider, XServiceInfo FWK_DECLARE_XINTERFACE diff --git a/framework/inc/dispatch/systemexec.hxx b/framework/inc/dispatch/systemexec.hxx index 3469e42a6b76..c0e2b641c7dc 100644 --- a/framework/inc/dispatch/systemexec.hxx +++ b/framework/inc/dispatch/systemexec.hxx @@ -78,13 +78,13 @@ class SystemExec : // interfaces private: /// reference to global uno service manager which had created us - css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory; + css::uno::Reference< css::uno::XComponentContext > m_xContext; /* interface */ public: // ctor/dtor - SystemExec( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory ); + SystemExec( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); virtual ~SystemExec( ); // XInterface, XTypeProvider, XServiceInfo diff --git a/framework/inc/services.h b/framework/inc/services.h index 6af3d9a06d64..179633660509 100644 --- a/framework/inc/services.h +++ b/framework/inc/services.h @@ -55,7 +55,6 @@ namespace framework{ #define SERVICENAME_JOB DECLARE_ASCII("com.sun.star.task.Job" ) #define SERVICENAME_DISPATCHRECORDERSUPPLIER DECLARE_ASCII("com.sun.star.frame.DispatchRecorderSupplier" ) #define SERVICENAME_DISPATCHRECORDER DECLARE_ASCII("com.sun.star.frame.DispatchRecorder" ) -#define SERVICENAME_SYSTEMSHELLEXECUTE DECLARE_ASCII("com.sun.star.system.SystemShellExecute" ) #define SERVICENAME_PROTOCOLHANDLER DECLARE_ASCII("com.sun.star.frame.ProtocolHandler" ) #define SERVICENAME_SUBSTITUTEPATHVARIABLES DECLARE_ASCII("com.sun.star.util.PathSubstitution" ) #define SERVICENAME_PATHSETTINGS DECLARE_ASCII("com.sun.star.util.PathSettings" ) diff --git a/framework/source/dispatch/mailtodispatcher.cxx b/framework/source/dispatch/mailtodispatcher.cxx index 903e33ce695c..6555f3a885d5 100644 --- a/framework/source/dispatch/mailtodispatcher.cxx +++ b/framework/source/dispatch/mailtodispatcher.cxx @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include @@ -60,7 +60,7 @@ DEFINE_XTYPEPROVIDER_5(MailToDispatcher , css::frame::XNotifyingDispatch, css::frame::XDispatch ) -DEFINE_XSERVICEINFO_MULTISERVICE(MailToDispatcher , +DEFINE_XSERVICEINFO_MULTISERVICE_2(MailToDispatcher , ::cppu::OWeakObject , SERVICENAME_PROTOCOLHANDLER , IMPLEMENTATIONNAME_MAILTODISPATCHER) @@ -81,15 +81,15 @@ DEFINE_INIT_SERVICE(MailToDispatcher, @short standard ctor @descr These initialize a new instance of ths class with needed informations for work. - @param xFactory + @param rxContext reference to uno servicemanager for creation of new services */ -MailToDispatcher::MailToDispatcher( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory ) +MailToDispatcher::MailToDispatcher( const css::uno::Reference< css::uno::XComponentContext >& rxContext ) // Init baseclasses first : ThreadHelpBase( &Application::GetSolarMutex() ) , OWeakObject ( ) // Init member - , m_xFactory ( xFactory ) + , m_xContext ( rxContext ) { } @@ -101,7 +101,7 @@ MailToDispatcher::MailToDispatcher( const css::uno::Reference< css::lang::XMulti */ MailToDispatcher::~MailToDispatcher() { - m_xFactory = NULL; + m_xContext = NULL; } //_________________________________________________________________________________________________________________ @@ -228,29 +228,27 @@ sal_Bool MailToDispatcher::implts_dispatch( const css::util::URL& { sal_Bool bSuccess = sal_False; - css::uno::Reference< css::lang::XMultiServiceFactory > xFactory; + css::uno::Reference< css::uno::XComponentContext > xContext; /* SAFE */{ ReadGuard aReadLock( m_aLock ); - xFactory = m_xFactory; + xContext = m_xContext; /* SAFE */} - css::uno::Reference< css::system::XSystemShellExecute > xSystemShellExecute( xFactory->createInstance(SERVICENAME_SYSTEMSHELLEXECUTE), css::uno::UNO_QUERY ); - if (xSystemShellExecute.is()) + css::uno::Reference< css::system::XSystemShellExecute > xSystemShellExecute = css::system::SystemShellExecute::create( xContext ); + + try + { + // start mail client + // Because there is no notofocation about success - we use case of + // no detected exception as SUCCESS - FAILED otherwhise. + xSystemShellExecute->execute( aURL.Complete, ::rtl::OUString(), css::system::SystemShellExecuteFlags::URIS_ONLY ); + bSuccess = sal_True; + } + catch (const css::lang::IllegalArgumentException&) + { + } + catch (const css::system::SystemShellExecuteException&) { - try - { - // start mail client - // Because there is no notofocation about success - we use case of - // no detected exception as SUCCESS - FAILED otherwhise. - xSystemShellExecute->execute( aURL.Complete, ::rtl::OUString(), css::system::SystemShellExecuteFlags::URIS_ONLY ); - bSuccess = sal_True; - } - catch (const css::lang::IllegalArgumentException&) - { - } - catch (const css::system::SystemShellExecuteException&) - { - } } return bSuccess; diff --git a/framework/source/dispatch/systemexec.cxx b/framework/source/dispatch/systemexec.cxx index 4d67609b1406..1934552af98e 100644 --- a/framework/source/dispatch/systemexec.cxx +++ b/framework/source/dispatch/systemexec.cxx @@ -31,7 +31,7 @@ #include #include -#include +#include #include #include #include @@ -63,7 +63,7 @@ DEFINE_XTYPEPROVIDER_5(SystemExec , css::frame::XNotifyingDispatch, css::frame::XDispatch ) -DEFINE_XSERVICEINFO_MULTISERVICE(SystemExec , +DEFINE_XSERVICEINFO_MULTISERVICE_2(SystemExec , ::cppu::OWeakObject , SERVICENAME_PROTOCOLHANDLER , IMPLEMENTATIONNAME_SYSTEMEXEC) @@ -80,12 +80,12 @@ DEFINE_INIT_SERVICE(SystemExec, //_________________________________________________________________________________________________________________ -SystemExec::SystemExec( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory ) +SystemExec::SystemExec( const css::uno::Reference< css::uno::XComponentContext >& rxContext ) // Init baseclasses first : ThreadHelpBase( &Application::GetSolarMutex() ) , OWeakObject ( ) // Init member - , m_xFactory ( xFactory ) + , m_xContext ( rxContext ) { } @@ -93,7 +93,7 @@ SystemExec::SystemExec( const css::uno::Reference< css::lang::XMultiServiceFacto SystemExec::~SystemExec() { - m_xFactory = NULL; + m_xContext = NULL; } //_________________________________________________________________________________________________________________ @@ -149,7 +149,7 @@ void SAL_CALL SystemExec::dispatchWithNotification( const css::util::URL& // SAFE -> ReadGuard aReadLock(m_aLock); - css::uno::Reference< css::lang::XMultiServiceFactory > xFactory = m_xFactory; + css::uno::Reference< css::uno::XComponentContext > xContext = m_xContext; aReadLock.unlock(); // <- SAFE @@ -157,14 +157,11 @@ void SAL_CALL SystemExec::dispatchWithNotification( const css::util::URL& try { - css::uno::Reference< css::uno::XComponentContext > xContext( comphelper::getComponentContext(xFactory) ); css::uno::Reference< css::util::XStringSubstitution > xPathSubst( css::util::PathSubstitution::create(xContext) ); ::rtl::OUString sSystemURL = xPathSubst->substituteVariables(sSystemURLWithVariables, sal_True); // sal_True force an exception if unknown variables exists ! - css::uno::Reference< css::system::XSystemShellExecute > xShell( - xFactory->createInstance(SERVICENAME_SYSTEMSHELLEXECUTE), - css::uno::UNO_QUERY_THROW); + css::uno::Reference< css::system::XSystemShellExecute > xShell = css::system::SystemShellExecute::create( xContext ); xShell->execute(sSystemURL, ::rtl::OUString(), css::system::SystemShellExecuteFlags::URIS_ONLY); impl_notifyResultListener(xListener, css::frame::DispatchResultState::SUCCESS); -- cgit v1.2.3