brasero r652 - in trunk: . po src src/plugins/cdrdao src/plugins/dvdcss



Author: philippr
Date: Tue Feb 26 21:02:10 2008
New Revision: 652
URL: http://svn.gnome.org/viewvc/brasero?rev=652&view=rev

Log:
2008-02-26  Philippe Rouquier  <philippr svn gnome org>

	Started to remove ncb.
	This patch removes any use of nautilus_burn_drive_selection widget and replace by our own
	It also lays the basis for a medium monitor (which should use GIO in the future).

	* src/Makefile.am:
	* src/brasero-data-session.c:
	(brasero_data_session_get_loaded_medium):
	* src/brasero-dest-selection.c: (brasero_dest_selection_init):
	* src/brasero-disc-copy-dialog.c: (brasero_disc_copy_dialog_init):
	* src/brasero-disc-option-dialog.c:
	(brasero_disc_option_dialog_save_multi_state),
	(brasero_disc_option_dialog_set_disc),
	(brasero_disc_option_dialog_init):
	* src/brasero-drive-info.c: (brasero_drive_info_set_drive),
	(brasero_drive_info_finalize):
	* src/brasero-drive-selection.c:
	(brasero_drive_selection_drive_changed_cb),
	(brasero_drive_selection_set_drive),
	(brasero_drive_selection_get_drive),
	(brasero_drive_selection_lock),
	(brasero_drive_selection_set_type_shown),
	(brasero_drive_selection_init):
	* src/brasero-drive-selection.h:
	* src/brasero-image-option-dialog.c:
	(brasero_image_option_dialog_init):
	* src/brasero-medium-selection.c:
	(brasero_medium_selection_changed),
	(brasero_medium_selection_set_active),
	(brasero_medium_selection_get_active),
	(brasero_medium_selection_show_type),
	(brasero_medium_selection_medium_added_cb),
	(brasero_medium_selection_medium_removed_cb),
	(brasero_medium_selection_init),
	(brasero_medium_selection_finalize),
	(brasero_medium_selection_class_init),
	(brasero_medium_selection_new):
	* src/brasero-medium-selection.h:
	* src/brasero-ncb.c: (NCB_DRIVE_GET_MEDIUM),
	(NCB_DRIVE_SET_MEDIUM):
	* src/brasero-ncb.h:
	* src/brasero-src-selection.c: (brasero_src_selection_init):
	* src/brasero-tool-dialog.c: (brasero_tool_dialog_init):
	* src/burn-basics.c: (brasero_burn_library_init),
	(brasero_burn_library_get_plugins_list),
	(brasero_burn_library_shutdown):
	* src/burn-medium-monitor.c: (brasero_burn_medium_get_file),
	(brasero_medium_monitor_get_media),
	(brasero_medium_monitor_inserted_cb),
	(brasero_medium_monitor_removed_cb), (brasero_medium_monitor_init),
	(brasero_medium_monitor_finalize),
	(brasero_medium_monitor_class_init),
	(brasero_medium_monitor_get_default):
	* src/burn-medium-monitor.h:
	* src/burn-medium.c: (brasero_medium_init_file),
	(brasero_medium_set_property), (brasero_medium_can_be_written),
	(brasero_medium_can_be_rewritten),
	(brasero_medium_get_display_name), (brasero_medium_get_drive):
	* src/burn-medium.h:
	* src/plugins/cdrdao/burn-toc2cue.c:
	* src/plugins/dvdcss/burn-dvdcss.c:
	* src/scsi-read-disc-structure.c:


Added:
   trunk/src/brasero-medium-selection.c
   trunk/src/brasero-medium-selection.h
   trunk/src/burn-medium-monitor.c
   trunk/src/burn-medium-monitor.h
Modified:
   trunk/ChangeLog
   trunk/po/ChangeLog
   trunk/po/POTFILES.in
   trunk/src/Makefile.am
   trunk/src/brasero-data-session.c
   trunk/src/brasero-dest-selection.c
   trunk/src/brasero-disc-copy-dialog.c
   trunk/src/brasero-disc-option-dialog.c
   trunk/src/brasero-drive-info.c
   trunk/src/brasero-drive-selection.c
   trunk/src/brasero-drive-selection.h
   trunk/src/brasero-image-option-dialog.c
   trunk/src/brasero-ncb.c
   trunk/src/brasero-ncb.h
   trunk/src/brasero-src-selection.c
   trunk/src/brasero-tool-dialog.c
   trunk/src/burn-basics.c
   trunk/src/burn-medium.c
   trunk/src/burn-medium.h
   trunk/src/plugins/cdrdao/burn-toc2cue.c
   trunk/src/plugins/dvdcss/burn-dvdcss.c
   trunk/src/scsi-read-disc-structure.c

Modified: trunk/po/POTFILES.in
==============================================================================
--- trunk/po/POTFILES.in	(original)
+++ trunk/po/POTFILES.in	Tue Feb 26 21:02:10 2008
@@ -95,3 +95,5 @@
 src/brasero-io.c
 src/brasero-data-vfs.c
 src/brasero-io.c
+src/brasero-medium-selection.c
+src/brasero-medium-selection.c

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Tue Feb 26 21:02:10 2008
@@ -231,7 +231,11 @@
 	baobab-cell-renderer-progress.h         \
 	scsi-device.h         \
 	brasero-io.h         \
-	brasero-io.c 
+	brasero-io.c         \
+	brasero-medium-selection.h         \
+	brasero-medium-selection.c         \
+	burn-medium-monitor.c         \
+	burn-medium-monitor.h 
 
 if BUILD_INOTIFY
 brasero_SOURCES += brasero-file-monitor.c brasero-file-monitor.h

Modified: trunk/src/brasero-data-session.c
==============================================================================
--- trunk/src/brasero-data-session.c	(original)
+++ trunk/src/brasero-data-session.c	Tue Feb 26 21:02:10 2008
@@ -247,7 +247,7 @@
 	BraseroDataSessionPrivate *priv;
 
 	priv = BRASERO_DATA_SESSION_PRIVATE (self);
-	if (!priv->multi_inserted)
+	if (!priv->multi_inserted || !priv->nodes)
 		return NULL;
 
 	return priv->drive;

Modified: trunk/src/brasero-dest-selection.c
==============================================================================
--- trunk/src/brasero-dest-selection.c	(original)
+++ trunk/src/brasero-dest-selection.c	Tue Feb 26 21:02:10 2008
@@ -1334,7 +1334,9 @@
 			  G_CALLBACK (brasero_dest_selection_copies_num_changed_cb),
 			  object);
 
-	brasero_drive_selection_set_show_all_drives (BRASERO_DRIVE_SELECTION (object), FALSE);
+	/* only show media on which we can write and which are in a burner */
+	brasero_drive_selection_set_type_shown (BRASERO_DRIVE_SELECTION (object),
+						BRASERO_MEDIA_TYPE_WRITABLE);
 
 	priv->default_ext = TRUE;
 	priv->default_path = TRUE;

Modified: trunk/src/brasero-disc-copy-dialog.c
==============================================================================
--- trunk/src/brasero-disc-copy-dialog.c	(original)
+++ trunk/src/brasero-disc-copy-dialog.c	Tue Feb 26 21:02:10 2008
@@ -133,8 +133,11 @@
 
 	/* take care of source media */
 	priv->source = brasero_src_selection_new (priv->session);
-	brasero_drive_selection_show_file_drive (BRASERO_DRIVE_SELECTION (priv->source), FALSE);
-	brasero_drive_selection_set_show_all_drives (BRASERO_DRIVE_SELECTION (priv->source), TRUE);
+
+	/* only show media with something to be read on them */
+	brasero_drive_selection_set_type_shown (BRASERO_DRIVE_SELECTION (priv->source),
+						BRASERO_MEDIA_TYPE_READABLE);
+
 	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (obj)->vbox),
 			    brasero_utils_pack_properties (_("<b>Select source drive to copy</b>"),
 							   priv->source,
@@ -143,17 +146,17 @@
 			    FALSE,
 			    6);
 
-	brasero_drive_selection_select_default_drive (BRASERO_DRIVE_SELECTION (priv->source),
-						      BRASERO_MEDIUM_HAS_DATA);
-
 	/* destination drive */
 	priv->selection = brasero_dest_selection_new (priv->session);
 	g_signal_connect (priv->selection,
 			  "valid-media",
 			  G_CALLBACK (brasero_disc_copy_dialog_valid_media_cb),
 			  obj);
