brasero-drive-properties.c 26.4 KB
Newer Older
1 2
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 * Libbrasero-burn
 * Copyright (C) Philippe Rouquier 2005-2009 <bonfire-app@wanadoo.fr>
 *
 * Libbrasero-burn is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The Libbrasero-burn authors hereby grant permission for non-GPL compatible
 * GStreamer plugins to be used and distributed together with GStreamer
 * and Libbrasero-burn. This permission is above and beyond the permissions granted
 * by the GPL license by which Libbrasero-burn is covered. If you modify this code
 * you may extend this exception to your version of the code, but you are not
 * obligated to do so. If you do not wish to do so, delete this exception
 * statement from your version.
18
 * 
19
 * Libbrasero-burn is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
23 24
 * 
 * You should have received a copy of the GNU General Public License
25
 * along with this program; if not, write to:
26 27 28 29 30 31 32 33 34
 * 	The Free Software Foundation, Inc.,
 * 	51 Franklin Street, Fifth Floor
 * 	Boston, MA  02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

35 36
#include <string.h>

37 38 39 40
#include <glib.h>
#include <glib-object.h>
#include <glib/gi18n-lib.h>

41 42
#include <gio/gio.h>

43
#include <gtk/gtk.h>
44

45 46
#include "brasero-medium.h"
#include "brasero-drive.h"
47 48 49 50 51

#include "brasero-misc.h"

#include "burn-basics.h"
#include "burn-debug.h"
52 53 54 55 56
#include "brasero-drive-properties.h"

typedef struct _BraseroDrivePropertiesPrivate BraseroDrivePropertiesPrivate;
struct _BraseroDrivePropertiesPrivate
{
57 58 59 60
	BraseroSessionCfg *session;
	gulong valid_sig;
	gulong output_sig;

61 62
	GtkWidget *speed;
	GtkWidget *dummy;
63
	GtkWidget *multi;
64 65
	GtkWidget *burnproof;
	GtkWidget *notmp;
66 67

	GtkWidget *tmpdir;
68 69 70 71 72
};

#define BRASERO_DRIVE_PROPERTIES_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_DRIVE_PROPERTIES, BraseroDrivePropertiesPrivate))

enum {
73 74 75
	TEXT_COL,
	RATE_COL,
	COL_NUM
76 77
};

78 79 80 81
enum {
	PROP_0,
	PROP_SESSION
};
82

83
G_DEFINE_TYPE (BraseroDriveProperties, brasero_drive_properties, GTK_TYPE_ALIGNMENT);
84

85 86 87
static void
brasero_drive_properties_no_tmp_toggled (GtkToggleButton *button,
					 BraseroDriveProperties *self)
88 89 90 91 92 93 94
{
	BraseroDrivePropertiesPrivate *priv;

	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);

	/* retrieve the flags */
	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->notmp)))
95 96 97 98 99 100
		brasero_session_cfg_add_flags (priv->session,
					       BRASERO_BURN_FLAG_NO_TMP_FILES);
	else
		brasero_session_cfg_remove_flags (priv->session,
						  BRASERO_BURN_FLAG_NO_TMP_FILES);
}
101

102 103 104
static void
brasero_drive_properties_dummy_toggled (GtkToggleButton *button,
					BraseroDriveProperties *self)
105 106 107 108 109
{
	BraseroDrivePropertiesPrivate *priv;

	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);

110 111 112 113 114 115 116 117
	/* retrieve the flags */
	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->dummy)))
		brasero_session_cfg_add_flags (priv->session,
					       BRASERO_BURN_FLAG_DUMMY);
	else
		brasero_session_cfg_remove_flags (priv->session,
						  BRASERO_BURN_FLAG_DUMMY);
}
118

119 120 121 122 123
static void
brasero_drive_properties_burnproof_toggled (GtkToggleButton *button,
					    BraseroDriveProperties *self)
{
	BraseroDrivePropertiesPrivate *priv;
124

125 126 127 128 129 130 131 132 133
	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);

	/* retrieve the flags */
	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->burnproof)))
		brasero_session_cfg_add_flags (priv->session,
					       BRASERO_BURN_FLAG_BURNPROOF);
	else
		brasero_session_cfg_remove_flags (priv->session,
						  BRASERO_BURN_FLAG_BURNPROOF);
