Subversion Repositories Kolibri OS

Rev

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

  1. /*
  2. SOFTWARE CENTER v2.85
  3. */
  4.  
  5. #define MEMSIZE 4096 * 15
  6. #include "..\lib\strings.h"
  7. #include "..\lib\mem.h"
  8. #include "..\lib\io.h"
  9. #include "..\lib\gui.h"
  10.  
  11. #include "..\lib\obj\libio.h"
  12. #include "..\lib\obj\libimg.h"
  13. #include "..\lib\obj\libini.h"
  14. #include "..\lib\kfont.h"
  15. #include "..\lib\list_box.h"
  16. #include "..\lib\collection.h"
  17.  
  18. proc_info Form;
  19. llist list;
  20. collection app_path_collection;
  21. byte kolibrios_mounted;
  22.  
  23. int window_width,
  24.         window_height;
  25.  
  26. int list_pos,
  27.         row,
  28.         col,
  29.         default_icon;
  30.  
  31. char window_title[128],
  32.          settings_ini_path[256] = "/sys/settings/";
  33.  
  34. bool small_screen = false;
  35.  
  36. #define LIST_BACKGROUND_COLOR 0xF3F3F3
  37.  
  38. block ipos[128];
  39.  
  40. void load_config()
  41. {
  42.         ini_get_str stdcall (#settings_ini_path, "Config", "window_title", #window_title, sizeof(window_title), "Software widget");
  43.         ini_get_int stdcall (#settings_ini_path, "Config", "window_width", 690);
  44.         window_width = EAX;
  45.         ini_get_int stdcall (#settings_ini_path, "Config", "cell_w", 73);
  46.         list.item_w = EAX;
  47.         ini_get_int stdcall (#settings_ini_path, "Config", "cell_h", 71);
  48.         list.item_h = EAX;
  49.         ini_get_int stdcall (#settings_ini_path, "Config", "default_icon", 0);
  50.         default_icon = EAX;
  51. }
  52.  
  53.  
  54. void main()
  55. {  
  56.         dword id;
  57.         kfont.init(DEFAULT_FONT);
  58.         load_dll(libio,  #libio_init,1);
  59.         load_dll(libimg, #libimg_init,1);
  60.         load_dll(libini, #lib_init,1);
  61.  
  62.         Libimg_LoadImage(#skin, "/sys/icons32.png");
  63.         Libimg_FillTransparent(skin.image, skin.w, skin.h, LIST_BACKGROUND_COLOR);
  64.         kolibrios_mounted = dir_exists("/kolibrios");
  65.  
  66.         if (param)
  67.         {
  68.                 strcpy(#settings_ini_path, #param);
  69.         }
  70.         else
  71.         {
  72.                 strcat(#settings_ini_path, I_Path + strrchr(I_Path, '/'));
  73.                 strcat(#settings_ini_path, ".ini");            
  74.         }
  75.        
  76.         load_config();
  77.         list.cur_y = -1;
  78.         list.y = 32;
  79.  
  80.         DrawList();
  81.         window_height = row+1*list.item_h + list_pos + skin_height + 15;
  82.         if (window_height>screen.height) {
  83.                 window_width = screen.width;
  84.                 list.item_h -= 5;
  85.                 window_height = row+1*list.item_h + list_pos + skin_height + 15;
  86.                 small_screen = true;
  87.         }
  88.  
  89.         loop() switch(WaitEvent())
  90.         {
  91.                 case evKey:
  92.                         GetKeys();
  93.                         if (SCAN_CODE_LEFT == key_scancode) key_scancode = SCAN_CODE_UP;
  94.                         if (SCAN_CODE_RIGHT == key_scancode) key_scancode = SCAN_CODE_DOWN;
  95.                         if (list.ProcessKey(key_scancode)) DrawSelection();
  96.                         if (SCAN_CODE_ENTER == key_scancode) EventRunApp(list.cur_y);
  97.                         break;
  98.  
  99.                 case evButton:
  100.                         id=GetButtonID();              
  101.                         if (id==1) ExitProcess();
  102.                         if (id>=100) EventRunApp(id-100);
  103.                         break;
  104.  
  105.                 case evReDraw:
  106.                         system.color.get();
  107.                         DefineAndDrawWindow(screen.width-window_width/2,screen.height-window_height/2,window_width,window_height,0x74,system.color.work,"",0);
  108.                         GetProcessInfo(#Form, SelfInfo);
  109.                         if (Form.status_window>2) {
  110.                                 DrawTitle(#window_title);
  111.                                 break;
  112.                         }
  113.                         if (small_screen) {
  114.                                 DrawTitle(#window_title);
  115.                                 list.y = 0;    
  116.                         } else {
  117.                                 DrawTitle(NULL);
  118.                                 draw_top_bar();
  119.                         }
  120.                         DrawList();
  121.                         DrawBar(0, row +1 * list.item_h + list_pos, Form.cwidth, -row - 1 * list.item_h - list_pos + Form.cheight, LIST_BACKGROUND_COLOR);
  122.                         DrawSelection();
  123.         }
  124. }
  125.  
  126. void DrawList() {
  127.         list.count = 0;
  128.         row = -1;
  129.         app_path_collection.drop();
  130.         list_pos = list.y;
  131.         list.column_max = window_width - 10 / list.item_w;
  132.         ini_enum_sections stdcall (#settings_ini_path, #process_sections);
  133.         list.visible = list.count;
  134. }
  135.  
  136. byte draw_icons_from_section(dword key_value, key_name, sec_name, f_name)
  137. {
  138.         int tmp,
  139.                 icon_id,
  140.                 icon_char_pos;
  141.         int text_w;
  142.  
  143.         //do not show items located in /kolibrios/ if this directory not mounted
  144.         if (!strncmp(key_value, "/kolibrios/", 11)) || (!strncmp(key_value, "/k/", 3))
  145.                 if (!kolibrios_mounted) return true;
  146.  
  147.         if (col==list.column_max) {
  148.                 row++;
  149.                 col=0;
  150.         }
  151.  
  152.         if (col==0) DrawBar(0, row * list.item_h + list_pos, Form.cwidth, list.item_h, LIST_BACKGROUND_COLOR);
  153.         DefineButton(col*list.item_w+6, row*list.item_h + list_pos,list.item_w,list.item_h-5,list.count + 100 + BT_HIDE,0);
  154.         tmp = list.item_w/2;
  155.  
  156.         icon_char_pos = strchr(key_value, ',');
  157.         if (icon_char_pos) icon_id = atoi(icon_char_pos+1); else icon_id = default_icon;
  158.         img_draw stdcall(skin.image, col*list.item_w+tmp-10, row*list.item_h+5 + list_pos, 32, 32, 0, icon_id*32);
  159.         if (icon_char_pos) ESBYTE[icon_char_pos] = '\0'; //delete icon from string
  160.         app_path_collection.add(key_value);
  161.         //kfont.WriteIntoWindowCenter(col*list.item_w+7,row*list.item_h+47 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0xDCDCDC, 12, key_name);
  162.         text_w = kfont.WriteIntoWindowCenter(col*list.item_w+5,row*list.item_h+46 + list_pos, list.item_w,0, LIST_BACKGROUND_COLOR, 0x000000, 12, key_name);
  163.         ipos[list.count].x = list.item_w-text_w/2+calc(col*list.item_w)+5;
  164.         ipos[list.count].y = row*list.item_h+46 + list_pos + 16;
  165.         ipos[list.count].w = text_w;
  166.         list.count++;
  167.         col++;
  168.         return true;
  169. }
  170.  
  171.  
  172. int old_row; //to detect empty sections
  173. byte process_sections(dword sec_name, f_name)
  174. {
  175.         int text_len;
  176.         if (!strcmp(sec_name, "Config")) return true;
  177.  
  178.         if ((col==0) && (row==old_row))
  179.         {
  180.                 list_pos -= 28;
  181.         }
  182.         else
  183.         {
  184.                 row++;
  185.         }
  186.         col = 0;
  187.         old_row = row;
  188.  
  189.         if (!small_screen) {
  190.                 DrawBar(0, row * list.item_h + list_pos, Form.cwidth , 29, LIST_BACKGROUND_COLOR);
  191.                 text_len = kfont.WriteIntoWindow(10, row * list.item_h + 10 + list_pos, LIST_BACKGROUND_COLOR, 0, 15, sec_name);
  192.                 DrawBar(text_len+20, row * list.item_h + list_pos + 20, Form.cwidth-text_len-20, 1, 0xDCDCDC);
  193.                 DrawBar(text_len+20, row * list.item_h + list_pos + 21, Form.cwidth-text_len-20, 1, 0xFCFCFC);
  194.                 list_pos += 29;        
  195.         }
  196.         ini_enum_keys stdcall (f_name, sec_name, #draw_icons_from_section);
  197.         return true;
  198. }
  199.  
  200. void draw_top_bar()
  201. {
  202.         DrawBar(0,0,Form.cwidth, list.y-2, system.color.work);
  203.         DrawBar(0,list.y-2, Form.cwidth, 1, MixColors(system.color.work, system.color.work_graph, 180));
  204.         DrawBar(0,list.y-1, Form.cwidth, 1, system.color.work_graph);
  205.         kfont.WriteIntoWindowCenter(0,5, Form.cwidth, list.y, system.color.work, system.color.work_text, 16, #window_title);
  206. }
  207.  
  208. void EventRunApp(dword appid)
  209. {
  210.         char run_app_path[4096]=0;
  211.         dword app_path = app_path_collection.get(appid);
  212.         dword param_pos = strchr(app_path, '|');
  213.         if (param_pos) {
  214.                 ESBYTE[param_pos] = NULL;
  215.                 param_pos++;
  216.         }
  217.  
  218.         // the next block is created to save some space in ramdisk{
  219.         //
  220.         // convert relative path to absolute      "calc"    => "/sys/calc"
  221.         // convert short kolibrios path to full   "/k/calc" => "/kolibrios/calc"
  222.         // other copy => as is
  223.         if (ESBYTE[app_path]!='/') {
  224.                 strcpy(#run_app_path, "/sys/");
  225.         }
  226.         else if (!strncmp(app_path, "/k/",3)) {
  227.                 strcpy(#run_app_path, "/kolibrios/");
  228.                 app_path+=3;
  229.         }
  230.         strcat(#run_app_path, app_path);
  231.         // }end
  232.  
  233.         if (file_exists(#run_app_path))
  234.         {
  235.                 io.run(#run_app_path, param_pos); //0 or offset
  236.                 if (param_pos) ESBYTE[param_pos - 1] = '|';
  237.         }
  238.         else
  239.         {
  240.                 notify("'Application not found' -E");
  241.         }
  242. }
  243.  
  244. void DrawSelection()
  245. {
  246.         int i;
  247.         dword col;
  248.         for (i=0; i<list.count; i++) {
  249.                 if (i==list.cur_y) col=0x0080FF; else col=LIST_BACKGROUND_COLOR;
  250.                 DrawBar(ipos[i].x, ipos[i].y, ipos[i].w+2, 3, col);
  251.         }
  252. }
  253.  
  254.  
  255. stop:
  256.