-	
-	brasero_drive_selection_show_file_drive (BRASERO_DRIVE_SELECTION (priv->selection), TRUE);
+
+	brasero_drive_selection_set_type_shown (BRASERO_DRIVE_SELECTION (priv->selection),
+						BRASERO_MEDIA_TYPE_WRITABLE|
+						BRASERO_MEDIA_TYPE_FILE);
+
 	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (obj)->vbox),
 			    brasero_utils_pack_properties (_("<b>Select a drive to write to</b>"),
 							   priv->selection,
@@ -162,8 +165,10 @@
 			    FALSE,
 			    6);
 
-	brasero_drive_selection_select_default_drive (BRASERO_DRIVE_SELECTION (priv->selection),
-						      BRASERO_MEDIUM_WRITABLE);
+	brasero_drive_selection_set_type_shown (BRASERO_DRIVE_SELECTION (priv->selection),
+						BRASERO_MEDIA_TYPE_WRITABLE|
+						BRASERO_MEDIA_TYPE_REWRITABLE|
+						BRASERO_MEDIA_TYPE_READABLE);
 
 	if (brasero_burn_session_same_src_dest_drive (priv->session)) {
 		BraseroMedia media;

Modified: trunk/src/brasero-disc-option-dialog.c
==============================================================================
--- trunk/src/brasero-disc-option-dialog.c	(original)
+++ trunk/src/brasero-disc-option-dialog.c	Tue Feb 26 21:02:10 2008
@@ -95,6 +95,9 @@
 	priv = BRASERO_DISC_OPTION_DIALOG_PRIVATE (dialog);
 
 	key = brasero_burn_session_get_config_key (priv->session, "multi");
+	if (!key)
+		return;
+
 	multi_on = (brasero_burn_session_get_flags (priv->session) & BRASERO_BURN_FLAG_MULTI) != 0;
 
 	client = gconf_client_get_default ();
@@ -820,11 +823,14 @@
 
 	brasero_burn_session_get_input_type (priv->session, &type);
 	if (type.type == BRASERO_TRACK_TYPE_DATA) {
-		brasero_drive_selection_show_file_drive (BRASERO_DRIVE_SELECTION (priv->selection), TRUE);
+	brasero_drive_selection_set_type_shown (BRASERO_DRIVE_SELECTION (priv->selection),
+						BRASERO_MEDIA_TYPE_WRITABLE|
+						BRASERO_MEDIA_TYPE_FILE);
 		brasero_disc_option_dialog_add_data_options (dialog);
 	}
 	else if (type.type == BRASERO_TRACK_TYPE_AUDIO) {
-		brasero_drive_selection_show_file_drive (BRASERO_DRIVE_SELECTION (priv->selection), FALSE);
+		brasero_drive_selection_set_type_shown (BRASERO_DRIVE_SELECTION (priv->selection),
+							BRASERO_MEDIA_TYPE_WRITABLE);
 		brasero_disc_option_dialog_add_audio_options (dialog);
 	}
 }
@@ -902,9 +908,6 @@
 			  G_CALLBACK (brasero_disc_option_dialog_valid_media_cb),
 			  obj);
 
-	brasero_drive_selection_select_default_drive (BRASERO_DRIVE_SELECTION (priv->selection),
-						      BRASERO_MEDIUM_WRITABLE);
-
 	options = brasero_utils_pack_properties (_("<b>Select a drive to write to</b>"),
 						 priv->selection,
 						 NULL);

Modified: trunk/src/brasero-drive-info.c
==============================================================================
--- trunk/src/brasero-drive-info.c	(original)
+++ trunk/src/brasero-drive-info.c	Tue Feb 26 21:02:10 2008
@@ -49,9 +49,6 @@
 {
 	NautilusBurnDrive *drive;
 
-	guint added_sig;
-	guint removed_sig;
-
 	GtkWidget *notebook;
 	GtkWidget *image;
 
@@ -262,20 +259,6 @@
 	gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), 0);
 }
 
-static void
-brasero_drive_info_media_added (NautilusBurnDrive *drive,
-				BraseroDriveInfo *self)
-{
-	brasero_drive_info_update_info (self, drive);
-}
-
-static void
-brasero_drive_info_media_removed (NautilusBurnDrive *drive,
-				  BraseroDriveInfo *self)
-{
-	brasero_drive_info_update_info (self, drive);
-}
-
 void
 brasero_drive_info_set_drive (BraseroDriveInfo *self,
 			      NautilusBurnDrive *drive)
@@ -285,16 +268,6 @@
 	priv = BRASERO_DRIVE_INFO_PRIVATE (self);
 
 	if (priv->drive) {
-		if (priv->added_sig) {
-			g_signal_handler_disconnect (priv->drive, priv->added_sig);
-			priv->added_sig = 0;
-		}
-
-		if (priv->removed_sig) {
-			g_signal_handler_disconnect (priv->drive, priv->removed_sig);
-			priv->removed_sig = 0;
-		}
-
 		nautilus_burn_drive_unref (priv->drive);
 		priv->drive = NULL;
 	}
@@ -307,19 +280,6 @@
 		return;
 	}
 
-	if (drive) {
-		priv->added_sig = g_signal_connect (drive,
-						    "media-added",
-						    G_CALLBACK (brasero_drive_info_media_added),
-						    self);
-		priv->removed_sig = g_signal_connect (drive,
-						      "media-removed",
-						      G_CALLBACK (brasero_drive_info_media_removed),
-						      self);
-		priv->drive = drive;
-		nautilus_burn_drive_ref (drive);
-	}
-
 	brasero_drive_info_update_info (self, drive);
 	gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), 1);
 }
@@ -413,16 +373,6 @@
 
 	priv = BRASERO_DRIVE_INFO_PRIVATE (object);
 	if (priv->drive) {
-		if (priv->added_sig) {
-			g_signal_handler_disconnect (priv->drive, priv->added_sig);
-			priv->added_sig = 0;
-		}
-
-		if (priv->removed_sig) {
-			g_signal_handler_disconnect (priv->drive, priv->removed_sig);
-			priv->removed_sig = 0;
-		}
-
 		nautilus_burn_drive_unref (priv->drive);
 		priv->drive = NULL;
 	}

Modified: trunk/src/brasero-drive-selection.c
==============================================================================
--- trunk/src/brasero-drive-selection.c	(original)
+++ trunk/src/brasero-drive-selection.c	Tue Feb 26 21:02:10 2008
@@ -35,11 +35,10 @@
 #include <gtk/gtkhbox.h>
 
 #include <nautilus-burn-drive.h>
-#include <nautilus-burn-drive-monitor.h>
-#include <nautilus-burn-drive-selection.h>
 
 #include "burn-medium.h"
 #include "brasero-ncb.h"
+#include "brasero-medium-selection.h"
 #include "brasero-drive-selection.h"
 #include "brasero-drive-info.h"
 
@@ -67,14 +66,16 @@
 G_DEFINE_TYPE (BraseroDriveSelection, brasero_drive_selection, GTK_TYPE_VBOX);
 
 static void
