home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd2.bin / suse / inst-sys / lib / YaST2 / clients / inst_video_data.ycp < prev    next >
Encoding:
Text File  |  2000-03-30  |  17.3 KB  |  566 lines

  1. /**
  2.  *
  3.  * $Id: inst_video_data.ycp,v 1.23 2000/03/10 16:15:25 kkaempf Exp $
  4.  *
  5.  * Module:        inst_video_data.ycp      
  6.  *
  7.  * Author:        Stefan Hundhammer <sh@suse.de>
  8.  *            Stefan Schubert <schubi@suse.de>
  9.  *
  10.  * Purpose:        Prompt the user for monitor data
  11.  *            after auto-probing the monitor failed:
  12.  *            Let the user choose monitor vendor and type.
  13.  *            Optionally let him input monitor horizontal
  14.  *            and vertical frequencies.
  15.  *            Optionally read a monitor driver floppy
  16.  *            (originally intended for MS Windows).
  17.  *
  18.  * user_settings:    monitor
  19.  *                      monitor_auto_probed
  20.  *
  21.  */
  22. {
  23.   boolean test_mode    = lookup ( user_settings, "test_mode", false );
  24.   string current_vendor = "";
  25.   
  26.   // Get a list of all monitor models from the specified vendor.
  27.   // Returns a list of strings.
  28.   
  29.   define select_models( string vendor ) ``{
  30.       list vendor_monitors = filter( `monitor, all_monitors, ``(lookup(monitor, `vendor) == vendor) );
  31.       return toset( maplist( `monitor, vendor_monitors, ``lookup(monitor, `model) ) );
  32.   };
  33.  
  34.  
  35.   // Check if the numer is in the format [+]<number>[kKmMgGtT]
  36.   // Returns true or false
  37.   define IsNumber( string input )
  38.       ``{
  39.          integer n = 0;
  40.          while (n < size(input))
  41.          {
  42.             string erg = filterchars(substring(input, n,1), "0123456789.");
  43.             _debug( erg);
  44.             
  45.             if (size(erg) != 1)
  46.             {
  47.              _debug(n);
  48.              return(false);
  49.             }
  50.             n = n + 1;
  51.          }
  52.          
  53.          return(true);
  54.   };
  55.  
  56.   //
  57.   // Checking, if the monitor support the resolution which xr
  58.   // returns.
  59.   //
  60.  
  61.   define resolutionSupported(integer width,integer height) ``{
  62.       boolean entryFound = false;
  63.       list monitor_list = SCR(`Read(.probe.byclass.monitor));
  64.       if ( size(monitor_list) > 0 )
  65.       {
  66.       map|void monitor = select (monitor_list, 0);
  67.  
  68.       if ( is(monitor,map)) 
  69.       {
  70.           map resource =  lookup( monitor, "resource", $[] );
  71.           list resolutionList = lookup( resource, "monitor_resol" , [] );
  72.           
  73.           foreach ( `monitor_resolution, resolutionList, ``{
  74.         // check if the resolution is supported
  75.                  if ( width <= lookup ( monitor_resolution, "width",0 ) &&
  76.              height <= lookup ( monitor_resolution, "height",0 ) )
  77.         {
  78.             entryFound = true;
  79.         }
  80.           });
  81.       }
  82.       }
  83.       if ( !entryFound )
  84.       {
  85.     y2log(.milestone, "inst_video_data",
  86.           3,
  87.           sformat("resolution %1:%2 not found in probed monitor-data",
  88.           width, height ));
  89.       }
  90.  
  91.       return entryFound;
  92.   };
  93.  
  94.   
  95.   //
  96.   // Adding monitor-resolutions, color-depth to the monitor-data
  97.   //
  98.  
  99.   define evaluateResolution( map monitor, boolean check ) ``{
  100.  
  101.       map resource =  lookup( monitor, "resource", $[] );
  102.       list resolution = lookup( resource, "monitor_resol" , [] );
  103.       integer xresult = 0;
  104.  
  105.       // Calling script xr to get resolution and color-depth
  106.       xresult = Shell("y2xr -s  $SERVER -c 8,16,24,32 >/tmp/xr.ycp",
  107.               $[ "SERVER" : lookup(user_settings, "xservername", "XF86_SVGA") ] );
  108.       if (xresult == 0) 
  109.       {
  110.       map output = Read ( "/tmp/xr.ycp" );
  111.  
  112.       foreach ( `color, `resolutions, output,
  113.             ``{
  114.         foreach ( `cu_resolution, resolutions,
  115.            ``{
  116.             integer height = 0;
  117.             integer width = 0;
  118.             map res = $[];
  119.  
  120.             if ( cu_resolution == 1 )
  121.             {
  122.                 width = 640;
  123.                 height = 480;
  124.             } else if ( cu_resolution == 2 )
  125.             {
  126.                 width = 800;
  127.                 height = 600;
  128.             } else if ( cu_resolution == 3 )
  129.             {
  130.                 width = 1024;
  131.                 height = 768;
  132.             } else if ( cu_resolution == 4 )
  133.             {
  134.                 width = 1152;
  135.                 height = 864;
  136.             } else if ( cu_resolution == 5 )
  137.             {
  138.                 width = 1280;
  139.                 height = 960;
  140.             } else if ( cu_resolution == 6 )
  141.             {
  142.                 width = 1280;
  143.                 height = 1024;
  144.             } else if ( cu_resolution == 7 )
  145.             {
  146.                 width = 1600;
  147.                 height = 1200;
  148.             }
  149.             if ( !check ||
  150.                  resolutionSupported(width,height) )
  151.             {
  152.                 res = add ( res, "height", height );
  153.                 res = add ( res, "width", width );
  154.                 res = add ( res, "color", color );
  155.                 resolution = add ( resolution, res );
  156.             }
  157.             });
  158.         });    
  159.           resolution = toset ( resolution );
  160.       resource = add( resource, "monitor_resol", resolution );
  161.       monitor = add ( monitor, "resource", resource );
  162.       }
  163.       else
  164.       {
  165.           y2log(.warning, "inst_video_data", 1, "Calling script xr failed");
  166.       }
  167.  
  168.       return( monitor );
  169.   };
  170.  
  171.  
  172.   // Check, if there was found the monitor by probing
  173.   list monitor_list = SCR(`Read(.probe.byclass.monitor));
  174.   if ( size(monitor_list) > 0 )
  175.   {
  176.        map|void monitor = select (monitor_list, 0);
  177.  
  178.        if ( is(monitor,map)) 
  179.        {
  180.         // Monitor found --> save into user_settings and return 
  181.         // to the next frame
  182.         monitor =evaluateResolution( monitor, true );
  183.         user_settings = add(user_settings, "monitor", monitor);
  184.         user_settings = add(user_settings, "monitor_auto_probed", true);
  185.         y2log(.milestone, "inst_video_data",
  186.           1,
  187.           sformat("Monitor settings: %1: monitor_auto_probed = true",
  188.           monitor ));    
  189.         return `next;
  190.     }
  191.   }
  192.  
  193.   // No probed data found ==> manual configuration
  194.   user_settings = add(user_settings, "monitor_auto_probed", false);
  195.  
  196.   map map_monitor = lookup ( user_settings, "monitor", $[] );
  197.   map map_display = lookup ( map_monitor, "display", $[] );
  198.   string vendor = lookup ( map_monitor, "vendor", "" );
  199.   string model = lookup ( map_monitor, "device", "" );
  200.  
  201.   integer|float hsync_min = lookup ( map_display, "hsync_min", 0 );
  202.   integer|float hsync_max = lookup ( map_display, "hsync_max", 0 );
  203.   integer|float vsync_min = lookup ( map_display, "vsync_min", 0 );
  204.   integer|float vsync_max = lookup ( map_display, "vsync_max", 0 );
  205.  
  206.  
  207.   
  208.   // Read the monitor description file in $YAST2HOME -
  209.   // a list of records like this:
  210.   //    
  211.   //      $[
  212.   //           vendor:        "EIZO",
  213.   //           model:        "F563-T",
  214.   //           hsync_min:    55.5,
  215.   //           hsync_max:    160,
  216.   //           vsync_min:    30.5,
  217.   //           vsync_max:    86
  218.   //       ]
  219.  
  220.   list all_monitors = ReadY2 ( "monitors.ycp" );
  221.  
  222.   // Special monitor list entry for users who don't want to install X11 at all
  223.   list vendors = flatten( [ [ `item( `id("No X11"), UI( _( "No X11" ) ) ) ],
  224.               toset( maplist( `monitor, all_monitors, ``lookup(monitor, `vendor) ) ) ] );
  225.   y2log( .debug, "inst_video_data", 1, sformat("Vendors 1: %1", vendors ));
  226.  
  227.   
  228.   // Build the wizard windows contents:
  229.   //
  230.   // Two selection boxes (one for monitor vendors, one for the monitor
  231.   // models belonging to the currently selected vendor,
  232.   // input fields for hsync and vsync (min and max each)
  233.   // and a push button to import monitor data from a floppy.
  234.   
  235.   term contents =
  236.       `VBox(
  237.         `HBox(
  238.           `ReplacePoint( `id(`replace_point_vendors), 
  239.                  `SelectionBox( `id(`vendors), `opt(`notify, `immediate), 
  240.                         // Headline for monitor vendor selection box
  241.                         _( "Vendor" ),
  242.                         vendors
  243.                         )
  244.                  ),
  245.           `ReplacePoint( `id(`replace_point_models), 
  246.                  `SelectionBox( `id(`models), `opt(`notify, `immediate), 
  247.                         // Headline for monitor model selection box
  248.                         _( "Model" )
  249.                         // , select_models(" VESA")
  250.                         )
  251.                  )
  252.           ),
  253.         `VSquash(
  254.              `HBox(
  255.                `HWeight( 40,
  256.                      `Frame(
  257.                         // Frame title for horizontal frequency input fields
  258.                         _( "Horizontal frequency" ),
  259.                         `HBox(
  260.                           `HWeight( 50, `TextEntry( `id(`hsync_min ), `opt(`shrinkable), _( "min" ) ) ),
  261.  
  262.                           // Separator between min and max frequency fields
  263.                           `HWeight( 20, `Bottom(`Label( _("-") ) ) ),
  264.                           `HWeight( 50, `TextEntry( `id(`hsync_max ), `opt(`shrinkable), _( "max" ) ) ),
  265.  
  266.                           // Unit for horizontal frequency
  267.                           `HWeight( 20, `Bottom(`Label( _("kHz") ) ) )
  268.                           )
  269.                         )
  270.                      ),
  271.                `HWeight( 40,
  272.                      `Frame(
  273.                         // Frame title for vertical frequency input fields
  274.                         _( "Vertical frequency" ),
  275.                         `HBox(
  276.                           `HWeight( 50, `TextEntry( `id(`vsync_min ), `opt(`shrinkable), _( "min" ) ) ),
  277.  
  278.                           // Separator between min and max frequency fields
  279.                           `HWeight( 20, `Bottom(`Label( _("-") ) ) ),
  280.                           `HWeight( 50, `TextEntry( `id(`vsync_max ), `opt(`shrinkable), _( "max" ) ) ),
  281.  
  282.                           // Unit for horizontal frequency
  283.                           `HWeight( 20, `Bottom( `Label( _("Hz") ) ) )
  284.                           )
  285.                         )
  286.                      )
  287.                )
  288.              ),
  289.         // Push button for monitor driver disk
  290.         `HWeight( 20, `PushButton( `id(`driver_disk), _( "Driver disk" ) ) )
  291.         );
  292.  
  293.   // help text for monitor configuration dialog
  294.   // help part 1 of 7
  295.   string helptext = UI(_("<p>
  296. The type of your monitor could not be determined automatically.
  297. Please select your monitor's <b>vendor</b> and <b>model</b>.
  298. </p>
  299.  
  300. <p>
  301. If your monitor is not listed here, use <b>VESA</b>
  302. - most monitors comply to that standard.
  303. </p>"));
  304.  
  305.   // help part 2 of 7
  306.   helptext = helptext + UI(_("<p>
  307. You can use a monitor <b>driver disk</b> to import the monitor's
  308. technical data. Notice that you do not need a special Linux monitor
  309. driver disk; most common monitor driver disks will do. Just try the
  310. floppy that came with your monitor.
  311. </p>"));
  312.  
  313.    // help part 3 of 7
  314.    helptext = helptext + UI(_("<p>
  315. If you do not wish to use the X Window System (X11), select
  316. <b>no X11</b>.
  317. </p>"));
  318.  
  319.    // help part 4 of 7
  320.    helptext = helptext + UI(_("<p>
  321. You can modify the monitor's frequencies in the respective input
  322. fields below the selection boxes.
  323. Refer to your monitor manual for your monitor's maximum
  324. frequencies. <b><i>Do not exceed</i></b> the values specified there -
  325. otherwise, there is a serious risk of <b><i>damaging your monitor</i></b>.
  326. </p>"));
  327.  
  328.    // help part 5 of 7
  329.    helptext = helptext + UI(_("<p>
  330. The <b>horizontal frequency</b> (in kHz) specifies how many times
  331. per second the monitor can write a horizontal scan line. This is a
  332. hard limit of the monitor independent of the screen resolution.
  333. </p>"));
  334.  
  335.    // help part 6 of 7
  336.    helptext = helptext + UI(_("<p>
  337. The <b>vertical frequency</b> (in Hz) specifies how often in a second the
  338. image on the screen is refreshed. This value depends on the screen
  339. resolution and the monitor's maximum horizontal frequency.  
  340. </p>"));
  341.  
  342.    // help part 7 of 7
  343.    helptext = helptext + UI(_("<p>
  344. If you experience a constant high frequency beep from your monitor,
  345. you might wish to use slightly lower frequency values than the maximum 
  346. specified in your monitor's manual. This usually helps a lot to reduce
  347. the noise.
  348. </p>
  349. "));
  350.    
  351.   UI(`SetWizardContents(
  352.             // Title for monitor configuration dialog:
  353.             // The user is prompted for vendor and model of his monitor.
  354.             // He also has the option of entering video frequencies
  355.             // or using a monitor driver disk.
  356.             _("Configure Monitor"),
  357.             contents,
  358.             helptext,
  359.             Args(0), Args(1)));
  360.  
  361.   if ( vendor != nil && vendor != "" )
  362.   {
  363.      // setting selected values
  364.      // UI(`ChangeWidget(`id(`vendors), `CurrentItem, vendor));
  365.     _debug ("Change Widget does not work --> CORE ", vendor );
  366.   }
  367.   if ( model != nil && model != "" )
  368.   {
  369.      // setting selected values
  370.      //UI(`ChangeWidget(`id(`models), `CurrentItem, model));
  371.      _debug ("ChangeWidget does not work ---> CORE ", model );
  372.   }
  373.  
  374.   any ret = nil;
  375.  
  376.   repeat {
  377.       ret = UI( `UserInput() );
  378.       
  379.       if ( ret == `vendors )    // New monitor vendor selected
  380.       {
  381.       // Get the currently selected monitor vendor
  382.       
  383.       current_vendor = UI(`QueryWidget(`id(`vendors), `CurrentItem));
  384.  
  385.  
  386.       // Replace the monitor model list with this vendor's monitors
  387.       //
  388.       // Workaround for UI limitation: Currently, a SelectionBox's items cannot be replaced,
  389.       // so we have to replace the entire SelectionBox. This will be changed in due course.
  390.       
  391.       UI( `ReplaceWidget( `id( `replace_point_models),
  392.                   `SelectionBox( `id( `models),
  393.                          `opt( `notify, `immediate),
  394.                          
  395.                          // Headline for monitor model selection box
  396.                          _( "Model" ),
  397.                          select_models(current_vendor)
  398.                          )
  399.                   )
  400.           );
  401.       }
  402.       else if ( ret == `models )    // New monitor model selected
  403.       {
  404.       // Get the currently selected monitor vendor and model
  405.       
  406.       current_vendor = UI( `QueryWidget(`id(`vendors), `CurrentItem) );
  407.       string current_model  = UI( `QueryWidget(`id(`models),  `CurrentItem) );
  408.  
  409.  
  410.       // Get the data record for this monitor
  411.       
  412.       map monitor = find( `monitor, all_monitors,
  413.                   ``( lookup( monitor, `vendor ) == current_vendor && lookup( monitor, `model ) == current_model ) );
  414.  
  415.       // Set all the input fields according to this monitor's data
  416.  
  417.       define printnum(integer i) ``("" + i);
  418.       define printnum(float f) ``(tostring(f, 1));
  419.       
  420.       foreach( `freq,
  421.            [ `hsync_min, `hsync_max, `vsync_min, `vsync_max ], 
  422.           ``UI( `ChangeWidget( `id( freq ), `Value, printnum(lookup( monitor, freq ) ) ) ) // TODO: implement and use tostring()
  423.            );
  424.       }
  425.       else if ( ret == `driver_disk ) // get monitor data from M$ drivers floppy
  426.       {
  427.       integer doresult = 0;
  428.  
  429.       UI(`DisplayMessage(_("Please insert a drivers floppy and confirm with 'OK'.")));
  430.  
  431.       doresult = Shell("mount /dev/fd0 /floppy -t msdos");   // mount floppy
  432.  
  433.  
  434.       if ( doresult != 0 )
  435.       {
  436.           UI(`DisplayMessage(_("Drivers disk could not be mounted")));
  437.       }
  438.       else
  439.       {
  440.           list directory = Dir("/floppy");   // get directory from floppy
  441.           // get all files from floppy ending with .inf
  442.           list files = filter(`file, directory, ``(substring(file, size(file)-4) == ".inf"));
  443.  
  444.           if (!is(files, list) || files == [])
  445.           {
  446.           UI(`DisplayMessage(_("No monitor information file found on this disk")));
  447.           }
  448.           else
  449.           {
  450.           // from this list take the first one
  451.           string convert_it = "/usr/bin/perl /lib/YaST2/bin/pars-inf.pl < /floppy/" + select(files, 0) + " > /tmp/monitors.ycp";
  452.           _debug ("Conversion M$ --> ycp: ", convert_it );
  453.  
  454.           Shell(convert_it);   // convert M$ to ycp
  455.  
  456.           all_monitors = Read( "/tmp/monitors.ycp" );
  457.           _debug ("all_monitors: ", all_monitors );
  458.  
  459.           // Special monitor list entry for users who don't want to install X11 at all
  460.           vendors = flatten( [ [ `item( `id("No X11"), UI( _( "No X11" ) ) ) ],
  461.                      toset( maplist( `monitor, all_monitors, ``lookup(monitor, `vendor) ) ) ] );
  462.       
  463.           //YYYY list disk_monitors = toset( maplist( `monitor, all_monitors, ``lookup(monitor, `model) ) );
  464.       
  465.           // Replace the selection boxes
  466.           //
  467.           // Workaround for UI limitation: Currently, a SelectionBox's items cannot be replaced,
  468.           // so we have to replace the entire SelectionBox. This will be changed in due course.
  469.       
  470.           UI( `ReplaceWidget( `id( `replace_point_vendors),
  471.                       `SelectionBox( `id(`vendors), `opt(`notify, `immediate), 
  472.                              // Headline for monitor vendor selection box
  473.                              _( "Vendor" ),
  474.                              vendors
  475.                              )
  476.                       )
  477.               );
  478.  
  479.           UI( `ReplaceWidget( `id( `replace_point_models),
  480.                       `SelectionBox( `id( `models),
  481.                              `opt( `notify, `immediate),
  482.                          
  483.                              // Headline for monitor model selection box
  484.                              _( "Model" ),
  485.                              []
  486.                              )
  487.                       )
  488.               );
  489.           }
  490.       }
  491.       
  492.       Shell("umount /floppy");   // umount floppy
  493.       }
  494.       else if ( ret == `next && current_vendor != "No X11" ) // other input
  495.       {
  496.       // check input
  497.           string dummy = UI(`QueryWidget(`id(`hsync_min), `Value));
  498.  
  499.       if ( ! test_mode )
  500.       {
  501.           if ( !IsNumber( dummy ) || size ( dummy ) <= 0)
  502.           {
  503.           UI(`DisplayMessage(_("Minimal horizontal frequency is not a numerical value.\nPlease try again.")));
  504.           // TODO: SetFocus()));
  505.           continue;
  506.           }
  507.           dummy = UI(`QueryWidget(`id(`hsync_max), `Value));
  508.           if ( !IsNumber ( dummy ) || size ( dummy ) <= 0)
  509.           {
  510.           UI(`DisplayMessage(_("Maximal horizontal frequency is not a numerical value.\nPlease try again.")));
  511.           // TODO: SetFocus()));
  512.           continue;
  513.           }
  514.           dummy = UI(`QueryWidget(`id(`vsync_min), `Value));
  515.           if ( !IsNumber ( dummy ) || size ( dummy ) <= 0)
  516.           {
  517.           UI(`DisplayMessage(_("Minimal vertical frequency is not a numerical value.\nPlease try again.")));
  518.           // TODO: SetFocus()));
  519.           continue;
  520.           }
  521.           dummy = UI(`QueryWidget(`id(`vsync_max), `Value));
  522.           if ( !IsNumber ( dummy ) || size ( dummy ) <= 0)
  523.           {
  524.           UI(`DisplayMessage(_("Maximal vertical frequency is not a numerical value.\nPlease try again.")));
  525.           // TODO: SetFocus()));
  526.           continue;
  527.           }
  528.       }
  529.       }
  530.   } until (ret == `next || ret == `back);
  531.  
  532.  
  533.   if ( ( ret == `next || ret == `back ) && current_vendor != "No X11" )
  534.   {
  535.     // Save selected monitor in the user_setttings.monitor
  536.     vendor = UI( `QueryWidget(`id(`vendors), `CurrentItem) );
  537.     model  = UI( `QueryWidget(`id(`models),  `CurrentItem) );
  538.     hsync_min = tointeger ( UI(`QueryWidget(`id(`hsync_min), `Value)) );
  539.         hsync_max = tointeger (     UI(`QueryWidget(`id(`hsync_max), `Value)) );
  540.     vsync_min = tointeger (     UI(`QueryWidget(`id(`vsync_min), `Value)) );
  541.     vsync_max = tointeger (     UI(`QueryWidget(`id(`vsync_max), `Value)) );
  542.  
  543.         map map_display = $[];
  544.     map_display = add( map_display, "hsync_min", hsync_min );
  545.     map_display = add( map_display, "hsync_max", hsync_max );
  546.     map_display = add( map_display, "vsync_max", vsync_max );
  547.     map_display = add( map_display, "vsync_min", vsync_min );
  548.  
  549.     map_monitor = $[];
  550.     map_monitor = add( map_monitor, "display", map_display );
  551.     map_monitor = add( map_monitor, "device", model );
  552.     map_monitor = add( map_monitor, "vendor", vendor );
  553.  
  554.     map monitor = evaluateResolution( map_monitor, false );
  555.     user_settings = add( user_settings, "monitor", monitor );
  556.     y2log(.milestone, "inst_video_data",
  557.           2,
  558.           sformat("Monitor settings: %1: monitor_auto_probed = false",
  559.           monitor ));    
  560.   }
  561.  
  562.   if ( current_vendor == "No X11" ) ret = `no_x11;
  563.   
  564.   return ret;
  565. }
  566.