Subversion Repositories Kolibri OS

Rev

Rev 9481 | Rev 9516 | 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. int active_skin, active_wallpaper, active_screensaver;
  29.  
  30. char folder_path[4096];
  31. char cur_file_path[4096];
  32. char cur_skin_path[4096];
  33. char default_skin[4096];
  34. char default_wallp[4096];
  35. char ss_available[200];
  36.  
  37. int screensaver_timeout;
  38.  
  39. _tabs tabs = { -sizeof(t_skins)-sizeof(t_wallpapers)-sizeof(t_screensaver)-3*8+WIN_W
  40.          - TAB_PADDING / 2, LP, NULL, BASE_TAB_BUTTON_ID };
  41.  
  42. checkbox update_docky = { T_UPDATE_DOCK, false };
  43. checkbox ss_in_on = { T_UPDATE_DOCK, false };
  44.  
  45. checkbox optionbox_stretch = { T_CHECKBOX_STRETCH, false };
  46. checkbox optionbox_tiled = { T_CHECKBOX_TILED, false };
  47. checkbox optionbox_auto = { T_CHECKBOX_AUTO, true };
  48.  
  49. collection list;
  50.  
  51. //===================================================//
  52. //                                                   //
  53. //                       CODE                        //
  54. //                                                   //
  55. //===================================================//
  56.  
  57. void main()
  58. {  
  59.         int id, i;
  60.         load_dll(boxlib, #box_lib_init,0);
  61.         load_dll(libini, #lib_init,1);
  62.         load_dll(Proc_lib, #OpenDialog_init,0);
  63.         o_dialog.type = 2; //select folder
  64.         OpenDialog_init stdcall (#o_dialog);
  65.  
  66.         GetIniSettings();
  67.  
  68.         tabs.add(#t_skins, #EventTabSkinsClick);       
  69.         tabs.add(#t_wallpapers, #EventTabWallpappersClick);
  70.         tabs.add(#t_screensaver, #EventTabScreensaverClick);
  71.         tabs.draw_active_tab();
  72.  
  73.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  74.         loop() switch(WaitEvent())
  75.         {
  76.                 case evMouse:
  77.                         SelectList_ProcessMouse();
  78.                         break;
  79.  
  80.                 case evButton:
  81.                         id=GetButtonID();
  82.                         if (id==1) EventExit();
  83.                         tabs.click(id);
  84.                         if (tabs.active_tab == TAB_SKINS) {
  85.                                 checkbox1.click(id);
  86.                                 spinbox1.click(id);
  87.                                 if (update_docky.click(id)) EventUpdateDocky();
  88.                         }
  89.                         if (tabs.active_tab == TAB_WALLPAPERS) {
  90.                                 if (id==BTN_SELECT_WALLP_FOLDER) EventSelectWallpFolder();
  91.                                 if (optionbox_stretch.click(id)) EventSetWallpMode(1,0,0);
  92.                                 if (optionbox_tiled.click(id)) EventSetWallpMode(0,1,0);
  93.                                 if (optionbox_auto.click(id)) EventSetWallpMode(0,0,1);
  94.                         }
  95.                         if (tabs.active_tab == TAB_SCREENSAVERS) {
  96.                                 if (id==BTN_TEST_SCREENSAVER) EventOpenFile();
  97.                                 if (id==BTN_SET_SCREENSAVER) EventSetSs();
  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 = list.get(i) + strrchr(list.get(i), '/');
  117.                                 if (ESBYTE[id]==key_ascii) || (ESBYTE[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.                 miniprintf(#param, T_SS_TIMEOUT, screensaver_timeout);
  185.                 WriteTextWithBg(RIGHTx, PANEL_H, 0xD0, sc.work_text, #param, sc.work);
  186.                 ESI = DrawStandartCaptButton(RIGHTx, PANEL_H + 25, BTN_TEST_SCREENSAVER, T_SS_PREVIEW);
  187.                 DrawStandartCaptButton(RIGHTx+ESI, PANEL_H + 25, BTN_SET_SCREENSAVER, T_SS_SET);
  188.         }
  189. }
  190.  
  191. bool strreqi(dword _left, _right)
  192. {
  193.         return strcmp(_left+strrchr(_left,'.'), _right);
  194. }
  195.  
  196. dword files_mas[400];
  197. void Open_Dir()
  198. {
  199.         int j;
  200.         char fname[4096];
  201.         select_list.ClearList();
  202.         if(io.dir.buffer)free(io.dir.buffer);
  203.         io.dir.load(#folder_path,DIR_ONLYREAL);
  204.  
  205.         for (j=0; j<io.dir.count; j++)
  206.         {
  207.                 strcpy(#fname, io.dir.position(j));
  208.                 strlwr(#fname);
  209.                 if (tabs.active_tab==TAB_SKINS) {
  210.                         if (strreqi(#fname,"skn")!=0) continue;
  211.                 }
  212.                 if (tabs.active_tab==TAB_WALLPAPERS) {
  213.                         if (strreqi(#fname,"png")!=0)
  214.                         && (strreqi(#fname,"jpg")!=0)
  215.                         && (strreqi(#fname,"jpeg")!=0)
  216.                         && (strreqi(#fname,"bmp")!=0)
  217.                         && (strreqi(#fname,"gif")!=0) continue;
  218.                 }
  219.                 ESDWORD[select_list.count*4 + #files_mas] = j;
  220.                 select_list.count++;
  221.         }
  222.         Sort_by_Name(0, select_list.count-1);
  223.  
  224.         list.drop();
  225.         //save current item for tab change
  226.         //add default item
  227.         switch(tabs.active_tab) {
  228.                 CASE TAB_SKINS:
  229.                                 select_list.cur_y = active_skin;
  230.                                 select_list.count++;
  231.                                 list.add(#default_skin);
  232.                                 BREAK;
  233.                 CASE TAB_WALLPAPERS:
  234.                                 select_list.cur_y = active_wallpaper;
  235.                                 select_list.count++;
  236.                                 list.add(#default_wallp);
  237.                                 BREAK;
  238.                 CASE TAB_SCREENSAVERS:
  239.                                 select_list.cur_y = active_screensaver;
  240.         }
  241.  
  242.         for (j=0; j<select_list.count; j++) {
  243.                 miniprintf(#param,"%s/",#folder_path);
  244.                 strcat(#param, io.dir.position(files_mas[j]));
  245.                 list.add(#param);
  246.         }
  247.  
  248.         if (!select_list.count) notify(T_NO_FILES);
  249.         if (select_list.cur_y>select_list.visible) select_list.first=select_list.cur_y;
  250.         select_list.CheckDoesValuesOkey();     
  251.         if (LIST_W) draw_window();
  252. }
  253.  
  254. void Sort_by_Name(int a, b) // for the first call: a = 0, b = sizeof(mas) - 1
  255. {                                        
  256.         int j;
  257.         int isn = a;
  258.         if (a >= b) return;
  259.         for (j = a; j <= b; j++) {
  260.                 if (strcmpi(io.dir.position(files_mas[j]), io.dir.position(files_mas[b]))<=0) {
  261.                         files_mas[isn] >< files_mas[j];
  262.                         isn++;
  263.                 }
  264.         }
  265.         Sort_by_Name(a, isn-2);
  266.         Sort_by_Name(isn, b);
  267. }
  268.  
  269. void SelectList_DrawLine(dword i)
  270. {
  271.         int draw_y = i*SELECT_LIST_ITEMH+PANEL_H;
  272.         int i_abs = select_list.first + i;
  273.         char filename_buf[4096];
  274.         char* filename = #filename_buf;
  275.  
  276.         strcpy(filename, list.get(i_abs));
  277.         if (EAX = strrchr(filename,'/')) filename += EAX;
  278.         if (ESBYTE[filename]=='T') && (ESBYTE[filename+1]=='_') filename+=2;
  279.         EAX = math.min(strrchr(filename,'.')-1, LIST_W - 24 / 8);
  280.         if(EAX) ESBYTE[filename+EAX] = '\0';
  281.  
  282.         //save current item for tab change
  283.         switch(tabs.active_tab) {
  284.                 CASE TAB_SKINS:
  285.                                 active_skin = select_list.cur_y;
  286.                                 if (!i_abs) filename = T_DEFAULT;
  287.                                 BREAK;
  288.                 CASE TAB_WALLPAPERS:
  289.                                 active_wallpaper = select_list.cur_y;
  290.                                 if (!i_abs) filename = T_DEFAULT;
  291.                                 BREAK;
  292.                 CASE TAB_SCREENSAVERS:
  293.                                 active_screensaver = select_list.cur_y;
  294.         }
  295.        
  296.         if (select_list.cur_y == i_abs)
  297.         {
  298.                 DrawBar(select_list.x, draw_y, LIST_W, SELECT_LIST_ITEMH, sc.button);
  299.                 WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,sc.button_text, filename);
  300.         }
  301.         else
  302.         {
  303.                 DrawBar(select_list.x,draw_y,LIST_W, SELECT_LIST_ITEMH, 0xFFFfff);
  304.                 WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,0, filename);
  305.         }
  306. }
  307.  
  308. void SelectList_LineChanged()
  309. {
  310.         EventApply();
  311. }
  312.  
  313. dword GetRealKolibriosPath()
  314. {
  315.         char real_kolibrios_path[4096];
  316.         SetCurDir("/kolibrios");
  317.         GetCurDir(#real_kolibrios_path, sizeof(real_kolibrios_path));
  318.         return #real_kolibrios_path;
  319. }
  320.  
  321. void GetIniSettings()
  322. {
  323.         ini.section = "screensaver";
  324.         screensaver_timeout = ini.GetInt("timeout", 10);
  325.         ini.GetString("available", #ss_available, sizeof(ss_available), 0);
  326.         ini.section = "style";
  327.         ini.GetString("default_skin", #default_skin, sizeof(default_skin), 0);
  328.         ini.GetString("default_wallp", #default_wallp, sizeof(default_wallp), 0);
  329. }
  330.  
  331. //===================================================//
  332. //                                                   //
  333. //                     EVENTS                        //
  334. //                                                   //
  335. //===================================================//
  336.  
  337. void EventTabSkinsClick()
  338. {
  339.         miniprintf(#folder_path, "%s/res/skins", GetRealKolibriosPath());
  340.         Open_Dir();
  341. }
  342.  
  343. void EventTabWallpappersClick()
  344. {
  345.         if (opendir_path) {
  346.                 strcpy(#folder_path, #opendir_path);
  347.         } else {
  348.                 miniprintf(#folder_path, "%s/res/wallpapers", GetRealKolibriosPath());
  349.         }
  350.         Open_Dir();
  351. }
  352.  
  353. void EventTabScreensaverClick()
  354. {
  355.         dword j;
  356.         char ssmas[sizeof(ss_available)];
  357.         list.drop();
  358.         select_list.ClearList();
  359.  
  360.         select_list.count++;
  361.         list.add(T_NO_SS);
  362.  
  363.         strcpy(#ssmas, #ss_available);
  364.         do {
  365.                 j = strrchr(#ssmas, '|');
  366.                 miniprintf(#param, "/sys/%s", #ssmas + j);
  367.                 list.add(#param);
  368.                 ESBYTE[#ssmas + j - 1] = '\0';
  369.                 select_list.count++;
  370.         } while (j);
  371.  
  372.         if (LIST_W) draw_window();
  373. }
  374.  
  375. void EventDeleteFile()
  376. {
  377.         if (select_list.cur_y) DeleteFile(#cur_file_path); //no not delete default
  378.         Open_Dir();
  379.         EventApply();
  380. }
  381.  
  382. void EventSelectWallpFolder()
  383. {
  384.         OpenDialog_start stdcall (#o_dialog);
  385.         if (o_dialog.status) EventTabWallpappersClick();
  386. }
  387.  
  388. void EventSetWallpMode(dword _stretch, _titled, _auto)
  389. {
  390.         optionbox_stretch.checked = _stretch;
  391.         optionbox_tiled.checked = _titled;
  392.         optionbox_auto.checked = _auto;
  393.         optionbox_tiled.redraw();
  394.         optionbox_stretch.redraw();
  395.         optionbox_auto.redraw();
  396.         EventApply();
  397. }
  398.  
  399. void EventApply()
  400. {
  401.         char kivparam[4096+10];
  402.         dword file_name = list.get(select_list.cur_y);
  403.         strcpy(#cur_file_path, list.get(select_list.cur_y));
  404.         if (tabs.active_tab==TAB_SKINS)
  405.         {
  406.                 SetSystemSkin(#cur_file_path);
  407.                 SelectList_Draw();
  408.                 strcpy(#cur_skin_path, #cur_file_path);
  409.                 EventUpdateDocky();
  410.         }
  411.         if (tabs.active_tab==TAB_WALLPAPERS)
  412.         {
  413.                 SelectList_Draw();
  414.                 miniprintf(#kivparam, "\\S__%s", #cur_file_path);
  415.                 if (optionbox_tiled.checked) || (!select_list.cur_y) kivparam[1]='T';
  416.                 if (optionbox_auto.checked) {
  417.                         file_name += strrchr(file_name, '/');
  418.                         if (ESBYTE[file_name] == 'T') && (ESBYTE[file_name+1] == '_') {
  419.                                 kivparam[1]='T';
  420.                         }
  421.                 }
  422.                 RunProgram("/sys/media/kiv", #kivparam);
  423.         }
  424.         if (tabs.active_tab==TAB_SCREENSAVERS)
  425.         {
  426.                 SelectList_Draw();
  427.         }
  428. }
  429.  
  430. void EventUpdateDocky()
  431. {
  432.         if (!update_docky.checked) return;
  433.         // KillProcessByName("@docky", MULTIPLE);
  434.         // RunProgram("/sys/@docky",NULL);
  435.         RestartProcessByName("/sys/@docky", MULTIPLE);
  436.         pause(50);
  437.         ActivateWindow_Self();
  438. }
  439.  
  440. void EventOpenFile()
  441. {
  442.         switch (tabs.active_tab) {
  443.                 case TAB_SKINS: RunProgram("/sys/skincfg", #cur_file_path); break;
  444.                 case TAB_WALLPAPERS: RunProgram("/sys/media/kiv", #cur_file_path); break;
  445.                 case TAB_SCREENSAVERS: if(select_list.cur_y) RunProgram(list.get(select_list.cur_y), "@ss");
  446.         }
  447. }
  448.  
  449. void EventExit()
  450. {
  451.         if (cur_skin_path) {
  452.                 ini.section = "style";
  453.                 ini.SetString("skin", #cur_skin_path, strlen(#cur_skin_path));
  454.         }
  455.         ExitProcess();
  456. }
  457.  
  458. void EventSetSs()
  459. {
  460.         dword cur_ss = list.get(select_list.cur_y);
  461.         ini.section = "screensaver";
  462.         ini.SetString("program", cur_ss, strlen(cur_ss));
  463.         RestartProcessByName("/sys/@ss", MULTIPLE);
  464. }
  465.  
  466. stop:
  467.