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 #ifndef INCLUDED_LINGUISTIC_SOURCE_CONVDIC_HXX 20 #define INCLUDED_LINGUISTIC_SOURCE_CONVDIC_HXX 21 22 #include <com/sun/star/linguistic2/XConversionDictionary.hpp> 23 #include <com/sun/star/linguistic2/XConversionPropertyType.hpp> 24 #include <com/sun/star/util/XFlushable.hpp> 25 #include <com/sun/star/lang/XServiceInfo.hpp> 26 #include <cppuhelper/implbase.hxx> 27 #include <comphelper/interfacecontainer2.hxx> 28 #include <i18nlangtag/lang.h> 29 30 #include <memory> 31 #include <unordered_map> 32 33 // text conversion dictionary extension 34 #define CONV_DIC_EXT "tcd" 35 #define CONV_DIC_DOT_EXT ".tcd" 36 37 #define SN_CONV_DICTIONARY "com.sun.star.linguistic2.ConversionDictionary" 38 39 40 bool IsConvDic( const OUString &rFileURL, LanguageType &nLang, sal_Int16 &nConvType ); 41 42 typedef std::unordered_multimap<OUString, OUString> ConvMap; 43 typedef std::unordered_multimap<OUString, sal_Int16> PropTypeMap; 44 45 class ConvDic : 46 public ::cppu::WeakImplHelper 47 < 48 css::linguistic2::XConversionDictionary, 49 css::linguistic2::XConversionPropertyType, 50 css::util::XFlushable, 51 css::lang::XServiceInfo 52 > 53 { 54 friend class ConvDicXMLExport; 55 56 protected: 57 58 ::comphelper::OInterfaceContainerHelper2 aFlushListeners; 59 60 ConvMap aFromLeft; 61 std::unique_ptr< ConvMap > pFromRight; // only available for bidirectional conversion dictionaries 62 63 std::unique_ptr< PropTypeMap > pConvPropType; 64 65 OUString aMainURL; // URL to file 66 OUString aName; 67 LanguageType nLanguage; 68 sal_Int16 nConversionType; 69 sal_Int16 nMaxLeftCharCount; 70 sal_Int16 nMaxRightCharCount; 71 bool bMaxCharCountIsValid; 72 bool bNeedEntries; 73 bool bIsModified; 74 bool bIsActive; 75 76 // disallow copy-constructor and assignment-operator for now 77 ConvDic(const ConvDic &); 78 ConvDic & operator = (const ConvDic &); 79 80 static ConvMap::iterator GetEntry( ConvMap &rMap, const OUString &rFirstText, std::u16string_view rSecondText ); 81 void Load(); 82 void Save(); 83 84 public: 85 ConvDic( const OUString &rName, 86 LanguageType nLanguage, 87 sal_Int16 nConversionType, 88 bool bBiDirectional, 89 const OUString &rMainURL); 90 virtual ~ConvDic() override; 91 92 // XConversionDictionary 93 virtual OUString SAL_CALL getName( ) override; 94 virtual css::lang::Locale SAL_CALL getLocale( ) override; 95 virtual sal_Int16 SAL_CALL getConversionType( ) override; 96 virtual void SAL_CALL setActive( sal_Bool bActivate ) override; 97 virtual sal_Bool SAL_CALL isActive( ) override; 98 virtual void SAL_CALL clear( ) override; 99 virtual css::uno::Sequence< OUString > SAL_CALL getConversions( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength, css::linguistic2::ConversionDirection eDirection, sal_Int32 nTextConversionOptions ) override; 100 virtual css::uno::Sequence< OUString > SAL_CALL getConversionEntries( css::linguistic2::ConversionDirection eDirection ) override; 101 virtual void SAL_CALL addEntry( const OUString& aLeftText, const OUString& aRightText ) override; 102 virtual void SAL_CALL removeEntry( const OUString& aLeftText, const OUString& aRightText ) override; 103 virtual sal_Int16 SAL_CALL getMaxCharCount( css::linguistic2::ConversionDirection eDirection ) override; 104 105 // XConversionPropertyType 106 virtual void SAL_CALL setPropertyType( const OUString& aLeftText, const OUString& aRightText, ::sal_Int16 nPropertyType ) override; 107 virtual ::sal_Int16 SAL_CALL getPropertyType( const OUString& aLeftText, const OUString& aRightText ) override; 108 109 // XFlushable 110 virtual void SAL_CALL flush( ) override; 111 virtual void SAL_CALL addFlushListener( const css::uno::Reference< css::util::XFlushListener >& l ) override; 112 virtual void SAL_CALL removeFlushListener( const css::uno::Reference< css::util::XFlushListener >& l ) override; 113 114 // XServiceInfo 115 virtual OUString SAL_CALL getImplementationName( ) override; 116 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; 117 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; 118 119 bool HasEntry( const OUString &rLeftText, std::u16string_view rRightText ); 120 void AddEntry( const OUString &rLeftText, const OUString &rRightText ); 121 void RemoveEntry( const OUString &rLeftText, const OUString &rRightText ); 122 }; 123 124 #endif 125 126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 127