Index: sj-extracting.c
===================================================================
RCS file: /cvs/gnome/sound-juicer/src/sj-extracting.c,v
retrieving revision 1.49
diff -u -r1.49 sj-extracting.c
--- sj-extracting.c	1 Feb 2005 22:05:53 -0000	1.49
+++ sj-extracting.c	7 Feb 2005 07:30:57 -0000
@@ -40,6 +40,9 @@
 #include "sj-extracting.h"
 #include "sj-util.h"
 
+static int mode;
+static int ret;
+
 typedef struct {
   int seconds;
   struct timeval time;
@@ -47,6 +50,12 @@
   int taken;
 } Progress;
 
+typedef enum {
+	OVERWRITE_ALL = 1,
+	SKIP_ALL = 2,
+	NORMAL = 3
+} Modes;
+
 /** If this module has been initialised yet. */
 static gboolean initialised = FALSE;
 
@@ -170,7 +179,7 @@
  * Check if a file exists, can be written to, etc.
  * Return true on continue, false on skip.
  */
-static gboolean
+static int
 check_for_file (const char* filename)
 {
   struct stat stats;
@@ -201,13 +210,39 @@
   g_free (utf8_filename);
   gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Skip"), GTK_RESPONSE_CANCEL);
   gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Overwrite"), GTK_RESPONSE_ACCEPT);
+  gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Cancel Ripping"), GTK_RESPONSE_YES);
+  gtk_dialog_add_button (GTK_DIALOG (dialog), _("Overwrite _All"), GTK_RESPONSE_NO);
+  gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Ignore All"), GTK_RESPONSE_OK);
+
   gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
   gtk_widget_show_all (dialog);
   ret = gtk_dialog_run (GTK_DIALOG (dialog));
   gtk_widget_destroy (dialog);
-  return ret == GTK_RESPONSE_ACCEPT;
+return ret;
 }
 
+static int
+check_for_file1 (const char* filename)
+{
+  struct stat stats;
+  int ret;
+
+  ret = stat (filename, &stats);
+  if (ret == -1) {
+    if (errno == ENOENT) {
+      return TRUE;
+    }
+    g_warning ("stat failed: %s", g_strerror (errno));
+    return FALSE;
+  }
+  if (stats.st_size < (100000)) {
+    /* The file exists but is small, assume overwriting */
+    return TRUE;
+  }
+  ret= GTK_RESPONSE_CANCEL;
+  return ret ;
+ }
+
 /**
  * Find the name of the directory this file is in, create it, and return the
  * directory.
@@ -236,7 +271,7 @@
  * update the UI, and start the extractor.
  */
 static void
-pop_and_extract (void)
+pop_and_extract (int *mode)
 {
   if (pending == NULL) {
     g_assert_not_reached ();
@@ -272,10 +307,40 @@
     /* Save the directory name for later */
     paths = g_list_append (paths, directory);
     /* See if the file exists */
-    if (!check_for_file (file_path)) {
-      on_completion_cb (NULL, NULL);
-      return;
-    }
+	if (*mode != OVERWRITE_ALL)
+	{
+	if (*mode == SKIP_ALL)
+	ret = check_for_file1 (file_path);
+	}
+	if (*mode == NORMAL)
+	ret= check_for_file (file_path);
+			
+    if (ret == GTK_RESPONSE_CANCEL){
+	/* SKIP */
+        on_completion_cb (NULL, mode);
+        return;
+	}
+
+    if (ret == GTK_RESPONSE_OK){
+	/* SKIP ALL */
+	*mode = SKIP_ALL;
+        on_completion_cb (NULL, mode);
+        return;
+  	}
+
+    else if (ret == GTK_RESPONSE_NO) {
+	/*Overwrite ALL*/
+	*mode = OVERWRITE_ALL;
+	}
+   else if (ret == GTK_RESPONSE_YES) {
+	/* Cancel Ripping */
+	sj_extractor_cancel_extract (extractor);
+	cleanup ();
+	gtk_widget_hide (progress_dialog);
+	extracting = FALSE;
+	return;	
+	}
+ 
 
     /* Update the progress bars */
     gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (track_progress), 0);
@@ -495,7 +560,7 @@
     /* Increment the duration */
     current_duration += track->duration;
     /* And go and do it all again */
-    pop_and_extract ();
+    pop_and_extract ((int*)data);
   }
 }
 
@@ -549,6 +614,7 @@
   total_extracting = 0;
   current_duration = total_duration = 0;
   before.seconds = -1;
+  mode = NORMAL;
   gtk_tree_model_foreach (GTK_TREE_MODEL (track_store), extract_track_foreach_cb, NULL);
   /* If the pending list is still empty, return */
   if (pending == NULL) {
@@ -561,7 +627,7 @@
   if (!initialised) {
     /* Connect to the SjExtractor signals */
     g_signal_connect (extractor, "progress", G_CALLBACK (on_progress_cb), NULL);
-    g_signal_connect (extractor, "completion", G_CALLBACK (on_completion_cb), NULL);
+    g_signal_connect (extractor, "completion", G_CALLBACK (on_completion_cb), (gpointer)&mode);
     g_signal_connect (extractor, "error", G_CALLBACK (on_error_cb), NULL);
 
     /* Get the progress dialog */
@@ -611,7 +677,7 @@
   
   /* Start the extracting */
   extracting = TRUE;
-  pop_and_extract ();
+  pop_and_extract (&mode);
 }
 
 /*
