Commit 5de4df45 authored by Stefan Tauner's avatar Stefan Tauner
Browse files

fiji_ee_gui: unify loading of FIJI settings by GUI and -s parameter

parent 71a4f809
......@@ -234,28 +234,15 @@ sub main {
### Load settings
my $tmp_settings;
if (defined $settings_filename) {
my $filename = FIJI::Utils::glob_path($settings_filename);
my ($tmp_settings, $errors, $warnings) = FIJI::Settings->new('download', $filename); # fixme
if (!defined($tmp_settings)) {
my $msg = "Settings file $filename could not be loaded correctly.\n$errors";
$logger->error($msg) if !$tmp_settings;
my $d = $self->{'mw'}->FIJIModalDialog(-image => (!defined($tmp_settings) ? Tk::FIJIUtils::error_image($self->{'mw'}) : Tk::FIJIUtils::alert_image($self->{'mw'})),
-wraplength => $self->{'mw'}->screenwidth,
-text => $msg,
-title => 'Open FIJI Settings failed!',
);
$d->Show();
if (!defined($tmp_settings)) {
$ret = 1;
goto bailout;
}
$tmp_settings = $self->_load_settings($filename);
if (!blessed($tmp_settings) || !$tmp_settings->isa("FIJI::Settings")) {
$ret = 1;
goto bailout;
}
$self->{'settings'} = $tmp_settings;
${$self->{'settings_ini_name'}} = $filename;
$current_dir = _setdir($filename);
} else {
my $tmp_settings;
do {
$tmp_settings = $self->_load_settings_prompt($mw);
if (!defined($tmp_settings)) {
......@@ -264,8 +251,8 @@ sub main {
goto bailout;
}
} while (!blessed($tmp_settings) || !$tmp_settings->isa("FIJI::Settings"));
$self->{'settings'} = $tmp_settings;
}
$self->{'settings'} = $tmp_settings;
my $tmp_tests;
unless (defined($tests_filename) && defined ($tmp_tests = $self->_read_tests_file($tests_filename))) {
......@@ -325,7 +312,7 @@ sub main {
# The download_helper will notify the GUI at startup of its status
# by sending a message with 'state' set to either 'starting' or 'dying'
# The event handler below will kill the main window in case something bad happend.
# The event handler below will kill the main window in case something bad happens.
$mw->afterIdle(sub {
my $worker_msg = $self->{'FIJITestsViewer'}->{'queue_from_worker'}->dequeue();
if ($worker_msg->{'state'} eq "dying") {
......@@ -493,6 +480,32 @@ sub _setdir {
return File::Spec->catpath($volume, $directories, "");
}
sub _load_settings {
my $logger = get_logger("");
my ($self, $filename) = @_;
my ($tmp_settings, $errors, $warnings) = FIJI::Settings->new('download', $filename);
if (defined($errors) || defined($warnings)) {
my $msg = "";
$msg .= "Following errors prevented the settings to be loaded correctly:\n$errors\n" if $errors;
$msg .= "Potential (future) problems:\n$warnings\n" if defined($warnings);
chomp($msg);
chomp($msg);
$logger->error($msg) if !$tmp_settings;
my $d = $self->{'mw'}->FIJIModalDialog(-image => (!defined($tmp_settings) ?
Tk::FIJIUtils::error_image($self->{'mw'}) :
Tk::FIJIUtils::alert_image($self->{'mw'})
),
-wraplength => $self->{'mw'}->screenwidth,
-text => $msg,
-title => "Problems while loading settings file $filename!",);
$d->Show();
return $msg if !$tmp_settings;
}
$current_dir = _setdir($filename);
${$self->{'settings_ini_name'}} = $filename;
return $tmp_settings;
}
# Returns
# - undef if the user canceled the open dialog
# - a FIJI::Settings reference in case of success
......@@ -518,30 +531,7 @@ sub _load_settings_prompt {
$logger->debug("User aborted open configuration action");
return undef;
}
$current_dir = _setdir($filename);
$tmp_settings = (defined $self->{'settings'}) ? \%{Clone::clone($self->{'settings'})} : undef;
my ($errors, $warnings);
($tmp_settings, $errors, $warnings) = FIJI::Settings->new('download', $filename, $tmp_settings);
if (defined($errors) || defined($warnings)) {
my $msg = "";
$msg .= "Following errors prevented the settings to be loaded correctly:\n$errors\n" if $errors;
$msg .= "Potential (future) problems:\n$warnings\n" if defined($warnings);
chomp($msg);
chomp($msg);
$logger->error($msg) if !$tmp_settings;
my $d = $self->{'mw'}->FIJIModalDialog(-image => (!defined($tmp_settings) ?
Tk::FIJIUtils::error_image($self->{'mw'}) :
Tk::FIJIUtils::alert_image($self->{'mw'})
),
-wraplength => $self->{'mw'}->screenwidth,
-text => $msg,
-title => "Problems while loading settings file $filename!",);
$d->Show();
return $msg if !$tmp_settings;
}
${$self->{'settings_ini_name'}} = $filename;
return $tmp_settings;
return $self->_load_settings($filename);
}
sub _ctrl_frame {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment