[Xfce4-commits] r24288 - xfburn/branches/libburn_trial/xfburn
Jean-François Wauthy
pollux at xfce.org
Sun Jan 7 17:27:53 CET 2007
Author: pollux
Date: 2007-01-07 16:27:52 +0000 (Sun, 07 Jan 2007)
New Revision: 24288
Modified:
xfburn/branches/libburn_trial/xfburn/xfburn-device-box.c
xfburn/branches/libburn_trial/xfburn/xfburn-device-list.c
xfburn/branches/libburn_trial/xfburn/xfburn-device-list.h
Log:
speed selection (still not accurate and a bit buggy)
Modified: xfburn/branches/libburn_trial/xfburn/xfburn-device-box.c
===================================================================
--- xfburn/branches/libburn_trial/xfburn/xfburn-device-box.c 2007-01-07 15:29:12 UTC (rev 24287)
+++ xfburn/branches/libburn_trial/xfburn/xfburn-device-box.c 2007-01-07 16:27:52 UTC (rev 24288)
@@ -81,6 +81,7 @@
static void xfburn_device_box_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
static void xfburn_device_box_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
+static void cb_speed_refresh_clicked (GtkButton *button, XfburnDeviceBox *box);
static void cb_combo_device_changed (GtkComboBox *combo, XfburnDeviceBox *box);
/* globals */
@@ -151,7 +152,7 @@
{
XfburnDeviceBoxPrivate *priv = XFBURN_DEVICE_BOX_GET_PRIVATE (box);
- GtkWidget *label;
+ GtkWidget *label, *img, *button;
GList *device = NULL;
GtkListStore *store = NULL;
GtkCellRenderer *cell;
@@ -198,6 +199,15 @@
gtk_widget_show (priv->combo_speed);
gtk_box_pack_start (GTK_BOX (priv->hbox_speed_selection), priv->combo_speed, TRUE, TRUE, BORDER);
+ img = gtk_image_new_from_stock (GTK_STOCK_REFRESH, GTK_ICON_SIZE_SMALL_TOOLBAR);
+ gtk_widget_show (img);
+ button = gtk_button_new ();
+ gtk_container_add (GTK_CONTAINER (button), img);
+ gtk_widget_show (button);
+ gtk_box_pack_start (GTK_BOX (priv->hbox_speed_selection), button, FALSE, FALSE, 0);
+
+ g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (cb_speed_refresh_clicked), box);
+
/* mode */
priv->hbox_mode_selection = gtk_hbox_new (FALSE, 0);
gtk_widget_show (priv->hbox_mode_selection);
@@ -279,19 +289,22 @@
{
XfburnDeviceBoxPrivate *priv = XFBURN_DEVICE_BOX_GET_PRIVATE (box);
GtkTreeModel *model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->combo_speed));
- gint i;
+ GSList *el = device->supported_cdr_speeds;
gtk_list_store_clear (GTK_LIST_STORE (model));
- for (i = device->min_cdr_speed; i <= device->max_cdr_speed; i += 2) {
+ while (el) {
+ gint speed = GPOINTER_TO_INT (el->data);
GtkTreeIter iter;
gchar *str = NULL;
- str = g_strdup_printf ("%d", i);
+ str = g_strdup_printf ("%d", speed);
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
- gtk_list_store_set (GTK_LIST_STORE (model), &iter, SPEED_TEXT_COLUMN, str, SPEED_VALUE_COLUMN, i, -1);
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, SPEED_TEXT_COLUMN, str, SPEED_VALUE_COLUMN, speed, -1);
g_free (str);
+
+ el = g_slist_next (el);
}
gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combo_speed), gtk_tree_model_iter_n_children (model, NULL) - 1);
}
@@ -334,6 +347,17 @@
}
static void
+cb_speed_refresh_clicked (GtkButton *button, XfburnDeviceBox *box)
+{
+ XfburnDevice *device = NULL;
+
+ device = xfburn_device_box_get_selected_device (box);
+ xfburn_device_refresh_supported_speeds (device);
+
+ fill_combo_speed (box, device);
+}
+
+static void
cb_combo_device_changed (GtkComboBox *combo, XfburnDeviceBox *box)
{
XfburnDevice *device;
Modified: xfburn/branches/libburn_trial/xfburn/xfburn-device-list.c
===================================================================
--- xfburn/branches/libburn_trial/xfburn/xfburn-device-list.c 2007-01-07 15:29:12 UTC (rev 24287)
+++ xfburn/branches/libburn_trial/xfburn/xfburn-device-list.c 2007-01-07 16:27:52 UTC (rev 24288)
@@ -38,7 +38,7 @@
#define CDR_1X_SPEED 150
/* private */
-static gint supported_cdr_speeds[] = {2, 4, 6, 8, 10, 12, 16, 24, 32, 40, 48, 52, -1};
+static gint supported_cdr_speeds[] = {2, 4, 6, 8, 10, 12, 16, 20, 24, 32, 40, 48, 52, -1};
static GList *devices = NULL;
/*************/
@@ -49,23 +49,45 @@
{
g_free (device->name);
g_free (device->node_path);
+
+ g_slist_free (device->supported_cdr_speeds);
}
static gint
get_closest_supported_cdr_speed (gint speed)
{
+ /* TODO: need some fixing */
gint i = 0;
+ gint previous = 0;
while (supported_cdr_speeds[i] != -1) {
- if (speed < (supported_cdr_speeds[i] * CDR_1X_SPEED))
- return supported_cdr_speeds[i];
- else
- i++;
+ if (speed < (supported_cdr_speeds[i] * CDR_1X_SPEED)) {
+ return supported_cdr_speeds[previous];
+ } else
+ previous = i;
+ i++;
}
return 0;
}
+static gboolean
+no_speed_duplicate (GSList *speed_list, gint speed)
+{
+ GSList *el = speed_list;
+
+ while (el) {
+ gint el_speed = GPOINTER_TO_INT (el->data);
+
+ if (el_speed == speed)
+ return FALSE;
+
+ el = g_slist_next (el);
+ }
+
+ return TRUE;
+}
+
/**************/
/* public API */
/**************/
@@ -76,6 +98,50 @@
}
void
+xfburn_device_refresh_supported_speeds (XfburnDevice * device)
+{
+ struct burn_drive_info *drive_info = NULL;
+ struct burn_speed_descriptor *speed_list = NULL;
+ gint ret;
+
+ if (!xfburn_device_grab (device, &drive_info)) {
+ g_error ("Couldn't grab drive in order to update speed list.");
+ return;
+ }
+
+ /* empty previous list */
+ g_slist_free (device->supported_cdr_speeds);
+ device->supported_cdr_speeds = NULL;
+
+ /* fill new list */
+ ret = burn_drive_get_speedlist (drive_info->drive, &speed_list);
+
+ if (ret > 0) {
+ struct burn_speed_descriptor *el = speed_list;
+
+ while (el) {
+ gint speed = -1;
+
+ speed = get_closest_supported_cdr_speed (el->write_speed);
+ if (speed > 0 && no_speed_duplicate (device->supported_cdr_speeds, speed)) {
+ device->supported_cdr_speeds = g_slist_prepend (device->supported_cdr_speeds, GINT_TO_POINTER (speed));
+ DBG ("added speed: %d\n", speed);
+ }
+
+ el = el->next;
+ }
+
+ burn_drive_free_speedlist (&speed_list);
+ } else if (ret == 0) {
+ g_warning ("reported speed list is empty");
+ } else {
+ g_error ("severe error while retrieving speed list");
+ }
+
+ burn_drive_release (drive_info->drive, 0);
+}
+
+void
xfburn_device_list_init ()
{
struct burn_drive_info *drives;
@@ -100,10 +166,6 @@
device->cdr = drives[i].write_cdr;
device->cdrw = drives[i].write_cdrw;
- DBG ("max speed reported by libburn: %d", burn_drive_get_write_speed (drives[i].drive));
- DBG ("min speed reported by libburn: %d", burn_drive_get_min_write_speed (drives[i].drive));
- device->min_cdr_speed = 2;
- device->max_cdr_speed = 48;
device->buffer_size = drives[i].buffer_size;
device->dummy_write = drives[i].write_simulate;
@@ -121,34 +183,9 @@
if (ret <= 0)
g_error ("Unable to get drive %s address (ret=%d). Please report this problem to libburn-hackers at pykix.org", device->name, ret);
-
- /* speed list */
- struct burn_speed_descriptor *speed_list = NULL;
-
- ret = burn_drive_get_speedlist (drives[i].drive, &speed_list);
-
- if (ret > 0) {
- struct burn_speed_descriptor *el = speed_list;
-
- while (el) {
- DBG ("====================");
- DBG ("source = %d", el->source);
- DBG ("write speed = %d", el->write_speed);
- DBG ("read speed = %d", el->read_speed);
- DBG ("wrc = %d", el->wrc);
- DBG ("exact = %d", el->exact);
- DBG ("mrw = %d", el->mrw);
- DBG ("====================");
-
- el = el->next;
- }
- } else if (ret == 0) {
- DBG ("speed list is empty");
- } else {
- DBG ("severe error while retrieving speed list");
- }
- burn_drive_free_speedlist (&speed_list);
+ xfburn_device_refresh_supported_speeds (device);
+
devices = g_list_append (devices, device);
ret = burn_drive_info_forget (&(drives[i]), 1);
Modified: xfburn/branches/libburn_trial/xfburn/xfburn-device-list.h
===================================================================
--- xfburn/branches/libburn_trial/xfburn/xfburn-device-list.h 2007-01-07 15:29:12 UTC (rev 24287)
+++ xfburn/branches/libburn_trial/xfburn/xfburn-device-list.h 2007-01-07 16:27:52 UTC (rev 24288)
@@ -35,8 +35,7 @@
gboolean cdr;
gboolean cdrw;
- gint min_cdr_speed;
- gint max_cdr_speed;
+ GSList *supported_cdr_speeds;
gint tao_block_types;
gint sao_block_types;
@@ -54,6 +53,7 @@
GList * xfburn_device_list_get_list ();
void xfburn_device_list_free ();
+void xfburn_device_refresh_supported_speeds (XfburnDevice * device);
gboolean xfburn_device_grab (XfburnDevice * device, struct burn_drive_info **drive_info);
void xfburn_device_free (XfburnDevice * device);
More information about the Xfce4-commits
mailing list