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 VIBRATION_FILE, 34 }; 35 36 class RingtoneLanguageManager { 37 public: 38 EXPORT RingtoneLanguageManager(); 39 EXPORT ~RingtoneLanguageManager(); 40 EXPORT static std::shared_ptr<RingtoneLanguageManager> GetInstance(); 41 42 EXPORT void SyncAssetLanguage(); 43 44 private: 45 EXPORT static std::string GetSystemLanguage(); 46 EXPORT void UpdateRingtoneLanguage(); 47 EXPORT void UpdateVibrationLanguage(); 48 49 EXPORT int32_t CheckLanguageTypeByRingtone(int32_t &rowCount, std::shared_ptr<NativeRdb::ResultSet> &resultSet); 50 EXPORT void ChangeLanguageDataToRingtone(int32_t rowCount, const std::shared_ptr<NativeRdb::ResultSet> &resultSet); 51 EXPORT static int32_t GetFieldIndex(const std::shared_ptr<NativeRdb::ResultSet> &resultSet, 52 std::map<std::string, int> &fieldIndex); 53 EXPORT int32_t SetValuesFromResultSet(const std::shared_ptr<NativeRdb::ResultSet> &resultSet, 54 const std::map<std::string, int> &fieldIndex, NativeRdb::ValuesBucket &values, int32_t &indexId, 55 ResourceFileType resourceFileType); 56 57 EXPORT int32_t CheckLanguageTypeByVibration(int32_t &rowCount, std::shared_ptr<NativeRdb::ResultSet> &resultSet); 58 EXPORT void ChangeLanguageDataToVibration(int32_t rowCount, const std::shared_ptr<NativeRdb::ResultSet> &resultSet); 59 60 EXPORT bool ReadMultilingualResources(const std::string &filePath, ResourceFileType resourceFileType); 61 EXPORT bool ParseMultilingualXml(xmlNodePtr& parentNode, ResourceFileType resourceFileType); 62 63 std::map<std::string, std::map<std::string, std::string>> ringtoneTranslate_; 64 std::map<std::string, std::map<std::string, std::string>> vibrationTranslate_; 65 std::string systemLanguage_; 66 static std::mutex mutex_; 67 static std::shared_ptr<RingtoneLanguageManager> instance_; 68 }; 69 } // namespace Media 70 } // namespace OHOS 71 #endif // RINGTONE_LANGUAGE_MANAGER_H 72