brasero r1010 - in trunk: . src



Author: philippr
Date: Thu Jul 17 18:28:24 2008
New Revision: 1010
URL: http://svn.gnome.org/viewvc/brasero?rev=1010&view=rev

Log:
	Fix video project drive choice
	Also fix a problem with size display

	* src/brasero-project-size.c
	(brasero_project_size_get_ruler_min_width),
	(brasero_project_size_get_media_string),
	(brasero_project_size_expose),
	(brasero_project_size_is_valid_drive),
	(brasero_project_size_build_menu),
	(brasero_project_size_scroll_event),
	(brasero_project_size_find_proper_drive),
	(brasero_project_size_set_context):
	* src/brasero-project-size.h:
	* src/brasero-project.c (brasero_project_switch):
	* src/brasero-utils.c (brasero_utils_get_time_string),
	(brasero_utils_get_time_string_from_size):
	* src/brasero-utils.h:
	* src/burn-basics.h:

Modified:
   trunk/ChangeLog
   trunk/src/brasero-project-size.c
   trunk/src/brasero-project-size.h
   trunk/src/brasero-project.c
   trunk/src/brasero-utils.c
   trunk/src/brasero-utils.h
   trunk/src/burn-basics.h

Modified: trunk/src/brasero-project-size.c
==============================================================================
--- trunk/src/brasero-project-size.c	(original)
+++ trunk/src/brasero-project-size.c	Thu Jul 17 18:28:24 2008
@@ -38,6 +38,7 @@
 #include <gtk/gtkmenu.h>
 #include <gtk/gtkcontainer.h>
 
+#include "brasero-project-type-chooser.h"
 #include "brasero-project-size.h"
 #include "burn-caps.h"
 #include "burn-volume-obj.h"
@@ -109,7 +110,8 @@
 	GList *drives;
 	BraseroDriveSize *current;
 
-	guint is_audio_context:1;
+	BraseroProjectType context;
+
 	guint was_chosen:1;
 	guint is_loaded:1;
 	guint multi:1;
@@ -419,7 +421,7 @@
 	}
 
 	/* the number of interval needs to be reasonable, not over 8 not under 5 */
-	if (self->priv->is_audio_context)
+	if (self->priv->context != BRASERO_PROJECT_TYPE_DATA)
 		interval_size = AUDIO_INTERVAL_CD;
 	else if (self->priv->current->media & (BRASERO_MEDIUM_DVD|BRASERO_MEDIUM_DVD_DL))
 		interval_size = DATA_INTERVAL_DVD;
@@ -461,7 +463,7 @@
 		gchar *markup, *string;
 
 		string = brasero_utils_get_sectors_string (i * interval_size,
-							   self->priv->is_audio_context,
+							   (self->priv->context != BRASERO_PROJECT_TYPE_DATA),
 							   TRUE,
 							   TRUE);
 
@@ -544,7 +546,7 @@
 	}
 
 	disc_sectors_str = brasero_utils_get_sectors_string (disc_size,
-							     self->priv->is_audio_context,
+							     (self->priv->context != BRASERO_PROJECT_TYPE_DATA),
 							     TRUE,
 							     TRUE);
 
@@ -562,7 +564,7 @@
 */	}
 
 	selection_size_str = brasero_utils_get_sectors_string (self->priv->sectors,
-							       self->priv->is_audio_context,
+							       (self->priv->context != BRASERO_PROJECT_TYPE_DATA),
 							       TRUE,
 							       FALSE);
 
@@ -731,7 +733,7 @@
 	/* The number of interval needs to be reasonable, not over 8 not under 5
 	 * They should also depend on the available space for the bar. */
 	
-	if (self->priv->is_audio_context)
+	if (self->priv->context != BRASERO_PROJECT_TYPE_DATA)
 		interval_size = AUDIO_INTERVAL_CD;
 	else if (self->priv->current->media & (BRASERO_MEDIUM_DVD|BRASERO_MEDIUM_DVD_DL))
 		interval_size = DATA_INTERVAL_DVD;
@@ -764,7 +766,7 @@
 		guint text_x;
 
 		string = brasero_utils_get_sectors_string (i * interval_size,
-							   self->priv->is_audio_context,
+							   (self->priv->context != BRASERO_PROJECT_TYPE_DATA),
 							   TRUE,
 							   TRUE);
 
@@ -1034,6 +1036,39 @@
 	*push_in = FALSE;
 }
 