-brasero_drive_selection_drive_changed_cb (NautilusBurnDriveSelection *selector,
-					  NautilusBurnDrive *drive,
+brasero_drive_selection_drive_changed_cb (BraseroMediumSelection *selector,
 					  BraseroDriveSelection *self)
 {
 	BraseroDriveSelectionPrivate *priv;
+	NautilusBurnDrive *drive;
 
 	priv = BRASERO_DRIVE_SELECTION_PRIVATE (self);
 
+	drive = brasero_drive_selection_get_drive (self);
+
 	brasero_drive_info_set_drive (BRASERO_DRIVE_INFO (priv->info), drive);
 
 	if (priv->locked_drive
@@ -85,7 +86,7 @@
 		priv->locked_drive = NULL;
 	}
 
-	if (drive == NULL) {
+	if (!drive) {
 	    	gtk_widget_set_sensitive (priv->selection, FALSE);
 		g_signal_emit (self,
 			       brasero_drive_selection_signals [DRIVE_CHANGED_SIGNAL],
@@ -109,102 +110,6 @@
 }
 
 void
-brasero_drive_selection_select_default_drive (BraseroDriveSelection *self,
-					      BraseroMedia type)
-{
-	GList *iter;
-	GList *drives;
-	gboolean image;
-	gboolean recorders;
-	BraseroMedia media;
-	NautilusBurnDrive *drive;
-	NautilusBurnDrive *candidate = NULL;
-	BraseroDriveSelectionPrivate *priv;
-
-	priv = BRASERO_DRIVE_SELECTION_PRIVATE (self);
-
-	if (priv->locked_drive)
-		return;
-
-	g_object_get (priv->selection,
-		      "show-recorders-only",
-		      &recorders,
-		      NULL);
-	g_object_get (priv->selection,
-		      "file-image",
-		      &image,
-		      NULL);
-
-	NCB_DRIVE_GET_LIST (drives, recorders, image);
-	for (iter = drives; iter; iter = iter->next) {
-		drive = iter->data;
-
-		if (!drive || NCB_DRIVE_GET_TYPE (drive) == NAUTILUS_BURN_DRIVE_TYPE_FILE)
-			continue;
-
-		media = NCB_MEDIA_GET_STATUS (drive);
-		if (type == BRASERO_MEDIUM_WRITABLE && (media & (BRASERO_MEDIUM_APPENDABLE|BRASERO_MEDIUM_REWRITABLE|BRASERO_MEDIUM_BLANK))) {
-			/* the perfect candidate would be blank; if not keep for later and see if no better media comes up */
-			if (media & BRASERO_MEDIUM_BLANK) {
-				nautilus_burn_drive_selection_set_active (NAUTILUS_BURN_DRIVE_SELECTION (priv->selection), drive);
-				goto end;
-			}
-
-			/* a second choice would be rewritable media and if not appendable */
-			if (media & BRASERO_MEDIUM_REWRITABLE) {
-				if (NCB_MEDIA_GET_STATUS (candidate) & BRASERO_MEDIUM_REWRITABLE){
-					gint64 size_candidate;
-					gint64 size;
-
-					NCB_MEDIA_GET_FREE_SPACE (candidate, &size_candidate, NULL);
-					NCB_MEDIA_GET_FREE_SPACE (drive, &size, NULL);
-					if (size_candidate < size)
-						candidate = drive;
-				}
-				else
-					candidate = drive;
-
-			}
-			/* if both are appendable choose the one with the bigger free space */
-			else if (!(NCB_MEDIA_GET_STATUS (candidate) & BRASERO_MEDIUM_REWRITABLE)) {
-				gint64 size_candidate;
-				gint64 size;
-
-				NCB_MEDIA_GET_FREE_SPACE (candidate, &size_candidate, NULL);
-				NCB_MEDIA_GET_FREE_SPACE (drive, &size, NULL);
-				if (size_candidate < size)
-					candidate = drive;
-			}
-		}
-		else if (type == BRASERO_MEDIUM_REWRITABLE && (media & BRASERO_MEDIUM_REWRITABLE)) {
-			/* the perfect candidate would have data; if not keep it for later and see if no better media comes up */
-			if (media & (BRASERO_MEDIUM_HAS_DATA|BRASERO_MEDIUM_HAS_AUDIO)) {
-				nautilus_burn_drive_selection_set_active (NAUTILUS_BURN_DRIVE_SELECTION (priv->selection), drive);
-				goto end;
-			}
-
-			candidate = drive;
-		}
-		else if (type == BRASERO_MEDIUM_HAS_DATA && (media & (BRASERO_MEDIUM_HAS_DATA|BRASERO_MEDIUM_HAS_AUDIO))) {
-			/* the perfect candidate would not be rewritable; if not keep it for later and see if no better media comes up */
-			if (!(media & BRASERO_MEDIUM_REWRITABLE)) {
-				nautilus_burn_drive_selection_set_active (NAUTILUS_BURN_DRIVE_SELECTION (priv->selection), drive);
-				goto end;
-			}
-
-			candidate = drive;
-		}
-	}
-
-	if (candidate)
-		nautilus_burn_drive_selection_set_active (NAUTILUS_BURN_DRIVE_SELECTION (priv->selection), candidate);
-
-end:
-	g_list_foreach (drives, (GFunc) nautilus_burn_drive_unref, NULL);
-	g_list_free (drives);
-}
-
-void
 brasero_drive_selection_set_image_path (BraseroDriveSelection *self,
 					const gchar *path)
 {
@@ -228,37 +133,30 @@
 				   NautilusBurnDrive *drive)
 {
 	BraseroDriveSelectionPrivate *priv;
+	BraseroMedium *medium;
 
 	priv = BRASERO_DRIVE_SELECTION_PRIVATE (self);
 	if (priv->locked_drive)
 		return;
 
-	nautilus_burn_drive_selection_set_active (NAUTILUS_BURN_DRIVE_SELECTION (priv->selection),
-						  drive);
+	medium = NCB_DRIVE_GET_MEDIUM (drive);
+	brasero_medium_selection_set_active (BRASERO_MEDIUM_SELECTION (priv->selection), medium);
 }
 
 NautilusBurnDrive *
 brasero_drive_selection_get_drive (BraseroDriveSelection *self)
 {
-	GtkTreeIter iter;
-	GtkTreeModel *model;
+	BraseroMedium *medium;
 	NautilusBurnDrive *drive;
 	BraseroDriveSelectionPrivate *priv;
 
 	priv = BRASERO_DRIVE_SELECTION_PRIVATE (self);
 
-	/* This is a hack to work around the inability of ncb to return the
-	 * current selected drive while we're initting an object derived from it
-	 */
-	if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->selection), &iter))
+	medium = brasero_medium_selection_get_active (BRASERO_MEDIUM_SELECTION (priv->selection));
+	if (!medium)
 		return NULL;
 
-	model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->selection));
-	gtk_tree_model_get (model, &iter,
-			    1, &drive,
-			    -1);
-
-	nautilus_burn_drive_ref (drive);
+	drive = brasero_medium_get_drive (medium);
 	return drive;
 }
 
@@ -271,6 +169,7 @@
 	priv = BRASERO_DRIVE_SELECTION_PRIVATE (self);
 
 	gtk_widget_set_sensitive (priv->selection, (locked != TRUE));
+
 	gtk_widget_queue_draw (priv->selection);
 	if (priv->locked_drive) {
 		nautilus_burn_drive_unlock (priv->locked_drive);
@@ -302,31 +201,13 @@
 }
 
 void
-brasero_drive_selection_set_show_all_drives (BraseroDriveSelection *self,
-					     gboolean show)
-{
-	BraseroDriveSelectionPrivate *priv;
-
-	priv = BRASERO_DRIVE_SELECTION_PRIVATE (self);
-	g_object_set (G_OBJECT (priv->selection),
-		      "show-recorders-only", (show == FALSE),
-		      NULL);
-
-	/* ncb sets sensitivity on its own so we need to reset it correctly */
-	if (priv->locked_drive)
-		gtk_widget_set_sensitive (priv->selection, FALSE);
-}
-
-void
-brasero_drive_selection_show_file_drive (BraseroDriveSelection *self,
-					 gboolean show)
+brasero_drive_selection_set_type_shown (BraseroDriveSelection *self,
+					BraseroMediaType type)
 {
 	BraseroDriveSelectionPrivate *priv;
 
 	priv = BRASERO_DRIVE_SELECTION_PRIVATE (self);
-	g_object_set (G_OBJECT (priv->selection),
-		      "file-image", show,
-		      NULL);
+	brasero_medium_selection_show_type (BRASERO_MEDIUM_SELECTION (priv->selection), type);
 
 	/* ncb sets sensitivity on its own so we need to reset it correctly */
 	if (priv->locked_drive)
@@ -355,9 +236,9 @@
 	priv->box = gtk_hbox_new (FALSE, 12);
 	gtk_box_pack_start (GTK_BOX (object), priv->box, FALSE, FALSE, 0);
 
-	priv->selection = nautilus_burn_drive_selection_new ();
+	priv->selection = brasero_medium_selection_new ();
 	g_signal_connect (priv->selection,
-			  "drive-changed",
+			  "medium-changed",
 			  G_CALLBACK (brasero_drive_selection_drive_changed_cb),
 			  object);
 	gtk_box_pack_start (GTK_BOX (priv->box),

Modified: trunk/src/brasero-drive-selection.h
==============================================================================
--- trunk/src/brasero-drive-selection.h	(original)
+++ trunk/src/brasero-drive-selection.h	Tue Feb 26 21:02:10 2008
@@ -30,6 +30,7 @@
 
 #include <nautilus-burn-drive.h>
 
+#include "burn-medium-monitor.h"
 #include "burn-medium.h"
 
 G_BEGIN_DECLS
@@ -85,20 +86,12 @@
 brasero_drive_selection_set_same_src_dest (BraseroDriveSelection *selection);
 
 void
-brasero_drive_selection_select_default_drive (BraseroDriveSelection *selection,
-					      BraseroMedia type);
-
-void
 brasero_drive_selection_set_button (BraseroDriveSelection *selection,
 				    GtkWidget *button);
 
 void
-brasero_drive_selection_show_file_drive (BraseroDriveSelection *selection,
-					 gboolean show);
-
-void
-brasero_drive_selection_set_show_all_drives (BraseroDriveSelection *selection,
-					     gboolean show);
+brasero_drive_selection_set_type_shown (BraseroDriveSelection *self,
+					BraseroMediaType type);
 
 G_END_DECLS
 

Modified: trunk/src/brasero-image-option-dialog.c
==============================================================================
--- trunk/src/brasero-image-option-dialog.c	(original)
+++ trunk/src/brasero-image-option-dialog.c	Tue Feb 26 21:02:10 2008
@@ -532,7 +532,8 @@
 			    FALSE,
 			    6);
 
-	brasero_drive_selection_show_file_drive (BRASERO_DRIVE_SELECTION (priv->selection), FALSE);
+	brasero_drive_selection_set_type_shown (BRASERO_DRIVE_SELECTION (priv->selection),
+						BRASERO_MEDIA_TYPE_WRITABLE);
 
 	/* Image properties */
 	box1 = gtk_table_new (2, 2, FALSE);
@@ -612,9 +613,6 @@
 			  6);
 
 	gtk_widget_show_all (box);
