#! /bin/sh /usr/share/dpatch/dpatch-run
## 13_fix_device_selection.dpatch by Goedson Teixeira Paixao <goedson@debian.org>
##
## DP: Fix a bug in the writer device selection that would make
## DP: gnomebaker use a device different from the one selected when
## DP: there's a read only device installed in the system.

@DPATCH@
diff -urNad gnomebaker-0.6.0~/gnomebaker.glade gnomebaker-0.6.0/gnomebaker.glade
--- gnomebaker-0.6.0~/gnomebaker.glade	2006-09-06 16:21:44.000000000 -0300
+++ gnomebaker-0.6.0/gnomebaker.glade	2006-11-24 22:39:56.000000000 -0200
@@ -3262,7 +3262,7 @@
 	  <property name="border_width">10</property>
 	  <property name="visible">True</property>
 	  <property name="n_rows">3</property>
-	  <property name="n_columns">5</property>
+	  <property name="n_columns">1</property>
 	  <property name="homogeneous">False</property>
 	  <property name="row_spacing">10</property>
 	  <property name="column_spacing">10</property>
@@ -3287,7 +3287,7 @@
 	    </widget>
 	    <packing>
 	      <property name="left_attach">0</property>
-	      <property name="right_attach">5</property>
+	      <property name="right_attach">1</property>
 	      <property name="top_attach">0</property>
 	      <property name="bottom_attach">1</property>
 	      <property name="x_options">fill</property>
@@ -3315,7 +3315,7 @@
 	    </widget>
 	    <packing>
 	      <property name="left_attach">0</property>
-	      <property name="right_attach">5</property>
+	      <property name="right_attach">1</property>
 	      <property name="top_attach">1</property>
 	      <property name="bottom_attach">2</property>
 	      <property name="x_options">fill</property>
@@ -3324,18 +3324,17 @@
 	  </child>
 
 	  <child>
-	    <widget class="GtkOptionMenu" id="optmenWriter">
+	    <widget class="GtkComboBox" id="cmbWriter">
 	      <property name="visible">True</property>
-	      <property name="can_focus">True</property>
-	      <property name="history">-1</property>
+	      <property name="add_tearoffs">False</property>
+	      <property name="focus_on_click">True</property>
 	    </widget>
 	    <packing>
 	      <property name="left_attach">0</property>
-	      <property name="right_attach">5</property>
+	      <property name="right_attach">1</property>
 	      <property name="top_attach">2</property>
 	      <property name="bottom_attach">3</property>
 	      <property name="x_options">fill</property>
-	      <property name="y_options"></property>
 	    </packing>
 	  </child>
 	</widget>
diff -urNad gnomebaker-0.6.0~/gnomebaker.gladep gnomebaker-0.6.0/gnomebaker.gladep
--- gnomebaker-0.6.0~/gnomebaker.gladep	1969-12-31 21:00:00.000000000 -0300
+++ gnomebaker-0.6.0/gnomebaker.gladep	2006-11-24 22:39:56.000000000 -0200
@@ -0,0 +1,7 @@
+<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
+<!DOCTYPE glade-project SYSTEM "http://glade.gnome.org/glade-project-2.0.dtd">
+
+<glade-project>
+  <name></name>
+  <program_name></program_name>
+</glade-project>
diff -urNad gnomebaker-0.6.0~/src/devices.c gnomebaker-0.6.0/src/devices.c
--- gnomebaker-0.6.0~/src/devices.c	2006-11-24 22:39:56.000000000 -0200
+++ gnomebaker-0.6.0/src/devices.c	2006-11-24 22:41:00.000000000 -0200
@@ -171,21 +171,16 @@
 
 
 void
