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 "fltlst.hxx"
22 :
23 : #include <com/sun/star/uno/Sequence.hxx>
24 : #include <com/sun/star/uno/Any.hxx>
25 : #include <com/sun/star/document/FilterConfigRefresh.hpp>
26 : #include <comphelper/processfactory.hxx>
27 :
28 : #include <sfx2/sfxuno.hxx>
29 : #include <sfx2/docfac.hxx>
30 :
31 : #include <vcl/svapp.hxx>
32 : #include <osl/mutex.hxx>
33 :
34 :
35 : // namespaces
36 :
37 : using namespace ::com::sun::star;
38 :
39 :
40 : class SfxRefreshListener : public ::cppu::WeakImplHelper1<com::sun::star::util::XRefreshListener>
41 : {
42 : private:
43 : SfxFilterListener *m_pOwner;
44 :
45 : public:
46 0 : SfxRefreshListener(SfxFilterListener *pOwner)
47 0 : : m_pOwner(pOwner)
48 : {
49 0 : }
50 :
51 0 : virtual ~SfxRefreshListener()
52 0 : {
53 0 : }
54 :
55 : // util.XRefreshListener
56 0 : virtual void SAL_CALL refreshed( const ::com::sun::star::lang::EventObject& rEvent )
57 : throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
58 : {
59 0 : m_pOwner->refreshed(rEvent);
60 0 : }
61 :
62 : // lang.XEventListener
63 0 : virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
64 : throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
65 : {
66 0 : m_pOwner->disposing(rEvent);
67 0 : }
68 : };
69 :
70 : /*-************************************************************************************************************
71 : @short ctor
72 : @descr These initialize an instance of a SfxFilterListener class. Created object listen automaticly
73 : on right FilterFactory-Service for all changes and synchronize right SfxFilterContainer with
74 : corresponding framework-cache.
75 : We use given "sFactory" value to decide which query must be used to fill "pContainer" with new values.
76 : Given "pContainer" hold us alive as uno reference and we use it to syschronize it with framework caches.
77 : We will die, if he die! see dtor for further information.
78 :
79 : @seealso dtor
80 : @seealso class framework::FilterCache
81 : @seealso service ::document::FilterFactory
82 :
83 : @param "sFactory" , short name of module which contains filter container
84 : @param "pContainer", pointer to filter container which will be informed
85 : @onerror We show some assertions in non product version.
86 : Otherwise we do nothing!
87 : @threadsafe yes
88 : *//*-*************************************************************************************************************/
89 0 : SfxFilterListener::SfxFilterListener()
90 : {
91 0 : m_xFilterCache = document::FilterConfigRefresh::create( comphelper::getProcessComponentContext() );
92 0 : m_xFilterCacheListener = new SfxRefreshListener(this);
93 0 : m_xFilterCache->addRefreshListener( m_xFilterCacheListener );
94 0 : }
95 :
96 0 : SfxFilterListener::~SfxFilterListener()
97 : {
98 0 : }
99 :
100 0 : void SAL_CALL SfxFilterListener::refreshed( const lang::EventObject& aSource ) throw( uno::RuntimeException )
101 : {
102 0 : SolarMutexGuard aGuard;
103 0 : uno::Reference< util::XRefreshable > xContainer( aSource.Source, uno::UNO_QUERY );
104 0 : if(
105 0 : (xContainer.is() ) &&
106 0 : (xContainer==m_xFilterCache)
107 : )
108 : {
109 0 : SfxFilterContainer::ReadFilters_Impl( true );
110 0 : }
111 0 : }
112 :
113 0 : void SAL_CALL SfxFilterListener::disposing( const lang::EventObject& aSource ) throw( uno::RuntimeException )
114 : {
115 0 : SolarMutexGuard aGuard;
116 0 : uno::Reference< util::XRefreshable > xNotifier( aSource.Source, uno::UNO_QUERY );
117 0 : if (!xNotifier.is())
118 0 : return;
119 :
120 0 : if (xNotifier == m_xFilterCache)
121 0 : m_xFilterCache.clear();
122 : }
123 :
124 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|