-
-	brasero_drive_selection_select_default_drive (BRASERO_DRIVE_SELECTION (priv->selection),
-						      BRASERO_MEDIUM_WRITABLE);
 	brasero_image_option_dialog_set_formats (obj);
 }
 

Added: trunk/src/brasero-medium-selection.c
==============================================================================
--- (empty file)
+++ trunk/src/brasero-medium-selection.c	Tue Feb 26 21:02:10 2008
@@ -0,0 +1,422 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * brasero
+ * Copyright (C) Philippe Rouquier 2008 <bonfire-app wanadoo fr>
+ * 
+ * brasero is free software.
+ * 
+ * You may redistribute it and/or modify it under the terms of the
+ * GNU General Public License, as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ * 
+ * brasero is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with brasero.  If not, write to:
+ * 	The Free Software Foundation, Inc.,
+ * 	51 Franklin Street, Fifth Floor
+ * 	Boston, MA  02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gi18n-lib.h>
+
+#include <gtk/gtk.h>
+
+#include "brasero-medium-selection.h"
+#include "burn-medium.h"
+#include "burn-basics.h"
+
+typedef struct _BraseroMediumSelectionPrivate BraseroMediumSelectionPrivate;
+struct _BraseroMediumSelectionPrivate
+{
+	BraseroMediaType type;
+	gulong added_sig;
+	gulong removed_sig;
+};
+
+#define BRASERO_MEDIUM_SELECTION_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_MEDIUM_SELECTION, BraseroMediumSelectionPrivate))
+
+enum {
+	MEDIUM_COL,
+	NAME_COL,
+	ICON_COL,
+	NUM_COL
+};
+
+G_DEFINE_TYPE (BraseroMediumSelection, brasero_medium_selection, GTK_TYPE_COMBO_BOX);
+
+enum {
+	MEDIUM_CHANGED,
+	LAST_SIGNAL
+};
+static gulong medium_selection_signals [LAST_SIGNAL];
+
+static void
+brasero_medium_selection_changed (GtkComboBox *box)
+{
+	GtkTreeIter iter;
+
+	if (gtk_combo_box_get_active_iter (box, &iter))
+		g_signal_emit (box,
+			       medium_selection_signals [MEDIUM_CHANGED],
+			       0);
+}
+
+void
+brasero_medium_selection_set_active (BraseroMediumSelection *self,
+				     BraseroMedium *medium)
+{
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+
+	model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
+	if (!gtk_tree_model_get_iter_first (model, &iter))
+		return;
+
+	do {
+		BraseroMedium *iter_medium;
+
+		gtk_tree_model_get (model, &iter,
+				    MEDIUM_COL, &iter_medium,
+				    -1);
+
+		if (medium == iter_medium) {
+			gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self), &iter);
+			g_signal_emit (self,
+				       medium_selection_signals [MEDIUM_CHANGED],
+				       0);
+			break;
+		}
+
+	} while (gtk_tree_model_iter_next (model, &iter));
+}
+
+BraseroMedium *
+brasero_medium_selection_get_active (BraseroMediumSelection *self)
+{
+	BraseroMedium *medium;
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+
+	model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
+	if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (self), &iter))
+		return NULL;
+
+	gtk_tree_model_get (model, &iter,
+			    MEDIUM_COL, &medium,
+			    -1);
+
+	if (!medium)
+		return NULL;
+
+	g_object_ref (medium);
+	return medium;
+}
+
+void
+brasero_medium_selection_show_type (BraseroMediumSelection *self,
+				    BraseroMediaType type)
+{
+	BraseroMediumSelectionPrivate *priv;
+	BraseroMediumMonitor *monitor;
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+	GSList *list;
+	GSList *item;
+
+	priv = BRASERO_MEDIUM_SELECTION_PRIVATE (self);
+
+	priv->type = type;
+
+	monitor = brasero_medium_monitor_get_default ();
+	list = brasero_medium_monitor_get_media (monitor, type);
+	g_object_unref (monitor);
+
+	model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
+	if (gtk_tree_model_get_iter_first (model, &iter)) {
+		/* First filter */
+		do {
+			BraseroMedium *medium;
+
+			gtk_tree_model_get (model, &iter,
+					    MEDIUM_COL, &medium,
+					    -1);
+
+			if (!medium) {
+				/* That's the dummy line saying there isn't any
+				 * available medium for whatever action it is */
+				gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+				break;
+			}
+
+			if (!g_slist_find (list, medium)) {
+				if (gtk_list_store_remove (GTK_LIST_STORE (model), &iter))
+					continue;
+
+				break;
+			}
+
+			list = g_slist_remove (list, medium);
+			g_object_unref (medium);
+		} while (gtk_tree_model_iter_next (model, &iter));
+	}
+
+	if (list) {
+		/* add remaining media */
+		for (item = list; item; item = item->next) {
+			gchar *medium_name;
+			BraseroMedium *medium;
+			const gchar *medium_icon;
+
+			medium = item->data;
+
+			medium_name = brasero_medium_get_display_name (medium);
+			medium_icon = brasero_medium_get_icon (medium);
+
+			gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+			gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+					    MEDIUM_COL, medium,
+					    NAME_COL, medium_name,
+					    ICON_COL, medium_icon,
+					    -1);
+			g_free (medium_name);
+		}
+		g_slist_foreach (list, (GFunc) g_object_unref, NULL);
+		g_slist_free (list);
+	}
+
+	if (!gtk_tree_model_get_iter_first (model, &iter)) {
+		/* Nothing's available =(. Say it. */
+		gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+		gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+				    NAME_COL, _("There is no available medium. Please insert one."),
+				    -1),
+
+		gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self), &iter);
+		g_signal_emit (self,
+			       medium_selection_signals [MEDIUM_CHANGED],
+			       0);
+		return;
+	}
+
+	if (gtk_combo_box_get_active (GTK_COMBO_BOX (self)) == -1) {
+		gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self), &iter);
+		g_signal_emit (self,
+			       medium_selection_signals [MEDIUM_CHANGED],
+			       0);
+	}
+}
+
+static void
+brasero_medium_selection_medium_added_cb (BraseroMediumMonitor *monitor,
+					  BraseroMedium *medium,
+					  BraseroMediumSelection *self)
+{
+	BraseroMediumSelectionPrivate *priv;
+	const gchar *medium_icon;
+	gboolean add = FALSE;
+	GtkTreeModel *model;
+	gchar *medium_name;
+	GtkTreeIter iter;
+
+	priv = BRASERO_MEDIUM_SELECTION_PRIVATE (self);
+
+	if ((priv->type & BRASERO_MEDIA_TYPE_READABLE)
+	&&  (brasero_medium_get_status (medium) & (BRASERO_MEDIUM_HAS_AUDIO|BRASERO_MEDIUM_HAS_DATA)))
+		add = TRUE;
+
+	if (priv->type & BRASERO_MEDIA_TYPE_WRITABLE) {
+		if (brasero_medium_can_be_written (medium))
+			add = TRUE;
+	}
+
+	if (priv->type & BRASERO_MEDIA_TYPE_REWRITABLE) {
+		if (brasero_medium_can_be_rewritten (medium))
+			add = TRUE;
+	}
+
+	if (!add)
+		return;
+
+	model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
+
+	/* remove warning message */
+	if (gtk_tree_model_get_iter_first (model, &iter)) {
+		BraseroMedium *tmp;
+
+		gtk_tree_model_get (model, &iter,
+				    MEDIUM_COL, &tmp,
+				    -1);
+		if (!medium)
+			gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+	}
+
+	medium_name = brasero_medium_get_display_name (medium);
+	medium_icon = brasero_medium_get_icon (medium);
+	gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+	gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+			    MEDIUM_COL, medium,
+			    NAME_COL, medium_name,
+			    ICON_COL, medium_icon,
+			    -1);
+	g_free (medium_name);
+
+	if (gtk_combo_box_get_active (GTK_COMBO_BOX (self)) == -1) {
+		gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self), &iter);
+		g_signal_emit (self,
+			       medium_selection_signals [MEDIUM_CHANGED],
+			       0);
+	}
+}
+
+static void
+brasero_medium_selection_medium_removed_cb (BraseroMediumMonitor *monitor,
+					    BraseroMedium *medium,
+					    BraseroMediumSelection *self)
+{
+	GtkTreeModel *model;
+	GtkTreeIter iter;
+
+	model = gtk_combo_box_get_model (GTK_COMBO_BOX (self));
+	if (!gtk_tree_model_get_iter_first (model, &iter))
+		return;
+
+	do {
+		BraseroMedium *iter_medium;
+
+		gtk_tree_model_get (model, &iter,
+				    MEDIUM_COL, &iter_medium,
+				    -1);
+
+		if (medium == iter_medium) {
+			gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+			break;
+		}
+	} while (gtk_tree_model_iter_next (model, &iter));
+
+	if (!gtk_tree_model_get_iter_first (model, &iter)) {
+		/* Nothing's available any more =(. Say it. */
+		gtk_list_store_append (GTK_LIST_STORE (model), &iter);
+		gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+				    NAME_COL, _("There is no available medium. Please insert one."),
+				    -1),
+
+		gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self), &iter);
+		g_signal_emit (self,
+			       medium_selection_signals [MEDIUM_CHANGED],
+			       0);
+		return;
+	}
+
+	if (gtk_combo_box_get_active (GTK_COMBO_BOX (self)) == -1) {
+		gtk_combo_box_set_active_iter (GTK_COMBO_BOX (self), &iter);
+		g_signal_emit (self,
+			       medium_selection_signals [MEDIUM_CHANGED],
+			       0);
+	}
+}
+
+static void
+brasero_medium_selection_init (BraseroMediumSelection *object)
+{
+	GtkListStore *model;
+	GtkCellRenderer *renderer;
+	BraseroMediumMonitor *monitor;
+	BraseroMediumSelectionPrivate *priv;
+
+	priv = BRASERO_MEDIUM_SELECTION_PRIVATE (object);
+
+	monitor = brasero_medium_monitor_get_default ();
+	priv->added_sig = g_signal_connect (monitor,
+					    "medium-added",
+					    G_CALLBACK (brasero_medium_selection_medium_added_cb),
+					    object);
+	priv->removed_sig = g_signal_connect (monitor,
+					      "medium-removed",
+					      G_CALLBACK (brasero_medium_selection_medium_removed_cb),
+					      object);
+
+	g_object_unref (monitor);
+
+	/* get the list and fill the model */
+	model = gtk_list_store_new (NUM_COL,
+				    G_TYPE_OBJECT,
+				    G_TYPE_STRING,
+				    G_TYPE_STRING);
+
+	gtk_combo_box_set_model (GTK_COMBO_BOX (object), GTK_TREE_MODEL (model));
+
+	renderer = gtk_cell_renderer_pixbuf_new ();
+	g_object_set (renderer, "follow-state", TRUE, NULL);
+	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), renderer, FALSE);
+	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (object), renderer,
+					"icon-name", ICON_COL,
+					NULL);
+
+	renderer = gtk_cell_renderer_text_new ();
+	g_object_set (renderer, "xpad", 8, NULL);
+	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (object), renderer, TRUE);
+	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (object), renderer,
+					"markup", NAME_COL,
+					NULL);
+}
+
+static void
+brasero_medium_selection_finalize (GObject *object)
+{
+	BraseroMediumSelectionPrivate *priv;
+	BraseroMediumMonitor *monitor;
+
+	priv = BRASERO_MEDIUM_SELECTION_PRIVATE (object);
+
+	monitor = brasero_medium_monitor_get_default ();
+
+	g_signal_handler_disconnect (monitor, priv->added_sig);
+	g_signal_handler_disconnect (monitor, priv->removed_sig);
+	priv->added_sig = 0;
+	priv->removed_sig = 0;
+
+	g_object_unref (monitor);
+
+	G_OBJECT_CLASS (brasero_medium_selection_parent_class)->finalize (object);
+}
+
+static void
+brasero_medium_selection_class_init (BraseroMediumSelectionClass *klass)
+{
+	GObjectClass* object_class = G_OBJECT_CLASS (klass);
+	GtkComboBoxClass *combo_class = GTK_COMBO_BOX_CLASS (klass);
+
+	g_type_class_add_private (klass, sizeof (BraseroMediumSelectionPrivate));
+
+	object_class->finalize = brasero_medium_selection_finalize;
+
+	combo_class->changed = brasero_medium_selection_changed;
+
+	medium_selection_signals [MEDIUM_CHANGED] =
+	    g_signal_new ("medium_changed",
+			  G_TYPE_FROM_CLASS (klass),
+			  G_SIGNAL_RUN_FIRST,
+			  0,
+			  NULL, NULL,
+			  g_cclosure_marshal_VOID__VOID,
+			  G_TYPE_NONE,
+			  0,
+			  G_TYPE_NONE);
+}
+
+GtkWidget *
+brasero_medium_selection_new (void)
+{
+	return g_object_new (BRASERO_TYPE_MEDIUM_SELECTION, NULL);
+}