134 135
}

136 137 138
static void
brasero_drive_properties_multi_toggled (GtkToggleButton *button,
					BraseroDriveProperties *self)
139 140 141 142
{
	BraseroDrivePropertiesPrivate *priv;

	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);
143 144 145 146 147 148 149 150

	/* retrieve the flags */
	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->multi)))
		brasero_session_cfg_add_flags (priv->session,
					       BRASERO_BURN_FLAG_MULTI);
	else
		brasero_session_cfg_remove_flags (priv->session,
						  BRASERO_BURN_FLAG_MULTI);
151 152
}

153
static void
154
brasero_drive_properties_set_tmpdir_info (BraseroDriveProperties *self,
155
					  const gchar *path)
156
{
157
	GFile *file;
158
	gchar *string;
159
	GFileInfo *info;
160
	gchar *string_size;
161
	guint64 vol_size = 0;
162 163 164 165
	BraseroDrivePropertiesPrivate *priv;

	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);

166
	/* get the volume free space */
167 168
	file = g_file_new_for_commandline_arg (path);
	if (!file) {
169
		BRASERO_BURN_LOG ("Impossible to retrieve size for %s", path);
170
		gtk_label_set_text (GTK_LABEL (priv->tmpdir), path);
171
		return;
172 173
	}

174 175 176 177
	info = g_file_query_filesystem_info (file,
					     G_FILE_ATTRIBUTE_FILESYSTEM_FREE,
					     NULL,
					     NULL);
Philippe Rouquier's avatar
Philippe Rouquier committed
178 179
	g_object_unref (file);

180 181
	if (!info) {
		BRASERO_BURN_LOG ("Impossible to retrieve size for %s", path);
182
		gtk_label_set_text (GTK_LABEL (priv->tmpdir), path);
183 184 185 186 187 188
		return;
	}

	vol_size = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_FILESYSTEM_FREE);
	g_object_unref (info);

189 190 191 192 193
	string_size = g_format_size_for_display (vol_size);
	/* Translators: the first %s is the path of the directory where brasero
	 * will store its temporary files; the second one is the size available */
	string = g_strdup_printf (_("%s: %s free"), path, string_size);
	g_free (string_size);
194

195 196
	gtk_label_set_text (GTK_LABEL (priv->tmpdir), string);
	g_free (string);
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
}

static gboolean
brasero_drive_properties_check_tmpdir (BraseroDriveProperties *self,
				       const gchar *path)
{
	GFile *file;
	GFileInfo *info;
	GError *error = NULL;
	const gchar *filesystem;
	BraseroDrivePropertiesPrivate *priv;

	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);

	file = g_file_new_for_commandline_arg (path);
	if (!file)
213
		return TRUE;
214

215 216 217 218 219
	info = g_file_query_info (file,
				  G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
				  G_FILE_QUERY_INFO_NONE,
				  NULL,
				  &error);
220
	if (error) {
221 222 223 224
		gint answer;
		gchar *string;
		GtkWidget *dialog;
		GtkWidget *toplevel;
225

226 227 228 229 230 231 232 233 234 235 236 237
		if (error)
			return TRUE;

		/* Tell the user what went wrong */
		toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
		dialog = gtk_message_dialog_new (GTK_WINDOW (toplevel),
						 GTK_DIALOG_DESTROY_WITH_PARENT |
						 GTK_DIALOG_MODAL,
						 GTK_MESSAGE_WARNING,
						 GTK_BUTTONS_NONE,
						 _("Do you really want to choose this location?"));

238 239 240
		gtk_window_set_icon_name (GTK_WINDOW (dialog),
					  gtk_window_get_icon_name (GTK_WINDOW (toplevel)));

241
		string = g_strdup_printf ("%s.", error->message);
242
		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", string);
243
		g_error_free (error);
244
		g_free (string);
245

246 247 248 249 250 251 252 253 254 255 256
		gtk_dialog_add_buttons (GTK_DIALOG (dialog),
					_("_Keep Current Location"), GTK_RESPONSE_CANCEL,
					_("_Change Location"), GTK_RESPONSE_OK,
					NULL);

		gtk_widget_show_all (dialog);
		answer = gtk_dialog_run (GTK_DIALOG (dialog));
		gtk_widget_destroy (dialog);

		g_object_unref (info);
		g_object_unref (file);
257 258
		if (answer != GTK_RESPONSE_OK)
			return TRUE;
259

260
		return FALSE;
261 262
	}

