Subversion Repositories Kolibri OS

Rev

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

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