1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _unotools_LINGUCFG_HXX_
25 #define _unotools_LINGUCFG_HXX_
26 
27 #include "unotools/unotoolsdllapi.h"
28 #include <com/sun/star/beans/PropertyValues.hpp>
29 #include <com/sun/star/uno/Sequence.hxx>
30 #include <com/sun/star/uno/Any.h>
31 #include <com/sun/star/lang/Locale.hpp>
32 #include <com/sun/star/util/XChangesBatch.hpp>
33 #include <tools/solar.h>
34 #include <rtl/ustring.hxx>
35 #include <unotools/configitem.hxx>
36 #include <osl/mutex.hxx>
37 #include <unotools/options.hxx>
38 #include <i18npool/lang.h>
39 
40 #include <vector>
41 
42 class SvtLinguConfigItem;
43 
44 //////////////////////////////////////////////////////////////////////
45 
46 struct UNOTOOLS_DLLPUBLIC SvtLinguOptions
47 {
48 	::com::sun::star::uno::Sequence< rtl::OUString >	aActiveDics;
49     ::com::sun::star::uno::Sequence< rtl::OUString >    aActiveConvDics;
50 
51     sal_Bool                                                bROActiveDics;
52     sal_Bool                                                bROActiveConvDics;
53 
54 	// Hyphenator service specific options
55 	sal_Int16	nHyphMinLeading,
56 			nHyphMinTrailing,
57 			nHyphMinWordLength;
58 
59     sal_Bool    bROHyphMinLeading,
60             bROHyphMinTrailing,
61             bROHyphMinWordLength;
62 
63 	// misc options (non-service specific)
64 	sal_Int16	nDefaultLanguage;
65 	sal_Int16	nDefaultLanguage_CJK;
66 	sal_Int16	nDefaultLanguage_CTL;
67 
68     sal_Bool    bRODefaultLanguage;
69     sal_Bool    bRODefaultLanguage_CJK;
70     sal_Bool    bRODefaultLanguage_CTL;
71 
72 	// spelling options (non-service specific)
73 	sal_Bool	bIsSpellSpecial;
74 	sal_Bool	bIsSpellAuto;
75 	sal_Bool	bIsSpellReverse;
76 
77     sal_Bool    bROIsSpellSpecial;
78     sal_Bool    bROIsSpellAuto;
79     sal_Bool    bROIsSpellReverse;
80 
81 	// hyphenation options (non-service specific)
82 	sal_Bool	bIsHyphSpecial;
83 	sal_Bool	bIsHyphAuto;
84 
85     sal_Bool    bROIsHyphSpecial;
86     sal_Bool    bROIsHyphAuto;
87 
88 	// common to SpellChecker, Hyphenator and Thesaurus service
89 	sal_Bool	bIsUseDictionaryList;
90 	sal_Bool	bIsIgnoreControlCharacters;
91 
92     sal_Bool    bROIsUseDictionaryList;
93     sal_Bool    bROIsIgnoreControlCharacters;
94 
95 	// SpellChecker service specific options
96 	sal_Bool	bIsSpellWithDigits,
97 			bIsSpellUpperCase,
98 			bIsSpellCapitalization;
99 
100     sal_Bool    bROIsSpellWithDigits,
101             bROIsSpellUpperCase,
102             bROIsSpellCapitalization;
103 
104     // text conversion specific options
105     sal_Bool    bIsIgnorePostPositionalWord;
106     sal_Bool    bIsAutoCloseDialog;
107     sal_Bool    bIsShowEntriesRecentlyUsedFirst;
108     sal_Bool    bIsAutoReplaceUniqueEntries;
109     sal_Bool    bIsDirectionToSimplified;
110     sal_Bool    bIsUseCharacterVariants;
111     sal_Bool    bIsTranslateCommonTerms;
112     sal_Bool    bIsReverseMapping;
113 
114     sal_Bool    bROIsIgnorePostPositionalWord;
115     sal_Bool    bROIsAutoCloseDialog;
116     sal_Bool    bROIsShowEntriesRecentlyUsedFirst;
117     sal_Bool    bROIsAutoReplaceUniqueEntries;
118     sal_Bool    bROIsDirectionToSimplified;
119     sal_Bool    bROIsUseCharacterVariants;
120     sal_Bool    bROIsTranslateCommonTerms;
121     sal_Bool    bROIsReverseMapping;
122 
123     // check value need to determine if the configuration needs to updatet
124     // or not (used for a quick check if data files have been changed/added
125     // or deleted
126     sal_Int32   nDataFilesChangedCheckValue;
127     sal_Bool    bRODataFilesChangedCheckValue;
128 
129     sal_Bool    bIsGrammarAuto;
130     sal_Bool    bIsGrammarInteractive;
131 
132     sal_Bool    bROIsGrammarAuto;
133     sal_Bool    bROIsGrammarInteractive;
134 
135 	SvtLinguOptions();
136 };
137 
138 //////////////////////////////////////////////////////////////////////
139 
140 struct UNOTOOLS_DLLPUBLIC SvtLinguConfigDictionaryEntry
141 {
142 	// the URL's pointing to the location of the files the dictionary consists of
143     com::sun::star::uno::Sequence< rtl::OUString >	aLocations;
144     // the name of the dictionary format implement
145 	rtl::OUString									aFormatName;
146     // the list of languages (ISO names) the dictionary can be used for
147 	com::sun::star::uno::Sequence< rtl::OUString >	aLocaleNames;
148 };
149 
150 //////////////////////////////////////////////////////////////////////
151 
152 class UNOTOOLS_DLLPUBLIC SvtLinguConfig: public utl::detail::Options
153 {
154     // returns static object
155     UNOTOOLS_DLLPRIVATE SvtLinguConfigItem &   GetConfigItem();
156 
GetConfigItem() const157     SvtLinguConfigItem &   GetConfigItem() const    { return const_cast< SvtLinguConfig * >( this )->GetConfigItem(); }
158 
159     // configuration update access for the 'Linguistic' main node
160     mutable com::sun::star::uno::Reference< com::sun::star::util::XChangesBatch > m_xMainUpdateAccess;
161 
162     com::sun::star::uno::Reference< com::sun::star::util::XChangesBatch > GetMainUpdateAccess() const;
163 
164     com::sun::star::uno::Sequence< rtl::OUString > GetCurrentOrLastActiveDicts_Impl( const rtl::OUString &rPropName ) const;
165     void SetCurrentOrLastActiveDicts_Impl( const rtl::OUString &rPropName, const com::sun::star::uno::Sequence< rtl::OUString > &rDictionaries ) const;
166 
167     rtl::OUString GetVendorImageUrl_Impl( const rtl::OUString &rServiceImplName, const rtl::OUString &rImageName ) const;
168 
169     // disallow copy-constructor and assignment-operator for now
170     SvtLinguConfig( const SvtLinguConfig & );
171     SvtLinguConfig & operator = ( const SvtLinguConfig & );
172 
173 public:
174     SvtLinguConfig();
175     virtual ~SvtLinguConfig();
176 
177     //
178     // borrowed from utl::ConfigItem
179     //
180     com::sun::star::uno::Sequence< rtl::OUString >
181         GetNodeNames( const rtl::OUString &rNode );
182     //
183     com::sun::star::uno::Sequence< com::sun::star::uno::Any >
184         GetProperties(
185             const com::sun::star::uno::Sequence< rtl::OUString > &rNames );
186     //
187     sal_Bool
188         ReplaceSetProperties(
189             const rtl::OUString &rNode,
190             com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > rValues );
191 
192 	com::sun::star::uno::Any
193             GetProperty( const rtl::OUString &rPropertyName ) const;
194     com::sun::star::uno::Any
195             GetProperty( sal_Int32 nPropertyHandle ) const;
196 
197 	sal_Bool    SetProperty( const rtl::OUString &rPropertyName,
198                          const com::sun::star::uno::Any &rValue );
199     sal_Bool    SetProperty( sal_Int32 nPropertyHandle,
200                          const com::sun::star::uno::Any &rValue );
201 
202     sal_Bool    GetOptions( SvtLinguOptions &rOptions ) const;
203     sal_Bool    SetOptions( const SvtLinguOptions &rOptions );
204 
205     sal_Bool    IsReadOnly( const rtl::OUString &rPropertyName ) const;
206     sal_Bool    IsReadOnly( sal_Int32 nPropertyHandle ) const;
207 
208     //!
209     //! the following functions work on the 'ServiceManager' sub node of the
210     //! linguistic configuration only
211     //!
212     sal_Bool GetElementNamesFor( const rtl::OUString &rNodeName, com::sun::star::uno::Sequence< rtl::OUString > &rElementNames ) const;
213     //
214     sal_Bool GetSupportedDictionaryFormatsFor( const rtl::OUString &rSetName, const rtl::OUString &rSetEntry, com::sun::star::uno::Sequence< rtl::OUString > &rFormatList ) const;
215     void SetOrCreateSupportedDictionaryFormatsFor( const rtl::OUString &rSetName, const rtl::OUString &rSetEntry, const com::sun::star::uno::Sequence< rtl::OUString > &rFormatList  ) const;
216     //
217     sal_Bool GetDictionaryEntry( const rtl::OUString &rNodeName, SvtLinguConfigDictionaryEntry &rDicEntry ) const;
218     void SetOrCreateDictionaryEntry( const rtl::OUString &rNodeName, const SvtLinguConfigDictionaryEntry &rDicEntry ) const;
219     //
220     com::sun::star::uno::Sequence< rtl::OUString > GetDisabledDictionaries() const;
221     void SetDisabledDictionaries( const com::sun::star::uno::Sequence< rtl::OUString > &rDictionaries ) const;
222 	//
223     std::vector< SvtLinguConfigDictionaryEntry > GetActiveDictionariesByFormat( const rtl::OUString &rFormatName );
224 
225     // functions returning file URLs to the respective images (if found) and empty string otherwise
226     ::rtl::OUString     GetSpellAndGrammarDialogImage( const ::rtl::OUString &rServiceImplName, bool bHighContrast = false ) const;
227     ::rtl::OUString     GetSpellAndGrammarContextSuggestionImage( const ::rtl::OUString &rServiceImplName, bool bHighContrast = false ) const;
228     ::rtl::OUString     GetSpellAndGrammarContextDictionaryImage( const ::rtl::OUString &rServiceImplName, bool bHighContrast = false ) const;
229     ::rtl::OUString     GetThesaurusDialogImage( const ::rtl::OUString &rServiceImplName, bool bHighContrast = false ) const;
230     ::rtl::OUString     GetSynonymsContextImage( const ::rtl::OUString &rServiceImplName, bool bHighContrast = false ) const;
231 
232     bool                HasVendorImages( const char *pImageName ) const;
233     bool                HasGrammarChecker() const;
234 };
235 
236 //////////////////////////////////////////////////////////////////////
237 
238 #endif
239 
240