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_DLISTIMP_HXX
21 #define INCLUDED_LINGUISTIC_SOURCE_DLISTIMP_HXX
22 
23 #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
24 #include <com/sun/star/lang/XComponent.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 
27 #include <cppuhelper/implbase.hxx>
28 #include <rtl/ref.hxx>
29 
30 #include <vector>
31 
32 #include <linguistic/misc.hxx>
33 #include "lngopt.hxx"
34 
35 class DicEvtListenerHelper;
36 
37 
38 class DicList :
39     public cppu::WeakImplHelper
40     <
41         css::linguistic2::XSearchableDictionaryList,
42         css::lang::XComponent,
43         css::lang::XServiceInfo
44     >
45 {
46     class MyAppExitListener : public linguistic::AppExitListener
47     {
48         DicList & rMyDicList;
49 
50     public:
MyAppExitListener(DicList & rDicList)51         explicit MyAppExitListener( DicList &rDicList ) : rMyDicList( rDicList ) {}
52         virtual void    AtExit() override;
53     };
54 
55     LinguOptions    aOpt;
56 
57     ::comphelper::OInterfaceContainerHelper2    aEvtListeners;
58 
59     typedef std::vector< css::uno::Reference< css::linguistic2::XDictionary > >   DictionaryVec_t;
60     DictionaryVec_t                             aDicList;
61 
62     rtl::Reference<DicEvtListenerHelper>        mxDicEvtLstnrHelper;
63     rtl::Reference<MyAppExitListener>           mxExitListener;
64 
65     bool    bDisposing;
66     bool    bInCreation;
67 
68     DicList( const DicList & ) = delete;
69     DicList & operator = (const DicList &) = delete;
70 
71     void                CreateDicList();
GetOrCreateDicList()72     DictionaryVec_t &   GetOrCreateDicList()
73                         {
74                             if ( !bInCreation && aDicList.empty() )
75                                 CreateDicList();
76                             return aDicList;
77                         }
78 
79     void                SearchForDictionaries( DictionaryVec_t &rDicList,
80                                             const OUString &rDicDir, bool bIsWritePath );
81     sal_Int32           GetDicPos(const css::uno::Reference<
82                             css::linguistic2::XDictionary > &xDic);
83 
84 public:
85     DicList();
86     virtual ~DicList() override;
87 
88     // XDictionaryList
89     virtual ::sal_Int16 SAL_CALL getCount(  ) override;
90     virtual css::uno::Sequence< css::uno::Reference< css::linguistic2::XDictionary > > SAL_CALL getDictionaries(  ) override;
91     virtual css::uno::Reference< css::linguistic2::XDictionary > SAL_CALL getDictionaryByName( const OUString& aDictionaryName ) override;
92     virtual sal_Bool SAL_CALL addDictionary( const css::uno::Reference< css::linguistic2::XDictionary >& xDictionary ) override;
93     virtual sal_Bool SAL_CALL removeDictionary( const css::uno::Reference< css::linguistic2::XDictionary >& xDictionary ) override;
94     virtual sal_Bool SAL_CALL addDictionaryListEventListener( const css::uno::Reference< css::linguistic2::XDictionaryListEventListener >& xListener, sal_Bool bReceiveVerbose ) override;
95     virtual sal_Bool SAL_CALL removeDictionaryListEventListener( const css::uno::Reference< css::linguistic2::XDictionaryListEventListener >& xListener ) override;
96     virtual ::sal_Int16 SAL_CALL beginCollectEvents(  ) override;
97     virtual ::sal_Int16 SAL_CALL endCollectEvents(  ) override;
98     virtual ::sal_Int16 SAL_CALL flushEvents(  ) override;
99     virtual css::uno::Reference< css::linguistic2::XDictionary > SAL_CALL createDictionary( const OUString& aName, const css::lang::Locale& aLocale, css::linguistic2::DictionaryType eDicType, const OUString& aURL ) override;
100 
101     // XSearchableDictionaryList
102     virtual css::uno::Reference< css::linguistic2::XDictionaryEntry > SAL_CALL queryDictionaryEntry( const OUString& aWord, const css::lang::Locale& aLocale, sal_Bool bSearchPosDics, sal_Bool bSpellEntry ) override;
103 
104     // XComponent
105     virtual void SAL_CALL dispose() override;
106     virtual void SAL_CALL addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener ) override;
107     virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& aListener ) override;
108 
109     // XServiceInfo
110     virtual OUString SAL_CALL getImplementationName() override;
111     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
112     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
113 
114     // non UNO-specific
115     void    SaveDics();
116 };
117 
118 #endif
119 
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
121