263
	if (!g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE)) {
264 265 266 267 268 269 270 271 272 273 274 275 276
		gint answer;
		gchar *string;
		GtkWidget *dialog;
		GtkWidget *toplevel;

		toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
		dialog = gtk_message_dialog_new (GTK_WINDOW (toplevel),
						 GTK_DIALOG_DESTROY_WITH_PARENT |
						 GTK_DIALOG_MODAL,
						 GTK_MESSAGE_WARNING,
						 GTK_BUTTONS_NONE,
						 _("Do you really want to choose this location?"));

277 278 279
		gtk_window_set_icon_name (GTK_WINDOW (dialog),
					  gtk_window_get_icon_name (GTK_WINDOW (toplevel)));

280
		string = g_strdup_printf ("%s.", _("You do not have the required permission to write at this location"));
281
		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", string);
282 283 284 285 286 287 288 289 290 291 292
		g_free (string);

		gtk_dialog_add_buttons (GTK_DIALOG (dialog),
					_("_Keep Current Location"), GTK_RESPONSE_CANCEL,
					_("_Change Location"), GTK_RESPONSE_OK,
					NULL);

		gtk_widget_show_all (dialog);
		answer = gtk_dialog_run (GTK_DIALOG (dialog));
		gtk_widget_destroy (dialog);

293 294
		g_object_unref (info);
		g_object_unref (file);
295 296
		if (answer != GTK_RESPONSE_OK)
			return TRUE;
297

298
		return FALSE;
299 300
	}

301 302 303 304 305 306 307
	g_object_unref (info);
	info = g_file_query_filesystem_info (file,
					     G_FILE_ATTRIBUTE_FILESYSTEM_TYPE,
					     NULL,
					     &error);
	g_object_unref (file);

308 309 310 311 312
	/* NOTE/FIXME: also check, probably best at start or in a special dialog
	 * whether quotas or any other limitation enforced on the system may not
	 * get in out way. Think getrlimit (). */

	/* check the filesystem type: the problem here is that some
313 314
	 * filesystems have a maximum file size limit of 4 GiB and more than
	 * often we need a temporary file size of 4 GiB or more. */
315
	filesystem = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE);
316
	if (!g_strcmp0 (filesystem, "msdos")) {
317 318 319 320 321 322 323 324 325 326 327 328
		gint answer;
		GtkWidget *dialog;
		GtkWidget *toplevel;

		toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
		dialog = gtk_message_dialog_new (GTK_WINDOW (toplevel),
						 GTK_DIALOG_DESTROY_WITH_PARENT |
						 GTK_DIALOG_MODAL,
						 GTK_MESSAGE_WARNING,
						 GTK_BUTTONS_NONE,
						 _("Do you really want to choose this location?"));

329 330 331
		gtk_window_set_icon_name (GTK_WINDOW (dialog),
					  gtk_window_get_icon_name (GTK_WINDOW (toplevel)));

332
		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
333
							  _("The filesystem on this volume does not support large files (size over 2 GiB)."
334 335 336
							    "\nThis can be a problem when writing DVDs or large images."));

		gtk_dialog_add_buttons (GTK_DIALOG (dialog),
337 338
					_("_Keep Current Location"), GTK_RESPONSE_CANCEL,
					_("_Change Location"), GTK_RESPONSE_OK,
339 340 341 342 343 344
					NULL);

		gtk_widget_show_all (dialog);
		answer = gtk_dialog_run (GTK_DIALOG (dialog));
		gtk_widget_destroy (dialog);

345
		g_object_unref (info);
346 347
		if (answer != GTK_RESPONSE_OK)
			return TRUE;
348
	}
349 350
	else if (info)
		g_object_unref (info);
351

352
	return FALSE;
353 354 355
}

static void
356 357
brasero_drive_properties_tmpdir_clicked (GtkButton *button,
					 BraseroDriveProperties *self)
