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

  1. /**
  2.  *
  3.  * $Id: inst_environment.ycp,v 1.73 2000/03/13 11:46:06 kkaempf Exp $
  4.  *
  5.  * Module:        inst_environment.ycp
  6.  *
  7.  * Author:        Klaus   KΣmpf
  8.  *            Michael Hager
  9.  *            Stefan  Hundhammer <sh@suse.de>
  10.  *
  11.  * Purpose:        Let the user choose keyboard and timezone.
  12.  *                      Set the console font for the target machine.
  13.  *            The font depends on the current language.
  14.  *
  15.  * user_settings:
  16.  *
  17.  * wr: "console_font"         \
  18.  * wr: "console_unicodemap"   > set console font
  19.  * wr: "console_screenmap"   /
  20.  *
  21.  * rw: "keyboard"   the keyboardseting for the installation and
  22.  *                  for target machine
  23.  * rw: "timezone"   the timezone for the target machine
  24.  *
  25.  * "rw" read/write
  26.  * "wr" write only
  27.  *
  28.  * Reads:
  29.  * timezone.ycp:     a map with all supported timezones
  30.  * keyboard.ycp:     a map which contains all supported keyboards
  31.  * consolefonts.ycp: map language to the corresponding font
  32.  *
  33.  *
  34.  */
  35. {
  36.   boolean test_mode    = lookup ( user_settings, "test_mode", false );
  37.  
  38.   // map keyboard map back to yast1 (for install.inf)
  39.  
  40.   map keymap2yast1 =
  41.       $[
  42.     "english-uk"    : "us",
  43.     "english-us"    : "us",
  44.     "german"    : "de-lat1-nd",
  45.     "german-ch"    : "de-lat1-nd",
  46.     "french"    : "fr-latin1",
  47.     "french-ch"    : "fr-latin1",
  48.     "italian"    : "it",
  49.     "spanish"    : "es",
  50.     "dutch"        : "nl",
  51.     "portugese"    : "pt2",
  52.     "portugese-br"    : "br-abnt2",
  53.     "hungarian"    : "hu",
  54.     "polish"    : "Pl02",
  55.     "greek"        : "gr",
  56.     "russian"    : "ru1",
  57.     "czech"        : "cz-lat2"
  58.       ];
  59.  
  60.   /*
  61.    * Set the console (text mode) keyboard as specified.
  62.    * Uses the 'loadkeys' program.
  63.    */
  64.  
  65.     define SetConsoleKeyboard( map all_keyboards, string keyboard_name ) ``{
  66.     list keyboard_desc = lookup ( all_keyboards, keyboard_name, [] );
  67.     string keymap = lookup ( select ( keyboard_desc, 1 ), "ncurses", "us.map.gz" );
  68.     string loadkeys_command = "loadkeys " + keymap;
  69.     Shell( loadkeys_command );
  70.     return loadkeys_command;
  71.     };
  72.  
  73.  
  74.   /*
  75.    * Set the X keyboard as specified.
  76.    * Uses the 'xkbset' command (originally from SaX).
  77.    */
  78.  
  79.   define SetXKeyboard( map all_keyboards, string keyboard_name ) ``{
  80.       list keyboard_desc = lookup ( all_keyboards, keyboard_name, [] );
  81.       list xkbset_args = lookup ( select ( keyboard_desc, 1 ), "qt", "english-us" );
  82.       string xkbset_command = "xkbset";
  83.       foreach( `arg, xkbset_args, ``{
  84.       xkbset_command = xkbset_command + " \"" + arg + "\"";
  85.       });
  86.  
  87.       if ( test_mode )
  88.       y2log( .milestone, "inst_environment", 1,
  89.          "Test mode - NOT setting X keyboard - would have called:\n" + xkbset_command );
  90.       else
  91.       Shell( xkbset_command );
  92.  
  93.       return xkbset_command;
  94.   };
  95.  
  96.  
  97.  
  98.   string language = lookup( user_settings, "language" );
  99.  
  100.  
  101.   /* ----------------------------------------------------------------------
  102.    * Keyboard
  103.    * ----------------------------------------------------------------------*/
  104.  
  105.   map lang2kbd =
  106.       $[
  107.     "en_GB"        : "english-uk",
  108.     "en_US"        : "english-us",
  109.     "en"         : "english-us",
  110.     "de_DE"        : "german",
  111.     "de_CH"        : "german-ch",
  112.     "de"          : "german",
  113.     "br_FR"        : "french",
  114.     "fr_FR"        : "french",
  115.     "fr_CH"        : "french-ch",
  116.     "it_IT"        : "italian",
  117.     "es_ES"        : "spanish",
  118.     "nl_NL"        : "dutch",
  119.     "pt_PT"        : "portugese",
  120.     "pt_BR"        : "portugese-br",
  121.     "hu_HU"        : "hungarian",
  122.     "pl_PL"        : "polish",
  123.     "el_GR"        : "greek",
  124.     "ru"         : "russian",
  125.     "ru_RU"         : "russian",
  126.     "ru_RU.KOI8-R"    : "russian",
  127.     "cs_CZ"        : "czech"
  128.       ];
  129.  
  130.   string default_keyboard = lookup ( lang2kbd, language, "english-us" );
  131.  
  132.   map     keyboards = ReadY2( "keyboard.ycp" );
  133.   string keyboard  = lookup ( user_settings, "keyboard", default_keyboard );
  134.   SetConsoleKeyboard( keyboards, keyboard );
  135.   SetXKeyboard( keyboards, keyboard );
  136.  
  137.   // Create keyboard selection box with the default selection
  138.   // according to user_settings
  139.  
  140.   term keyboardsel =
  141.       `SelectionBox( `id( `keyboard ), `opt( `notify ),
  142.              // title for selection box 'keyboard layout'
  143.              _( "Keyboard layout" ),
  144.              maplist( `key, `value, keyboards, ``{
  145.              map languagemap = select( value, 0 );
  146.              string name = translate( languagemap, language );
  147.              return  `item( `id( key ), name, key == keyboard );
  148.              }));
  149.  
  150.   /* ----------------------------------------------------------------------
  151.    * Timezone
  152.    * ----------------------------------------------------------------------*/
  153.  
  154.   map timezones = ReadY2( "timezone.ycp" );
  155.  
  156.   // build up timezone selection box
  157.   //   with the default selection according to user_settings
  158.  
  159.   map lang2tz =
  160.       $[
  161.     "en_GB"        : "Europe/London",
  162.     "en_US"        : "US/Pacific",
  163.     "en"         : "US/Pacific",
  164.     "de_DE"        : "Europe/Berlin",
  165.     "de_CH"        : "Europe/Zurich",
  166.     "de_AT"        : "Europe/Vienna",
  167.     "de"          : "Europe/Berlin",
  168.     "br_FR"        : "Europe/Paris",
  169.     "fr_FR"        : "Europe/Paris",
  170.     "fr_CH"        : "Europe/Zurich",
  171.     "fr"         : "Europe/Paris",
  172.     "it_IT"        : "Europe/Rome",
  173.     "es_ES"        : "Europe/Madrid",
  174.     "nl_NL"        : "Europe/Amsterdam",
  175.     "pt_PT"        : "Europe/Lisbon",
  176.     "pt_BR"        : "America/Buenos_Aires",
  177.     "hu_HU"        : "Europe/Budapest",
  178.     "pl_PL"        : "Europe/Warsaw",
  179.     "el_GR"        : "Europe/Athens",
  180.     "ru"         : "Europe/Moscow",
  181.     "ru_RU"         : "Europe/Moscow",
  182.     "ru_RU.KOI8-R"     : "Europe/Moscow",
  183.     "cs_CZ"        : "Europe/Prague"
  184.       ];
  185.  
  186.   string default_timezone = lookup ( lang2tz, language, "Europe/Berlin" );
  187.  
  188.   string timezone = lookup ( user_settings, "timezone", default_timezone );
  189.   map sortedzone = $[];
  190.   foreach (`key, `languagemap, timezones, ``{
  191.     string name = translate( languagemap, language );
  192.     sortedzone = add (sortedzone, name, key);
  193.   });
  194.   term timezonesel =
  195.       `SelectionBox( `id( `timezone ), `opt( `notify ),
  196.             // title for selection box 'timezone'
  197.             _( "Timezone" ),
  198.             maplist( `name, `key, sortedzone, ``{
  199.               return `item( `id( key ), name, key == timezone );
  200.             })
  201.            );
  202.  
  203.   /* ----------------------------------------------------------------------
  204.    * Build dialog
  205.    * ----------------------------------------------------------------------*/
  206.  
  207.   term contents =
  208.       `HBox (
  209.          `HWeight ( 5, `HStretch() ),
  210.          `HWeight ( 100, `VBox(
  211.                    `HBox(
  212.                      `HWeight ( 50, keyboardsel ),
  213.                      `HWeight ( 2, `HStretch() ),
  214.                      `HWeight ( 50, timezonesel )
  215.                      ),
  216.  
  217.                    // title for textentry widget to test your keyboard setting
  218.                    `TextEntry( _("Test your keyboard") ),
  219.                    `Label ( "" )
  220.                    )
  221.             ),
  222.          `HWeight ( 5, `HStretch() )
  223.          );
  224.  
  225.   // Show a Wizardwindow with  that contents.
  226.   // Don't use the IDs `next, `back, and `help.
  227.   //
  228.  
  229.   // help text for language,keyboard,timezone screen
  230.   string help_text = UI( _( "\
  231. <p>
  232. Choose the <b>keyboard layout</b> you want to use now during
  233. installation and later in the installed system.
  234. </p>" ) );
  235.  
  236.   help_text = help_text + UI( _( "\
  237. <p>
  238. Then select the appropriate <b>timezone</b>. Choose the country or
  239. region where you are located.
  240. </p>" ) );
  241.  
  242.   help_text = help_text + UI( _( "\
  243. <p>
  244. If you are unsure, please use the default values already selected.
  245. </p>
  246. <br>" ) );
  247.  
  248.   // Screen title for keyboard and timezone screen
  249.   any dlg = UI( `SetWizardContents( _( "Basic Configuration" ), contents,
  250.                   help_text,
  251.                   Args(0), Args(1) ) );
  252.  
  253.   any ret = nil;
  254.  
  255.   repeat
  256.       {
  257.       ret= UI( `UserInput() );
  258.  
  259.       if ( ret == `next || ret == `keyboard )
  260.       {
  261.           keyboard = UI( `QueryWidget( `id( `keyboard ), `CurrentItem ) );
  262.           user_settings = add( user_settings, "keyboard", keyboard );
  263.           string ckb_cmd = SetConsoleKeyboard( keyboards, keyboard );
  264.           user_settings = add (user_settings, "ckb_cmd", ckb_cmd);
  265.           string xkb_cmd = SetXKeyboard( keyboards, keyboard );
  266.           user_settings = add (user_settings, "xkb_cmd", xkb_cmd);
  267.  
  268.           // replace Keytable in /etc/install.inf
  269.  
  270.           string yast1_keymap = lookup (keymap2yast1, keyboard, keyboard);
  271.           user_settings = add (user_settings, "yast1_keymap", yast1_keymap);
  272.  
  273.           Shell ("grep -v ^Keytable /etc/install.inf > /tmp/install.inf");
  274.           WriteString ("/tmp/yast2.inf", "Keytable: "+yast1_keymap+"\n");
  275.           Shell ("cat /tmp/yast2.inf /tmp/install.inf > /etc/install.inf");
  276.       }
  277.  
  278.       if ( ret == `next || ret == `timezone )
  279.       {
  280.           timezone = UI( `QueryWidget( `id( `timezone ), `CurrentItem ) );
  281.           user_settings = add( user_settings, "timezone", timezone );
  282.       }
  283.       } until ( ret == `next || ret == `back || ret == `cancel );
  284.  
  285.   return ret;
  286. }
  287.