+static gboolean
+brasero_project_size_is_valid_drive (BraseroProjectSize *self,
+				     BraseroDriveSize *current)
+{
+	BraseroBurnCaps *caps;
+	gboolean result = TRUE;
+	BraseroMedia media_status;
+
+	if (!current)
+		return FALSE;
+
+	caps = brasero_burn_caps_get_default ();
+	media_status = brasero_burn_caps_media_capabilities (caps, current->media);
+	
+	if (!BRASERO_MEDIUM_VALID (current->media))
+		result = FALSE;
+	/* Library must support it */
+	else if (!(media_status & (BRASERO_MEDIUM_WRITABLE|BRASERO_MEDIUM_REWRITABLE)))
+		result = FALSE;
+	/* No media with data for audio/video context, that can't be erased */
+	else if (self->priv->context != BRASERO_PROJECT_TYPE_DATA
+	     && (current->media & (BRASERO_MEDIUM_HAS_AUDIO|BRASERO_MEDIUM_HAS_DATA))
+	     && !(media_status & BRASERO_MEDIUM_REWRITABLE))
+		result = FALSE;
+	/* No DVDs in an audio context */
+	else if (self->priv->context == BRASERO_PROJECT_TYPE_AUDIO
+	     && (current->media & (BRASERO_MEDIUM_DVD|BRASERO_MEDIUM_DVD_DL|BRASERO_MEDIUM_APPENDABLE)))
+		result = FALSE;
+
+	g_object_unref (caps);
+	return result;
+}
+
 static GtkWidget *
 brasero_project_size_build_menu (BraseroProjectSize *self)
 {
@@ -1054,16 +1089,7 @@
 
 		drive = iter->data;
 
-		if (!BRASERO_MEDIUM_VALID (drive->media))
-			continue;
-
-	    	if (!(drive->media & (BRASERO_MEDIUM_BLANK|BRASERO_MEDIUM_REWRITABLE))
-		&& (!(drive->media & BRASERO_MEDIUM_APPENDABLE)
-		||   self->priv->is_audio_context))
-			continue;
-
-		if (self->priv->is_audio_context
-		&& (drive->media & (BRASERO_MEDIUM_DVD|BRASERO_MEDIUM_DVD_DL)))
+		if (!brasero_project_size_is_valid_drive (self, drive))
 			continue;
 
 		if (!drive->medium && !separator) {
@@ -1081,7 +1107,7 @@
 		else
 			disc_size = drive->free_space;
 
-		if (self->priv->is_audio_context)
+		if (self->priv->context != BRASERO_PROJECT_TYPE_DATA)
 			size_str = brasero_utils_get_time_string_from_size (disc_size * AUDIO_SECTOR_SIZE, TRUE, TRUE);
 		else
 			size_str = brasero_utils_get_size_string (disc_size * DATA_SECTOR_SIZE, TRUE, TRUE); 
@@ -1213,51 +1239,32 @@
 				   GdkEventScroll *event)
 {
 	BraseroProjectSize *self;
-	BraseroBurnCaps *caps;
 
 	self = BRASERO_PROJECT_SIZE (widget);
-	caps = brasero_burn_caps_get_default ();
 
 	if (event->direction == GDK_SCROLL_DOWN) {
 		GList *node, *iter;
 
 		node = g_list_find (self->priv->drives, self->priv->current);
 		iter = g_list_next (node);
-		if (!iter) {
-			g_object_unref (caps);
+		if (!iter)
 			return TRUE;
-		}
 
 		while (iter != node) {
 			BraseroDriveSize *drive;
-			BraseroMedia media_status;
 
 			drive = iter->data;
-			media_status = brasero_burn_caps_media_capabilities (caps, drive->media);
 
 			/* must be a valid media */
-			if (!BRASERO_MEDIUM_VALID (drive->media))
-				iter = g_list_next (iter);
-			/* in an audio context only CDs are valid */
-			else if (self->priv->is_audio_context
-			     && (drive->media & (BRASERO_MEDIUM_DVD|BRASERO_MEDIUM_DVD_DL)))
-				iter = g_list_next (iter);
-			/* we want a drive supported by the library */
-			else if (!(media_status & (BRASERO_MEDIUM_WRITABLE|BRASERO_MEDIUM_REWRITABLE)))
-				iter = g_list_next (iter);
-			/* if we are in an audio context no drive with data */
-			else if (self->priv->is_audio_context
-			     &&  drive->media & (BRASERO_MEDIUM_HAS_AUDIO|BRASERO_MEDIUM_HAS_DATA))
+			if (!brasero_project_size_is_valid_drive (self, drive))
 				iter = g_list_next (iter);
 			else {
 				self->priv->current = drive;
 				break;
 			}
 
-			if (!iter) {
-				g_object_unref (caps);
+			if (!iter)
 				return TRUE;
-			}
 		}
 		brasero_project_size_disc_changed (self);
 	}
@@ -1266,46 +1273,28 @@
 
 		node = g_list_find (self->priv->drives, self->priv->current);
 		iter = g_list_previous (node);
-		if (!iter) {
-			g_object_unref (caps);
+		if (!iter)
 			return TRUE;
-		}
 
 		while (iter != node) {
 			BraseroDriveSize *drive;
-			BraseroMedia media_status;
 
 			drive = iter->data;
-			media_status = brasero_burn_caps_media_capabilities (caps, drive->media);
 
 			/* must be a valid media */
-			if (!BRASERO_MEDIUM_VALID (drive->media))
-				iter = g_list_previous (iter);
-			/* in an audio context only CDs are valid */
-			else if (self->priv->is_audio_context
-			     && (drive->media & (BRASERO_MEDIUM_DVD|BRASERO_MEDIUM_DVD_DL)))
-				iter = g_list_previous (iter);
-			/* we want a drive supported by the library */
-			else if (!(media_status & (BRASERO_MEDIUM_WRITABLE|BRASERO_MEDIUM_REWRITABLE)))
-				iter = g_list_previous (iter);
-			/* if we are in an audio context no drive with data */
-			else if (self->priv->is_audio_context
-			     &&  drive->media & (BRASERO_MEDIUM_HAS_AUDIO|BRASERO_MEDIUM_HAS_DATA))
+			if (!brasero_project_size_is_valid_drive (self, drive))
 				iter = g_list_previous (iter);
 			else {
 				self->priv->current = drive;
 				break;
 			}
 
-			if (!iter) {
-				g_object_unref (caps);
+			if (!iter)
 				return TRUE;
-			}
 		}
 		brasero_project_size_disc_changed (self);
 	}
 
-	g_object_unref (caps);
 	return FALSE;
 }
 
