Subversion Repositories Kolibri OS

Rev

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