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_UNOTOOLS_LINGUCFG_HXX
21 #define INCLUDED_UNOTOOLS_LINGUCFG_HXX
22 
23 #include <unotools/unotoolsdllapi.h>
24 #include <com/sun/star/uno/Sequence.hxx>
25 #include <com/sun/star/uno/Any.h>
26 #include <rtl/ustring.hxx>
27 #include <unotools/options.hxx>
28 #include <i18nlangtag/lang.h>
29 #include <vector>
30 
31 namespace com { namespace sun { namespace star { namespace beans { struct PropertyValue; } } } }
32 namespace com { namespace sun { namespace star { namespace util { class XChangesBatch; } } } }
33 
34 class SvtLinguConfigItem;
35 
36 struct UNOTOOLS_DLLPUBLIC SvtLinguOptions
37 {
38     css::uno::Sequence< OUString >    aActiveDics;
39     css::uno::Sequence< OUString >    aActiveConvDics;
40 
41     bool                              bROActiveDics;
42     bool                              bROActiveConvDics;
43 
44     // Hyphenator service specific options
45     sal_Int16   nHyphMinLeading,
46             nHyphMinTrailing,
47             nHyphMinWordLength;
48 
49     bool    bROHyphMinLeading,
50             bROHyphMinTrailing,
51             bROHyphMinWordLength;
52 
53     // misc options (non-service specific)
54     LanguageType nDefaultLanguage;
55     LanguageType nDefaultLanguage_CJK;
56     LanguageType nDefaultLanguage_CTL;
57 
58     bool    bRODefaultLanguage;
59     bool    bRODefaultLanguage_CJK;
60     bool    bRODefaultLanguage_CTL;
61 
62     // spelling options (non-service specific)
63     bool    bIsSpellSpecial;
64     bool    bIsSpellAuto;
65     bool    bIsSpellReverse;
66 
67     bool    bROIsSpellSpecial;
68     bool    bROIsSpellAuto;
69     bool    bROIsSpellReverse;
70 
71     // hyphenation options (non-service specific)
72     bool    bIsHyphSpecial;
73     bool    bIsHyphAuto;
74 
75     bool    bROIsHyphSpecial;
76     bool    bROIsHyphAuto;
77 
78     // common to SpellChecker, Hyphenator and Thesaurus service
79     bool    bIsUseDictionaryList;
80     bool    bIsIgnoreControlCharacters;
81 
82     bool    bROIsUseDictionaryList;
83     bool    bROIsIgnoreControlCharacters;
84 
85     // SpellChecker service specific options
86     bool    bIsSpellWithDigits,
87             bIsSpellUpperCase,
88             bIsSpellCapitalization;
89 
90     bool    bROIsSpellWithDigits,
91             bROIsSpellUpperCase,
92             bROIsSpellCapitalization;
93 
94     // text conversion specific options
95     bool    bIsIgnorePostPositionalWord;
96     bool    bIsAutoCloseDialog;
97     bool    bIsShowEntriesRecentlyUsedFirst;
98     bool    bIsAutoReplaceUniqueEntries;
99     bool    bIsDirectionToSimplified;
100     bool    bIsUseCharacterVariants;
101     bool    bIsTranslateCommonTerms;
102     bool    bIsReverseMapping;
103 
104     bool    bROIsIgnorePostPositionalWord;
105     bool    bROIsAutoCloseDialog;
106     bool    bROIsShowEntriesRecentlyUsedFirst;
107     bool    bROIsAutoReplaceUniqueEntries;
108     bool    bROIsDirectionToSimplified;
109     bool    bROIsUseCharacterVariants;
110     bool    bROIsTranslateCommonTerms;
111     bool    bROIsReverseMapping;
112 
113     // check value need to determine if the configuration needs to be updated
114     // or not (used for a quick check if data files have been changed/added
115     // or deleted
116     sal_Int32   nDataFilesChangedCheckValue;
117     bool    bRODataFilesChangedCheckValue;
118 
119     bool    bIsGrammarAuto;
120     bool    bIsGrammarInteractive;
121 
122     bool    bROIsGrammarAuto;
123     bool    bROIsGrammarInteractive;
124 
125     SvtLinguOptions();
126 };
127 
128 struct UNOTOOLS_DLLPUBLIC SvtLinguConfigDictionaryEntry
129 {
130     // the URL's pointing to the location of the files the dictionary consists of
131     css::uno::Sequence< OUString >  aLocations;
132     // the name of the dictionary format implement
133     OUString                                   aFormatName;
134     // the list of languages (ISO names) the dictionary can be used for
135     css::uno::Sequence< OUString >  aLocaleNames;
136 };
137 
138 class UNOTOOLS_DLLPUBLIC SvtLinguConfig final : public utl::detail::Options
139 {
140     // returns static object
141     UNOTOOLS_DLLPRIVATE static SvtLinguConfigItem & GetConfigItem();
142 
143     // configuration update access for the 'Linguistic' main node
144     mutable css::uno::Reference< css::util::XChangesBatch > m_xMainUpdateAccess;
145 
146     css::uno::Reference< css::util::XChangesBatch > const & GetMainUpdateAccess() const;
147 
148     OUString GetVendorImageUrl_Impl( const OUString &rServiceImplName, const OUString &rImageName ) const;
149 
150     SvtLinguConfig( const SvtLinguConfig & ) = delete;
151     SvtLinguConfig & operator = ( const SvtLinguConfig & ) = delete;
152 
153 public:
154     SvtLinguConfig();
155     virtual ~SvtLinguConfig() override;
156 
157     // borrowed from utl::ConfigItem
158 
159     css::uno::Sequence< OUString >
160         GetNodeNames( const OUString &rNode ) const;
161 
162     css::uno::Sequence< css::uno::Any >
163         GetProperties(
164             const css::uno::Sequence< OUString > &rNames ) const;
165 
166     bool
167         ReplaceSetProperties(
168             const OUString &rNode,
169             const css::uno::Sequence< css::beans::PropertyValue >& rValues );
170 
171     css::uno::Any
172             GetProperty( const OUString &rPropertyName ) const;
173     css::uno::Any
174             GetProperty( sal_Int32 nPropertyHandle ) const;
175 
176     bool    SetProperty( const OUString &rPropertyName,
177                          const css::uno::Any &rValue );
178     bool    SetProperty( sal_Int32 nPropertyHandle,
179                          const css::uno::Any &rValue );
180 
181     void    GetOptions( SvtLinguOptions &rOptions ) const;
182 
183     bool    IsReadOnly( const OUString &rPropertyName ) const;
184 
185     //!
186     //! the following functions work on the 'ServiceManager' sub node of the
187     //! linguistic configuration only
188     //!
189     bool GetElementNamesFor( const OUString &rNodeName, css::uno::Sequence< OUString > &rElementNames ) const;
190 
191     bool GetSupportedDictionaryFormatsFor( const OUString &rSetName, const OUString &rSetEntry, css::uno::Sequence< OUString > &rFormatList ) const;
192 
193     bool GetDictionaryEntry( const OUString &rNodeName, SvtLinguConfigDictionaryEntry &rDicEntry ) const;
194 
195     css::uno::Sequence< OUString > GetDisabledDictionaries() const;
196 
197     std::vector< SvtLinguConfigDictionaryEntry > GetActiveDictionariesByFormat( const OUString &rFormatName ) const;
198 
199     // functions returning file URLs to the respective images (if found) and empty string otherwise
200     OUString     GetSpellAndGrammarContextSuggestionImage( const OUString &rServiceImplName ) const;
201     OUString     GetSpellAndGrammarContextDictionaryImage( const OUString &rServiceImplName ) const;
202     OUString     GetSynonymsContextImage( const OUString &rServiceImplName ) const;
203 
204     bool                HasGrammarChecker() const;
205 };
206 
207 #endif
208 
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
210