Subversion Repositories Kolibri OS

Rev

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