Subversion Repositories Kolibri OS

Rev

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