358
{
359 360 361 362 363
	GtkWidget *parent;
	const gchar *path;
	GtkWidget *chooser;
	GtkResponseType res;
	const gchar *new_path;
364 365
	BraseroDrivePropertiesPrivate *priv;

366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);

	parent = gtk_widget_get_toplevel (GTK_WIDGET (button));
	chooser = gtk_file_chooser_dialog_new (_("Location for Temporary Files"),
					       GTK_WINDOW (parent),
					       GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
					       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
					       GTK_STOCK_OK, GTK_RESPONSE_OK,
					       NULL);

	path = brasero_burn_session_get_tmpdir (BRASERO_BURN_SESSION (priv->session));
	gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (chooser), path);
	res = gtk_dialog_run (GTK_DIALOG (chooser));
	if (res != GTK_RESPONSE_OK) {
		gtk_widget_destroy (chooser);
381
		return;
382
	}
383

384 385 386 387 388 389 390 391 392 393 394 395
	new_path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
	if (!new_path || !strcmp (new_path, path)) {
		gtk_widget_destroy (chooser);
		return;
	}

	if (!brasero_drive_properties_check_tmpdir (self, new_path)) {
		brasero_burn_session_set_tmpdir (BRASERO_BURN_SESSION (priv->session), new_path);
		brasero_drive_properties_set_tmpdir_info (self, new_path);
	}

	gtk_widget_destroy (chooser);
396 397
}

398
static void
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
brasero_drive_properties_set_tmpdir (BraseroDriveProperties *self,
				     const gchar *path)
{
	BraseroDrivePropertiesPrivate *priv;

	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);

	if (!path)
		path = g_get_tmp_dir ();

	brasero_drive_properties_set_tmpdir_info (self, path);
}

static void
brasero_drive_properties_set_flags (BraseroDriveProperties *self,
				    BraseroBurnFlag flags,
				    BraseroBurnFlag supported,
				    BraseroBurnFlag compulsory);

static void
brasero_drive_properties_set_toggle_state (BraseroDriveProperties *self,
					   GtkWidget *toggle,
421 422 423 424 425 426 427 428
					   BraseroBurnFlag flag,
					   BraseroBurnFlag flags,
					   BraseroBurnFlag supported,
					   BraseroBurnFlag compulsory)
{
	if (!(supported & flag)) {
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), FALSE);
		gtk_widget_set_sensitive (toggle, FALSE);
429
		gtk_widget_hide (toggle);
430 431 432
		return;
	}

433 434 435 436
	gtk_widget_show (toggle);
	g_signal_handlers_block_by_func (toggle,
					 brasero_drive_properties_set_flags,
					 self);
437
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), (flags & flag));
438 439 440 441
	g_signal_handlers_unblock_by_func (toggle,
					   brasero_drive_properties_set_flags,
					   self);

442 443 444
	gtk_widget_set_sensitive (toggle, (compulsory & flag) == 0);
}

445
static void
446 447 448 449 450 451 452 453 454 455 456 457 458 459
brasero_drive_properties_set_flags (BraseroDriveProperties *self,
				    BraseroBurnFlag flags,
				    BraseroBurnFlag supported,
				    BraseroBurnFlag compulsory)
{
	BraseroDrivePropertiesPrivate *priv;

	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);

	flags &= BRASERO_DRIVE_PROPERTIES_FLAGS;
	supported &= BRASERO_DRIVE_PROPERTIES_FLAGS;
	compulsory &= BRASERO_DRIVE_PROPERTIES_FLAGS;

	/* flag properties */
460 461
	brasero_drive_properties_set_toggle_state (self,
						   priv->dummy,
462 463 464 465
						   BRASERO_BURN_FLAG_DUMMY,
						   flags,
						   supported,
						   compulsory);
466 467
	brasero_drive_properties_set_toggle_state (self,
						   priv->burnproof,
468 469 470 471
						   BRASERO_BURN_FLAG_BURNPROOF,
						   flags,
						   supported,
						   compulsory);
472 473
	brasero_drive_properties_set_toggle_state (self,
						   priv->notmp,
474 475 476 477
						   BRASERO_BURN_FLAG_NO_TMP_FILES,
						   flags,
						   supported,
						   compulsory);
