1 /* 2 * Copyright (c) 2022 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 UPDATER_UI_TRAITS_H 17 #define UPDATER_UI_TRAITS_H 18 19 #include "component/component_factory.h" 20 #include "json_visitor.h" 21 #include "macros.h" 22 #include "traits_util.h" 23 24 namespace Updater { 25 // define struct for load ui strategy in ui config file 26 DEFINE_STRUCT_TRAIT(ComInfo, "com", 27 (std::string, pageId), 28 (std::string, comId) 29 ); 30 31 DEFINE_STRUCT_TRAIT(ProgressPage, "", 32 (std::string, progressPageId), 33 (std::string, progressComId), 34 (std::string, progressType), 35 (std::string, logoComId), 36 (std::string, logoType), 37 (std::string, warningComId) 38 ); 39 40 DEFINE_STRUCT_TRAIT(ResPage, "", 41 (std::string, successPageId), 42 (std::string, failPageId) 43 ); 44 45 DEFINE_STRUCT_TRAIT(UiStrategyCfg, "strategy", 46 (std::string, confirmPageId), 47 (ComInfo, labelLogId), 48 (ComInfo, labelLogResId), 49 (ComInfo, labelUpdId), 50 (ProgressPage, progressPage), 51 (ResPage, resPage) 52 ); 53 54 // define struct for load pages' components from page json config, such as menu.json, update.json 55 DEFINE_TRAIT(UxViewCommonInfo, "Common", 56 (int, x), 57 (int, y), 58 (int, w), 59 (int, h), 60 (std::string, id), 61 (std::string, type), 62 (bool, visible) 63 ); 64 65 DEFINE_TRAIT(UxBoxProgressInfo, BoxProgressAdapter::COMPONENT_TYPE, 66 (uint32_t, defaultValue), 67 (std::string, fgColor), 68 (std::string, bgColor), 69 (std::string, endPoint), 70 (bool, hasEp) 71 ); 72 73 DEFINE_TRAIT(UxLabelInfo, TextLabelAdapter::COMPONENT_TYPE, 74 (uint8_t, fontSize), 75 (std::string, text), 76 (std::string, align), 77 (std::string, fontColor), 78 (std::string, bgColor) 79 ); 80 81 DEFINE_TRAIT(UxImageInfo, ImgViewAdapter::COMPONENT_TYPE, 82 (std::string, resPath), 83 (std::string, filePrefix), 84 (uint32_t, imgCnt), 85 (uint32_t, updInterval) 86 ); 87 88 DEFINE_TRAIT(UxLabelBtnInfo, LabelBtnAdapter::COMPONENT_TYPE, 89 (uint8_t, fontSize), 90 (std::string, text), 91 (std::string, txtColor), 92 (std::string, bgColor), 93 (std::string, focusedTxtColor), 94 (std::string, focusedBgColor), 95 (bool, focusable) 96 ); 97 98 DEFINE_STRUCT_TRAIT(UxSubPageInfo, "subpages", 99 (std::string, id), 100 (std::string, bgColor), 101 (std::vector<std::string>, coms) 102 ); 103 104 DEFINE_STRUCT_TRAIT(PagePath, "", 105 (std::string, dir), 106 (std::string, entry), 107 (std::vector<std::string>, pages) 108 ); 109 110 struct UxPageInfo { 111 std::string id {}; 112 std::string bgColor {}; 113 std::vector<UxViewInfo> viewInfos {}; 114 std::vector<UxSubPageInfo> subpages {}; 115 }; 116 117 /** 118 * only define trait for uxpageinfo, because viewInfos_ is a variant, 119 * can't be parsed by Visit<SETVAL>(...), so it's manually parsed in 120 * LayoutParser 121 */ 122 DEFINE_TRAIT(UxPageInfo, "", 123 (std::string, id), 124 (std::string, bgColor), 125 (std::vector<UxSubPageInfo>, subpages) 126 ); 127 128 // define struct for load language resources in ui config file 129 DEFINE_STRUCT_TRAIT(Res, "Res", 130 (std::string, path), 131 (int, level) 132 ); 133 134 DEFINE_STRUCT_TRAIT(LangResource, "", 135 (std::string, localeFile), 136 (std::vector<Res>, res) 137 ); 138 139 // define struct for load callback configuration in ui config file 140 DEFINE_STRUCT_TRAIT(CallbackCfg, "", 141 (std::string, pageId), 142 (std::string, comId), 143 (std::string, type), 144 (std::string, func) 145 ); 146 147 inline std::ostream &operator<<(std::ostream &os, const ComInfo &com) 148 { 149 os << "pageId: " << com.pageId << " comId: " << com.comId; 150 return os; 151 } 152 } 153 #endif 154