Subversion Repositories Kolibri OS

Rev

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