478 479
	brasero_drive_properties_set_toggle_state (self,
						   priv->multi,
480 481 482 483
						   BRASERO_BURN_FLAG_MULTI,
						   flags,
						   supported,
						   compulsory);
484 485
}

486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
static gint64
brasero_drive_properties_get_rate (BraseroDriveProperties *self)
{
	BraseroDrivePropertiesPrivate *priv;
	GtkTreeModel *model;
	GtkTreeIter iter;
	gint64 rate;

	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);

	model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->speed));
	if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->speed), &iter)
	&&  !gtk_tree_model_get_iter_first (model, &iter))
		return 0;

	gtk_tree_model_get (model, &iter,
			    RATE_COL, &rate,
			    -1);
	return rate;
}

static void
brasero_drive_properties_rate_changed_cb (GtkComboBox *combo,
					  BraseroDriveProperties *self)
{
	BraseroDrivePropertiesPrivate *priv;
	guint64 rate;

	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);

	rate = brasero_drive_properties_get_rate (self);
	if (!rate)
		return;

	brasero_burn_session_set_rate (BRASERO_BURN_SESSION (priv->session), rate);
}

Philippe Rouquier's avatar
Philippe Rouquier committed
523 524 525 526 527 528
static gchar *
brasero_drive_properties_format_disc_speed (BraseroMedia media,
					    gint64 rate)
{
	gchar *text;

529
	if (media & BRASERO_MEDIUM_DVD)
530
		/* Translators %s.1f is the speed used to burn */
531
		text = g_strdup_printf (_("%.1f\303\227 (DVD)"),
Philippe Rouquier's avatar
Philippe Rouquier committed
532 533
					BRASERO_RATE_TO_SPEED_DVD (rate));
	else if (media & BRASERO_MEDIUM_CD)
534
		/* Translators %s.1f is the speed used to burn */
535
		text = g_strdup_printf (_("%.1f\303\227 (CD)"),
Philippe Rouquier's avatar
Philippe Rouquier committed
536
					BRASERO_RATE_TO_SPEED_CD (rate));
537
	else if (media & BRASERO_MEDIUM_BD)
538
		/* Translators %s.1f is the speed used to burn */
539
		text = g_strdup_printf (_("%.1f\303\227 (BD)"),
540
					BRASERO_RATE_TO_SPEED_BD (rate));
Philippe Rouquier's avatar
Philippe Rouquier committed
541
	else
542 543
		/* Translators %s.1f is the speed used to burn for every medium
		 * type*/
544
		text = g_strdup_printf (_("%.1f\303\227 (BD) %.1f\303\227 (DVD) %.1f\303\227 (CD)"),
545
					BRASERO_RATE_TO_SPEED_BD (rate),
Philippe Rouquier's avatar
Philippe Rouquier committed
546 547 548 549 550 551
					BRASERO_RATE_TO_SPEED_DVD (rate),
					BRASERO_RATE_TO_SPEED_CD (rate));

	return text;
}

552
static void
553
brasero_drive_properties_set_drive (BraseroDriveProperties *self,
554
				    BraseroDrive *drive,
555 556 557
				    gint64 default_rate)
{
	BraseroDrivePropertiesPrivate *priv;
558
	BraseroMedium *medium;
559 560 561
	BraseroMedia media;
	GtkTreeModel *model;
	GtkTreeIter iter;
562
	guint64 *rates;
Philippe Rouquier's avatar
Philippe Rouquier committed
563
	gchar *text;
564
	guint i;
565 566 567 568

	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);

	/* Speed combo */
569 570
	medium = brasero_drive_get_medium (drive);
	media = brasero_medium_get_status (medium);
571 572 573
	if (media & BRASERO_MEDIUM_FILE)
		return;

574
	rates = brasero_medium_get_write_speeds (medium);
575
	model = gtk_combo_box_get_model (GTK_COMBO_BOX (priv->speed));
576
	gtk_list_store_clear (GTK_LIST_STORE (model));
Philippe Rouquier's avatar
Philippe Rouquier committed
577

