Index: sj-extracting.c
===================================================================
RCS file: /cvs/gnome/sound-juicer/src/sj-extracting.c,v
retrieving revision 1.48
diff -u -r1.48 sj-extracting.c
--- sj-extracting.c	5 Jan 2005 10:23:29 -0000	1.48
+++ sj-extracting.c	29 Jan 2005 18:00:00 -0000
@@ -40,6 +40,11 @@
 #include "sj-extracting.h"
 #include "sj-util.h"
 
+#define playlist 0 /* In playlist mode,playlist file is created*/
+#define no_list 1 /* In no_list mode, playlist file is not created*/
+
+static int mode;
+
 typedef struct {
   int seconds;
   struct timeval time;
@@ -236,7 +241,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 ();
@@ -244,12 +249,36 @@
     char *file_path, *directory;
     GError *error = NULL;
     char *text;
-    
+    static int no_of_times;
+    char *filename;	
+
+    FILE *fp;
     /* Pop the next track to extract */
     track = pending->data;
+
     pending = g_list_remove (pending, track);
     /* Build the filename for this track */
+
     file_path = build_filename (track);
+    
+    /* Building Playlist */
+    if (*mode == playlist)
+    {
+    filename = g_build_filename (base_path,g_strconcat(track->album->title,".m3u"), NULL);
+	    if (no_of_times == 0){
+	        fp=fopen(filename,"w");
+	    	fprintf(fp,"%s\n","#EXTM3U");
+		}
+	    else
+	        {
+		fp=fopen(filename,"a+");
+		}
+    no_of_times ++;	
+    fprintf(fp,"%s:%d,%s\n","#EXTINF",track->duration,track->title);
+    fprintf(fp,"%s\n",file_path);
+    fclose(fp); 	
+	}
+
     /* And create the directory it lives in */
     directory = create_directory_for (file_path, &error);
     if (error) {
@@ -273,7 +302,7 @@
     paths = g_list_append (paths, directory);
     /* See if the file exists */
     if (!check_for_file (file_path)) {
-      on_completion_cb (NULL, NULL);
+      on_completion_cb (NULL, mode);
       return;
     }
 
@@ -494,7 +523,7 @@
     /* Increment the duration */
     current_duration += track->duration;
     /* And go and do it all again */
-    pop_and_extract ();
+    pop_and_extract ((int*)data);
   }
 }
 
@@ -543,6 +572,8 @@
 void
 on_extract_activate (GtkWidget *button, gpointer user_data)
 {
+  int ret;
+  GtkWidget *dialog;
   /* Populate the pending list */
   pending = NULL;
   total_extracting = 0;
@@ -556,11 +587,30 @@
     return;
   }
 
+  /* Creating Dialog to determine playlist should be created or not*/
+  dialog = gtk_message_dialog_new (GTK_WINDOW (main_window), GTK_DIALOG_MODAL,
+                                   GTK_MESSAGE_QUESTION,
+                                   GTK_BUTTONS_NONE,
+                                   _("Do u want to create Playlist file?"));
+
+  gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Yes"), GTK_RESPONSE_ACCEPT);
+  gtk_dialog_add_button (GTK_DIALOG (dialog), _("_No"), GTK_RESPONSE_CANCEL);
+  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);
+  if (ret == GTK_RESPONSE_ACCEPT)
+	{
+	mode = playlist;
+	}
+	else 
+	mode =no_list;
+
   /* Initialise ourself */
   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 */
@@ -610,7 +660,7 @@
   
   /* Start the extracting */
   extracting = TRUE;
-  pop_and_extract ();
+  pop_and_extract (&mode); 
 }
 
 /*
