Index: /main/trunk/greenstone2/cgi-bin/talkback-progressbar.pl
===================================================================
--- /main/trunk/greenstone2/cgi-bin/talkback-progressbar.pl	(revision 23148)
+++ /main/trunk/greenstone2/cgi-bin/talkback-progressbar.pl	(revision 23149)
@@ -25,14 +25,136 @@
 
 
+sub get_progress_filename
+{
+    my ($uploaded_file) = @_;
+
+    my $progress_file = $uploaded_file;
+
+    $progress_file =~ s{^(.*)\/}{}; 
+    $progress_file =~ s/\.*?$//;
+    $progress_file .= "-progress.txt";
+
+    my $progress_filename = &util::filename_cat($gsdl_tmp_dir, $progress_file);
+
+    return $progress_filename;
+}
+
+sub get_file_central_filename
+{
+    my $file_central = &util::filename_cat($gsdl_tmp_dir,"file-central.txt");
+
+    return $file_central;
+}
+
+sub read_file_central
+{
+    my $fc_filename = get_file_central_filename();
+
+    my @fc_list;
+
+    if (open(FCIN,"<$fc_filename")) {
+	
+	my $fc_list_str = do { local $/; <FCIN> };
+	@fc_list = split(/\n/,$fc_list_str);
+
+	close(FCIN);
+    }
+    else {
+	# OK to have no file-central.txt to start with
+	# return empty list
+	@fc_list = ();
+    }
+
+    return \@fc_list;
+    
+}
+
+sub remove_from_file_central
+{
+    my ($filename,$fc_list) = @_;
+
+    my @new_fc_list = ();
+
+    my $removed = 0;
+
+    foreach my $f (@$fc_list) {
+
+	if ($f ne $filename) {
+	    push(@new_fc_list,$f);
+	}
+	else {
+	    $removed = 1;
+	}
+    }
+
+    if (!$removed) {
+	print STDERR "Warning: Failed to locate '$filename' in file-central.txt\n";
+    }
+
+    return \@new_fc_list;
+}
+
+sub add_to_file_central
+{
+    my ($filename,$fc_list) = @_;
+
+    my @new_fc_list = @$fc_list;
+
+    my $duplicate = 0;
+    foreach my $f (@new_fc_list) {
+
+	if ($f eq $filename) {
+	    $duplicate = 1;
+	}
+    }
+
+    if (!$duplicate) {
+	push(@new_fc_list,$filename);
+    }
+    else {
+	print STDERR "Warning: Ingoring request to add duplicate entry:\n";
+	print STDERR "         '$filename' into file-central.txt\n"
+	}
+
+    return \@new_fc_list;
+}
+
+
+
+sub write_file_central
+{
+    my ($fc_list) = @_;
+
+    my $fc_filename = get_file_central_filename();
+
+    if (open(FCOUT,">$fc_filename")) {
+	
+	foreach my $f (@$fc_list) {
+	    print FCOUT "$f\n";
+	}
+
+	close(FCOUT);
+    }
+    else {
+	print STDERR "Error: Failed to write out $fc_filename\n";
+	print STDERR "$!\n";
+    }
+}
+
 sub monitor_upload 
 {            
-    my ($filename, $buffer, $bytes_read, $data) = @_;
+    my ($uploading_file, $buffer, $bytes_read, $data) = @_;
     
     $bytes_read ||= 0; 
-
-    my $full_filename = &util::filename_cat($gsdl_tmp_dir,
-					    "$filename-progress.txt");
-      
-    open(COUNTER, ">$full_filename"); 
+    
+    my $progress_filename = get_progress_filename($uploading_file);
+
+    if (! -f $progress_filename) {
+	my $fc_list = read_file_central();
+	$fc_list = add_to_file_central($uploading_file,$fc_list);
+	write_file_central($fc_list);
+    }
+    
+    open(COUNTER, ">$progress_filename"); 
     
     my $per = 0; 
@@ -46,4 +168,5 @@
     # Sleep for 10 msecs
     select(undef, undef, undef, 0.01);
+    #select(undef, undef, undef, 0.1);
 }
 
@@ -75,14 +198,15 @@
 sub remove_progress_file 
 { 
-    my ($file) = @_;
-
-    $file =~ s{^(.*)\/}{}; 
-
-    my $progress_filename = &util::filename_cat($gsdl_tmp_dir,
-						"$file-progress.txt");
+    my ($uploaded_file) = @_;
+
+    my $progress_filename = get_progress_filename($uploaded_file);
 
     if (!unlink($progress_filename)) {
 	print STDERR "Warning: Failed to delete $progress_filename\n"; 
     }
+
+    my $fc_list = read_file_central();
+    $fc_list = remove_from_file_central($uploaded_file,$fc_list);
+    write_file_central($fc_list);
 }
 
@@ -151,7 +275,6 @@
 main(); 
 
+
 #=====
-
-
 
 sub inc_wait_dots
@@ -172,11 +295,10 @@
 }
 
+
 sub check_status_single_file
 {
     my ($filename) = @_;
-    $filename =~ s{^(.*)\/}{}; 
-
-    my $monitor_filename = &util::filename_cat($gsdl_tmp_dir,
-					       "$filename-progress.txt");
+    
+    my $monitor_filename = get_progress_filename($filename);
 
     if (! -f  $monitor_filename ) {
@@ -197,9 +319,11 @@
 
     my $r = "";
-    $r .= "<div style=\"float:left;\">$filename:</div>";
+    $r .= "<div>$filename:</div>";
+    $r .= "<nobr>";
     $r .= "<div style=\"width: ${fgwidth}px; $fgcol $style_base\"></div>"; 
     $r .= "<div style=\"width: ${bgwidth}px; $bgcol $style_base\"></div>";
     $r .= "<div style=\"float:left; width: 80px\">&nbsp;$s%</div>"; 
-    $r .= "<br>";
+    $r .= "</nobr>";
+    $r .= "<br />";
 
     return $r; 
@@ -209,22 +333,12 @@
 sub check_status_all
 {
-    my $file_central = &util::filename_cat($gsdl_tmp_dir,"file-central.txt");
+    my $file_central = get_file_central_filename();
 
     my $html = "";
 
-    if (open my $FC, '<', $file_central) {
-	# Read entire file in all at once
-	my $file_list_str = do { local $/; <$FC> };
-	my @file_list = split(/\n/,$file_list_str);
-
-	foreach my $f (@file_list) {
-	    $html .= check_status_single_file($f);
-	}
-
-	close ($FC); 
-    }
-    else {
-	# error
-	$html = "Failed to open $file_central: $!\n";
+    my $fc_list = read_file_central();
+
+    foreach my $f (@$fc_list) {
+	$html .= check_status_single_file($f);
     }
 
@@ -243,5 +357,6 @@
 
     my $filename = $gsdl_cgi->param('uploadedfile');
-    if (defined $filename) {
+
+    if ((defined $filename) && ($filename ne "")) {
 	$html .= check_status_single_file($filename);
     }
