[Xfce4-commits] <xfburn:master> Autodetect write mode by default, reorganize the burning code for images

David Mohr noreply at xfce.org
Fri Oct 30 04:28:01 CET 2009


Updating branch refs/heads/master
         to b5cafcee7ed9f0ff802f24c250a59a490f6df4db (commit)
       from 10efef06c1507037a09148a55b9ec521701eeb23 (commit)

commit b5cafcee7ed9f0ff802f24c250a59a490f6df4db
Author: David Mohr <squisher at xfce.org>
Date:   Thu Oct 29 21:25:55 2009 -0600

    Autodetect write mode by default, reorganize the burning code for images

 xfburn/xfburn-burn-audio-cd-composition-dialog.c  |   39 +---
 xfburn/xfburn-burn-data-composition-base-dialog.c |   48 ++----
 xfburn/xfburn-burn-image-dialog.c                 |  207 +++++++++++----------
 xfburn/xfburn-device-box.c                        |    3 +
 xfburn/xfburn-device-box.h                        |    1 +
 xfburn/xfburn-perform-burn.c                      |   63 +++++++
 xfburn/xfburn-perform-burn.h                      |    3 +
 7 files changed, 203 insertions(+), 161 deletions(-)

diff --git a/xfburn/xfburn-burn-audio-cd-composition-dialog.c b/xfburn/xfburn-burn-audio-cd-composition-dialog.c
index 197b0f8..b015703 100644
--- a/xfburn/xfburn-burn-audio-cd-composition-dialog.c
+++ b/xfburn/xfburn-burn-audio-cd-composition-dialog.c
@@ -320,36 +320,19 @@ thread_burn_prep_and_burn (ThreadBurnCompositionParams * params, struct burn_dri
   burn_options = burn_write_opts_new (drive);
   burn_write_opts_set_perform_opc (burn_options, 0);
   burn_write_opts_set_multi (burn_options, 0);
+  burn_write_opts_set_simulate(burn_options, params->dummy ? 1 : 0);
+  burn_write_opts_set_underrun_proof (burn_options, params->burnfree ? 1 : 0);
 
-  /* keep all modes here, just in case we want to change the default sometimes */
-  switch (params->write_mode) {
-  case WRITE_MODE_TAO:
-    burn_write_opts_set_write_type (burn_options, BURN_WRITE_TAO, BURN_BLOCK_MODE1);
-    break;
-  case WRITE_MODE_SAO:
-    burn_write_opts_set_write_type (burn_options, BURN_WRITE_SAO, BURN_BLOCK_SAO);
-    break;
-  case WRITE_MODE_RAW16:
-    burn_write_opts_set_write_type (burn_options, BURN_WRITE_RAW, BURN_BLOCK_RAW16);
-    break;
-  case WRITE_MODE_RAW96P:
-    burn_write_opts_set_write_type (burn_options, BURN_WRITE_RAW, BURN_BLOCK_RAW96P);
-    break;
-  case WRITE_MODE_RAW96R:
-    burn_write_opts_set_write_type (burn_options, BURN_WRITE_RAW, BURN_BLOCK_RAW96R);
-    break;
-  default:
+  if (!xfburn_set_write_mode (burn_options, params->write_mode, disc, WRITE_MODE_SAO)) {
     xfburn_progress_dialog_burning_failed (XFBURN_PROGRESS_DIALOG (dialog_progress), _("The write mode is not supported currently."));
-    return;
-  }
+  } else {
 
-  burn_write_opts_set_simulate(burn_options, params->dummy ? 1 : 0);
-  DBG ("Set speed to %d kb/s", params->speed);
-  burn_drive_set_speed (drive, 0, params->speed);
-  burn_write_opts_set_underrun_proof (burn_options, params->burnfree ? 1 : 0);
-  burn_drive_set_buffer_waiting (drive, 1, -1, -1, -1, 75, 95);
+    DBG ("Set speed to %d kb/s", params->speed);
+    burn_drive_set_speed (drive, 0, params->speed);
+    burn_drive_set_buffer_waiting (drive, 1, -1, -1, -1, 75, 95);
 
-  xfburn_perform_burn_write (dialog_progress, drive, params->write_mode, burn_options, AUDIO_BYTES_PER_SECTOR, disc, srcs, track_sectors);
+    xfburn_perform_burn_write (dialog_progress, drive, params->write_mode, burn_options, AUDIO_BYTES_PER_SECTOR, disc, srcs, track_sectors);
+  }
 
   burn_write_opts_free (burn_options);
 }
