Subversion Repositories Kolibri OS

Rev

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