Added: trunk/src/brasero-medium-selection.h
==============================================================================
--- (empty file)
+++ trunk/src/brasero-medium-selection.h	Tue Feb 26 21:02:10 2008
@@ -0,0 +1,74 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * brasero
+ * Copyright (C) Philippe Rouquier 2008 <bonfire-app wanadoo fr>
+ * 
+ * brasero is free software.
+ * 
+ * You may redistribute it and/or modify it under the terms of the
+ * GNU General Public License, as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ * 
+ * brasero is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with brasero.  If not, write to:
+ * 	The Free Software Foundation, Inc.,
+ * 	51 Franklin Street, Fifth Floor
+ * 	Boston, MA  02110-1301, USA.
+ */
+
+#ifndef _BRASERO_MEDIUM_SELECTION_H_
+#define _BRASERO_MEDIUM_SELECTION_H_
+
+#include <glib-object.h>
+
+#include <gtk/gtkcombobox.h>
+
+#include "burn-medium-monitor.h"
+#include "burn-medium.h"
+
+G_BEGIN_DECLS
+
+#define BRASERO_TYPE_MEDIUM_SELECTION             (brasero_medium_selection_get_type ())
+#define BRASERO_MEDIUM_SELECTION(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), BRASERO_TYPE_MEDIUM_SELECTION, BraseroMediumSelection))
+#define BRASERO_MEDIUM_SELECTION_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), BRASERO_TYPE_MEDIUM_SELECTION, BraseroMediumSelectionClass))
+#define BRASERO_IS_MEDIUM_SELECTION(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BRASERO_TYPE_MEDIUM_SELECTION))
+#define BRASERO_IS_MEDIUM_SELECTION_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), BRASERO_TYPE_MEDIUM_SELECTION))
+#define BRASERO_MEDIUM_SELECTION_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), BRASERO_TYPE_MEDIUM_SELECTION, BraseroMediumSelectionClass))
+
+typedef struct _BraseroMediumSelectionClass BraseroMediumSelectionClass;
+typedef struct _BraseroMediumSelection BraseroMediumSelection;
+
+struct _BraseroMediumSelectionClass
+{
+	GtkComboBoxClass parent_class;
+};
+
+struct _BraseroMediumSelection
+{
+	GtkComboBox parent_instance;
+};
+
+GType brasero_medium_selection_get_type (void) G_GNUC_CONST;
+GtkWidget* brasero_medium_selection_new (void);
+
+
+BraseroMedium *
+brasero_medium_selection_get_active (BraseroMediumSelection *self);
+
+void
+brasero_medium_selection_set_active (BraseroMediumSelection *self,
+				     BraseroMedium *medium);
+
+void
+brasero_medium_selection_show_type (BraseroMediumSelection *self,
+				    BraseroMediaType type);
+
+G_END_DECLS
+
+#endif /* _BRASERO_MEDIUM_SELECTION_H_ */

