~ubuntu-branches/ubuntu/wily/brasero/wily

« back to all changes in this revision

Viewing changes to src/brasero-dest-selection.c

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2008-11-18 11:30:50 UTC
  • mfrom: (1.1.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20081118113050-hoy0pi04uv7ww9d8
Tags: 0.8.3-0ubuntu1
* New upstream release (LP: #299411)
  - allow use of remote files
  - drives are now probed asynchronously and may not popup immediatly
    but brasero starts faster
  - some parts of GUI were revisited (in particular the burn
    option dialogs)
  - command line option for video projects (LP: #273140)
  - brasero crashed with SIGSEGV in g_main_context_dispatch()
    (LP: #281599)
  - Brasero main GUI appears after closing the dialog
    when opening an ISO file using Nautilus (LP: #242022)
  - brasero delete original files in VIDEO_TS folder (LP: #280835)
  - brasero crashed with SIGSEGV in 
    brasero_mkisofs_base_write_to_files() (LP: #275312)
  - brasero crashed with SIGSEGV in 
    brasero_project_save_project_as() (LP: #275086)
  - brasero crashed with SIGSEGV in 
    IA__g_sequence_iter_get_sequence() (LP: #282622)
  - brasero crashed with SIGSEGV in brasero_medium_get_drive()
    (LP: #283197)
  - Dialog contains a lot of empty space (LP: #190192)
 * debian/patches/008-add-gettext-domain-to-desktop-file.patch:
   - Dropped, we don't need this anymore
 * debian/control:
  - Add Build-deps on libeel2-dev and libnautilus-extension-dev
 * debian/brasero.install:
  - Install nautilus extension

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
#include "burn-session.h"
50
50
#include "burn-plugin-manager.h"
51
51
#include "burn-drive.h"
52
 
#include "brasero-drive-selection.h"
53
 
#include "brasero-drive-properties.h"
54
 
#include "brasero-drive-info.h"
55
 
#include "brasero-image-properties.h"
 
52
#include "burn-volume-obj.h"
 
53
 
56
54
#include "brasero-dest-selection.h"
57
 
 
 
55
#include "brasero-session-cfg.h"
 
56
#include "brasero-utils.h"
58
57
 
59
58
typedef struct _BraseroDestSelectionPrivate BraseroDestSelectionPrivate;
60
59
struct _BraseroDestSelectionPrivate
61
60
{
 
61
        BraseroBurnSession *session;
62
62
        BraseroBurnCaps *caps;
63
 
        BraseroBurnSession *session;
64
 
 
65
 
        GtkWidget *info;
66
 
 
67
 
        GtkWidget *drive_prop;
68
 
        GtkWidget *button;
69
 
 
70
 
        GtkWidget *copies_box;
71
 
        GtkWidget *copies_spin;
72
 
 
73
 
        guint caps_sig;
74
 
        guint input_sig;
75
 
        guint output_sig;
76
 
 
77
 
        guint default_format:1;
78
 
        guint default_path:1;
79
 
        guint default_ext:1;
 
63
 
 
64
        BraseroDrive *locked_drive;
 
65
 
 
66
        gulong valid_sig;
80
67
};
81
68
 
82
69
#define BRASERO_DEST_SELECTION_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_DEST_SELECTION, BraseroDestSelectionPrivate))
86
73
        PROP_SESSION
87
74
};
88
75
 
89
 
static BraseroDriveSelectionClass* parent_class = NULL;
90
 
 
91
 
G_DEFINE_TYPE (BraseroDestSelection, brasero_dest_selection, BRASERO_TYPE_DRIVE_SELECTION);
92
 
 
93
 
enum {
94
 
        VALID_MEDIA_SIGNAL,
95
 
        LAST_SIGNAL
96
 
};
97
 
static guint brasero_dest_selection_signals [LAST_SIGNAL] = { 0 };
98
 
 
99
 
#define BRASERO_DEST_SAVED_FLAGS        (BRASERO_DRIVE_PROPERTIES_FLAGS|BRASERO_BURN_FLAG_MULTI)
100
 
 
101
 
static void
102
 
brasero_dest_selection_save_drive_properties (BraseroDestSelection *self)
103
 
{
104
 
        BraseroDestSelectionPrivate *priv;
105
 
        BraseroBurnFlag flags;
106
 
        GConfClient *client;
107
 
        const gchar *path;
108
 
        guint64 rate;
109
 
        gchar *key;
110
 
 
111
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
112
 
 
113
 
        client = gconf_client_get_default ();
114
 
 
115
 
        rate = brasero_burn_session_get_rate (priv->session);
116
 
        key = brasero_burn_session_get_config_key (priv->session, "speed");
117
 
        if (!key) {
118
 
                g_object_unref (client);
119
 
                return;
120
 
        }
121
 
 
122
 
        gconf_client_set_int (client, key, rate / 1024, NULL);
123
 
        g_free (key);
124
 
 
125
 
        key = brasero_burn_session_get_config_key (priv->session, "flags");
126
 
        if (!key) {
127
 
                g_object_unref (client);
128
 
                return;
129
 
        }
130
 
 
131
 
        flags = gconf_client_get_int (client, key, NULL);
132
 
        flags &= ~BRASERO_DRIVE_PROPERTIES_FLAGS;
133
 
        flags |= (brasero_burn_session_get_flags (priv->session) & BRASERO_DEST_SAVED_FLAGS);
134
 
        gconf_client_set_int (client, key, flags, NULL);
135
 
        g_free (key);
136
 
 
137
 
        /* temporary directory */
138
 
        path = brasero_burn_session_get_tmpdir (priv->session);
139
 
        key = g_strdup_printf ("%s/tmpdir", BRASERO_DRIVE_PROPERTIES_KEY);
140
 
        gconf_client_set_string (client, key, path, NULL);
141
 
        g_free (key);
142
 
 
143
 
        g_object_unref (client);
144
 
}
145
 
 
146
 
static gboolean
147
 
brasero_dest_selection_check_same_src_dest (BraseroDestSelection *self)
148
 
{
149
 
        BraseroDestSelectionPrivate *priv;
150
 
        BraseroMedium *medium;
151
 
        BraseroDrive *drive;
152
 
        BraseroMedia media;
153
 
 
154
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
155
 
 
156
 
        /* if we have the same source and destination as drives then we don't 
157
 
         * grey out the properties button as otherwise it would always remain
158
 
         * so. Instead of that we grey it only if there is no medium or if the
159
 
         * medium is blank. */
160
 
        if (!brasero_burn_session_same_src_dest_drive (priv->session))
161
 
                return FALSE;
162
 
 
163
 
        /* grey out button only if the source (and therefore dest drive)
164
 
         * hasn't got any medium inside */
165
 
        drive = brasero_burn_session_get_src_drive (priv->session);
166
 
        if (!drive)
167
 
                return FALSE;
168
 
 
169
 
        medium = brasero_drive_get_medium (drive);
170
 
        media = brasero_medium_get_status (medium);;
171
 
 
172
 
        if (media == BRASERO_MEDIUM_NONE)
173
 
                return FALSE;
174
 
 
175
 
        if (media & BRASERO_MEDIUM_BLANK
176
 
        || (media & (BRASERO_MEDIUM_HAS_AUDIO|BRASERO_MEDIUM_HAS_DATA)) == 0)
177
 
                return FALSE;
178
 
 
179
 
        return TRUE;
180
 
}
181
 
 
182
 
static void
183
 
brasero_dest_selection_drive_properties (BraseroDestSelection *self)
184
 
{
185
 
        BraseroDestSelectionPrivate *priv;
186
 
        BraseroBurnFlag compulsory = 0;
187
 
        BraseroBurnFlag supported = 0;
188
 
        BraseroBurnFlag flags = 0;
189
 
        BraseroDrive *drive;
190
 
        GtkWidget *toplevel;
191
 
        const gchar *path;
192
 
        gint result;
193
 
        gint64 rate;
194
 
 
195
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
196
 
 
197
 
        /* Build dialog */
198
 
        priv->drive_prop = brasero_drive_properties_new ();
199
 
 
200
 
        toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
201
 
        gtk_window_set_transient_for (GTK_WINDOW (priv->drive_prop), GTK_WINDOW (toplevel));
202
 
        gtk_window_set_destroy_with_parent (GTK_WINDOW (priv->drive_prop), TRUE);
203
 
        gtk_window_set_position (GTK_WINDOW (toplevel), GTK_WIN_POS_CENTER_ON_PARENT);
204
 
 
205
 
        /* get information */
206
 
        drive = brasero_burn_session_get_burner (priv->session);
207
 
        rate = brasero_burn_session_get_rate (priv->session);
208
 
 
209
 
        brasero_drive_properties_set_drive (BRASERO_DRIVE_PROPERTIES (priv->drive_prop),
210
 
                                            drive,
211
 
                                            rate);
212
 
 
213
 
        flags = brasero_burn_session_get_flags (priv->session);
214
 
        brasero_burn_caps_get_flags (priv->caps,
215
 
                                     priv->session,
216
 
                                     &supported,
217
 
                                     &compulsory);
218
 
 
219
 
        brasero_drive_properties_set_flags (BRASERO_DRIVE_PROPERTIES (priv->drive_prop),
220
 
                                            flags,
221
 
                                            supported,
222
 
                                            compulsory);
223
 
 
224
 
        path = brasero_burn_session_get_tmpdir (priv->session);
225
 
        brasero_drive_properties_set_tmpdir (BRASERO_DRIVE_PROPERTIES (priv->drive_prop),
226
 
                                             path);
227
 
 
228
 
        /* launch the dialog */
229
 
        gtk_widget_show_all (priv->drive_prop);
230
 
        result = gtk_dialog_run (GTK_DIALOG (priv->drive_prop));
231
 
        if (result != GTK_RESPONSE_ACCEPT) {
232
 
                gtk_widget_destroy (priv->drive_prop);
233
 
                priv->drive_prop = NULL;
234
 
                return;
235
 
        }
236
 
 
237
 
        rate = brasero_drive_properties_get_rate (BRASERO_DRIVE_PROPERTIES (priv->drive_prop));
238
 
        brasero_burn_session_set_rate (priv->session, rate);
239
 
 
240
 
        brasero_burn_session_remove_flag (priv->session, BRASERO_DRIVE_PROPERTIES_FLAGS);
241
 
        flags = brasero_drive_properties_get_flags (BRASERO_DRIVE_PROPERTIES (priv->drive_prop));
242
 
        brasero_burn_session_add_flag (priv->session, flags);
243
 
 
244
 
        path = brasero_drive_properties_get_tmpdir (BRASERO_DRIVE_PROPERTIES (priv->drive_prop));
245
 
        brasero_burn_session_set_tmpdir (priv->session, path);
246
 
 
247
 
        brasero_dest_selection_save_drive_properties (self);
248
 
 
249
 
        gtk_widget_destroy (priv->drive_prop);
250
 
        priv->drive_prop = NULL;
251
 
}
252
 
 
253
 
static gchar *
254
 
brasero_dest_selection_get_output_path (BraseroDestSelection *self)
255
 
{
256
 
        gchar *path = NULL;
257
 
        BraseroImageFormat format;
258
 
        BraseroDestSelectionPrivate *priv;
259
 
 
260
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
261
 
 
262
 
        format = brasero_burn_session_get_output_format (priv->session);
263
 
        switch (format) {
264
 
        case BRASERO_IMAGE_FORMAT_BIN:
265
 
                brasero_burn_session_get_output (priv->session,
266
 
                                                 &path,
267
 
                                                 NULL,
268
 
                                                 NULL);
269
 
                break;
270
 
 
271
 
        case BRASERO_IMAGE_FORMAT_CLONE:
272
 
                brasero_burn_session_get_output (priv->session,
273
 
                                                 NULL,
274
 
                                                 &path,
275
 
                                                 NULL);
276
 
                break;
277
 
 
278
 
        case BRASERO_IMAGE_FORMAT_CDRDAO:
279
 
                brasero_burn_session_get_output (priv->session,
280
 
                                                 NULL,
281
 
                                                 &path,
282
 
                                                 NULL);
283
 
                break;
284
 
 
285
 
        case BRASERO_IMAGE_FORMAT_CUE:
286
 
                brasero_burn_session_get_output (priv->session,
287
 
                                                 NULL,
288
 
                                                 &path,
289
 
                                                 NULL);
290
 
                break;
291
 
 
292
 
        default:
293
 
                break;
294
 
        }
295
 
 
296
 
        return path;
297
 
}
298
 
 
299
 
static void
300
 
brasero_dest_selection_set_output_path (BraseroDestSelection *self,
301
 
                                        BraseroImageFormat format,
302
 
                                        const gchar *path)
303
 
{
304
 
        BraseroDestSelectionPrivate *priv;
305
 
 
306
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
307
 
 
308
 
        switch (format) {
309
 
        case BRASERO_IMAGE_FORMAT_BIN:
310
 
                brasero_burn_session_set_image_output_full (priv->session,
311
 
                                                            format,
312
 
                                                            path,
313
 
                                                            NULL);
314
 
                break;
315
 
 
316
 
        case BRASERO_IMAGE_FORMAT_CDRDAO:
317
 
        case BRASERO_IMAGE_FORMAT_CLONE:
318
 
        case BRASERO_IMAGE_FORMAT_CUE:
319
 
                brasero_burn_session_set_image_output_full (priv->session,
320
 
                                                            format,
321
 
                                                            NULL,
322
 
                                                            path);
323
 
                break;
324
 
 
325
 
        default:
326
 
                break;
327
 
        }
328
 
}
329
 
 
330
 
static void
331
 
brasero_dest_selection_get_default_output_format (BraseroDestSelection *self,
332
 
                                                  BraseroTrackType *output)
333
 
{
334
 
        BraseroTrackType source;
335
 
        BraseroBurnResult result;
336
 
        BraseroDestSelectionPrivate *priv;
337
 
 
338
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
339
 
 
340
 
        brasero_burn_session_get_input_type (priv->session, &source);
341
 
        if (source.type == BRASERO_TRACK_TYPE_NONE) {
342
 
                output->type = BRASERO_TRACK_TYPE_NONE;
343
 
                return;
344
 
        }
345
 
 
346
 
        output->type = BRASERO_TRACK_TYPE_IMAGE;
347
 
        output->subtype.img_format = BRASERO_IMAGE_FORMAT_NONE;
348
 
 
349
 
        if (source.type == BRASERO_TRACK_TYPE_IMAGE) {
350
 
                output->subtype.img_format = source.subtype.img_format;
351
 
                return;
352
 
        }
353
 
 
354
 
        if (source.type == BRASERO_TRACK_TYPE_AUDIO) {
355
 
                /* If that's AUDIO only without VIDEO then return */
356
 
                if (!(source.subtype.audio_format & (BRASERO_VIDEO_FORMAT_UNDEFINED|BRASERO_VIDEO_FORMAT_VCD|BRASERO_VIDEO_FORMAT_VIDEO_DVD)))
357
 
                        return;
358
 
 
359
 
                /* Otherwise try all possible image types */
360
 
                output->subtype.img_format = BRASERO_IMAGE_FORMAT_CDRDAO;
361
 
                for (; output->subtype.img_format != BRASERO_IMAGE_FORMAT_NONE;
362
 
                       output->subtype.img_format >>= 1) {
363
 
                
364
 
                        result = brasero_burn_caps_is_output_supported (priv->caps,
365
 
                                                                        priv->session,
366
 
                                                                        output);
367
 
                        if (result == BRASERO_BURN_OK)
368
 
                                return;
369
 
                }
370
 
                return;
371
 
        }
372
 
 
373
 
        if (source.type == BRASERO_TRACK_TYPE_DATA
374
 
        ||  source.subtype.media & (BRASERO_MEDIUM_DVD|BRASERO_MEDIUM_DVD_DL)) {
375
 
                output->subtype.img_format = BRASERO_IMAGE_FORMAT_BIN;
376
 
                result = brasero_burn_caps_is_output_supported (priv->caps,
377
 
                                                                priv->session,
378
 
                                                                output);
379
 
                if (result != BRASERO_BURN_OK)
380
 
                        output->subtype.img_format = BRASERO_IMAGE_FORMAT_NONE;
381
 
 
382
 
                return;
383
 
        }
384
 
 
385
 
        /* for the input which are CDs there are lots of possible formats */
386
 
        output->subtype.img_format = BRASERO_IMAGE_FORMAT_CDRDAO;
387
 
        for (; output->subtype.img_format != BRASERO_IMAGE_FORMAT_NONE;
388
 
               output->subtype.img_format >>= 1) {
389
 
        
390
 
                result = brasero_burn_caps_is_output_supported (priv->caps,
391
 
                                                                priv->session,
392
 
                                                                output);
393
 
                if (result == BRASERO_BURN_OK)
394
 
                        return;
395
 
        }
396
 
 
397
 
        return;
398
 
}
399
 
 
400
 
static gchar *
401
 
brasero_dest_selection_get_default_output_path (BraseroDestSelection *self,
402
 
                                                BraseroImageFormat format)
403
 
{
404
 
        const gchar *suffixes [] = {".iso",
405
 
                                    ".toc",
406
 
                                    ".cue",
407
 
                                    ".toc",
408
 
                                    NULL };
409
 
        BraseroDestSelectionPrivate *priv;
410
 
        const gchar *suffix = NULL;
411
 
        gchar *path;
412
 
        gint i = 0;
413
 
 
414
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
415
 
 
416
 
        if (format & BRASERO_IMAGE_FORMAT_BIN)
417
 
                suffix = suffixes [0];
418
 
        else if (format & BRASERO_IMAGE_FORMAT_CLONE)
419
 
                suffix = suffixes [1];
420
 
        else if (format & BRASERO_IMAGE_FORMAT_CUE)
421
 
                suffix = suffixes [2];
422
 
        else if (format & BRASERO_IMAGE_FORMAT_CDRDAO)
423
 
                suffix = suffixes [3];
424
 
 
425
 
        path = g_strdup_printf ("%s/brasero%s",
426
 
                                g_get_home_dir (),
427
 
                                suffix);
428
 
 
429
 
        while (g_file_test (path, G_FILE_TEST_EXISTS)) {
430
 
                g_free (path);
431
 
 
432
 
                path = g_strdup_printf ("%s/brasero-%i%s",
433
 
                                        g_get_home_dir (),
434
 
                                        i,
435
 
                                        suffix);
436
 
                i ++;
437
 
        }
438
 
 
439
 
        return path;
440
 
}
441
 
 
442
 
static gchar *
443
 
brasero_dest_selection_fix_image_extension (BraseroImageFormat format,
444
 
                                            gboolean check_existence,
445
 
                                            gchar *path)
446
 
{
447
 
        gchar *dot;
448
 
        guint i = 0;
449
 
        gchar *retval = NULL;
450
 
        const gchar *suffix = NULL;;
451
 
        const gchar *suffixes [] = {".iso",
452
 
                                    ".toc",
453
 
                                    ".cue",
454
 
                                    ".toc",
455
 
                                    NULL };
456
 
 
457
 
        /* search the last dot to check extension */
458
 
        dot = g_utf8_strrchr (path, -1, '.');
459
 
        if (dot && strlen (dot) < 5 && strlen (dot) > 1) {
460
 
                if (format & BRASERO_IMAGE_FORMAT_BIN
461
 
                &&  strcmp (suffixes [0], dot))
462
 
                        *dot = '\0';
463
 
                else if (format & BRASERO_IMAGE_FORMAT_CLONE
464
 
                     &&  strcmp (suffixes [1], dot))
465
 
                        *dot = '\0';
466
 
                else if (format & BRASERO_IMAGE_FORMAT_CUE
467
 
                     &&  strcmp (suffixes [2], dot))
468
 
                        *dot = '\0';
469
 
                else if (format & BRASERO_IMAGE_FORMAT_CDRDAO
470
 
                     &&  strcmp (suffixes [3], dot))
471
 
                        *dot = '\0';
472
 
                else
473
 
                        return path;
474
 
        }
475
 
 
476
 
        /* determine the proper suffix */
477
 
        if (format & BRASERO_IMAGE_FORMAT_BIN)
478
 
                suffix = suffixes [0];
479
 
        else if (format & BRASERO_IMAGE_FORMAT_CLONE)
480
 
                suffix = suffixes [1];
481
 
        else if (format & BRASERO_IMAGE_FORMAT_CUE)
482
 
                suffix = suffixes [2];
483
 
        else if (format & BRASERO_IMAGE_FORMAT_CDRDAO)
484
 
                suffix = suffixes [3];
485
 
        else
486
 
                return path;
487
 
 
488
 
        /* make sure the file doesn't exist */
489
 
        retval = g_strdup_printf ("%s%s", path, suffix);
490
 
        if (!check_existence) {
491
 
                g_free (path);
492
 
                return retval;
493
 
        }
494
 
 
495
 
        while (g_file_test (retval, G_FILE_TEST_EXISTS)) {
496
 
                g_free (retval);
497
 
                retval = g_strdup_printf ("%s-%i%s", path, i, suffix);
498
 
                i ++;
499
 
        }
500
 
 
501
 
        g_free (path);
502
 
        return retval;
503
 
}
504
 
 
505
 
static guint
506
 
brasero_dest_selection_get_possible_output_formats (BraseroDestSelection *self,
507
 
                                                    BraseroImageFormat *formats)
508
 
{
509
 
        guint num = 0;
510
 
        BraseroTrackType output;
511
 
        BraseroImageFormat format;
512
 
        BraseroDestSelectionPrivate *priv;
513
 
 
514
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
515
 
 
516
 
        /* see how many output format are available */
517
 
        format = BRASERO_IMAGE_FORMAT_CDRDAO;
518
 
        (*formats) = BRASERO_IMAGE_FORMAT_NONE;
519
 
        output.type = BRASERO_TRACK_TYPE_IMAGE;
520
 
 
521
 
        for (; format > BRASERO_IMAGE_FORMAT_NONE; format >>= 1) {
522
 
                BraseroBurnResult result;
523
 
 
524
 
                output.subtype.img_format = format;
525
 
                result = brasero_burn_caps_is_output_supported (priv->caps,
526
 
                                                                priv->session,
527
 
                                                                &output);
528
 
                if (result == BRASERO_BURN_OK) {
529
 
                        (*formats) |= format;
530
 
                        num ++;
531
 
                }
532
 
        }
533
 
 
534
 
        return num;
535
 
}
536
 
 
537
 
static void
538
 
brasero_dest_selection_image_format_changed_cb (BraseroImageProperties *dialog,
539
 
                                                BraseroDestSelection *self)
540
 
{
541
 
        BraseroDestSelectionPrivate *priv;
542
 
        BraseroImageFormat format;
543
 
        gchar *image_path;
544
 
 
545
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
546
 
 
547
 
        /* make sure the extension is still valid */
548
 
        image_path = brasero_image_properties_get_path (dialog);
549
 
        if (!image_path)
550
 
                return;
551
 
 
552
 
        format = brasero_image_properties_get_format (dialog);
553
 
 
554
 
        if (format == BRASERO_IMAGE_FORMAT_ANY || format == BRASERO_IMAGE_FORMAT_NONE) {
555
 
                BraseroTrackType output;
556
 
 
557
 
                brasero_dest_selection_get_default_output_format (self, &output);
558
 
                format = output.subtype.img_format;
559
 
        }
560
 
 
561
 
        if (priv->default_path && !brasero_image_properties_is_path_edited (dialog)) {
562
 
                /* not changed: get a new default path */
563
 
                g_free (image_path);
564
 
                image_path = brasero_dest_selection_get_default_output_path (self, format);
565
 
        }
566
 
        else if (image_path)
567
 
                image_path = brasero_dest_selection_fix_image_extension (format, FALSE, image_path);
568
 
        else
569
 
                image_path = brasero_dest_selection_get_default_output_path (self, format);
570
 
 
571
 
        brasero_image_properties_set_path (dialog, image_path);
572
 
}
573
 
 
574
 
static gboolean
575
 
brasero_dest_selection_image_check_extension (BraseroDestSelection *self,
576
 
                                              BraseroImageFormat format,
577
 
                                              const gchar *path)
578
 
{
579
 
        gchar *dot;
580
 
        const gchar *suffixes [] = {".iso",
581
 
                                    ".toc",
582
 
                                    ".cue",
583
 
                                    ".toc",
584
 
                                    NULL };
585
 
 
586
 
        dot = g_utf8_strrchr (path, -1, '.');
587
 
        if (dot) {
588
 
                if (format & BRASERO_IMAGE_FORMAT_BIN
589
 
                && !strcmp (suffixes [0], dot))
590
 
                        return TRUE;
591
 
                else if (format & BRASERO_IMAGE_FORMAT_CLONE
592
 
                     && !strcmp (suffixes [1], dot))
593
 
                        return TRUE;
594
 
                else if (format & BRASERO_IMAGE_FORMAT_CUE
595
 
                     && !strcmp (suffixes [2], dot))
596
 
                        return TRUE;
597
 
                else if (format & BRASERO_IMAGE_FORMAT_CDRDAO
598
 
                     && !strcmp (suffixes [3], dot))
599
 
                        return TRUE;
600
 
        }
601
 
 
602
 
        return FALSE;
603
 
}
604
 
 
605
 
static gboolean
606
 
brasero_dest_selection_image_extension_ask (BraseroDestSelection *self)
607
 
{
608
 
        GtkWidget *dialog;
609
 
        GtkWidget *toplevel;
610
 
        GtkResponseType answer;
611
 
 
612
 
        toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
613
 
        dialog = gtk_message_dialog_new (GTK_WINDOW (toplevel),
614
 
                                         GTK_DIALOG_DESTROY_WITH_PARENT |
615
 
                                         GTK_DIALOG_MODAL,
616
 
                                         GTK_MESSAGE_WARNING,
617
 
                                         GTK_BUTTONS_NONE,
618
 
                                         _("Do you really want to keep the current extension for the disc image name?"));
619
 
 
620
 
                
621
 
        gtk_window_set_title (GTK_WINDOW (dialog), _("Image Extension"));
622
 
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
623
 
                                                  _("If you choose to keep it programs may not be able to recognize the file type properly."));
624
 
 
625
 
        gtk_dialog_add_button (GTK_DIALOG (dialog),
626
 
                               _("_Don't change extension"),
627
 
                               GTK_RESPONSE_CANCEL);
628
 
        gtk_dialog_add_button (GTK_DIALOG (dialog),
629
 
                               _("Change _extension"),
630
 
                               GTK_RESPONSE_YES);
631
 
 
632
 
        answer = gtk_dialog_run (GTK_DIALOG (dialog));
633
 
        gtk_widget_destroy (dialog);
634
 
 
635
 
        if (answer == GTK_RESPONSE_YES)
636
 
                return TRUE;
637
 
 
638
 
        return FALSE;
639
 
}
640
 
 
641
 
static void
642
 
brasero_dest_selection_image_properties (BraseroDestSelection *self)
643
 
{
644
 
        BraseroDestSelectionPrivate *priv;
645
 
        BraseroImageFormat formats;
646
 
        BraseroImageFormat format;
647
 
        BraseroTrackType output;
648
 
        gulong format_changed;
649
 
        gchar *original_path;
650
 
        GtkWindow *toplevel;
651
 
        gchar *image_path;
652
 
        gint answer;
653
 
        guint num;
654
 
 
655
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
656
 
 
657
 
        priv->drive_prop = brasero_image_properties_new ();
658
 
 
659
 
        toplevel = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)));
660
 
        gtk_window_set_transient_for (GTK_WINDOW (priv->drive_prop), GTK_WINDOW (toplevel));
661
 
        gtk_window_set_destroy_with_parent (GTK_WINDOW (priv->drive_prop), TRUE);
662
 
        gtk_window_set_position (GTK_WINDOW (toplevel), GTK_WIN_POS_CENTER_ON_PARENT);
663
 
 
664
 
        /* set all information namely path and format */
665
 
        original_path = brasero_dest_selection_get_output_path (self);
666
 
        brasero_image_properties_set_path (BRASERO_IMAGE_PROPERTIES (priv->drive_prop), original_path);
667
 
        g_free (original_path);
668
 
 
669
 
        if (!priv->default_format)
670
 
                format = brasero_burn_session_get_output_format (priv->session);
671
 
        else
672
 
                format = BRASERO_IMAGE_FORMAT_ANY;
673
 
 
674
 
        num = brasero_dest_selection_get_possible_output_formats (self, &formats);
675
 
        brasero_image_properties_set_formats (BRASERO_IMAGE_PROPERTIES (priv->drive_prop),
676
 
                                              num > 0 ? formats:BRASERO_IMAGE_FORMAT_NONE,
677
 
                                              format);
678
 
 
679
 
        format_changed = g_signal_connect (priv->drive_prop,
680
 
                                           "format-changed",
681
 
                                           G_CALLBACK (brasero_dest_selection_image_format_changed_cb),
682
 
                                           self);
683
 
 
684
 
        /* and here we go ... run the thing */
685
 
        gtk_widget_show (priv->drive_prop);
686
 
        answer = gtk_dialog_run (GTK_DIALOG (priv->drive_prop));
687
 
 
688
 
        g_signal_handler_disconnect (priv->drive_prop, format_changed);
689
 
 
690
 
        if (answer != GTK_RESPONSE_OK) {
691
 
                gtk_widget_destroy (priv->drive_prop);
692
 
                priv->drive_prop = NULL;
693
 
                return;
694
 
        }
695
 
 
696
 
        /* get and check format */
697
 
        format = brasero_image_properties_get_format (BRASERO_IMAGE_PROPERTIES (priv->drive_prop));
698
 
 
699
 
        /* see if we are to choose the format ourselves */
700
 
        if (format == BRASERO_IMAGE_FORMAT_ANY || format == BRASERO_IMAGE_FORMAT_NONE) {
701
 
                brasero_dest_selection_get_default_output_format (self, &output);
702
 
                format = output.subtype.img_format;
703
 
                priv->default_format = TRUE;
704
 
        }
705
 
        else
706
 
                priv->default_format = FALSE;
707
 
 
708
 
        /* see if the user has changed the path */
709
 
        if (brasero_image_properties_is_path_edited (BRASERO_IMAGE_PROPERTIES (priv->drive_prop)))
710
 
                priv->default_path = FALSE;
711
 
 
712
 
        if (!priv->default_path) {
713
 
                /* check the extension */
714
 
                image_path = brasero_image_properties_get_path (BRASERO_IMAGE_PROPERTIES (priv->drive_prop));
715
 
 
716
 
                if (!brasero_dest_selection_image_check_extension (self, format, image_path)) {
717
 
                        if (brasero_dest_selection_image_extension_ask (self)) {
718
 
                                priv->default_ext = TRUE;
719
 
                                image_path = brasero_dest_selection_fix_image_extension (format, TRUE, image_path);
720
 
                        }
721
 
                        else
722
 
                                priv->default_ext = FALSE;
723
 
                }
724
 
        }
725
 
        else
726
 
                image_path = brasero_dest_selection_get_default_output_path (self, format);
727
 
 
728
 
        gtk_widget_destroy (priv->drive_prop);
729
 
        priv->drive_prop = NULL;
730
 
 
731
 
        brasero_drive_info_set_image_path (BRASERO_DRIVE_INFO (priv->info), image_path);
732
 
        brasero_dest_selection_set_output_path (self,
733
 
                                                format,
734
 
                                                image_path);
735
 
        g_free (image_path);
736
 
}
737
 
 
738
 
static void
739
 
brasero_dest_selection_properties_button_cb (GtkWidget *button,
740
 
                                             BraseroDestSelection *self)
741
 
{
742
 
        BraseroDestSelectionPrivate *priv;
743
 
        BraseroDrive *drive;
744
 
 
745
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
746
 
 
747
 
        drive = brasero_burn_session_get_burner (priv->session);
748
 
        if (!drive)
749
 
                return;
750
 
 
751
 
        if (brasero_drive_is_fake (drive))
752
 
                brasero_dest_selection_image_properties (self);
753
 
        else
754
 
                brasero_dest_selection_drive_properties (self);
755
 
}
756
 
 
757
 
static void
758
 
brasero_dest_selection_add_drive_properties_flags (BraseroDestSelection *self,
759
 
                                                   BraseroBurnFlag flags,
760
 
                                                   BraseroBurnFlag *supported_retval,
761
 
                                                   BraseroBurnFlag *compulsory_retval)
762
 
{
763
 
        BraseroBurnFlag flag;
764
 
        BraseroDestSelectionPrivate *priv;
765
 
        BraseroBurnFlag supported = BRASERO_BURN_FLAG_NONE;
766
 
        BraseroBurnFlag compulsory = BRASERO_BURN_FLAG_NONE;
767
 
 
768
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
769
 
 
770
 
        /* add flags then wipe out flags from session to check them one by one */
771
 
        flags |= brasero_burn_session_get_flags (priv->session);
772
 
        brasero_burn_session_remove_flag (priv->session, flags);
773
 
 
774
 
        brasero_burn_caps_get_flags (priv->caps,
775
 
                                     priv->session,
776
 
                                     &supported,
777
 
                                     &compulsory);
778
 
 
779
 
        for (flag = 1; flag < BRASERO_BURN_FLAG_LAST; flag <<= 1) {
780
 
                /* see if this flag was originally set */
781
 
                if (!(flags & flag))
782
 
                        continue;
783
 
 
784
 
                /* Don't set write modes now in this case */
785
 
                if (brasero_burn_session_same_src_dest_drive (priv->session)
786
 
                && (flag & (BRASERO_BURN_FLAG_DAO|BRASERO_BURN_FLAG_RAW)))
787
 
                        continue;
788
 
 
789
 
                if (compulsory
790
 
                && (compulsory & brasero_burn_session_get_flags (priv->session)) != compulsory) {
791
 
                        brasero_burn_session_add_flag (priv->session, compulsory);
792
 
                        supported = BRASERO_BURN_FLAG_NONE;
793
 
                        compulsory = BRASERO_BURN_FLAG_NONE;
794
 
                        brasero_burn_caps_get_flags (priv->caps,
795
 
                                                     priv->session,
796
 
                                                     &supported,
797
 
                                                     &compulsory);
798
 
                }
799
 
 
800
 
                if (supported & flag) {
801
 
                        brasero_burn_session_add_flag (priv->session, flag);
802
 
                        supported = BRASERO_BURN_FLAG_NONE;
803
 
                        compulsory = BRASERO_BURN_FLAG_NONE;
804
 
                        brasero_burn_caps_get_flags (priv->caps,
805
 
                                                     priv->session,
806
 
                                                     &supported,
807
 
                                                     &compulsory);
808
 
                }
809
 
        }
810
 
 
811
 
        /* Always set this flag whenever possible */
812
 
        if (supported & BRASERO_BURN_FLAG_BLANK_BEFORE_WRITE) {
813
 
                brasero_burn_session_add_flag (priv->session,
814
 
                                               BRASERO_BURN_FLAG_BLANK_BEFORE_WRITE|
815
 
                                               BRASERO_BURN_FLAG_FAST_BLANK);
816
 
        }
817
 
 
818
 
        /* When copying with same drive don't set write mode, it'll be set later */
819
 
        if (!brasero_burn_session_same_src_dest_drive (priv->session)) {
820
 
                /* use DAO whenever it's possible */
821
 
                if (supported & BRASERO_BURN_FLAG_DAO) {
822
 
                        brasero_burn_session_add_flag (priv->session, BRASERO_BURN_FLAG_DAO);
823
 
                        brasero_burn_caps_get_flags (priv->caps,
824
 
                                                     priv->session,
825
 
                                                     &supported,
826
 
                                                     &compulsory);
827
 
                }
828
 
        }
829
 
 
830
 
        if (supported_retval)
831
 
                *supported_retval = supported;
832
 
        if (compulsory_retval)
833
 
                *compulsory_retval = compulsory;
834
 
}
835
 
 
836
 
static void
837
 
brasero_dest_selection_set_drive_properties (BraseroDestSelection *self)
838
 
{
839
 
        BraseroDestSelectionPrivate *priv;
840
 
        BraseroBurnResult is_valid;
841
 
        BraseroTrackType source;
842
 
        BraseroBurnFlag flags;
843
 
        BraseroMedium *medium;
844
 
        BraseroDrive *drive;
845
 
        GConfClient *client;
846
 
        GConfValue *value;
847
 
        guint64 rate;
848
 
        gchar *path;
849
 
        gchar *key;
850
 
 
851
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
852
 
 
853
 
        brasero_burn_session_get_input_type (priv->session, &source);
854
 
        if (source.type == BRASERO_TRACK_TYPE_NONE) {
855
 
                g_signal_emit (self,
856
 
                               brasero_dest_selection_signals [VALID_MEDIA_SIGNAL],
857
 
                               0,
858
 
                               FALSE);
859
 
                gtk_widget_set_sensitive (priv->button, FALSE);
860
 
                gtk_widget_set_sensitive (priv->copies_box, FALSE);
861
 
                return;
862
 
        }
863
 
 
864
 
        if (brasero_burn_session_is_dest_file (priv->session)) {
865
 
                BraseroBurnResult result;
866
 
 
867
 
                result = brasero_burn_caps_is_session_supported (priv->caps, priv->session);
868
 
                g_signal_emit (self,
869
 
                               brasero_dest_selection_signals [VALID_MEDIA_SIGNAL],
870
 
                               0,
871
 
                               (result == BRASERO_BURN_OK));
872
 
 
873
 
                gtk_widget_set_sensitive (priv->button, (result == BRASERO_BURN_OK));
874
 
                return;
875
 
        }
876
 
 
877
 
        drive = brasero_burn_session_get_burner (priv->session);
878
 
        if (!drive) {
879
 
                g_signal_emit (self,
880
 
                               brasero_dest_selection_signals [VALID_MEDIA_SIGNAL],
881
 
                               0,
882
 
                               FALSE);
883
 
                gtk_widget_set_sensitive (priv->button, FALSE);
884
 
                gtk_widget_set_sensitive (priv->copies_box, FALSE);
885
 
                return;
886
 
        }
887
 
 
888
 
        medium = brasero_drive_get_medium (drive);
889
 
        if (!medium || brasero_medium_get_status (medium) == BRASERO_MEDIUM_NONE) {
890
 
                g_signal_emit (self,
891
 
                               brasero_dest_selection_signals [VALID_MEDIA_SIGNAL],
892
 
                               0,
893
 
                               FALSE);
894
 
                gtk_widget_set_sensitive (priv->button, FALSE);
895
 
                gtk_widget_set_sensitive (priv->copies_box, FALSE);
896
 
                return;
897
 
        }
898
 
 
899
 
        /* update/set the rate */
900
 
        client = gconf_client_get_default ();
901
 
 
902
 
        key = brasero_burn_session_get_config_key (priv->session, "speed");
903
 
        if (!key) {
904
 
                g_object_unref (client);
905
 
                return;
906
 
        }
907
 
 
908
 
        value = gconf_client_get_without_default (client, key, NULL);
909
 
        g_free (key);
910
 
 
911
 
        if (!value)
912
 
                rate = brasero_medium_get_max_write_speed (medium);
913
 
        else {
914
 
                rate = gconf_value_get_int (value) * 1024;
915
 
                gconf_value_free (value);
916
 
        }
917
 
 
918
 
        brasero_burn_session_set_rate (priv->session, rate);
919
 
 
920
 
        /* do the same with the flags.
921
 
         * NOTE: every time we add a flag we have to re-ask for supported flags.
922
 
         * Indeed two flags could be mutually exclusive and then adding both at
923
 
         * the same would make the session unusable (MULTI and BLANK_BEFORE_WRITE) */
924
 
        key = brasero_burn_session_get_config_key (priv->session, "flags");
925
 
        if (!key) {
926
 
                g_object_unref (client);
927
 
                return;
928
 
        }
929
 
 
930
 
        value = gconf_client_get_without_default (client, key, NULL);
931
 
        g_free (key);
932
 
 
933
 
        if (brasero_dest_selection_check_same_src_dest (self)) {
934
 
                BraseroBurnFlag supported = BRASERO_BURN_FLAG_NONE;
935
 
                BraseroBurnFlag compulsory = BRASERO_BURN_FLAG_NONE;
936
 
 
937
 
                /* Special case */
938
 
 
939
 
                /* wipe out previous flags */
940
 
                brasero_burn_session_remove_flag (priv->session,
941
 
                                                  BRASERO_DRIVE_PROPERTIES_FLAGS);
942
 
 
943
 
                /* set new ones */
944
 
                if (value) {
945
 
                        flags = gconf_value_get_int (value) & BRASERO_DEST_SAVED_FLAGS;
946
 
                        gconf_value_free (value);
947
 
                }
948
 
                else
949
 
                        flags = BRASERO_BURN_FLAG_EJECT|
950
 
                                BRASERO_BURN_FLAG_BURNPROOF;
951
 
 
952
 
                brasero_dest_selection_add_drive_properties_flags (self,
953
 
                                                                   flags|
954
 
                                                                   BRASERO_BURN_FLAG_BLANK_BEFORE_WRITE|
955
 
                                                                   BRASERO_BURN_FLAG_FAST_BLANK,
956
 
                                                                   &supported,
957
 
                                                                   &compulsory);
958
 
 
959
 
                /* NOTE: of course NO_TMP is not possible; DAO and BLANK_BEFORE
960
 
                 * could be yet. The problem here is that we cannot test all
961
 
                 * this since we don't know yet what the disc type is going to 
962
 
                 * be. So we set DAO and BLANK_BEFORE_WRITE just in case.
963
 
                 * Hopefully burn.c will be able to handle that later. */
964
 
        }
965
 
        else if (!value) {
966
 
                BraseroBurnFlag supported = BRASERO_BURN_FLAG_NONE;
967
 
                BraseroBurnFlag compulsory = BRASERO_BURN_FLAG_NONE;
968
 
 
969
 
                flags = BRASERO_BURN_FLAG_EJECT|
970
 
                        BRASERO_BURN_FLAG_BURNPROOF;
971
 
 
972
 
                if (source.type == BRASERO_TRACK_TYPE_DATA
973
 
                ||  source.type == BRASERO_TRACK_TYPE_DISC
974
 
                ||  source.type == BRASERO_TRACK_TYPE_IMAGE)
975
 
                        flags |= BRASERO_BURN_FLAG_NO_TMP_FILES;
976
 
 
977
 
                brasero_dest_selection_add_drive_properties_flags (self,
978
 
                                                                   flags,
979
 
                                                                   &supported,
980
 
                                                                   &compulsory);
981
 
        }
982
 
        else {
983
 
                BraseroBurnFlag supported = BRASERO_BURN_FLAG_NONE;
984
 
                BraseroBurnFlag compulsory = BRASERO_BURN_FLAG_NONE;
985
 
 
986
 
                /* set the saved flags (make sure they are supported) */
987
 
                flags = gconf_value_get_int (value) & BRASERO_DEST_SAVED_FLAGS;
988
 
                gconf_value_free (value);
989
 
 
990
 
                brasero_dest_selection_add_drive_properties_flags (self,
991
 
                                                                   flags,
992
 
                                                                   &supported,
993
 
                                                                   &compulsory);
994
 
        }
995
 
 
996
 
        /* Now that we updated the session flags see if everything works */
997
 
        is_valid = brasero_burn_caps_is_session_supported (priv->caps, priv->session);
998
 
        g_signal_emit (self,
999
 
                       brasero_dest_selection_signals [VALID_MEDIA_SIGNAL],
1000
 
                       0,
1001
 
                       (is_valid == BRASERO_BURN_OK));
1002
 
 
1003
 
        gtk_widget_set_sensitive (priv->copies_box, (is_valid == BRASERO_BURN_OK));
1004
 
        gtk_widget_set_sensitive (priv->button, (is_valid == BRASERO_BURN_OK));
1005
 
 
1006
 
        key = g_strdup_printf ("%s/tmpdir", BRASERO_DRIVE_PROPERTIES_KEY);
1007
 
        path = gconf_client_get_string (client, key, NULL);
1008
 
        brasero_burn_session_set_tmpdir (priv->session, path);
1009
 
        g_free (path);
1010
 
        g_free (key);
1011
 
 
1012
 
        g_object_unref (client);
1013
 
}
1014
 
 
1015
 
static void
1016
 
brasero_dest_selection_set_image_properties (BraseroDestSelection *self)
1017
 
{
1018
 
        BraseroDestSelectionPrivate *priv;
1019
 
        BraseroBurnResult result;
1020
 
        BraseroTrackType output;
1021
 
        gchar *path;
1022
 
 
1023
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
1024
 
        priv->default_format = TRUE;
1025
 
        priv->default_path = TRUE;
1026
 
 
1027
 
        /* apparently nothing has been set yet so give a default location */
1028
 
        brasero_dest_selection_get_default_output_format (self, &output);
1029
 
 
1030
 
        if (output.type == BRASERO_TRACK_TYPE_NONE
1031
 
        ||  output.subtype.img_format == BRASERO_IMAGE_FORMAT_NONE) {
1032
 
                /* That means that we've got a problem */
1033
 
                /* FIXME: we need to display a message nevertheless */
1034
 
                brasero_burn_session_set_image_output_full (priv->session,
1035
 
                                                            BRASERO_IMAGE_FORMAT_NONE,
1036
 
                                                            NULL,
1037
 
                                                            NULL);
1038
 
                g_signal_emit (self,
1039
 
                               brasero_dest_selection_signals [VALID_MEDIA_SIGNAL],
1040
 
                               0,
1041
 
                               FALSE);
1042
 
 
1043
 
                gtk_widget_set_sensitive (priv->button, FALSE);
1044
 
                return;
1045
 
        }
1046
 
 
1047
 
        path = brasero_dest_selection_get_default_output_path (self, output.subtype.img_format);
1048
 
        g_signal_emit (self,
1049
 
                       brasero_dest_selection_signals [VALID_MEDIA_SIGNAL],
1050
 
                       0,
1051
 
                       TRUE);
1052
 
        gtk_widget_set_sensitive (priv->button, TRUE);
1053
 
        brasero_dest_selection_set_output_path (self,
1054
 
                                                output.subtype.img_format,
1055
 
                                                path);
1056
 
        brasero_drive_info_set_image_path (BRASERO_DRIVE_INFO (priv->info), path);
1057
 
        g_free (path);
1058
 
 
1059
 
        brasero_burn_session_remove_flag (priv->session,
1060
 
                                          BRASERO_BURN_FLAG_DUMMY|
1061
 
                                          BRASERO_BURN_FLAG_NO_TMP_FILES);
1062
 
 
1063
 
        result = brasero_burn_caps_is_session_supported (priv->caps, priv->session);
1064
 
        g_signal_emit (self,
1065
 
                       brasero_dest_selection_signals [VALID_MEDIA_SIGNAL],
1066
 
                       0,
1067
 
                       (result == BRASERO_BURN_OK));
1068
 
        gtk_widget_set_sensitive (priv->button, (result == BRASERO_BURN_OK));
1069
 
}
1070
 
 
1071
 
static void
1072
 
brasero_dest_selection_check_image_settings (BraseroDestSelection *self)
1073
 
{
1074
 
        BraseroDestSelectionPrivate *priv;
1075
 
        BraseroBurnResult result;
1076
 
 
1077
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
1078
 
 
1079
 
        if (brasero_burn_session_get_output (priv->session, NULL, NULL, NULL) == BRASERO_BURN_OK) {
1080
 
                gchar *path;
1081
 
                BraseroTrackType output;
1082
 
                BraseroImageFormat format;
1083
 
 
1084
 
                /* we already have an output check its validity */
1085
 
                output.type = BRASERO_TRACK_TYPE_IMAGE;
1086
 
 
1087
 
                if (!priv->default_format) {
1088
 
                        /* The user set a format */
1089
 
                        output.subtype.img_format = brasero_burn_session_get_output_format (priv->session);
1090
 
 
1091
 
                        /* check that the format is still supported. If not then find a good default */
1092
 
                        result = brasero_burn_caps_is_output_supported (priv->caps,
1093
 
                                                                        priv->session,
1094
 
                                                                        &output);
1095
 
                        if (result != BRASERO_BURN_OK) {
1096
 
                                priv->default_format = TRUE;
1097
 
                                brasero_dest_selection_get_default_output_format (self, &output);
1098
 
                        }
1099
 
                }
1100
 
                else /* retrieve a possible better default format */
1101
 
                        brasero_dest_selection_get_default_output_format (self, &output);
1102
 
 
1103
 
                format = output.subtype.img_format;
1104
 
                g_signal_emit (self,
1105
 
                               brasero_dest_selection_signals [VALID_MEDIA_SIGNAL],
1106
 
                               0,
1107
 
                               (format != BRASERO_IMAGE_FORMAT_NONE));
1108
 
 
1109
 
                if (priv->button)
1110
 
                        gtk_widget_set_sensitive (priv->button, (format != BRASERO_IMAGE_FORMAT_NONE));
1111
 
 
1112
 
                if (format == BRASERO_IMAGE_FORMAT_NONE) {
1113
 
                        /* FIXME: we've got a problem and it's not possible,
1114
 
                         * display a message to say so */
1115
 
                        if (priv->drive_prop) {
1116
 
                                gtk_widget_destroy (priv->drive_prop);
1117
 
                                priv->drive_prop = NULL;
1118
 
                        }
1119
 
 
1120
 
                        return;
1121
 
                }
1122
 
 
1123
 
                if (!priv->default_path) {
1124
 
                        /* check that the extension is ok if not update it */
1125
 
                        path = brasero_dest_selection_get_output_path (self);
1126
 
                        if (priv->default_ext
1127
 
                        &&  brasero_dest_selection_image_check_extension (self, format, path))
1128
 
                                path = brasero_dest_selection_fix_image_extension (format, TRUE, path);
1129
 
                }
1130
 
                else
1131
 
                        path = brasero_dest_selection_get_default_output_path (self, format);
1132
 
 
1133
 
                brasero_dest_selection_set_output_path (self,
1134
 
                                                        format,
1135
 
                                                        path);
1136
 
                brasero_drive_info_set_image_path (BRASERO_DRIVE_INFO (priv->info), path);
1137
 
                g_free (path);
1138
 
        }
1139
 
        else
1140
 
                brasero_dest_selection_set_image_properties (self);
1141
 
 
1142
 
        if (priv->drive_prop) {
1143
 
                BraseroImageFormat formats;
1144
 
                guint num;
1145
 
 
1146
 
                /* update image settings dialog if needed */
1147
 
                num = brasero_dest_selection_get_possible_output_formats (self, &formats);
1148
 
                brasero_image_properties_set_formats (BRASERO_IMAGE_PROPERTIES (priv->drive_prop),
1149
 
                                                      num > 1 ? formats:BRASERO_IMAGE_FORMAT_NONE,
1150
 
                                                      BRASERO_IMAGE_FORMAT_ANY);
1151
 
        }
1152
 
 
1153
 
        brasero_burn_session_remove_flag (priv->session, BRASERO_BURN_FLAG_DUMMY);
1154
 
 
1155
 
        result = brasero_burn_caps_is_session_supported (priv->caps, priv->session);
1156
 
        g_signal_emit (self,
1157
 
                       brasero_dest_selection_signals [VALID_MEDIA_SIGNAL],
1158
 
                       0,
1159
 
                       (result == BRASERO_BURN_OK));
1160
 
        gtk_widget_set_sensitive (priv->button, (result == BRASERO_BURN_OK));
1161
 
}
1162
 
 
1163
 
static void
1164
 
brasero_dest_selection_check_drive_settings (BraseroDestSelection *self)
1165
 
{
1166
 
        BraseroBurnFlag compulsory = BRASERO_BURN_FLAG_NONE;
1167
 
        BraseroBurnFlag supported = BRASERO_BURN_FLAG_NONE;
1168
 
        BraseroDestSelectionPrivate *priv;
1169
 
        BraseroBurnResult result;
1170
 
        BraseroBurnFlag flags;
1171
 
 
1172
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
1173
 
 
1174
 
        /* Update the flags and save them */
1175
 
        if (brasero_dest_selection_check_same_src_dest (self)) {
1176
 
                /* These are always set in any case and there is no way to check
1177
 
                 * the current flags */
1178
 
                brasero_dest_selection_add_drive_properties_flags (self,
1179
 
                                                                   BRASERO_BURN_FLAG_BLANK_BEFORE_WRITE|
1180
 
                                                                   BRASERO_BURN_FLAG_FAST_BLANK,
1181
 
                                                                   &supported,
1182
 
                                                                   &compulsory);
1183
 
        }
1184
 
        else {
1185
 
                /* Try to properly update the flags for the current drive */
1186
 
                flags = brasero_burn_session_get_flags (priv->session);
1187
 
 
1188
 
                /* check each flag before re-adding it */
1189
 
                brasero_dest_selection_add_drive_properties_flags (self,
1190
 
                                                                   flags,
1191
 
                                                                   &supported,
1192
 
                                                                   &compulsory);
1193
 
        }
1194
 
 
1195
 
        /* NOTE: we save even if result != BRASERO_BURN_OK. That way if a flag
1196
 
         * is no longer supported after the removal of a plugin then the 
1197
 
         * properties are reset and the user can access them again */
1198
 
 
1199
 
        /* save potential changes for the new profile */
1200
 
        brasero_dest_selection_save_drive_properties (self);
1201
 
 
1202
 
        if (priv->drive_prop) {
1203
 
                /* the dialog may need to be updated */
1204
 
                brasero_drive_properties_set_flags (BRASERO_DRIVE_PROPERTIES (priv->drive_prop),
1205
 
                                                    flags,
1206
 
                                                    supported,
1207
 
                                                    compulsory);
1208
 
        }
1209
 
 
1210
 
        /* Once we've updated the flags, send a signal to tell whether we
1211
 
         * support this disc or not. Update everything. */
1212
 
        result = brasero_burn_caps_is_session_supported (priv->caps, priv->session);
1213
 
        g_signal_emit (self,
1214
 
                       brasero_dest_selection_signals [VALID_MEDIA_SIGNAL],
1215
 
                       0,
1216
 
                       (result == BRASERO_BURN_OK));
1217
 
 
1218
 
        if (priv->button)
1219
 
                gtk_widget_set_sensitive (priv->button, (result == BRASERO_BURN_OK));
1220
 
 
1221
 
        gtk_widget_set_sensitive (priv->copies_box, (result == BRASERO_BURN_OK));
1222
 
}
1223
 
 
1224
 
static void
1225
 
brasero_dest_selection_source_changed (BraseroBurnSession *session,
1226
 
                                       BraseroDestSelection *self)
1227
 
{
1228
 
        BraseroDestSelectionPrivate *priv;
1229
 
 
1230
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
1231
 
 
1232
 
        brasero_drive_info_set_same_src_dest (BRASERO_DRIVE_INFO (priv->info),
1233
 
                                              brasero_burn_session_same_src_dest_drive (priv->session));
1234
 
 
1235
 
        if (brasero_burn_session_is_dest_file (priv->session)) {
1236
 
                /* check that if a path was set there may be none if there was
1237
 
                 * no disc inserted when the dialog was created. */
1238
 
                if (brasero_burn_session_get_output (priv->session, NULL, NULL, NULL) != BRASERO_BURN_OK)
1239
 
                        brasero_dest_selection_set_image_properties (self);
1240
 
                else
1241
 
                        brasero_dest_selection_check_image_settings (self);
1242
 
 
1243
 
                return;
1244
 
        }
1245
 
 
1246
 
        brasero_dest_selection_set_drive_properties (self);
1247
 
}
1248
 
 
1249
 
static void
1250
 
brasero_dest_selection_caps_changed (BraseroPluginManager *manager,
1251
 
                                     BraseroDestSelection *self)
1252
 
{
1253
 
        BraseroDestSelectionPrivate *priv;
1254
 
 
1255
 
        /* In this case we are still in the same context (same src, dest) so we
1256
 
         * check that all current flags and such are still valid */
1257
 
 
1258
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
1259
 
 
1260
 
        /* The caps of the library / the source have changed so we must check:
1261
 
         * if it's an image that the output type is still possible
1262
 
         * if it's a drive that all flags are still supported and that the media is too */
1263
 
        if (brasero_burn_session_is_dest_file (priv->session))
1264
 
                brasero_dest_selection_check_image_settings (self);
1265
 
        else
1266
 
                brasero_dest_selection_check_drive_settings (self);
1267
 
}
1268
 
 
1269
 
static void
1270
 
brasero_dest_selection_output_changed (BraseroBurnSession *session,
1271
 
                                       BraseroDestSelection *self)
 
76
G_DEFINE_TYPE (BraseroDestSelection, brasero_dest_selection, BRASERO_TYPE_MEDIUM_SELECTION);
 
77
 
 
78
 
 
79
void
 
80
brasero_dest_selection_lock (BraseroDestSelection *self,
 
81
                             gboolean locked)
 
82
{
 
83
        BraseroDestSelectionPrivate *priv;
 
84
 
 
85
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
 
86
 
 
87
        gtk_widget_set_sensitive (GTK_WIDGET (self), (locked != TRUE));
 
88
 
 
89
        gtk_widget_queue_draw (GTK_WIDGET (self));
 
90
        if (priv->locked_drive) {
 
91
                brasero_drive_unlock (priv->locked_drive);
 
92
                g_object_unref (priv->locked_drive);
 
93
        }
 
94
 
 
95
        if (locked) {
 
96
                BraseroDrive *drive;
 
97
 
 
98
                drive = brasero_medium_selection_get_active_drive (BRASERO_MEDIUM_SELECTION (self));
 
99
                priv->locked_drive = drive;
 
100
 
 
101
                if (priv->locked_drive)
 
102
                        brasero_drive_lock (priv->locked_drive,
 
103
                                            _("ongoing burning process"),
 
104
                                            NULL);
 
105
        }
 
106
}
 
107
 
 
108
static void
 
109
brasero_dest_selection_valid_session (BraseroSessionCfg *session,
 
110
                                      BraseroDestSelection *self)
1272
111
{
1273
112
        BraseroDestSelectionPrivate *priv;
1274
113
        BraseroDrive *burner;
1278
117
 
1279
118
        /* make sure the current displayed drive reflects that */
1280
119
        burner = brasero_burn_session_get_burner (priv->session);
1281
 
        drive = brasero_drive_selection_get_drive (BRASERO_DRIVE_SELECTION (self));
 
120
        drive = brasero_medium_selection_get_active_drive (BRASERO_MEDIUM_SELECTION (self));
1282
121
        if (burner != drive) {
1283
 
                brasero_drive_selection_set_drive (BRASERO_DRIVE_SELECTION (self), drive);
 
122
                BraseroMedium *medium;
1284
123
 
1285
 
                if (priv->drive_prop) {
1286
 
                        /* cancel the drive properties dialog as it's not the same drive */
1287
 
                        gtk_dialog_response (GTK_DIALOG (priv->drive_prop), GTK_RESPONSE_CANCEL);
1288
 
                }
 
124
                medium = brasero_drive_get_medium (drive);
 
125
                brasero_medium_selection_set_active (BRASERO_MEDIUM_SELECTION (self), medium);
1289
126
        }
1290
127
 
1291
128
        if (drive)
1292
129
                g_object_unref (drive);
1293
130
 
1294
 
        if (!burner) {
1295
 
                brasero_dest_selection_set_drive_properties (self);
1296
 
                return;
1297
 
        }
1298
 
 
1299
 
        if (!brasero_drive_is_fake (burner)) {
1300
 
                gint numcopies;
1301
 
 
1302
 
                brasero_dest_selection_set_drive_properties (self);
1303
 
 
1304
 
                numcopies = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (priv->copies_spin));
1305
 
                brasero_burn_session_set_num_copies (priv->session, numcopies);
1306
 
                gtk_widget_show (priv->copies_box);
1307
 
        }
1308
 
        else {
1309
 
                gtk_widget_hide (priv->copies_box);
1310
 
                brasero_burn_session_set_num_copies (priv->session, 1);
1311
 
 
1312
 
                /* Make sure there is an output path/type in case that's an image;
1313
 
                 * if not, set default ones */
1314
 
                if (brasero_burn_session_get_output (priv->session, NULL, NULL, NULL) != BRASERO_BURN_OK)
1315
 
                        brasero_dest_selection_set_image_properties (self);
1316
 
                else
1317
 
                        brasero_dest_selection_check_image_settings (self);
1318
 
        }
 
131
        brasero_medium_selection_update_media_string (BRASERO_MEDIUM_SELECTION (self));
1319
132
}
1320
133
 
1321
134
static void
1322
 
brasero_dest_selection_drive_changed (BraseroDriveSelection *selection,
1323
 
                                      BraseroDrive *drive)
 
135
brasero_dest_selection_medium_changed (GtkComboBox *combo)
1324
136
{
1325
137
        BraseroDestSelectionPrivate *priv;
1326
 
 
1327
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (selection);
1328
 
 
1329
 
        brasero_drive_info_set_medium (BRASERO_DRIVE_INFO (priv->info),
1330
 
                                       brasero_drive_get_medium (drive));
1331
 
 
1332
 
 
 
138
        BraseroDrive *drive;
 
139
 
 
140
        priv = BRASERO_DEST_SELECTION_PRIVATE (combo);
 
141
 
1333
142
        if (!priv->session)
1334
 
                return;
 
143
                goto chain;
 
144
 
 
145
        drive = brasero_medium_selection_get_active_drive (BRASERO_MEDIUM_SELECTION (combo));
 
146
        if (!drive) {
 
147
                gtk_widget_set_sensitive (GTK_WIDGET (combo), FALSE);
 
148
                goto chain;
 
149
        }
 
150
 
 
151
        if (drive == brasero_burn_session_get_burner (priv->session)) {
 
152
                g_object_unref (drive);
 
153
                goto chain;
 
154
        }
 
155
 
 
156
        if (priv->locked_drive && priv->locked_drive != drive) {
 
157
                brasero_medium_selection_set_active (BRASERO_MEDIUM_SELECTION (combo),
 
158
                                                     brasero_drive_get_medium (priv->locked_drive));
 
159
                goto chain;
 
160
        }
1335
161
 
1336
162
        brasero_burn_session_set_burner (priv->session, drive);
1337
 
 
1338
 
        if (brasero_burn_session_same_src_dest_drive (priv->session))
1339
 
                brasero_drive_info_set_same_src_dest (BRASERO_DRIVE_INFO (priv->info), TRUE);
1340
 
}
1341
 
 
1342
 
static void
1343
 
brasero_dest_selection_copies_num_changed_cb (GtkSpinButton *button,
1344
 
                                              BraseroDestSelection *self)
1345
 
{
1346
 
        gint numcopies;
1347
 
        BraseroDestSelectionPrivate *priv;
1348
 
 
1349
 
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
1350
 
        numcopies = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (priv->copies_spin));
1351
 
        brasero_burn_session_set_num_copies (priv->session, numcopies);
 
163
        gtk_widget_set_sensitive (GTK_WIDGET (combo), (priv->locked_drive == NULL));
 
164
 
 
165
chain:
 
166
 
 
167
        if (GTK_COMBO_BOX_CLASS (brasero_dest_selection_parent_class)->changed)
 
168
                GTK_COMBO_BOX_CLASS (brasero_dest_selection_parent_class)->changed (combo);
1352
169
}
1353
170
 
1354
171
static void
1355
172
brasero_dest_selection_init (BraseroDestSelection *object)
1356
173
{
1357
174
        BraseroDestSelectionPrivate *priv;
1358
 
        BraseroPluginManager *manager;
1359
 
        GtkWidget *label;
1360
175
 
1361
176
        priv = BRASERO_DEST_SELECTION_PRIVATE (object);
1362
177
 
1363
 
        priv->info = brasero_drive_info_new ();
1364
 
        gtk_widget_show (priv->info);
1365
 
        gtk_box_pack_start (GTK_BOX (object),
1366
 
                            priv->info,
1367
 
                            FALSE,
1368
 
                            FALSE,
1369
 
                            0);
1370
 
 
1371
178
        priv->caps = brasero_burn_caps_get_default ();
1372
 
        manager = brasero_plugin_manager_get_default ();
1373
 
        priv->caps_sig = g_signal_connect (manager,
1374
 
                                           "caps-changed",
1375
 
                                           G_CALLBACK (brasero_dest_selection_caps_changed),
1376
 
                                           object);
1377
 
 
1378
 
        priv->button = gtk_button_new_from_stock (GTK_STOCK_PROPERTIES);
1379
 
        gtk_widget_show (priv->button);
1380
 
        gtk_widget_set_tooltip_text (priv->button, _("Configure some options for the recording"));
1381
 
        g_signal_connect (G_OBJECT (priv->button),
1382
 
                          "clicked",
1383
 
                          G_CALLBACK (brasero_dest_selection_properties_button_cb),
1384
 
                          object);
1385
 
 
1386
 
        brasero_drive_selection_set_tooltip (BRASERO_DRIVE_SELECTION (object),
1387
 
                                             _("Choose the disc to write to"));
1388
 
 
1389
 
        brasero_drive_selection_set_button (BRASERO_DRIVE_SELECTION (object),
1390
 
                                            priv->button);
1391
 
 
1392
 
        priv->copies_box = gtk_hbox_new (FALSE, 0);
1393
 
        gtk_widget_show (priv->copies_box);
1394
 
        gtk_box_pack_end (GTK_BOX (object), priv->copies_box, FALSE, FALSE, 0);
1395
 
 
1396
 
        label = gtk_label_new (_("Number of copies "));
1397
 
        gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
1398
 
        gtk_widget_show (label);
1399
 
        gtk_box_pack_start (GTK_BOX (priv->copies_box), label, FALSE, FALSE, 0);
1400
 
 
1401
 
        priv->copies_spin = gtk_spin_button_new_with_range (1.0, 99.0, 1.0);
1402
 
        gtk_widget_show (priv->copies_spin);
1403
 
        gtk_box_pack_start (GTK_BOX (priv->copies_box), priv->copies_spin, FALSE, FALSE, 0);
1404
 
        g_signal_connect (priv->copies_spin,
1405
 
                          "value-changed",
1406
 
                          G_CALLBACK (brasero_dest_selection_copies_num_changed_cb),
1407
 
                          object);
1408
179
 
1409
180
        /* Only show media on which we can write and which are in a burner.
1410
181
         * There is one exception though, when we're copying media and when the
1411
182
         * burning device is the same as the dest device. */
1412
 
        brasero_drive_selection_set_type_shown (BRASERO_DRIVE_SELECTION (object),
1413
 
                                                BRASERO_MEDIA_TYPE_WRITABLE);
1414
 
 
1415
 
        priv->default_ext = TRUE;
1416
 
        priv->default_path = TRUE;
1417
 
        priv->default_format = TRUE;
 
183
        brasero_medium_selection_show_type (BRASERO_MEDIUM_SELECTION (object),
 
184
                                            BRASERO_MEDIA_TYPE_WRITABLE);
1418
185
}
1419
186
 
1420
187
static void
1424
191
 
1425
192
        priv = BRASERO_DEST_SELECTION_PRIVATE (object);
1426
193
 
1427
 
        if (priv->output_sig) {
1428
 
                g_signal_handler_disconnect (priv->session, priv->output_sig);
1429
 
                priv->output_sig = 0;
1430
 
        }
1431
 
 
1432
 
        if (priv->input_sig) {
1433
 
                g_signal_handler_disconnect (priv->session, priv->input_sig);
1434
 
                priv->input_sig = 0;
1435
 
        }
1436
 
 
1437
 
        if (priv->caps_sig) {
1438
 
                BraseroPluginManager *manager;
1439
 
 
1440
 
                manager = brasero_plugin_manager_get_default ();
1441
 
                g_signal_handler_disconnect (manager, priv->caps_sig);
1442
 
                priv->caps_sig = 0;
1443
 
        }
1444
 
 
1445
194
        if (priv->caps) {
1446
195
                g_object_unref (priv->caps);
1447
196
                priv->caps = NULL;
1448
197
        }
1449
198
 
 
199
        if (priv->valid_sig) {
 
200
                g_signal_handler_disconnect (priv->session,
 
201
                                             priv->valid_sig);
 
202
                priv->valid_sig = 0;
 
203
        }
 
204
 
1450
205
        if (priv->session) {
1451
206
                g_object_unref (priv->session);
1452
207
                priv->session = NULL;
1453
208
        }
1454
209
 
1455
 
        G_OBJECT_CLASS (parent_class)->finalize (object);
 
210
        if (priv->locked_drive) {
 
211
                brasero_drive_unlock (priv->locked_drive);
 
212
                g_object_unref (priv->locked_drive);
 
213
        }
 
214
 
 
215
        G_OBJECT_CLASS (brasero_dest_selection_parent_class)->finalize (object);
 
216
}
 
217
 
 
218
static gboolean
 
219
brasero_dest_selection_foreach_medium (BraseroMedium *medium,
 
220
                                       gpointer callback_data)
 
221
{
 
222
        BraseroBurnSession *session;
 
223
        BraseroDrive *burner;
 
224
 
 
225
        session = callback_data;
 
226
        burner = brasero_burn_session_get_burner (session);
 
227
 
 
228
        if (!burner) {
 
229
                brasero_burn_session_set_burner (session, brasero_medium_get_drive (medium));
 
230
                return TRUE;
 
231
        }
 
232
 
 
233
        /* no need to deal with this case */
 
234
        if (brasero_drive_get_medium (burner) == medium)
 
235
                return TRUE;
 
236
 
 
237
        /* The rule is:
 
238
         * - take the biggest
 
239
         * - blank media are our favourite
 
240
         * - try to avoid a medium that is already our source for copying */
 
241
 
 
242
        /* NOTE: we could check if medium is bigger */
 
243
        if (brasero_burn_session_get_dest_media (session) & BRASERO_MEDIUM_BLANK)
 
244
                return TRUE;
 
245
 
 
246
        if (brasero_medium_get_status (medium) & BRASERO_MEDIUM_BLANK) {
 
247
                brasero_burn_session_set_burner (session, brasero_medium_get_drive (medium));
 
248
                return TRUE;
 
249
        }
 
250
        if (brasero_burn_session_same_src_dest_drive (session)) {
 
251
                brasero_burn_session_set_burner (session, brasero_medium_get_drive (medium));
 
252
                return TRUE;
 
253
        }
 
254
 
 
255
        return TRUE;
 
256
}
 
257
 
 
258
void
 
259
brasero_dest_selection_choose_best (BraseroDestSelection *self)
 
260
{
 
261
        BraseroDestSelectionPrivate *priv;
 
262
 
 
263
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
 
264
        if (!(brasero_burn_session_get_flags (priv->session) & BRASERO_BURN_FLAG_MERGE)) {
 
265
                BraseroDrive *drive;
 
266
 
 
267
                /* Select the best fitting media */
 
268
                brasero_medium_selection_foreach (BRASERO_MEDIUM_SELECTION (self),
 
269
                                                  brasero_dest_selection_foreach_medium,
 
270
                                                  priv->session);
 
271
 
 
272
                drive = brasero_burn_session_get_burner (BRASERO_BURN_SESSION (priv->session));
 
273
                if (drive)
 
274
                        brasero_medium_selection_set_active (BRASERO_MEDIUM_SELECTION (self),
 
275
                                                             brasero_drive_get_medium (drive));
 
276
        }
1456
277
}
1457
278
 
1458
279
static void
1479
300
                priv->session = session;
1480
301
                g_object_ref (session);
1481
302
 
1482
 
                drive = brasero_drive_selection_get_drive (BRASERO_DRIVE_SELECTION (object));
1483
 
                brasero_burn_session_set_burner (session, drive);
1484
 
 
1485
 
                if (drive)
1486
 
                        g_object_unref (drive);
1487
 
 
1488
 
                brasero_drive_info_set_same_src_dest (BRASERO_DRIVE_INFO (priv->info),
1489
 
                                                      brasero_burn_session_same_src_dest_drive (priv->session));
1490
 
 
1491
 
                /* NOTE: there is no need for the following as we don't know the
1492
 
                 * track type yet. Better wait for the track to be set */
1493
 
                /* if (brasero_burn_session_is_dest_file (session))
1494
 
                        brasero_dest_selection_set_image_properties (BRASERO_DEST_SELECTION (object));
1495
 
                else
1496
 
                        brasero_dest_selection_set_drive_properties (BRASERO_DEST_SELECTION (object));
1497
 
                */
1498
 
 
1499
 
                priv->input_sig = g_signal_connect (session,
1500
 
                                                    "input-changed",
1501
 
                                                    G_CALLBACK (brasero_dest_selection_source_changed),
 
303
                if (brasero_burn_session_get_flags (session) & BRASERO_BURN_FLAG_MERGE) {
 
304
                        drive = brasero_burn_session_get_burner (session);
 
305
                        brasero_medium_selection_set_active (BRASERO_MEDIUM_SELECTION (object),
 
306
                                                             brasero_drive_get_medium (drive));
 
307
                }
 
308
                else {
 
309
                        drive = brasero_medium_selection_get_active_drive (BRASERO_MEDIUM_SELECTION (object));
 
310
                        if (drive) {
 
311
                                brasero_burn_session_set_burner (session, drive);
 
312
                                g_object_unref (drive);
 
313
                        }
 
314
                }
 
315
 
 
316
                priv->valid_sig = g_signal_connect (session,
 
317
                                                    "is-valid",
 
318
                                                    G_CALLBACK (brasero_dest_selection_valid_session),
1502
319
                                                    object);
1503
 
                priv->output_sig = g_signal_connect (session,
1504
 
                                                     "output-changed",
1505
 
                                                     G_CALLBACK (brasero_dest_selection_output_changed),
1506
 
                                                     object);
 
320
 
 
321
                brasero_medium_selection_update_media_string (BRASERO_MEDIUM_SELECTION (object));
1507
322
                break;
1508
323
 
1509
324
        default:
1531
346
        }
1532
347
}
1533
348
 
 
349
static gchar *
 
350
brasero_dest_selection_get_output_path (BraseroDestSelection *self)
 
351
{
 
352
        gchar *path = NULL;
 
353
        BraseroImageFormat format;
 
354
        BraseroDestSelectionPrivate *priv;
 
355
 
 
356
        priv = BRASERO_DEST_SELECTION_PRIVATE (self);
 
357
 
 
358
        format = brasero_burn_session_get_output_format (priv->session);
 
359
        switch (format) {
 
360
        case BRASERO_IMAGE_FORMAT_BIN:
 
361
                brasero_burn_session_get_output (priv->session,
 
362
                                                 &path,
 
363
                                                 NULL,
 
364
                                                 NULL);
 
365
                break;
 
366
 
 
367
        case BRASERO_IMAGE_FORMAT_CLONE:
 
368
                brasero_burn_session_get_output (priv->session,
 
369
                                                 NULL,
 
370
                                                 &path,
 
371
                                                 NULL);
 
372
                break;
 
373
 
 
374
        case BRASERO_IMAGE_FORMAT_CDRDAO:
 
375
                brasero_burn_session_get_output (priv->session,
 
376
                                                 NULL,
 
377
                                                 &path,
 
378
                                                 NULL);
 
379
                break;
 
380
 
 
381
        case BRASERO_IMAGE_FORMAT_CUE:
 
382
                brasero_burn_session_get_output (priv->session,
 
383
                                                 NULL,
 
384
                                                 &path,
 
385
                                                 NULL);
 
386
                break;
 
387
 
 
388
        default:
 
389
                break;
 
390
        }
 
391
 
 
392
        return path;
 
393
}
 
394
 
 
395
static gchar *
 
396
brasero_dest_selection_format_medium_string (BraseroMediumSelection *selection,
 
397
                                             BraseroMedium *medium)
 
398
{
 
399
        gchar *label;
 
400
        gint64 size = 0;
 
401
        gchar *medium_name;
 
402
        gchar *size_string;
 
403
        BraseroMedia media;
 
404
        BraseroBurnFlag flags;
 
405
        BraseroTrackType input = { 0, };
 
406
        BraseroDestSelectionPrivate *priv;
 
407
 
 
408
        priv = BRASERO_DEST_SELECTION_PRIVATE (selection);
 
409
 
 
410
        medium_name = brasero_volume_get_name (BRASERO_VOLUME (medium));
 
411
        if (brasero_medium_get_status (medium) & BRASERO_MEDIUM_FILE) {
 
412
                gchar *path;
 
413
 
 
414
                /* get the set path for the image file */
 
415
                path = brasero_dest_selection_get_output_path (BRASERO_DEST_SELECTION (selection));
 
416
                if (!path)
 
417
                        return medium_name;
 
418
 
 
419
                /* NOTE for translators: the first %s is medium_name ("File
 
420
                 * Image") and the second the path for the image file */
 
421
                label = g_strdup_printf (_("%s: \"%s\""),
 
422
                                         medium_name,
 
423
                                         path);
 
424
                g_free (medium_name);
 
425
                g_free (path);
 
426
                return label;
 
427
        }
 
428
 
 
429
        if (!priv->session) {
 
430
                g_free (medium_name);
 
431
                return NULL;
 
432
        }
 
433
 
 
434
        brasero_burn_session_get_input_type (priv->session, &input);
 
435
        if (input.type == BRASERO_TRACK_TYPE_DISC) {
 
436
                BraseroMedium *src_medium;
 
437
 
 
438
                src_medium = brasero_burn_session_get_src_medium (priv->session);
 
439
                if (src_medium == medium) {
 
440
                        /* Translators: this string is only used when the user
 
441
                         * wants to copy a disc using the same destination and
 
442
                         * source drive. It tells him that brasero will use as
 
443
                         * destination disc a new one (once the source has been
 
444
                         * copied) which is to be inserted in the drive currently
 
445
                         * holding the source disc */
 
446
                        label = g_strdup_printf (_("New disc in burner holding source medium"));
 
447
                        g_free (medium_name);
 
448
                        return label;
 
449
                }
 
450
        }
 
451
 
 
452
        media = brasero_medium_get_status (medium);
 
453
        flags = brasero_burn_session_get_flags (priv->session);
 
454
 
 
455
        if ((media & BRASERO_MEDIUM_BLANK)
 
456
        || ((flags & BRASERO_BURN_FLAG_BLANK_BEFORE_WRITE)
 
457
        &&  brasero_burn_caps_can_blank (priv->caps, priv->session) == BRASERO_BURN_OK)) {
 
458
                brasero_medium_get_capacity (medium,
 
459
                                             &size,
 
460
                                             NULL);
 
461
        }
 
462
        else if (flags & (BRASERO_BURN_FLAG_MERGE|BRASERO_BURN_FLAG_APPEND)) {
 
463
                brasero_medium_get_free_space (medium,
 
464
                                               &size,
 
465
                                               NULL);
 
466
        }
 
467
        else if (media & BRASERO_MEDIUM_CLOSED) {
 
468
                /* NOTE for translators, the first %s is the medium name */
 
469
                label = g_strdup_printf (_("%s: no free space"), medium_name);
 
470
                g_free (medium_name);
 
471
                return label;
 
472
        }
 
473
        else {
 
474
                brasero_medium_get_capacity (medium,
 
475
                                             &size,
 
476
                                             NULL);
 
477
        }
 
478
 
 
479
        /* format the size */
 
480
        if (input.type == BRASERO_TRACK_TYPE_AUDIO
 
481
        || (input.type == BRASERO_TRACK_TYPE_DISC
 
482
        && (input.subtype.media & BRASERO_MEDIUM_HAS_AUDIO)))
 
483
                size_string = brasero_utils_get_time_string_from_size (size,
 
484
                                                                       TRUE,
 
485
                                                                       TRUE);
 
486
        else
 
487
                size_string = g_format_size_for_display (size);
 
488
 
 
489
        /* NOTE for translators: the first %s is the medium name, the second %s
 
490
         * is its available free space. "Free" here is the free space available. */
 
491
        label = g_strdup_printf (_("%s: %s of free space"), medium_name, size_string);
 
492
        g_free (medium_name);
 
493
        g_free (size_string);
 
494
 
 
495
        return label;
 
496
}
 
497
 
1534
498
static void
1535
499
brasero_dest_selection_class_init (BraseroDestSelectionClass *klass)
1536
500
{
1537
501
        GObjectClass* object_class = G_OBJECT_CLASS (klass);
1538
 
        BraseroDriveSelectionClass *select_class = BRASERO_DRIVE_SELECTION_CLASS (klass);
1539
 
 
1540
 
        parent_class = BRASERO_DRIVE_SELECTION_CLASS (g_type_class_peek_parent (klass));
 
502
        GtkComboBoxClass *combo_box_class = GTK_COMBO_BOX_CLASS (klass);
 
503
        BraseroMediumSelectionClass *medium_selection_class = BRASERO_MEDIUM_SELECTION_CLASS (klass);
1541
504
 
1542
505
        g_type_class_add_private (klass, sizeof (BraseroDestSelectionPrivate));
1543
506
 
1545
508
        object_class->set_property = brasero_dest_selection_set_property;
1546
509
        object_class->get_property = brasero_dest_selection_get_property;
1547
510
 
1548
 
        select_class->drive_changed = brasero_dest_selection_drive_changed;
 
511
        combo_box_class->changed = brasero_dest_selection_medium_changed;
1549
512
 
1550
 
        brasero_dest_selection_signals [VALID_MEDIA_SIGNAL] =
1551
 
            g_signal_new ("valid_media",
1552
 
                          G_TYPE_FROM_CLASS (klass),
1553
 
                          G_SIGNAL_RUN_LAST|G_SIGNAL_NO_RECURSE,
1554
 
                          0,
1555
 
                          NULL, NULL,
1556
 
                          g_cclosure_marshal_VOID__BOOLEAN,
1557
 
                          G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
 
513
        medium_selection_class->format_medium_string = brasero_dest_selection_format_medium_string;
1558
514
 
1559
515
        g_object_class_install_property (object_class,
1560
516
                                         PROP_SESSION,
1570
526
{
1571
527
        g_return_val_if_fail (BRASERO_IS_BURN_SESSION (session), NULL);
1572
528
 
1573
 
        return GTK_WIDGET (g_object_new (BRASERO_TYPE_DEST_SELECTION,
1574
 
                                         "session", session,
1575
 
                                         NULL));
 
529
        return g_object_new (BRASERO_TYPE_DEST_SELECTION,
 
530
                             "session", session,
 
531
                             NULL);
1576
532
}