578 579 580 581
	if (!rates) {
		gtk_widget_set_sensitive (priv->speed, FALSE);
		gtk_list_store_append (GTK_LIST_STORE (model), &iter);
		gtk_list_store_set (GTK_LIST_STORE (model), &iter,
582 583
				    TEXT_COL, _("Impossible to retrieve speeds"),
				    RATE_COL, 1764, /* Speed 1 */
584 585 586 587
				    -1);
		gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->speed), &iter);
		return;
	}
Philippe Rouquier's avatar
Philippe Rouquier committed
588

589 590
	gtk_list_store_append (GTK_LIST_STORE (model), &iter);
	gtk_list_store_set (GTK_LIST_STORE (model), &iter,
591
			    TEXT_COL, _("Maximum speed"),
592
			    RATE_COL, rates [0],
593
			    -1);
Philippe Rouquier's avatar
Philippe Rouquier committed
594

595 596 597
	/* fill model */
	for (i = 0; rates [i] != 0; i ++) {
		text = brasero_drive_properties_format_disc_speed (media, rates [i]);
598 599
		gtk_list_store_append (GTK_LIST_STORE (model), &iter);
		gtk_list_store_set (GTK_LIST_STORE (model), &iter,
600 601
				    TEXT_COL, text,
				    RATE_COL, rates [i],
602 603
				    -1);
		g_free (text);
604
	}
Philippe Rouquier's avatar
Philippe Rouquier committed
605
	g_free (rates);
606 607 608 609 610 611 612

	/* Set active one preferably max speed */
	gtk_tree_model_get_iter_first (model, &iter);
	do {
		gint64 rate;

		gtk_tree_model_get (model, &iter,
613
				    RATE_COL, &rate,
614
				    -1);
615 616

		/* we do this to round things and get the closest possible speed */
617
		if ((rate / 1024) == (default_rate / 1024)) {
618
			gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->speed), &iter);
619 620 621 622 623 624 625 626 627
			break;
		}

	} while (gtk_tree_model_iter_next (model, &iter));

	/* make sure at least one is active */
	if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (priv->speed), &iter)) {
		gtk_tree_model_get_iter_first (model, &iter);
		gtk_combo_box_set_active_iter (GTK_COMBO_BOX (priv->speed), &iter);
628 629 630
	}
}

631 632 633
static void
brasero_drive_properties_update (BraseroDriveProperties *self)
{
634 635
	BraseroBurnFlag compulsory = BRASERO_BURN_FLAG_NONE;
	BraseroBurnFlag supported = BRASERO_BURN_FLAG_NONE;
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
	BraseroDrivePropertiesPrivate *priv;
	BraseroBurnFlag flags;

	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);
	brasero_drive_properties_set_drive (self,
					    brasero_burn_session_get_burner (BRASERO_BURN_SESSION (priv->session)),
					    brasero_burn_session_get_rate (BRASERO_BURN_SESSION (priv->session)));

	flags = brasero_burn_session_get_flags (BRASERO_BURN_SESSION (priv->session));
	brasero_burn_session_get_burn_flags (BRASERO_BURN_SESSION (priv->session),
					     &supported,
					     &compulsory);
	brasero_drive_properties_set_flags (self,
					    flags,
					    supported,
					    compulsory);
	brasero_drive_properties_set_tmpdir (self, brasero_burn_session_get_tmpdir (BRASERO_BURN_SESSION (priv->session)));
}

static void
brasero_drive_properties_is_valid_cb (BraseroSessionCfg *session,
				      BraseroDriveProperties *self)
{
	BraseroDrivePropertiesPrivate *priv;
	BraseroBurnFlag compulsory;
	BraseroBurnFlag supported;
	BraseroBurnFlag flags;

	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);

	flags = brasero_burn_session_get_flags (BRASERO_BURN_SESSION (priv->session));
	brasero_burn_session_get_burn_flags (BRASERO_BURN_SESSION (priv->session),
					     &supported,
					     &compulsory);
	brasero_drive_properties_set_flags (self,
					    flags,
					    supported,
					    compulsory);
}

static void
brasero_drive_properties_output_changed_cb (BraseroSessionCfg *session,
					    BraseroMedium *former,
					    BraseroDriveProperties *self)
{
	BraseroDrivePropertiesPrivate *priv;

	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (self);

	/* if the drive changed update rate but only if the drive changed that's
	 * why we don't do it when the is-valid signal is emitted. */
	brasero_drive_properties_set_drive (self,
					    brasero_burn_session_get_burner (BRASERO_BURN_SESSION (priv->session)),
					    brasero_burn_session_get_rate (BRASERO_BURN_SESSION (priv->session)));
}