@@ -1355,38 +1344,18 @@
 brasero_project_size_find_proper_drive (BraseroProjectSize *self)
 {
 	GList *iter;
-	BraseroBurnCaps *caps;
-	BraseroMedia media_status;
 	BraseroDriveSize *candidate = NULL;
 
-	caps = brasero_burn_caps_get_default ();
-
 	if (self->priv->current) {
 		BraseroDriveSize *current;
 
 		/* we check the current drive to see if it is suitable */
 		current = self->priv->current;
-		media_status = brasero_burn_caps_media_capabilities (caps, current->media);
 
-		if (self->priv->is_audio_context
-		&& (current->media & (BRASERO_MEDIUM_DVD|BRASERO_MEDIUM_DVD_DL))) {
-			current = NULL;
-		}
-		else if (!BRASERO_MEDIUM_VALID (current->media)) {
-			current = NULL;
-		}
-		else if (!(media_status & (BRASERO_MEDIUM_WRITABLE|BRASERO_MEDIUM_REWRITABLE))) {
-			/* we want a drive supported by the library */
+		if (!brasero_project_size_is_valid_drive (self, current))
 			current = NULL;
-		}
-	    	else if (self->priv->is_audio_context
-		     &&  current->media & (BRASERO_MEDIUM_HAS_AUDIO|BRASERO_MEDIUM_HAS_DATA)) {
-			/* if we are in an audio context no drive with data */
-			current = NULL;
-		}
 		else if (current->sectors >= self->priv->sectors && current->medium) {
 			/* The current drive is still a perfect fit keep it */
-			g_object_unref (caps);
 			return;
 		}
 		else if (self->priv->multi) {
@@ -1398,7 +1367,6 @@
 			 * - we don't change the current drive if it is real
 			 * unless another real drive comes up with a size
 			 * fitting the size of the selection. */
-			g_object_unref (caps);
 			return;
 		}
 		else /* see if there is better */
@@ -1411,22 +1379,7 @@
 
 		drive = iter->data;
 
-		/* No DVD if context is audio */
-		if (self->priv->is_audio_context
-		&& (drive->media & (BRASERO_MEDIUM_DVD|BRASERO_MEDIUM_DVD_DL)))
-			continue;
-
-		if (!BRASERO_MEDIUM_VALID (drive->media))
-			continue;
-
-		/* we want a drive supported by the library */
-		media_status = brasero_burn_caps_media_capabilities (caps, drive->media);
-		if (!(media_status & (BRASERO_MEDIUM_WRITABLE|BRASERO_MEDIUM_REWRITABLE)))
-			continue;
-
-		/* if we are in an audio context no drive with data */
-	    	if (self->priv->is_audio_context
-		&&  drive->media & (BRASERO_MEDIUM_HAS_AUDIO|BRASERO_MEDIUM_HAS_DATA))
+		if (!brasero_project_size_is_valid_drive (self, drive))
 			continue;
 
 		/* we must have at least one candidate */
@@ -1455,18 +1408,17 @@
 		}
 	}
 
