Subversion Repositories Kolibri OS

Rev

Rev 7613 | Rev 7628 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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