-devices_populate_optionmenu(GtkWidget *option_menu, const gchar *device_key, const gboolean add_writers_only)
+devices_populate_combo_box(GtkComboBox *combo_box, const gchar *device_key, const gboolean add_writers_only)
 {
 	GB_LOG_FUNC
-	g_return_if_fail(option_menu != NULL);
-	g_return_if_fail(device_key != NULL);
+	  g_return_val_if_fail(device_key != NULL, NULL);
 
 	gchar *default_select = preferences_get_string(device_key);
 
-	GtkWidget *menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(option_menu));
-	if(menu != NULL)
-		gtk_widget_destroy(menu);
-	menu = gtk_menu_new();
-	gtk_widget_show(menu);
-
-	gint index = 0, history = 0;
+	GtkListStore *model  = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
+	GtkTreeIter iter;
+	gint index = 0, current_item = 0, active_item = 0;
 	GSList *devices = preferences_get_key_subkeys(GB_DEVICES_KEY);
 	GSList *item = devices;
 	for(; item != NULL; item = item->next)
@@ -193,53 +188,62 @@
 		gchar *device_key = (gchar*)item->data;
 		gchar *device_name_key = g_strconcat(device_key, GB_DEVICE_NAME_LABEL, NULL);
 		gchar *device_name = preferences_get_string(device_name_key);
-        gchar *device_capabilities_key = g_strconcat(device_key, GB_DEVICE_CAPABILITIES_LABEL, NULL);
-        const gint capabilities = preferences_get_int(device_capabilities_key);
-        /* Check the capabilities of the device and make sure that, if we are only adding
-         * writers to the option menu, the device can actually write disks */
+		gchar *device_capabilities_key = g_strconcat(device_key, GB_DEVICE_CAPABILITIES_LABEL, NULL);
+		const gint capabilities = preferences_get_int(device_capabilities_key);
+		/* Check the capabilities of the device and make sure that, if we are only adding
+		 * writers to the option menu, the device can actually write disks */
 		if(device_name != NULL && (!add_writers_only ||
                 (capabilities & DC_WRITE_CDR || capabilities & DC_WRITE_CDRW ||
                 capabilities & DC_WRITE_DVDR || capabilities & DC_WRITE_DVDRAM)))
 		{
-			GtkWidget *menu_item = gtk_menu_item_new_with_label(device_name);
-			gtk_widget_show(menu_item);
-			gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
-
-			if(default_select != NULL)
+		  gtk_list_store_append(model, &iter);
+		  gtk_list_store_set(model, &iter, 0, device_name, 1, index, -1);
+			
+		  	if(default_select != NULL)
 			{
 				gchar *device_key_id = g_strrstr(device_key, default_select);
 				if(device_key_id != NULL)
-					history = index;
+					active_item = current_item;
 			}
 			g_free(device_name);
+			current_item ++;
 		}
-
-        g_free(device_capabilities_key);
+		g_free(device_capabilities_key);
 		g_free(device_key);
 		g_free(device_name_key);
 		++index;
 	}
 
 	g_slist_free(devices);
-
-	gtk_option_menu_set_menu(GTK_OPTION_MENU(option_menu), menu);
-	gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), history);
-
 	g_free(default_select);
+	gtk_combo_box_set_model(combo_box, model);
+	gtk_combo_box_set_active(combo_box, active_item);
+	g_object_unref(model);
+	GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
+	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), renderer, TRUE);
+	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), renderer,"text", 0, NULL);
+
 }
 
 
 void
-devices_save_optionmenu(GtkOptionMenu *option_menu, const gchar *device_key)
+devices_save_combo_box(GtkComboBox *combo_box, const gchar *device_key)
 {
 	GB_LOG_FUNC
-	g_return_if_fail(option_menu != NULL);
-	g_return_if_fail(device_key != NULL);
+	g_assert(combo_box != NULL);
+	g_assert(device_key != NULL);
 
-	gint index = gtk_option_menu_get_history(option_menu);
-	gchar *device = g_strdup_printf(GB_DEVICE_FORMAT, index + 1);
-	preferences_set_string(device_key, device);
-	g_free(device);
+    gint index;
+	GtkTreeIter iter;
+	GtkTreeModel *model = gtk_combo_box_get_model(combo_box);
+	
+	if (gtk_combo_box_get_active_iter(combo_box, &iter)) 
+    {
+          gtk_tree_model_get(model, &iter, 1, &index, -1);
+          gchar *device = g_strdup_printf(GB_DEVICE_FORMAT, index + 1);
+          preferences_set_string(device_key, device);
+          g_free(device);
+    }
 }
 
 
