~mfisch/brasero/update-to-3.8.0

« back to all changes in this revision

Viewing changes to src/plugins/cdrtools/burn-cdrecord.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Ancell
  • Date: 2009-06-03 10:36:30 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20090603103630-2r72408gk45sc0ws
Tags: 2.27.2-0ubuntu1
* New upstream release (LP: #380850)
  - Split burning backend into a new library called libbrasero-burn
  - Split some utilities into a new library called libbrasero-utils
  - Use Brasero as a single instance application using libunique
  - Data spanning
  - Memleak fixes
  - Bug Fixes
  - String fixes
  - Use autogenerated Changelog via git
  - Translation Updates
  - Fixes (LP: #360671)
* Bump GTK+ requirement and add libunique requirement

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *            cdrecord.c
3
 
 *
4
 
 *  dim jan 22 15:22:52 2006
5
 
 *  Copyright  2006  Rouquier Philippe
6
 
 *  brasero-app@wanadoo.fr
7
 
 ***************************************************************************/
8
 
 
9
 
/*
10
 
 *  Brasero is free software; you can redistribute it and/or modify
11
 
 *  it under the terms of the GNU General Public License as published by
12
 
 *  the Free Software Foundation; either version 2 of the License, or
13
 
 *  (at your option) any later version.
14
 
 *
15
 
 *  Brasero is distributed in the hope that it will be useful,
16
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
 *  GNU Library General Public License for more details.
19
 
 *
20
 
 *  You should have received a copy of the GNU General Public License
21
 
 *  along with this program; if not, write to:
22
 
 *      The Free Software Foundation, Inc.,
23
 
 *      51 Franklin Street, Fifth Floor
24
 
 *      Boston, MA  02110-1301, USA.
25
 
 */
26
 
 
27
 
#ifdef HAVE_CONFIG_H
28
 
#  include <config.h>
29
 
#endif
30
 
 
31
 
#include <string.h>
32
 
#include <math.h>
33
 
#include <sys/types.h>
34
 
#include <sys/stat.h>
35
 
#include <fcntl.h>
36
 
#include <unistd.h>
37
 
#include <errno.h>
38
 
#include <stdlib.h>
39
 
 
40
 
#include <glib.h>
41
 
#include <glib-object.h>
42
 
#include <glib/gi18n-lib.h>
43
 
#include <glib/gstdio.h>
44
 
#include <gmodule.h>
45
 
 
46
 
#include <gconf/gconf-client.h>
47
 
 
48
 
#include "burn-basics.h"
49
 
#include "burn-job.h"
50
 
#include "burn-process.h"
51
 
#include "burn-plugin.h"
52
 
#include "burn-cdrtools.h"
53
 
#include "burn-cdrecord.h"
54
 
 
55
 
BRASERO_PLUGIN_BOILERPLATE (BraseroCDRecord, brasero_cdrecord, BRASERO_TYPE_PROCESS, BraseroProcess);
56
 
 
57
 
struct _BraseroCDRecordPrivate {
58
 
        gint64 current_track_end_pos;
59
 
        gint64 current_track_written;
60
 
 
61
 
        gint current_track_num;
62
 
        gint track_count;
63
 
 
64
 
        gint minbuf;
65
 
 
66
 
        GSList *infs;
67
 
 
68
 
        guint immediate:1;
69
 
};
70
 
typedef struct _BraseroCDRecordPrivate BraseroCDRecordPrivate;
71
 
#define BRASERO_CD_RECORD_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_CD_RECORD, BraseroCDRecordPrivate))
72
 
 
73
 
static GObjectClass *parent_class = NULL;
74
 
 
75
 
#define GCONF_KEY_IMMEDIATE_FLAG        "/apps/brasero/config/immed_flag"
76
 
#define GCONF_KEY_MINBUF_VALUE          "/apps/brasero/config/minbuf_value"
77
 
 
78
 
static BraseroBurnResult
79
 
brasero_cdrecord_stderr_read (BraseroProcess *process, const gchar *line)
80
 
{
81
 
        BraseroBurnFlag flags;
82
 
 
83
 
        brasero_job_get_flags (BRASERO_JOB (process), &flags);
84
 
 
85
 
        if (strstr (line, "Cannot open SCSI driver.")
86
 
        ||  strstr (line, "Operation not permitted. Cannot send SCSI cmd via ioctl")
87
 
        ||  strstr (line, "Cannot open or use SCSI driver")) {
88
 
                brasero_job_error (BRASERO_JOB (process),
89
 
                                   g_error_new (BRASERO_BURN_ERROR,
90
 
                                                BRASERO_BURN_ERROR_PERMISSION,
91
 
                                                _("You do not have the required permissions to use this drive")));
92
 
        }
93
 
        else if (!(flags & BRASERO_BURN_FLAG_OVERBURN)
94
 
             &&  strstr (line, "Data may not fit on current disk")) {
95
 
                /* we don't error out if overburn was chosen */
96
 
                brasero_job_error (BRASERO_JOB (process),
97
 
                                   g_error_new (BRASERO_BURN_ERROR,
98
 
                                                BRASERO_BURN_ERROR_MEDIUM_SPACE,
99
 
                                                _("Not enough space available on the disc")));
100
 
        }
101
 
        else if (strstr (line ,"cdrecord: A write error occured")
102
 
             ||  strstr (line, "Could not write Lead-in")
103
 
             ||  strstr (line, "Cannot fixate disk")) {
104
 
                brasero_job_error (BRASERO_JOB (process),
105
 
                                   g_error_new (BRASERO_BURN_ERROR,
106
 
                                                BRASERO_BURN_ERROR_WRITE_MEDIUM,
107
 
                                                _("An error occured while writing to disc")));
108
 
        }
109
 
        else if (strstr (line, "DMA speed too slow") != NULL) {
110
 
                brasero_job_error (BRASERO_JOB (process),
111
 
                                   g_error_new (BRASERO_BURN_ERROR,
112
 
                                                BRASERO_BURN_ERROR_SLOW_DMA,
113
 
                                                _("The system is too slow to write the disc at this speed. Try a lower speed")));
114
 
        }
115
 
        else if (strstr (line, "Device or resource busy")) {
116
 
                if (!strstr (line, "retrying in")) {
117
 
                        brasero_job_error (BRASERO_JOB (process),
118
 
                                           g_error_new (BRASERO_BURN_ERROR,
119
 
                                                        BRASERO_BURN_ERROR_DRIVE_BUSY,
120
 
                                                        _("The drive is busy")));
121
 
                }
122
 
        }
123
 
        else if (strstr (line, "Illegal write mode for this drive")) {
124
 
                /* NOTE : when it happened I had to unlock the
125
 
                 * drive with cdrdao and eject it. Should we ? */
126
 
                brasero_job_error (BRASERO_JOB (process),
127
 
                                   g_error_new (BRASERO_BURN_ERROR,
128
 
                                                BRASERO_BURN_ERROR_DRIVE_BUSY,
129
 
                                                _("The drive is busy")));
130
 
        }
131
 
 
132
 
        /* REMINDER: these should not be necessary as we checked that already */
133
 
        /**
134
 
        else if (strstr (line, "cannot write medium - incompatible format") != NULL) {
135
 
                brasero_job_error (BRASERO_JOB (process),
136
 
                                   g_error_new (BRASERO_BURN_ERROR,
137
 
                                                BRASERO_BURN_ERROR_INPUT_INVALID,
138
 
                                                _("The image does not seem to be a proper iso9660 file system")));
139
 
        }
140
 
        else if (strstr (line, "This means that we are checking recorded media.") != NULL) {
141
 
        **/     /* NOTE: defer the consequence of this error as it is not always
142
 
                 * fatal. So send a warning but don't stop the process. */
143
 
        /**     brasero_process_deferred_error (process,
144
 
                                                g_error_new (BRASERO_BURN_ERROR,
145
 
                                                             BRASERO_BURN_ERROR_MEDIUM_INVALID,
146
 
                                                             _("The disc is already burnt")));
147
 
        }
148
 
        else if (strstr (line, "Cannot blank disk, aborting.") != NULL) {
149
 
                brasero_job_error (BRASERO_JOB (process),
150
 
                                   g_error_new (BRASERO_BURN_ERROR,
151
 
                                                BRASERO_BURN_ERROR_MEDIUM_INVALID,
152
 
                                                _("The disc could not be blanked")));
153
 
        }
154
 
        else if (strstr (line, "Bad audio track size")) {
155
 
                brasero_job_error (BRASERO_JOB (process),
156
 
                                   g_error_new (BRASERO_BURN_ERROR,
157
 
                                                BRASERO_BURN_ERROR_GENERAL,
158
 
                                                _("The audio tracks are too short or not a multiple of 2352")));
159
 
        }
160
 
        else if (strstr (line, "cdrecord: No such file or directory. Cannot open")
161
 
             ||  strstr (line, "No tracks specified. Need at least one.")) {
162
 
                brasero_job_error (BRASERO_JOB (process),
163
 
                                   g_error_new (BRASERO_BURN_ERROR,
164
 
                                                BRASERO_BURN_ERROR_INPUT,
165
 
                                                _("The image file cannot be found")));
166
 
        }
167
 
        else if (strstr (line, "Inappropriate audio coding")) {
168
 
                brasero_job_error (BRASERO_JOB (process),
169
 
                                   g_error_new (BRASERO_BURN_ERROR,
170
 
                                                BRASERO_BURN_ERROR_INPUT_INVALID,
171
 
                                                _("All audio files must be stereo, 16-bit digital audio with 44100Hz samples")));
172
 
        }
173
 
        else if (strstr (line, "No disk / Wrong disk!") != NULL) {
174
 
                brasero_job_error (BRASERO_JOB (process),
175
 
                                   g_error_new (BRASERO_BURN_ERROR,
176
 
                                                BRASERO_BURN_ERROR_MEDIA_NONE,
177
 
                                                _("There seems to be no disc in the drive")));
178
 
        }
179
 
 
180
 
        **/
181
 
 
182
 
        /** For these we'd rather have a message saying "cdrecord failed"
183
 
         *  as an internal error occured says nothing/even less
184
 
        else if (strstr (line, "Bad file descriptor. read error on input file")
185
 
             ||  strstr (line, "Input buffer error, aborting")) {
186
 
                brasero_job_error (BRASERO_JOB (process),
187
 
                                   g_error_new (BRASERO_BURN_ERROR,
188
 
                                                BRASERO_BURN_ERROR_GENERAL,
189
 
                                                _("An internal error occured")));
190
 
        }
191
 
 
192
 
        **/
193
 
 
194
 
        return BRASERO_BURN_OK;
195
 
}
196
 
 
197
 
static void
198
 
brasero_cdrecord_compute (BraseroCDRecord *cdrecord,
199
 
                          gint mb_written,
200
 
                          gint mb_total,
201
 
                          gint track_num)
202
 
{
203
 
        gboolean track_num_changed = FALSE;
204
 
        BraseroCDRecordPrivate *priv;
205
 
        gchar *action_string;
206
 
        gint64 this_remain;
207
 
        gint64 bytes;
208
 
        gint64 total;
209
 
 
210
 
        priv = BRASERO_CD_RECORD_PRIVATE (cdrecord);
211
 
        if (mb_total <= 0)
212
 
                return;
213
 
 
214
 
        total = mb_total * 1048576;
215
 
 
216
 
        if (track_num > priv->current_track_num) {
217
 
                track_num_changed = TRUE;
218
 
                priv->current_track_num = track_num;
219
 
                priv->current_track_end_pos += mb_total * 1048576;
220
 
        }
221
 
 
222
 
        this_remain = (mb_total - mb_written) * 1048576;
223
 
        bytes = (total - priv->current_track_end_pos) + this_remain;
224
 
        brasero_job_set_written_session (BRASERO_JOB (cdrecord), total - bytes);
225
 
 
226
 
        action_string = g_strdup_printf ("Writing track %02i", track_num);
227
 
        brasero_job_set_current_action (BRASERO_JOB (cdrecord),
228
 
                                        BRASERO_BURN_ACTION_RECORDING,
229
 
                                        action_string,
230
 
                                        track_num_changed);
231
 
        g_free (action_string);
232
 
}
233
 
 
234
 
static BraseroBurnResult
235
 
brasero_cdrecord_stdout_read (BraseroProcess *process, const gchar *line)
236
 
{
237
 
        guint track;
238
 
        guint speed_1, speed_2;
239
 
        BraseroCDRecord *cdrecord;
240
 
        BraseroCDRecordPrivate *priv;
241
 
        int mb_written = 0, mb_total = 0, fifo = 0, buf = 0;
242
 
 
243
 
        cdrecord = BRASERO_CD_RECORD (process);
244
 
        priv = BRASERO_CD_RECORD_PRIVATE (cdrecord);
245
 
 
246
 
        if (sscanf (line, "Track %2u: %d of %d MB written (fifo %d%%) [buf %d%%] %d.%dx.",
247
 
                    &track, &mb_written, &mb_total, &fifo, &buf, &speed_1, &speed_2) == 7) {
248
 
                gdouble current_rate;
249
 
 
250
 
                current_rate = (gdouble) ((gdouble) speed_1 +
251
 
                               (gdouble) speed_2 / 10.0) *
252
 
                               (gdouble) CD_RATE;
253
 
                brasero_job_set_rate (BRASERO_JOB (cdrecord), current_rate);
254
 
 
255
 
                priv->current_track_written = mb_written * 1048576;
256
 
                brasero_cdrecord_compute (cdrecord,
257
 
                                          mb_written,
258
 
                                          mb_total,
259
 
                                          track);
260
 
 
261
 
                brasero_job_start_progress (BRASERO_JOB (cdrecord), FALSE);
262
 
        } 
263
 
        else if (sscanf (line, "Track %2u:    %d MB written (fifo %d%%) [buf  %d%%]  %d.%dx.",
264
 
                         &track, &mb_written, &fifo, &buf, &speed_1, &speed_2) == 6) {
265
 
                gdouble current_rate;
266
 
 
267
 
                /* this line is printed when cdrecord writes on the fly */
268
 
                current_rate = (gdouble) ((gdouble) speed_1 +
269
 
                               (gdouble) speed_2 / 10.0) *
270
 
                               (gdouble) CD_RATE;
271
 
                brasero_job_set_rate (BRASERO_JOB (cdrecord), current_rate);
272
 
 
273
 
                priv->current_track_written = mb_written * 1048576;
274
 
                if (brasero_job_get_fd_in (BRASERO_JOB (cdrecord), NULL) == BRASERO_BURN_OK) {
275
 
                        gint64 bytes = 0;
276
 
 
277
 
                        /* we must ask the imager what is the total size */
278
 
                        brasero_job_get_session_output_size (BRASERO_JOB (cdrecord),
279
 
                                                             NULL,
280
 
                                                             &bytes);
281
 
                        mb_total = bytes / 1048576;
282
 
                        brasero_cdrecord_compute (cdrecord,
283
 
                                                  mb_written,
284
 
                                                  mb_total,
285
 
                                                  track);
286
 
                }
287
 
 
288
 
                brasero_job_start_progress (BRASERO_JOB (cdrecord), FALSE);
289
 
        }
290
 
        else if (sscanf (line, "Track %*d: %*s %d MB ", &mb_total) == 1) {
291
 
/*              if (mb_total > 0)
292
 
                        priv->tracks_total_bytes += mb_total * 1048576;
293
 
*/      }
294
 
        else if (strstr (line, "Formatting media")) {
295
 
                brasero_job_set_current_action (BRASERO_JOB (process),
296
 
                                                BRASERO_BURN_ACTION_BLANKING,
297
 
                                                _("Formatting disc"),
298
 
                                                FALSE);
299
 
        }
300
 
        else if (strstr (line, "Sending CUE sheet")) {
301
 
                BraseroTrackType type;
302
 
 
303
 
                /* See if we are in an audio case which would mean we're writing
304
 
                 * CD-TEXT */
305
 
                brasero_job_get_input_type (BRASERO_JOB (cdrecord), &type);
306
 
                brasero_job_set_current_action (BRASERO_JOB (process),
307
 
                                                BRASERO_BURN_ACTION_RECORDING_CD_TEXT,
308
 
                                                (type.type == BRASERO_TRACK_TYPE_AUDIO) ? NULL:_("Writing cue sheet"),
309
 
                                                FALSE);
310
 
        }
311
 
        else if (g_str_has_prefix (line, "Re-load disk and hit <CR>")
312
 
             ||  g_str_has_prefix (line, "send SIGUSR1 to continue")) {
313
 
                BraseroBurnAction action = BRASERO_BURN_ACTION_NONE;
314
 
 
315
 
                brasero_job_get_current_action (BRASERO_JOB (process), &action);
316
 
 
317
 
                /* NOTE: There seems to be a BUG somewhere when writing raw images
318
 
                 * with clone mode. After disc has been written and fixated cdrecord
319
 
                 * asks the media to be reloaded. So we simply ignore this message
320
 
                 * and returns that everything went well. Which is indeed the case */
321
 
                if (action == BRASERO_BURN_ACTION_FIXATING) {
322
 
                        brasero_job_finished_session (BRASERO_JOB (process));
323
 
                        return BRASERO_BURN_OK;
324
 
                }
325
 
 
326
 
                brasero_job_error (BRASERO_JOB (process),
327
 
                                   g_error_new (BRASERO_BURN_ERROR,
328
 
                                                BRASERO_BURN_ERROR_MEDIUM_NEED_RELOADING,
329
 
                                                _("The disc needs to be reloaded before being recorded")));
330
 
        }
331
 
        else if (g_str_has_prefix (line, "Fixating...")
332
 
             ||  g_str_has_prefix (line, "Writing Leadout...")) {
333
 
                brasero_job_set_current_action (BRASERO_JOB (process),
334
 
                                                BRASERO_BURN_ACTION_FIXATING,
335
 
                                                NULL,
336
 
                                                FALSE);
337
 
        }
338
 
        else if (g_str_has_prefix (line, "Last chance to quit, ")) {
339
 
                brasero_job_set_dangerous (BRASERO_JOB (process), TRUE);
340
 
        }
341
 
        else if (g_str_has_prefix (line, "Blanking PMA, TOC, pregap")
342
 
             ||  strstr (line, "Blanking entire disk")) {
343
 
 
344
 
        }
345
 
        /* This should not happen */
346
 
        /* else if (strstr (line, "Use tsize= option in SAO mode to specify track size")) */
347
 
 
348
 
        return BRASERO_BURN_OK;
349
 
}
350
 
 
351
 
static gboolean
352
 
brasero_cdrecord_write_inf (BraseroCDRecord *cdrecord,
353
 
                            GPtrArray *argv,
354
 
                            BraseroTrack *track,
355
 
                            const gchar *tmpdir,
356
 
                            const gchar *album,
357
 
                            gint index,
358
 
                            gint start,
359
 
                            gboolean last_track,
360
 
                            GError **error)
361
 
{
362
 
        gint fd;
363
 
        gint size;
364
 
        gchar *path;
365
 
        gint64 length;
366
 
        gchar *string;
367
 
        gint b_written;
368
 
        gint64 sectors;
369
 
        gchar buffer [128];
370
 
        BraseroSongInfo *info;
371
 
        BraseroCDRecordPrivate *priv;
372
 
        int errsv;
373
 
 
374
 
        priv = BRASERO_CD_RECORD_PRIVATE (cdrecord);
375
 
 
376
 
        /* NOTE: about the .inf files: they should have the exact same path
377
 
         * but the ending suffix file is replaced by inf:
378
 
         * example : /path/to/file.mp3 => /path/to/file.inf */
379
 
        if (brasero_job_get_fd_in (BRASERO_JOB (cdrecord), NULL) != BRASERO_BURN_OK) {
380
 
                gchar *dot, *separator;
381
 
 
382
 
                path = brasero_track_get_audio_source (track, FALSE);
383
 
 
384
 
                dot = strrchr (path, '.');
385
 
                separator = strrchr (path, G_DIR_SEPARATOR);
386
 
 
387
 
                if (dot && dot > separator)
388
 
                        path = g_strdup_printf ("%.*s.inf",
389
 
                                                dot - path,
390
 
                                                path);
391
 
                else
392
 
                        path = g_strdup_printf ("%s.inf",
393
 
                                                path);
394
 
 
395
 
                /* since this file was not returned by brasero_job_get_tmp_file
396
 
                 * it won't be erased when session is unrefed so we have to do 
397
 
                 * it ourselves */
398
 
                priv->infs = g_slist_prepend (priv->infs, g_strdup (path));
399
 
        }
400
 
        else {
401
 
                BraseroBurnResult result;
402
 
 
403
 
                /* in this case don't care about the name since stdin is used */
404
 
                result = brasero_job_get_tmp_file (BRASERO_JOB (cdrecord),
405
 
                                                   ".inf",
406
 
                                                   &path,
407
 
                                                   error);
408
 
                if (result != BRASERO_BURN_OK)
409
 
                        return result;
410
 
        }
411
 
 
412
 
        fd = open (path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
413
 
        if (fd < 0)
414
 
                goto error;
415
 
 
416
 
        BRASERO_JOB_LOG (cdrecord, "writing inf (%s)", path);
417
 
 
418
 
        /* The problem here is that when writing CD-TEXT from .inf files, wodim
419
 
         * uses only one charset (and don't let us specify which one) which is
420
 
         * ISO-8859-1. (NOTE: don't believe the doc claiming it requires ASCII
421
 
         * and see cdrecord/cdtext.c line 309).
422
 
         * So we have to convert our UTF-8 input into such a charset.
423
 
         * NOTE: according to docs ASCII should be used for text packs other
424
 
         * than disc/track title.
425
 
         * It might be good in the end to write and pack CD-TEXT pack data 
426
 
         * ourselves so we can set a different charset from English like 
427
 
         * Chinese for example. */
428
 
        info = brasero_track_get_audio_info (track);
429
 
 
430
 
        strcpy (buffer, "# created by brasero\n");
431
 
        size = strlen (buffer);
432
 
        b_written = write (fd, buffer, size);
433
 
        if (b_written != size)
434
 
                goto error;
435
 
 
436
 
        strcpy (buffer, "MCN=\t\n");
437
 
        size = strlen (buffer);
438
 
        b_written = write (fd, buffer, size);
439
 
        if (b_written != size)
440
 
                goto error;
441
 
 
442
 
        if (info->isrc > 0)
443
 
                string = g_strdup_printf ("ISRC=\t%i\n", info->isrc);
444
 
        else
445
 
                string = g_strdup ("ISRC=\t\n");
446
 
        size = strlen (string);
447
 
        b_written = write (fd, string, size);
448
 
        g_free (string);
449
 
        if (b_written != size)
450
 
                goto error;
451
 
 
452
 
        strcpy (buffer, "Albumperformer=\t\n");
453
 
        size = strlen (buffer);
454
 
        b_written = write (fd, buffer, size);
455
 
        if (b_written != size)
456
 
                goto error;
457
 
 
458
 
        if (album) {
459
 
                gchar *encoded;
460
 
 
461
 
                encoded = g_convert_with_fallback (album,
462
 
                                                   -1,
463
 
                                                   "ISO-8859-1",
464
 
                                                   "UTF-8",
465
 
                                                   "_", /* Fallback for non convertible characters */
466
 
                                                   NULL,
467
 
                                                   NULL,
468
 
                                                   NULL);
469
 
                string = g_strdup_printf ("Albumtitle=\t%s\n", encoded);
470
 
                g_free (encoded);
471
 
        }
472
 
        else
473
 
                string = strdup ("Albumtitle=\t\n");
474
 
        size = strlen (string);
475
 
        b_written = write (fd, string, size);
476
 
        g_free (string);
477
 
        if (b_written != size)
478
 
                goto error;
479
 
 
480
 
        if (info->artist) {
481
 
                gchar *encoded;
482
 
 
483
 
                encoded = g_convert_with_fallback (info->artist,
484
 
                                                   -1,
485
 
                                                   "ISO-8859-1",
486
 
                                                   "UTF-8",
487
 
                                                   "_", /* Fallback for non convertible characters */
488
 
                                                   NULL,
489
 
                                                   NULL,
490
 
                                                   NULL);
491
 
                string = g_strdup_printf ("Performer=\t%s\n", encoded);
492
 
                g_free (encoded);
493
 
        }
494
 
        else
495
 
                string = strdup ("Performer=\t\n");
496
 
        size = strlen (string);
497
 
        b_written = write (fd, string, size);
498
 
        g_free (string);
499
 
        if (b_written != size)
500
 
                goto error;
501
 
 
502
 
        if (info->composer) {
503
 
                gchar *encoded;
504
 
 
505
 
                encoded = g_convert_with_fallback (info->composer,
506
 
                                                   -1,
507
 
                                                   "ISO-8859-1",
508
 
                                                   "UTF-8",
509
 
                                                   "_", /* Fallback for non convertible characters */
510
 
                                                   NULL,
511
 
                                                   NULL,
512
 
                                                   NULL);
513
 
                string = g_strdup_printf ("Composer=\t%s\n", encoded);
514
 
                g_free (encoded);
515
 
        }
516
 
        else
517
 
                string = strdup ("Composer=\t\n");
518
 
        size = strlen (string);
519
 
        b_written = write (fd, string, size);
520
 
        g_free (string);
521
 
        if (b_written != size)
522
 
                goto error;
523
 
 
524
 
        if (info->title) {
525
 
                gchar *encoded;
526
 
 
527
 
                encoded = g_convert_with_fallback (info->title,
528
 
                                                   -1,
529
 
                                                   "ISO-8859-1",
530
 
                                                   "UTF-8",
531
 
                                                   "_", /* Fallback for non convertible characters */
532
 
                                                   NULL,
533
 
                                                   NULL,
534
 
                                                   NULL);
535
 
                string = g_strdup_printf ("Tracktitle=\t%s\n", encoded);
536
 
                g_free (encoded);
537
 
        }
538
 
        else
539
 
                string = strdup ("Tracktitle=\t\n");
540
 
        size = strlen (string);
541
 
        b_written = write (fd, string, size);
542
 
        g_free (string);
543
 
        if (b_written != size)
544
 
                goto error;
545
 
 
546
 
        string = g_strdup_printf ("Tracknumber=\t%i\n", index);
547
 
        size = strlen (string);
548
 
        b_written = write (fd, string, size);
549
 
        g_free (string);
550
 
        if (b_written != size)
551
 
                goto error;
552
 
 
553
 
        string = g_strdup_printf ("Trackstart=\t%i\n", start);
554
 
        size = strlen (string);
555
 
        b_written = write (fd, string, size);
556
 
        g_free (string);
557
 
        if (b_written != size)
558
 
                goto error;
559
 
 
560
 
        length = 0;
561
 
        brasero_track_get_audio_length (track, &length);
562
 
        sectors = BRASERO_DURATION_TO_SECTORS (length);
563
 
 
564
 
        BRASERO_JOB_LOG (cdrecord, "got track length %lli", length);
565
 
        string = g_strdup_printf ("Tracklength=\t%"G_GINT64_FORMAT", 0\n", sectors);
566
 
        size = strlen (string);
567
 
        b_written = write (fd, string, size);
568
 
        g_free (string);
569
 
        if (b_written != size)
570
 
                goto error;
571
 
 
572
 
        strcpy (buffer, "Pre-emphasis=\tno\n");
573
 
        size = strlen (buffer);
574
 
        b_written = write (fd, buffer, size);
575
 
        if (b_written != size)
576
 
                goto error;
577
 
 
578
 
        strcpy (buffer, "Channels=\t2\n");
579
 
        size = strlen (buffer);
580
 
        b_written = write (fd, buffer, size);
581
 
        if (b_written != size)
582
 
                goto error;
583
 
 
584
 
        strcpy (buffer, "Copy_permitted=\tyes\n");
585
 
        size = strlen (buffer);
586
 
        b_written = write (fd, buffer, size);
587
 
        if (b_written != size)
588
 
                goto error;
589
 
 
590
 
        strcpy (buffer, "Endianess=\tlittle\n");
591
 
        size = strlen (buffer);
592
 
        b_written = write (fd, buffer, size);
593
 
        if (b_written != size)
594
 
                goto error;
595
 
 
596
 
        strcpy (buffer, "Index=\t\t0\n");
597
 
        size = strlen (buffer);
598
 
        b_written = write (fd, buffer, size);
599
 
        if (b_written != size)
600
 
                goto error;
601
 
 
602
 
        /* NOTE: -1 here means no pregap */
603
 
        if (!last_track) {
604
 
                /* K3b does this (possibly to remove silence) */
605
 
                string = g_strdup_printf ("Index0=\t\t%"G_GINT64_FORMAT"\n",
606
 
                                          sectors - 150);
607
 
        }
608
 
        else
609
 
                string = g_strdup_printf ("Index0=\t\t-1\n");
610
 
 
611
 
        size = strlen (string);
612
 
        b_written = write (fd, string, size);
613
 
        g_free (string);
614
 
        if (b_written != size)
615
 
                goto error;
616
 
 
617
 
        close (fd);
618
 
 
619
 
        if (argv)
620
 
                g_ptr_array_add (argv, path);
621
 
        else
622
 
                g_free (path);
623
 
 
624
 
        return BRASERO_BURN_OK;
625
 
 
626
 
 
627
 
error:
628
 
        errsv = errno;
629
 
 
630
 
        g_remove (path);
631
 
        g_free (path);
632
 
 
633
 
        g_set_error (error,
634
 
                     BRASERO_BURN_ERROR,
635
 
                     BRASERO_BURN_ERROR_GENERAL,
636
 
                     _("An internal error occured (%s)"), 
637
 
                     g_strerror (errsv));
638
 
 
639
 
        return BRASERO_BURN_ERR;
640
 
}
641
 
 
642
 
static BraseroBurnResult
643
 
brasero_cdrecord_write_infs (BraseroCDRecord *cdrecord,
644
 
                             GPtrArray *argv,
645
 
                             GError **error)
646
 
{
647
 
        BraseroCDRecordPrivate *priv;
648
 
        BraseroBurnResult result;
649
 
        gchar *tmpdir = NULL;
650
 
        GSList *tracks;
651
 
        GSList *iter;
652
 
        gchar *album;
653
 
        gint index;
654
 
        gint start;
655
 
 
656
 
        priv = BRASERO_CD_RECORD_PRIVATE (cdrecord);
657
 
 
658
 
        brasero_job_get_audio_title (BRASERO_JOB (cdrecord), &album);
659
 
        brasero_job_get_tracks (BRASERO_JOB (cdrecord), &tracks);
660
 
        index = 1;
661
 
        start = 0;
662
 
 
663
 
        for (iter = tracks; iter; iter = iter->next) {
664
 
                gint64 length;
665
 
                BraseroTrack *track;
666
 
 
667
 
                track = iter->data;
668
 
                result = brasero_cdrecord_write_inf (cdrecord,
669
 
                                                     argv,
670
 
                                                     track,
671
 
                                                     tmpdir,
672
 
                                                     album,
673
 
                                                     index,
674
 
                                                     start,
675
 
                                                     (iter->next == NULL),
676
 
                                                     error);
677
 
                if (result != BRASERO_BURN_OK)
678
 
                        return result;
679
 
 
680
 
                index ++;
681
 
                length = 0;
682
 
 
683
 
                brasero_track_get_audio_length (track, &length);
684
 
                start += BRASERO_DURATION_TO_SECTORS (length);
685
 
        }
686
 
 
687
 
        g_free (album);
688
 
        g_free (tmpdir);
689
 
 
690
 
        return BRASERO_BURN_OK;
691
 
}
692
 
 
693
 
static BraseroBurnResult
694
 
brasero_cdrecord_set_argv_record (BraseroCDRecord *cdrecord,
695
 
                                  GPtrArray *argv, 
696
 
                                  GError **error)
697
 
{
698
 
        guint speed;
699
 
        BraseroBurnFlag flags;
700
 
        BraseroTrackType type;
701
 
        BraseroCDRecordPrivate *priv;
702
 
 
703
 
        priv = BRASERO_CD_RECORD_PRIVATE (cdrecord);
704
 
 
705
 
        if (priv->immediate) {
706
 
                g_ptr_array_add (argv, g_strdup ("-immed"));
707
 
                g_ptr_array_add (argv, g_strdup_printf ("minbuf=%i", priv->minbuf));
708
 
        }
709
 
 
710
 
        if (brasero_job_get_speed (BRASERO_JOB (cdrecord), &speed) == BRASERO_BURN_OK) {
711
 
                gchar *speed_str;
712
 
 
713
 
                speed_str = g_strdup_printf ("speed=%d", speed);
714
 
                g_ptr_array_add (argv, speed_str);
715
 
        }
716
 
 
717
 
        brasero_job_get_flags (BRASERO_JOB (cdrecord), &flags);
718
 
        if (flags & BRASERO_BURN_FLAG_OVERBURN)
719
 
                g_ptr_array_add (argv, g_strdup ("-overburn"));
720
 
        if (flags & BRASERO_BURN_FLAG_BURNPROOF)
721
 
                g_ptr_array_add (argv, g_strdup ("driveropts=burnfree"));
722
 
        if (flags & BRASERO_BURN_FLAG_MULTI)
723
 
                g_ptr_array_add (argv, g_strdup ("-multi"));
724
 
 
725
 
        /* NOTE: This write mode is necessary for all CLONE images burning */
726
 
        if (flags & BRASERO_BURN_FLAG_RAW)
727
 
                g_ptr_array_add (argv, g_strdup ("-raw96r"));
728
 
 
729
 
        /* NOTE1: DAO can't be used if we're appending to a disc */
730
 
        /* NOTE2: CD-text cannot be written in tao mode (which is the default)
731
 
         * NOTE3: when we don't want wodim to use stdin then we give the audio
732
 
         * file on the command line. Otherwise we use the .inf */
733
 
        if (flags & BRASERO_BURN_FLAG_DAO)
734
 
                g_ptr_array_add (argv, g_strdup ("-dao"));
735
 
 
736
 
        brasero_job_get_input_type (BRASERO_JOB (cdrecord), &type);
737
 
        if (brasero_job_get_fd_in (BRASERO_JOB (cdrecord), NULL) == BRASERO_BURN_OK) {
738
 
                BraseroBurnResult result;
739
 
                int buffer_size;
740
 
                gint64 sectors;
741
 
                
742
 
                /* we need to know what is the type of the track (audio / data) */
743
 
                result = brasero_job_get_input_type (BRASERO_JOB (cdrecord), &type);
744
 
                if (result != BRASERO_BURN_OK) {
745
 
                        BRASERO_JOB_LOG (cdrecord, "Imager doesn't seem to be ready")
746
 
                        g_set_error (error,
747
 
                                     BRASERO_BURN_ERROR,
748
 
                                     BRASERO_BURN_ERROR_GENERAL,
749
 
                                     _("An internal error occured"));
750
 
                        return BRASERO_BURN_ERR;
751
 
                }
752
 
                
753
 
                /* ask the size */
754
 
                result = brasero_job_get_session_output_size (BRASERO_JOB (cdrecord),
755
 
                                                              &sectors,
756
 
                                                              NULL);
757
 
                if (result != BRASERO_BURN_OK) {
758
 
                        BRASERO_JOB_LOG (cdrecord, "The size of the session cannot be retrieved")
759
 
                        g_set_error (error,
760
 
                                     BRASERO_BURN_ERROR,
761
 
                                     BRASERO_BURN_ERROR_GENERAL,
762
 
                                     _("An internal error occured"));
763
 
                        return BRASERO_BURN_ERR;
764
 
                }
765
 
 
766
 
                /* we create a buffer depending on the size 
767
 
                 * buffer 4m> < 64m and is 1/25th of size otherwise */
768
 
                buffer_size = sectors * 2352 / 1024 / 1024 / 25;
769
 
                if (buffer_size > 32)
770
 
                        buffer_size = 32;
771
 
                else if (buffer_size < 4)
772
 
                        buffer_size = 4;
773
 
 
774
 
                g_ptr_array_add (argv, g_strdup_printf ("fs=%im", buffer_size));
775
 
                if (type.type == BRASERO_TRACK_TYPE_IMAGE) {
776
 
                        if (type.subtype.img_format == BRASERO_IMAGE_FORMAT_BIN) {
777
 
                                g_ptr_array_add (argv, g_strdup_printf ("tsize=%Lis", sectors));
778
 
                                g_ptr_array_add (argv, g_strdup ("-data"));
779
 
                                g_ptr_array_add (argv, g_strdup ("-nopad"));
780
 
                                g_ptr_array_add (argv, g_strdup ("-"));
781
 
                        }
782
 
                        else
783
 
                                BRASERO_JOB_NOT_SUPPORTED (cdrecord);;
784
 
                }
785
 
                else if (type.type == BRASERO_TRACK_TYPE_AUDIO) {
786
 
                        g_ptr_array_add (argv, g_strdup ("-swab"));
787
 
                        g_ptr_array_add (argv, g_strdup ("-audio"));
788
 
                        g_ptr_array_add (argv, g_strdup ("-useinfo"));
789
 
                        g_ptr_array_add (argv, g_strdup ("-text"));
790
 
 
791
 
                        result = brasero_cdrecord_write_infs (cdrecord,
792
 
                                                              argv,
793
 
                                                              error);
794
 
                        if (result != BRASERO_BURN_OK)
795
 
                                return result;
796
 
                }
797
 
                else
798
 
                        BRASERO_JOB_NOT_SUPPORTED (cdrecord);
799
 
        }
800
 
        else if (type.type == BRASERO_TRACK_TYPE_AUDIO) {
801
 
                BraseroBurnResult result;
802
 
                GSList *tracks;
803
 
 
804
 
                g_ptr_array_add (argv, g_strdup ("fs=16m"));
805
 
                g_ptr_array_add (argv, g_strdup ("-audio"));
806
 
                g_ptr_array_add (argv, g_strdup ("-swab"));
807
 
                g_ptr_array_add (argv, g_strdup ("-pad"));
808
 
        
809
 
                g_ptr_array_add (argv, g_strdup ("-useinfo"));
810
 
                g_ptr_array_add (argv, g_strdup ("-text"));
811
 
 
812
 
                result = brasero_cdrecord_write_infs (cdrecord,
813
 
                                                      NULL,
814
 
                                                      error);
815
 
                if (result != BRASERO_BURN_OK)
816
 
                        return result;
817
 
 
818
 
                tracks = NULL;
819
 
                brasero_job_get_tracks (BRASERO_JOB (cdrecord), &tracks);
820
 
                for (; tracks; tracks = tracks->next) {
821
 
                        BraseroTrack *track;
822
 
                        gchar *path;
823
 
 
824
 
                        track = tracks->data;
825
 
                        path = brasero_track_get_audio_source (track, FALSE);
826
 
                        g_ptr_array_add (argv, path);
827
 
                }
828
 
        }
829
 
        else if (type.type == BRASERO_TRACK_TYPE_IMAGE) {
830
 
                BraseroTrack *track = NULL;
831
 
 
832
 
                brasero_job_get_current_track (BRASERO_JOB (cdrecord), &track);
833
 
                if (!track)
834
 
                        BRASERO_JOB_NOT_READY (cdrecord);
835
 
 
836
 
                if (type.subtype.img_format == BRASERO_IMAGE_FORMAT_NONE) {
837
 
                        gchar *image_path;
838
 
 
839
 
                        image_path = brasero_track_get_image_source (track, FALSE);
840
 
                        if (!image_path)
841
 
                                BRASERO_JOB_NOT_READY (cdrecord);
842
 
 
843
 
                        g_ptr_array_add (argv, g_strdup ("fs=16m"));
844
 
                        g_ptr_array_add (argv, g_strdup ("-data"));
845
 
                        g_ptr_array_add (argv, g_strdup ("-nopad"));
846
 
                        g_ptr_array_add (argv, image_path);
847
 
                }
848
 
                else if (type.subtype.img_format == BRASERO_IMAGE_FORMAT_BIN) {
849
 
                        gchar *isopath;
850
 
 
851
 
                        isopath = brasero_track_get_image_source (track, FALSE);
852
 
                        if (!isopath)
853
 
                                BRASERO_JOB_NOT_READY (cdrecord);
854
 
 
855
 
                        g_ptr_array_add (argv, g_strdup ("fs=16m"));
856
 
                        g_ptr_array_add (argv, g_strdup ("-data"));
857
 
                        g_ptr_array_add (argv, g_strdup ("-nopad"));
858
 
                        g_ptr_array_add (argv, isopath);
859
 
                }
860
 
                else if (type.subtype.img_format == BRASERO_IMAGE_FORMAT_CLONE) {
861
 
                        gchar *rawpath;
862
 
 
863
 
                        rawpath = brasero_track_get_image_source (track, FALSE);
864
 
                        if (!rawpath)
865
 
                                BRASERO_JOB_NOT_READY (cdrecord);
866
 
 
867
 
                        g_ptr_array_add (argv, g_strdup ("fs=16m"));
868
 
                        g_ptr_array_add (argv, g_strdup ("-clone"));
869
 
                        g_ptr_array_add (argv, rawpath);
870
 
                }
871
 
                else if (type.subtype.img_format == BRASERO_IMAGE_FORMAT_CUE) {
872
 
                        gchar *cue_str;
873
 
                        gchar *cuepath;
874
 
 
875
 
                        cuepath = brasero_track_get_toc_source (track, FALSE);
876
 
                        if (!cuepath)
877
 
                                BRASERO_JOB_NOT_READY (cdrecord);
878
 
 
879
 
                        g_ptr_array_add (argv, g_strdup ("fs=16m"));
880
 
 
881
 
                        cue_str = g_strdup_printf ("cuefile=%s", cuepath);
882
 
                        g_ptr_array_add (argv, cue_str);
883
 
                        g_free (cuepath);
884
 
                }
885
 
                else
886
 
                        BRASERO_JOB_NOT_SUPPORTED (cdrecord);
887
 
        }
888
 
        else
889
 
                BRASERO_JOB_NOT_SUPPORTED (cdrecord);
890
 
 
891
 
        brasero_job_set_current_action (BRASERO_JOB (cdrecord),
892
 
                                        BRASERO_BURN_ACTION_START_RECORDING,
893
 
                                        NULL,
894
 
                                        FALSE);
895
 
        return BRASERO_BURN_OK;
896
 
}
897
 
 
898
 
static BraseroBurnResult
899
 
brasero_cdrecord_set_argv_blank (BraseroCDRecord *cdrecord, GPtrArray *argv)
900
 
{
901
 
        gchar *blank_str;
902
 
        BraseroBurnFlag flags;
903
 
 
904
 
        brasero_job_get_flags (BRASERO_JOB (cdrecord), &flags);
905
 
        blank_str = g_strdup_printf ("blank=%s",
906
 
                                    (flags & BRASERO_BURN_FLAG_FAST_BLANK) ? "fast" : "all");
907
 
        g_ptr_array_add (argv, blank_str);
908
 
 
909
 
        brasero_job_set_current_action (BRASERO_JOB (cdrecord),
910
 
                                        BRASERO_BURN_ACTION_BLANKING,
911
 
                                        NULL,
912
 
                                        FALSE);
913
 
        return BRASERO_BURN_OK;
914
 
}
915
 
 
916
 
static BraseroBurnResult
917
 
brasero_cdrecord_set_argv (BraseroProcess *process,
918
 
                           GPtrArray *argv,
919
 
                           GError **error)
920
 
{
921
 
        BraseroCDRecordPrivate *priv;
922
 
        BraseroCDRecord *cdrecord;
923
 
        BraseroBurnResult result;
924
 
        BraseroJobAction action;
925
 
        BraseroBurnFlag flags;
926
 
        gchar *dev_str;
927
 
        gchar *device;
928
 
 
929
 
        cdrecord = BRASERO_CD_RECORD (process);
930
 
        priv = BRASERO_CD_RECORD_PRIVATE (cdrecord);
931
 
 
932
 
        brasero_job_get_action (BRASERO_JOB (cdrecord), &action);
933
 
        if (action == BRASERO_JOB_ACTION_SIZE)
934
 
                return BRASERO_BURN_NOT_SUPPORTED;
935
 
 
936
 
        g_ptr_array_add (argv, g_strdup ("cdrecord"));
937
 
        g_ptr_array_add (argv, g_strdup ("-v"));
938
 
 
939
 
#ifdef HAVE_CAM_LIB_H
940
 
        /* FreeBSD like that better */
941
 
        brasero_job_get_bus_target_lun (BRASERO_JOB (cdrecord), &device);
942
 
#else
943
 
        brasero_job_get_device (BRASERO_JOB (cdrecord), &device);
944
 
#endif
945
 
 
946
 
        dev_str = g_strdup_printf ("dev=%s", device);
947
 
        g_ptr_array_add (argv, dev_str);
948
 
        g_free (device);
949
 
 
950
 
        brasero_job_get_flags (BRASERO_JOB (cdrecord), &flags);
951
 
        if (flags & BRASERO_BURN_FLAG_DUMMY)
952
 
                g_ptr_array_add (argv, g_strdup ("-dummy"));
953
 
 
954
 
        if (flags & BRASERO_BURN_FLAG_NOGRACE)
955
 
                g_ptr_array_add (argv, g_strdup ("gracetime=0"));
956
 
 
957
 
        if (action == BRASERO_JOB_ACTION_RECORD)
958
 
                result = brasero_cdrecord_set_argv_record (cdrecord, argv, error);
959
 
        else if (action == BRASERO_JOB_ACTION_ERASE)
960
 
                result = brasero_cdrecord_set_argv_blank (cdrecord, argv);
961
 
        else
962
 
                BRASERO_JOB_NOT_SUPPORTED (cdrecord);
963
 
 
964
 
        return result;  
965
 
}
966
 
 
967
 
static BraseroBurnResult
968
 
brasero_cdrecord_post (BraseroJob *job)
969
 
{
970
 
        BraseroCDRecordPrivate *priv;
971
 
        GSList *iter;
972
 
 
973
 
        priv = BRASERO_CD_RECORD_PRIVATE (job);
974
 
        for (iter = priv->infs; iter; iter = iter->next) {
975
 
                gchar *path;
976
 
 
977
 
                path = iter->data;
978
 
                g_remove (path);
979
 
                g_free (path);
980
 
        }
981
 
 
982
 
        g_slist_free (priv->infs);
983
 
        priv->infs = NULL;
984
 
 
985
 
        return brasero_job_finished_session (job);
986
 
}
987
 
 
988
 
static void
989
 
brasero_cdrecord_class_init (BraseroCDRecordClass *klass)
990
 
{
991
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
992
 
        BraseroProcessClass *process_class = BRASERO_PROCESS_CLASS (klass);
993
 
 
994
 
        g_type_class_add_private (klass, sizeof (BraseroCDRecordPrivate));
995
 
 
996
 
        parent_class = g_type_class_peek_parent (klass);
997
 
        object_class->finalize = brasero_cdrecord_finalize;
998
 
 
999
 
        process_class->stderr_func = brasero_cdrecord_stderr_read;
1000
 
        process_class->stdout_func = brasero_cdrecord_stdout_read;
1001
 
        process_class->set_argv = brasero_cdrecord_set_argv;
1002
 
        process_class->post = brasero_cdrecord_post;
1003
 
}
1004
 
 
1005
 
static void
1006
 
brasero_cdrecord_init (BraseroCDRecord *obj)
1007
 
{
1008
 
        GConfClient *client;
1009
 
        BraseroCDRecordPrivate *priv;
1010
 
 
1011
 
        /* load our "configuration" */
1012
 
        priv = BRASERO_CD_RECORD_PRIVATE (obj);
1013
 
 
1014
 
        client = gconf_client_get_default ();
1015
 
        priv->immediate = gconf_client_get_bool (client,
1016
 
                                                 GCONF_KEY_IMMEDIATE_FLAG,
1017
 
                                                 NULL);
1018
 
        priv->minbuf = gconf_client_get_int (client,
1019
 
                                             GCONF_KEY_MINBUF_VALUE,
1020
 
                                             NULL);
1021
 
        if (priv->minbuf > 95 || priv->minbuf < 25)
1022
 
                priv->minbuf = 30;
1023
 
 
1024
 
        g_object_unref (client);
1025
 
}
1026
 
 
1027
 
static void
1028
 
brasero_cdrecord_finalize (GObject *object)
1029
 
{
1030
 
        BraseroCDRecordPrivate *priv;
1031
 
        GSList *iter;
1032
 
 
1033
 
        priv = BRASERO_CD_RECORD_PRIVATE (object);
1034
 
 
1035
 
        for (iter = priv->infs; iter; iter = iter->next) {
1036
 
                gchar *path;
1037
 
 
1038
 
                path = iter->data;
1039
 
                g_remove (path);
1040
 
                g_free (path);
1041
 
        }
1042
 
 
1043
 
        g_slist_free (priv->infs);
1044
 
        priv->infs = NULL;
1045
 
 
1046
 
        G_OBJECT_CLASS (parent_class)->finalize (object);
1047
 
}
1048
 
 
1049
 
static BraseroBurnResult
1050
 
brasero_cdrecord_export_caps (BraseroPlugin *plugin, gchar **error)
1051
 
{
1052
 
        BraseroPluginConfOption *immed, *minbuf;
1053
 
        const BraseroMedia media = BRASERO_MEDIUM_CD|
1054
 
                                   BRASERO_MEDIUM_WRITABLE|
1055
 
                                   BRASERO_MEDIUM_REWRITABLE|
1056
 
                                   BRASERO_MEDIUM_BLANK|
1057
 
                                   BRASERO_MEDIUM_APPENDABLE|
1058
 
                                   BRASERO_MEDIUM_HAS_AUDIO|
1059
 
                                   BRASERO_MEDIUM_HAS_DATA;
1060
 
        const BraseroMedia dvd_media = BRASERO_MEDIUM_DVD|
1061
 
                                       BRASERO_MEDIUM_PLUS|
1062
 
                                       BRASERO_MEDIUM_SEQUENTIAL|
1063
 
                                       BRASERO_MEDIUM_WRITABLE|
1064
 
                                       BRASERO_MEDIUM_REWRITABLE|
1065
 
                                       BRASERO_MEDIUM_BLANK|
1066
 
                                       BRASERO_MEDIUM_UNFORMATTED|
1067
 
                                       BRASERO_MEDIUM_APPENDABLE|
1068
 
                                       BRASERO_MEDIUM_HAS_DATA;
1069
 
        const BraseroMedia media_rw = BRASERO_MEDIUM_CD|
1070
 
                                      BRASERO_MEDIUM_REWRITABLE|
1071
 
                                      BRASERO_MEDIUM_APPENDABLE|
1072
 
                                      BRASERO_MEDIUM_CLOSED|
1073
 
                                      BRASERO_MEDIUM_HAS_AUDIO|
1074
 
                                      BRASERO_MEDIUM_HAS_DATA|
1075
 
                                      BRASERO_MEDIUM_BLANK;
1076
 
        BraseroBurnResult result;
1077
 
        GSList *output;
1078
 
        GSList *input;
1079
 
 
1080
 
        /* NOTE: it seems that cdrecord can burn cue files on the fly */
1081
 
        brasero_plugin_define (plugin,
1082
 
                               "cdrecord",
1083
 
                               _("Use cdrecord to burn CDs and DVDs"),
1084
 
                               "Philippe Rouquier",
1085
 
                               1);
1086
 
 
1087
 
        /* First see if this plugin can be used */
1088
 
        result = brasero_process_check_path ("cdrecord", error);
1089
 
        if (result != BRASERO_BURN_OK)
1090
 
                return result;
1091
 
 
1092
 
        /* for recording */
1093
 
        input = brasero_caps_image_new (BRASERO_PLUGIN_IO_ACCEPT_PIPE|
1094
 
                                        BRASERO_PLUGIN_IO_ACCEPT_FILE,
1095
 
                                        BRASERO_IMAGE_FORMAT_BIN);
1096
 
 
1097
 
        /* cdrecord can burn all DVDs (except restricted) when it's ISOs */
1098
 
        output = brasero_caps_disc_new (dvd_media);
1099
 
        brasero_plugin_link_caps (plugin, output, input);
1100
 
        g_slist_free (output);
1101
 
 
1102
 
        /* All CD-R(W) */
1103
 
        output = brasero_caps_disc_new (media);
1104
 
        brasero_plugin_link_caps (plugin, output, input);
1105
 
        g_slist_free (input);
1106
 
 
1107
 
        input = brasero_caps_audio_new (BRASERO_PLUGIN_IO_ACCEPT_PIPE|
1108
 
                                        BRASERO_PLUGIN_IO_ACCEPT_FILE,
1109
 
                                        BRASERO_AUDIO_FORMAT_RAW|
1110
 
                                        BRASERO_AUDIO_FORMAT_44100|
1111
 
                                        BRASERO_METADATA_INFO);
1112
 
 
1113
 
        brasero_plugin_link_caps (plugin, output, input);
1114
 
        g_slist_free (input);
1115
 
 
1116
 
        input = brasero_caps_audio_new (BRASERO_PLUGIN_IO_ACCEPT_PIPE|
1117
 
                                        BRASERO_PLUGIN_IO_ACCEPT_FILE,
1118
 
                                        BRASERO_AUDIO_FORMAT_RAW|
1119
 
                                        BRASERO_AUDIO_FORMAT_44100);
1120
 
 
1121
 
        brasero_plugin_link_caps (plugin, output, input);
1122
 
        g_slist_free (output);
1123
 
        g_slist_free (input);
1124
 
 
1125
 
        /* for CLONE and CUE type images, we only want blank CD-R(W) */
1126
 
        output = brasero_caps_disc_new (BRASERO_MEDIUM_CD|
1127
 
                                        BRASERO_MEDIUM_WRITABLE|
1128
 
                                        BRASERO_MEDIUM_REWRITABLE|
1129
 
                                        BRASERO_MEDIUM_BLANK);
1130
 
 
1131
 
        input = brasero_caps_image_new (BRASERO_PLUGIN_IO_ACCEPT_FILE,
1132
 
                                        BRASERO_IMAGE_FORMAT_CUE|
1133
 
                                        BRASERO_IMAGE_FORMAT_CLONE);
1134
 
 
1135
 
        brasero_plugin_link_caps (plugin, output, input);
1136
 
        g_slist_free (output);
1137
 
        g_slist_free (input);
1138
 
 
1139
 
        /* Blank CD(R)W : don't use standard flags cdrecord fails consistently
1140
 
         * to write a first track of a multisession disc with DAO mode. */
1141
 
        brasero_plugin_set_flags (plugin,
1142
 
                                  BRASERO_MEDIUM_CD|
1143
 
                                  BRASERO_MEDIUM_WRITABLE|
1144
 
                                  BRASERO_MEDIUM_REWRITABLE|
1145
 
                                  BRASERO_MEDIUM_BLANK,
1146
 
                                  BRASERO_BURN_FLAG_DAO|
1147
 
                                  BRASERO_BURN_FLAG_BURNPROOF|
1148
 
                                  BRASERO_BURN_FLAG_OVERBURN|
1149
 
                                  BRASERO_BURN_FLAG_DUMMY|
1150
 
                                  BRASERO_BURN_FLAG_NOGRACE,
1151
 
                                  BRASERO_BURN_FLAG_NONE);
1152
 
 
1153
 
        brasero_plugin_set_flags (plugin,
1154
 
                                  BRASERO_MEDIUM_CD|
1155
 
                                  BRASERO_MEDIUM_WRITABLE|
1156
 
                                  BRASERO_MEDIUM_REWRITABLE|
1157
 
                                  BRASERO_MEDIUM_BLANK,
1158
 
                                  BRASERO_BURN_FLAG_MULTI|
1159
 
                                  BRASERO_BURN_FLAG_BURNPROOF|
1160
 
                                  BRASERO_BURN_FLAG_OVERBURN|
1161
 
                                  BRASERO_BURN_FLAG_DUMMY|
1162
 
                                  BRASERO_BURN_FLAG_NOGRACE,
1163
 
                                  BRASERO_BURN_FLAG_NONE);
1164
 
 
1165
 
        /* Apart from DAO it also supports RAW mode to burn CLONE images. This
1166
 
         * is a special mode for which there isn't any DUMMY burn possible */
1167
 
        brasero_plugin_set_flags (plugin,
1168
 
                                  BRASERO_MEDIUM_CD|
1169
 
                                  BRASERO_MEDIUM_WRITABLE|
1170
 
                                  BRASERO_MEDIUM_REWRITABLE|
1171
 
                                  BRASERO_MEDIUM_BLANK,
1172
 
                                  BRASERO_BURN_FLAG_RAW|
1173
 
                                  BRASERO_BURN_FLAG_BURNPROOF|
1174
 
                                  BRASERO_BURN_FLAG_OVERBURN|
1175
 
                                  BRASERO_BURN_FLAG_NOGRACE,
1176
 
                                  BRASERO_BURN_FLAG_NONE);
1177
 
 
1178
 
        /* This is a CDR with data data can be merged or at least appended */
1179
 
        brasero_plugin_set_flags (plugin,
1180
 
                                  BRASERO_MEDIUM_CD|
1181
 
                                  BRASERO_MEDIUM_WRITABLE|
1182
 
                                  BRASERO_MEDIUM_APPENDABLE|
1183
 
                                  BRASERO_MEDIUM_HAS_AUDIO|
1184
 
                                  BRASERO_MEDIUM_HAS_DATA,
1185
 
                                  BRASERO_BURN_FLAG_APPEND|
1186
 
                                  BRASERO_BURN_FLAG_MERGE|
1187
 
                                  BRASERO_BURN_FLAG_BURNPROOF|
1188
 
                                  BRASERO_BURN_FLAG_OVERBURN|
1189
 
                                  BRASERO_BURN_FLAG_MULTI|
1190
 
                                  BRASERO_BURN_FLAG_DUMMY|
1191
 
                                  BRASERO_BURN_FLAG_NOGRACE,
1192
 
                                  BRASERO_BURN_FLAG_APPEND);
1193
 
 
1194
 
        /* It is a CDRW we want the CD to be either blanked before or appended
1195
 
         * that's why we set MERGE as compulsory. That way if the CD is not
1196
 
         * MERGED we force the blank before writing to avoid appending sessions
1197
 
         * endlessly until there is no free space. */
1198
 
        brasero_plugin_set_flags (plugin,
1199
 
                                  BRASERO_MEDIUM_CD|
1200
 
                                  BRASERO_MEDIUM_REWRITABLE|
1201
 
                                  BRASERO_MEDIUM_APPENDABLE|
1202
 
                                  BRASERO_MEDIUM_HAS_AUDIO|
1203
 
                                  BRASERO_MEDIUM_HAS_DATA,
1204
 
                                  BRASERO_BURN_FLAG_APPEND|
1205
 
                                  BRASERO_BURN_FLAG_MERGE|
1206
 
                                  BRASERO_BURN_FLAG_BURNPROOF|
1207
 
                                  BRASERO_BURN_FLAG_OVERBURN|
1208
 
                                  BRASERO_BURN_FLAG_MULTI|
1209
 
                                  BRASERO_BURN_FLAG_DUMMY|
1210
 
                                  BRASERO_BURN_FLAG_NOGRACE,
1211
 
                                  BRASERO_BURN_FLAG_MERGE);
1212
 
 
1213
 
        /* DVD-RW cdrecord capabilites are limited to blank media.
1214
 
         * It should not start a multisession disc. */
1215
 
        brasero_plugin_set_flags (plugin,
1216
 
                                  BRASERO_MEDIUM_DVD|
1217
 
                                  BRASERO_MEDIUM_SEQUENTIAL|
1218
 
                                  BRASERO_MEDIUM_WRITABLE|
1219
 
                                  BRASERO_MEDIUM_REWRITABLE|
1220
 
                                  BRASERO_MEDIUM_BLANK,
1221
 
                                  BRASERO_BURN_FLAG_DAO|
1222
 
                                  BRASERO_BURN_FLAG_BURNPROOF|
1223
 
                                  BRASERO_BURN_FLAG_OVERBURN|
1224
 
                                  BRASERO_BURN_FLAG_DUMMY|
1225
 
                                  BRASERO_BURN_FLAG_NOGRACE,
1226
 
                                  BRASERO_BURN_FLAG_NONE);
1227
 
 
1228
 
        /* DVD+W cdrecord capabilities are limited to blank media */
1229
 
        brasero_plugin_set_flags (plugin,
1230
 
                                  BRASERO_MEDIUM_DVDR_PLUS|
1231
 
                                  BRASERO_MEDIUM_BLANK,
1232
 
                                  BRASERO_BURN_FLAG_DAO|
1233
 
                                  BRASERO_BURN_FLAG_BURNPROOF|
1234
 
                                  BRASERO_BURN_FLAG_OVERBURN|
1235
 
                                  BRASERO_BURN_FLAG_NOGRACE,
1236
 
                                  BRASERO_BURN_FLAG_NONE);
1237
 
 
1238
 
        /* for DVD+RW cdrecord capabilities are limited no MERGE */
1239
 
        brasero_plugin_set_flags (plugin,
1240
 
                                  BRASERO_MEDIUM_DVDRW_PLUS|
1241
 
                                  BRASERO_MEDIUM_UNFORMATTED|
1242
 
                                  BRASERO_MEDIUM_BLANK,
1243
 
                                  BRASERO_BURN_FLAG_OVERBURN|
1244
 
                                  BRASERO_BURN_FLAG_NOGRACE,
1245
 
                                  BRASERO_BURN_FLAG_NONE);
1246
 
 
1247
 
        brasero_plugin_set_flags (plugin,
1248
 
                                  BRASERO_MEDIUM_DVDRW_PLUS|
1249
 
                                  BRASERO_MEDIUM_APPENDABLE|
1250
 
                                  BRASERO_MEDIUM_CLOSED|
1251
 
                                  BRASERO_MEDIUM_HAS_DATA,
1252
 
                                  BRASERO_BURN_FLAG_OVERBURN|
1253
 
                                  BRASERO_BURN_FLAG_NOGRACE,
1254
 
                                  BRASERO_BURN_FLAG_NONE);
1255
 
 
1256
 
        /* blanking/formatting caps and flags for +/sequential RW
1257
 
         * NOTE: restricted overwrite DVD-RW can't be formatted.
1258
 
         * moreover DVD+RW are formatted while DVD-RW sequential are blanked.
1259
 
         */
1260
 
        output = brasero_caps_disc_new (BRASERO_MEDIUM_DVD|
1261
 
                                        BRASERO_MEDIUM_PLUS|
1262
 
                                        BRASERO_MEDIUM_REWRITABLE|
1263
 
                                        BRASERO_MEDIUM_APPENDABLE|
1264
 
                                        BRASERO_MEDIUM_SEQUENTIAL|
1265
 
                                        BRASERO_MEDIUM_CLOSED|
1266
 
                                        BRASERO_MEDIUM_HAS_DATA|
1267
 
                                        BRASERO_MEDIUM_UNFORMATTED|
1268
 
                                        BRASERO_MEDIUM_BLANK);
1269
 
        brasero_plugin_blank_caps (plugin, output);
1270
 
        g_slist_free (output);
1271
 
 
1272
 
        brasero_plugin_set_blank_flags (plugin,
1273
 
                                        BRASERO_MEDIUM_DVDRW |
1274
 
                                        BRASERO_MEDIUM_BLANK|
1275
 
                                        BRASERO_MEDIUM_CLOSED |
1276
 
                                        BRASERO_MEDIUM_APPENDABLE|
1277
 
                                        BRASERO_MEDIUM_HAS_DATA|
1278
 
                                        BRASERO_MEDIUM_UNFORMATTED,
1279
 
                                        BRASERO_BURN_FLAG_NOGRACE|
1280
 
                                        BRASERO_BURN_FLAG_FAST_BLANK,
1281
 
                                        BRASERO_BURN_FLAG_NONE);
1282
 
        /* again DVD+RW don't support dummy */
1283
 
        brasero_plugin_set_blank_flags (plugin,
1284
 
                                        BRASERO_MEDIUM_DVDRW_PLUS|
1285
 
                                        BRASERO_MEDIUM_APPENDABLE|
1286
 
                                        BRASERO_MEDIUM_HAS_DATA|
1287
 
                                        BRASERO_MEDIUM_UNFORMATTED|
1288
 
                                        BRASERO_MEDIUM_BLANK|
1289
 
                                        BRASERO_MEDIUM_CLOSED,
1290
 
                                        BRASERO_BURN_FLAG_NOGRACE,
1291
 
                                        BRASERO_BURN_FLAG_NONE);
1292
 
 
1293
 
        /* for blanking (CDRWs) */
1294
 
        output = brasero_caps_disc_new (media_rw);
1295
 
        brasero_plugin_blank_caps (plugin, output);
1296
 
        g_slist_free (output);
1297
 
 
1298
 
        brasero_plugin_set_blank_flags (plugin,
1299
 
                                        media_rw,
1300
 
                                        BRASERO_BURN_FLAG_NOGRACE|
1301
 
                                        BRASERO_BURN_FLAG_FAST_BLANK,
1302
 
                                        BRASERO_BURN_FLAG_NONE);
1303
 
 
1304
 
        /* add some configure options */
1305
 
        immed = brasero_plugin_conf_option_new (GCONF_KEY_IMMEDIATE_FLAG,
1306
 
                                                _("Enable \"-immed\" flag (see cdrecord manual)"),
1307
 
                                                BRASERO_PLUGIN_OPTION_BOOL);
1308
 
        minbuf = brasero_plugin_conf_option_new (GCONF_KEY_MINBUF_VALUE,
1309
 
                                                 _("Minimum drive buffer fill ratio (in %%)(see cdrecord manual):"),
1310
 
                                                 BRASERO_PLUGIN_OPTION_INT);
1311
 
        brasero_plugin_conf_option_int_set_range (minbuf, 25, 95);
1312
 
 
1313
 
        brasero_plugin_conf_option_bool_add_suboption (immed, minbuf);
1314
 
        brasero_plugin_add_conf_option (plugin, immed);
1315
 
 
1316
 
        brasero_plugin_register_group (plugin, _(CDRTOOLS_DESCRIPTION));
1317
 
 
1318
 
        return BRASERO_BURN_OK;
1319
 
}