Rev 7049 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4870 | leency | 1 | /* |
6091 | leency | 2 | SOFTWARE CENTER v2.8 |
4870 | leency | 3 | */ |
4 | |||
6786 | leency | 5 | #define MEMSIZE 4096 * 15 |
4870 | leency | 6 | #include "..\lib\strings.h" |
7 | #include "..\lib\mem.h" |
||
6253 | leency | 8 | #include "..\lib\io.h" |
5499 | leency | 9 | #include "..\lib\gui.h" |
5409 | leency | 10 | |
7049 | leency | 11 | #include "..\lib\obj\libio.h" |
12 | #include "..\lib\obj\libimg.h" |
||
5499 | leency | 13 | #include "..\lib\obj\libini.h" |
6805 | leency | 14 | #include "..\lib\kfont.h" |
6091 | leency | 15 | #include "..\lib\list_box.h" |
16 | #include "..\lib\collection.h" |
||
5405 | leency | 17 | |
4870 | leency | 18 | proc_info Form; |
6091 | leency | 19 | llist list; |
20 | collection app_path_collection; |
||
5424 | leency | 21 | byte kolibrios_mounted; |
22 | |||
5405 | leency | 23 | int window_width, |
6091 | leency | 24 | window_height; |
5403 | leency | 25 | |
6091 | leency | 26 | int list_pos, |
27 | row, |
||
28 | col, |
||
29 | default_icon; |
||
5403 | leency | 30 | |
5405 | leency | 31 | char window_title[128], |
6091 | leency | 32 | settings_ini_path[256] = "/sys/settings/"; |
5405 | leency | 33 | |
5403 | leency | 34 | #define LIST_BACKGROUND_COLOR 0xF3F3F3 |
35 | |||
36 | void load_config() |
||
37 | { |
||
38 | ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget"); |
||
39 | ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690); |
||
40 | window_width = EAX; |
||
6091 | leency | 41 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 73); |
42 | list.item_w = EAX; |
||
43 | ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 71); |
||
44 | list.item_h = EAX; |
||
5405 | leency | 45 | ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0); |
46 | default_icon = EAX; |
||
4870 | leency | 47 | } |
48 | |||
49 | |||
50 | void main() |
||
51 | { |
||
6091 | leency | 52 | dword id; |
6806 | leency | 53 | kfont.init(DEFAULT_FONT); |
5626 | leency | 54 | load_dll(libio, #libio_init,1); |
55 | load_dll(libimg, #libimg_init,1); |
||
56 | load_dll(libini, #lib_init,1); |
||
5403 | leency | 57 | |
5425 | leency | 58 | Libimg_LoadImage(#skin, "/sys/icons32.png"); |
5409 | leency | 59 | Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR); |
6251 | leency | 60 | kolibrios_mounted = dir_exists("/kolibrios"); |
5409 | leency | 61 | |
5407 | leency | 62 | if (param) |
5406 | leency | 63 | { |
64 | strcpy(#settings_ini_path, #param); |
||
65 | } |
||
66 | else |
||
67 | { |
||
6735 | leency | 68 | strcat(#settings_ini_path, I_Path + strrchr(I_Path, '/')); |
5406 | leency | 69 | strcat(#settings_ini_path, ".ini"); |
70 | } |
||
6091 | leency | 71 | |
5403 | leency | 72 | load_config(); |
6091 | leency | 73 | list.cur_y = -1; |
74 | list.y = 32; |
||
5403 | leency | 75 | |
6091 | leency | 76 | DrawList(); |
77 | window_height = row+1*list.item_h + list_pos + skin_height + 15; |
||
78 | |||
79 | loop() switch(WaitEvent()) |
||
5403 | leency | 80 | { |
6091 | leency | 81 | // case evKey: |
82 | // GetKeys(); |
||
83 | // if (list.ProcessKey(key_scancode)) DrawList(); |
||
84 | // break; |
||
85 | |||
86 | case evButton: |
||
87 | id=GetButtonID(); |
||
88 | if (id==1) ExitProcess(); |
||
6253 | leency | 89 | if (id>=100) EventRunApp(id-100); |
4870 | leency | 90 | break; |
5403 | leency | 91 | |
6091 | leency | 92 | case evReDraw: |
5674 | pavelyakov | 93 | system.color.get(); |
6746 | leency | 94 | DefineAndDrawWindow(screen.width-window_width/2,screen.height-window_height/2,window_width,window_height,0x74,system.color.work,"",0); |
4870 | leency | 95 | GetProcessInfo(#Form, SelfInfo); |
5406 | leency | 96 | if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle(""); |
6008 | leency | 97 | draw_top_bar(); |
6091 | leency | 98 | DrawList(); |
99 | DrawBar(0, row + 1 * list.item_h + list_pos, Form.cwidth, -row - 1 * list.item_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR); |
||
4870 | leency | 100 | break; |
5403 | leency | 101 | } |
4870 | leency | 102 | } |
103 | |||
6091 | leency | 104 | void DrawList() { |
105 | list.count = 0; |
||
106 | row = -1; |
||
107 | app_path_collection.drop(); |
||
108 | list_pos = list.y; |
||
109 | list.column_max = window_width - 10 / list.item_w; |
||
110 | ini_enum_sections stdcall (#settings_ini_path, #process_sections); |
||
111 | list.visible = list.count; |
||
5151 | leency | 112 | } |
4870 | leency | 113 | |
5403 | leency | 114 | byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name) |
5151 | leency | 115 | { |
5405 | leency | 116 | int tmp, |
6091 | leency | 117 | icon_id, |
118 | icon_char_pos; |
||
5151 | leency | 119 | |
6192 | leency | 120 | //do not show items located in /kolibrios/ if this directory not mounted |
121 | if (!strncmp(key_value, "/kolibrios/", 11)) && (!kolibrios_mounted) return true; |
||
122 | |||
6091 | leency | 123 | if (col==list.column_max) { |
5151 | leency | 124 | row++; |
125 | col=0; |
||
126 | } |
||
5424 | leency | 127 | |
6091 | leency | 128 | if (col==0) DrawBar(0, row * list.item_h + list_pos, Form.cwidth, list.item_h, LIST_BACKGROUND_COLOR); |
129 | DefineButton(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-5,list.count + 100 + BT_HIDE,0); |
||
130 | tmp = list.item_w/2; |
||
5405 | leency | 131 | |
132 | icon_char_pos = strchr(key_value, ','); |
||
5624 | leency | 133 | if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon; |
6091 | leency | 134 | img_draw stdcall(skin.image, col*list.item_w+tmp-10, row*list.item_h+5 + list_pos, 32, 32, 0, icon_id*32); |
135 | if (icon_char_pos) ESBYTE[icon_char_pos] = '\0'; //delete icon from string |
||
136 | app_path_collection.add(key_value); |
||
6806 | leency | 137 | //kfont.WriteIntoWindowCenter(col*list.item_w+7,row*list.item_h+47 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0xDCDCDC, 12, key_name); |
138 | kfont.WriteIntoWindowCenter(col*list.item_w+6,row*list.item_h+46 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0x000000, 12, key_name); |
||
6091 | leency | 139 | if (list.cur_y == list.count) DrawWideRectangle(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-5, 2, 0x0080FF); |
140 | list.count++; |
||
5151 | leency | 141 | col++; |
5656 | pavelyakov | 142 | return true; |
5151 | leency | 143 | } |
144 | |||
5403 | leency | 145 | |
6091 | leency | 146 | int old_row; //to detect empty sections |
5424 | leency | 147 | byte process_sections(dword sec_name, f_name) |
4870 | leency | 148 | { |
5817 | leency | 149 | int text_len; |
5656 | pavelyakov | 150 | if (!strcmp(sec_name, "Config")) return true; |
4870 | leency | 151 | |
6091 | leency | 152 | if ((col==0) && (row==old_row)) |
5403 | leency | 153 | { |
6091 | leency | 154 | list_pos -= 28; |
5403 | leency | 155 | } |
156 | else |
||
157 | { |
||
6091 | leency | 158 | row++; |
5403 | leency | 159 | } |
6091 | leency | 160 | col = 0; |
161 | old_row = row; |
||
162 | DrawBar(0, row * list.item_h + list_pos, Form.cwidth , 29, LIST_BACKGROUND_COLOR); |
||
6806 | leency | 163 | text_len = kfont.WriteIntoWindow(10, row * list.item_h + 10 + list_pos, LIST_BACKGROUND_COLOR, 0, 15, sec_name); |
6091 | leency | 164 | DrawBar(text_len+20, row * list.item_h + list_pos + 20, Form.cwidth-text_len-20, 1, 0xDCDCDC); |
165 | DrawBar(text_len+20, row * list.item_h + list_pos + 21, Form.cwidth-text_len-20, 1, 0xFCFCFC); |
||
166 | list_pos += 29; |
||
167 | ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section); |
||
5656 | pavelyakov | 168 | return true; |
4870 | leency | 169 | } |
170 | |||
5403 | leency | 171 | void draw_top_bar() |
172 | { |
||
6091 | leency | 173 | DrawBar(0,0,Form.cwidth, list.y-2, system.color.work); |
6177 | leency | 174 | DrawBar(0,list.y-2, Form.cwidth, 1, MixColors(system.color.work, system.color.work_graph, 180)); |
6091 | leency | 175 | DrawBar(0,list.y-1, Form.cwidth, 1, system.color.work_graph); |
6806 | leency | 176 | kfont.WriteIntoWindowCenter(0,5, Form.cwidth, list.y, system.color.work, system.color.work_text, 16, #window_title); |
5403 | leency | 177 | } |
4870 | leency | 178 | |
6253 | leency | 179 | void EventRunApp(dword appid) |
180 | { |
||
6955 | leency | 181 | dword app_path = app_path_collection.get(appid); |
182 | |||
183 | dword param_pos = strchr(app_path, '|'); |
||
184 | if (param_pos) { |
||
185 | ESBYTE[param_pos] = NULL; |
||
186 | param_pos++; |
||
6253 | leency | 187 | } |
6955 | leency | 188 | |
189 | if (file_exists(app_path)) |
||
190 | { |
||
191 | io.run(app_path, param_pos); //0 or offset |
||
192 | if (param_pos) ESBYTE[param_pos - 1] = '|'; |
||
193 | } |
||
194 | else |
||
195 | { |
||
6253 | leency | 196 | notify("'Application not found' -E"); |
197 | } |
||
6955 | leency | 198 | |
6253 | leency | 199 | } |
4870 | leency | 200 | |
5403 | leency | 201 | |
6253 | leency | 202 | |
4870 | leency | 203 | stop: |