@@ -464,8 +447,8 @@ cb_dialog_response (XfburnBurnAudioCdCompositionDialog * dialog, gint response_i
 
     device = xfburn_device_box_get_selected_device (XFBURN_DEVICE_BOX (priv->device_box));
     speed = xfburn_device_box_get_speed (XFBURN_DEVICE_BOX (priv->device_box));
-    /* cdrskin burns audio with SAO */
-    write_mode = WRITE_MODE_SAO;
+    /* cdrskin burns audio with SAO, but we assume auto knows that */
+    write_mode = WRITE_MODE_AUTO;
 
     /* burn composition */
     params = g_new0 (ThreadBurnCompositionParams, 1);
diff --git a/xfburn/xfburn-burn-data-composition-base-dialog.c b/xfburn/xfburn-burn-data-composition-base-dialog.c
index 35d8a94..e05a9b9 100644
--- a/xfburn/xfburn-burn-data-composition-base-dialog.c
+++ b/xfburn/xfburn-burn-data-composition-base-dialog.c
@@ -560,48 +560,32 @@ thread_burn_prep_and_burn (ThreadBurnCompositionParams * params, struct burn_dri
   burn_options = burn_write_opts_new (drive);
   burn_write_opts_set_perform_opc (burn_options, 0);
   burn_write_opts_set_multi (burn_options, 0);
-
-  switch (params->write_mode) {
-  case WRITE_MODE_TAO:
-    burn_write_opts_set_write_type (burn_options, BURN_WRITE_TAO, BURN_BLOCK_MODE1);
-    break;
-  case WRITE_MODE_SAO:
-    burn_write_opts_set_write_type (burn_options, BURN_WRITE_SAO, BURN_BLOCK_SAO);
-    break;
-  case WRITE_MODE_RAW16:
-    burn_write_opts_set_write_type (burn_options, BURN_WRITE_RAW, BURN_BLOCK_RAW16);
-    break;
-  case WRITE_MODE_RAW96P:
-    burn_write_opts_set_write_type (burn_options, BURN_WRITE_RAW, BURN_BLOCK_RAW96P);
-    break;
-  case WRITE_MODE_RAW96R:
-    burn_write_opts_set_write_type (burn_options, BURN_WRITE_RAW, BURN_BLOCK_RAW96R);
-    break;
-  default:
-    xfburn_progress_dialog_burning_failed (XFBURN_PROGRESS_DIALOG (dialog_progress), _("The write mode is not supported currently."));
-    return;
-  }
-
   /* enable this when there is some time for testing
   DBG ("Enabling multisession");
   burn_write_opts_set_multi(burn_options, 1);
   */
   burn_write_opts_set_simulate(burn_options, params->dummy ? 1 : 0);
-  DBG ("Set speed to %d kb/s", params->speed);
-  burn_drive_set_speed (drive, 0, params->speed);
   burn_write_opts_set_underrun_proof (burn_options, params->burnfree ? 1 : 0);
 
-  sectors[0] = burn_disc_get_sectors (disc);
+  if (!xfburn_set_write_mode (burn_options, params->write_mode, disc, WRITE_MODE_TAO)) {
+    xfburn_progress_dialog_burning_failed (XFBURN_PROGRESS_DIALOG (dialog_progress), _("The write mode is not supported currently."));
+  } else {
 
-  if (params->is_fifo) {
-    fifos = g_new(struct burn_source *,1);
-    fifos[0] = params->src;
-  }
+    DBG ("Set speed to %d kb/s", params->speed);
+    burn_drive_set_speed (drive, 0, params->speed);
 
-  xfburn_perform_burn_write (dialog_progress, drive, params->write_mode, burn_options, DATA_BYTES_PER_SECTOR, disc, fifos, sectors);
+    sectors[0] = burn_disc_get_sectors (disc);
 
-  if (params->is_fifo) {
-    g_free (fifos);
+    if (params->is_fifo) {
+      fifos = g_new(struct burn_source *,1);
+      fifos[0] = params->src;
+    }
+
+    xfburn_perform_burn_write (dialog_progress, drive, params->write_mode, burn_options, DATA_BYTES_PER_SECTOR, disc, fifos, sectors);
+
+    if (params->is_fifo) {
+      g_free (fifos);
+    }
   }
 
   burn_write_opts_free (burn_options);
diff --git a/xfburn/xfburn-burn-image-dialog.c b/xfburn/xfburn-burn-image-dialog.c
index 79a9320..2a78ad3 100644
--- a/xfburn/xfburn-burn-image-dialog.c
+++ b/xfburn/xfburn-burn-image-dialog.c
@@ -50,6 +50,13 @@ typedef struct {
   gboolean eject;
   gboolean dummy;
   gboolean burnfree;
+
+  struct burn_disc *disc;
+  struct burn_session *session;
+  struct burn_track *track;
+  struct burn_source *fifo_src;
+  struct burn_write_opts * burn_options;
+
 } ThreadBurnIsoParams;
 
 typedef struct
@@ -76,15 +83,21 @@ static void xfburn_burn_image_dialog_class_init (XfburnBurnImageDialogClass * kl
 static void xfburn_burn_image_dialog_init (XfburnBurnImageDialog * sp);
 static void xfburn_burn_image_dialog_finalize (GObject *object);
 
+/* internal prototypes */
 void burn_image_dialog_error (XfburnBurnImageDialog * dialog, const gchar * msg_error);
 static void cb_volume_change_end (XfburnDeviceList *devlist, gboolean device_changed, XfburnDevice *device, XfburnBurnImageDialog * dialog);
 static void cb_dialog_response (XfburnBurnImageDialog * dialog, gint response_id, gpointer user_data);
 
 static void update_image_label (GtkFileChooser *chooser, XfburnBurnImageDialog * dialog);
 static void check_burn_button (XfburnBurnImageDialog * dialog);
-static gboolean check_media (XfburnBurnImageDialog * dialog, ThreadBurnIsoParams *params, struct burn_drive *drive, struct burn_write_opts * burn_options);
+static gboolean check_media (XfburnBurnImageDialog * dialog, ThreadBurnIsoParams *params, struct burn_drive *drive);
 static void cb_clicked_ok (GtkButton * button, gpointer user_data);
 
+static void free_params (ThreadBurnIsoParams *params);
+static gboolean prepare_params (ThreadBurnIsoParams *params, struct burn_drive *drive, gchar **failure_msg);
+static gboolean create_disc (ThreadBurnIsoParams *params, gchar **failure_msg);
+static void thread_burn_iso (ThreadBurnIsoParams * params);
+
 /*********************/
 /* class declaration */
 /*********************/
@@ -242,78 +255,75 @@ xfburn_burn_image_dialog_finalize (GObject *object)
 /*************/
 /* internals */
 /*************/
-static struct burn_write_opts * 
-make_burn_options(ThreadBurnIsoParams *params, struct burn_drive *drive) {
+static gboolean 
+prepare_params (ThreadBurnIsoParams *params, struct burn_drive *drive, gchar **failure_msg)
+{
   struct burn_write_opts * burn_options;
 
   burn_options = burn_write_opts_new (drive);
   burn_write_opts_set_perform_opc (burn_options, 0);
   burn_write_opts_set_multi (burn_options, 0);
+  burn_write_opts_set_simulate(burn_options, params->dummy ? 1 : 0);
+  burn_write_opts_set_underrun_proof (burn_options, params->burnfree ? 1 : 0);
 
-  switch (params->write_mode) {
-  case WRITE_MODE_TAO:
-    burn_write_opts_set_write_type (burn_options, BURN_WRITE_TAO, BURN_BLOCK_MODE1);
-    break;
-  case WRITE_MODE_SAO:
-    burn_write_opts_set_write_type (burn_options, BURN_WRITE_SAO, BURN_BLOCK_SAO);
-    break;
-  /*
-  case WRITE_MODE_RAW16:
-    burn_write_opts_set_write_type (burn_options, BURN_WRITE_RAW, BURN_BLOCK_RAW16);
-    break;
-  case WRITE_MODE_RAW96P:
-    burn_write_opts_set_write_type (burn_options, BURN_WRITE_RAW, BURN_BLOCK_RAW96P);
-    break;
-  case WRITE_MODE_RAW96R:
-    burn_write_opts_set_write_type (burn_options, BURN_WRITE_RAW, BURN_BLOCK_RAW96R);
-    break;
-  */
-  default:
+  if (!xfburn_set_write_mode (burn_options, params->write_mode, params->disc, WRITE_MODE_TAO)) {
     burn_write_opts_free (burn_options);
-    return NULL;
+    *failure_msg = _("Burn mode is not currently implemented.");
+    return FALSE;
   }
 
-  burn_write_opts_set_simulate(burn_options, params->dummy ? 1 : 0);
-  burn_write_opts_set_underrun_proof (burn_options, params->burnfree ? 1 : 0);
+  params->burn_options = burn_options;
+
+  params->disc = burn_disc_create ();
+  params->session = burn_session_create ();
+  params->track = burn_track_create ();
+
+  if (!create_disc (params, failure_msg)) {
+    return FALSE;
+  }
 
-  return burn_options;
+  return TRUE;
 }
 
 static void
-thread_burn_iso (ThreadBurnIsoParams * params)
+free_params (ThreadBurnIsoParams *params)
 {
-  GtkWidget *dialog_progress = params->dialog_progress;
+  if (params->fifo_src)
+    burn_source_free (params->fifo_src);
 
-  struct burn_disc *disc;
-  struct burn_session *session;
-  struct burn_track *track;
+  if (params->burn_options)
+    burn_write_opts_free (params->burn_options);
+
+  if (params->track)
+    burn_track_free (params->track);
+
+  if (params->session)
+    burn_session_free (params->session);
+
+  if (params->disc)
+    burn_disc_free (params->disc);
 
+  g_free (params->iso_path);
+}
+
+static gboolean
+create_disc (ThreadBurnIsoParams *params, gchar **failure_msg)
+{
   gint fd;
   struct stat stbuf;
   off_t fixed_size = 0;
   struct burn_source *data_src;
-  struct burn_source *fifo_src;
-  int sectors[1];
-
-  struct burn_drive *drive;
-  struct burn_drive_info *drive_info = NULL;
-  struct burn_write_opts * burn_options;
-  struct burn_source **fifos = NULL;
 
   gint ret;
 
-  disc = burn_disc_create ();
-  session = burn_session_create ();
-  track = burn_track_create ();
-
-  ret = burn_disc_add_session (disc, session, BURN_POS_END);
+  ret = burn_disc_add_session (params->disc, params->session, BURN_POS_END);
   if (ret == 0) {
-    g_warning ("Unable to create disc object");
-    xfburn_progress_dialog_burning_failed (XFBURN_PROGRESS_DIALOG (dialog_progress), _("An error occurred in the burn backend"));
-    goto end;
+    g_warning ("Unable to add session to the disc object");
+    *failure_msg = _("An error occurred in the burn backend");
+    return FALSE;
   }
 
-  burn_track_define_data (track, 0, 300*1024, 1, BURN_MODE1);
+  burn_track_define_data (params->track, 0, 300*1024, 1, BURN_MODE1);
 
   fd = open (params->iso_path, O_RDONLY);
   if (fd >= 0)
@@ -322,68 +332,65 @@ thread_burn_iso (ThreadBurnIsoParams * params)
 	fixed_size = stbuf.st_size;
 
   if (fixed_size == 0) {
-    xfburn_progress_dialog_burning_failed (XFBURN_PROGRESS_DIALOG (dialog_progress), _("Unable to determine image size."));
-    goto end;
+    *failure_msg = _("Unable to determine image size.");
+    return FALSE;
   }
 
   data_src = burn_fd_source_new(fd, -1, fixed_size);
 
   if (data_src == NULL) {
-    xfburn_progress_dialog_burning_failed (XFBURN_PROGRESS_DIALOG (dialog_progress), _("Cannot open image."));
-    goto end;
+    *failure_msg = _("Cannot open image.");
+    return FALSE;
   }
 
-  fifo_src = burn_fifo_source_new (data_src, 2048, xfburn_settings_get_int ("fifo-size", FIFO_DEFAULT_SIZE) / 2, 0);
+  params->fifo_src = burn_fifo_source_new (data_src, 2048, xfburn_settings_get_int ("fifo-size", FIFO_DEFAULT_SIZE) / 2, 0);
   burn_source_free (data_src);
 
-  if (burn_track_set_source (track, fifo_src) != BURN_SOURCE_OK) {
+  if (burn_track_set_source (params->track, params->fifo_src) != BURN_SOURCE_OK) {
     g_warning ("Cannot attach source object to track object");
-    xfburn_progress_dialog_burning_failed (XFBURN_PROGRESS_DIALOG (dialog_progress), _("An error occurred in the burn backend"));
-    goto end;
+    *failure_msg = _("An error occurred in the burn backend");
+    return FALSE;
   }
   
-  burn_session_add_track (session, track, BURN_POS_END);
+  burn_session_add_track (params->session, params->track, BURN_POS_END);
 
-  if (!xfburn_device_grab (params->device, &drive_info)) {
-    xfburn_progress_dialog_burning_failed (XFBURN_PROGRESS_DIALOG (dialog_progress), _("Unable to grab the drive."));
+  return TRUE;
+}
 
-    goto end;
-  }
+static void
+thread_burn_iso (ThreadBurnIsoParams * params)
+{
+  GtkWidget *dialog_progress = params->dialog_progress;
 
-  drive = drive_info->drive;
+  struct burn_drive *drive;
+  struct burn_drive_info *drive_info = NULL;
+  struct burn_source **fifos = NULL;
+  int sectors[1];
 
-  burn_options = make_burn_options (params, drive);
-  if (burn_options == NULL) {
-    xfburn_progress_dialog_burning_failed (XFBURN_PROGRESS_DIALOG (dialog_progress), _("Burn mode is not currently implemented."));
-    goto cleanup;
-  }
+  if (xfburn_device_grab (params->device, &drive_info)) {
+    drive = drive_info->drive;
 
-  DBG ("Set speed to %d kb/s", params->speed);
-  burn_drive_set_speed (drive, 0, params->speed);
+    DBG ("Set speed to %d kb/s", params->speed);
+    burn_drive_set_speed (drive, 0, params->speed);
 
-  // this assumes that an iso image can only have one track
-  sectors[0] = burn_disc_get_sectors (disc);
-  
-  xfburn_progress_dialog_set_status_with_text (XFBURN_PROGRESS_DIALOG (dialog_progress), XFBURN_PROGRESS_DIALOG_STATUS_RUNNING, _("Burning image..."));
+    // this assumes that an iso image can only have one track
+    sectors[0] = burn_disc_get_sectors (params->disc);
+    
+    xfburn_progress_dialog_set_status_with_text (XFBURN_PROGRESS_DIALOG (dialog_progress), XFBURN_PROGRESS_DIALOG_STATUS_RUNNING, _("Burning image..."));
 
-  fifos = g_new(struct burn_source *,1);
-  fifos[0] = fifo_src;
+    fifos = g_new(struct burn_source *,1);
+    fifos[0] = params->fifo_src;
 
-  xfburn_perform_burn_write (dialog_progress, drive, params->write_mode, burn_options, DATA_BYTES_PER_SECTOR, disc, fifos, sectors);
+    xfburn_perform_burn_write (dialog_progress, drive_info->drive, params->write_mode, params->burn_options, DATA_BYTES_PER_SECTOR, params->disc, fifos, sectors);
+ 
+    xfburn_device_release (drive_info, params->eject);
+  } else {
+    xfburn_progress_dialog_burning_failed (XFBURN_PROGRESS_DIALOG (dialog_progress), _("Unable to grab the drive."));
+  }
 
   g_free (fifos);
 
-  burn_source_free (fifo_src);
-  burn_write_opts_free (burn_options);
-
- cleanup:
-  xfburn_device_release (drive_info, params->eject);
- end:
-  burn_track_free (track);
-  burn_session_free (session);
-  burn_disc_free (disc);
-
-  g_free (params->iso_path);
+  free_params (params);
   g_free (params);
 }
 
@@ -460,7 +467,7 @@ check_burn_button (XfburnBurnImageDialog * dialog)
 }
 
 static gboolean 
-check_media (XfburnBurnImageDialog * dialog, ThreadBurnIsoParams *params, struct burn_drive *drive, struct burn_write_opts * burn_options)
+check_media (XfburnBurnImageDialog * dialog, ThreadBurnIsoParams *params, struct burn_drive *drive)
 {
   enum burn_disc_status disc_state;
   struct stat st;
@@ -491,7 +498,7 @@ check_media (XfburnBurnImageDialog * dialog, ThreadBurnIsoParams *params, struct
   ret = stat (params->iso_path, &st);
   if (ret == 0) {
     off_t disc_size;
-    disc_size = burn_disc_available_space (drive, burn_options);
+    disc_size = burn_disc_available_space (drive, params->burn_options);
     if (st.st_size > disc_size) {
       burn_image_dialog_error (dialog, _("The selected image does not fit on the inserted disc"));
       return FALSE;
@@ -515,11 +522,12 @@ cb_clicked_ok (GtkButton *button, gpointer user_data)
   XfburnDevice *device;
   gint speed;
   XfburnWriteMode write_mode;
-  struct burn_write_opts * burn_options;
 
   ThreadBurnIsoParams *params = NULL;
   struct burn_drive_info *drive_info = NULL;
 
+  gchar *failure_msg;
+
   /* check if the image file really exists and can be opened */
   iso_path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (priv->chooser_image));
 
@@ -552,24 +560,21 @@ cb_clicked_ok (GtkButton *button, gpointer user_data)
     return;
   }
 
-  burn_options = make_burn_options (params, drive_info->drive);
-
-  if (burn_options == NULL)
-    burn_image_dialog_error (dialog, _("The write mode is not currently supported"));
-  else {
-    checks_passed = check_media (dialog, params, drive_info->drive, burn_options);
-
-    burn_write_opts_free (burn_options);
+  if (!prepare_params(params, drive_info->drive, &failure_msg)) {
+    burn_image_dialog_error (dialog, failure_msg);
+  } else {
+    checks_passed = check_media (dialog, params, drive_info->drive);
   }
 
   xfburn_device_release (drive_info, 0);
 
-  priv->params = params;
 
-  if (checks_passed)
+  if (checks_passed) {
+    priv->params = params;
+
     gtk_dialog_response (GTK_DIALOG(dialog), GTK_RESPONSE_OK);
-  else {
-    g_free (params->iso_path);
+  } else {
+    free_params (params);
     g_free (params);
   }
 }
diff --git a/xfburn/xfburn-device-box.c b/xfburn/xfburn-device-box.c
index c751d4d..a99d0e9 100644
--- a/xfburn/xfburn-device-box.c
+++ b/xfburn/xfburn-device-box.c
@@ -676,6 +676,9 @@ fill_combo_mode (XfburnDeviceBox *box, XfburnDevice *device)
 
   gtk_list_store_clear (GTK_LIST_STORE (model));
 
+  gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+  gtk_list_store_set (GTK_LIST_STORE (model), &iter, MODE_TEXT_COLUMN, _("Auto"), MODE_VALUE_COLUMN, WRITE_MODE_AUTO, -1);
+
   g_object_get (G_OBJECT (device), "tao-block-types", &block_types, NULL);
   if (block_types) {
     gtk_list_store_append (GTK_LIST_STORE (model), &iter);
diff --git a/xfburn/xfburn-device-box.h b/xfburn/xfburn-device-box.h
index 87805d3..90d83db 100644
--- a/xfburn/xfburn-device-box.h
+++ b/xfburn/xfburn-device-box.h
@@ -65,6 +65,7 @@ typedef enum
 
 typedef enum
 {
+  WRITE_MODE_AUTO,
   WRITE_MODE_TAO,
   WRITE_MODE_SAO,
   WRITE_MODE_RAW16,
diff --git a/xfburn/xfburn-perform-burn.c b/xfburn/xfburn-perform-burn.c
index 47c6b20..c79b13a 100644
--- a/xfburn/xfburn-perform-burn.c
+++ b/xfburn/xfburn-perform-burn.c
@@ -25,6 +25,8 @@
 #include <libburn.h>
 #include <unistd.h>
 
+#include <libburn.h>
+
 #include "xfburn-perform-burn.h"
 #include "xfburn-progress-dialog.h"
 #include "xfburn-utils.h"
@@ -43,6 +45,67 @@ xfburn_perform_burn_init (struct burn_disc **disc, struct burn_session **session
 {
 }
 */
+gboolean
+xfburn_set_write_mode (struct burn_write_opts *opts, XfburnWriteMode write_mode, struct burn_disc *disc, 
+                       XfburnWriteMode fallback)
+{
+  g_assert (fallback != WRITE_MODE_AUTO);
+
+  /* set all other burn_write_opts before calling this!
+   * See docs on burn_write_opts_auto_write_type
+   */
+
+  /* keep all modes here, just in case we want to change the default sometimes */
+  if (write_mode == WRITE_MODE_AUTO) {
+    char reason[BURN_REASONS_LEN];
+    enum burn_write_types mode;
+
+    mode = burn_write_opts_auto_write_type (opts, disc, reason, 0);
+
+    if (mode != BURN_WRITE_NONE) {
+      DBG("Automatically selected burn mode %d", mode);
+
+      // write mode set, we're done
+      
+      return TRUE;
+
+    } else {
+      g_warning ("Could not automatically determine write mode: %s", reason);
+      DBG ("This could be bad. Falling back to default %d.", fallback);
+
+      write_mode = fallback;
+      // fall through to set opts up
+    }
+  }
+
+  switch (write_mode) {
+  case WRITE_MODE_AUTO:
+    g_error ("WRITE_MODE_AUTO not valid at this point.");
+    break;
+  case WRITE_MODE_TAO:
+    burn_write_opts_set_write_type (opts, BURN_WRITE_TAO, BURN_BLOCK_MODE1);
+    break;
+  case WRITE_MODE_SAO:
+    burn_write_opts_set_write_type (opts, BURN_WRITE_SAO, BURN_BLOCK_SAO);
+    break;
+  case WRITE_MODE_RAW16:
+    burn_write_opts_set_write_type (opts, BURN_WRITE_RAW, BURN_BLOCK_RAW16);
+    break;
+  case WRITE_MODE_RAW96P:
+    burn_write_opts_set_write_type (opts, BURN_WRITE_RAW, BURN_BLOCK_RAW96P);
+    break;
+  case WRITE_MODE_RAW96R:
+    burn_write_opts_set_write_type (opts, BURN_WRITE_RAW, BURN_BLOCK_RAW96R);
+    break;
+  default:
+    /*
+    xfburn_progress_dialog_burning_failed (XFBURN_PROGRESS_DIALOG (dialog_progress), _("The write mode is not supported currently."));
+    */
+    return FALSE;
+  }
+
+  return TRUE;
+}
 
 void
 xfburn_perform_burn_write (GtkWidget *dialog_progress, 
diff --git a/xfburn/xfburn-perform-burn.h b/xfburn/xfburn-perform-burn.h
index 1df501b..d3504d4 100644
--- a/xfburn/xfburn-perform-burn.h
+++ b/xfburn/xfburn-perform-burn.h
@@ -31,6 +31,9 @@
 
 #include "xfburn-device-box.h"
 
+gboolean xfburn_set_write_mode (struct burn_write_opts *opts, XfburnWriteMode write_mode, struct burn_disc *disc,
+                                XfburnWriteMode fallback);
+
 void xfburn_perform_burn_write (GtkWidget *dialog_progress, 
                                 struct burn_drive *drive, XfburnWriteMode write_mode, struct burn_write_opts *burn_options, int sector_size,
                                 struct burn_disc *disc, struct burn_source **fifos, int *track_sectors);



More information about the Xfce4-commits mailing list