Subversion Repositories Kolibri OS

Rev

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