1 /* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef RINGTONE_LANGUAGE_MANAGER_H 17 #define RINGTONE_LANGUAGE_MANAGER_H 18 19 #include "result_set.h" 20 #include "values_bucket.h" 21 22 #include <cstdint> 23 #include <libxml/tree.h> 24 #include <memory> 25 #include <mutex> 26 27 namespace OHOS { 28 namespace Media { 29 #define EXPORT __attribute__ ((visibility ("default"))) 30 31 enum ResourceFileType { 32 RINGTONE_FILE, 33 }; 34 35 class RingtoneLanguageManager { 36 public: 37 EXPORT RingtoneLanguageManager(); 38 EXPORT ~RingtoneLanguageManager(); 39 EXPORT static std::shared_ptr<RingtoneLanguageManager> GetInstance(); 40 41 EXPORT void SyncAssetLanguage(); 42 43 private: 44 EXPORT static std::string GetSystemLanguage(); 45 EXPORT void UpdateRingtoneLanguage(); 46 47 EXPORT int32_t CheckLanguageTypeByRingtone(int32_t &rowCount, std::shared_ptr<NativeRdb::ResultSet> &resultSet); 48 EXPORT void ChangeLanguageDataToRingtone(int32_t rowCount, const std::shared_ptr<NativeRdb::ResultSet> &resultSet); 49 EXPORT int32_t SetValuesFromResultSet(const std::shared_ptr<NativeRdb::ResultSet> &resultSet, 50 const std::vector<std::pair<std::string, int>> &fieldIndex, 51 NativeRdb::ValuesBucket &values, int32_t &ringtoneId); 52 EXPORT static int32_t GetFieldIndex(const std::shared_ptr<NativeRdb::ResultSet> &resultSet, 53 std::vector<std::pair<std::string, int>> &fieldIndex); 54 55 EXPORT bool ReadMultilingualResources(const std::string &filePath, ResourceFileType resourceFileType); 56 EXPORT bool ParseMultilingualXml(xmlNodePtr& parentNode, ResourceFileType resourceFileType); 57 58 std::map<std::string, std::map<std::string, std::string>> ringtoneTranslate_; 59 std::string systemLanguage_; 60 static std::mutex mutex_; 61 static std::shared_ptr<RingtoneLanguageManager> instance_; 62 }; 63 } // namespace Media 64 } // namespace OHOS 65 #endif // RINGTONE_LANGUAGE_MANAGER_H 66