Index: /trunk/gli/src/org/greenstone/gatherer/GathererApplet.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/GathererApplet.java	(revision 9094)
+++ /trunk/gli/src/org/greenstone/gatherer/GathererApplet.java	(revision 9095)
@@ -42,4 +42,5 @@
 import org.greenstone.gatherer.gui.GUIManager;
 import org.greenstone.gatherer.util.Utility;
+import org.greenstone.gatherer.shell.GShell;
 
 
@@ -208,5 +209,5 @@
 
 
-    static public void download_url_zip(String col_name, String dir)
+    static public void download_url_zip(String col_name, String dir, GShell source)
     {
 	try {
@@ -247,5 +248,5 @@
 	    int len;
 
-	    while ((len = dl_dbis.read(buf)) >= 0) {
+	    while ((len = dl_dbis.read(buf)) >= 0 && !source.hasSignalledStop()) {
 		zip_bfos.write(buf,0,len);
 	    }
@@ -261,5 +262,5 @@
 
 
-    static public void upload_url_zip(String col_name, String dir)
+    static public void upload_url_zip(String col_name, String dir, GShell source)
     {
 	final String lineEnd = "\r\n";
@@ -320,6 +321,10 @@
 	    // read file and write it into form...
 	    int bytesRead = fileInputStream.read(buffer, 0, bufferSize);
-	    
+
 	    while (bytesRead > 0) {
+		// Check to see if action has been cancelled.
+		if (source != null && source.hasSignalledStop()) {
+		    break;
+		}
 		dos.write(buffer, 0, bufferSize);
 		bytesAvailable = fileInputStream.available();
Index: /trunk/gli/src/org/greenstone/gatherer/cdm/CollectionDesignManager.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/cdm/CollectionDesignManager.java	(revision 9094)
+++ /trunk/gli/src/org/greenstone/gatherer/cdm/CollectionDesignManager.java	(revision 9095)
@@ -216,6 +216,6 @@
 	    if (formats_changed && Gatherer.c_man.built()) {
 		// upload etc/collect.cfg to server to reflect changes
-		Utility.zipup(Gatherer.getCollectDirectoryPath(), collection_name, Utility.CONFIG_FILE);
-		GathererApplet.upload_url_zip(collection_name, "etc");
+		Utility.zipup(Gatherer.getCollectDirectoryPath(), collection_name, Utility.CONFIG_FILE, null);
+		GathererApplet.upload_url_zip(collection_name, "etc", null);
 	    }
 	}
Index: /trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java	(revision 9094)
+++ /trunk/gli/src/org/greenstone/gatherer/collection/CollectionManager.java	(revision 9095)
@@ -1066,5 +1066,9 @@
 	    }
 	}
-	else if(event.getStatus() == GShell.ERROR || event.getStatus() == GShell.CANCELLED) {
+	else if (event.getStatus() == GShell.CANCELLED) {
+	    JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("CollectionManager.Build_Cancelled"), Dictionary.get("General.Error"), JOptionPane.ERROR_MESSAGE);
+	    Gatherer.g_man.repaint();
+	}
+	else if (event.getStatus() == GShell.ERROR) {
 	    DebugStream.println("There was an error in the gshell:"+ event.getMessage());
 	    if (event.getType() == GShell.NEW) {
Index: /trunk/gli/src/org/greenstone/gatherer/shell/GShell.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/shell/GShell.java	(revision 9094)
+++ /trunk/gli/src/org/greenstone/gatherer/shell/GShell.java	(revision 9095)
@@ -227,21 +227,80 @@
     protected void runRemote(String[] args, BufferedOutputStream bos) 
     {
+	if(hasSignalledStop()) { return; }
+	int error_count = 0;
+	StringBuffer error_list = new StringBuffer();
 	try {
-
+	    if (type == IMPORT) {
+		String col_name = args[args.length-1];
+		if (progress!=null) {
+		    progress.messageOnProgressBar("Uploading data to server");
+		}
+
+		String collect_directory_path = Gatherer.getCollectDirectoryPath();
+		
+		// zip up import folder
+		Utility.zipup(collect_directory_path, col_name, "import", this);
+
+		if(hasSignalledStop()) { return; }
+		// upload it to gsdl server
+		GathererApplet.upload_url_zip(col_name, "import", this);
+
+		if(hasSignalledStop()) { return; }
+		// upload etc folder to server (need collect.cfg and any hfiles)
+		Utility.zipup(collect_directory_path, col_name, "etc", this);
+
+		if(hasSignalledStop()) { return; }
+		GathererApplet.upload_url_zip(col_name, "etc", this);
+
+		String collection_directory_path = Gatherer.c_man.getCollectionDirectoryPath(col_name);
+		File img_dir = new File(Gatherer.c_man.getCollectionImagesDirectoryPath());
+		if (img_dir.exists() && img_dir.list().length > 0) {
+		    // upload images/ directory to server
+		    if(hasSignalledStop()) { return; }
+		    Utility.zipup(collect_directory_path, col_name, "images", this);
+
+		    if(hasSignalledStop()) { return; }
+		    GathererApplet.upload_url_zip(col_name, "images", this);		    
+		}
+
+		if(hasSignalledStop()) { return; }
+		// see if collection specific image needs uploading
+		CollectionMetaManager cmm 
+		    = CollectionDesignManager.collectionmeta_manager;
+		
+		CollectionMeta icon_collection_collectionmeta 
+		    = cmm.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTION_STR);
+		CollectionMeta icon_collection_small_collectionmeta 
+		    = cmm.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR);
+		
+		String ics_text = icon_collection_collectionmeta.getValue(CollectionMeta.TEXT);
+		String icsc_text = icon_collection_small_collectionmeta.getValue(CollectionMeta.TEXT);
+		if ((ics_text != null) && (ics_text != "")) {
+		    // Stub code for detecting when collectoin image changed
+		    // => need to upload images
+		    // System.err.println("**** ics_text = " + ics_text);
+		}
+		
+		if (progress!=null) {
+		    progress.messageOnProgressBar("");
+		}
+	    }
+	    
+	    if(hasSignalledStop()) { return; }
 	    String perl_cmd = args[0];
 	    int perl_cmd_root = perl_cmd.lastIndexOf(File.separator);
-		
+	    
 	    if (perl_cmd_root > 0) {
 		String perl_cmd_cut = perl_cmd.substring(perl_cmd_root+1);
 		perl_cmd = perl_cmd_cut;
 	    }
-
+	    
 	    String launch  = Gatherer.cgiBase + "launch";
 	    launch = launch + "?cmd=" + perl_cmd;
-
+	    
 	    for(int i = 1; i<args.length; i++) {
-		    
+		
 		String arg = args[i];
-
+		
 		if (arg.equals("-collectdir") || arg.equals("-importdir")
 		    || arg.equals("-builddir")) {
@@ -250,7 +309,7 @@
 		    continue;
 		}
-	    
+		
 		launch += "&";
-	    
+		
 		if(arg.startsWith(StaticStrings.MINUS_CHARACTER)) {
 		    String name = arg.substring(1);
@@ -268,18 +327,15 @@
 		}
 	    }
-
+	    
 	    System.err.println("**** launch url = " + launch);
 	    // fireMessage(type, Dictionary.get("GShell.Command") + ": " + launch, status, null); // ****
-
+	    
 	    URL launch_url = new URL(launch);
 	    URLConnection launch_connection = launch_url.openConnection();
 	    InputStream stdis = launch_connection.getInputStream();
 	    InputStreamReader stdisr = new InputStreamReader(stdis, "UTF-8");
-	
+	    
 	    BufferedReader stdbr = new BufferedReader(stdisr);
-	
-	    StringBuffer error_list = new StringBuffer();
-	    int error_count = 0;
-
+	    
 	    if (type == GShell.NEW) {
 		while(true) {
@@ -295,8 +351,9 @@
 		    error_count = check_for_error(line,error_list,error_count);
 		    fireMessage(type, typeAsString(type) + "> " + line, status, bos);
-		}		
+		}
+		System.err.println("Wants to stop (1)."); 
 	    }
 	    stdbr.close();
-	
+	    
 	    if (error_count>0) {
 		status = ERROR;
@@ -305,4 +362,8 @@
 		    fireMessage(type, typeAsString(type) + "> " + error_list, status, null);
 		}
+	    }
+	    else if(hasSignalledStop()) {
+		//User pressed the cancel button.
+		//Status already set in hasSignalledStop method.
 	    }
 	    else {
@@ -458,55 +519,4 @@
 	}
 
-	if (Gatherer.isGsdlRemote) {
-	    if (type == IMPORT) {
-		if (progress!=null) {
-		    progress.messageOnProgressBar("Uploading data to server");
-		}
-
-		String collect_directory_path = Gatherer.getCollectDirectoryPath();
-
-		// zip up import folder
-		Utility.zipup(collect_directory_path, col_name, "import");
-		// upload it to gsdl server
-		GathererApplet.upload_url_zip(col_name, "import");
-
-		// upload etc folder to server (need collect.cfg and any hfiles)
-		Utility.zipup(collect_directory_path, col_name, "etc");
-		GathererApplet.upload_url_zip(col_name, "etc");
-
-		String collection_directory_path = Gatherer.c_man.getCollectionDirectoryPath(col_name);
-		File img_dir = new File(Gatherer.c_man.getCollectionImagesDirectoryPath());
-		if (img_dir.exists() && img_dir.list().length > 0) {
-		    // upload images/ directory to server
-		    Utility.zipup(collect_directory_path, col_name, "images");
-		    GathererApplet.upload_url_zip(col_name, "images");
-		}
-
-		// see if collection specific image needs uploading
-		CollectionMetaManager cmm 
-		    = CollectionDesignManager.collectionmeta_manager;
-
-		CollectionMeta icon_collection_collectionmeta 
-		    = cmm.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTION_STR);
-		CollectionMeta icon_collection_small_collectionmeta 
-		    = cmm.getMetadatum(CollectionConfiguration.COLLECTIONMETADATA_ICONCOLLECTIONSMALL_STR);
-
-		String ics_text = icon_collection_collectionmeta.getValue(CollectionMeta.TEXT);
-		String icsc_text = icon_collection_small_collectionmeta.getValue(CollectionMeta.TEXT);
-		if ((ics_text != null) && (ics_text != "")) {
-		    // Stub code for detecting when collectoin image changed
-		    // => need to upload images
-		    // System.err.println("**** ics_text = " + ics_text);
-		}
-
-
-		if (progress!=null) {
-		    progress.messageOnProgressBar("");
-		}
-
-	    }
-	}
-
-
 	// Issue a processBegun event
 	fireProcessBegun(type, status);
@@ -521,6 +531,8 @@
 	    if (type == NEW) {
 		if (Gatherer.isGsdlRemote) {
-		    GathererApplet.download_url_zip(col_name,".");
-		    Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name);
+		    GathererApplet.download_url_zip(col_name, ".", this);
+		    if (!hasSignalledStop()) {
+			Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name);
+		    }
 		}
 	    }
