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 / modules / PackageSelectionIO.ycp < prev    next >
Text File  |  2006-11-29  |  8KB  |  308 lines

  1. /**
  2.  * Module:         PackageSelectionIO.ycp
  3.  *
  4.  * Authors:        Stefan Schubert (schubi@suse.de)
  5.  *
  6.  * Purpose:         Saving and loading user package selections
  7.  *
  8.  * $Id: PackageSelectionIO.ycp 21866 2005-02-23 13:50:15Z jsrain $
  9.  */
  10.  
  11. {
  12.  
  13.     module "PackageSelectionIO";
  14.  
  15.     textdomain "packager";
  16.  
  17.     import "Installation";
  18.     import "Label";
  19.     import "Stage";
  20.     import "Popup";
  21.     import "Report";
  22.     import "StorageDevices";
  23.  
  24.     string lastHarddiskPath = "/var/lib/YaST2/packages.usr";
  25.     string lastFloppyPath = "packages.usr";
  26.     boolean floppySelected = false;
  27.     boolean savedLaterSelected = false;
  28.  
  29.     //
  30.     // Saving package selections
  31.     //
  32.     global define boolean savePackageSelection( boolean    saveLater ) ``{
  33.     boolean success    = true;
  34.     if ( floppySelected && saveLater)
  35.     {
  36.         string floppy_path = "/media/floppy/";
  37.         WFM::Execute (.local.umount, floppy_path); // Just for safety
  38.  
  39.         // Yes/No MsgBox; default: Yes
  40.         // Ask for a formatted floppy to save the package selection
  41.         while (Popup::YesNo(_("The current package selection will be saved
  42. on a floppy disk.  Insert a formatted floppy.
  43.  
  44. Write data to the floppy disk now?
  45. ")))
  46.         {
  47.  
  48.         // mount floppy_path by WFM, so use Execute() and Write()
  49.  
  50.         if ( WFM::Execute (.local.mount, [StorageDevices::FloppyDevice, floppy_path]) == true)
  51.         {
  52.             success = SCR::Write (.package.packageSelections, floppy_path+lastFloppyPath );
  53.  
  54.             WFM::Execute (.local.umount, floppy_path);
  55.  
  56.             if (success)
  57.             {
  58.             // msgbox
  59.             // data saved to floppy disk
  60.             Report::Message(_("Your settings have been saved to the floppy disk."));
  61.             break;
  62.             }
  63.             else
  64.             {
  65.             // text of a error popup: error occured while saving settings to the floppy
  66.             Report::Error(_("Error while saving settings to the floppy disk.
  67. Verify that the floppy is formatted
  68. and is not write protected.
  69. "));
  70.             }
  71.         }
  72.         else
  73.         {
  74.             // Popup with a 'Retry', a 'Cancel' button and a 'Format floppy' button.
  75.             // Check inserted floppy.
  76.             // headline
  77.             any ret = Popup::AnyQuestion3(_("Could not find a formatted floppy disk."),
  78. // popup contents
  79.                             _("Are you sure you inserted a floppy disk
  80. into the correct drive?
  81. If so, is the disk formatted and verified?
  82. "), Label::RetryButton(), Label::CancelButton(),
  83. // push button
  84. _("&Format floppy"), `focus_yes);
  85.  
  86.             if (ret == `no)        // cancel
  87.             {
  88.             break;
  89.             }
  90.             else if (ret == `retry)    // format floppy
  91.             {
  92.             UI::OpenDialog( `opt( `decorated ),
  93.                     `HBox(`HSpacing(1), `Label(Label::PleaseWaitMsg()), `HSpacing(1)));
  94.             SCR::Execute (.target.bash, "/sbin/mkdosfs " + StorageDevices::FloppyDevice);
  95.             UI::CloseDialog();
  96.             }
  97.             // default: retry loop
  98.         }
  99.         }
  100.     }
  101.     else if ( !floppySelected )
  102.     {
  103.         // Harddisk
  104.         if ( !Stage::initial () ||
  105.          ( !saveLater
  106.            && savedLaterSelected ))
  107.         {
  108.         // harddisk is present
  109.         success = SCR::Write (.package.packageSelections,
  110.                       Installation::destdir + lastHarddiskPath );
  111.         if ( success )
  112.         {
  113.             // text of a message popup: package selection is written correctly
  114.             Report::Message(_("Your package selections have been written to the hard disk."));
  115.         }
  116.         else
  117.         {
  118.             // text of en error popup: error while writing data
  119.             Report::Message(_("Error while saving package selections to the hard disk."));
  120.         }
  121.         }
  122.         else
  123.         {
  124.         savedLaterSelected = true;
  125.         }
  126.     }
  127.     return success;
  128.     };
  129.  
  130.     //
  131.     // Loading package selections
  132.     //
  133.     global define boolean loadPackageSelection( ) ``{
  134.     boolean success = true;
  135.     // text of a popup with 'Yes' and 'No' button
  136.     if ( Popup::YesNo(_("Do you really want to reset your settings?")))
  137.     {
  138.         if ( floppySelected )
  139.         {
  140.         string floppy_path = "/media/floppy/";
  141.         WFM::Execute (.local.umount, floppy_path); // Just for safety
  142.  
  143.         // Yes/No MsgBox; default: Yes
  144.         // Ask for the floppy with the package selection.
  145.         while (Popup::YesNo(_("The current package selection will be loaded
  146. from a floppy disk.  Insert the floppy.
  147.  
  148. Read data from the floppy disk now?
  149. ")))
  150.         {
  151.             // mount floppy_path by WFM, so use Execute() and Read()
  152.  
  153.             if ( WFM::Execute (.local.mount, [StorageDevices::FloppyDevice, floppy_path]) == true)
  154.             {
  155.             success = (boolean) SCR::Read (.package.packageSelections, floppy_path+lastFloppyPath );
  156.  
  157.             WFM::Execute (.local.umount, floppy_path);
  158.  
  159.             if (success)
  160.             {
  161.                 break;
  162.             }
  163.             else
  164.             {
  165.                 // text of an error popup: can't read settings from floppy
  166.                 Report::Error(_("Error while loading settings from the floppy disk.
  167. Verify that the correct floppy has been inserted
  168. and that the path name has been written correctly.
  169. "));
  170.             }
  171.             }
  172.         }
  173.         }
  174.         else
  175.         {
  176.         // Harddisk
  177.         success = (boolean) SCR::Read (.package.packageSelections,
  178.                      Installation::destdir + lastHarddiskPath );
  179.         if ( !success )
  180.         {
  181.             // text of an error poup: can't read settings from hard disk
  182.             Report::Error(_("Error while loading settings from the hard disk.
  183. Verify that the path name has been written correctly.
  184. "));
  185.         }
  186.         }
  187.     }
  188.     else
  189.     {
  190.         success = false;
  191.     }
  192.  
  193.     return success;
  194.     };
  195.  
  196.     //
  197.     // Saving and Loading package user selections
  198.     //
  199.     global define void SaveLoadSelection( ) ``{
  200.  
  201.     savedLaterSelected = false;
  202.  
  203.     term dia_opt = `opt ( `decorated );
  204.  
  205.     UI::OpenDialog( dia_opt,
  206.             `HBox( `VSpacing(10),
  207.                `VBox (`HSpacing(50),
  208.                   // Headline of a popup with a 'Cancel', a 'Load' and a 'Save' button.
  209.                   // A user defined selection of packages can be loaded or saved.
  210.                   `Left(`Heading( _("Load or save package selection") )),
  211.                   `VSpacing(0.2),
  212.                   `RadioButtonGroup(`id(`selections),`opt(`notify),
  213.                             `VBox(
  214.                               `HBox(
  215.                                 `Left(`RadioButton(`id(`harddisk),
  216.                                            `opt(`notify),
  217.                                            // Radio button for saving/loading from harddisk
  218.                                            _("&Harddisk"),
  219.                                            !floppySelected)),
  220.                                 `Left(`RadioButton(`id(`floppy),
  221.                                            `opt(`notify),
  222.                                            // Radio button for saving/loading from floppy
  223.                                            _("&Floppy"),
  224.                                            floppySelected))
  225.                                 ),
  226.                               `VSpacing(0.8),
  227.                               `TextEntry(`id(`path),
  228.                                      // Input field label for the filename
  229.                                      _("&Path name"),
  230.                                      ( floppySelected? lastFloppyPath:lastHarddiskPath ))
  231.                               )
  232.                             ),
  233.                   `VSpacing(0.2),
  234.                   `HBox(
  235.                     // button labels selection popup
  236.                     `Left(`PushButton( `id(`cancel),`opt(`default), Label::CancelButton())),
  237.                     // push button
  238.                     `Right(`PushButton( `id(`load), _("&Load"))),
  239.                     // push button
  240.                     `Right(`PushButton( `id(`save),  _("&Save")))
  241.                     )
  242.                   )
  243.                )
  244.             );
  245.  
  246.     while ( true )
  247.     {
  248.         boolean oldDiskSelected = (boolean) UI::QueryWidget(`id(`harddisk), `Value);
  249.  
  250.         any ret = UI::UserInput();
  251.  
  252.         if ( ret == `cancel )
  253.         {
  254.         break;
  255.         }
  256.  
  257.         if ( UI::QueryWidget(`id(`harddisk), `Value)  == true)
  258.         {
  259.         floppySelected = false;
  260.         if ( !oldDiskSelected )
  261.         {
  262.             // changed from floppy to HD
  263.             UI::ChangeWidget( `id(`path), `Value, lastHarddiskPath );
  264.         }
  265.         else
  266.         {
  267.             lastHarddiskPath = (string) UI::QueryWidget(`id(`path), `Value);
  268.         }
  269.         }
  270.         else
  271.         {
  272.         floppySelected = true;
  273.         if ( oldDiskSelected )
  274.         {
  275.             // changed from HD to floppy
  276.             UI::ChangeWidget( `id(`path), `Value, lastFloppyPath );
  277.         }
  278.         else
  279.         {
  280.             lastFloppyPath = (string) UI::QueryWidget(`id(`path), `Value);
  281.         }
  282.         }
  283.  
  284.         if ( ret == `load )
  285.         {
  286.         if ( loadPackageSelection() )
  287.         {
  288.             break;
  289.         }
  290.         }
  291.  
  292.         if ( ret == `save )
  293.         {
  294.         if ( savePackageSelection( true ) )
  295.         {
  296.             break;
  297.         }
  298.         }
  299.     }
  300.  
  301.     UI::CloseDialog();
  302.     };
  303.  
  304.  
  305.  
  306.  
  307. }
  308.