Subversion Repositories Kolibri OS

Rev

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