diff -urNad gnomebaker-0.6.0~/src/devices.h gnomebaker-0.6.0/src/devices.h
--- gnomebaker-0.6.0~/src/devices.h	2006-05-29 13:20:49.000000000 -0300
+++ gnomebaker-0.6.0/src/devices.h	2006-11-24 22:41:24.000000000 -0200
@@ -38,14 +38,14 @@
 
 gboolean devices_probe_busses();
 gboolean devices_init();
-void devices_populate_optionmenu(GtkWidget *option_menu, const gchar *default_select, const gboolean add_writers_only);
+void devices_populate_combo_box(GtkComboBox *option_menu, const gchar *default_select, const gboolean add_writers_only);
 gchar *devices_get_device_config(const gchar *device_key, const gchar *device_item);
 void devices_write_device_to_gconf(const gint device_number, const gchar *device_name,
 	const gchar *device_id, const gchar *device_node, const gchar *mount_point,
 	const gint capabilities);
 gboolean devices_mount_device(const gchar *device_key, gchar* *mount_point);
 void devices_unmount_device(const gchar *device_key);
-void devices_save_optionmenu(GtkOptionMenu *option_menu, const gchar *device_key);
+void devices_save_combo_box(GtkComboBox *combo_box, const gchar *device_key);
 gboolean devices_eject_disk(const gchar *device_key);
 gint devices_prompt_for_disk(GtkWindow *parent, const gchar *device_key);
 gint devices_prompt_for_blank_disk(GtkWindow *parent, const gchar *device_key);
diff -urNad gnomebaker-0.6.0~/src/selectdevicedlg.c gnomebaker-0.6.0/src/selectdevicedlg.c
--- gnomebaker-0.6.0~/src/selectdevicedlg.c	2006-05-29 13:20:49.000000000 -0300
+++ gnomebaker-0.6.0/src/selectdevicedlg.c	2006-11-24 22:39:56.000000000 -0200
@@ -27,7 +27,7 @@
 
 
 /* Select device dialog widget names */
-static const gchar *const widget_select_writer = "optmenWriter";
+static const gchar *const widget_select_writer = "cmbWriter";
 static const gchar *const widget_select_device_dlg = "selectDeviceDlg";
 
 static GladeXML *selectdevicedlgdlg_xml = NULL;
@@ -40,8 +40,8 @@
 	selectdevicedlgdlg_xml = glade_xml_new(glade_file, widget_select_device_dlg, NULL);
 	glade_xml_signal_autoconnect(selectdevicedlgdlg_xml);
 
-	GtkWidget *option_menu = glade_xml_get_widget(selectdevicedlgdlg_xml, widget_select_writer);
-	devices_populate_optionmenu(option_menu, GB_WRITER, TRUE);
+    GtkComboBox *combo_box = GTK_COMBO_BOX(glade_xml_get_widget(selectdevicedlgdlg_xml, widget_select_writer));
+	devices_populate_combo_box(combo_box, GB_WRITER, TRUE);
 
     GtkWidget *dlg = glade_xml_get_widget(selectdevicedlgdlg_xml, widget_select_device_dlg);
     gbcommon_center_window_on_parent(dlg);
@@ -65,6 +65,6 @@
 	GB_LOG_FUNC
 	g_return_if_fail(selectdevicedlgdlg_xml != NULL);
 