692 693 694 695 696 697
static void
brasero_drive_properties_init (BraseroDriveProperties *object)
{
	BraseroDrivePropertiesPrivate *priv;
	GtkCellRenderer *renderer;
	GtkTreeModel *model;
698 699
	GtkWidget *button;
	GtkWidget *image;
700
	GtkWidget *label;
701
	GtkWidget *vbox;
702
	GtkWidget *box;
703
	gchar *string;
704 705 706

	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (object);

707 708 709
	vbox = gtk_vbox_new (FALSE, 0);
	gtk_widget_show (vbox);
	gtk_container_add (GTK_CONTAINER (object), vbox);
710

711
	model = GTK_TREE_MODEL (gtk_list_store_new (COL_NUM,
712 713 714 715
						    G_TYPE_STRING,
						    G_TYPE_INT64));

	priv->speed = gtk_combo_box_new_with_model (model);
716
	gtk_widget_show (priv->speed);
717
	string = g_strdup_printf ("<b>%s</b>", _("Burning speed"));
718
	gtk_box_pack_start (GTK_BOX (vbox),
719
			    brasero_utils_pack_properties (string,
720 721
							   priv->speed, NULL),
			    FALSE, FALSE, 0);
722
	g_free (string);
723 724 725 726

	renderer = gtk_cell_renderer_text_new ();
	gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->speed), renderer, TRUE);
	gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (priv->speed), renderer,
727
					"text", TEXT_COL,
728 729
					NULL);

730
	priv->dummy = gtk_check_button_new_with_mnemonic (_("_Simulate before burning"));
731
	gtk_widget_set_tooltip_text (priv->dummy, _("Brasero will simulate the burning and, if it is successful, go on with actual burning after 10 seconds"));
732
	gtk_widget_show (priv->dummy);
733
	priv->burnproof = gtk_check_button_new_with_mnemonic (_("Use burn_proof (decrease the risk of failures)"));
734
	gtk_widget_show (priv->burnproof);
735
	priv->notmp = gtk_check_button_new_with_mnemonic (_("Burn the image directly _without saving it to disc"));
736
	gtk_widget_show (priv->notmp);
737 738
	priv->multi = gtk_check_button_new_with_mnemonic (_("Leave the disc _open to add other files later"));
	gtk_widget_set_tooltip_text (priv->multi, _("Allow to add more data to the disc later"));
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756
	gtk_widget_show (priv->multi);

	g_signal_connect (priv->dummy,
			  "toggled",
			  G_CALLBACK (brasero_drive_properties_dummy_toggled),
			  object);
	g_signal_connect (priv->burnproof,
			  "toggled",
			  G_CALLBACK (brasero_drive_properties_burnproof_toggled),
			  object);
	g_signal_connect (priv->multi,
			  "toggled",
			  G_CALLBACK (brasero_drive_properties_multi_toggled),
			  object);
	g_signal_connect (priv->notmp,
			  "toggled",
			  G_CALLBACK (brasero_drive_properties_no_tmp_toggled),
			  object);
757

758
	string = g_strdup_printf ("<b>%s</b>", _("Options"));
759
	gtk_box_pack_start (GTK_BOX (vbox),
760
			    brasero_utils_pack_properties (string,
761 762
							   priv->dummy,
							   priv->burnproof,
763
							   priv->multi,
764 765 766 767
							   priv->notmp,
							   NULL),
			    FALSE,
			    FALSE, 0);
768
	g_free (string);
769

770 771 772 773 774 775 776 777 778 779 780
	label = gtk_label_new_with_mnemonic (_("Location for _Temporary Files"));
	gtk_widget_show (label);
	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
	gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
	gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_START);
	gtk_widget_show (label);

	priv->tmpdir = label;

	image = gtk_image_new_from_icon_name ("folder", GTK_ICON_SIZE_BUTTON);
	gtk_widget_show (image);
781 782 783

	box = gtk_hbox_new (FALSE, 6);
	gtk_widget_show (box);
