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 #ifndef INCLUDED_LINGUISTIC_SOURCE_LNGSVCMGR_HXX
21 #define INCLUDED_LINGUISTIC_SOURCE_LNGSVCMGR_HXX
22 
23 #include <cppuhelper/implbase.hxx>
24 #include <comphelper/interfacecontainer2.hxx>
25 
26 
27 #include <com/sun/star/uno/Reference.h>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/linguistic2/XLinguServiceManager2.hpp>
30 #include <com/sun/star/util/XModifyBroadcaster.hpp>
31 #include <com/sun/star/util/XModifyListener.hpp>
32 #include <unotools/configitem.hxx>
33 #include <rtl/ref.hxx>
34 #include <vcl/timer.hxx>
35 #include <vcl/idle.hxx>
36 #include <vector>
37 #include <memory>
38 
39 class SpellCheckerDispatcher;
40 class HyphenatorDispatcher;
41 class ThesaurusDispatcher;
42 class GrammarCheckingIterator;
43 class LngSvcMgrListenerHelper;
44 struct SvcInfo;
45 
46 namespace com::sun::star::linguistic2 {
47     class XLinguServiceEventBroadcaster;
48     class XSpellChecker;
49     class XProofreadingIterator;
50     class XHyphenator;
51     class XThesaurus;
52 }
53 
54 
55 class LngSvcMgr :
56     public cppu::WeakImplHelper
57     <
58         css::linguistic2::XLinguServiceManager2,
59         css::lang::XServiceInfo,
60         css::util::XModifyListener
61     >,
62     private utl::ConfigItem
63 {
64     friend class LngSvcMgrListenerHelper;
65 
66     ::comphelper::OInterfaceContainerHelper2            aEvtListeners;
67 
68     css::uno::Reference<
69         css::util::XModifyBroadcaster>                  xMB;
70 
71     Idle                                                aUpdateIdle;
72 
73 
74     css::uno::Sequence<
75         css::lang::Locale >                             aAvailSpellLocales;
76     css::uno::Sequence<
77         css::lang::Locale >                             aAvailGrammarLocales;
78     css::uno::Sequence<
79         css::lang::Locale >                             aAvailHyphLocales;
80     css::uno::Sequence<
81         css::lang::Locale >                             aAvailThesLocales;
82 
83     rtl::Reference<SpellCheckerDispatcher>              mxSpellDsp;
84     rtl::Reference<GrammarCheckingIterator>             mxGrammarDsp;
85     rtl::Reference<HyphenatorDispatcher>                mxHyphDsp;
86     rtl::Reference<ThesaurusDispatcher>                 mxThesDsp;
87 
88     rtl::Reference<LngSvcMgrListenerHelper>             mxListenerHelper;
89 
90     typedef std::vector< std::unique_ptr<SvcInfo> >    SvcInfoArray;
91     std::unique_ptr<SvcInfoArray>                      pAvailSpellSvcs;
92     std::unique_ptr<SvcInfoArray>                      pAvailGrammarSvcs;
93     std::unique_ptr<SvcInfoArray>                      pAvailHyphSvcs;
94     std::unique_ptr<SvcInfoArray>                      pAvailThesSvcs;
95 
96     bool bDisposing;
97 
98     LngSvcMgr(const LngSvcMgr &) = delete;
99     LngSvcMgr & operator = (const LngSvcMgr &) = delete;
100 
101     void    GetAvailableSpellSvcs_Impl();
102     void    GetAvailableGrammarSvcs_Impl();
103     void    GetAvailableHyphSvcs_Impl();
104     void    GetAvailableThesSvcs_Impl();
105     void    GetListenerHelper_Impl();
106 
107     void    GetSpellCheckerDsp_Impl( bool bSetSvcList = true );
108     void    GetGrammarCheckerDsp_Impl( bool bSetSvcList = true );
109     void    GetHyphenatorDsp_Impl( bool bSetSvcList = true );
110     void    GetThesaurusDsp_Impl( bool bSetSvcList = true );
111 
112     void    SetCfgServiceLists( SpellCheckerDispatcher &rSpellDsp );
113     void    SetCfgServiceLists( GrammarCheckingIterator &rGrammarDsp );
114     void    SetCfgServiceLists( HyphenatorDispatcher &rHyphDsp );
115     void    SetCfgServiceLists( ThesaurusDispatcher &rThesDsp );
116 
117     bool    SaveCfgSvcs( std::u16string_view rServiceName );
118 
119     // utl::ConfigItem (to allow for listening of changes of relevant properties)
120     virtual void    Notify( const css::uno::Sequence< OUString > &rPropertyNames ) override;
121     virtual void    ImplCommit() override;
122 
123     void UpdateAll();
124     void stopListening();
125     DECL_LINK( updateAndBroadcast, Timer*, void );
126 
127 public:
128     LngSvcMgr();
129     virtual ~LngSvcMgr() override;
130 
131     // XLinguServiceManager
132     virtual css::uno::Reference< css::linguistic2::XSpellChecker > SAL_CALL getSpellChecker(  ) override;
133     virtual css::uno::Reference< css::linguistic2::XHyphenator > SAL_CALL getHyphenator(  ) override;
134     virtual css::uno::Reference< css::linguistic2::XThesaurus > SAL_CALL getThesaurus(  ) override;
135     virtual sal_Bool SAL_CALL addLinguServiceManagerListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
136     virtual sal_Bool SAL_CALL removeLinguServiceManagerListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
137     virtual css::uno::Sequence< OUString > SAL_CALL getAvailableServices( const OUString& aServiceName, const css::lang::Locale& aLocale ) override;
138     virtual void SAL_CALL setConfiguredServices( const OUString& aServiceName, const css::lang::Locale& aLocale, const css::uno::Sequence< OUString >& aServiceImplNames ) override;
139     virtual css::uno::Sequence< OUString > SAL_CALL getConfiguredServices( const OUString& aServiceName, const css::lang::Locale& aLocale ) override;
140 
141     // XAvailableLocales
142     virtual css::uno::Sequence< css::lang::Locale > SAL_CALL getAvailableLocales( const OUString& aServiceName ) override;
143 
144     // XComponent
145     virtual void SAL_CALL dispose(  ) override;
146     virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
147     virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
148 
149     // XServiceInfo
150     virtual OUString SAL_CALL getImplementationName(  ) override;
151     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
152     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) override;
153 
154     // XEventListener
155     virtual void SAL_CALL disposing( const css::lang::EventObject& rSource ) override;
156 
157     // XModifyListener
158     virtual void SAL_CALL modified( const css::lang::EventObject& rEvent ) override;
159 
160     bool    AddLngSvcEvtBroadcaster(
161                 const css::uno::Reference< css::linguistic2::XLinguServiceEventBroadcaster > &rxBroadcaster );
162 };
163 
164 
165 #endif
166 
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
168