Subversion Repositories Kolibri OS

Rev

Rev 9455 | Rev 9465 | 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. #include "const.h"
  21.  
  22. //===================================================//
  23. //                                                   //
  24. //                       DATA                        //
  25. //                                                   //
  26. //===================================================//
  27.  
  28. signed int active_skin=-1, active_wallpaper=-1, active_screensaver=-1;
  29. enum {
  30.         BASE_TAB_BUTTON_ID=3,
  31.         BTN_SELECT_WALLP_FOLDER=10,
  32.         BTN_TEST_SCREENSAVER };
  33.  
  34. char folder_path[4096];
  35. char cur_file_path[4096];
  36. char cur_skin_path[4096];
  37. int files_mas[400];
  38.  
  39. _tabs tabs = { -sizeof(t_skins)-sizeof(t_wallpapers)-sizeof(t_screensaver)-3*8+WIN_W
  40.          - TAB_PADDING / 2, LP, NULL, BASE_TAB_BUTTON_ID };
  41.  
  42. checkbox update_docky = { T_UPDATE_DOCK, false };
  43.  
  44. checkbox optionbox_stretch = { T_CHECKBOX_STRETCH, true };
  45. checkbox optionbox_tiled = { T_CHECKBOX_TILED, false };
  46.  
  47. struct SCREENSAVER_SETTINGS {
  48.         int timeout;
  49.         char program[60];
  50.         char available[200];
  51. } ss_settings;
  52.  
  53. //===================================================//
  54. //                                                   //
  55. //                       CODE                        //
  56. //                                                   //
  57. //===================================================//
  58.  
  59. void main()
  60. {  
  61.         int id, i;
  62.         load_dll(boxlib, #box_lib_init,0);
  63.         load_dll(libini, #lib_init,1);
  64.         load_dll(Proc_lib, #OpenDialog_init,0);
  65.         o_dialog.type = 2; //select folder
  66.         OpenDialog_init stdcall (#o_dialog);
  67.  
  68.         tabs.add(#t_skins, #EventTabSkinsClick);       
  69.         tabs.add(#t_wallpapers, #EventTabWallpappersClick);
  70.         tabs.add(#t_screensaver, #EventTabScreensaverClick);
  71.         tabs.draw_active_tab();
  72.  
  73.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  74.         loop() switch(WaitEvent())
  75.         {
  76.                 case evMouse:
  77.                         SelectList_ProcessMouse();
  78.                         break;
  79.  
  80.                 case evButton:
  81.                         id=GetButtonID();
  82.                         if (id==1) EventExit();
  83.                         if (id==BTN_SELECT_WALLP_FOLDER) EventSelectWallpFolder();
  84.                         tabs.click(id);
  85.                         checkbox1.click(id);
  86.                         spinbox1.click(id);
  87.                         if (update_docky.click(id)) EventUpdateDocky();
  88.                         if (!optionbox_stretch.checked) && (optionbox_stretch.click(id)) EventSetWallpMode_Stretch();
  89.                         if (!optionbox_tiled.checked) && (optionbox_tiled.click(id)) EventSetWallpMode_Tiled();
  90.                         break;
  91.          
  92.                 case evKey:
  93.                         GetKeys();
  94.                         if (select_list.ProcessKey(key_scancode)) EventApply();
  95.                         if (key_scancode==SCAN_CODE_ENTER) EventOpenFile();
  96.                         if (key_scancode==SCAN_CODE_DEL) EventDeleteFile();
  97.                         if (key_scancode==SCAN_CODE_TAB) {
  98.                                 id = tabs.active_tab+1;
  99.                                 if(id==3)id=0;
  100.                                 tabs.click(id + tabs.base_id);
  101.                                 DrawWindowContent();
  102.                                 break;
  103.                         }
  104.  
  105.                         if (! edit_cmm.flags & ed_focus) && (! edit_st.flags & ed_focus)
  106.                         for (i=select_list.cur_y+1; i<select_list.count; i++)
  107.                         {
  108.                                 id = ESBYTE[io.dir.position(files_mas[i])];
  109.                                 if (id==ESBYTE[EAX]) || (id==key_ascii-32)
  110.                                 {
  111.                                         select_list.cur_y = i - 1;
  112.                                         select_list.KeyDown();
  113.                                         EventApply();
  114.                                         break;
  115.                                 }
  116.                         }
  117.  
  118.                         if (tabs.active_tab == TAB_SKINS) {
  119.                                 EAX = key_editbox;
  120.                                 edit_box_key stdcall (#edit_cmm);
  121.                                 edit_box_key stdcall (#edit_st);                               
  122.                         }
  123.                         break;
  124.                  
  125.                  case evReDraw:        
  126.                         draw_window();
  127.    }
  128. }
  129.  
  130. void draw_window()
  131. {
  132.         sc.get();
  133.         DefineAndDrawWindow(screen.width-WIN_W-9/2,80,WIN_W+9,WIN_H+4+skin_height,0x34,sc.work,WINDOW_HEADER,0);
  134.         DrawWindowContent();
  135. }
  136.  
  137. void DrawWindowContent()
  138. {
  139.         sc.get();      
  140.  
  141.         tabs.draw();
  142.         draw_icon_16w(tabs.x + TAB_PADDING, LP+5, 17);
  143.         draw_icon_16w(sizeof(t_skins)-1*8 + TAB_PADDING + TAB_PADDING + tabs.x, LP+5, 6);
  144.         draw_icon_16w(sizeof(t_wallpapers)+sizeof(t_skins)-2*8 + TAB_PADDING + TAB_PADDING + TAB_PADDING + tabs.x, LP+5, 61);
  145.  
  146.         $push select_list.cur_y
  147.         SelectList_Init(
  148.                 LP + TAB_PADDING,
  149.                 PANEL_H,
  150.                 LIST_W,
  151.                 WIN_H - LP - TAB_PADDING - PANEL_H
  152.                 );
  153.         $pop select_list.cur_y
  154.  
  155.         DrawBar(RIGHTx, PANEL_H, RIGHTw, WIN_H-PANEL_H-LP, sc.work);
  156.  
  157.         SelectList_Draw();
  158.         SelectList_DrawBorder();
  159.  
  160.         if (tabs.active_tab == TAB_SKINS)
  161.         {
  162.                 DrawFrame(RIGHTx, PANEL_H+5, RIGHTw, RIGHTh, T_UI_PREVIEW);
  163.                 DrawUiElementsPreview(RIGHTx+20, PANEL_H+5, RIGHTh);
  164.                 if (CheckProcessExists("@DOCKY")) update_docky.draw(RIGHTx, PANEL_H+250);
  165.         }
  166.         if (tabs.active_tab == TAB_WALLPAPERS)
  167.         {
  168.                 DrawFrame(RIGHTx, PANEL_H+5, 180, 80, T_PICTURE_MODE);
  169.                 optionbox_stretch.draw(RIGHTx+14, PANEL_H+25);
  170.                 optionbox_tiled.draw(RIGHTx+14, PANEL_H+52);
  171.                 DrawStandartCaptButton(RIGHTx, PANEL_H+100, BTN_SELECT_WALLP_FOLDER, T_SELECT_FOLDER);
  172.         }
  173.         if (tabs.active_tab == TAB_SCREENSAVERS)
  174.         {
  175.                 DrawStandartCaptButton(RIGHTx, PANEL_H, BTN_TEST_SCREENSAVER, "Test");
  176.         }
  177. }
  178.  
  179. bool strreqi(dword _left, _right)
  180. {
  181.         return strcmp(_left+strrchr(_left,'.'), _right);
  182. }
  183.  
  184. void Open_Dir()
  185. {
  186.         int j;
  187.         char temp_filename[4096];
  188.         select_list.count = 0;
  189.         if(io.dir.buffer)free(io.dir.buffer);
  190.         io.dir.load(#folder_path,DIR_ONLYREAL);
  191.         for (j=0; j<io.dir.count; j++)
  192.         {
  193.                 strcpy(#temp_filename, io.dir.position(j));
  194.                 strlwr(#temp_filename);
  195.                 if (tabs.active_tab==TAB_SKINS) {
  196.                         if (strreqi(#temp_filename,"skn")!=0) continue;
  197.                 }
  198.                 if (tabs.active_tab==TAB_WALLPAPERS) {
  199.                         if (strreqi(#temp_filename,"png")!=0)
  200.                         && (strreqi(#temp_filename,"jpg")!=0)
  201.                         && (strreqi(#temp_filename,"jpeg")!=0)
  202.                         && (strreqi(#temp_filename,"bmp")!=0)
  203.                         && (strreqi(#temp_filename,"gif")!=0) continue;
  204.                 }
  205.                 files_mas[calc(select_list.count)]=j;
  206.                 select_list.count++;
  207.         }
  208.         Sort_by_Name(0, select_list.count-1);
  209. }
  210.  
  211. void Sort_by_Name(int a, b) // for the first call: a = 0, b = sizeof(mas) - 1
  212. {                                        
  213.         int j;
  214.         int isn = a;
  215.         if (a >= b) return;
  216.         for (j = a; j <= b; j++) {
  217.                 if (strcmpi(io.dir.position(files_mas[j]), io.dir.position(files_mas[b]))<=0) {
  218.                         files_mas[isn] >< files_mas[j];
  219.                         isn++;
  220.                 }
  221.         }
  222.         Sort_by_Name(a, isn-2);
  223.         Sort_by_Name(isn, b);
  224. }
  225.  
  226. void SelectList_DrawLine(dword i)
  227. {
  228.         int draw_y = i*SELECT_LIST_ITEMH+PANEL_H;
  229.         int i_abs = select_list.first + i;
  230.         char filename[4096];
  231.  
  232.         strcpy(#filename, io.dir.position(files_mas[i_abs]));
  233.         EAX = math.min(strrchr(#filename,'.')-1, LIST_W - 24 / 8);
  234.         filename[EAX] = '\0';
  235.        
  236.         if (select_list.cur_y == i_abs)
  237.         {
  238.                 DrawBar(select_list.x, draw_y, LIST_W, SELECT_LIST_ITEMH, sc.button);
  239.                 WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,sc.button_text, #filename);
  240.         }
  241.         else
  242.         {
  243.                 DrawBar(select_list.x,draw_y,LIST_W, SELECT_LIST_ITEMH, 0xFFFfff);
  244.                 WriteText(select_list.x+12,draw_y+select_list.text_y,select_list.font_type,0, #filename);
  245.         }
  246. }
  247.  
  248. void SelectList_LineChanged()
  249. {
  250.         EventApply();
  251. }
  252.  
  253. void ActivateTab(int _id)
  254. {
  255.         select_list.ClearList();
  256.         Open_Dir();
  257.         if (!select_list.count) notify(T_NO_FILES);
  258.         select_list.cur_y = _id;
  259.         if (select_list.cur_y>select_list.visible) select_list.first=select_list.cur_y;
  260.         select_list.CheckDoesValuesOkey();     
  261.         if (LIST_W) DrawWindowContent();
  262. }
  263.  
  264. dword GetRealKolibriosPath()
  265. {
  266.         char real_kolibrios_path[4096];
  267.         SetCurDir("/kolibrios");
  268.         GetCurDir(#real_kolibrios_path, sizeof(real_kolibrios_path));
  269.         return #real_kolibrios_path;
  270. }
  271.  
  272. //===================================================//
  273. //                                                   //
  274. //                     EVENTS                        //
  275. //                                                   //
  276. //===================================================//
  277.  
  278. void EventTabSkinsClick()
  279. {
  280.         active_wallpaper = select_list.cur_y;
  281.         miniprintf(#folder_path, "%s/res/skins", GetRealKolibriosPath());
  282.         ActivateTab(active_skin);
  283. }
  284.  
  285. void EventTabWallpappersClick()
  286. {
  287.         active_skin = select_list.cur_y;
  288.         if (opendir_path) {
  289.                 strcpy(#folder_path, #opendir_path);
  290.         } else {
  291.                 miniprintf(#folder_path, "%s/res/wallpapers", GetRealKolibriosPath());
  292.         }
  293.         ActivateTab(active_wallpaper);
  294. }
  295.  
  296. void EventTabScreensaverClick()
  297. {
  298.         ini.section = "screensaver";
  299.         ss_settings.timeout = ini.GetInt("timeout", 10);
  300.         ini.GetString("title", #ss_settings.program, sizeof(ss_settings.program), 0);
  301.         ini.GetString("available", #ss_settings.available, sizeof(ss_settings.available), 0);
  302.         ActivateTab(active_screensaver);
  303. }
  304.  
  305. void EventDeleteFile()
  306. {
  307.         io.del(#cur_file_path);
  308.         Open_Dir();
  309.         EventApply();
  310. }
  311.  
  312. void EventSetNewCurrent()
  313. {
  314.         miniprintf(#cur_file_path,"%s/",#folder_path);
  315.         strcat(#cur_file_path, io.dir.position(files_mas[calc(select_list.cur_y)]));
  316. }
  317.  
  318. void EventSelectWallpFolder()
  319. {
  320.         OpenDialog_start stdcall (#o_dialog);
  321.         if (o_dialog.status) EventTabWallpappersClick();
  322. }
  323.  
  324. void EventSetWallpMode_Stretch()
  325. {
  326.         optionbox_tiled.checked = false;
  327.         optionbox_tiled.redraw();
  328.         EventApply();
  329. }
  330.  
  331. void EventSetWallpMode_Tiled()
  332. {
  333.         optionbox_stretch.checked = false;
  334.         optionbox_stretch.redraw();
  335.         EventApply();
  336. }
  337.  
  338. void EventApply()
  339. {
  340.         char kivpath[4096+10];
  341.         EventSetNewCurrent();
  342.         if (tabs.active_tab==TAB_SKINS)
  343.         {
  344.                 SetSystemSkin(#cur_file_path);
  345.                 SelectList_Draw();
  346.                 strcpy(#cur_skin_path, #cur_file_path);
  347.                 EventUpdateDocky();
  348.         }
  349.         if (tabs.active_tab==TAB_WALLPAPERS)
  350.         {
  351.                 SelectList_Draw();
  352.                 if (optionbox_stretch.checked) miniprintf(#kivpath, "\\S__%s", #cur_file_path);
  353.                 if (optionbox_tiled.checked) miniprintf(#kivpath, "\\T__%s", #cur_file_path);
  354.                 RunProgram("/sys/media/kiv", #kivpath);
  355.         }
  356. }
  357.  
  358. void EventUpdateDocky()
  359. {
  360.         if (!update_docky.checked) return;
  361.         KillProcessByName("@docky", MULTIPLE);
  362.         RunProgram("/sys/@docky",NULL);
  363.         pause(50);
  364.         ActivateWindow_Self();
  365. }
  366.  
  367. void EventOpenFile()
  368. {
  369.         if (tabs.active_tab==TAB_SKINS) RunProgram("/sys/skincfg", #cur_file_path);
  370.         if (tabs.active_tab==TAB_WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path);
  371. }
  372.  
  373. void EventExit()
  374. {
  375.         if (cur_skin_path) {
  376.                 ini.section = "style";
  377.                 ini.SetString("skin", #cur_skin_path, strlen(#cur_skin_path));
  378.         }
  379.         ExitProcess();
  380. }
  381.  
  382. stop:
  383.