1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <com/sun/star/lang/XTypeProvider.hpp>
23 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
24 #include <com/sun/star/frame/XStatusListener.hpp>
25 #include <com/sun/star/document/XExtendedFilterDetection.hpp>
26 #include <com/sun/star/media/XPlayer.hpp>
27 #include <com/sun/star/beans/PropertyValue.hpp>
28 #include <com/sun/star/util/URL.hpp>
30 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <cppuhelper/basemutex.hxx>
33 #include <cppuhelper/weak.hxx>
35 #include <vcl/timer.hxx>
36 #include <vcl/idle.hxx>
37 #include <tools/link.hxx>
41 /*-************************************************************************************************************
42 @short handler to detect and play sounds ("wav" and "au" only!)
43 @descr Register this implementation as a content handler to detect and/or play wav- and au-sounds.
44 It doesn't depend from the target platform. But one instance of this class
45 can play one sound at the same time only. Means every new dispatch request will stop the
46 might still running one. So we support one operation/one URL/one listener at the same time
51 *//*-*************************************************************************************************************/
52 class SoundHandler
: // interfaces
53 public css::lang::XTypeProvider
54 , public css::lang::XServiceInfo
55 , public css::frame::XNotifyingDispatch
// => XDispatch
56 , public css::document::XExtendedFilterDetection
58 // Order is necessary for right initialization!
59 , private cppu::BaseMutex
60 , public ::cppu::OWeakObject
65 // constructor / destructor
67 virtual ~SoundHandler( ) override
;
69 // XInterface, XTypeProvider, XServiceInfo
70 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& aType
) override
;
71 virtual void SAL_CALL
acquire() noexcept override
;
72 virtual void SAL_CALL
release() noexcept override
;
73 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes () override
;
74 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId() override
;
76 /* interface XServiceInfo */
77 virtual OUString SAL_CALL
getImplementationName ( ) override
;
78 virtual sal_Bool SAL_CALL
supportsService ( const OUString
& sServiceName
) override
;
79 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames ( ) override
;
82 virtual void SAL_CALL
dispatchWithNotification(const css::util::URL
& aURL
,
83 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
,
84 const css::uno::Reference
< css::frame::XDispatchResultListener
>& xListener
) override
;
87 virtual void SAL_CALL
dispatch ( const css::util::URL
& aURL
,
88 const css::uno::Sequence
< css::beans::PropertyValue
>& lArguments
) override
;
90 virtual void SAL_CALL
addStatusListener ( const css::uno::Reference
< css::frame::XStatusListener
>& /*xListener*/ ,
91 const css::util::URL
& /*aURL*/ ) override
{};
92 virtual void SAL_CALL
removeStatusListener ( const css::uno::Reference
< css::frame::XStatusListener
>& /*xListener*/ ,
93 const css::util::URL
& /*aURL*/ ) override
{};
95 // XExtendedFilterDetection
96 virtual OUString SAL_CALL
detect ( css::uno::Sequence
< css::beans::PropertyValue
>& lDescriptor
) override
;
103 DECL_LINK( implts_PlayerNotify
, Timer
*, void );
106 // (should be private everyway!)
110 css::uno::Reference
< css::uno::XInterface
> m_xSelfHold
; // we must protect us against dying during async(!) dispatch() call!
111 css::uno::Reference
< css::media::XPlayer
> m_xPlayer
; // uses avmedia player to play sounds...
113 css::uno::Reference
< css::frame::XDispatchResultListener
> m_xListener
;
116 }; // class SoundHandler
118 } // namespace avmedia
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */