Subversion Repositories Kolibri OS

Rev

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

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