[Xfce4-commits] r24072 - xfburn/branches/libburn_trial/xfburn
Jean-François Wauthy
pollux at xfce.org
Sun Dec 10 12:22:29 CET 2006
Author: pollux
Date: 2006-12-10 11:22:28 +0000 (Sun, 10 Dec 2006)
New Revision: 24072
Modified:
xfburn/branches/libburn_trial/xfburn/xfburn-blank-cd-dialog.c
xfburn/branches/libburn_trial/xfburn/xfburn-main.c
Log:
move the libburn code into a thread so the GUI can show what's going on
Modified: xfburn/branches/libburn_trial/xfburn/xfburn-blank-cd-dialog.c
===================================================================
--- xfburn/branches/libburn_trial/xfburn/xfburn-blank-cd-dialog.c 2006-12-09 11:38:32 UTC (rev 24071)
+++ xfburn/branches/libburn_trial/xfburn/xfburn-blank-cd-dialog.c 2006-12-10 11:22:28 UTC (rev 24072)
@@ -146,7 +146,114 @@
g_signal_connect (G_OBJECT (obj), "response", G_CALLBACK (xfburn_blank_cd_dialog_response_cb), obj);
}
+typedef struct {
+ GtkWidget *dialog_progress;
+ XfburnDevice *device;
+ gint blank_type;
+ gboolean eject;
+} ThreadBlankParams;
+
static void
+thread_blank (ThreadBlankParams * params)
+{
+ GtkWidget *dialog_progress = params->dialog_progress;
+
+ struct burn_drive *drive;
+ enum burn_disc_status disc_state;
+ struct burn_progress progress;
+
+ drive = params->device->drive_info->drive;
+
+ if (!burn_drive_grab (drive, 1)) {
+ gdk_threads_enter ();
+ xfburn_progress_dialog_set_status (XFBURN_PROGRESS_DIALOG (dialog_progress), XFBURN_PROGRESS_DIALOG_STATUS_FAILED);
+ xfce_err (_("Unable to grab drive"));
+ gdk_threads_leave ();
+ goto cleanup;
+ }
+
+ while (burn_drive_get_status (drive, NULL) != BURN_DRIVE_IDLE) {
+ usleep (1001);
+ }
+
+ while ( (disc_state = burn_disc_get_status (drive)) == BURN_DISC_UNREADY)
+ usleep (1001);
+
+ switch (disc_state) {
+ case BURN_DISC_BLANK:
+ gdk_threads_enter ();
+ xfburn_progress_dialog_set_status (XFBURN_PROGRESS_DIALOG (dialog_progress), XFBURN_PROGRESS_DIALOG_STATUS_FAILED);
+ burn_drive_release (drive, 0);
+ xfce_err (_("The inserted disc is already blank"));
+ gdk_threads_leave ();
+ goto cleanup;
+ case BURN_DISC_FULL:
+ case BURN_DISC_APPENDABLE:
+ /* these ones we can blank */
+ gdk_threads_enter ();
+ xfburn_progress_dialog_set_action_text (XFBURN_PROGRESS_DIALOG (dialog_progress), _("Ready"));
+ gdk_threads_leave ();
+ break;
+ case BURN_DISC_EMPTY:
+ gdk_threads_enter ();
+ xfburn_progress_dialog_set_status (XFBURN_PROGRESS_DIALOG (dialog_progress), XFBURN_PROGRESS_DIALOG_STATUS_FAILED);
+ burn_drive_release (drive, 1);
+ xfce_err (_("No disc detected in the drive"));
+ gdk_threads_leave ();
+ goto cleanup;
+ default:
+ gdk_threads_enter ();
+ xfburn_progress_dialog_set_status (XFBURN_PROGRESS_DIALOG (dialog_progress), XFBURN_PROGRESS_DIALOG_STATUS_FAILED);
+ burn_drive_release (drive, 0);
+ xfce_err (_("Cannot recognize drive and media state"));
+ gdk_threads_leave ();
+ goto cleanup;
+ }
+
+ if (!burn_disc_erasable (drive)) {
+ gdk_threads_enter ();
+ xfburn_progress_dialog_set_status (XFBURN_PROGRESS_DIALOG (dialog_progress), XFBURN_PROGRESS_DIALOG_STATUS_FAILED);
+ burn_drive_release (drive, 1);
+ xfce_err (_("Media is not erasable"));
+ gdk_threads_leave ();
+ goto cleanup;
+ }
+
+ burn_disc_erase(drive, params->blank_type);
+ sleep(1);
+
+ gdk_threads_enter ();
+ xfburn_progress_dialog_set_action_text (XFBURN_PROGRESS_DIALOG (dialog_progress), _("Blanking disc"));
+ xfburn_progress_dialog_set_status (XFBURN_PROGRESS_DIALOG (dialog_progress), XFBURN_PROGRESS_DIALOG_STATUS_RUNNING);
+ gdk_threads_leave ();
+
+ while (burn_drive_get_status(drive, &progress) != BURN_DRIVE_IDLE) {
+ if(progress.sectors>0 && progress.sector>=0) {
+ gdouble percent = 1.0 + ((gdouble) progress.sector+1.0) / ((gdouble) progress.sectors) * 98.0;
+
+ gdk_threads_enter ();
+ xfburn_progress_dialog_set_progress_bar_fraction (XFBURN_PROGRESS_DIALOG (dialog_progress), percent / 100.0);
+ gdk_threads_leave ();
+ }
+ usleep(500000);
+ }
+
+ gdk_threads_enter ();
+ xfburn_progress_dialog_set_action_text (XFBURN_PROGRESS_DIALOG (dialog_progress), _("Done"));
+ xfburn_progress_dialog_set_status (XFBURN_PROGRESS_DIALOG (dialog_progress), XFBURN_PROGRESS_DIALOG_STATUS_COMPLETED);
+ gdk_threads_leave ();
+
+ burn_drive_release (drive, params->eject ? 1 : 0);
+
+ cleanup:
+ gdk_threads_enter ();
+ gtk_widget_destroy (dialog_progress);
+ gdk_threads_leave ();
+
+ g_free (params);
+}
+
+static void
xfburn_blank_cd_dialog_response_cb (XfburnBlankCdDialog * dialog, gint response_id, gpointer user_data)
{
if (response_id == GTK_RESPONSE_OK) {
@@ -154,14 +261,10 @@
XfburnDevice *device;
gint blank_type;
- struct burn_drive *drive;
- enum burn_disc_status disc_state;
- struct burn_progress progress;
-
GtkWidget *dialog_progress;
+ ThreadBlankParams *params = NULL;
device = xfburn_device_box_get_selected_device (XFBURN_DEVICE_BOX (priv->device_box));
- drive = device->drive_info->drive;
switch (gtk_combo_box_get_active (GTK_COMBO_BOX (priv->combo_type))) {
case 0:
@@ -183,70 +286,15 @@
xfburn_progress_dialog_set_action_text (XFBURN_PROGRESS_DIALOG (dialog_progress), _("Initializing"));
gtk_widget_show (dialog_progress);
- if (!burn_drive_grab (drive, 1)) {
- xfburn_progress_dialog_set_status (XFBURN_PROGRESS_DIALOG (dialog_progress), XFBURN_PROGRESS_DIALOG_STATUS_FAILED);
- xfce_err (_("Unable to grab drive"));
- gtk_widget_destroy (dialog_progress);
- return;
- }
-
- while (burn_drive_get_status (drive, NULL) != BURN_DRIVE_IDLE)
- usleep (1001);
-
- while ( (disc_state = burn_disc_get_status (drive)) == BURN_DISC_UNREADY)
- usleep (1001);
-
- switch (disc_state) {
- case BURN_DISC_BLANK:
- xfburn_progress_dialog_set_status (XFBURN_PROGRESS_DIALOG (dialog_progress), XFBURN_PROGRESS_DIALOG_STATUS_FAILED);
- burn_drive_release (drive, 0);
- xfce_err (_("The inserted disc is already blank"));
- gtk_widget_destroy (dialog_progress);
- return;
- case BURN_DISC_FULL:
- case BURN_DISC_APPENDABLE:
- /* these ones we can blank */
- xfburn_progress_dialog_set_action_text (XFBURN_PROGRESS_DIALOG (dialog_progress), _("Ready"));
- break;
- case BURN_DISC_EMPTY:
- xfburn_progress_dialog_set_status (XFBURN_PROGRESS_DIALOG (dialog_progress), XFBURN_PROGRESS_DIALOG_STATUS_FAILED);
- burn_drive_release (drive, 1);
- xfce_err (_("No disc detected in the drive"));
- gtk_widget_destroy (dialog_progress);
- return;
- default:
- xfburn_progress_dialog_set_status (XFBURN_PROGRESS_DIALOG (dialog_progress), XFBURN_PROGRESS_DIALOG_STATUS_FAILED);
- burn_drive_release (drive, 0);
- xfce_err (_("Cannot recognize drive and media state"));
- gtk_widget_destroy (dialog_progress);
- return;
- }
-
- if (!burn_disc_erasable (drive)) {
- xfburn_progress_dialog_set_status (XFBURN_PROGRESS_DIALOG (dialog_progress), XFBURN_PROGRESS_DIALOG_STATUS_FAILED);
- burn_drive_release (drive, 1);
- xfce_err (_("Media is not erasable"));
- gtk_widget_destroy (dialog_progress);
- return;
- }
-
- burn_disc_erase(drive, blank_type);
- sleep(1);
- xfburn_progress_dialog_set_action_text (XFBURN_PROGRESS_DIALOG (dialog_progress), _("Blanking disc"));
- xfburn_progress_dialog_set_status (XFBURN_PROGRESS_DIALOG (dialog_progress), XFBURN_PROGRESS_DIALOG_STATUS_RUNNING);
- while (burn_drive_get_status(drive, &progress) != BURN_DRIVE_IDLE) {
- if(progress.sectors>0 && progress.sector>=0) {
- gdouble percent = 1.0 + ((gdouble) progress.sector+1.0) / ((gdouble) progress.sectors) * 98.0;
-
- xfburn_progress_dialog_set_progress_bar_fraction (XFBURN_PROGRESS_DIALOG (dialog_progress), percent / 100.0);
- }
- usleep(500000);
- }
- xfburn_progress_dialog_set_action_text (XFBURN_PROGRESS_DIALOG (dialog_progress), _("Done"));
- xfburn_progress_dialog_set_status (XFBURN_PROGRESS_DIALOG (dialog_progress), XFBURN_PROGRESS_DIALOG_STATUS_COMPLETED);
- burn_drive_release (drive, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->check_eject)) ? 1 : 0);
+ params = g_new0 (ThreadBlankParams, 1);
+ params->dialog_progress = dialog_progress;
+ params->device = device;
+ params->blank_type = blank_type;
+ params->eject = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->check_eject));
+ g_thread_create ((GThreadFunc) thread_blank, params, FALSE, NULL);
}
}
+
/* public */
GtkWidget *
Modified: xfburn/branches/libburn_trial/xfburn/xfburn-main.c
===================================================================
--- xfburn/branches/libburn_trial/xfburn/xfburn-main.c 2006-12-09 11:38:32 UTC (rev 24071)
+++ xfburn/branches/libburn_trial/xfburn/xfburn-main.c 2006-12-10 11:22:28 UTC (rev 24072)
@@ -65,6 +65,10 @@
exit (EXIT_SUCCESS);
}
+ g_thread_init (NULL);
+ gdk_threads_init ();
+ gdk_threads_enter ();
+
if (!burn_initialize ()) {
g_critical ("Unable to initiliaze libburn");
return EXIT_FAILURE;
@@ -101,5 +105,8 @@
xfburn_device_list_free ();
burn_finish ();
+
+ gdk_threads_leave ();
+
return EXIT_SUCCESS;
}
More information about the Xfce4-commits
mailing list