-	g_object_unref (caps);
 	self->priv->current = candidate;
 }
 
 void
 brasero_project_size_set_context (BraseroProjectSize *self,
-				  gboolean is_audio)
+				  BraseroProjectType type)
 {
 	BraseroDriveSize *current;
 
 	self->priv->sectors = 0;
-	self->priv->is_audio_context = is_audio;
+	self->priv->context = type;
 
 	if (!self->priv->is_loaded) {
 		brasero_project_size_add_real_medias (self);
@@ -1479,12 +1431,12 @@
 	 *   appendable disc or the disc is a DVD
 	 * No need to find a better one for DVD+RW */
 	current = self->priv->current;
+
 	if (!current)
 		brasero_project_size_find_proper_drive (self);
 	else if (!current->medium)
 		brasero_project_size_find_proper_drive (self);
-	else if (is_audio
-	     && (current->media & (BRASERO_MEDIUM_DVD|BRASERO_MEDIUM_DVD_DL|BRASERO_MEDIUM_APPENDABLE)))
+	else if (!brasero_project_size_is_valid_drive (self, current))
 		brasero_project_size_find_proper_drive (self);
 
 	brasero_project_size_disc_changed (self);

Modified: trunk/src/brasero-project-size.h
==============================================================================
--- trunk/src/brasero-project-size.h	(original)
+++ trunk/src/brasero-project-size.h	Thu Jul 17 18:28:24 2008
@@ -33,6 +33,7 @@
 #include <gtk/gtkwidget.h>
 #include <gtk/gtkcontainer.h>
 
+#include "brasero-project-type-chooser.h"
 #include "burn-medium.h"
 
 G_BEGIN_DECLS
@@ -75,7 +76,7 @@
 
 void
 brasero_project_size_set_context (BraseroProjectSize *self,
-				  gboolean is_audio);
+				  BraseroProjectType type);
 
 gboolean
 brasero_project_size_check_status (BraseroProjectSize *self,

Modified: trunk/src/brasero-project.c
==============================================================================
--- trunk/src/brasero-project.c	(original)
+++ trunk/src/brasero-project.c	Thu Jul 17 18:28:24 2008
@@ -1129,7 +1129,7 @@
 							       project->priv->message);
 
 		gtk_notebook_set_current_page (GTK_NOTEBOOK (project->priv->discs), 0);
-		brasero_project_size_set_context (BRASERO_PROJECT_SIZE (project->priv->size_display), TRUE);
+		brasero_project_size_set_context (BRASERO_PROJECT_SIZE (project->priv->size_display), BRASERO_PROJECT_TYPE_AUDIO);
 	}
 	else if (type == BRASERO_PROJECT_TYPE_DATA) {
 		project->priv->current = BRASERO_DISC (project->priv->data);
@@ -1138,7 +1138,7 @@
 							       project->priv->message);
 
 		gtk_notebook_set_current_page (GTK_NOTEBOOK (project->priv->discs), 1);
-		brasero_project_size_set_context (BRASERO_PROJECT_SIZE (project->priv->size_display), FALSE);
+		brasero_project_size_set_context (BRASERO_PROJECT_SIZE (project->priv->size_display), BRASERO_PROJECT_TYPE_DATA);
 	}
 	else if (type == BRASERO_PROJECT_TYPE_VIDEO) {
 		project->priv->current = BRASERO_DISC (project->priv->video);
@@ -1147,7 +1147,7 @@
 							       project->priv->message);
 
 		gtk_notebook_set_current_page (GTK_NOTEBOOK (project->priv->discs), 2);
-		brasero_project_size_set_context (BRASERO_PROJECT_SIZE (project->priv->size_display), TRUE);
+		brasero_project_size_set_context (BRASERO_PROJECT_SIZE (project->priv->size_display), BRASERO_PROJECT_TYPE_VIDEO);
 	}
 
 	brasero_notify_message_remove (BRASERO_NOTIFY (project->priv->message), BRASERO_NOTIFY_CONTEXT_SIZE);

Modified: trunk/src/brasero-utils.c
==============================================================================
--- trunk/src/brasero-utils.c	(original)
+++ trunk/src/brasero-utils.c	Thu Jul 17 18:28:24 2008
@@ -184,13 +184,13 @@
 }
 
 gchar *
