16d739b60SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 36d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 46d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file 56d739b60SAndrew Rist * distributed with this work for additional information 66d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file 76d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the 86d739b60SAndrew Rist * "License"); you may not use this file except in compliance 96d739b60SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 116d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 136d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing, 146d739b60SAndrew Rist * software distributed under the License is distributed on an 156d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 166d739b60SAndrew Rist * KIND, either express or implied. See the License for the 176d739b60SAndrew Rist * specific language governing permissions and limitations 186d739b60SAndrew Rist * under the License. 19cdf0e10cSrcweir * 206d739b60SAndrew Rist *************************************************************/ 216d739b60SAndrew Rist 226d739b60SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_framework.hxx" 26cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 27cdf0e10cSrcweir // my own includes 28cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 29cdf0e10cSrcweir 30cdf0e10cSrcweir #ifndef __FRAMEWORK_DISPATCH_OXT_HANDLER_HXX_ 31cdf0e10cSrcweir #include <dispatch/oxt_handler.hxx> 32cdf0e10cSrcweir #endif 33cdf0e10cSrcweir 34cdf0e10cSrcweir #ifndef __FRAMEWORK_THREADHELP_TRANSACTIONGUARD_HXX_ 35cdf0e10cSrcweir #include <threadhelp/transactionguard.hxx> 36cdf0e10cSrcweir #endif 37cdf0e10cSrcweir 38cdf0e10cSrcweir #ifndef __FRAMEWORK_THREADHELP_WRITEGUARD_HXX_ 39cdf0e10cSrcweir #include <threadhelp/writeguard.hxx> 40cdf0e10cSrcweir #endif 41cdf0e10cSrcweir 42cdf0e10cSrcweir #ifndef __FRAMEWORK_THREADHELP_READGUARD_HXX_ 43cdf0e10cSrcweir #include <threadhelp/readguard.hxx> 44cdf0e10cSrcweir #endif 45cdf0e10cSrcweir 46cdf0e10cSrcweir #ifndef __FRAMEWORK_MACROS_DEBUG_HXX_ 47cdf0e10cSrcweir #include <macros/debug.hxx> 48cdf0e10cSrcweir #endif 49cdf0e10cSrcweir 50cdf0e10cSrcweir #ifndef __FRAMEWORK_SERVICES_H_ 51cdf0e10cSrcweir #include <services.h> 52cdf0e10cSrcweir #endif 53cdf0e10cSrcweir 54cdf0e10cSrcweir #ifndef __COMPHELPER_MEDIADESCRIPTOR_HXX_ 55cdf0e10cSrcweir #include <comphelper/mediadescriptor.hxx> 56cdf0e10cSrcweir #endif 57cdf0e10cSrcweir 58cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 59cdf0e10cSrcweir // interface includes 60cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 61cdf0e10cSrcweir 62cdf0e10cSrcweir #include <com/sun/star/io/XInputStream.hpp> 63cdf0e10cSrcweir #include <com/sun/star/frame/DispatchResultState.hpp> 64cdf0e10cSrcweir #include <com/sun/star/task/XJobExecutor.hpp> 65cdf0e10cSrcweir 66cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 67cdf0e10cSrcweir // includes of other projects 68cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 69cdf0e10cSrcweir 70cdf0e10cSrcweir #ifndef _COMPHELPER_SEQUENCEASHASHMAP_HXX_ 71cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx> 72cdf0e10cSrcweir #endif 73cdf0e10cSrcweir 74cdf0e10cSrcweir #ifndef _RTL_USTRBUF_HXX_ 75cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 76cdf0e10cSrcweir #endif 77cdf0e10cSrcweir 78cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 79cdf0e10cSrcweir // namespace 80cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 81cdf0e10cSrcweir 82cdf0e10cSrcweir namespace framework{ 83cdf0e10cSrcweir 84cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 85cdf0e10cSrcweir // non exported const 86cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 87cdf0e10cSrcweir 88cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 89cdf0e10cSrcweir // non exported definitions 90cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 91cdf0e10cSrcweir 92cdf0e10cSrcweir #define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s)) 93cdf0e10cSrcweir 94cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 95cdf0e10cSrcweir // declarations 96cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 97cdf0e10cSrcweir 98cdf0e10cSrcweir //***************************************************************************************************************** 99cdf0e10cSrcweir // XInterface, XTypeProvider, XServiceInfo 100cdf0e10cSrcweir //***************************************************************************************************************** 101cdf0e10cSrcweir DEFINE_XINTERFACE_5 ( Oxt_Handler , 102cdf0e10cSrcweir OWeakObject , 103cdf0e10cSrcweir DIRECT_INTERFACE( css::lang::XTypeProvider ), 104cdf0e10cSrcweir DIRECT_INTERFACE( css::lang::XServiceInfo ), 105cdf0e10cSrcweir DIRECT_INTERFACE( css::frame::XNotifyingDispatch ), 106cdf0e10cSrcweir DIRECT_INTERFACE( css::frame::XDispatch ), 107cdf0e10cSrcweir DIRECT_INTERFACE( css::document::XExtendedFilterDetection ) 108cdf0e10cSrcweir ) 109cdf0e10cSrcweir 110cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_5 ( Oxt_Handler , 111cdf0e10cSrcweir css::lang::XTypeProvider , 112cdf0e10cSrcweir css::lang::XServiceInfo , 113cdf0e10cSrcweir css::frame::XNotifyingDispatch , 114cdf0e10cSrcweir css::frame::XDispatch , 115cdf0e10cSrcweir css::document::XExtendedFilterDetection 116cdf0e10cSrcweir ) 117cdf0e10cSrcweir 118cdf0e10cSrcweir DEFINE_XSERVICEINFO_MULTISERVICE ( Oxt_Handler , 119cdf0e10cSrcweir ::cppu::OWeakObject , 120cdf0e10cSrcweir SERVICENAME_CONTENTHANDLER , 121cdf0e10cSrcweir IMPLEMENTATIONNAME_OXT_HANDLER 122cdf0e10cSrcweir ) 123cdf0e10cSrcweir 124cdf0e10cSrcweir DEFINE_INIT_SERVICE ( Oxt_Handler, 125cdf0e10cSrcweir { 126cdf0e10cSrcweir } 127cdf0e10cSrcweir ) 128cdf0e10cSrcweir 129cdf0e10cSrcweir /*-************************************************************************************************************//** 130cdf0e10cSrcweir @short standard ctor 131cdf0e10cSrcweir @descr These initialize a new instance of this class with needed informations for work. 132cdf0e10cSrcweir 133cdf0e10cSrcweir @seealso using at owner 134cdf0e10cSrcweir 135cdf0e10cSrcweir @param "xFactory", reference to service manager for creation of new services 136cdf0e10cSrcweir @return - 137cdf0e10cSrcweir 138cdf0e10cSrcweir @onerror Show an assertion and do nothing else. 139cdf0e10cSrcweir @threadsafe yes 140cdf0e10cSrcweir *//*-*************************************************************************************************************/ 141cdf0e10cSrcweir Oxt_Handler::Oxt_Handler( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory ) 142cdf0e10cSrcweir // Init baseclasses first 143cdf0e10cSrcweir : ThreadHelpBase ( ) 144cdf0e10cSrcweir , ::cppu::OWeakObject ( ) 145cdf0e10cSrcweir // Init member 146cdf0e10cSrcweir , m_xFactory ( xFactory ) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir /*-************************************************************************************************************//** 151cdf0e10cSrcweir @short standard dtor 152cdf0e10cSrcweir @descr - 153cdf0e10cSrcweir 154cdf0e10cSrcweir @seealso - 155cdf0e10cSrcweir 156cdf0e10cSrcweir @param - 157cdf0e10cSrcweir @return - 158cdf0e10cSrcweir 159cdf0e10cSrcweir @onerror - 160cdf0e10cSrcweir @threadsafe - 161cdf0e10cSrcweir *//*-*************************************************************************************************************/ 162cdf0e10cSrcweir Oxt_Handler::~Oxt_Handler() 163cdf0e10cSrcweir { 164cdf0e10cSrcweir if ( m_xListener.is() ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir css::frame::DispatchResultEvent aEvent; 167cdf0e10cSrcweir aEvent.State = css::frame::DispatchResultState::FAILURE; 168cdf0e10cSrcweir m_xListener->dispatchFinished( aEvent ); 169cdf0e10cSrcweir m_xListener = css::uno::Reference< css::frame::XDispatchResultListener >(); 170cdf0e10cSrcweir } 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir /*-************************************************************************************************************//** 174cdf0e10cSrcweir @interface ::com::sun::star::frame::XDispatch 175cdf0e10cSrcweir 176cdf0e10cSrcweir @short try to load audio file 177cdf0e10cSrcweir @descr This method try to load given audio file by URL and play it. We use vcl/Sound class to do that. 178cdf0e10cSrcweir Playing of sound is asynchron every time. 179cdf0e10cSrcweir 180cdf0e10cSrcweir @attention We must hold us alive by ourself ... because we use async. vcl sound player ... but playing is started 181cdf0e10cSrcweir in async interface call "dispatch()" too. And caller forget us imediatly. But then our uno ref count 182cdf0e10cSrcweir will decreased to 0 and will die. The only solution is to use own reference to our implementation. 18307a3d7f1SPedro Giffuni But we do it for really started jobs only and release it during call back of vcl. 184cdf0e10cSrcweir 185cdf0e10cSrcweir @seealso class vcl/Sound 186cdf0e10cSrcweir @seealso method implts_PlayerNotify() 187cdf0e10cSrcweir 188cdf0e10cSrcweir @param "aURL" , URL to dispatch. 189cdf0e10cSrcweir @param "lArguments", list of optional arguments. 190cdf0e10cSrcweir @return - 191cdf0e10cSrcweir 192cdf0e10cSrcweir @onerror We do nothing. 193cdf0e10cSrcweir @threadsafe yes 194cdf0e10cSrcweir *//*-*************************************************************************************************************/ 195cdf0e10cSrcweir void SAL_CALL Oxt_Handler::dispatchWithNotification( const css::util::URL& aURL, 196cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >& /*lArguments*/, 197cdf0e10cSrcweir const css::uno::Reference< css::frame::XDispatchResultListener >& xListener ) 198cdf0e10cSrcweir throw( css::uno::RuntimeException ) 199cdf0e10cSrcweir { 200cdf0e10cSrcweir // SAFE { 201cdf0e10cSrcweir ResetableGuard aLock( m_aLock ); 202cdf0e10cSrcweir 203cdf0e10cSrcweir rtl::OUString sServiceName = UNISTRING( "com.sun.star.deployment.ui.PackageManagerDialog" ); 204cdf0e10cSrcweir css::uno::Sequence< css::uno::Any > lParams(1); 205cdf0e10cSrcweir lParams[0] <<= aURL.Main; 206cdf0e10cSrcweir 207cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > xService; 208cdf0e10cSrcweir 209cdf0e10cSrcweir xService = m_xFactory->createInstanceWithArguments( sServiceName, lParams ); 210cdf0e10cSrcweir css::uno::Reference< css::task::XJobExecutor > xExecuteable( xService, css::uno::UNO_QUERY ); 211cdf0e10cSrcweir if ( xExecuteable.is() ) 212cdf0e10cSrcweir xExecuteable->trigger( rtl::OUString() ); 213cdf0e10cSrcweir 214cdf0e10cSrcweir if ( xListener.is() ) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir css::frame::DispatchResultEvent aEvent; 217cdf0e10cSrcweir aEvent.State = css::frame::DispatchResultState::SUCCESS; 218cdf0e10cSrcweir xListener->dispatchFinished( aEvent ); 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221cdf0e10cSrcweir /* 222cdf0e10cSrcweir // Try to initialize player. 223cdf0e10cSrcweir m_xListener = xListener; 224cdf0e10cSrcweir if (m_aPlayer.SetSoundName(aURL.Complete)) 225cdf0e10cSrcweir { 226cdf0e10cSrcweir // OK- we can start async playing ... 227*30acf5e8Spfg // Count this request and initialize self-holder against dying by uno ref count ... 228cdf0e10cSrcweir m_xSelfHold = css::uno::Reference< css::uno::XInterface >(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY); 229cdf0e10cSrcweir m_aPlayer.Play(); 230cdf0e10cSrcweir } 231cdf0e10cSrcweir */ 232cdf0e10cSrcweir // } SAFE 233cdf0e10cSrcweir aLock.unlock(); 234cdf0e10cSrcweir } 235cdf0e10cSrcweir 236cdf0e10cSrcweir void SAL_CALL Oxt_Handler::dispatch( const css::util::URL& aURL , 237cdf0e10cSrcweir const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) 238cdf0e10cSrcweir throw( css::uno::RuntimeException ) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir dispatchWithNotification( aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >() ); 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir /*-************************************************************************************************************//** 244cdf0e10cSrcweir @interface ::com::sun::star::document::XExtendedFilterDetection 245cdf0e10cSrcweir 246cdf0e10cSrcweir @short try to detect file (given as argument included in "lDescriptor") 247cdf0e10cSrcweir @descr We try to detect, if given file could be handled by this class and is a well known one. 248cdf0e10cSrcweir If it is - we return right internal type name - otherwise we return nothing! 249cdf0e10cSrcweir So call can search for another detect service and ask him too. 250cdf0e10cSrcweir 251cdf0e10cSrcweir @attention a) We don't need any mutex here ... because we don't use any member! 252cdf0e10cSrcweir b) Dont' use internal player instance "m_pPlayer" to detect given sound file! 25307a3d7f1SPedro Giffuni It's not necessary to do that ... and we can use temp. variable to do the same. 254cdf0e10cSrcweir This way is easy - we don't must synchronize it with currently played sounds! 255cdf0e10cSrcweir Another reason to do so ... We are a listener on our internal ma_Player object. 256cdf0e10cSrcweir If you would call "IsSoundFile()" on this instance, he would call us back and 257cdf0e10cSrcweir we make some uneccssary things ... 258cdf0e10cSrcweir 259cdf0e10cSrcweir @seealso - 260cdf0e10cSrcweir 261cdf0e10cSrcweir @param "lDescriptor", description of file to detect 262cdf0e10cSrcweir @return Internal type name which match this file ... or nothing if it is unknown. 263cdf0e10cSrcweir 264cdf0e10cSrcweir @onerror We return nothing. 265cdf0e10cSrcweir @threadsafe yes 266cdf0e10cSrcweir *//*-*************************************************************************************************************/ 267cdf0e10cSrcweir ::rtl::OUString SAL_CALL Oxt_Handler::detect( css::uno::Sequence< css::beans::PropertyValue >& lDescriptor ) 268cdf0e10cSrcweir throw( css::uno::RuntimeException ) 269cdf0e10cSrcweir { 27007a3d7f1SPedro Giffuni // Our default is "nothing". So we can return it, if detection failed or fily type is really unknown. 271cdf0e10cSrcweir ::rtl::OUString sTypeName; 272cdf0e10cSrcweir 273cdf0e10cSrcweir // Analyze given descriptor to find filename or input stream or ... 274cdf0e10cSrcweir ::comphelper::MediaDescriptor aDescriptor( lDescriptor ); 275cdf0e10cSrcweir ::rtl::OUString sURL = aDescriptor.getUnpackedValueOrDefault( ::comphelper::MediaDescriptor::PROP_URL(), ::rtl::OUString() ); 276cdf0e10cSrcweir 277cdf0e10cSrcweir long nLength = sURL.getLength(); 278cdf0e10cSrcweir if ( ( nLength > 4 ) && sURL.matchIgnoreAsciiCase( UNISTRING(".oxt"), nLength-4 ) ) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir // "IsSoundFile" idffer between different "wav" and "au" file versions ... 281cdf0e10cSrcweir // couldn't return this information ... because: He use the OS to detect it! 282cdf0e10cSrcweir // I think we can the following ones: 283cdf0e10cSrcweir // a) look for given extension of url to map our type decision HARD CODED!!! 284cdf0e10cSrcweir // b) return preferred type every time... it's easy :-) 285cdf0e10cSrcweir sTypeName = ::rtl::OUString::createFromAscii("oxt_OpenOffice_Extension"); 286cdf0e10cSrcweir aDescriptor[::comphelper::MediaDescriptor::PROP_TYPENAME()] <<= sTypeName; 287cdf0e10cSrcweir aDescriptor >> lDescriptor; 288cdf0e10cSrcweir } 289cdf0e10cSrcweir 290cdf0e10cSrcweir // Return our decision. 291cdf0e10cSrcweir return sTypeName; 292cdf0e10cSrcweir } 293cdf0e10cSrcweir 294cdf0e10cSrcweir } // namespace framework 295