home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * $Id: inst_video_data.ycp,v 1.23 2000/03/10 16:15:25 kkaempf Exp $
- *
- * Module: inst_video_data.ycp
- *
- * Author: Stefan Hundhammer <sh@suse.de>
- * Stefan Schubert <schubi@suse.de>
- *
- * Purpose: Prompt the user for monitor data
- * after auto-probing the monitor failed:
- * Let the user choose monitor vendor and type.
- * Optionally let him input monitor horizontal
- * and vertical frequencies.
- * Optionally read a monitor driver floppy
- * (originally intended for MS Windows).
- *
- * user_settings: monitor
- * monitor_auto_probed
- *
- */
- {
- boolean test_mode = lookup ( user_settings, "test_mode", false );
- string current_vendor = "";
-
- // Get a list of all monitor models from the specified vendor.
- // Returns a list of strings.
-
- define select_models( string vendor ) ``{
- list vendor_monitors = filter( `monitor, all_monitors, ``(lookup(monitor, `vendor) == vendor) );
- return toset( maplist( `monitor, vendor_monitors, ``lookup(monitor, `model) ) );
- };
-
-
- // Check if the numer is in the format [+]<number>[kKmMgGtT]
- // Returns true or false
- define IsNumber( string input )
- ``{
- integer n = 0;
- while (n < size(input))
- {
- string erg = filterchars(substring(input, n,1), "0123456789.");
- _debug( erg);
-
- if (size(erg) != 1)
- {
- _debug(n);
- return(false);
- }
- n = n + 1;
- }
-
- return(true);
- };
-
- //
- // Checking, if the monitor support the resolution which xr
- // returns.
- //
-
- define resolutionSupported(integer width,integer height) ``{
- boolean entryFound = false;
- list monitor_list = SCR(`Read(.probe.byclass.monitor));
- if ( size(monitor_list) > 0 )
- {
- map|void monitor = select (monitor_list, 0);
-
- if ( is(monitor,map))
- {
- map resource = lookup( monitor, "resource", $[] );
- list resolutionList = lookup( resource, "monitor_resol" , [] );
-
- foreach ( `monitor_resolution, resolutionList, ``{
- // check if the resolution is supported
- if ( width <= lookup ( monitor_resolution, "width",0 ) &&
- height <= lookup ( monitor_resolution, "height",0 ) )
- {
- entryFound = true;
- }
- });
- }
- }
- if ( !entryFound )
- {
- y2log(.milestone, "inst_video_data",
- 3,
- sformat("resolution %1:%2 not found in probed monitor-data",
- width, height ));
- }
-
- return entryFound;
- };
-
-
- //
- // Adding monitor-resolutions, color-depth to the monitor-data
- //
-
- define evaluateResolution( map monitor, boolean check ) ``{
-
- map resource = lookup( monitor, "resource", $[] );
- list resolution = lookup( resource, "monitor_resol" , [] );
- integer xresult = 0;
-
- // Calling script xr to get resolution and color-depth
- xresult = Shell("y2xr -s $SERVER -c 8,16,24,32 >/tmp/xr.ycp",
- $[ "SERVER" : lookup(user_settings, "xservername", "XF86_SVGA") ] );
- if (xresult == 0)
- {
- map output = Read ( "/tmp/xr.ycp" );
-
- foreach ( `color, `resolutions, output,
- ``{
- foreach ( `cu_resolution, resolutions,
- ``{
- integer height = 0;
- integer width = 0;
- map res = $[];
-
- if ( cu_resolution == 1 )
- {
- width = 640;
- height = 480;
- } else if ( cu_resolution == 2 )
- {
- width = 800;
- height = 600;
- } else if ( cu_resolution == 3 )
- {
- width = 1024;
- height = 768;
- } else if ( cu_resolution == 4 )
- {
- width = 1152;
- height = 864;
- } else if ( cu_resolution == 5 )
- {
- width = 1280;
- height = 960;
- } else if ( cu_resolution == 6 )
- {
- width = 1280;
- height = 1024;
- } else if ( cu_resolution == 7 )
- {
- width = 1600;
- height = 1200;
- }
- if ( !check ||
- resolutionSupported(width,height) )
- {
- res = add ( res, "height", height );
- res = add ( res, "width", width );
- res = add ( res, "color", color );
- resolution = add ( resolution, res );
- }
- });
- });
- resolution = toset ( resolution );
- resource = add( resource, "monitor_resol", resolution );
- monitor = add ( monitor, "resource", resource );
- }
- else
- {
- y2log(.warning, "inst_video_data", 1, "Calling script xr failed");
- }
-
- return( monitor );
- };
-
-
- // Check, if there was found the monitor by probing
- list monitor_list = SCR(`Read(.probe.byclass.monitor));
- if ( size(monitor_list) > 0 )
- {
- map|void monitor = select (monitor_list, 0);
-
- if ( is(monitor,map))
- {
- // Monitor found --> save into user_settings and return
- // to the next frame
- monitor =evaluateResolution( monitor, true );
- user_settings = add(user_settings, "monitor", monitor);
- user_settings = add(user_settings, "monitor_auto_probed", true);
- y2log(.milestone, "inst_video_data",
- 1,
- sformat("Monitor settings: %1: monitor_auto_probed = true",
- monitor ));
- return `next;
- }
- }
-
- // No probed data found ==> manual configuration
- user_settings = add(user_settings, "monitor_auto_probed", false);
-
- map map_monitor = lookup ( user_settings, "monitor", $[] );
- map map_display = lookup ( map_monitor, "display", $[] );
- string vendor = lookup ( map_monitor, "vendor", "" );
- string model = lookup ( map_monitor, "device", "" );
-
- integer|float hsync_min = lookup ( map_display, "hsync_min", 0 );
- integer|float hsync_max = lookup ( map_display, "hsync_max", 0 );
- integer|float vsync_min = lookup ( map_display, "vsync_min", 0 );
- integer|float vsync_max = lookup ( map_display, "vsync_max", 0 );
-
-
-
- // Read the monitor description file in $YAST2HOME -
- // a list of records like this:
- //
- // $[
- // vendor: "EIZO",
- // model: "F563-T",
- // hsync_min: 55.5,
- // hsync_max: 160,
- // vsync_min: 30.5,
- // vsync_max: 86
- // ]
-
- list all_monitors = ReadY2 ( "monitors.ycp" );
-
- // Special monitor list entry for users who don't want to install X11 at all
- list vendors = flatten( [ [ `item( `id("No X11"), UI( _( "No X11" ) ) ) ],
- toset( maplist( `monitor, all_monitors, ``lookup(monitor, `vendor) ) ) ] );
- y2log( .debug, "inst_video_data", 1, sformat("Vendors 1: %1", vendors ));
-
-
- // Build the wizard windows contents:
- //
- // Two selection boxes (one for monitor vendors, one for the monitor
- // models belonging to the currently selected vendor,
- // input fields for hsync and vsync (min and max each)
- // and a push button to import monitor data from a floppy.
-
- term contents =
- `VBox(
- `HBox(
- `ReplacePoint( `id(`replace_point_vendors),
- `SelectionBox( `id(`vendors), `opt(`notify, `immediate),
- // Headline for monitor vendor selection box
- _( "Vendor" ),
- vendors
- )
- ),
- `ReplacePoint( `id(`replace_point_models),
- `SelectionBox( `id(`models), `opt(`notify, `immediate),
- // Headline for monitor model selection box
- _( "Model" )
- // , select_models(" VESA")
- )
- )
- ),
- `VSquash(
- `HBox(
- `HWeight( 40,
- `Frame(
- // Frame title for horizontal frequency input fields
- _( "Horizontal frequency" ),
- `HBox(
- `HWeight( 50, `TextEntry( `id(`hsync_min ), `opt(`shrinkable), _( "min" ) ) ),
-
- // Separator between min and max frequency fields
- `HWeight( 20, `Bottom(`Label( _("-") ) ) ),
- `HWeight( 50, `TextEntry( `id(`hsync_max ), `opt(`shrinkable), _( "max" ) ) ),
-
- // Unit for horizontal frequency
- `HWeight( 20, `Bottom(`Label( _("kHz") ) ) )
- )
- )
- ),
- `HWeight( 40,
- `Frame(
- // Frame title for vertical frequency input fields
- _( "Vertical frequency" ),
- `HBox(
- `HWeight( 50, `TextEntry( `id(`vsync_min ), `opt(`shrinkable), _( "min" ) ) ),
-
- // Separator between min and max frequency fields
- `HWeight( 20, `Bottom(`Label( _("-") ) ) ),
- `HWeight( 50, `TextEntry( `id(`vsync_max ), `opt(`shrinkable), _( "max" ) ) ),
-
- // Unit for horizontal frequency
- `HWeight( 20, `Bottom( `Label( _("Hz") ) ) )
- )
- )
- )
- )
- ),
- // Push button for monitor driver disk
- `HWeight( 20, `PushButton( `id(`driver_disk), _( "Driver disk" ) ) )
- );
-
- // help text for monitor configuration dialog
- // help part 1 of 7
- string helptext = UI(_("<p>
- The type of your monitor could not be determined automatically.
- Please select your monitor's <b>vendor</b> and <b>model</b>.
- </p>
-
- <p>
- If your monitor is not listed here, use <b>VESA</b>
- - most monitors comply to that standard.
- </p>"));
-
- // help part 2 of 7
- helptext = helptext + UI(_("<p>
- You can use a monitor <b>driver disk</b> to import the monitor's
- technical data. Notice that you do not need a special Linux monitor
- driver disk; most common monitor driver disks will do. Just try the
- floppy that came with your monitor.
- </p>"));
-
- // help part 3 of 7
- helptext = helptext + UI(_("<p>
- If you do not wish to use the X Window System (X11), select
- <b>no X11</b>.
- </p>"));
-
- // help part 4 of 7
- helptext = helptext + UI(_("<p>
- You can modify the monitor's frequencies in the respective input
- fields below the selection boxes.
- Refer to your monitor manual for your monitor's maximum
- frequencies. <b><i>Do not exceed</i></b> the values specified there -
- otherwise, there is a serious risk of <b><i>damaging your monitor</i></b>.
- </p>"));
-
- // help part 5 of 7
- helptext = helptext + UI(_("<p>
- The <b>horizontal frequency</b> (in kHz) specifies how many times
- per second the monitor can write a horizontal scan line. This is a
- hard limit of the monitor independent of the screen resolution.
- </p>"));
-
- // help part 6 of 7
- helptext = helptext + UI(_("<p>
- The <b>vertical frequency</b> (in Hz) specifies how often in a second the
- image on the screen is refreshed. This value depends on the screen
- resolution and the monitor's maximum horizontal frequency.
- </p>"));
-
- // help part 7 of 7
- helptext = helptext + UI(_("<p>
- If you experience a constant high frequency beep from your monitor,
- you might wish to use slightly lower frequency values than the maximum
- specified in your monitor's manual. This usually helps a lot to reduce
- the noise.
- </p>
- "));
-
- UI(`SetWizardContents(
- // Title for monitor configuration dialog:
- // The user is prompted for vendor and model of his monitor.
- // He also has the option of entering video frequencies
- // or using a monitor driver disk.
- _("Configure Monitor"),
- contents,
- helptext,
- Args(0), Args(1)));
-
- if ( vendor != nil && vendor != "" )
- {
- // setting selected values
- // UI(`ChangeWidget(`id(`vendors), `CurrentItem, vendor));
- _debug ("Change Widget does not work --> CORE ", vendor );
- }
- if ( model != nil && model != "" )
- {
- // setting selected values
- //UI(`ChangeWidget(`id(`models), `CurrentItem, model));
- _debug ("ChangeWidget does not work ---> CORE ", model );
- }
-
- any ret = nil;
-
- repeat {
- ret = UI( `UserInput() );
-
- if ( ret == `vendors ) // New monitor vendor selected
- {
- // Get the currently selected monitor vendor
-
- current_vendor = UI(`QueryWidget(`id(`vendors), `CurrentItem));
-
-
- // Replace the monitor model list with this vendor's monitors
- //
- // Workaround for UI limitation: Currently, a SelectionBox's items cannot be replaced,
- // so we have to replace the entire SelectionBox. This will be changed in due course.
-
- UI( `ReplaceWidget( `id( `replace_point_models),
- `SelectionBox( `id( `models),
- `opt( `notify, `immediate),
-
- // Headline for monitor model selection box
- _( "Model" ),
- select_models(current_vendor)
- )
- )
- );
- }
- else if ( ret == `models ) // New monitor model selected
- {
- // Get the currently selected monitor vendor and model
-
- current_vendor = UI( `QueryWidget(`id(`vendors), `CurrentItem) );
- string current_model = UI( `QueryWidget(`id(`models), `CurrentItem) );
-
-
- // Get the data record for this monitor
-
- map monitor = find( `monitor, all_monitors,
- ``( lookup( monitor, `vendor ) == current_vendor && lookup( monitor, `model ) == current_model ) );
-
- // Set all the input fields according to this monitor's data
-
- define printnum(integer i) ``("" + i);
- define printnum(float f) ``(tostring(f, 1));
-
- foreach( `freq,
- [ `hsync_min, `hsync_max, `vsync_min, `vsync_max ],
- ``UI( `ChangeWidget( `id( freq ), `Value, printnum(lookup( monitor, freq ) ) ) ) // TODO: implement and use tostring()
- );
- }
- else if ( ret == `driver_disk ) // get monitor data from M$ drivers floppy
- {
- integer doresult = 0;
-
- UI(`DisplayMessage(_("Please insert a drivers floppy and confirm with 'OK'.")));
-
- doresult = Shell("mount /dev/fd0 /floppy -t msdos"); // mount floppy
-
-
- if ( doresult != 0 )
- {
- UI(`DisplayMessage(_("Drivers disk could not be mounted")));
- }
- else
- {
- list directory = Dir("/floppy"); // get directory from floppy
- // get all files from floppy ending with .inf
- list files = filter(`file, directory, ``(substring(file, size(file)-4) == ".inf"));
-
- if (!is(files, list) || files == [])
- {
- UI(`DisplayMessage(_("No monitor information file found on this disk")));
- }
- else
- {
- // from this list take the first one
- string convert_it = "/usr/bin/perl /lib/YaST2/bin/pars-inf.pl < /floppy/" + select(files, 0) + " > /tmp/monitors.ycp";
- _debug ("Conversion M$ --> ycp: ", convert_it );
-
- Shell(convert_it); // convert M$ to ycp
-
- all_monitors = Read( "/tmp/monitors.ycp" );
- _debug ("all_monitors: ", all_monitors );
-
- // Special monitor list entry for users who don't want to install X11 at all
- vendors = flatten( [ [ `item( `id("No X11"), UI( _( "No X11" ) ) ) ],
- toset( maplist( `monitor, all_monitors, ``lookup(monitor, `vendor) ) ) ] );
-
- //YYYY list disk_monitors = toset( maplist( `monitor, all_monitors, ``lookup(monitor, `model) ) );
-
- // Replace the selection boxes
- //
- // Workaround for UI limitation: Currently, a SelectionBox's items cannot be replaced,
- // so we have to replace the entire SelectionBox. This will be changed in due course.
-
- UI( `ReplaceWidget( `id( `replace_point_vendors),
- `SelectionBox( `id(`vendors), `opt(`notify, `immediate),
- // Headline for monitor vendor selection box
- _( "Vendor" ),
- vendors
- )
- )
- );
-
- UI( `ReplaceWidget( `id( `replace_point_models),
- `SelectionBox( `id( `models),
- `opt( `notify, `immediate),
-
- // Headline for monitor model selection box
- _( "Model" ),
- []
- )
- )
- );
- }
- }
-
- Shell("umount /floppy"); // umount floppy
- }
- else if ( ret == `next && current_vendor != "No X11" ) // other input
- {
- // check input
- string dummy = UI(`QueryWidget(`id(`hsync_min), `Value));
-
- if ( ! test_mode )
- {
- if ( !IsNumber( dummy ) || size ( dummy ) <= 0)
- {
- UI(`DisplayMessage(_("Minimal horizontal frequency is not a numerical value.\nPlease try again.")));
- // TODO: SetFocus()));
- continue;
- }
- dummy = UI(`QueryWidget(`id(`hsync_max), `Value));
- if ( !IsNumber ( dummy ) || size ( dummy ) <= 0)
- {
- UI(`DisplayMessage(_("Maximal horizontal frequency is not a numerical value.\nPlease try again.")));
- // TODO: SetFocus()));
- continue;
- }
- dummy = UI(`QueryWidget(`id(`vsync_min), `Value));
- if ( !IsNumber ( dummy ) || size ( dummy ) <= 0)
- {
- UI(`DisplayMessage(_("Minimal vertical frequency is not a numerical value.\nPlease try again.")));
- // TODO: SetFocus()));
- continue;
- }
- dummy = UI(`QueryWidget(`id(`vsync_max), `Value));
- if ( !IsNumber ( dummy ) || size ( dummy ) <= 0)
- {
- UI(`DisplayMessage(_("Maximal vertical frequency is not a numerical value.\nPlease try again.")));
- // TODO: SetFocus()));
- continue;
- }
- }
- }
- } until (ret == `next || ret == `back);
-
-
- if ( ( ret == `next || ret == `back ) && current_vendor != "No X11" )
- {
- // Save selected monitor in the user_setttings.monitor
- vendor = UI( `QueryWidget(`id(`vendors), `CurrentItem) );
- model = UI( `QueryWidget(`id(`models), `CurrentItem) );
- hsync_min = tointeger ( UI(`QueryWidget(`id(`hsync_min), `Value)) );
- hsync_max = tointeger ( UI(`QueryWidget(`id(`hsync_max), `Value)) );
- vsync_min = tointeger ( UI(`QueryWidget(`id(`vsync_min), `Value)) );
- vsync_max = tointeger ( UI(`QueryWidget(`id(`vsync_max), `Value)) );
-
- map map_display = $[];
- map_display = add( map_display, "hsync_min", hsync_min );
- map_display = add( map_display, "hsync_max", hsync_max );
- map_display = add( map_display, "vsync_max", vsync_max );
- map_display = add( map_display, "vsync_min", vsync_min );
-
- map_monitor = $[];
- map_monitor = add( map_monitor, "display", map_display );
- map_monitor = add( map_monitor, "device", model );
- map_monitor = add( map_monitor, "vendor", vendor );
-
- map monitor = evaluateResolution( map_monitor, false );
- user_settings = add( user_settings, "monitor", monitor );
- y2log(.milestone, "inst_video_data",
- 2,
- sformat("Monitor settings: %1: monitor_auto_probed = false",
- monitor ));
- }
-
- if ( current_vendor == "No X11" ) ret = `no_x11;
-
- return ret;
- }
-