+ if ($conn->is_connected) {
+ ### FIXME: Busy cursor should be started earlier
+ busy("Checking server status...");
+ my $r = new Sherlock::Object("!" => "STATUS"); ### FIXME: use a NOP command
+ $r = $conn->request($r);
+ }
+ if (!$conn->is_connected) {
+ busy("Reconnecting to server...");
+ if (!$conn->connect) {
+ ready($conn->{"error"});
+ submit_failed("Unable to connect to the server"); ### FIXME: Mention local submit
+ }
+ }
+ busy("Submitting...");
+
+ my ($task, $part) = split /\//, $selected_task;
+ defined $part or $part = $task;
+
+ my $fh = new IO::File($submit_filename);
+ if (!$fh) {
+ submit_failed("Unable to open $submit_filename\n($!)");
+ return;
+ }
+ my $stat = File::stat::populate($fh->stat);
+ if (!$stat) {
+ submit_failed("Unable to stat $submit_filename\n($!)");
+ return;
+ }
+ my $size = $stat->size;
+
+ my $r = new Sherlock::Object("!" => "SUBMIT", "T" => $task, "P" => $part, "X" => $submit_extension, "S" => $size);
+ $r = $conn->request($r);
+ if (!defined($r)) {
+ submit_failed("Connection to the server lost");
+ return;
+ } elsif ($r->get("-")) {
+ submit_failed($r->get("-"));
+ return;
+ }
+
+ $r = $conn->send_file($fh, $size);
+ if (!defined($r)) {
+ submit_failed("Connection to the server lost");
+ return;
+ } elsif ($r->get("-")) {
+ submit_failed($r->get("-"));
+ return;
+ }
+
+ close $fh;
+ submit_ok();