/**************
FILE          : x11.ycp
***************
PROJECT       : YaST2
              :
AUTHOR        : Marcus Schäfer <ms@suse.de>
              :
BELONGS TO    : YaST2
              : (X11 integration part using SaX2/ISaX)
              :
DESCRIPTION   : This script is a wrapper for x11main.ycp
              : it implements what to do after the main dialog
              : has been finished
              :
STATUS        : Development
**************/
/**
 * File:        x11main/x11.ycp
 * Package:     X11 Configuration
 * Summary:     Main Module started if yast2 x11 is called
 * Authors:     Marcus Schaefer <ms@suse.de>
 *
 * $Id: x11.ycp 22717 2005-03-21 16:40:08Z ms $
 */
{
textdomain "x11";

import "XMessages";
import "Display";
import "Wizard";
import "X11Version";
import "Popup";
import "Mode";
import "Package";

//==========================================
// Globals...
//------------------------------------------
any ret = nil;

//==========================================
// Functions...
//------------------------------------------
//---[ finish ]----//
define any finish() ``{
	any localReturn = `next;
	UI::BusyCursor();
	SCR::Execute (.target.bash, "/sbin/SuSEconfig --module xdm");
	SCR::Execute (.target.bash, "/sbin/SuSEconfig --module kdm3");
	SCR::Execute (.target.bash, "/sbin/SuSEconfig --module gdm");
	UI::NormalCursor();
	return localReturn;
}

//==========================================
// installPackages()...
//------------------------------------------
define any installPackages() ``{
	list<string> requiredPacs = [
		"xorg-x11", "xorg-x11-server","xorg-x11-server-glx","libusb",
		"3ddiag", "sax2", "sax2-gui", "sax2-ident", "sax2-tools"
	];
	// ... /
	// setup contents of requiredPacs plus required pacs
	// for the detected card(s)
	// ---
	requiredPacs = toset (
		flatten( [requiredPacs, Display::pacs_to_install] )
	);

        return Package::InstallAllMsg (
		requiredPacs,
                XMessages::pacsMissing)
            ? `auto
            : nil;
}

//==========================================
// Check if X11 is installed
//------------------------------------------
if ( ! X11Version::have_x11 () ) {
	return `auto;
}

//==========================================
// check X11 version
//------------------------------------------
if ( X11Version::version == "3" ) {
	Popup::Error ( XMessages::versionMismatch );
    return `auto;
}

//==========================================
// install eventually missing packages...
//------------------------------------------
if (installPackages() == nil) {
	return `auto;
}

//==========================================
// Save touched configuration files...
//------------------------------------------
SCR::Execute (.target.bash,
	"/bin/cp /etc/X11/xorg.conf /etc/X11/xorg.conf.YaST2save"
);
if (SCR::Read(.sysconfig.bootloader.LOADER_TYPE) == "lilo") {
	SCR::Execute (.target.bash,
		"/bin/cp /etc/lilo.conf /etc/lilo.conf.YaST2save"
	);
}

//==========================================
// call x11main.ycp
//------------------------------------------
boolean next = true;
boolean back = true;

if (!(boolean)WFM::Args(0))
   back = false;
if (!(boolean)WFM::Args(1))
   next = false;

ret =  WFM::CallFunction ("x11main", [back, next]);
if ( ret == `next ) {
	ret = finish();
}
return (symbol) ret;
}
