Subversion Repositories Kolibri OS

Rev

Rev 9465 | Rev 9469 | 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 (filename_buf[0]=='T') && (filename_buf[1]=='_') filename+=2;
  261.         if (EAX = strrchr(filename,'/')) filename += EAX;
  262.  
  263.         //save current item for tab change
  264.         switch(tabs.active_tab) {
  265.                 CASE TAB_SKINS: active_skin = select_list.cur_y; BREAK;
  266.                 CASE TAB_WALLPAPERS: active_wallpaper = select_list.cur_y; BREAK;
  267.                 CASE TAB_SCREENSAVERS: active_screensaver = select_list.cur_y;
  268.         }
  269.        
  270.         if (select_list.cur_y == i_abs)
  271.         {
  272.                 DrawBar(select_list.x, draw_y, LIST_W, SELECT_LIST_ITEMH, sc.button);
  273.                 WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,sc.button_text, filename);
  274.         }
  275.         else
  276.         {
  277.                 DrawBar(select_list.x,draw_y,LIST_W, SELECT_LIST_ITEMH, 0xFFFfff);
  278.                 WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,0, filename);
  279.         }
  280. }
  281.  
  282. void SelectList_LineChanged()
  283. {
  284.         EventApply();
  285. }
  286.  
  287. dword GetRealKolibriosPath()
  288. {
  289.         char real_kolibrios_path[4096];
  290.         SetCurDir("/kolibrios");
  291.         GetCurDir(#real_kolibrios_path, sizeof(real_kolibrios_path));
  292.         return #real_kolibrios_path;
  293. }
  294.  
  295. void GetScreensaverIniSettings()
  296. {
  297.         ini.section = "screensaver";
  298.         screensaver_timeout = ini.GetInt("timeout", 10);
  299.         ini.GetString("available", #ss_available, sizeof(ss_available), 0);
  300. }
  301.  
  302. //===================================================//
  303. //                                                   //
  304. //                     EVENTS                        //
  305. //                                                   //
  306. //===================================================//
  307.  
  308. void EventTabSkinsClick()
  309. {
  310.         miniprintf(#folder_path, "%s/res/skins", GetRealKolibriosPath());
  311.         Open_Dir();
  312. }
  313.  
  314. void EventTabWallpappersClick()
  315. {
  316.         if (opendir_path) {
  317.                 strcpy(#folder_path, #opendir_path);
  318.         } else {
  319.                 miniprintf(#folder_path, "%s/res/wallpapers", GetRealKolibriosPath());
  320.         }
  321.         Open_Dir();
  322. }
  323.  
  324. void EventTabScreensaverClick()
  325. {
  326.         dword j;
  327.         char ssmas[sizeof(ss_available)];
  328.         list.drop();
  329.         select_list.ClearList();
  330.  
  331.         strcpy(#ssmas, #ss_available);
  332.         do {
  333.                 j = strrchr(#ss_available, '|');
  334.                 miniprintf(#param, "/sys/%s", #ss_available + j);
  335.                 list.add(#param);
  336.                 ESBYTE[#ss_available + j - 1] = '\0';
  337.                 select_list.count++;
  338.         } while (j);
  339.  
  340.         if (LIST_W) draw_window();
  341. }
  342.  
  343. void EventDeleteFile()
  344. {
  345.         DeleteFile(#cur_file_path);
  346.         Open_Dir();
  347.         EventApply();
  348. }
  349.  
  350. void EventSelectWallpFolder()
  351. {
  352.         OpenDialog_start stdcall (#o_dialog);
  353.         if (o_dialog.status) EventTabWallpappersClick();
  354. }
  355.  
  356. void EventSetWallpMode(dword _stretch, _titled, _auto)
  357. {
  358.         optionbox_stretch.checked = _stretch;
  359.         optionbox_tiled.checked = _titled;
  360.         optionbox_auto.checked = _auto;
  361.         optionbox_tiled.redraw();
  362.         optionbox_stretch.redraw();
  363.         optionbox_auto.redraw();
  364.         EventApply();
  365. }
  366.  
  367. void EventApply()
  368. {
  369.         char kivparam[4096+10];
  370.         dword file_name = list.get(select_list.cur_y);
  371.         miniprintf(#cur_file_path,"%s/",#folder_path);
  372.         strcat(#cur_file_path, list.get(select_list.cur_y));
  373.         if (tabs.active_tab==TAB_SKINS)
  374.         {
  375.                 SetSystemSkin(#cur_file_path);
  376.                 SelectList_Draw();
  377.                 strcpy(#cur_skin_path, #cur_file_path);
  378.                 EventUpdateDocky();
  379.         }
  380.         if (tabs.active_tab==TAB_WALLPAPERS)
  381.         {
  382.                 SelectList_Draw();
  383.                 miniprintf(#kivparam, "\\S__%s", #cur_file_path);
  384.                 if (optionbox_tiled.checked) kivparam[1]='T';
  385.                 if (optionbox_auto.checked) {
  386.                         if (ESBYTE[file_name+1] == '_') && (ESBYTE[file_name] == 'T') {
  387.                                 kivparam[1]='T';
  388.                         }
  389.                 }
  390.                 RunProgram("/sys/media/kiv", #kivparam);
  391.         }
  392.         if (tabs.active_tab==TAB_SCREENSAVERS)
  393.         {
  394.                 SelectList_Draw();
  395.         }
  396. }
  397.  
  398. void EventUpdateDocky()
  399. {
  400.         if (!update_docky.checked) return;
  401.         KillProcessByName("@docky", MULTIPLE);
  402.         RunProgram("/sys/@docky",NULL);
  403.         pause(50);
  404.         ActivateWindow_Self();
  405. }
  406.  
  407. void EventOpenFile()
  408. {
  409.         if (tabs.active_tab==TAB_SKINS) RunProgram("/sys/skincfg", #cur_file_path);
  410.         if (tabs.active_tab==TAB_WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path);
  411.         if (tabs.active_tab==TAB_SCREENSAVERS) RunProgram(list.get(select_list.cur_y), "@ss");
  412. }
  413.  
  414. void EventExit()
  415. {
  416.         if (cur_skin_path) {
  417.                 ini.section = "style";
  418.                 ini.SetString("skin", #cur_skin_path, strlen(#cur_skin_path));
  419.         }
  420.         ExitProcess();
  421. }
  422.  
  423. stop:
  424.