Subversion Repositories Kolibri OS

Rev

Rev 5425 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2. SOFTWARE CENTER v2.31
  3. */
  4.  
  5. #define MEMSIZE 0x3E80
  6. #include "..\lib\kolibri.h"
  7. #include "..\lib\strings.h"
  8. #include "..\lib\mem.h"
  9. #include "..\lib\file_system.h"
  10. #include "..\lib\dll.h"
  11. #include "..\lib\figures.h"
  12.  
  13. #include "..\lib\lib.obj\libio_lib.h"
  14. #include "..\lib\lib.obj\libimg_lib.h"
  15. #include "..\lib\lib.obj\libini.h"
  16.  
  17. #include "..\lib\patterns\libimg_load_skin.h"
  18.  
  19. system_colors sc;
  20. proc_info Form;
  21. mouse m;
  22.  
  23. byte kolibrios_mounted;
  24.  
  25. int item_id_need_to_run=-1,
  26.     current_item_id;
  27.  
  28. int window_width,
  29.     window_height;
  30.  
  31. int col_max,
  32.     cell_w,
  33.     cell_h,
  34.     list_pos,
  35.     list_top,
  36.     row,
  37.     old_row, //to detect empty sections
  38.     col,
  39.     default_icon;
  40.  
  41. char window_title[128],
  42.      settings_ini_path[256] = "/sys/settings/";
  43.  
  44. #define LIST_BACKGROUND_COLOR 0xF3F3F3
  45.  
  46. libimg_image skin;
  47.  
  48. void load_config()
  49. {
  50.         ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget");
  51.         ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690);
  52.         window_width = EAX;
  53.         ini_get_int stdcall (#settings_ini_path, "Config", "window_height", 540);
  54.         window_height = EAX;
  55.         ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 66);
  56.         cell_w = EAX;
  57.         ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 64);
  58.         cell_h = EAX;
  59.         ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0);
  60.         default_icon = EAX;
  61. }
  62.  
  63.  
  64. void main()
  65. {  
  66.         dword id, key;
  67.         mem_Init();
  68.         if (load_dll2(libio,  #libio_init,1)!=0) notify("Error: library doesn't exists - libio");
  69.         if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg");
  70.         if (load_dll2(libini, #lib_init,1)!=0) notify("Error: library doesn't exists - libini");
  71.  
  72.         Libimg_LoadImage(#skin, "/sys/icons32.png");
  73.         Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR);
  74.  
  75.         if (param)
  76.         {
  77.                 strcpy(#settings_ini_path, #param);
  78.         }
  79.         else
  80.         {
  81.                 strcat(#settings_ini_path, #program_path + strrchr(#program_path, '/'));
  82.                 strcat(#settings_ini_path, ".ini");            
  83.         }
  84.         load_config();
  85.  
  86.         loop()
  87.         {
  88.       switch(WaitEvent())
  89.       {
  90.          case evButton:
  91.             id=GetButtonID();              
  92.             if (id==1) ExitProcess();
  93.             if (id>=100)
  94.             {
  95.                 item_id_need_to_run = id - 100;
  96.                 current_item_id = 0;
  97.                 ini_enum_sections stdcall (#settings_ini_path, #process_sections);
  98.                 item_id_need_to_run = -1;
  99.             }
  100.                         break;
  101.  
  102.          case evReDraw:
  103.                         sc.get();
  104.                         DefineAndDrawWindow(GetScreenWidth()-window_width/2,GetScreenHeight()-window_height/2,window_width,window_height,0x74,sc.work,"");
  105.                         GetProcessInfo(#Form, SelfInfo);
  106.                         if (Form.status_window>2) { DrawTitle(#window_title); break; } else DrawTitle("");
  107.                         kolibrios_mounted = isdir("/kolibrios");
  108.                         col_max = Form.cwidth - 10 / cell_w;
  109.                         current_item_id = 0;
  110.                         draw_top_bar();
  111.                         ini_enum_sections stdcall (#settings_ini_path, #process_sections);
  112.                         DrawBar(0, row + 1 * cell_h + list_pos, Form.cwidth, -row - 1 * cell_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR);
  113.                         break;
  114.       }
  115.         }
  116. }
  117.  
  118. byte search_for_id_need_to_run(dword key_value, key_name, sec_name, f_name)
  119. {
  120.         int icon_char_pos;
  121.         if (item_id_need_to_run == current_item_id)
  122.         {
  123.                 icon_char_pos = strchr(key_value, ',');
  124.                 if (icon_char_pos) ESBYTE[key_value + icon_char_pos - 1] = 0; //delete icon from string
  125.                 RunProgram(key_value, "");
  126.         }
  127.         current_item_id++;
  128.         if (strncmp(key_value, "/kolibrios/", 11)==0) && (!kolibrios_mounted) current_item_id--;
  129.         return 1;
  130. }
  131.  
  132.  
  133. byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
  134. {
  135.         int tmp,
  136.             icon_id,
  137.             icon_char_pos;
  138.  
  139.         if (col==col_max) {
  140.                 row++;
  141.                 col=0;
  142.         }
  143.  
  144.         //do not show items located in /kolibrios/ if this directory not mounted
  145.         if (strncmp(key_value, "/kolibrios/", 11)==0) && (!kolibrios_mounted) return 1;
  146.  
  147.         if (col==0) DrawBar(0, row * cell_h + list_pos, Form.cwidth, cell_h, LIST_BACKGROUND_COLOR);
  148.         DefineButton(col*cell_w+6,row*cell_h + list_pos,cell_w,cell_h-5,current_item_id + 100 + BT_HIDE,0);
  149.         tmp = cell_w/2;
  150.  
  151.         icon_char_pos = strchr(key_value, ',');
  152.         if (icon_char_pos) icon_id = atoi(key_value + icon_char_pos); else icon_id = default_icon;
  153.         img_draw stdcall(skin.image, col*cell_w+tmp-10, row*cell_h+5 + list_pos, 32, 32, 0, icon_id*32);
  154.         WriteTextCenter(col*cell_w+7,row*cell_h+47 + list_pos,cell_w,0xDCDCDC,key_name);
  155.         WriteTextCenter(col*cell_w+6,row*cell_h+46 + list_pos,cell_w,0x000000,key_name);
  156.         current_item_id++;
  157.         col++;
  158.         return 1;
  159. }
  160.  
  161.  
  162. byte process_sections(dword sec_name, f_name)
  163. {
  164.         if (strcmp(sec_name, "Config")==0) return 1;
  165.  
  166.         if (item_id_need_to_run!=-1)
  167.         {
  168.                 ini_enum_keys stdcall (f_name, sec_name, #search_for_id_need_to_run);
  169.         }
  170.         else
  171.         {
  172.                 if ((col==0) && (row==old_row))
  173.                 {
  174.                         list_pos -= 20;
  175.                 }
  176.                 else
  177.                 {
  178.                         row++;
  179.                 }
  180.                 col = 0;
  181.                 old_row = row;
  182.                 DrawBar(0, row * cell_h + list_pos, Form.cwidth , 20, LIST_BACKGROUND_COLOR);
  183.                 WriteTextB(10, row * cell_h + 9 + list_pos, 0x90, 0x000000, sec_name);
  184.                 list_pos += 20;
  185.                 ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
  186.         }
  187.         return 1;
  188. }
  189.  
  190. void draw_top_bar()
  191. {
  192.         int top_position = 25;
  193.         DrawBar(0,0,Form.cwidth, top_position-1, sc.work);
  194.         DrawBar(0,top_position-1, Form.cwidth, 1, sc.work_graph);
  195.         WriteTextB(Form.cwidth/2-70, 9, 0x90, sc.work_text, #window_title);
  196.         list_top = top_position;
  197.         list_pos = list_top;
  198.         row = -1;
  199. }
  200.  
  201.  
  202.  
  203. stop:
  204.