Subversion Repositories Kolibri OS

Rev

Rev 9461 | Rev 9467 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. //11.03.12 - start!
  2. //ver 2.31
  3.  
  4. #define MEMSIZE 1024*70
  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"
  10.  
  11. #include "../lib/obj/box_lib.h"
  12. #include "../lib/obj/proc_lib.h"
  13. #include "../lib/obj/libini.h"
  14.  
  15. #include "../lib/patterns/select_list.h"
  16. #include "../lib/patterns/simple_open_dialog.h"
  17. #include "../lib/patterns/restart_process.h"
  18.  
  19. #include "ui_elements_preview.h"
  20. #include "const.h"
  21.  
  22. //===================================================//
  23. //                                                   //
  24. //                       DATA                        //
  25. //                                                   //
  26. //===================================================//
  27.  
  28. signed int active_skin=-1, active_wallpaper=-1, active_screensaver=-1;
  29. enum {
  30.         BASE_TAB_BUTTON_ID=3,
  31.         BTN_SELECT_WALLP_FOLDER=10,
  32.         BTN_TEST_SCREENSAVER };
  33.  
  34. char folder_path[4096];
  35. char cur_file_path[4096];
  36. char cur_skin_path[4096];
  37. char ss_available[200];
  38.  
  39. int screensaver_timeout;
  40.  
  41. _tabs tabs = { -sizeof(t_skins)-sizeof(t_wallpapers)-sizeof(t_screensaver)-3*8+WIN_W
  42.          - TAB_PADDING / 2, LP, NULL, BASE_TAB_BUTTON_ID };
  43.  
  44. checkbox update_docky = { T_UPDATE_DOCK, false };
  45.  
  46. checkbox optionbox_stretch = { T_CHECKBOX_STRETCH, false };
  47. checkbox optionbox_tiled = { T_CHECKBOX_TILED, false };
  48. checkbox optionbox_auto = { T_CHECKBOX_AUTO, true };
  49.  
  50. collection list;
  51.  
  52. //===================================================//
  53. //                                                   //
  54. //                       CODE                        //
  55. //                                                   //
  56. //===================================================//
  57.  
  58. void main()
  59. {  
  60.         int id, i;
  61.         load_dll(boxlib, #box_lib_init,0);
  62.         load_dll(libini, #lib_init,1);
  63.         load_dll(Proc_lib, #OpenDialog_init,0);
  64.         o_dialog.type = 2; //select folder
  65.         OpenDialog_init stdcall (#o_dialog);
  66.  
  67.         tabs.add(#t_skins, #EventTabSkinsClick);       
  68.         tabs.add(#t_wallpapers, #EventTabWallpappersClick);
  69.         tabs.add(#t_screensaver, #EventTabScreensaverClick);
  70.         tabs.draw_active_tab();
  71.  
  72.         GetScreensaverIniSettings();
  73.  
  74.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  75.         loop() switch(WaitEvent())
  76.         {
  77.                 case evMouse:
  78.                         SelectList_ProcessMouse();
  79.                         break;
  80.  
  81.                 case evButton:
  82.                         id=GetButtonID();
  83.                         if (id==1) EventExit();
  84.                         tabs.click(id);
  85.                         if (tabs.active_tab == TAB_SKINS) {
  86.                                 checkbox1.click(id);
  87.                                 spinbox1.click(id);
  88.                                 if (update_docky.click(id)) EventUpdateDocky();
  89.                         }
  90.                         if (tabs.active_tab == TAB_WALLPAPERS) {
  91.                                 if (id==BTN_SELECT_WALLP_FOLDER) EventSelectWallpFolder();
  92.                                 if (optionbox_stretch.click(id)) EventSetWallpMode(1,0,0);
  93.                                 if (optionbox_tiled.click(id)) EventSetWallpMode(0,1,0);
  94.                                 if (optionbox_auto.click(id)) EventSetWallpMode(0,0,1);
  95.                         }
  96.                         if (tabs.active_tab == TAB_SCREENSAVERS) {
  97.                                 if (id==BTN_TEST_SCREENSAVER) EventOpenFile();
  98.                         }
  99.                         break;
  100.          
  101.                 case evKey:
  102.                         GetKeys();
  103.                         if (select_list.ProcessKey(key_scancode)) EventApply();
  104.                         if (key_scancode==SCAN_CODE_ENTER) EventOpenFile();
  105.                         if (key_scancode==SCAN_CODE_DEL) EventDeleteFile();
  106.                         if (key_scancode==SCAN_CODE_TAB) {
  107.                                 id = tabs.active_tab+1;
  108.                                 if(id==3)id=0;
  109.                                 tabs.click(id + tabs.base_id);
  110.                                 break;
  111.                         }
  112.  
  113.                         if (! edit_cmm.flags & ed_focus) && (! edit_st.flags & ed_focus)
  114.                         for (i=select_list.cur_y+1; i<select_list.count; i++)
  115.                         {
  116.                                 id = ESBYTE[list.get(i)];
  117.                                 if (id==ESBYTE[EAX]) || (id==key_ascii-32)
  118.                                 {
  119.                                         select_list.cur_y = i - 1;
  120.                                         select_list.KeyDown();
  121.                                         EventApply();
  122.                                         break;
  123.                                 }
  124.                         }
  125.  
  126.                         if (tabs.active_tab == TAB_SKINS) {
  127.                                 EAX = key_editbox;
  128.                                 edit_box_key stdcall (#edit_cmm);
  129.                                 edit_box_key stdcall (#edit_st);                               
  130.                         }
  131.                         break;
  132.                  
  133.                  case evReDraw:        
  134.                         draw_window();
  135.    }
  136. }
  137.  
  138. void draw_window()
  139. {
  140.         sc.get();
  141.         DefineAndDrawWindow(screen.width-WIN_W-9/2,80,WIN_W+9,WIN_H+4+skin_height,0x34,sc.work,WINDOW_HEADER,0);
  142.         DrawWindowContent();
  143. }
  144.  
  145. void DrawWindowContent()
  146. {
  147.         sc.get();      
  148.  
  149.         tabs.draw();
  150.         draw_icon_16w(tabs.x + TAB_PADDING, LP+5, 17);
  151.         draw_icon_16w(sizeof(t_skins)-1*8 + TAB_PADDING + TAB_PADDING + tabs.x, LP+5, 6);
  152.         draw_icon_16w(sizeof(t_wallpapers)+sizeof(t_skins)-2*8 + TAB_PADDING + TAB_PADDING + TAB_PADDING + tabs.x, LP+5, 61);
  153.  
  154.         $push select_list.cur_y
  155.         SelectList_Init(
  156.                 LP + TAB_PADDING,
  157.                 PANEL_H,
  158.                 LIST_W,
  159.                 WIN_H - LP - TAB_PADDING - PANEL_H
  160.                 );
  161.         $pop select_list.cur_y
  162.  
  163.         DrawBar(RIGHTx, PANEL_H, RIGHTw, WIN_H-PANEL_H-LP, sc.work);
  164.  
  165.         SelectList_Draw();
  166.         SelectList_DrawBorder();
  167.  
  168.         if (tabs.active_tab == TAB_SKINS)
  169.         {
  170.                 DrawFrame(RIGHTx, PANEL_H+5, RIGHTw, RIGHTh, T_UI_PREVIEW);
  171.                 DrawUiElementsPreview(RIGHTx+20, PANEL_H+5, RIGHTh);
  172.                 if (CheckProcessExists("@DOCKY")) update_docky.draw(RIGHTx, PANEL_H+250);
  173.         }
  174.         if (tabs.active_tab == TAB_WALLPAPERS)
  175.         {
  176.                 DrawFrame(RIGHTx, PANEL_H+5, 180, 105, T_PICTURE_MODE);
  177.                 optionbox_stretch.draw(RIGHTx+14, PANEL_H+25);
  178.                 optionbox_tiled.draw(RIGHTx+14, PANEL_H+52);
  179.                 optionbox_auto.draw(RIGHTx+14, PANEL_H+79);
  180.                 DrawStandartCaptButton(RIGHTx, PANEL_H+130, BTN_SELECT_WALLP_FOLDER, T_SELECT_FOLDER);
  181.         }
  182.         if (tabs.active_tab == TAB_SCREENSAVERS)
  183.         {
  184.                 DrawStandartCaptButton(RIGHTx, PANEL_H, BTN_TEST_SCREENSAVER, T_SCREENSAVER_PREVIEW);
  185.         }
  186. }
  187.  
  188. bool strreqi(dword _left, _right)
  189. {
  190.         return strcmp(_left+strrchr(_left,'.'), _right);
  191. }
  192.  
  193. dword files_mas[400];
  194. void Open_Dir()
  195. {
  196.         int j;
  197.         char fname[4096];
  198.         select_list.ClearList();
  199.         if(io.dir.buffer)free(io.dir.buffer);
  200.         io.dir.load(#folder_path,DIR_ONLYREAL);
  201.         for (j=0; j<io.dir.count; j++)
  202.         {
  203.                 strcpy(#fname, io.dir.position(j));
  204.                 strlwr(#fname);
  205.                 if (tabs.active_tab==TAB_SKINS) {
  206.                         if (strreqi(#fname,"skn")!=0) continue;
  207.                 }
  208.                 if (tabs.active_tab==TAB_WALLPAPERS) {
  209.                         if (strreqi(#fname,"png")!=0)
  210.                         && (strreqi(#fname,"jpg")!=0)
  211.                         && (strreqi(#fname,"jpeg")!=0)
  212.                         && (strreqi(#fname,"bmp")!=0)
  213.                         && (strreqi(#fname,"gif")!=0) continue;
  214.                 }
  215.                 ESDWORD[select_list.count*4 + #files_mas] = j;
  216.                 select_list.count++;
  217.         }
  218.         Sort_by_Name(0, select_list.count-1);
  219.         list.drop();
  220.         for (j=0; j<select_list.count; j++) {
  221.                 list.add(io.dir.position(files_mas[j]));
  222.         }
  223.         if (!select_list.count) notify(T_NO_FILES);
  224.         //save current item for tab change
  225.         switch(tabs.active_tab) {
  226.                 CASE TAB_SKINS: select_list.cur_y = active_skin; BREAK;
  227.                 CASE TAB_WALLPAPERS: select_list.cur_y = active_wallpaper; BREAK;
  228.                 CASE TAB_SCREENSAVERS: select_list.cur_y = active_screensaver;
  229.         }
  230.         if (select_list.cur_y>select_list.visible) select_list.first=select_list.cur_y;
  231.         select_list.CheckDoesValuesOkey();     
  232.         if (LIST_W) draw_window();
  233. }
  234.  
  235. void Sort_by_Name(int a, b) // for the first call: a = 0, b = sizeof(mas) - 1
  236. {                                        
  237.         int j;
  238.         int isn = a;
  239.         if (a >= b) return;
  240.         for (j = a; j <= b; j++) {
  241.                 if (strcmpi(io.dir.position(files_mas[j]), io.dir.position(files_mas[b]))<=0) {
  242.                         files_mas[isn] >< files_mas[j];
  243.                         isn++;
  244.                 }
  245.         }
  246.         Sort_by_Name(a, isn-2);
  247.         Sort_by_Name(isn, b);
  248. }
  249.  
  250. void SelectList_DrawLine(dword i)
  251. {
  252.         int draw_y = i*SELECT_LIST_ITEMH+PANEL_H;
  253.         int i_abs = select_list.first + i;
  254.         char filename_buf[4096];
  255.         char* filename = #filename_buf;
  256.  
  257.         strcpy(filename, list.get(i_abs));
  258.         EAX = math.min(strrchr(filename,'.')-1, LIST_W - 24 / 8);
  259.         filename_buf[EAX] = '\0';
  260.         if (EAX = strrchr(filename,'/')) filename += EAX;
  261.  
  262.         //save current item for tab change
  263.         switch(tabs.active_tab) {
  264.                 CASE TAB_SKINS: active_skin = select_list.cur_y; BREAK;
  265.                 CASE TAB_WALLPAPERS: active_wallpaper = select_list.cur_y; BREAK;
  266.                 CASE TAB_SCREENSAVERS: active_screensaver = select_list.cur_y;
  267.         }
  268.        
  269.         if (select_list.cur_y == i_abs)
  270.         {
  271.                 DrawBar(select_list.x, draw_y, LIST_W, SELECT_LIST_ITEMH, sc.button);
  272.                 WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,sc.button_text, filename);
  273.         }
  274.         else
  275.         {
  276.                 DrawBar(select_list.x,draw_y,LIST_W, SELECT_LIST_ITEMH, 0xFFFfff);
  277.                 WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,0, filename);
  278.         }
  279. }
  280.  
  281. void SelectList_LineChanged()
  282. {
  283.         EventApply();
  284. }
  285.  
  286. dword GetRealKolibriosPath()
  287. {
  288.         char real_kolibrios_path[4096];
  289.         SetCurDir("/kolibrios");
  290.         GetCurDir(#real_kolibrios_path, sizeof(real_kolibrios_path));
  291.         return #real_kolibrios_path;
  292. }
  293.  
  294. void GetScreensaverIniSettings()
  295. {
  296.         ini.section = "screensaver";
  297.         screensaver_timeout = ini.GetInt("timeout", 10);
  298.         ini.GetString("available", #ss_available, sizeof(ss_available), 0);
  299. }
  300.  
  301. //===================================================//
  302. //                                                   //
  303. //                     EVENTS                        //
  304. //                                                   //
  305. //===================================================//
  306.  
  307. void EventTabSkinsClick()
  308. {
  309.         miniprintf(#folder_path, "%s/res/skins", GetRealKolibriosPath());
  310.         Open_Dir();
  311. }
  312.  
  313. void EventTabWallpappersClick()
  314. {
  315.         if (opendir_path) {
  316.                 strcpy(#folder_path, #opendir_path);
  317.         } else {
  318.                 miniprintf(#folder_path, "%s/res/wallpapers", GetRealKolibriosPath());
  319.         }
  320.         Open_Dir();
  321. }
  322.  
  323. void EventTabScreensaverClick()
  324. {
  325.         dword j;
  326.         char ssmas[sizeof(ss_available)];
  327.         list.drop();
  328.         select_list.ClearList();
  329.  
  330.         strcpy(#ssmas, #ss_available);
  331.         do {
  332.                 j = strrchr(#ss_available, '|');
  333.                 miniprintf(#param, "/sys/%s", #ss_available + j);
  334.                 list.add(#param);
  335.                 ESBYTE[#ss_available + j - 1] = '\0';
  336.                 select_list.count++;
  337.         } while (j);
  338.  
  339.         if (LIST_W) draw_window();
  340. }
  341.  
  342. void EventDeleteFile()
  343. {
  344.         DeleteFile(#cur_file_path);
  345.         Open_Dir();
  346.         EventApply();
  347. }
  348.  
  349. void EventSelectWallpFolder()
  350. {
  351.         OpenDialog_start stdcall (#o_dialog);
  352.         if (o_dialog.status) EventTabWallpappersClick();
  353. }
  354.  
  355. void EventSetWallpMode(dword _stretch, _titled, _auto)
  356. {
  357.         optionbox_stretch.checked = _stretch;
  358.         optionbox_tiled.checked = _titled;
  359.         optionbox_auto.checked = _auto;
  360.         optionbox_tiled.redraw();
  361.         optionbox_stretch.redraw();
  362.         optionbox_auto.redraw();
  363.         EventApply();
  364. }
  365.  
  366. void EventApply()
  367. {
  368.         char kivparam[4096+10];
  369.         dword file_name = list.get(select_list.cur_y);
  370.         miniprintf(#cur_file_path,"%s/",#folder_path);
  371.         strcat(#cur_file_path, list.get(select_list.cur_y));
  372.         if (tabs.active_tab==TAB_SKINS)
  373.         {
  374.                 SetSystemSkin(#cur_file_path);
  375.                 SelectList_Draw();
  376.                 strcpy(#cur_skin_path, #cur_file_path);
  377.                 EventUpdateDocky();
  378.         }
  379.         if (tabs.active_tab==TAB_WALLPAPERS)
  380.         {
  381.                 SelectList_Draw();
  382.                 miniprintf(#kivparam, "\\S__%s", #cur_file_path);
  383.                 if (optionbox_tiled.checked) kivparam[1]='T';
  384.                 if (optionbox_auto.checked) {
  385.                         if (ESBYTE[file_name+1] == ' ') && (ESBYTE[file_name] == 'T') {
  386.                                 kivparam[1]='T';
  387.                         }
  388.                 }
  389.                 RunProgram("/sys/media/kiv", #kivparam);
  390.         }
  391.         if (tabs.active_tab==TAB_SCREENSAVERS)
  392.         {
  393.                 SelectList_Draw();
  394.         }
  395. }
  396.  
  397. void EventUpdateDocky()
  398. {
  399.         if (!update_docky.checked) return;
  400.         KillProcessByName("@docky", MULTIPLE);
  401.         RunProgram("/sys/@docky",NULL);
  402.         pause(50);
  403.         ActivateWindow_Self();
  404. }
  405.  
  406. void EventOpenFile()
  407. {
  408.         if (tabs.active_tab==TAB_SKINS) RunProgram("/sys/skincfg", #cur_file_path);
  409.         if (tabs.active_tab==TAB_WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path);
  410.         if (tabs.active_tab==TAB_SCREENSAVERS) RunProgram(list.get(select_list.cur_y), "@ss");
  411. }
  412.  
  413. void EventExit()
  414. {
  415.         if (cur_skin_path) {
  416.                 ini.section = "style";
  417.                 ini.SetString("skin", #cur_skin_path, strlen(#cur_skin_path));
  418.         }
  419.         ExitProcess();
  420. }
  421.  
  422. stop:
  423.