@@ -535,10 +547,11 @@
 
 		    Utility.delete(Gatherer.c_man.getCollectionArchivesDirectoryPath()); // remove current archives
-		    GathererApplet.download_url_zip(col_name,"archives");
-		    Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name);
-
-		    if (progress!=null) {
-			progress.messageOnProgressBar("");
-		    }
+		    GathererApplet.download_url_zip(col_name, "archives", this);
+		       if (!hasSignalledStop()) {
+			   Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name);
+		       }
+		       if (progress!=null) {
+			   progress.messageOnProgressBar("");
+		       }      
 		}
 
@@ -560,7 +573,9 @@
  		    Utility.delete(buildDir); // remove current build dir
 		    buildDir.mkdir(); //Make a clean dir
- 		    GathererApplet.download_url_zip(col_name,"building/build.cfg"); //Only need build.cfg
- 		    Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name);
-
+ 		    GathererApplet.download_url_zip(col_name, "building/build.cfg", this); //Only need build.cfg
+		    if (!hasSignalledStop()) {
+			Utility.unzip(Gatherer.getCollectDirectoryPath(), col_name);
+		    }
+		    
  		    if (progress!=null) {
  			progress.messageOnProgressBar("");
@@ -570,7 +585,4 @@
 	}
 
-	if(hasSignalledStop()) {
-	    status = CANCELLED;
-	}
 	// We're done.
 	fireProcessComplete(type, status);