-	GtkWidget *option_menu = glade_xml_get_widget(selectdevicedlgdlg_xml, widget_select_writer);
-	devices_save_optionmenu(GTK_OPTION_MENU(option_menu), GB_WRITER);
+    GtkComboBox *combo_box = GTK_COMBO_BOX(glade_xml_get_widget(selectdevicedlgdlg_xml, widget_select_writer));
+	devices_save_combo_box(combo_box, GB_WRITER);
 }
diff -urNad gnomebaker-0.6.0~/src/startdlg.c gnomebaker-0.6.0/src/startdlg.c
--- gnomebaker-0.6.0~/src/startdlg.c	2006-08-30 20:41:15.000000000 -0300
+++ gnomebaker-0.6.0/src/startdlg.c	2006-11-24 22:39:56.000000000 -0200
@@ -69,8 +69,8 @@
     g_return_if_fail(user_data != NULL);
 
     StartDlg *start_dlg = (StartDlg*)user_data;
-    devices_save_optionmenu(start_dlg->reader, GB_READER);
-    devices_save_optionmenu(start_dlg->writer, GB_WRITER);
+    devices_save_combo_box(start_dlg->reader, GB_READER);
+    devices_save_combo_box(start_dlg->writer, GB_WRITER);
     const gint index = gtk_option_menu_get_history(start_dlg->write_speed);
     if(index == 0)
         preferences_set_int(start_dlg->dvdmode ? GB_DVDWRITE_SPEED : GB_CDWRITE_SPEED, 0);
@@ -544,6 +544,7 @@
 	GB_LOG_FUNC
 
     StartDlg *start_dlg = g_new0(StartDlg, 1);
+    
     start_dlg->dialog = GTK_DIALOG(gtk_dialog_new ());
     gtk_window_set_default_size(GTK_WINDOW(start_dlg->dialog), 320, -1);
     gtk_window_set_title(GTK_WINDOW(start_dlg->dialog), _(BurnTypeText[burn_type]));
@@ -552,10 +553,10 @@
     gtk_window_set_skip_taskbar_hint (GTK_WINDOW (start_dlg->dialog), TRUE);
     gtk_dialog_set_has_separator (start_dlg->dialog, FALSE);
 
-    start_dlg->writer = GTK_OPTION_MENU(gtk_option_menu_new ());
-    devices_populate_optionmenu(GTK_WIDGET(start_dlg->writer), GB_WRITER, TRUE);
-    start_dlg->reader = GTK_OPTION_MENU(gtk_option_menu_new ());
-    devices_populate_optionmenu(GTK_WIDGET(start_dlg->reader), GB_READER, FALSE);
+    start_dlg->writer = GTK_COMBO_BOX(gtk_combo_box_new());
+    devices_populate_combo_box(start_dlg->writer, GB_WRITER, TRUE);
+    start_dlg->reader = GTK_COMBO_BOX(gtk_combo_box_new ());
+    devices_populate_combo_box(start_dlg->reader, GB_READER, FALSE);
     start_dlg->write_speed = GTK_OPTION_MENU(gtk_option_menu_new ());
     start_dlg->write_mode = GTK_OPTION_MENU(gtk_option_menu_new ());
     start_dlg->dummy = startdlg_create_check_button(_("Dummy write"), GB_DUMMY);
diff -urNad gnomebaker-0.6.0~/src/startdlg.h gnomebaker-0.6.0/src/startdlg.h
--- gnomebaker-0.6.0~/src/startdlg.h	2006-05-29 19:00:41.000000000 -0300
+++ gnomebaker-0.6.0/src/startdlg.h	2006-11-24 22:39:56.000000000 -0200
@@ -32,8 +32,8 @@
 typedef struct
 {
     GtkDialog *dialog;
-    GtkOptionMenu *reader;
-    GtkOptionMenu *writer;
+    GtkComboBox *reader;
+    GtkComboBox *writer;
     GtkOptionMenu *write_speed;
     GtkOptionMenu *write_mode;
     GtkCheckButton *dummy;
