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

  1. // Edit your logcontrol file
  2.  
  3. {
  4.   if ( Args() == [ "get_menuentry" ] )
  5.  
  6.  
  7.     return [ "logcontrol",
  8.        $[
  9.          `menuentry    : "YaST2/Logcontrol",
  10.          `arguments    : [ ],
  11.          `widget       : `RichText(UI(_("This module configures, which log entries YaST2 should create and which not"))),
  12.          `codefragment : nil
  13.        ]
  14.     ];
  15.  
  16.  
  17.     UI(``{
  18.  
  19.       // Generic buttons
  20.       define OKButton()     `PushButton(`id(`ok), `opt(`default, `hstretch), _("&Ok"));
  21.       define CancelButton() `PushButton(`id(`cancel), `opt(`hstretch),  _("&Cancel"));
  22.  
  23.       // Construct a selectionbox containing all notified components.
  24.       define BuildSelectionBox(list logcon) ``
  25.     `SelectionBox(`id(`comp), _("Component"), maplist(`entry, logcon, ``select(entry, 0)));
  26.  
  27.       // Build the main dialog
  28.       define OpenMainDialog(list logcon) ``{
  29.     list logcon_sorted = sort(`x, `y, logcon, ``(select(x, 0) <= select(y,0)));
  30.     OpenDialog( `HBox(
  31.              BuildSelectionBox(logcon_sorted),
  32.              `Bottom(`VBox(`PushButton(`id(`add),    `opt(`hstretch), _("&Add")),
  33.                `PushButton(`id(`remove), `opt(`hstretch), _("&Remove")),
  34.                `PushButton(`id(`edit),   `opt(`hstretch), _("&Edit")),
  35.                OKButton(), 
  36.                CancelButton()
  37.                ))));
  38.       };
  39.  
  40.       // Ask user for componentname
  41.       define AskComponentName() ``{
  42.     OpenDialog(`HBox( `TextEntry(`id(`name), "Enter name of component", ""),
  43.               `Bottom(OKButton())));
  44.     string|void ret = nil;
  45.     while (true) {
  46.       any input = UserInput();
  47.       if (input == `ok) {
  48.         string name = QueryWidget(`id(`name), `Value);
  49.         if (name != "") {
  50.           ret = name;
  51.           break;
  52.         }
  53.       }
  54.       else if (input == `cancel) break;
  55.     }
  56.     CloseDialog();
  57.     return ret;
  58.       };
  59.  
  60.       // Edit one entry
  61.       define EditEntry(list entry) ``{
  62.     list levelnames = [ 
  63.                _("Debug messages"), 
  64.                _("Normal messages"),
  65.                _("Warnings"), 
  66.                _("Errors"), 
  67.                _("Security messages"), 
  68.                _("Internal errors") ];
  69.     
  70.     string name   = select(entry, 0);
  71.     list enabling = select(entry, 1);
  72.     term checkfield = `VBox();
  73.  
  74.     integer level = 0;
  75.     while (level < size(levelnames)) 
  76.       {
  77.         boolean checked = size(enabling) <= level || select(enabling, level);
  78.         checkfield = add(checkfield, 
  79.                  `Left(`CheckBox(`id(level), "" + level + ": " + _("Show ") 
  80.                        + select(levelnames, level), checked)));
  81.         level = level + 1;
  82.       }
  83.     
  84.     OpenDialog(`VBox(
  85.              `Label(_("Properties for ") + name),
  86.              checkfield,
  87.              `HBox(
  88.                    OKButton(),
  89.                    CancelButton())));
  90.  
  91.     if (UserInput() == `ok) {
  92.       enabling = [];
  93.       integer level = 0;
  94.       while (level < size(levelnames)) {
  95.         enabling = add(enabling, QueryWidget(`id(level), `Value));
  96.         level = level + 1;
  97.       }
  98.     }
  99.     CloseDialog();
  100.     return [ name, enabling ];
  101.       };
  102.  
  103.       // Macro that shows and handles the dialog
  104.       define EditLogcontrol(list logcon) ``{
  105.  
  106.     list old_logcon = logcon;
  107.     OpenMainDialog(logcon);
  108.     
  109.     do {
  110.       any ret = UserInput();
  111.       if (ret == `cancel) {
  112.         logcon = old_logcon;
  113.         break;
  114.       }
  115.       else if (ret == `add)
  116.         {
  117.           string|void name = AskComponentName();
  118.           if (is(name, string)) {
  119.         logcon = add(logcon, [ name, [ false ]]);
  120.         CloseDialog();
  121.         OpenMainDialog(logcon);
  122.           }
  123.         }
  124.       
  125.       else if (ret == `remove) 
  126.         {
  127.           string|void id = QueryWidget(`id(`comp), `CurrentItem);
  128.           if (is(id, string)) {
  129.         logcon = filter(`entry, logcon, ``(select(entry, 0) != id));
  130.         CloseDialog();
  131.         OpenMainDialog(logcon);
  132.           }
  133.         }
  134.       
  135.       else if (ret == `edit)
  136.         {
  137.           string|void id = QueryWidget(`id(`comp), `CurrentItem);
  138.           if (is(id, string)) {
  139.         list entry = find(`entry, logcon, ``(select(entry, 0) == id));
  140.         entry = EditEntry(entry);
  141.         logcon = add(filter(`entry, logcon, ``(select(entry, 0) != id)),
  142.                  entry);
  143.           }
  144.         }
  145.       
  146.       else if (ret == `ok)
  147.         {
  148.           break;
  149.         }
  150.       
  151.     } while (true);
  152.     
  153.     CloseDialog();
  154.     return logcon;
  155.       };
  156.     });
  157.     
  158.     // Main entry
  159.     
  160.     any logcon = ReadY2("logconf.ycp");
  161.     if (logcon == nil) logcon = [];
  162.  
  163.     logcon = UI(`EditLogcontrol(logcon));
  164.     return WriteY2("logconf.ycp", logcon);
  165. }
  166.