-brasero_utils_get_time_string (gint64 time,
+brasero_utils_get_time_string (guint64 time,
 			       gboolean with_unit,
 			       gboolean round)
 {
-	int second, minute, hour;
+	gint64 second, minute, hour;
 
-	time = time / 1000000000;
+	time /= 1000000000;
 	hour = time / 3600;
 	time = time % 3600;
 	minute = time / 60;
@@ -207,34 +207,34 @@
 	if (hour) {
 		if (with_unit) {
 			if (hour && minute && second)
-				return g_strdup_printf ("%i h %02i min %02i",
+				return g_strdup_printf ("%lli h %02lli min %02lli",
 							 hour,
 							 minute,
 							 second);
 			else if (hour && minute)
-				return g_strdup_printf ("%i h %02i",
+				return g_strdup_printf ("%lli h %02lli",
 							 hour,
 							 minute);
 			else
-				return g_strdup_printf ("%i h",hour);
+				return g_strdup_printf ("%lli h",hour);
 		}
 		else if (hour && minute && second)
-			return g_strdup_printf ("%i:%02i:%02i",
+			return g_strdup_printf ("%lli:%02lli:%02lli",
 						 hour,
 						 minute,
 						 second);
 		else if (hour && minute)
-			return g_strdup_printf ("%i:%02i", hour, minute);
+			return g_strdup_printf ("%lli:%02lli", hour, minute);
 	}
 
 	if (with_unit) {
 		if (!second)
-			return g_strdup_printf (_("%i min"), minute);
+			return g_strdup_printf (_("%lli min"), minute);
 		else
-			return g_strdup_printf (_("%i:%02i min"), minute, second);
+			return g_strdup_printf (_("%lli:%02lli min"), minute, second);
 	}
 	else
-		return g_strdup_printf ("%i:%02i", minute, second);
+		return g_strdup_printf ("%lli:%02lli", minute, second);
 }
 
 gchar *
@@ -242,37 +242,10 @@
 					 gboolean with_unit,
 					 gboolean round)
 {
-	int second = 0;
-	int minute = 0;
-	gint64 time = 0.0;
+	guint64 time = 0;
 
 	time = BRASERO_BYTES_TO_DURATION (size);
-	time /= 1000000000;
-
-	minute = time / 60;
-	if (!round)
-		second = time % 60;
-
-	if (minute > 120) {
-		int hour;
-
-		hour = minute / 60;
-		minute = minute % 60;
-
-		if (with_unit == TRUE)
-			return g_strdup_printf (ngettext ("%d:%02i hour", "%i:%02i hours", hour), hour, minute);
-		else
-			return g_strdup_printf ("%i:%02i:%02i", hour,
-						minute, second);
-	}
-	else if (with_unit == TRUE) {
-		if (!second)
-			return g_strdup_printf (_("%i min"), minute);
-		else
-			return g_strdup_printf (_("%i:%02i min"), minute, second);
-	}
-	else
-		return g_strdup_printf ("%i:%02i", minute, second);
+	return brasero_utils_get_time_string (time, with_unit, round);
 }
 
 enum {

Modified: trunk/src/brasero-utils.h
==============================================================================
--- trunk/src/brasero-utils.h	(original)
+++ trunk/src/brasero-utils.h	Thu Jul 17 18:28:24 2008
@@ -56,7 +56,7 @@
 
 GQuark brasero_error_quark (void);
 
-gchar *brasero_utils_get_time_string (gint64 time,
+gchar *brasero_utils_get_time_string (guint64 time,
 				      gboolean with_unit,
 				      gboolean round);
 

Modified: trunk/src/burn-basics.h
==============================================================================
--- trunk/src/burn-basics.h	(original)
+++ trunk/src/burn-basics.h	Thu Jul 17 18:28:24 2008
@@ -170,8 +170,8 @@
 #define BRASERO_SIZE_TO_SECTORS(size, secsize)					\
 	(((size) / (secsize)) + (((size) % (secsize)) ? 1:0))
 #define BRASERO_BYTES_TO_DURATION(bytes)					\
-	(((bytes) * 1000000000) / (2352 * 75) + 				\
-	((((bytes) * 1000000000) % (2352 * 75)) ? 1:0))
+	(guint64) ((guint64) ((guint64) (bytes) * 1000000000) / (guint64) (2352 * 75) + 				\
+	(guint64) (((guint64) ((guint64) (bytes) * 1000000000) % (guint64) (2352 * 75)) ? 1:0))
 
 BraseroBurnResult
 brasero_burn_library_init (void);



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