Subversion Repositories Kolibri OS

Rev

Rev 9602 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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