home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / boot / i386 / root / usr / share / YaST2 / include / autoinstall / ask.ycp next >
Text File  |  2006-11-29  |  6KB  |  133 lines

  1. /**
  2.  * File:        clients/ask.ycp
  3.  * Package:     Auto-installation
  4.  * Author:      Uwe Gansert <ug@suse.de>
  5.  * Summary:     ask for some values in the profile
  6.  *
  7.  * Changes:
  8.  * $Id$
  9.  */
  10.  
  11. {
  12.     import "Profile";
  13.     import "UI";
  14.     import "Label";
  15.     import "Stage";
  16.     import "Popup";
  17.  
  18.     define boolean askDialog() {
  19.         boolean mod = false;
  20.         foreach( map ask, filter( map m, Profile::current["general","ask-list"]:[], ``{
  21.                                         if( Stage::initial() && m["stage"]:"initial" == "initial" ) {
  22.                                             return true;
  23.                                         } else if( Stage::cont() && m["stage"]:"initial" == "cont" ) {
  24.                                             return true;
  25.                                         }
  26.                                         return false;
  27.                                     }), ``{
  28.             list<string> position = splitstring( ask["path"]:"", "," );
  29.             string pathStr  = ask["path"]:"";
  30.             string type     = ask["type"]:"";
  31.             string question = ask["question"]:pathStr;
  32.             string helptext = ask["help"]:"";
  33.             string title    = ask["title"]:"";
  34.             string file     = ask["file"]:"";
  35.             list< map<string,any> > s  = ask["selection"]:[];
  36.             mod = true;
  37.  
  38.             term dlg = `Dummy();
  39.             if( type == "boolean" ) {
  40.                 boolean on=(ask["default"]:nil=="true")?(true):(false);
  41.                 dlg = `CheckBox(`id(`entry), question,on );
  42.             } else if( type == "symbol" ) {
  43.                 list<any> dummy = [];
  44.                 foreach( map<string,any> e, s, ``{
  45.                     boolean on=(e["value"]:""==ask["default"]:nil)?(true):(false);
  46.                     dummy = add( dummy, `item(`id(e["value"]:`none), e["label"]:"",on) );
  47.                 });
  48.                 dlg = `ComboBox( `id(`entry), question, dummy );
  49.             } else {
  50.                 if( ask["password"]:false == true ) {
  51.                     dlg = `VBox(
  52.                              `Password(`id(`entry), question),
  53.                              `Password(`id(`pw2), question)
  54.                             );
  55.                 } else {
  56.                     if( haskey( ask, "selection" ) ) {
  57.                         list<any> dummy = [];
  58.                         foreach( map<string,any> e, s, ``{
  59.                             boolean on=(e["value"]:""==ask["default"]:nil)?(true):(false);
  60.                             dummy = add( dummy, `item(`id(e["value"]:""), e["label"]:"",on) );
  61.                         });
  62.                         dlg = `ComboBox( `id(`entry), question, dummy );
  63.                     } else {
  64.                         dlg = `TextEntry(`id(`entry), question, ask["default"]:"" );
  65.                     }
  66.                 }
  67.             }
  68.  
  69.             UI::OpenDialog(
  70.                        `opt(`decorated  ),
  71.                        `HBox(
  72.                          `HWeight(30, `RichText( helptext )),
  73.                          `HStretch(),
  74.                          `HSpacing(1),
  75.                          `HWeight(70,
  76.                               `VBox(
  77.                                 `Heading( title ),
  78.                                 `VSpacing(1),
  79.                                 `VStretch(),
  80.                                 `HBox(
  81.                                   dlg
  82.                                   ),
  83.                                 `VSpacing(1),
  84.                                 `VStretch(),
  85.                                 `HBox(
  86.                                   `PushButton(`id(`ok),  Label::OKButton() )
  87.                                   )
  88.                                 )
  89.                               ),
  90.                          `HSpacing(1),
  91.                          `HStretch()
  92.                          )
  93.                        );
  94.             while (true) {
  95.                 any ret = UI::UserInput();
  96.                 if( ret == `ok ) {
  97.                     any val = UI::QueryWidget(`id(`entry),  `Value);
  98.                     if( ask["type"]:"string" == "integer" ) {
  99.                         val = tointeger((string)val);
  100.                     }
  101.                     if( ask["password"]:false == true ) {
  102.                         string pass2 = (string)UI::QueryWidget(`id(`pw2),  `Value);
  103.                         if( pass2 != (string)val ) {
  104.                             Popup::Error("The two passwords mismatch.");
  105.                             continue;
  106.                         }
  107.                     }
  108.                     y2milestone("question=%1 was answered with val=%2",question, val);
  109.                     list<any> pos = [];
  110.                     foreach( string p, position, ``{
  111.                         if( regexpmatch( p, "^[1,2,3,4,5,6,7,8,9,0]+$" ) ) {
  112.                             integer index = tointeger(p);
  113.                             pos = add(pos, index);
  114.                         } else {
  115.                             pos = add(pos, p);
  116.                         }
  117.                     });
  118.                     if( pathStr != "" )
  119.                         Profile::current = Profile::setElementByList( pos, val, Profile::current );
  120.                     if( file != "" ) {
  121.                         if( ! SCR::Write (.target.string, file, sformat("%1",val)) )
  122.                             y2milestone("writing answer to %1 failed",file);
  123.                     }
  124.                     break;
  125.                 }
  126.             }
  127.             UI::CloseDialog();
  128.         });
  129.         return mod;
  130.     }
  131. }
  132.  
  133.