Modified: trunk/src/brasero-ncb.c
==============================================================================
--- trunk/src/brasero-ncb.c	(original)
+++ trunk/src/brasero-ncb.c	Tue Feb 26 21:02:10 2008
@@ -742,60 +742,16 @@
 	return brasero_medium_get_icon (medium);
 }
 
-static void
-brasero_ncb_inserted_medium_cb (NautilusBurnDriveMonitor *monitor,
-				NautilusBurnDrive *drive,
-				gpointer null_data)
+BraseroMedium *
+NCB_DRIVE_GET_MEDIUM (NautilusBurnDrive *drive)
 {
-	BraseroMedium *medium;
-
-	medium = brasero_medium_new (drive);
-	g_object_set_data (G_OBJECT (drive), BRASERO_MEDIUM_KEY, medium);
-}
-
-static void
-brasero_ncb_removed_medium_cb (NautilusBurnDriveMonitor *monitor,
-			       NautilusBurnDrive *drive,
-			       gpointer null_data)
-{
-	BraseroMedium *medium;
-
-	medium = g_object_get_data (G_OBJECT (drive), BRASERO_MEDIUM_KEY);
-	g_object_set_data (G_OBJECT (drive), BRASERO_MEDIUM_KEY, NULL);
-
-	if (!medium)
-		return;
-
-	g_object_unref (medium);
+	return g_object_get_data (G_OBJECT (drive), BRASERO_MEDIUM_KEY);
 }
 
 void
-NCB_INIT (void)
+NCB_DRIVE_SET_MEDIUM (NautilusBurnDrive *drive,
+		      BraseroMedium *medium)
 {
-	NautilusBurnDriveMonitor *monitor;
-	GList *iter, *list;
-
-	monitor = nautilus_burn_get_drive_monitor ();
-
-	list = nautilus_burn_drive_monitor_get_drives (monitor);
-	for (iter = list; iter; iter = iter->next) {
-		BraseroMedium *medium;
-		NautilusBurnDrive *drive;
-
-		drive = iter->data;
-		medium = brasero_medium_new (drive);
-		g_object_set_data (G_OBJECT (drive),
-				   BRASERO_MEDIUM_KEY,
-				   medium);
-	}
-	g_list_free (list);
-
-	g_signal_connect (monitor,
-			  "media-added",
-			  G_CALLBACK (brasero_ncb_inserted_medium_cb),
-			  NULL);
-	g_signal_connect (monitor,
-			  "media-removed",
-			  G_CALLBACK (brasero_ncb_removed_medium_cb),
-			  NULL);
+	g_object_set_data (G_OBJECT (drive), BRASERO_MEDIUM_KEY, medium);
 }
+

Modified: trunk/src/brasero-ncb.h
==============================================================================
--- trunk/src/brasero-ncb.h	(original)
+++ trunk/src/brasero-ncb.h	Tue Feb 26 21:02:10 2008
@@ -55,6 +55,13 @@
 		list = g_list_prepend (list, nautilus_burn_drive_monitor_get_drive_for_image (monitor));	\
 }
 
+BraseroMedium *
+NCB_DRIVE_GET_MEDIUM (NautilusBurnDrive *drive);
+
+void
+NCB_DRIVE_SET_MEDIUM (NautilusBurnDrive *drive,
+		      BraseroMedium *medium);
+
 gboolean
 NCB_DRIVE_UNMOUNT (NautilusBurnDrive *drive, GError **error);
 

Modified: trunk/src/brasero-src-selection.c
==============================================================================
--- trunk/src/brasero-src-selection.c	(original)
+++ trunk/src/brasero-src-selection.c	Tue Feb 26 21:02:10 2008
@@ -88,7 +88,10 @@
 {
 	brasero_drive_selection_set_tooltip (BRASERO_DRIVE_SELECTION (object),
 					     _("Choose which drive holds the disc to read from"));
-	brasero_drive_selection_set_show_all_drives (BRASERO_DRIVE_SELECTION (object), TRUE);
+
+	/* only show media with something to be read on them */
+	brasero_drive_selection_set_type_shown (BRASERO_DRIVE_SELECTION (object),
+						BRASERO_MEDIA_TYPE_READABLE);
 }
 
 static void

Modified: trunk/src/brasero-tool-dialog.c
==============================================================================
--- trunk/src/brasero-tool-dialog.c	(original)
+++ trunk/src/brasero-tool-dialog.c	Tue Feb 26 21:02:10 2008
@@ -475,8 +475,9 @@
 							   NULL),
 			    FALSE, FALSE, 0);
 
-	brasero_drive_selection_select_default_drive (BRASERO_DRIVE_SELECTION (obj->priv->selector),
-						      BRASERO_MEDIUM_REWRITABLE);
+	brasero_drive_selection_set_type_shown (BRASERO_DRIVE_SELECTION (obj->priv->selector),
+						BRASERO_MEDIA_TYPE_REWRITABLE|
+						BRASERO_MEDIA_TYPE_READABLE);
 
 	gtk_widget_show_all (GTK_WIDGET (obj->priv->upper_box));
 

Modified: trunk/src/burn-basics.c
==============================================================================
--- trunk/src/burn-basics.c	(original)
+++ trunk/src/burn-basics.c	Tue Feb 26 21:02:10 2008
@@ -36,10 +36,12 @@
 #include "burn-debug.h"
 #include "burn-caps.h"
 #include "burn-plugin-manager.h"
+#include "burn-medium-monitor.h"
 #include "burn-plugin-private.h"
 #include "brasero-ncb.h"
 
-static BraseroPluginManager *manager = NULL;
+static BraseroPluginManager *plugin_manager = NULL;
+static BraseroMediumMonitor *medium_manager = NULL;
 
 GQuark
 brasero_burn_quark (void)