@@ -678,8 +690,11 @@
      * @return A <strong>boolean</strong> indicating if the user wanted to stop.
      */
-    private boolean hasSignalledStop() {
+    public boolean hasSignalledStop() {
 	boolean has_signalled_stop = false;
 	if(progress != null) {
 	    has_signalled_stop = progress.hasSignalledStop();
+	}
+	if(has_signalled_stop) {
+	    status = CANCELLED;
 	}
 	return has_signalled_stop;
Index: /trunk/gli/src/org/greenstone/gatherer/util/Utility.java
===================================================================
--- /trunk/gli/src/org/greenstone/gatherer/util/Utility.java	(revision 9094)
+++ /trunk/gli/src/org/greenstone/gatherer/util/Utility.java	(revision 9095)
@@ -49,4 +49,5 @@
 import org.greenstone.gatherer.DebugStream;
 import org.greenstone.gatherer.Dictionary;
+import org.greenstone.gatherer.shell.GShell;
 // Don't even think about adding import org.greenstone.gatherer.Gatherer in here!
 // The functions in this class should be independent of the Gatherer class. Put your function somewhere else buster!
@@ -601,8 +602,12 @@
     }
 
-    static protected void zipFunc (ZipOutputStream zos, String file_path, int prefix_strip) 
+    static protected void zipFunc (ZipOutputStream zos, String file_path, int prefix_strip, GShell source) 
     {
 	// Using try is required because of file io.
 	try {
+	    // Exit if pressed cancel.
+	    if (source != null && source.hasSignalledStop()) {
+		return;
+	    }
 	    // Create a Zip Entry and put it into the archive (no data yet).
 
@@ -624,4 +629,10 @@
 	    // to the zip output stream until the bis has been entirely read.
 	    while ((byteCount = bis.read(data, 0, 1024)) > -1) {
+		//Check for cancell
+		if(source != null) {
+		    if(source.hasSignalledStop()) {
+			break;
+		    }
+		}
 		zos.write(data, 0, byteCount);
 	    }
@@ -634,5 +645,5 @@
     }
 
-    static protected void dirFunc (ZipOutputStream zos, String dir_name, int prefix_strip) 
+    static protected void dirFunc (ZipOutputStream zos, String dir_name, int prefix_strip, GShell source) 
     {
 	File dirObj = new File(dir_name);
@@ -645,4 +656,9 @@
 		// Loop through File array and display.
 		for (int i = 0; i < fileList.length; i++) {
+		    if(source != null) {
+			if(source.hasSignalledStop()) {
+			    break;
+			}
+		    }
 		    File file = fileList[i];
 		    if (file.isDirectory()) {
@@ -661,9 +677,9 @@
 			}
 
-			dirFunc(zos,dir_path,prefix_strip);
+			dirFunc(zos,dir_path,prefix_strip, source);
 		    } else if (file.isFile()) {
 			// Call the zipFunc function
 			String file_path = fileList[i].getPath();
-			zipFunc(zos,file_path,prefix_strip);
+			zipFunc(zos,file_path,prefix_strip, source);
 		    }
 		} 
@@ -680,5 +696,5 @@
 
 
-    static public void zipup(String col_dir, String col_name, String dir_or_file)
+    static public void zipup(String col_dir, String col_name, String dir_or_file, GShell source)
     {
 	int prefix_strip = col_dir.length();
@@ -695,5 +711,5 @@
 		if (zip_dof.isDirectory()) {
 		    String zip_dir = zip_dir_or_file;
-		    dirFunc(zos,zip_dir,prefix_strip);
+		    dirFunc(zos,zip_dir,prefix_strip, source);
 		}
 		else {
@@ -714,5 +730,5 @@
 			}
 		    }
-		    zipFunc(zos,zip_full_file,prefix_strip);
+		    zipFunc(zos,zip_full_file,prefix_strip, source);
 		}
 	    }
@@ -728,5 +744,5 @@
 	catch (IOException exception) {
 	    DebugStream.printStackTrace(exception);
-	} 
+	}
     } 
     
