[brasero] Make use of the new API added by previous to limit the use of spanning



commit 1639b105085b1ee2f39ddc472a78b37e2401dbad
Author: Philippe Rouquier <bonfire-app wanadoo fr>
Date:   Fri Aug 14 15:36:08 2009 +0200

    Make use of the new API added by previous to limit the use of spanning
    Now to allow spanning, the disc available space must be enough to accomodate the size of the biggest batch of data

 libbrasero-burn/brasero-burn-options.c   |   13 ++++++++-
 libbrasero-burn/brasero-session-cfg.c    |   10 +------
 libbrasero-burn/brasero-session-helper.h |    4 +++
 libbrasero-burn/brasero-session-span.c   |   39 +++------------------------
 libbrasero-burn/brasero-session.c        |   41 ++++++++++++++++++++++++++++++
 src/brasero-project.c                    |   13 ++++++++-
 6 files changed, 76 insertions(+), 44 deletions(-)
---
diff --git a/libbrasero-burn/brasero-burn-options.c b/libbrasero-burn/brasero-burn-options.c
index c200f2c..6186027 100644
--- a/libbrasero-burn/brasero-burn-options.c
+++ b/libbrasero-burn/brasero-burn-options.c
@@ -318,9 +318,20 @@ brasero_burn_options_update_valid (BraseroBurnOptions *self)
 	}
 
 	if (valid == BRASERO_SESSION_INSUFFICIENT_SPACE) {
+		goffset min_disc_size;
+		goffset available_space;
+
+		min_disc_size = brasero_session_span_get_max_space (BRASERO_SESSION_SPAN (priv->session));
+
+		/* One rule should be that the maximum batch size should not exceed the disc size
+		 * FIXME: we could change it into a dialog telling the user what is the maximum
+		 * size required. */
+		available_space = brasero_burn_session_get_available_medium_space (BRASERO_BURN_SESSION (priv->session));
+
 		/* Here there is an alternative: we may be able to span the data
 		 * across multiple media. So try that. */
-		if (brasero_session_span_possible (BRASERO_SESSION_SPAN (priv->session)) == BRASERO_BURN_RETRY) {
+		if (available_space > min_disc_size
+		&& brasero_session_span_possible (BRASERO_SESSION_SPAN (priv->session)) == BRASERO_BURN_RETRY) {
 			GtkWidget *message;
 
 			message = brasero_notify_message_add (BRASERO_NOTIFY (priv->message_output),
diff --git a/libbrasero-burn/brasero-session-cfg.c b/libbrasero-burn/brasero-session-cfg.c
index e108d68..276c855 100644
--- a/libbrasero-burn/brasero-session-cfg.c
+++ b/libbrasero-burn/brasero-session-cfg.c
@@ -844,14 +844,7 @@ brasero_session_cfg_check_size (BraseroSessionCfg *self)
 		return BRASERO_SESSION_NO_OUTPUT;
 	}
 
-	flags = brasero_burn_session_get_flags (BRASERO_BURN_SESSION (self));
-	if (flags & (BRASERO_BURN_FLAG_MERGE|BRASERO_BURN_FLAG_APPEND))
-		brasero_medium_get_free_space (medium, NULL, &disc_size);
-	else if (brasero_burn_session_can_blank (BRASERO_BURN_SESSION (self)) == BRASERO_BURN_OK)
-		brasero_medium_get_capacity (medium, NULL, &disc_size);
-	else
-		brasero_medium_get_free_space (medium, NULL, &disc_size);
-
+	disc_size = brasero_burn_session_get_available_medium_space (BRASERO_BURN_SESSION (self));
 	if (disc_size < 0)
 		disc_size = 0;
 
@@ -897,6 +890,7 @@ brasero_session_cfg_check_size (BraseroSessionCfg *self)
 		return BRASERO_SESSION_INSUFFICIENT_SPACE;
 	}
 
+	flags = brasero_burn_session_get_flags (BRASERO_BURN_SESSION (self));
 	if (!(flags & BRASERO_BURN_FLAG_OVERBURN)) {
 		BraseroSessionCfgPrivate *priv;
 
diff --git a/libbrasero-burn/brasero-session-helper.h b/libbrasero-burn/brasero-session-helper.h
index bfa76fc..5e44eb6 100644
--- a/libbrasero-burn/brasero-session-helper.h
+++ b/libbrasero-burn/brasero-session-helper.h
@@ -44,6 +44,9 @@ G_BEGIN_DECLS
  * Some convenience functions used internally
  */
 
+goffset
+brasero_burn_session_get_available_medium_space (BraseroBurnSession *session);
+
 BraseroMedia
 brasero_burn_session_get_dest_media (BraseroBurnSession *session);
 
@@ -137,6 +140,7 @@ brasero_burn_session_push_tracks (BraseroBurnSession *session);
 BraseroBurnResult
 brasero_burn_session_pop_tracks (BraseroBurnSession *session);
 
+
 G_END_DECLS
 
 #endif
diff --git a/libbrasero-burn/brasero-session-span.c b/libbrasero-burn/brasero-session-span.c
index ca5e002..ba5f5b7 100644
--- a/libbrasero-burn/brasero-session-span.c
+++ b/libbrasero-burn/brasero-session-span.c
@@ -78,8 +78,6 @@ brasero_session_span_get_max_space (BraseroSessionSpan *session)
 
 	priv = BRASERO_SESSION_SPAN_PRIVATE (session);
 
-	g_return_val_if_fail (priv->track_list != NULL, 0);
-
 	if (priv->last_track) {
 		tracks = g_slist_find (priv->track_list, priv->last_track);
 
@@ -88,8 +86,10 @@ brasero_session_span_get_max_space (BraseroSessionSpan *session)
 
 		tracks = tracks->next;
 	}
-	else
+	else if (priv->track_list)
 		tracks = priv->track_list;
+	else
+		tracks = brasero_burn_session_get_tracks (BRASERO_BURN_SESSION (session));
 
 	for (; tracks; tracks = tracks->next) {
 		BraseroTrack *track;
@@ -111,35 +111,6 @@ brasero_session_span_get_max_space (BraseroSessionSpan *session)
 	return max_sectors;
 }
 
-static goffset
-brasero_session_span_get_available_medium_space (BraseroSessionSpan *session)
-{
-	BraseroDrive *burner;
-	BraseroMedium *medium;
-	BraseroBurnFlag flags;
-	goffset available_blocks = 0;
-
-	/* Retrieve the size available for burning */
-	burner = brasero_burn_session_get_burner (BRASERO_BURN_SESSION (session));
-	if (!burner)
-		return 0;
-
-	medium = brasero_drive_get_medium (burner);
-	if (!medium)
-		return 0;
-
-	flags = brasero_burn_session_get_flags (BRASERO_BURN_SESSION (session));
-	if (flags & (BRASERO_BURN_FLAG_MERGE|BRASERO_BURN_FLAG_APPEND))
-		brasero_medium_get_free_space (medium, NULL, &available_blocks);
-	else if (brasero_burn_session_can_blank (BRASERO_BURN_SESSION (session)) == BRASERO_BURN_OK)
-		brasero_medium_get_capacity (medium, NULL, &available_blocks);
-	else
-		brasero_medium_get_free_space (medium, NULL, &available_blocks);
-
-	BRASERO_BURN_LOG ("Available space for spanning %" G_GINT64_FORMAT, available_blocks);
-	return available_blocks;
-}
-
 /**
  * brasero_session_span_again:
  * @session: a #BraseroSessionSpan
@@ -211,7 +182,7 @@ brasero_session_span_possible (BraseroSessionSpan *session)
 
 	priv = BRASERO_SESSION_SPAN_PRIVATE (session);
 
-	max_sectors = brasero_session_span_get_available_medium_space (session);
+	max_sectors = brasero_burn_session_get_available_medium_space (BRASERO_BURN_SESSION (session));
 	if (max_sectors <= 0)
 		return BRASERO_BURN_ERR;
 
@@ -301,7 +272,7 @@ brasero_session_span_next (BraseroSessionSpan *session)
 
 	g_return_val_if_fail (priv->track_list != NULL, BRASERO_BURN_ERR);
 
-	max_sectors = brasero_session_span_get_available_medium_space (session);
+	max_sectors = brasero_burn_session_get_available_medium_space (BRASERO_BURN_SESSION (session));
 	if (max_sectors <= 0)
 		return BRASERO_BURN_ERR;
 
diff --git a/libbrasero-burn/brasero-session.c b/libbrasero-burn/brasero-session.c
index 0a4e0d4..dfa2789 100644
--- a/libbrasero-burn/brasero-session.c
+++ b/libbrasero-burn/brasero-session.c
@@ -1759,6 +1759,47 @@ brasero_burn_session_get_dest_media (BraseroBurnSession *self)
 	return brasero_medium_get_status (medium);
 }
 
+/**
+ * brasero_burn_session_get_available_medium_space:
+ * @session: a #BraseroBurnSession
+ *
+ * Returns the maximum space available for the
+ * medium currently inserted in the #BraseroDrive
+ * set as burner with brasero_burn_session_set_burner ().
+ * This takes into account flags.
+ *
+ * Return value: a #goffset.
+ **/
+
+goffset
+brasero_burn_session_get_available_medium_space (BraseroBurnSession *session)
+{
+	BraseroDrive *burner;
+	BraseroBurnFlag flags;
+	BraseroMedium *medium;
+	goffset available_blocks = 0;
+
+	/* Retrieve the size available for burning */
+	burner = brasero_burn_session_get_burner (session);
+	if (!burner)
+		return 0;
+
+	medium = brasero_drive_get_medium (burner);
+	if (!medium)
+		return 0;
+
+	flags = brasero_burn_session_get_flags (session);
+	if (flags & (BRASERO_BURN_FLAG_MERGE|BRASERO_BURN_FLAG_APPEND))
+		brasero_medium_get_free_space (medium, NULL, &available_blocks);
+	else if (brasero_burn_session_can_blank (session) == BRASERO_BURN_OK)
+		brasero_medium_get_capacity (medium, NULL, &available_blocks);
+	else
+		brasero_medium_get_free_space (medium, NULL, &available_blocks);
+
+	BRASERO_BURN_LOG ("Available space on medium %" G_GINT64_FORMAT, available_blocks);
+	return available_blocks;
+}
+
 BraseroMedium *
 brasero_burn_session_get_src_medium (BraseroBurnSession *self)
 {
diff --git a/src/brasero-project.c b/src/brasero-project.c
index 368bd53..1b1c9ce 100644
--- a/src/brasero-project.c
+++ b/src/brasero-project.c
@@ -945,12 +945,23 @@ brasero_project_is_valid (BraseroSessionCfg *session,
 		project->priv->empty = TRUE;
 	}
 	else if (valid == BRASERO_SESSION_INSUFFICIENT_SPACE) {
+		goffset min_disc_size;
+		goffset available_space;
+
 		project->priv->oversized = TRUE;
 		project->priv->empty = FALSE;
 
+		min_disc_size = brasero_session_span_get_max_space (BRASERO_SESSION_SPAN (session));
+
+		/* One rule should be that the maximum batch size should not exceed the disc size
+		 * FIXME: we could change it into a dialog telling the user what is the maximum
+		 * size required. */
+		available_space = brasero_burn_session_get_available_medium_space (BRASERO_BURN_SESSION (session));
+
 		/* Here there is an alternative: we may be able to span the data
 		 * across multiple media. So try that. */
-		if (brasero_session_span_possible (BRASERO_SESSION_SPAN (project->priv->session)) == BRASERO_BURN_RETRY) {
+		if (available_space > min_disc_size
+		&& brasero_session_span_possible (BRASERO_SESSION_SPAN (session)) == BRASERO_BURN_RETRY) {
 			GtkWidget *message;
 
 			message = brasero_notify_message_add (BRASERO_NOTIFY (project->priv->message),



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]