@@ -78,13 +80,18 @@
 BraseroBurnResult
 brasero_burn_library_init (void)
 {
+	/* initialize all device list */
+	
 	nautilus_burn_init ();
-	NCB_INIT ();
 
+	if (!medium_manager)
+		medium_manager = brasero_medium_monitor_get_default ();
+
+	/* initialize plugins */
 	brasero_burn_caps_get_default ();
 
-	if (!manager)
-		manager = brasero_plugin_manager_get_default ();
+	if (!plugin_manager)
+		plugin_manager = brasero_plugin_manager_get_default ();
 
 	brasero_caps_list_dump ();
 	return BRASERO_BURN_OK;
@@ -93,15 +100,19 @@
 GSList *
 brasero_burn_library_get_plugins_list (void)
 {
-	manager = brasero_plugin_manager_get_default ();
-	return brasero_plugin_manager_get_plugins_list (manager);
+	plugin_manager = brasero_plugin_manager_get_default ();
+	return brasero_plugin_manager_get_plugins_list (plugin_manager);
 }
 
 void
 brasero_burn_library_shutdown (void)
 {
-	if (manager) {
-		g_object_unref (manager);
-		manager = NULL;
+	if (plugin_manager) {
+		g_object_unref (plugin_manager);
+		plugin_manager = NULL;
+	}
+	if (medium_manager) {
+		g_object_unref (medium_manager);
+		medium_manager = NULL;
 	}
 }

Added: trunk/src/burn-medium-monitor.c
==============================================================================
--- (empty file)
+++ trunk/src/burn-medium-monitor.c	Tue Feb 26 21:02:10 2008
@@ -0,0 +1,280 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * brasero
+ * Copyright (C) Philippe Rouquier 2008 <bonfire-app wanadoo fr>
+ * 
+ * brasero is free software.
+ * 
+ * You may redistribute it and/or modify it under the terms of the
+ * GNU General Public License, as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ * 
+ * brasero is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with brasero.  If not, write to:
+ * 	The Free Software Foundation, Inc.,
+ * 	51 Franklin Street, Fifth Floor
+ * 	Boston, MA  02110-1301, USA.
+ */
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+
+#include <nautilus-burn-drive-monitor.h>
+
+#include "brasero-ncb.h"
+
+#include "burn-medium.h"
+#include "burn-medium-monitor.h"
+
+typedef struct _BraseroMediumMonitorPrivate BraseroMediumMonitorPrivate;
+struct _BraseroMediumMonitorPrivate
+{
+	GSList * media;
+	BraseroMedium *file_medium;
+	NautilusBurnDriveMonitor *monitor;
+};
+
+#define BRASERO_MEDIUM_MONITOR_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_MEDIUM_MONITOR, BraseroMediumMonitorPrivate))
+
+enum
+{
+	MEDIUM_INSERTED,
+	MEDIUM_REMOVED,
+
+	LAST_SIGNAL
+};
+
+
+static guint medium_monitor_signals[LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (BraseroMediumMonitor, brasero_medium_monitor, G_TYPE_OBJECT);
+
+static BraseroMedium *
+brasero_burn_medium_get_file (BraseroMediumMonitor *self)
+{
+	BraseroMediumMonitorPrivate *priv;
+
+	priv = BRASERO_MEDIUM_MONITOR_PRIVATE (self);
+
+	if (priv->file_medium) {
+		g_object_ref (priv->file_medium);
+		return priv->file_medium;
+	}
+
+	priv->file_medium = g_object_new (BRASERO_TYPE_MEDIUM,
+					  "drive", nautilus_burn_drive_monitor_get_drive_for_image (priv->monitor),
+					  NULL);
+	g_object_ref (priv->file_medium);
+	return priv->file_medium;
+}
+
+GSList *
+brasero_medium_monitor_get_media (BraseroMediumMonitor *self,
+				  BraseroMediaType type)
+{
+	GSList *iter;
+	GSList *list = NULL;
+	BraseroMediumMonitorPrivate *priv;
+
+	priv = BRASERO_MEDIUM_MONITOR_PRIVATE (self);
+
+	for (iter = priv->media; iter; iter = iter->next) {
+		BraseroMedium *medium;
+
+		medium = iter->data;
+		if ((type & BRASERO_MEDIA_TYPE_READABLE)
+		&&  (brasero_medium_get_status (medium) & (BRASERO_MEDIUM_HAS_AUDIO|BRASERO_MEDIUM_HAS_DATA))) {
+			list = g_slist_prepend (list, medium);
+			g_object_ref (medium);
+			continue;
+		}
+
+		if (type & BRASERO_MEDIA_TYPE_WRITABLE) {
+			if (brasero_medium_can_be_written (medium)) {
+				list = g_slist_prepend (list, medium);
+				g_object_ref (medium);
+				continue;
+			}
+		}
+
+		if (type & BRASERO_MEDIA_TYPE_REWRITABLE) {
+			if (brasero_medium_can_be_rewritten (medium)) {
+				list = g_slist_prepend (list, medium);
+				g_object_ref (medium);
+			}
+		}
+	}
+
+	if (type & BRASERO_MEDIA_TYPE_FILE)
+		list = g_slist_append (list, brasero_burn_medium_get_file (self));
+
+	return list;
+}
+
+static void
+brasero_medium_monitor_inserted_cb (NautilusBurnDriveMonitor *monitor,
+				    NautilusBurnDrive *drive,
+				    BraseroMedium *self)
+{
+	BraseroMediumMonitorPrivate *priv;
+	BraseroMedium *medium;
+
+	priv = BRASERO_MEDIUM_MONITOR_PRIVATE (self);
+
+	medium = brasero_medium_new (drive);
+	NCB_DRIVE_SET_MEDIUM (drive, medium);
+
+	priv->media = g_slist_prepend (priv->media, medium);
+	g_object_ref (medium);
+
+	g_signal_emit (self,
+		       medium_monitor_signals [MEDIUM_INSERTED],
+		       0,
+		       medium);
+}
+
+static void
+brasero_medium_monitor_removed_cb (NautilusBurnDriveMonitor *monitor,
+				   NautilusBurnDrive *drive,
+				   BraseroMedium *self)
+{
+	BraseroMediumMonitorPrivate *priv;
+	BraseroMedium *medium;
+
+	priv = BRASERO_MEDIUM_MONITOR_PRIVATE (self);
+
+	medium = NCB_DRIVE_GET_MEDIUM (drive);
+	NCB_DRIVE_SET_MEDIUM (drive, NULL);
+
+	if (!medium)
+		return;
+
+	priv->media = g_slist_remove (priv->media, medium);
+	g_signal_emit (self,
+		       medium_monitor_signals [MEDIUM_REMOVED],
+		       0,
+		       medium);
+
+	g_object_unref (medium);
+}
+
+static void
+brasero_medium_monitor_init (BraseroMediumMonitor *object)
+{
+	BraseroMediumMonitorPrivate *priv;
+	GList *iter, *list;
+
+	priv = BRASERO_MEDIUM_MONITOR_PRIVATE (object);
+
+	priv->monitor = nautilus_burn_get_drive_monitor ();
+
+	list = nautilus_burn_drive_monitor_get_drives (priv->monitor);
+	for (iter = list; iter; iter = iter->next) {
+		BraseroMedium *medium;
+		NautilusBurnDrive *drive;
+
+		drive = iter->data;
+		medium = brasero_medium_new (drive);
+
+		if (nautilus_burn_drive_get_media_type (drive) < NAUTILUS_BURN_MEDIA_TYPE_CD)
+			continue;
+
+		if (!medium)
+			continue;
+
+		priv->media = g_slist_prepend (priv->media, medium);
+		g_object_ref (medium);
+
+		NCB_DRIVE_SET_MEDIUM (drive, medium);
+	}
+	g_list_free (list);
+
+	g_signal_connect (priv->monitor,
+			  "media-added",
+			  G_CALLBACK (brasero_medium_monitor_inserted_cb),
+			  object);
+	g_signal_connect (priv->monitor,
+			  "media-removed",
+			  G_CALLBACK (brasero_medium_monitor_removed_cb),
+			  object);
+}
+
+static void
+brasero_medium_monitor_finalize (GObject *object)
+{
+	BraseroMediumMonitorPrivate *priv;
+
+	priv = BRASERO_MEDIUM_MONITOR_PRIVATE (object);
+
+	if (priv->monitor) {
+		g_object_unref (priv->monitor);
+		priv->monitor = NULL;
+	}
+
+	if (priv->file_medium) {
+		g_object_unref (priv->file_medium);
+		priv->file_medium = NULL;
+	}
+
+	if (priv->media) {
+		g_slist_foreach (priv->media, (GFunc) g_object_unref, NULL);
+		g_slist_free (priv->media);
+		priv->media = NULL;
+	}
+
+	G_OBJECT_CLASS (brasero_medium_monitor_parent_class)->finalize (object);
+}
+
+static void
+brasero_medium_monitor_class_init (BraseroMediumMonitorClass *klass)
+{
+	GObjectClass* object_class = G_OBJECT_CLASS (klass);
+
+	g_type_class_add_private (klass, sizeof (BraseroMediumMonitorPrivate));
+
+	object_class->finalize = brasero_medium_monitor_finalize;
+
+	medium_monitor_signals[MEDIUM_INSERTED] =
+		g_signal_new ("medium_added",
+		              G_OBJECT_CLASS_TYPE (klass),
+		              G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_ACTION,
+		              0,
+		              NULL, NULL,
+		              g_cclosure_marshal_VOID__OBJECT,
+		              G_TYPE_NONE, 1,
+		              BRASERO_TYPE_MEDIUM);
+
+	medium_monitor_signals[MEDIUM_REMOVED] =
+		g_signal_new ("medium_removed",
+		              G_OBJECT_CLASS_TYPE (klass),
+		              G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_ACTION,
+		              0,
+		              NULL, NULL,
+		              g_cclosure_marshal_VOID__OBJECT,
+		              G_TYPE_NONE, 1,
+		              BRASERO_TYPE_MEDIUM);
+}
+
+static BraseroMediumMonitor *singleton = NULL;
+
+BraseroMediumMonitor *
+brasero_medium_monitor_get_default (void)
+{
+	if (singleton) {
+		g_object_ref (singleton);
+		return singleton;
+	}
+
+	singleton = g_object_new (BRASERO_TYPE_MEDIUM_MONITOR, NULL);
+	g_object_ref (singleton);
+	return singleton;
+}

Added: trunk/src/burn-medium-monitor.h
==============================================================================
--- (empty file)
+++ trunk/src/burn-medium-monitor.h	Tue Feb 26 21:02:10 2008
@@ -0,0 +1,72 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * brasero
+ * Copyright (C) Philippe Rouquier 2008 <bonfire-app wanadoo fr>
+ * 
+ * brasero is free software.
+ * 
+ * You may redistribute it and/or modify it under the terms of the
+ * GNU General Public License, as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ * 
+ * brasero is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with brasero.  If not, write to:
+ * 	The Free Software Foundation, Inc.,
+ * 	51 Franklin Street, Fifth Floor
+ * 	Boston, MA  02110-1301, USA.
+ */
+
+#ifndef _BRASERO_MEDIUM_MONITOR_H_
+#define _BRASERO_MEDIUM_MONITOR_H_
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define BRASERO_TYPE_MEDIUM_MONITOR             (brasero_medium_monitor_get_type ())
+#define BRASERO_MEDIUM_MONITOR(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), BRASERO_TYPE_MEDIUM_MONITOR, BraseroMediumMonitor))
+#define BRASERO_MEDIUM_MONITOR_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), BRASERO_TYPE_MEDIUM_MONITOR, BraseroMediumMonitorClass))
+#define BRASERO_IS_MEDIUM_MONITOR(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BRASERO_TYPE_MEDIUM_MONITOR))
+#define BRASERO_IS_MEDIUM_MONITOR_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), BRASERO_TYPE_MEDIUM_MONITOR))
+#define BRASERO_MEDIUM_MONITOR_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), BRASERO_TYPE_MEDIUM_MONITOR, BraseroMediumMonitorClass))
+
+typedef struct _BraseroMediumMonitorClass BraseroMediumMonitorClass;
+typedef struct _BraseroMediumMonitor BraseroMediumMonitor;
+
+struct _BraseroMediumMonitorClass
+{
+	GObjectClass parent_class;
+};
+
+struct _BraseroMediumMonitor
+{
+	GObject parent_instance;
+};
+
+GType brasero_medium_monitor_get_type (void) G_GNUC_CONST;
+
+BraseroMediumMonitor *
+brasero_medium_monitor_get_default (void);
+
+typedef enum {
+	BRASERO_MEDIA_TYPE_NONE				= 0,
+	BRASERO_MEDIA_TYPE_FILE				= 1,
+	BRASERO_MEDIA_TYPE_READABLE			= 1 << 1,
+	BRASERO_MEDIA_TYPE_WRITABLE			= 1 << 2,
+	BRASERO_MEDIA_TYPE_REWRITABLE			= 1 << 3,
+	BRASERO_MEDIA_TYPE_ALL				= 0xFF
+} BraseroMediaType;
+
+GSList *
+brasero_medium_monitor_get_media (BraseroMediumMonitor *monitor,
+				  BraseroMediaType type);
+
+G_END_DECLS
+
+#endif /* _BRASERO_MEDIUM_MONITOR_H_ */

Modified: trunk/src/burn-medium.c
==============================================================================
--- trunk/src/burn-medium.c	(original)
+++ trunk/src/burn-medium.c	Tue Feb 26 21:02:10 2008
@@ -53,7 +53,7 @@
 #include "burn-volume.h"
 #include "brasero-ncb.h"
 
-const gchar *icons [] = { 	"gnome-dev-removable",
+const gchar *icons [] = { 	"iso-image-new",
 				"gnome-dev-cdrom",
 				"gnome-dev-disc-cdr",
 				"gnome-dev-disc-cdrw",
@@ -2053,6 +2053,18 @@
 }
 
 static void
+brasero_medium_init_file (BraseroMedium *self)
+{
+	BraseroMediumPrivate *priv;
+
+	priv = BRASERO_MEDIUM_PRIVATE (self);
+
+	priv->info = BRASERO_MEDIUM_FILE;
+	priv->type = types [0];
+	priv->icon = icons [0];
+}
+
+static void
 brasero_medium_init (BraseroMedium *object)
 {
 	BraseroMediumPrivate *priv;
@@ -2105,6 +2117,12 @@
 	case PROP_DRIVE:
 		priv->drive = g_value_get_object (value);
 		nautilus_burn_drive_ref (priv->drive);
+
+		if (nautilus_burn_drive_get_drive_type (priv->drive) == NAUTILUS_BURN_DRIVE_TYPE_FILE) {
+			brasero_medium_init_file (BRASERO_MEDIUM (object));
+			break;
+		}
+
 		brasero_medium_try_open (BRASERO_MEDIUM (object));
 		break;
 	default:
@@ -2155,6 +2173,60 @@
 	                                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 }
 
+gboolean
+brasero_medium_can_be_written (BraseroMedium *self)
+{
+	BraseroMediumPrivate *priv;
+
+	priv = BRASERO_MEDIUM_PRIVATE (self);
+
+	if (!(priv->info & BRASERO_MEDIUM_REWRITABLE)
+	&&   (priv->info & BRASERO_MEDIUM_CLOSED))
+		return FALSE;
+
+	return nautilus_burn_drive_can_write (priv->drive);
+}
+
+gboolean
+brasero_medium_can_be_rewritten (BraseroMedium *self)
+{
+	BraseroMediumPrivate *priv;
+
+	priv = BRASERO_MEDIUM_PRIVATE (self);
+
+	if (!(priv->info & BRASERO_MEDIUM_REWRITABLE))
+		return FALSE;
+
+	return nautilus_burn_drive_can_rewrite (priv->drive);
+}
+
+gchar *
+brasero_medium_get_display_name (BraseroMedium *self)
+{
+	BraseroMediumPrivate *priv;
+	gchar *label;
+
+	priv = BRASERO_MEDIUM_PRIVATE (self);
+	if (priv->info & BRASERO_MEDIUM_FILE)
+		return g_strdup (_("Image file"));
+
+	label = nautilus_burn_drive_get_media_label (priv->drive);
+	if (label && label [0] != '\0')
+		return label;
+
+	return nautilus_burn_drive_get_name_for_display (priv->drive);
+}
+
+NautilusBurnDrive *
+brasero_medium_get_drive (BraseroMedium *self)
+{
+	BraseroMediumPrivate *priv;
+
+	priv = BRASERO_MEDIUM_PRIVATE (self);
+	g_object_ref (priv->drive);
+	return priv->drive;
+}
+
 GType
 brasero_medium_get_type (void)
 {
@@ -2191,3 +2263,4 @@
 					     "drive", drive,
 					     NULL));
 }
+

Modified: trunk/src/burn-medium.h
==============================================================================
--- trunk/src/burn-medium.h	(original)
+++ trunk/src/burn-medium.h	Tue Feb 26 21:02:10 2008
@@ -254,12 +254,24 @@
 			      gint64 *size,
 			      gint64 *blocks);
 
+gboolean
+brasero_medium_can_be_rewritten (BraseroMedium *medium);
+
+gboolean
+brasero_medium_can_be_written (BraseroMedium *medium);
+
+gchar *
+brasero_medium_get_display_name (BraseroMedium *medium);
+
 const gchar *
 brasero_medium_get_type_string (BraseroMedium *medium);
 
 const gchar *
 brasero_medium_get_icon (BraseroMedium *medium);
 
+NautilusBurnDrive *
+brasero_medium_get_drive (BraseroMedium *self);
+
 G_END_DECLS
 
 #endif /* _BURN_MEDIUM_H_ */

Modified: trunk/src/plugins/cdrdao/burn-toc2cue.c
==============================================================================
--- trunk/src/plugins/cdrdao/burn-toc2cue.c	(original)
+++ trunk/src/plugins/cdrdao/burn-toc2cue.c	Tue Feb 26 21:02:10 2008
@@ -28,6 +28,7 @@
 
 #include <string.h>
 #include <errno.h>
+#include <unistd.h>
 
 #include <glib.h>
 #include <glib-object.h>

Modified: trunk/src/plugins/dvdcss/burn-dvdcss.c
==============================================================================
--- trunk/src/plugins/dvdcss/burn-dvdcss.c	(original)
+++ trunk/src/plugins/dvdcss/burn-dvdcss.c	Tue Feb 26 21:02:10 2008
@@ -30,6 +30,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 #include <glib.h>
 #include <glib-object.h>

Modified: trunk/src/scsi-read-disc-structure.c
==============================================================================
--- trunk/src/scsi-read-disc-structure.c	(original)
+++ trunk/src/scsi-read-disc-structure.c	Tue Feb 26 21:02:10 2008
@@ -91,7 +91,7 @@
 BRASERO_MEDIA_DVD_HD_DVD			= 0x00,
 BRASERO_MEDIA_BD				= 0x01
 	/* reserved */
-} BraseroMediaType;
+} BraseroScsiMediaType;
 
 static BraseroScsiResult
 brasero_read_disc_structure (BraseroReadDiscStructureCDB *cdb,



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