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