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