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
/
PackageCallbacks.ycp
< prev
next >
Wrap
Text File
|
2006-11-29
|
40KB
|
1,596 lines
/**
* Module: PackageCallbacks.ycp
*
* Authors: Gabriele Strattner <gs@suse.de>
* Klaus Kaempf <kkaempf@suse.de>
* Arvin Schnell <arvin@suse.de>
*
* Purpose: provides the default Callbacks for Pkg::
*
*/
{
module "PackageCallbacks";
textdomain "packager";
import "Installation";
import "Directory";
import "Label";
import "Mode";
import "Popup";
import "PackageCallbacksInit";
import "URL";
import "CommandLine";
import "String";
import "Report";
global boolean _provide_popup = false;
global boolean _source_popup = false;
global boolean _package_popup = false;
global boolean _script_popup = false;
global string _package_name = "";
global integer _package_size = 0;
global boolean _deleting_package = false;
global integer _current_source = 1;
// make showLongInfo module-global so it gets remembered (cf. #14018)
boolean showLongInfo = false;
// used to en-/disable StartPackage, ProgressPackage and DonePackage
boolean enable_asterix_package = true;
boolean provide_aborted = false;
boolean source_aborted = false;
string back_string = "\b\b\b\b\b\b\b\b\b\b";
string clear_string = back_string + " " + back_string;
//--------------------------------------------------------------------------
// defaults
term ProgressBox (string heading, string name, string sz) {
term progressbox = `VBox(
`HSpacing(40),
// popup heading
`Heading (heading),
`Left (`HBox (
`VBox (
`Left (`Label (`opt (`boldFont), _("Package: "))),
`Left (`Label (`opt (`boldFont), _("Size: ")))
),
`VBox (
`Left (`Label (name)),
`Left (`Label (sz))
)
)),
`ProgressBar(`id(`progress), "", 100, 0 ),
`HBox (
`HStretch (),
`PushButton (`id (`abort), Label::AbortButton ()),
`HStretch ()
)
);
return progressbox;
}
/** at start of file providal
*
*/
global boolean StartProvide (string name, integer archivesize, boolean remote)
{
y2milestone("StartProvide: name: %1, remote: %2", name, remote);
if (remote)
{
string sz = String::FormatSizeWithPrecision (archivesize, 2, false);
if (Mode::commandline()) {
CommandLine::PrintVerbose(sformat(_("Downloading package %1 (%2)..."), name, sz));
}
else {
// popup heading
term providebox = ProgressBox (_("Downloading Package"), name, sz);
UI::OpenDialog(providebox);
_provide_popup = true;
}
}
return true;
}
/** during file providal
*
*/
global boolean ProgressProvide (integer percent)
{
y2milestone("ProgressProvide: %1", percent);
if (_provide_popup)
{
UI::ChangeWidget(`id(`progress), `Value, percent);
provide_aborted = UI::PollInput () == `abort;
return ! provide_aborted;
}
else if (Mode::commandline()) {
// there is no popup window, but command line mode is set
CommandLine::PrintVerboseNoCR(clear_string + sformat("%1%%", percent));
}
return true;
}
// creates layout for ChangeMediumPopup
global term LayoutPopup ( string message, term button_box,
integer vertical_size, boolean info_on )
{
term dialog_layout = `VBox(
`HSpacing(40), // enforce width
`VSpacing(0.1),
`Left(`Label( message)),
`Left(`CheckBox(`id(`show), `opt(`notify),
// check box
_("Show &details"), info_on )),
`VSpacing(0.4),
`HBox(`VSpacing(vertical_size),
`HSpacing(0.1),
`ReplacePoint(`id(`info), `Empty()),
`HSpacing(0.1)
),
`HBox(`HSpacing(0.1),
button_box,
`HSpacing(0.1)
),
`VSpacing(0.2)
);
return dialog_layout;
}
global boolean ShowLogInfo (string message, term buttonbox)
{
if (UI::QueryWidget(`id(`show), `Value ) == true)
{
UI::CloseDialog();
UI::OpenDialog( `opt(`decorated), LayoutPopup (message, buttonbox, 10, true) );
return true;
}
else
{
UI::CloseDialog();
UI::OpenDialog( `opt(`decorated), LayoutPopup (message, buttonbox, 2, false) );
UI::ReplaceWidget(`id(`info), `Empty() );
}
return false;
}
/** during file providal
*
// return "" for ignore
// return "R" for retry
// return "C" for abort
*/
global string DoneProvide (integer error, string reason, string name)
{
y2milestone("DoneProvide: %1", error);
if (_provide_popup)
UI::CloseDialog();
if (Mode::commandline())
{
// remove the progress
CommandLine::PrintVerboseNoCR(clear_string);
}
if (provide_aborted)
{
provide_aborted = false;
return "CANCEL";
}
_provide_popup = false;
if (error != 0)
{
string message = sformat (_("Package %1 was not found on the medium."), name);
if (Mode::commandline()) {
CommandLine::Print(message);
// ask user in the interactive mode
if (CommandLine::Interactive())
{
CommandLine::Print("");
// command line mode - ask user whether installation of the failed package should be retried
CommandLine::Print(_("Retry installation of the package?"));
if (CommandLine::YesNo())
{
// return Retry
return "R";
}
// command line mode - ask user whether the installation should be aborted
CommandLine::Print(_("Abort the installation?"));
if (CommandLine::YesNo())
{
// return Abort
return "C";
}
// otherwise return Ignore (default)
return "I";
}
return "I";
}
term button_box = `HBox (`PushButton (`id(`abort), Label::AbortButton()));
button_box = add (button_box, `PushButton(`id(`retry), Label::RetryButton()));
button_box = add (button_box, `PushButton(`id(`ignore), Label::IgnoreButton()));
if ( showLongInfo )
{
UI::OpenDialog( `opt(`decorated), LayoutPopup (message, button_box, 10, true) );
UI::ReplaceWidget(`id(`info), `RichText (`opt(`plainText), sformat (_("Error: %1:"), error) + reason) );
}
else
{
UI::OpenDialog( `opt(`decorated), LayoutPopup (message, button_box, 2, false) );
UI::ReplaceWidget(`id(`info), `Empty() );
}
any r = nil;
repeat
{
r = UI::UserInput();
if ( r == `show )
{
showLongInfo = ShowLogInfo (message, button_box);
if (showLongInfo)
{
UI::ReplaceWidget(`id(`info),
`RichText (`opt(`plainText),
sformat (_("Error: %1:"), error) + reason) );
}
else
{
UI::ReplaceWidget(`id(`info), `Empty() );
}
}
} until (r == `abort || r == `retry || r == `ignore);
y2milestone ("DoneProvide %1", r);
UI::CloseDialog();
if (r == `abort)
return "C";
if (r == `retry)
return "R";
if (r == `ignore)
return "I";
y2error("Unknown user input: %1", r);
}
return "I";
}
/**
* Enable or disable StartPackage, ProgressPackage and DonePackage
* callbacks, but only the progress bar and not the final error
* message. Returns old value.
*/
global boolean EnableAsterixPackage (boolean f)
{
boolean ret = enable_asterix_package;
enable_asterix_package = f;
return ret;
}
/**
* At start of package install.
*/
global boolean StartPackage (string name, string summary, integer
installsize, boolean is_delete)
{
if (!enable_asterix_package)
return true;
_package_name = name;
_package_size = installsize;
_deleting_package = is_delete;
string sz = String::FormatSizeWithPrecision (installsize, 2, false);
if (Mode::commandline()) {
CommandLine::PrintVerbose(sformat(
is_delete
? _("Uninstalling package %1 (%2)...")
: _("Installing package %1 (%2)..."),
name, sz));
}
else {
term packagebox = ProgressBox (is_delete
? _("Uninstalling Package")
: _("Installing Package"),
name, sz);
UI::OpenDialog( `opt(`decorated), packagebox );
_package_popup = true;
}
return true;
}
/**
* During package install.
*/
global boolean ProgressPackage (integer percent)
{
if (_package_popup)
{
UI::ChangeWidget (`id(`progress), `Value, percent);
return UI::PollInput () != `abort;
}
else if (Mode::commandline()) {
CommandLine::PrintVerboseNoCR(clear_string + sformat("%1%%", percent));
if (percent == 100)
{
// sleep for a wile
sleep(200);
// remove the progress
CommandLine::PrintVerboseNoCR(clear_string);
}
}
return true;
}
/**
* After package install.
*
* return "" for ignore
* return "R" for retry
* return "C" for abort (not implemented !)
*/
global string DonePackage (integer error, string reason)
{
if (_package_popup)
UI::CloseDialog();
_package_popup = false;
if (error != 0)
{
string infopath = (string) SCR::Read (.target.tmpdir) + "/rpmlog";
SCR::Execute (.target.bash, "/usr/bin/tail '" + String::Quote (Installation::destdir)
+ Directory::logdir + "/y2logRPM' > " + infopath);
string info = reason + "\n---\n" + (string) SCR::Read (.target.string, [infopath, "-?-"]);
string message = sformat ( _deleting_package ?
// error popup during package installation, %1 is the name of the package
_("Removal of package %1 failed.")
// error popup during package installation, %1 is the name of the package
: _("Installation of package %1 failed.")
, _package_name);
if (Mode::commandline()) {
CommandLine::Print(message);
CommandLine::Print(info);
// ask user in the interactive mode
if (CommandLine::Interactive())
{
CommandLine::Print("");
// command line mode - ask user whether installation of the failed package should be retried
CommandLine::Print(_("Retry installation of the package?"));
if (CommandLine::YesNo())
{
// return Retry
return "R";
}
// command line mode - ask user whether the installation should be aborted
CommandLine::Print(_("Abort the installation?"));
if (CommandLine::YesNo())
{
// return Abort
return "C";
}
// otherwise return Ignore (default)
return "";
}
}
else {
term button_box = `HBox (`PushButton (`id(`abort), Label::AbortButton()),
`PushButton(`id(`retry), Label::RetryButton()),
`PushButton(`id(`ignore), Label::IgnoreButton()));
if ( showLongInfo )
{
UI::OpenDialog( `opt(`decorated), LayoutPopup (message, button_box, 10, true) );
UI::ReplaceWidget(`id(`info), `RichText (`opt(`plainText), info) );
}
else
{
UI::OpenDialog( `opt(`decorated), LayoutPopup (message, button_box, 2, false) );
UI::ReplaceWidget(`id(`info), `Empty() );
}
any r = nil;
repeat {
r = UI::UserInput();
if ( r == `show )
{
showLongInfo = ShowLogInfo (message, button_box);
if (showLongInfo)
{
UI::ReplaceWidget(`id(`info), `RichText (`opt(`plainText), info) );
}
else
{
UI::ReplaceWidget(`id(`info), `Empty() );
}
}
} until (r == `abort || r == `retry || r == `ignore);
y2milestone ("DonePackage %1", r);
UI::CloseDialog();
if (r == `abort)
return "C";
if (r == `retry)
return "R";
}
// default: ignore
}
return "";
}
//=============================================================================
// MEDIA CHANGE
//=============================================================================
//-------------------------------------------------------------------------
//
// media change callback
//
// if current == -1, show "Ignore"
//
// return "" for ok, retry
// return "E" for eject media
// return "I" for ignore bad media
// return "S" for skip this media
// return "C" for cancel (not implemented !)
// return url to change media URL
global string MediaChange (string error, string url, string product,
integer current, string current_label,
integer wanted, string wanted_label,
boolean double_sided)
{
import "Mode";
if (!Mode::normal ())
{
import "SlideShow";
SlideShow::StopTimer();
}
y2milestone ("MediaChange err'%1', url'%2', prd'%3', cur'%4'/'%5', wan'%6'/'%7'",
error, url, product, current, current_label, wanted, wanted_label);
map url_tokens = URL::Parse (url);
string url_scheme = url_tokens["scheme"]:"";
url_scheme = tolower (url_scheme);
// true if it makes sense to offer an eject button (for cd/dvd only ...)
boolean offer_eject_button = url_scheme == "cd" || url_scheme == "dvd";
if (issubstring (error, "ERROR(InstSrc:E_bad_id)"))
{
error =
// error report
_("<p>The source at the specified URL now provides a different media ID.
If the URL is correct, this indicates that the source content has changed. To
continue using this source, start <b>Change Source of Installation</b> from
the YaST control center and refresh the installation source.</p>\n");
}
if (wanted_label == "")
{
// will be used in conjunction with other text below
// prompt for user to insert the correct CD/DVD
string medianame = "CD "; // FIXME?
if (url_scheme == "cd")
{
medianame = "CD ";
}
if (url_scheme == "dvd")
{
medianame = "DVD ";
}
string mediaside = sformat ("%1", (medianame + wanted));
if (double_sided)
{
// media is double sided, we want the user to insert the 'Side A' of the media
// the complete string will be "<product> <media> <number>, <side>"
// e.g. "'SuSE Linux 9.0' DVD 1, Side A"
string side = _("Side A");
if ((wanted & 1) == 0)
{
// media is double sided, we want the user to insert the 'Side B' of the media
side = _("Side B");
}
wanted = (wanted + 1) >> 1;
mediaside = sformat ("%1", (medianame + wanted)) + ", " + side;
}
wanted_label = sformat ("%1 %2", product, mediaside);
}
// prompt to insert product (%1 == "SuSE Linux version 9.2 CD 2")
string message = sformat (_("Insert\n'%1'"), wanted_label);
// with network source it doesn't make sense to ask for disk
if (url_scheme == "dir")
{
// report error while accessing local directory with product (%1 == "SuSE Linux ...")
message = sformat (_("Cannot access installation media\n%1.
Check that the directory is accessible."), wanted_label);
}
else if (url_scheme != "cd" && url_scheme != "dvd")
{
// report error while accessing network media of product (%1 == "SuSE Linux ...")
message = sformat (_("Cannot access installation media \n%1.
Check that the server is accessible."), wanted_label);
}
// currently unused
string media_prompt = _("The correct catalog medium could not be mounted.");
// --------------------------------------
// build up button box
term button_box = `HBox (`PushButton (`id(`retry), `opt(`default), Label::OKButton()));
if (current == -1) // wrong media id, offer "Ignore"
{
button_box = add (button_box, `PushButton(`id(`ignore), Label::IgnoreButton()));
}
button_box = add (button_box, `PushButton (`id(`cancel), Label::AbortButton()));
// push button label during media change popup, user can skip
// this media (CD) so no packages from this media will be installed
button_box = add (button_box, `PushButton (`id(`skip), _("&Skip")));
if (offer_eject_button)
{
// push button label during media change popup, user can eject the CD/DVD
button_box = add (button_box, `PushButton (`id(`eject), _("&Eject")));
}
if (Mode::commandline())
{
CommandLine::Print(message);
CommandLine::Print(error);
// ask user in the interactive mode
if (CommandLine::Interactive())
{
CommandLine::Print("");
// command line mode - ask user whether installation of the failed package should be retried
CommandLine::Print(_("Retry the installation?"));
if (CommandLine::YesNo())
{
// return Retry
return "";
}
// command line mode - ask user whether the installation should be aborted
CommandLine::Print(_("Skip the medium?"));
if (CommandLine::YesNo())
{
// return Skip
return "S";
}
// otherwise ignore the medium
CommandLine::Print(_("Ignoring the bad medium..."));
return "I";
}
return "S";
}
if ( showLongInfo )
{
UI::OpenDialog( `opt(`decorated), LayoutPopup (message, button_box, 10, true) );
/* TextEntry label */
UI::ReplaceWidget(`id(`info), `VBox (`TextEntry (`id(`url), _("&URL")), `RichText(error)) );
UI::ChangeWidget(`id(`url), `Value, url);
}
else
{
UI::OpenDialog( `opt(`decorated), LayoutPopup (message, button_box, 2, false) );
UI::ReplaceWidget(`id(`info), `Empty() );
}
any r = nil;
repeat {
r = UI::UserInput();
if ( r == `show )
{
showLongInfo = ShowLogInfo (message, button_box);
if (showLongInfo)
{
/* TextEntry label */
UI::ReplaceWidget(`id(`info), `VBox (`TextEntry (`id(`url), _("&URL")), `RichText(error)) );
UI::ChangeWidget(`id(`url), `Value, url);
}
else
{
UI::ReplaceWidget(`id(`info), `Empty() );
}
}
if (r == `retry || r == `url)
{
if (showLongInfo) // id(`url) must exist
{
string newurl = (string) UI::QueryWidget(`id(`url), `Value);
if (newurl != url)
{
url = newurl;
r = `url;
}
}
}
} until (r == `cancel || r == `retry || r == `eject || r == `skip || r == `ignore || r == `url);
y2milestone ("MediaChange %1", r);
UI::CloseDialog();
if (!Mode::normal ())
{
import "SlideShow";
SlideShow::StartTimer();
}
if (r == `cancel)
return "C";
if (r == `ignore)
return "I";
if (r == `skip)
return "S";
if (r == `eject)
return "E";
if (!Mode::normal ())
{
import "SlideShow";
SlideShow::SetCurrentCdNo (_current_source, wanted);
}
if (r == `url)
{
return url;
}
return "";
}
/**
* dummy source change callback, see SlideShowCallbacks for the real one
*/
global void SourceChange (integer source, integer medianr)
{
y2milestone ("SourceChange (%1, %2)", source, medianr);
_current_source = source;
}
// reference couter to the open popup window
integer _source_open = 0;
void OpenSourcePopup(string text)
{
if (_source_open == 0)
{
// the popup doesn't exist
y2milestone("Opening source progress popup: %1", text);
// if the text is too long then display only part of the message
// and then refresh the label to the full string
// reason: display a small popup, but user can resize it to see
// the full message
integer max_size = 60;
string display = text;
boolean refresh_label = false;
// truncate long text
if (size(display) > max_size)
{
// ellipsis appended to a truncated text (if it's too long)
display = substring(text, 0, max_size - 1) + _("...");
refresh_label = true;
}
UI::OpenDialog(
`VBox(
`HSpacing(max_size),
`Heading(`id(`label), `opt(`hstretch), display),
`ProgressBar (`id (`progress), " ", 100, 0)
)
);
// set the full text if needed
if (refresh_label)
{
UI::ChangeWidget(`label, `Value, text);
}
}
else
{
// refresh the labels in the popup
UI::ChangeWidget(`progress, `Label, text);
// reset the progressbar
UI::ChangeWidget(`progress, `Value, 0);
y2milestone("OpenSourcePopup: new label: %1", text);
}
_source_open = _source_open + 1;
y2milestone("OpenSourcePopup: _source_open: %1", _source_open);
}
boolean SourcePopupSetProgress(integer value)
{
if (_source_open > 0)
{
UI::ChangeWidget (`id (`progress), `Value, value);
any input = UI::PollInput ();
if (input == `abort)
return false;
}
return true;
}
void CloseSourcePopup()
{
_source_open = _source_open - 1;
// set 100% progress
SourcePopupSetProgress(100);
if (_source_open == 0)
{
y2milestone("Closing source progress popup");
UI::CloseDialog();
}
y2milestone("CloseSourcePopup: _source_open: %1", _source_open);
}
global void SourceCreateStart(string url) {
y2milestone ("SourceCreateStart: %1", url);
// popup label (%1 is source URL)
string msg = sformat(_("Creating source %1"), url);
if (Mode::commandline()) {
CommandLine::Print(msg);
}
else
{
OpenSourcePopup(sformat(_("Creating source %1"), url));
}
}
global boolean SourceCreateProgress(integer percent) {
boolean ret = SourcePopupSetProgress(percent);
y2milestone("SourceCreateProgress(%1) = %2", percent, ret);
return ret;
}
global symbol SourceCreateError (string url, symbol error, string description) {
y2milestone ("Source create: error: url: %1, error: %2, description: %3", url, error, description);
// error message - a label followed by a richtext with details
string message = _("Error occurred while creating the catalog.");
if (error == `NOT_FOUND)
// error message - a label followed by a richtext with details
message = _("Unable to retrieve the remote catalog description.");
else if (error == `IO)
// error message - a label followed by a richtext with details
message = _("An error occurred while retrieving the new metadata.");
else if (error == `INVALID)
// error message - a label followed by a richtext with details
message = _("The source is not valid.");
else if (error == `REJECTED)
// error message - a label followed by a richtext with details
message = _("The source metadata is invalid.");
if (Mode::commandline())
{
CommandLine::Print(message);
CommandLine::Print(url);
CommandLine::Print(description);
// ask user in the interactive mode
if (CommandLine::Interactive())
{
CommandLine::Print("");
// command line mode - ask user whether the source refreshment should be retried
CommandLine::Print(_("Retry?"));
if (CommandLine::YesNo())
{
// return Retry
return `RETRY;
}
}
return `ABORT;
}
string detail = sformat ("%1<br>%2", url, description);
UI::OpenDialog (`VBox (
`Label (message),
`RichText(detail),
`HBox (
`PushButton (`id (`RETRY), Label::RetryButton()),
`PushButton (`id (`ABORT), Label::AbortButton())
)
));
symbol ret = (symbol)UI::UserInput ();
UI::CloseDialog ();
y2milestone ("Source create error: Returning %1", ret);
if (ret == `RETRY)
{
// The start callback will be evaluated again,
// but the end callback will be called just once.
// This call replaces the missing end callback.
CloseSourcePopup();
}
return ret;
}
global void SourceCreateEnd(string url, symbol error, string description)
{
CloseSourcePopup();
y2milestone ("Source create end: error: url: %1, error: %2, description: %3", url, error, description);
}
global void SourceProbeStart(string url)
{
y2milestone ("SourceProbeStart: %1", url);
// popup label (%1 is source URL)
string msg = sformat(_("Probing source %1"), url);
if (Mode::commandline()) {
CommandLine::Print(msg);
}
else
{
OpenSourcePopup(_("Probing source..."));
OpenSourcePopup(sformat(_("Probing source %1"), url));
}
}
global void SourceProbeFailed(string url, string type)
{
y2milestone("Source %1 is not %2 source", url, type);
}
global void SourceProbeSucceeded(string url, string type)
{
y2milestone("Source %1 is type %2", url, type);
}
global boolean SourceProbeProgress(string url, integer value)
{
return SourcePopupSetProgress(value);
}
global symbol SourceProbeError(string url, symbol error, string description) {
y2milestone ("Source probe: error: url: %1, error: %2, description: %3", url, error, description);
// error message - a label followed by a richtext with details
string message = _("Error occurred while probing the source.");
if (error == `NOT_FOUND)
// error message - a label followed by a richtext with details
message = _("Unable to retrieve the remote catalog description.");
else if (error == `IO)
// error message - a label followed by a richtext with details
message = _("An error occurred while retrieving the new metadata.");
else if (error == `INVALID)
// error message - a label followed by a richtext with details
message = _("The source is not valid.");
else if (error == `NO_ERROR)
// error message - a label followed by a richtext with details
message = _("Source probing details.");
else if (error == `REJECTED)
// error message - a label followed by a richtext with details
message = _("Source metadata is invalid.");
if (Mode::commandline())
{
CommandLine::Print(message);
CommandLine::Print(url);
CommandLine::Print(description);
// ask user in the interactive mode
if (CommandLine::Interactive())
{
CommandLine::Print("");
// command line mode - ask user whether the source refreshment should be retried
CommandLine::Print(_("Retry?"));
if (CommandLine::YesNo())
{
// return Retry
return `RETRY;
}
}
return `ABORT;
}
string detail = sformat ("%1<br>%2", url, description);
UI::OpenDialog (`VBox (
`Label (message),
`RichText(detail),
`HBox (
`PushButton (`id (`RETRY), Label::RetryButton()),
`PushButton (`id (`ABORT), Label::AbortButton())
)
));
symbol ret = (symbol)UI::UserInput ();
UI::CloseDialog ();
y2milestone ("Source probe error: Returning %1", ret);
return ret;
}
global void SourceProbeEnd(string url, symbol error, string description) {
CloseSourcePopup();
CloseSourcePopup();
y2milestone ("Source probe end: error: url: %1, error: %2, description: %3", url, error, description);
}
global void SourceReportStart(integer source_id, string url, string task)
{
y2milestone("Source report start: src: %1, URL: %2, task: %3", source_id, url, task);
if (Mode::commandline()) {
CommandLine::Print(task);
}
else
{
OpenSourcePopup(task);
}
}
global boolean SourceReportProgress(integer value)
{
boolean ret = SourcePopupSetProgress(value);
y2debug("SourceReportProgress(%1) = %2", value, ret);
return ret;
}
global symbol SourceReportError(integer source_id, string url, symbol error, string description) {
y2milestone ("Source report: error: id: %1, url: %2, error: %3, description: %4", source_id, url, error, description);
// error message - a label followed by a richtext with details
string message = sformat(_("Source %1"), url);
if (error == `NOT_FOUND)
// error message - a label followed by a richtext with details
message = _("Unable to retrieve the remote catalog description.");
else if (error == `IO)
// error message - a label followed by a richtext with details
message = _("An error occurred while retrieving the new metadata.");
else if (error == `INVALID)
// error message - a label followed by a richtext with details
message = _("The source is not valid.");
if (Mode::commandline())
{
CommandLine::Print(message);
CommandLine::Print(url);
CommandLine::Print(description);
// ask user in the interactive mode
if (CommandLine::Interactive())
{
CommandLine::Print("");
// command line mode - ask user whether the source refreshment should be retried
CommandLine::Print(_("Retry?"));
if (CommandLine::YesNo())
{
// return Retry
return `RETRY;
}
}
return `ABORT;
}
string detail = sformat ("%1<br>%2", url, description);
UI::OpenDialog (`VBox (
`Label (message),
`RichText(detail),
`HBox (
`PushButton (`id (`RETRY), Label::RetryButton()),
`PushButton (`id (`ABORT), Label::AbortButton())
)
));
symbol ret = (symbol)UI::UserInput ();
UI::CloseDialog ();
y2milestone ("Source report error: Returning %1", ret);
if (ret == `RETRY)
{
// The start callback will be evaluated again,
// but the end callback will be called just once.
// This call replaces the missing end callback.
CloseSourcePopup();
}
return ret;
}
global void SourceReportEnd(integer src_id, string url, string task, symbol error, string description)
{
CloseSourcePopup();
y2milestone ("Source report end: src: %1, url: %2, task: %3, error: %4, description: %5", src_id, url, task, error, description);
}
/** at start of delta providal
*
*/
global boolean StartDeltaProvide (string name, integer archivesize)
{
string sz = String::FormatSizeWithPrecision (archivesize, 2, false);
if (Mode::commandline())
{
CommandLine::PrintVerbose(sformat(_("Downloading delta RPM package %1 (%2)..."), name, sz));
}
else {
if (_provide_popup)
UI::CloseDialog ();
// popup heading
term providebox = ProgressBox (_("Downloading Delta RPM package"), name, sz);
UI::OpenDialog(providebox);
_provide_popup = true;
}
return true;
}
/** at start of delta application
*
*/
global boolean StartDeltaApply (string name)
{
if (Mode::commandline())
{
CommandLine::PrintVerbose(sformat(_("Applying delta RPM package %1..."), name));
}
else {
// popup heading
term progressbox = `VBox(
`HSpacing(40),
// popup heading
`Heading (_("Applying delta RPM package")),
`Left (`HBox (
`Left (`Label (`opt (`boldFont), _("Package: "))),
`Left (`Label (name))
)),
`ProgressBar(`id(`progress), "", 100, 0 )
);
if (_provide_popup)
UI::CloseDialog ();
UI::OpenDialog(progressbox);
_provide_popup = true;
}
return true;
}
/** at start of patch providal
*
*/
global boolean StartPatchProvide (string name, integer archivesize)
{
string sz = String::FormatSizeWithPrecision (archivesize, 2, false);
if (Mode::commandline())
{
CommandLine::PrintVerbose(sformat(_("Downloading patch RPM package %1 (%2)..."), name, sz));
}
else {
if (_provide_popup)
UI::CloseDialog ();
// popup heading
term providebox = ProgressBox (_("Downloading Patch RPM Package"), name, sz);
UI::OpenDialog(providebox);
_provide_popup = true;
}
return true;
}
global void FinishPatchDeltaProvide () {
if (_provide_popup)
{
UI::CloseDialog ();
_provide_popup = false;
}
}
global void ProblemDeltaDownload (string descr) {
FinishPatchDeltaProvide (); // close popup
Report::ShowText (_("Failed to download delta RPM"), descr);
}
global void ProblemDeltaApply (string descr) {
FinishPatchDeltaProvide (); // close popup
Report::ShowText (_("Failed to apply delta RPM"), descr);
}
global void ProblemPatchDownload (string descr) {
FinishPatchDeltaProvide (); // close popup
Report::ShowText (_("Failed to download patch RPM"), descr);
}
global string FormatPatchName(string patch_name, string patch_version, string patch_arch)
{
string patch_full_name = (patch_name != nil && patch_name != "") ? patch_name : "";
if (patch_full_name != "")
{
if (patch_version != nil && patch_version != "")
{
patch_full_name = patch_full_name + "-" + patch_version;
}
if (patch_arch != nil && patch_arch != "")
{
patch_full_name = patch_full_name + "." + patch_arch;
}
}
return patch_full_name;
}
global void ScriptStart(string patch_name, string patch_version, string patch_arch, string script_path, boolean installation)
{
string patch_full_name = FormatPatchName(patch_name, patch_version, patch_arch);
y2milestone("ScriptStart callback: patch: %1, script: %2, installation: %3", patch_full_name, script_path, installation);
if (Mode::commandline())
{
CommandLine::PrintVerbose(sformat(_("Starting script %1 (patch %2)..."), script_path, patch_full_name));
}
else
{
term progressbox = `VBox(
`HSpacing(40),
// popup heading
`Heading(_("Running Script")),
`Left(
`HBox
(
// label, script name follows
`Left(`Label(`opt(`boldFont), _("Script: "))),
`Left(`Label(script_path))
),
(patch_full_name != "") ?
`HBox
(
// label, patch name follows
`Left(`Label(`opt(`boldFont), _("Patch: "))),
`Left(`Label(patch_full_name))
)
:
`Empty()
),
// label
`LogView(`id(`log), _("Output of the Script")),
`PushButton(`id(`abort), Label::AbortButton())
);
if (_script_popup)
UI::CloseDialog ();
UI::OpenDialog(progressbox);
_script_popup = true;
}
}
global boolean ScriptProgress (boolean ping, string output)
{
y2milestone("ScriptProgress: ping:%1, output: %2", ping, output);
if (_script_popup)
{
if (ping)
{
// TODO: refresh progress indicator
}
if (output != nil && output != "")
{
// add the output to the log widget
UI::ChangeWidget(`id(`log), `Value, output);
}
any input = UI::PollInput ();
if (input == `abort || input == `close)
return false;
}
return true;
}
global void ScriptProblem(string description)
{
y2warning("ScriptProblem: %1", description);
Popup::Error(description);
}
global void ScriptFinish()
{
y2milestone("ScriptFinish");
if (_script_popup)
{
UI::CloseDialog();
}
}
global void Message(string patch_name, string patch_version, string patch_arch, string message)
{
string patch_full_name = FormatPatchName(patch_name, patch_version, patch_arch);
y2milestone("Message (%1): %2", patch_full_name, message);
if (patch_full_name != "")
{
// label, %1 is patch name with version and architecture
patch_full_name = sformat(_("Patch: %1\n\n"), patch_full_name);
}
Popup::LongMessage(patch_full_name + message);
}
global void SetScriptCallbacks()
{
Pkg::CallbackScriptStart("PackageCallbacks::ScriptStart");
Pkg::CallbackScriptProgress("PackageCallbacks::ScriptProgress");
Pkg::CallbackScriptProblem("PackageCallbacks::ScriptProblem");
Pkg::CallbackScriptFinish("PackageCallbacks::ScriptFinish");
Pkg::CallbackMessage("PackageCallbacks::Message");
}
global void ClearScriptCallbacks()
{
Pkg::CallbackScriptStart("");
Pkg::CallbackScriptProgress("");
Pkg::CallbackScriptProblem("");
Pkg::CallbackScriptFinish("");
Pkg::CallbackMessage("");
}
//=============================================================================
// constructor and callback init
//=============================================================================
/**
* constructor
*
*/
global void PackageCallbacks()
{
y2milestone ( "PackageCallbacks constructor" );
PackageCallbacksInit::InitPackageCallbacks ();
}
global void StartDownload (string url, string localfile)
{
// heading of popup
string heading = _("Download");
// message in a progress popup
string message = sformat (_("Downloading: %1"), url);
if (Mode::commandline()) {
CommandLine::PrintVerbose(message);
}
else
{
UI::OpenDialog (`opt(`decorated),
`VBox (`Heading (heading) ,
`VBox (
`Label(message),
`HSpacing(60),
`HBox(
`HSpacing(2),
`ProgressBar (`id(`progress),
_("Status"), 100),
`HSpacing(2)
),
`VSpacing(1),
`HBox (
`HStretch (),
`PushButton (`id (`abort), Label::AbortButton ()),
`HStretch ()
),
`VSpacing(1)
)
)
);
UI::ChangeWidget (`id(`progress), `Value, 0);
}
}
global boolean ProgressDownload (integer percent, integer expected_size)
{
if (Mode::commandline()) {
CommandLine::PrintVerboseNoCR(clear_string + sformat("%1%%", percent));
if (percent == 100)
{
// sleep for a wile
sleep(200);
// remove the progress
CommandLine::PrintVerboseNoCR(clear_string);
// print newline when reached 100%
}
}
else {
UI::ChangeWidget (`id(`progress), `Value, percent);
return UI::PollInput () != `abort;
}
}
global void DoneDownload (integer error_value, string error_text)
{
if (error_value != 0)
{
if (Mode::commandline()) {
//error message, %1 is the cause for the error
CommandLine::Print(sformat (_("Download failed:
%1"), error_text));
}
else
{
// error message, %1 is the cause for the error
Popup::Error (sformat (_("Download failed:
%1"), error_text));
}
}
UI::CloseDialog ();
}
global void SetDownloadCallbacks ()
{
Pkg::CallbackStartDownload ("PackageCallbacks::StartDownload");
Pkg::CallbackProgressDownload ("PackageCallbacks::ProgressDownload");
Pkg::CallbackDoneDownload ("PackageCallbacks::DoneDownload");
}
global void ClearDownloadCallbacks ()
{
Pkg::CallbackStartDownload ("");
Pkg::CallbackProgressDownload ("");
Pkg::CallbackDoneDownload ("");
}
global void StartRebuildDB ()
{
// heading of popup
string heading = _("Checking Package Database");
// message in a progress popup
string message = _("Rebuilding package database. This process can take some time.");
// progress bar label
string progress_label = _("Status");
UI::OpenDialog (`opt(`decorated),
`VBox (`Heading (heading) ,
`VBox (
`Label(message),
`HSpacing(60),
`HBox(
`HSpacing(2),
`ProgressBar (`id(`progress),
"", 100),
`HSpacing(2)
),
`VSpacing(1)
)
)
);
UI::ChangeWidget (`id(`progress), `Value, 0);
}
global void ProgressRebuildDB (integer percent)
{
UI::ChangeWidget (`id(`progress), `Value, percent);
}
global void StopRebuildDB (integer error_value, string error_text)
{
if (error_value != 0)
{
// error message, %1 is the cause for the error
Popup::Error (sformat (_("Rebuilding of package database failed:
%1"), error_text));
}
UI::CloseDialog ();
}
global void NotifyRebuildDB (string error_text)
{
// error popup
Popup::Error (sformat (_("Error rebuilding database:
%1"), error_text));
}
global void SetRebuildDBCallbacks ()
{
Pkg::CallbackStartRebuildDb ("PackageCallbacks::StartRebuildDB");
Pkg::CallbackProgressRebuildDb ("PackageCallbacks::ProgressRebuildDB");
Pkg::CallbackStopRebuildDb ("PackageCallbacks::StopRebuildDB");
Pkg::CallbackNotifyRebuildDb ("PackageCallbacks::NotifyRebuildDB");
}
global void StartConvertDB (string unused1)
{
// heading of popup
string heading = _("Checking Package Database");
// message in a progress popup
string message = _("Converting package database. This process can take some time.");
UI::OpenDialog (`opt(`decorated),
`VBox (`Heading (heading) ,
`VBox (
`Label(message),
`HSpacing(60),
`HBox(
`HSpacing(2),
`ProgressBar (`id(`progress),
_("Status"), 100),
`HSpacing(2)
),
`VSpacing(1)
)
)
);
UI::ChangeWidget (`id(`progress), `Value, 0);
}
global void ProgressConvertDB (integer percent, integer unused1,
integer unused2, integer unused3,
integer unused4)
{
UI::ChangeWidget (`id(`progress), `Value, percent);
}
global void StopConvertDB (integer error_value, string error_text)
{
if (error_value != 0)
{
// error message, %1 is the cause for the error
Popup::Error (sformat (_("Conversion of package database failed:
%1"), error_text));
}
UI::CloseDialog ();
}
global string NotifyConvertDB (string message_type, integer unused1,
string detail)
{
if (message_type == "Nindb")
{
// error popup
Popup::Error (sformat (_("Package %1 is already present in the new database."),
detail));
return "";
}
if (message_type == "Eread")
{
boolean skip = Popup::YesNoHeadline (Label::ErrorMsg (),
// yes-no popup
_("Error reading from old database.
Ignore this error and continue?"));
return skip ? "SKIP" : "CANCEL";
}
if (message_type == "Ewrite")
{
// error popup
Popup::Error (_("Error writing to new database"));
return "";
}
y2error ("unknown message_type %1", message_type);
}
global void SetConvertDBCallbacks ()
{
Pkg::CallbackStartConvertDb ("PackageCallbacks::StartConvertDB");
Pkg::CallbackProgressConvertDb ("PackageCallbacks::ProgressConvertDB");
Pkg::CallbackStopConvertDb ("PackageCallbacks::StopConvertDB");
Pkg::CallbackNotifyConvertDb ("PackageCallbacks::NotifyConvertDB");
}
// EOF
}