Rev 5626 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5626 | Rev 5640 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | SOFTWARE CENTER v2.31 |
2 | SOFTWARE CENTER v2.31 |
3 | */ |
3 | */ |
4 | 4 | ||
5 | #define MEMSIZE 0x3E80 |
5 | #define MEMSIZE 0x3E80 |
6 | #include "..\lib\kolibri.h" |
6 | #include "..\lib\kolibri.h" |
7 | #include "..\lib\strings.h" |
7 | #include "..\lib\strings.h" |
8 | #include "..\lib\mem.h" |
8 | #include "..\lib\mem.h" |
9 | #include "..\lib\file_system.h" |
9 | #include "..\lib\file_system.h" |
10 | #include "..\lib\dll.h" |
10 | #include "..\lib\dll.h" |
11 | #include "..\lib\gui.h" |
11 | #include "..\lib\gui.h" |
12 | 12 | ||
13 | #include "..\lib\obj\libio_lib.h" |
13 | #include "..\lib\obj\libio_lib.h" |
14 | #include "..\lib\obj\libimg_lib.h" |
14 | #include "..\lib\obj\libimg_lib.h" |
15 | #include "..\lib\obj\libini.h" |
15 | #include "..\lib\obj\libini.h" |
16 | 16 | ||
17 | #include "..\lib\patterns\libimg_load_skin.h" |
17 | #include "..\lib\patterns\libimg_load_skin.h" |
18 | 18 | ||
19 | system_colors sc; |
19 | system_colors sc; |
20 | proc_info Form; |
20 | proc_info Form; |
21 | mouse m; |
- | |
22 | 21 | ||
23 | byte kolibrios_mounted; |
22 | byte kolibrios_mounted; |
24 | 23 | ||
25 | int item_id_need_to_run=-1, |
24 | int item_id_need_to_run=-1, |
26 | current_item_id; |
25 | current_item_id; |
27 | 26 | ||
28 | int window_width, |
27 | int window_width, |
29 | window_height; |
28 | window_height; |
30 | 29 | ||
31 | int col_max, |
30 | int col_max, |
32 | cell_w, |
31 | cell_w, |
33 | cell_h, |
32 | cell_h, |
34 | list_pos, |
33 | list_pos, |
35 | list_top, |
34 | list_top, |
36 | row, |
35 | row, |
37 | old_row, //to detect empty sections |
36 | old_row, //to detect empty sections |
38 | col, |
37 | col, |
39 | default_icon; |
38 | default_icon; |
40 | 39 | ||
41 | char window_title[128], |
40 | char window_title[128], |
42 | settings_ini_path[256] = "/sys/settings/"; |
41 | settings_ini_path[256] = "/sys/settings/"; |
43 | 42 | ||
44 | #define LIST_BACKGROUND_COLOR 0xF3F3F3 |
43 | #define LIST_BACKGROUND_COLOR 0xF3F3F3 |
45 | 44 | ||
46 | libimg_image skin; |
45 | libimg_image skin; |
47 | 46 | ||
48 | void load_config() |
47 | void load_config() |
49 | { |
48 | { |
50 | ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget"); |
49 | ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget"); |
51 | ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690); |
50 | ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690); |
52 | window_width = EAX; |
51 | window_width = EAX; |
53 | ini_get_int stdcall (#settings_ini_path, "Config", "window_height", 540); |
52 | ini_get_int stdcall (#settings_ini_path, "Config", "window_height", 540); |
54 | window_height = EAX; |
53 | window_height = EAX; |
55 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 66); |
54 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 66); |
56 | cell_w = EAX; |
55 | cell_w = EAX; |
57 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 64); |
56 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 64); |
58 | cell_h = EAX; |
57 | cell_h = EAX; |
59 | ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0); |
58 | ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0); |
60 | default_icon = EAX; |
59 | default_icon = EAX; |
61 | } |
60 | } |
62 | 61 | ||
63 | 62 | ||
64 | void main() |
63 | void main() |
65 | { |
64 | { |
66 | dword id, key; |
65 | dword id, key; |
67 | mem_Init(); |
66 | mem_Init(); |
68 | load_dll(libio, #libio_init,1); |
67 | load_dll(libio, #libio_init,1); |
69 | load_dll(libimg, #libimg_init,1); |
68 | load_dll(libimg, #libimg_init,1); |
70 | load_dll(libini, #lib_init,1); |
69 | load_dll(libini, #lib_init,1); |
71 | 70 | ||
72 | Libimg_LoadImage(#skin, "/sys/icons32.png"); |
71 | Libimg_LoadImage(#skin, "/sys/icons32.png"); |
73 | Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR); |
72 | Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR); |
74 | 73 | ||
75 | if (param) |
74 | if (param) |
76 | { |
75 | { |
77 | strcpy(#settings_ini_path, #param); |
76 | strcpy(#settings_ini_path, #param); |
78 | } |
77 | } |
79 | else |
78 | else |
80 | { |
79 | { |
81 | strcat(#settings_ini_path, #program_path + strrchr(#program_path, '/')); |
80 | strcat(#settings_ini_path, #program_path + strrchr(#program_path, '/')); |
82 | strcat(#settings_ini_path, ".ini"); |
81 | strcat(#settings_ini_path, ".ini"); |
83 | } |
82 | } |
84 | load_config(); |
83 | load_config(); |
85 | 84 | ||
86 | loop() |
85 | loop() |
87 | { |
86 | { |
88 | switch(WaitEvent()) |
87 | switch(WaitEvent()) |
89 | { |
88 | { |
90 | case evButton: |
89 | case evButton: |
91 | id=GetButtonID(); |
90 | id=GetButtonID(); |
92 | if (id==1) ExitProcess(); |
91 | if (id==1) ExitProcess(); |
93 | if (id>=100) |
92 | if (id>=100) |
94 | { |
93 | { |
95 | item_id_need_to_run = id - 100; |
94 | item_id_need_to_run = id - 100; |
96 | current_item_id = 0; |
95 | current_item_id = 0; |
97 | ini_enum_sections stdcall (#settings_ini_path, #process_sections); |
96 | ini_enum_sections stdcall (#settings_ini_path, #process_sections); |
98 | item_id_need_to_run = -1; |
97 | item_id_need_to_run = -1; |
99 | } |
98 | } |
100 | break; |
99 | break; |
101 | 100 | ||
102 | case evReDraw: |
101 | case evReDraw: |
103 | sc.get(); |
102 | sc.get(); |
104 | DefineAndDrawWindow(GetScreenWidth()-window_width/2,GetScreenHeight()-window_height/2,window_width,window_height,0x74,sc.work,""); |
103 | DefineAndDrawWindow(GetScreenWidth()-window_width/2,GetScreenHeight()-window_height/2,window_width,window_height,0x74,sc.work,""); |
105 | GetProcessInfo(#Form, SelfInfo); |
104 | GetProcessInfo(#Form, SelfInfo); |
106 | if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle(""); |
105 | if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle(""); |
107 | kolibrios_mounted = isdir("/kolibrios"); |
106 | kolibrios_mounted = isdir("/kolibrios"); |
108 | col_max = Form.cwidth - 10 / cell_w; |
107 | col_max = Form.cwidth - 10 / cell_w; |
109 | current_item_id = 0; |
108 | current_item_id = 0; |
110 | draw_top_bar(); |
109 | draw_top_bar(); |
111 | ini_enum_sections stdcall (#settings_ini_path, #process_sections); |
110 | ini_enum_sections stdcall (#settings_ini_path, #process_sections); |
112 | DrawBar(0, row + 1 * cell_h + list_pos, Form.cwidth, -row - 1 * cell_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR); |
111 | DrawBar(0, row + 1 * cell_h + list_pos, Form.cwidth, -row - 1 * cell_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR); |
113 | break; |
112 | break; |
114 | } |
113 | } |
115 | } |
114 | } |
116 | } |
115 | } |
117 | 116 | ||
118 | byte search_for_id_need_to_run(dword key_value, key_name, sec_name, f_name) |
117 | byte search_for_id_need_to_run(dword key_value, key_name, sec_name, f_name) |
119 | { |
118 | { |
120 | int icon_char_pos; |
119 | int icon_char_pos; |
121 | if (item_id_need_to_run == current_item_id) |
120 | if (item_id_need_to_run == current_item_id) |
122 | { |
121 | { |
123 | icon_char_pos = strchr(key_value, ','); |
122 | icon_char_pos = strchr(key_value, ','); |
124 | if (icon_char_pos) ESBYTE[icon_char_pos] = 0; //delete icon from string |
123 | if (icon_char_pos) ESBYTE[icon_char_pos] = 0; //delete icon from string |
125 | RunProgram(key_value, ""); |
124 | RunProgram(key_value, ""); |
126 | } |
125 | } |
127 | current_item_id++; |
126 | current_item_id++; |
128 | if (strncmp(key_value, "/kolibrios/", 11)==0) && (!kolibrios_mounted) current_item_id--; |
127 | if (strncmp(key_value, "/kolibrios/", 11)==0) && (!kolibrios_mounted) current_item_id--; |
129 | return 1; |
128 | return 1; |
130 | } |
129 | } |
131 | 130 | ||
132 | 131 | ||
133 | byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name) |
132 | byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name) |
134 | { |
133 | { |
135 | int tmp, |
134 | int tmp, |
136 | icon_id, |
135 | icon_id, |
137 | icon_char_pos; |
136 | icon_char_pos; |
138 | 137 | ||
139 | if (col==col_max) { |
138 | if (col==col_max) { |
140 | row++; |
139 | row++; |
141 | col=0; |
140 | col=0; |
142 | } |
141 | } |
143 | 142 | ||
144 | //do not show items located in /kolibrios/ if this directory not mounted |
143 | //do not show items located in /kolibrios/ if this directory not mounted |
145 | if (strncmp(key_value, "/kolibrios/", 11)==0) && (!kolibrios_mounted) return 1; |
144 | if (strncmp(key_value, "/kolibrios/", 11)==0) && (!kolibrios_mounted) return 1; |
146 | 145 | ||
147 | if (col==0) DrawBar(0, row * cell_h + list_pos, Form.cwidth, cell_h, LIST_BACKGROUND_COLOR); |
146 | if (col==0) DrawBar(0, row * cell_h + list_pos, Form.cwidth, cell_h, LIST_BACKGROUND_COLOR); |
148 | DefineButton(col*cell_w+6,row*cell_h + list_pos,cell_w,cell_h-5,current_item_id + 100 + BT_HIDE,0); |
147 | DefineButton(col*cell_w+6,row*cell_h + list_pos,cell_w,cell_h-5,current_item_id + 100 + BT_HIDE,0); |
149 | tmp = cell_w/2; |
148 | tmp = cell_w/2; |
150 | 149 | ||
151 | icon_char_pos = strchr(key_value, ','); |
150 | icon_char_pos = strchr(key_value, ','); |
152 | if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon; |
151 | if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon; |
153 | img_draw stdcall(skin.image, col*cell_w+tmp-10, row*cell_h+5 + list_pos, 32, 32, 0, icon_id*32); |
152 | img_draw stdcall(skin.image, col*cell_w+tmp-10, row*cell_h+5 + list_pos, 32, 32, 0, icon_id*32); |
154 | WriteTextCenter(col*cell_w+7,row*cell_h+47 + list_pos,cell_w,0xDCDCDC,key_name); |
153 | WriteTextCenter(col*cell_w+7,row*cell_h+47 + list_pos,cell_w,0xDCDCDC,key_name); |
155 | WriteTextCenter(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0x000000,key_name); |
154 | WriteTextCenter(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0x000000,key_name); |
156 | current_item_id++; |
155 | current_item_id++; |
157 | col++; |
156 | col++; |
158 | return 1; |
157 | return 1; |
159 | } |
158 | } |
160 | 159 | ||
161 | 160 | ||
162 | byte process_sections(dword sec_name, f_name) |
161 | byte process_sections(dword sec_name, f_name) |
163 | { |
162 | { |
164 | if (strcmp(sec_name, "Config")==0) return 1; |
163 | if (strcmp(sec_name, "Config")==0) return 1; |
165 | 164 | ||
166 | if (item_id_need_to_run!=-1) |
165 | if (item_id_need_to_run!=-1) |
167 | { |
166 | { |
168 | ini_enum_keys stdcall (f_name, sec_name, #search_for_id_need_to_run); |
167 | ini_enum_keys stdcall (f_name, sec_name, #search_for_id_need_to_run); |
169 | } |
168 | } |
170 | else |
169 | else |
171 | { |
170 | { |
172 | if ((col==0) && (row==old_row)) |
171 | if ((col==0) && (row==old_row)) |
173 | { |
172 | { |
174 | list_pos -= 20; |
173 | list_pos -= 20; |
175 | } |
174 | } |
176 | else |
175 | else |
177 | { |
176 | { |
178 | row++; |
177 | row++; |
179 | } |
178 | } |
180 | col = 0; |
179 | col = 0; |
181 | old_row = row; |
180 | old_row = row; |
182 | DrawBar(0, row * cell_h + list_pos, Form.cwidth , 20, LIST_BACKGROUND_COLOR); |
181 | DrawBar(0, row * cell_h + list_pos, Form.cwidth , 20, LIST_BACKGROUND_COLOR); |
183 | WriteTextB(10, row * cell_h + 9 + list_pos, 0x90, 0x000000, sec_name); |
182 | WriteTextB(10, row * cell_h + 9 + list_pos, 0x90, 0x000000, sec_name); |
184 | list_pos += 20; |
183 | list_pos += 20; |
185 | ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section); |
184 | ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section); |
186 | } |
185 | } |
187 | return 1; |
186 | return 1; |
188 | } |
187 | } |
189 | 188 | ||
190 | void draw_top_bar() |
189 | void draw_top_bar() |
191 | { |
190 | { |
192 | int top_position = 25; |
191 | int top_position = 25; |
193 | DrawBar(0,0,Form.cwidth, top_position-1, sc.work); |
192 | DrawBar(0,0,Form.cwidth, top_position-1, sc.work); |
194 | DrawBar(0,top_position-1, Form.cwidth, 1, sc.work_graph); |
193 | DrawBar(0,top_position-1, Form.cwidth, 1, sc.work_graph); |
195 | WriteTextB(Form.cwidth/2-70, 9, 0x90, sc.work_text, #window_title); |
194 | WriteTextB(Form.cwidth/2-70, 9, 0x90, sc.work_text, #window_title); |
196 | list_top = top_position; |
195 | list_top = top_position; |
197 | list_pos = list_top; |
196 | list_pos = list_top; |
198 | row = -1; |
197 | row = -1; |
199 | } |
198 | } |
200 | 199 | ||
201 | 200 | ||
202 | 201 | ||
203 | stop: |
202 | stop: |