784 785
	gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
786

787 788 789 790
	button = gtk_button_new ();
	gtk_widget_show (button);
	gtk_container_add (GTK_CONTAINER (button), box);
	gtk_widget_set_tooltip_text (button, _("Set the directory where to store temporary files"));
791

792 793
	box = gtk_hbox_new (FALSE, 6);
	gtk_widget_show (box);
794

795
	string = g_strdup_printf ("<b>%s</b>", _("Temporary files"));
796
	gtk_box_pack_start (GTK_BOX (vbox),
797
			    brasero_utils_pack_properties (string,
798
							   box,
799
							   button,
800 801 802
							   NULL),
			    FALSE,
			    FALSE, 0);
803
	g_free (string);
804
	gtk_widget_show (vbox);
805

806 807 808 809 810 811 812
	g_signal_connect (button,
			  "clicked",
			  G_CALLBACK (brasero_drive_properties_tmpdir_clicked),
			  object);
	g_signal_connect (priv->speed,
			  "changed",
			  G_CALLBACK (brasero_drive_properties_rate_changed_cb),
813
			  object);
814 815 816 817 818
}

static void
brasero_drive_properties_finalize (GObject *object)
{
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
	BraseroDrivePropertiesPrivate *priv;
	
	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (object);
	if (priv->valid_sig) {
		g_signal_handler_disconnect (priv->session, priv->valid_sig);
		priv->valid_sig = 0;
	}
	if (priv->output_sig) {
		g_signal_handler_disconnect (priv->session, priv->output_sig);
		priv->output_sig = 0;
	}
	if (priv->session) {
		g_object_unref (priv->session);
		priv->session = NULL;
	}

835
	G_OBJECT_CLASS (brasero_drive_properties_parent_class)->finalize (object);
836 837
}

838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
static void
brasero_drive_properties_set_property (GObject *object,
				       guint property_id,
				       const GValue *value,
				       GParamSpec *pspec)
{
	BraseroDrivePropertiesPrivate *priv;
	BraseroBurnSession *session;

	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (object);

	switch (property_id) {
	case PROP_SESSION: /* Readable and only writable at creation time */
		/* NOTE: no need to unref a potential previous session since
		 * it's only set at construct time */
		session = g_value_get_object (value);
		priv->session = g_object_ref (session);

		brasero_drive_properties_update (BRASERO_DRIVE_PROPERTIES (object));
		priv->valid_sig = g_signal_connect (session,
						    "is-valid",
						    G_CALLBACK (brasero_drive_properties_is_valid_cb),
						    object);
		priv->output_sig = g_signal_connect (session,
						     "output-changed",
						     G_CALLBACK (brasero_drive_properties_output_changed_cb),
						     object);
		break;

	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
	}
}

static void
brasero_drive_properties_get_property (GObject *object,
				       guint property_id,
				       GValue *value,
				       GParamSpec *pspec)
{
	BraseroDrivePropertiesPrivate *priv;

	priv = BRASERO_DRIVE_PROPERTIES_PRIVATE (object);

	switch (property_id) {
	case PROP_SESSION:
		g_object_ref (priv->session);
		g_value_set_object (value, priv->session);
		break;

	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
	}
}

893 894 895
static void
brasero_drive_properties_class_init (BraseroDrivePropertiesClass *klass)
{
896
	GObjectClass *object_class = G_OBJECT_CLASS (klass);
897 898 899 900

	g_type_class_add_private (klass, sizeof (BraseroDrivePropertiesPrivate));

	object_class->finalize = brasero_drive_properties_finalize;
901 902 903 904 905 906 907 908 909 910
	object_class->set_property = brasero_drive_properties_set_property;
	object_class->get_property = brasero_drive_properties_get_property;

	g_object_class_install_property (object_class,
					 PROP_SESSION,
					 g_param_spec_object ("session",
							      "The session",
							      "The session to work with",
							      BRASERO_TYPE_BURN_SESSION,
							      G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
911 912 913
}

GtkWidget *
914
brasero_drive_properties_new (BraseroSessionCfg *session)
915
{
916 917 918
	return g_object_new (BRASERO_TYPE_DRIVE_PROPERTIES,
			     "session", session,
			     NULL);
919
}