Subversion Repositories Kolibri OS

Rev

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