Rev 9453 | Rev 9461 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4078 | leency | 1 | //11.03.12 - start! |
8261 | leency | 2 | //ver 2.31 |
4078 | leency | 3 | |
7660 | leency | 4 | #define MEMSIZE 200*1024 |
7909 | leency | 5 | #include "../lib/mem.h" |
6 | #include "../lib/strings.h" |
||
7 | #include "../lib/io.h" |
||
8 | #include "../lib/list_box.h" |
||
9 | #include "../lib/gui.h" |
||
7353 | leency | 10 | |
7909 | leency | 11 | #include "../lib/obj/box_lib.h" |
12 | #include "../lib/obj/proc_lib.h" |
||
13 | #include "../lib/obj/libini.h" |
||
7353 | leency | 14 | |
7909 | leency | 15 | #include "../lib/patterns/select_list.h" |
16 | #include "../lib/patterns/simple_open_dialog.h" |
||
9453 | leency | 17 | #include "../lib/patterns/restart_process.h" |
4078 | leency | 18 | |
7614 | leency | 19 | #include "ui_elements_preview.h" |
9455 | leency | 20 | #include "const.h" |
7614 | leency | 21 | |
6212 | leency | 22 | //===================================================// |
23 | // // |
||
24 | // DATA // |
||
25 | // // |
||
26 | //===================================================// |
||
27 | |||
9453 | leency | 28 | signed int active_skin=-1, active_wallpaper=-1, active_screensaver=-1; |
7353 | leency | 29 | enum { |
9453 | leency | 30 | BASE_TAB_BUTTON_ID=3, |
31 | BTN_SELECT_WALLP_FOLDER=10, |
||
32 | BTN_TEST_SCREENSAVER }; |
||
4078 | leency | 33 | |
34 | char folder_path[4096]; |
||
35 | char cur_file_path[4096]; |
||
7551 | leency | 36 | char cur_skin_path[4096]; |
4078 | leency | 37 | char temp_filename[4096]; |
6096 | leency | 38 | int files_mas[400]; |
4078 | leency | 39 | |
9455 | leency | 40 | _ini ini = { "/sys/settings/system.ini" }; |
9453 | leency | 41 | |
4078 | leency | 42 | int cur; |
43 | |||
44 | proc_info Form; |
||
7244 | leency | 45 | block skp; |
4078 | leency | 46 | |
9453 | leency | 47 | enum {SKINS, WALLPAPERS, SCREENSAVERS}; |
7225 | leency | 48 | |
9453 | leency | 49 | _tabs tabs = { -sizeof(t_skins)-sizeof(t_wallpapers)-sizeof(t_screensaver)-3*8+WIN_W |
50 | - TAB_PADDING / 2, LP, NULL, BASE_TAB_BUTTON_ID }; |
||
7909 | leency | 51 | |
7612 | leency | 52 | checkbox update_docky = { T_UPDATE_DOCK, false }; |
7244 | leency | 53 | |
7353 | leency | 54 | char default_dir[] = "/rd/1"; |
55 | od_filter filter2 = { 8, "TXT\0\0" }; |
||
56 | |||
7611 | leency | 57 | checkbox optionbox_stretch = { T_CHECKBOX_STRETCH, true }; |
58 | checkbox optionbox_tiled = { T_CHECKBOX_TILED, false }; |
||
59 | |||
6212 | leency | 60 | //===================================================// |
61 | // // |
||
62 | // CODE // |
||
63 | // // |
||
64 | //===================================================// |
||
5548 | leency | 65 | |
4078 | leency | 66 | void main() |
67 | { |
||
7909 | leency | 68 | int id; |
5626 | leency | 69 | load_dll(boxlib, #box_lib_init,0); |
7533 | leency | 70 | load_dll(libini, #lib_init,1); |
7353 | leency | 71 | load_dll(Proc_lib, #OpenDialog_init,0); |
72 | o_dialog.type = 2; //select folder |
||
73 | OpenDialog_init stdcall (#o_dialog); |
||
74 | |||
9453 | leency | 75 | tabs.add(#t_skins, #EventTabSkinsClick); |
76 | tabs.add(#t_wallpapers, #EventTabWallpappersClick); |
||
77 | tabs.add(#t_screensaver, #EventTabScreensaverClick); |
||
7909 | leency | 78 | tabs.draw_active_tab(); |
7353 | leency | 79 | |
7551 | leency | 80 | SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER); |
6096 | leency | 81 | loop() switch(WaitEvent()) |
4078 | leency | 82 | { |
83 | case evMouse: |
||
6653 | leency | 84 | SelectList_ProcessMouse(); |
4410 | leency | 85 | |
7353 | leency | 86 | if (tabs.active_tab == SKINS) { |
87 | edit_box_mouse stdcall (#edit_cmm); |
||
88 | edit_box_mouse stdcall (#edit_st); |
||
89 | } |
||
90 | |||
7778 | leency | 91 | if (mouse.key&MOUSE_RIGHT) && (mouse.up) |
92 | &&(select_list.MouseOver(mouse.x, mouse.y)) { |
||
6651 | leency | 93 | select_list.ProcessMouse(mouse.x, mouse.y); |
6653 | leency | 94 | SelectList_Draw(); |
7353 | leency | 95 | EventSetNewCurrent(); |
8020 | leency | 96 | open_lmenu(mouse.x, mouse.y, MENU_TOP_RIGHT, NULL, MENU_LIST); |
6212 | leency | 97 | } |
4078 | leency | 98 | break; |
99 | |||
100 | case evButton: |
||
101 | id=GetButtonID(); |
||
7551 | leency | 102 | if (id==1) EventExit(); |
7353 | leency | 103 | if (id==BTN_SELECT_WALLP_FOLDER) EventSelectWallpFolder(); |
7909 | leency | 104 | tabs.click(id); |
7244 | leency | 105 | checkbox1.click(id); |
7252 | leency | 106 | spinbox1.click(id); |
7612 | leency | 107 | if (update_docky.click(id)) EventUpdateDocky(); |
7611 | leency | 108 | if (!optionbox_stretch.checked) && (optionbox_stretch.click(id)) EventSetWallpMode_Stretch(); |
109 | if (!optionbox_tiled.checked) && (optionbox_tiled.click(id)) EventSetWallpMode_Tiled(); |
||
4078 | leency | 110 | break; |
111 | |||
112 | case evKey: |
||
5706 | leency | 113 | GetKeys(); |
6651 | leency | 114 | if (select_list.ProcessKey(key_scancode)) EventApply(); |
6212 | leency | 115 | if (key_scancode==SCAN_CODE_ENTER) EventOpenFile(); |
116 | if (key_scancode==SCAN_CODE_DEL) EventDeleteFile(); |
||
9453 | leency | 117 | if (key_scancode==SCAN_CODE_TAB) { |
118 | id = tabs.active_tab+1; |
||
119 | if(id==3)id=0; |
||
120 | tabs.click(id + tabs.base_id); |
||
9455 | leency | 121 | DrawWindowContent(); |
9453 | leency | 122 | break; |
123 | } |
||
7349 | leency | 124 | |
7506 | leency | 125 | if (! edit_cmm.flags & ed_focus) && (! edit_st.flags & ed_focus) |
6651 | leency | 126 | for (id=select_list.cur_y+1; id |
4078 | leency | 127 | { |
6212 | leency | 128 | strcpy(#temp_filename, io.dir.position(files_mas[id])); |
129 | if (temp_filename[0]==key_ascii) || (temp_filename[0]==key_ascii-32) |
||
130 | { |
||
6651 | leency | 131 | select_list.cur_y = id - 1; |
132 | select_list.KeyDown(); |
||
6212 | leency | 133 | EventApply(); |
134 | break; |
||
135 | } |
||
4078 | leency | 136 | } |
7349 | leency | 137 | |
7353 | leency | 138 | if (tabs.active_tab == SKINS) { |
139 | EAX = key_ascii << 8; |
||
140 | edit_box_key stdcall (#edit_cmm); |
||
141 | edit_box_key stdcall (#edit_st); |
||
142 | } |
||
4078 | leency | 143 | break; |
144 | |||
7353 | leency | 145 | case evReDraw: |
146 | draw_window(); |
||
7778 | leency | 147 | EventHandleMenuClick(); |
4078 | leency | 148 | } |
149 | } |
||
150 | |||
7353 | leency | 151 | void draw_window() |
152 | { |
||
7909 | leency | 153 | sc.get(); |
9455 | leency | 154 | DefineAndDrawWindow(screen.width-600/2,80,WIN_W+9,WIN_H+skin_height,0x34,sc.work,WINDOW_HEADER,0); |
7353 | leency | 155 | GetProcessInfo(#Form, SelfInfo); |
8946 | leency | 156 | IF (Form.status_window&ROLLED_UP) return; |
7353 | leency | 157 | DrawWindowContent(); |
158 | } |
||
7244 | leency | 159 | |
6212 | leency | 160 | void DrawWindowContent() |
161 | { |
||
162 | int id; |
||
7225 | leency | 163 | |
7806 | leency | 164 | sc.get(); |
7612 | leency | 165 | |
9453 | leency | 166 | //tabs.w = Form.cwidth-LP-LP; |
7909 | leency | 167 | tabs.draw(); |
9455 | leency | 168 | draw_icon_16w(tabs.x + TAB_PADDING, LP+5, 17); |
169 | draw_icon_16w(sizeof(t_skins)-1*8 + TAB_PADDING + TAB_PADDING + tabs.x, LP+5, 6); |
||
170 | draw_icon_16w(sizeof(t_wallpapers)+sizeof(t_skins)-2*8 + TAB_PADDING + TAB_PADDING + TAB_PADDING + tabs.x, LP+5, 61); |
||
7225 | leency | 171 | |
6651 | leency | 172 | id = select_list.cur_y; |
6653 | leency | 173 | SelectList_Init( |
9453 | leency | 174 | LP + TAB_PADDING, |
175 | PANEL_H, |
||
176 | LIST_W, |
||
9455 | leency | 177 | Form.cheight-LP - TAB_PADDING - PANEL_H |
6653 | leency | 178 | ); |
6651 | leency | 179 | select_list.cur_y = id; |
7244 | leency | 180 | |
181 | skp.set_size( |
||
9453 | leency | 182 | LP + TAB_PADDING + LIST_W + TAB_PADDING + 30, |
183 | PANEL_H, |
||
9455 | leency | 184 | 226, |
7612 | leency | 185 | 230 //select_list.h - 50 - 50 |
7244 | leency | 186 | ); |
9455 | leency | 187 | DrawBar(skp.x, skp.y, skp.w, WIN_H, sc.work); |
7244 | leency | 188 | |
6653 | leency | 189 | SelectList_Draw(); |
6662 | leency | 190 | SelectList_DrawBorder(); |
7244 | leency | 191 | |
192 | if (tabs.active_tab == SKINS) |
||
193 | { |
||
9453 | leency | 194 | DrawFrame(skp.x, PANEL_H+5, skp.w, skp.h, " Components Preview "); |
195 | DrawUiElementsPreview(skp.x+20, PANEL_H+5, skp.h); |
||
196 | if (CheckProcessExists("@DOCKY")) update_docky.draw(skp.x, PANEL_H+250); |
||
7244 | leency | 197 | } |
7353 | leency | 198 | if (tabs.active_tab == WALLPAPERS) |
199 | { |
||
9453 | leency | 200 | DrawFrame(skp.x, PANEL_H+5, 180, 80, T_PICTURE_MODE); |
201 | optionbox_stretch.draw(skp.x+14, PANEL_H+25); |
||
202 | optionbox_tiled.draw(skp.x+14, PANEL_H+52); |
||
203 | DrawStandartCaptButton(skp.x, PANEL_H+100, BTN_SELECT_WALLP_FOLDER, T_SELECT_FOLDER); |
||
7353 | leency | 204 | } |
9453 | leency | 205 | if (tabs.active_tab == SCREENSAVERS) |
206 | { |
||
207 | DrawStandartCaptButton(skp.x, PANEL_H, BTN_TEST_SCREENSAVER, "Test"); |
||
208 | } |
||
6212 | leency | 209 | } |
210 | |||
9455 | leency | 211 | bool strreqi(dword _left, _right) |
212 | { |
||
213 | return strcmpi(_left+strrchr(_left,'.')-1, _right); |
||
214 | } |
||
4410 | leency | 215 | |
6212 | leency | 216 | void Open_Dir() |
4078 | leency | 217 | { |
6212 | leency | 218 | int j; |
6651 | leency | 219 | select_list.count = 0; |
6212 | leency | 220 | if(io.dir.buffer)free(io.dir.buffer); |
221 | io.dir.load(#folder_path,DIR_ONLYREAL); |
||
222 | for (j=0; j |
||
4410 | leency | 223 | { |
6212 | leency | 224 | strcpy(#temp_filename, io.dir.position(j)); |
225 | strlwr(#temp_filename); |
||
7353 | leency | 226 | if (tabs.active_tab==SKINS) { |
9455 | leency | 227 | if (strreqi(#temp_filename,".skn")!=0) continue; |
7353 | leency | 228 | } |
229 | if (tabs.active_tab==WALLPAPERS) { |
||
9455 | leency | 230 | if (strreqi(#temp_filename,".png")!=0) |
231 | && (strreqi(#temp_filename,".jpg")!=0) |
||
232 | && (strreqi(#temp_filename,".jpeg")!=0) |
||
233 | && (strreqi(#temp_filename,".gif")!=0) continue; |
||
7353 | leency | 234 | } |
6651 | leency | 235 | cur = select_list.count; |
6212 | leency | 236 | files_mas[cur]=j; |
6651 | leency | 237 | select_list.count++; |
4410 | leency | 238 | } |
8261 | leency | 239 | Sort_by_Name(0, select_list.count-1); |
6212 | leency | 240 | } |
241 | |||
8261 | leency | 242 | void Sort_by_Name(int a, b) // for the first call: a = 0, b = sizeof(mas) - 1 |
243 | { |
||
244 | int j; |
||
245 | int isn = a; |
||
246 | if (a >= b) return; |
||
247 | for (j = a; j <= b; j++) { |
||
248 | if (strcmpi(io.dir.position(files_mas[j]), io.dir.position(files_mas[b]))<=0) { |
||
249 | files_mas[isn] >< files_mas[j]; |
||
250 | isn++; |
||
251 | } |
||
252 | } |
||
253 | Sort_by_Name(a, isn-2); |
||
254 | Sort_by_Name(isn, b); |
||
255 | } |
||
256 | |||
6653 | leency | 257 | void SelectList_DrawLine(dword i) |
6212 | leency | 258 | { |
8762 | leency | 259 | int yyy; |
6212 | leency | 260 | |
6651 | leency | 261 | cur = select_list.first + i; |
262 | strcpy(#temp_filename, io.dir.position(files_mas[cur])); |
||
263 | temp_filename[strlen(#temp_filename)-4] = 0; |
||
264 | yyy = i*select_list.item_h+select_list.y; |
||
265 | |||
266 | if (select_list.cur_y-select_list.first==i) |
||
4410 | leency | 267 | { |
7806 | leency | 268 | DrawBar(select_list.x, yyy, select_list.w, select_list.item_h, sc.button); |
269 | WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,sc.button_text, #temp_filename); |
||
4410 | leency | 270 | } |
6651 | leency | 271 | else |
272 | { |
||
273 | DrawBar(select_list.x,yyy,select_list.w, select_list.item_h, 0xFFFfff); |
||
274 | WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,0, #temp_filename); |
||
275 | } |
||
4078 | leency | 276 | } |
277 | |||
6653 | leency | 278 | void SelectList_LineChanged() |
279 | { |
||
280 | EventApply(); |
||
281 | } |
||
282 | |||
7960 | leency | 283 | void ActivateTab(int _id) |
284 | { |
||
285 | select_list.ClearList(); |
||
286 | Open_Dir(); |
||
287 | if (!select_list.count) notify("'No files were found' -E"); |
||
288 | select_list.cur_y = _id; |
||
289 | if (select_list.cur_y>select_list.visible) select_list.first=select_list.cur_y; |
||
290 | select_list.CheckDoesValuesOkey(); |
||
9455 | leency | 291 | if (select_list.w) DrawWindowContent(); |
7960 | leency | 292 | } |
293 | |||
9455 | leency | 294 | dword GetRealKolibriosPath() |
295 | { |
||
296 | char real_kolibrios_path[4096]; |
||
297 | SetCurDir("/kolibrios"); |
||
298 | GetCurDir(#real_kolibrios_path, sizeof(real_kolibrios_path)); |
||
299 | return #real_kolibrios_path; |
||
300 | } |
||
301 | |||
6212 | leency | 302 | //===================================================// |
303 | // // |
||
304 | // EVENTS // |
||
305 | // // |
||
306 | //===================================================// |
||
4078 | leency | 307 | |
7909 | leency | 308 | void EventTabSkinsClick() |
4085 | leency | 309 | { |
7909 | leency | 310 | active_wallpaper = select_list.cur_y; |
9455 | leency | 311 | miniprintf(#folder_path, "%s/res/skins", GetRealKolibriosPath()); |
7960 | leency | 312 | ActivateTab(active_skin); |
6212 | leency | 313 | } |
4078 | leency | 314 | |
7909 | leency | 315 | void EventTabWallpappersClick() |
316 | { |
||
317 | active_skin = select_list.cur_y; |
||
9455 | leency | 318 | if (opendir_path) { |
319 | strcpy(#folder_path, #opendir_path); |
||
320 | } else { |
||
321 | miniprintf(#folder_path, "%s/res/wallpapers", GetRealKolibriosPath()); |
||
322 | } |
||
7960 | leency | 323 | ActivateTab(active_wallpaper); |
7909 | leency | 324 | } |
325 | |||
9453 | leency | 326 | void EventTabScreensaverClick() |
327 | { |
||
328 | //strcpy(#folder_path, #wallp_folder_path); |
||
329 | ActivateTab(active_screensaver); |
||
330 | } |
||
331 | |||
6212 | leency | 332 | void EventDeleteFile() |
333 | { |
||
334 | io.del(#cur_file_path); |
||
335 | Open_Dir(); |
||
336 | EventApply(); |
||
337 | } |
||
4078 | leency | 338 | |
7353 | leency | 339 | void EventSetNewCurrent() |
340 | { |
||
341 | cur = select_list.cur_y; |
||
9453 | leency | 342 | miniprintf(#cur_file_path,"%s/",#folder_path); |
343 | strcat(#cur_file_path, io.dir.position(files_mas[cur])); |
||
7353 | leency | 344 | } |
345 | |||
346 | void EventSelectWallpFolder() |
||
347 | { |
||
348 | OpenDialog_start stdcall (#o_dialog); |
||
9455 | leency | 349 | if (o_dialog.status) EventTabWallpappersClick(); |
7353 | leency | 350 | } |
351 | |||
7611 | leency | 352 | void EventSetWallpMode_Stretch() |
353 | { |
||
354 | optionbox_tiled.checked = false; |
||
355 | optionbox_tiled.redraw(); |
||
356 | EventApply(); |
||
357 | } |
||
358 | |||
359 | void EventSetWallpMode_Tiled() |
||
360 | { |
||
361 | optionbox_stretch.checked = false; |
||
362 | optionbox_stretch.redraw(); |
||
363 | EventApply(); |
||
364 | } |
||
365 | |||
6212 | leency | 366 | void EventApply() |
367 | { |
||
7353 | leency | 368 | char kivpath[4096+10]; |
369 | EventSetNewCurrent(); |
||
6264 | leency | 370 | if (tabs.active_tab==SKINS) |
6212 | leency | 371 | { |
6651 | leency | 372 | cur = select_list.cur_y; |
6212 | leency | 373 | SetSystemSkin(#cur_file_path); |
7612 | leency | 374 | SelectList_Draw(); |
7551 | leency | 375 | strcpy(#cur_skin_path, #cur_file_path); |
7612 | leency | 376 | EventUpdateDocky(); |
6212 | leency | 377 | } |
6264 | leency | 378 | if (tabs.active_tab==WALLPAPERS) |
6212 | leency | 379 | { |
7551 | leency | 380 | SelectList_Draw(); |
9453 | leency | 381 | if (optionbox_stretch.checked) miniprintf(#kivpath, "\\S__%s", #cur_file_path); |
382 | if (optionbox_tiled.checked) miniprintf(#kivpath, "\\T__%s", #cur_file_path); |
||
7353 | leency | 383 | RunProgram("/sys/media/kiv", #kivpath); |
6212 | leency | 384 | } |
385 | } |
||
4085 | leency | 386 | |
7612 | leency | 387 | void EventUpdateDocky() |
388 | { |
||
389 | if (!update_docky.checked) return; |
||
390 | KillProcessByName("@docky", MULTIPLE); |
||
391 | RunProgram("/sys/@docky",NULL); |
||
392 | pause(50); |
||
393 | ActivateWindow(GetProcessSlot(Form.ID)); |
||
394 | } |
||
395 | |||
6212 | leency | 396 | void EventOpenFile() |
397 | { |
||
6264 | leency | 398 | if (tabs.active_tab==SKINS) RunProgram("/sys/skincfg", #cur_file_path); |
399 | if (tabs.active_tab==WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path); |
||
4085 | leency | 400 | } |
401 | |||
7551 | leency | 402 | void EventExit() |
403 | { |
||
9455 | leency | 404 | if (cur_skin_path) { |
405 | ini.section = "style"; |
||
406 | ini.SetString("skin", #cur_skin_path, strlen(#cur_skin_path)); |
||
407 | } |
||
7551 | leency | 408 | ExitProcess(); |
409 | } |
||
410 | |||
7778 | leency | 411 | void EventHandleMenuClick() |
412 | { |
||
413 | switch (get_menu_click()) |
||
414 | { |
||
415 | case 1: |
||
416 | EventOpenFile(); |
||
417 | break; |
||
418 | case 2: |
||
419 | EventDeleteFile(); |
||
420 | break; |
||
421 | }; |
||
422 | } |
||
423 | |||
4078 | leency | 424 | stop:>=0)>=>><> |