~ubuntu-branches/ubuntu/karmic/brasero/karmic

1.1.7 by Luis Medinas
Import upstream version 0.7.0
1
/***************************************************************************
2
 *            project.c
3
 *
4
 *  mar nov 29 09:32:17 2005
5
 *  Copyright  2005  Rouquier Philippe
6
 *  brasero-app@wanadoo.fr
7
 ***************************************************************************/
8
9
/*
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
10
 *  Brasero is free software; you can redistribute it and/or modify
1.1.7 by Luis Medinas
Import upstream version 0.7.0
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; either version 2 of the License, or
13
 *  (at your option) any later version.
14
 *
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
15
 *  Brasero is distributed in the hope that it will be useful,
1.1.7 by Luis Medinas
Import upstream version 0.7.0
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 *  GNU Library General Public License for more details.
19
 *
20
 *  You should have received a copy of the GNU General Public License
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
21
 *  along with this program; if not, write to:
22
 * 	The Free Software Foundation, Inc.,
23
 * 	51 Franklin Street, Fifth Floor
24
 * 	Boston, MA  02110-1301, USA.
1.1.7 by Luis Medinas
Import upstream version 0.7.0
25
 */
26
27
#ifdef HAVE_CONFIG_H
28
#  include <config.h>
29
#endif
30
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
31
#include <string.h>
32
1.1.7 by Luis Medinas
Import upstream version 0.7.0
33
#include <glib.h>
34
#include <glib/gstdio.h>
35
#include <glib/gi18n.h>
36
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
37
#include <gio/gio.h>
38
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
39
#include <gtk/gtk.h>
1.1.7 by Luis Medinas
Import upstream version 0.7.0
40
41
#include <libxml/xmlerror.h>
42
#include <libxml/xmlwriter.h>
43
#include <libxml/parser.h>
44
#include <libxml/xmlstring.h>
45
#include <libxml/uri.h>
46
47
#include <gconf/gconf-client.h>
48
1.1.20 by Pedro Fragoso
Import upstream version 2.25.92
49
#include <gst/gst.h>
50
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
51
#ifdef BUILD_PLAYLIST
52
#include <totem-pl-parser.h>
53
#endif
54
1.1.7 by Luis Medinas
Import upstream version 0.7.0
55
#include "burn-debug.h"
56
#include "burn-session.h"
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
57
58
#ifdef BUILD_PREVIEW
59
#include "brasero-player.h"
60
#endif
61
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
62
#include "brasero-app.h"
1.1.7 by Luis Medinas
Import upstream version 0.7.0
63
#include "brasero-project.h"
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
64
#include "brasero-session-cfg.h"
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
65
#include "brasero-jacket-edit.h"
1.1.7 by Luis Medinas
Import upstream version 0.7.0
66
#include "brasero-project-type-chooser.h"
67
#include "brasero-disc.h"
68
#include "brasero-data-disc.h"
69
#include "brasero-audio-disc.h"
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
70
#include "brasero-video-disc.h"
1.1.7 by Luis Medinas
Import upstream version 0.7.0
71
#include "brasero-disc-option-dialog.h"
72
#include "brasero-utils.h"
73
#include "brasero-uri-container.h"
74
#include "brasero-layout-object.h"
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
75
#include "brasero-disc-message.h"
76
#include "brasero-file-chooser.h"
77
#include "brasero-notify.h"
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
78
#include "brasero-project-parse.h"
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
79
#include "brasero-burn-options.h"
80
#include "brasero-project-name.h"
1.1.7 by Luis Medinas
Import upstream version 0.7.0
81
82
static void brasero_project_class_init (BraseroProjectClass *klass);
83
static void brasero_project_init (BraseroProject *sp);
84
static void brasero_project_iface_uri_container_init (BraseroURIContainerIFace *iface);
85
static void brasero_project_iface_layout_object_init (BraseroLayoutObjectIFace *iface);
86
static void brasero_project_finalize (GObject *object);
87
88
static void
89
brasero_project_save_cb (GtkAction *action, BraseroProject *project);
90
static void
91
brasero_project_save_as_cb (GtkAction *action, BraseroProject *project);
92
93
static void
94
brasero_project_add_uris_cb (GtkAction *action, BraseroProject *project);
95
static void
96
brasero_project_remove_selected_uris_cb (GtkAction *action, BraseroProject *project);
97
static void
98
brasero_project_empty_cb (GtkAction *action, BraseroProject *project);
99
100
static void
101
brasero_project_burn_cb (GtkAction *action, BraseroProject *project);
102
103
static void
104
brasero_project_size_changed_cb (BraseroDisc *disc,
105
			         gint64 size,
106
			         BraseroProject *project);
107
static void
108
brasero_project_flags_changed_cb (BraseroDisc *disc,
109
				  BraseroBurnFlag flags,
110
				  BraseroProject *project);
111
112
static void
113
brasero_project_burn_clicked_cb (GtkButton *button, BraseroProject *project);
114
115
static void
116
brasero_project_contents_changed_cb (BraseroDisc *disc,
117
				     gint nb_files,
118
				     BraseroProject *project);
119
static void
120
brasero_project_selection_changed_cb (BraseroDisc *disc,
121
				      BraseroProject *project);
122
123
static gchar *
124
brasero_project_get_selected_uri (BraseroURIContainer *container);
125
static gboolean
126
brasero_project_get_boundaries (BraseroURIContainer *container,
127
				gint64 *start,
128
				gint64 *end);
129
130
static void
131
brasero_project_get_proportion (BraseroLayoutObject *object,
132
				gint *header,
133
				gint *center,
134
				gint *footer);
135
136
static void
137
brasero_project_get_proportion (BraseroLayoutObject *object,
138
				gint *header,
139
				gint *center,
140
				gint *footer);
141
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
142
typedef enum {
143
	BRASERO_PROJECT_SAVE_XML			= 0,
144
	BRASERO_PROJECT_SAVE_PLAIN			= 1,
145
	BRASERO_PROJECT_SAVE_PLAYLIST_PLS		= 2,
146
	BRASERO_PROJECT_SAVE_PLAYLIST_M3U		= 3,
147
	BRASERO_PROJECT_SAVE_PLAYLIST_XSPF		= 4,
148
	BRASERO_PROJECT_SAVE_PLAYLIST_IRIVER_PLA	= 5
149
} BraseroProjectSave;
150
1.1.7 by Luis Medinas
Import upstream version 0.7.0
151
struct BraseroProjectPrivate {
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
152
	GtkWidget *name_display;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
153
	GtkWidget *discs;
154
	GtkWidget *audio;
155
	GtkWidget *data;
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
156
	GtkWidget *video;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
157
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
158
	GtkWidget *message;
159
1.1.7 by Luis Medinas
Import upstream version 0.7.0
160
	GtkUIManager *manager;
161
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
162
	guint status_ctx;
163
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
164
	GtkWidget *project_status;
165
1.1.7 by Luis Medinas
Import upstream version 0.7.0
166
	/* header */
167
	GtkWidget *burn;
168
169
	GtkActionGroup *project_group;
170
	guint merge_id;
171
172
	gchar *project;
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
173
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
174
	gchar *cover;
175
1.1.7 by Luis Medinas
Import upstream version 0.7.0
176
	gint64 sectors;
177
	BraseroDisc *current;
178
179
	BraseroURIContainer *current_source;
180
181
	GtkWidget *chooser;
182
	gulong selected_id;
183
	gulong activated_id;
184
185
	guint is_burning:1;
186
187
    	guint burnt:1;
188
189
	guint empty:1;
190
	guint modified:1;
191
	guint has_focus:1;
192
	guint oversized:1;
193
	guint selected_uris:1;
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
194
195
	guint merging:1;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
196
};
197
198
static GtkActionEntry entries [] = {
199
	{"Save", GTK_STOCK_SAVE, NULL, NULL,
200
	 N_("Save current project"), G_CALLBACK (brasero_project_save_cb)},
201
	{"SaveAs", GTK_STOCK_SAVE_AS, N_("Save _As..."), NULL,
202
	 N_("Save current project to a different location"), G_CALLBACK (brasero_project_save_as_cb)},
203
	{"Add", GTK_STOCK_ADD, N_("_Add Files"), NULL,
204
	 N_("Add files to the project"), G_CALLBACK (brasero_project_add_uris_cb)},
205
	{"DeleteProject", GTK_STOCK_REMOVE, N_("_Remove Files"), NULL,
206
	 N_("Remove the selected files from the project"), G_CALLBACK (brasero_project_remove_selected_uris_cb)},
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
207
	/* Translators: "empty" is a verb here */
1.1.7 by Luis Medinas
Import upstream version 0.7.0
208
	{"DeleteAll", GTK_STOCK_CLEAR, N_("E_mpty Project"), NULL,
1.1.12 by Pedro Fragoso
Import upstream version 0.8.2
209
	 N_("Remove all files from the project"), G_CALLBACK (brasero_project_empty_cb)},
1.1.7 by Luis Medinas
Import upstream version 0.7.0
210
	{"Burn", "media-optical-burn", N_("_Burn..."), NULL,
211
	 N_("Burn the disc"), G_CALLBACK (brasero_project_burn_cb)},
212
};
213
214
static const gchar *description = {
215
	"<ui>"
216
	    "<menubar name='menubar' >"
217
		"<menu action='ProjectMenu'>"
218
			"<placeholder name='ProjectPlaceholder'>"
219
			    "<menuitem action='Save'/>"
220
			    "<menuitem action='SaveAs'/>"
221
			    "<separator/>"
222
			"<menuitem action='Burn'/>"
223
			"</placeholder>"
224
		"</menu>"
225
		
226
		"<menu action='EditMenu'>"
227
			"<placeholder name='EditPlaceholder'>"
228
			    "<menuitem action='Add'/>"
229
			    "<menuitem action='DeleteProject'/>"
230
			    "<menuitem action='DeleteAll'/>"
231
			    "<separator/>"
232
			"</placeholder>"
233
		"</menu>"
234
235
		"<menu action='ViewMenu'>"
236
		"</menu>"
237
238
		"<menu action='ToolMenu'>"
239
			"<placeholder name='DiscPlaceholder'/>"
240
		"</menu>"
241
	    "</menubar>"
242
	    "<toolbar name='Toolbar'>"
243
		"<separator/>"
244
		"<toolitem action='Add'/>"
245
		"<toolitem action='DeleteProject'/>"
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
246
		"<toolitem action='DeleteAll'/>"
1.1.7 by Luis Medinas
Import upstream version 0.7.0
247
		"<placeholder name='DiscButtonPlaceholder'/>"
248
	     "</toolbar>"
249
	"</ui>"
250
};
251
252
static GObjectClass *parent_class = NULL;
253
254
#define BRASERO_PROJECT_SIZE_WIDGET_BORDER	1
255
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
256
#define BRASERO_KEY_SHOW_PREVIEW		"/apps/brasero/display/viewer"
1.1.7 by Luis Medinas
Import upstream version 0.7.0
257
258
#define BRASERO_PROJECT_VERSION "0.2"
259
1.1.12 by Pedro Fragoso
Import upstream version 0.8.2
260
#define BRASERO_RESPONSE_ADD			1976
261
1.1.7 by Luis Medinas
Import upstream version 0.7.0
262
GType
263
brasero_project_get_type ()
264
{
265
	static GType type = 0;
266
267
	if(type == 0) {
268
		static const GTypeInfo our_info = {
269
			sizeof (BraseroProjectClass),
270
			NULL,
271
			NULL,
272
			(GClassInitFunc)brasero_project_class_init,
273
			NULL,
274
			NULL,
275
			sizeof (BraseroProject),
276
			0,
277
			(GInstanceInitFunc) brasero_project_init,
278
		};
279
280
		static const GInterfaceInfo uri_container_info =
281
		{
282
			(GInterfaceInitFunc) brasero_project_iface_uri_container_init,
283
			NULL,
284
			NULL
285
		};
286
		static const GInterfaceInfo layout_object =
287
		{
288
			(GInterfaceInitFunc) brasero_project_iface_layout_object_init,
289
			NULL,
290
			NULL
291
		};
292
293
		type = g_type_register_static (GTK_TYPE_VBOX, 
294
					       "BraseroProject",
295
					       &our_info, 0);
296
297
		g_type_add_interface_static (type,
298
					     BRASERO_TYPE_URI_CONTAINER,
299
					     &uri_container_info);
300
		g_type_add_interface_static (type,
301
					     BRASERO_TYPE_LAYOUT_OBJECT,
302
					     &layout_object);
303
	}
304
305
	return type;
306
}
307
308
static void
309
brasero_project_class_init (BraseroProjectClass *klass)
310
{
311
	GObjectClass *object_class = G_OBJECT_CLASS (klass);
312
313
	parent_class = g_type_class_peek_parent (klass);
314
	object_class->finalize = brasero_project_finalize;
315
}
316
317
static void
318
brasero_project_iface_uri_container_init (BraseroURIContainerIFace *iface)
319
{
320
	iface->get_selected_uri = brasero_project_get_selected_uri;
321
	iface->get_boundaries = brasero_project_get_boundaries;
322
}
323
324
static void
325
brasero_project_iface_layout_object_init (BraseroLayoutObjectIFace *iface)
326
{
327
	iface->get_proportion = brasero_project_get_proportion;
328
}
329
330
static void
331
brasero_project_get_proportion (BraseroLayoutObject *object,
332
				gint *header,
333
				gint *center,
334
				gint *footer)
335
{
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
336
	if (!BRASERO_PROJECT (object)->priv->name_display)
337
		return;
338
339
	*footer = BRASERO_PROJECT (object)->priv->name_display->parent->allocation.height;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
340
}
341
342
static void
343
brasero_project_set_remove_button_state (BraseroProject *project)
344
{
345
	GtkAction *action;
346
	gboolean sensitive;
347
348
	sensitive = (project->priv->has_focus &&
349
		    !project->priv->empty &&
350
		     project->priv->selected_uris);
351
352
	action = gtk_action_group_get_action (project->priv->project_group, "DeleteProject");
353
	gtk_action_set_sensitive (action, sensitive);
354
}
355
356
static void
357
brasero_project_set_add_button_state (BraseroProject *project)
358
{
359
	GtkAction *action;
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
360
	GtkWidget *widget;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
361
	gboolean sensitive;
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
362
	GtkWidget *toplevel;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
363
364
	sensitive = ((!project->priv->current_source || !project->priv->has_focus) &&
365
		      !project->priv->oversized);
366
367
	action = gtk_action_group_get_action (project->priv->project_group, "Add");
368
	gtk_action_set_sensitive (action, sensitive);
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
369
370
	/* set the Add button to be the default for the whole window. That fixes 
371
	 * #465175 – Location field not working. GtkFileChooser needs a default
372
	 * widget to be activated. */
373
	toplevel = gtk_widget_get_toplevel (GTK_WIDGET (project));
374
	if (!sensitive) {
375
		gtk_window_set_default (GTK_WINDOW (toplevel), NULL);
376
		return;
377
	}
378
379
	widget = gtk_ui_manager_get_widget (project->priv->manager, "/Toolbar/Add");
380
	widget = gtk_bin_get_child (GTK_BIN (widget));
381
	GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT);
382
	gtk_window_set_default (GTK_WINDOW (toplevel), widget);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
383
}
384
385
static void
386
brasero_project_focus_changed_cb (GtkContainer *container,
387
				  GtkWidget *widget,
388
				  gpointer NULL_data)
389
{
390
	BraseroProject *project;
391
392
	project = BRASERO_PROJECT (container);
393
	project->priv->has_focus = (widget != NULL);
394
395
	brasero_project_set_remove_button_state (project);
396
	brasero_project_set_add_button_state (project);
397
}
398
399
static void
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
400
brasero_project_name_changed_cb (BraseroProjectName *name,
401
				 BraseroProject *project)
402
{
403
	GtkAction *action;
404
405
	project->priv->modified = TRUE;
406
407
	/* the state of the following depends on the existence of an opened project */
408
	action = gtk_action_group_get_action (project->priv->project_group, "Save");
409
	if (project->priv->modified)
410
		gtk_action_set_sensitive (action, TRUE);
411
	else
412
		gtk_action_set_sensitive (action, FALSE);
413
}
414
415
static void
1.1.7 by Luis Medinas
Import upstream version 0.7.0
416
brasero_project_init (BraseroProject *obj)
417
{
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
418
	GtkSizeGroup *size_group;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
419
	GtkWidget *alignment;
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
420
	GtkWidget *label;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
421
	GtkWidget *box;
422
423
	obj->priv = g_new0 (BraseroProjectPrivate, 1);
424
425
	g_signal_connect (G_OBJECT (obj),
426
			  "set-focus-child",
427
			  G_CALLBACK (brasero_project_focus_changed_cb),
428
			  NULL);
429
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
430
	obj->priv->message = brasero_notify_new ();
431
	gtk_box_pack_start (GTK_BOX (obj), obj->priv->message, FALSE, TRUE, 0);
432
	gtk_widget_show (obj->priv->message);
433
1.1.7 by Luis Medinas
Import upstream version 0.7.0
434
	/* bottom */
435
	box = gtk_hbox_new (FALSE, 6);
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
436
	gtk_container_set_border_width (GTK_CONTAINER (box), 4);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
437
	gtk_widget_show (box);
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
438
	gtk_box_pack_end (GTK_BOX (obj), box, FALSE, TRUE, 0);
439
440
	/* Name widget */
441
	label = gtk_label_new_with_mnemonic (_("_Name:"));
442
	gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
443
	gtk_misc_set_padding (GTK_MISC (label), 6, 0);
444
	gtk_widget_show (label);
445
	gtk_box_pack_start (GTK_BOX (box), label, FALSE, TRUE, 0);
446
447
	obj->priv->name_display = brasero_project_name_new ();
448
	gtk_widget_show (obj->priv->name_display);
449
	gtk_box_pack_start (GTK_BOX (box), obj->priv->name_display, TRUE, TRUE, 0);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
450
	obj->priv->empty = 1;
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
451
452
	g_signal_connect (obj->priv->name_display,
453
			  "name-changed",
454
			  G_CALLBACK (brasero_project_name_changed_cb),
455
			  obj);
456
457
	gtk_label_set_mnemonic_widget (GTK_LABEL (label), obj->priv->name_display);
458
1.1.7 by Luis Medinas
Import upstream version 0.7.0
459
	/* burn button set insensitive since there are no files in the selection */
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
460
	size_group = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
461
	obj->priv->burn = brasero_utils_make_button (_("_Burn..."),
1.1.7 by Luis Medinas
Import upstream version 0.7.0
462
						     NULL,
463
						     "media-optical-burn",
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
464
						     GTK_ICON_SIZE_BUTTON);
465
	gtk_widget_show (obj->priv->burn);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
466
	gtk_widget_set_sensitive (obj->priv->burn, FALSE);
467
	gtk_button_set_focus_on_click (GTK_BUTTON (obj->priv->burn), FALSE);
468
	g_signal_connect (obj->priv->burn,
469
			  "clicked",
470
			  G_CALLBACK (brasero_project_burn_clicked_cb),
471
			  obj);
472
	gtk_widget_set_tooltip_text (obj->priv->burn,
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
473
				     _("Start to burn the contents of the selection"));
474
	gtk_size_group_add_widget (GTK_SIZE_GROUP (size_group), obj->priv->burn);
475
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
476
	alignment = gtk_alignment_new (1.0, 0.5, 0.0, 0.0);
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
477
	gtk_widget_show (alignment);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
478
	gtk_container_add (GTK_CONTAINER (alignment), obj->priv->burn);
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
479
	gtk_box_pack_end (GTK_BOX (box), alignment, FALSE, TRUE, 0);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
480
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
481
	/* The three panes to put into the notebook */
1.1.7 by Luis Medinas
Import upstream version 0.7.0
482
	obj->priv->audio = brasero_audio_disc_new ();
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
483
	gtk_widget_show (obj->priv->audio);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
484
	g_signal_connect (G_OBJECT (obj->priv->audio),
485
			  "contents-changed",
486
			  G_CALLBACK (brasero_project_contents_changed_cb),
487
			  obj);
488
	g_signal_connect (G_OBJECT (obj->priv->audio),
489
			  "size-changed",
490
			  G_CALLBACK (brasero_project_size_changed_cb),
491
			  obj);
492
	g_signal_connect (G_OBJECT (obj->priv->audio),
493
			  "selection-changed",
494
			  G_CALLBACK (brasero_project_selection_changed_cb),
495
			  obj);
496
497
	obj->priv->data = brasero_data_disc_new ();
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
498
	gtk_widget_show (obj->priv->data);
499
	brasero_data_disc_set_right_button_group (BRASERO_DATA_DISC (obj->priv->data), size_group);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
500
	g_signal_connect (G_OBJECT (obj->priv->data),
501
			  "contents-changed",
502
			  G_CALLBACK (brasero_project_contents_changed_cb),
503
			  obj);
504
	g_signal_connect (G_OBJECT (obj->priv->data),
505
			  "size-changed",
506
			  G_CALLBACK (brasero_project_size_changed_cb),
507
			  obj);
508
	g_signal_connect (G_OBJECT (obj->priv->data),
509
			  "flags-changed",
510
			  G_CALLBACK (brasero_project_flags_changed_cb),
511
			  obj);
512
	g_signal_connect (G_OBJECT (obj->priv->data),
513
			  "selection-changed",
514
			  G_CALLBACK (brasero_project_selection_changed_cb),
515
			  obj);
516
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
517
	obj->priv->video = brasero_video_disc_new ();
518
	gtk_widget_show (obj->priv->video);
519
	g_signal_connect (G_OBJECT (obj->priv->video),
520
			  "contents-changed",
521
			  G_CALLBACK (brasero_project_contents_changed_cb),
522
			  obj);
523
	g_signal_connect (G_OBJECT (obj->priv->video),
524
			  "size-changed",
525
			  G_CALLBACK (brasero_project_size_changed_cb),
526
			  obj);
527
	g_signal_connect (G_OBJECT (obj->priv->video),
528
			  "selection-changed",
529
			  G_CALLBACK (brasero_project_selection_changed_cb),
530
			  obj);
531
1.1.7 by Luis Medinas
Import upstream version 0.7.0
532
	obj->priv->discs = gtk_notebook_new ();
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
533
	gtk_widget_show (obj->priv->discs);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
534
	gtk_notebook_set_show_border (GTK_NOTEBOOK (obj->priv->discs), FALSE);
535
	gtk_notebook_set_show_tabs (GTK_NOTEBOOK (obj->priv->discs), FALSE);
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
536
537
	gtk_notebook_prepend_page (GTK_NOTEBOOK (obj->priv->discs),
538
				   obj->priv->video, NULL);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
539
	gtk_notebook_prepend_page (GTK_NOTEBOOK (obj->priv->discs),
540
				   obj->priv->data, NULL);
541
	gtk_notebook_prepend_page (GTK_NOTEBOOK (obj->priv->discs),
542
				   obj->priv->audio, NULL);
543
544
	gtk_box_pack_start (GTK_BOX (obj),
545
			    obj->priv->discs,
546
			    TRUE,
547
			    TRUE,
548
			    0);
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
549
550
	g_object_unref (size_group);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
551
}
552
553
static void
554
brasero_project_finalize (GObject *object)
555
{
556
	BraseroProject *cobj;
557
	cobj = BRASERO_PROJECT(object);
558
559
	if (cobj->priv->project)
560
		g_free (cobj->priv->project);
561
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
562
	if (cobj->priv->cover)
563
		g_free (cobj->priv->cover);
564
565
	g_free (cobj->priv);
566
	G_OBJECT_CLASS (parent_class)->finalize (object);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
567
}
568
569
GtkWidget *
570
brasero_project_new ()
571
{
572
	BraseroProject *obj;
573
	
574
	obj = BRASERO_PROJECT(g_object_new(BRASERO_TYPE_PROJECT, NULL));
575
	gtk_notebook_set_current_page (GTK_NOTEBOOK (obj->priv->discs), 0);
576
577
	return GTK_WIDGET (obj);
578
}
579
580
/********************************** size ***************************************/
1.1.20 by Pedro Fragoso
Import upstream version 2.25.92
581
gchar *
582
brasero_project_get_sectors_string (gint64 sectors,
583
				    gboolean time_format)
584
{
585
	gint64 size_bytes;
586
587
	if (time_format) {
588
		size_bytes = sectors * GST_SECOND / 75;
589
		return brasero_units_get_time_string (size_bytes, TRUE, FALSE);
590
	}
591
	else {
592
		size_bytes = sectors * 2048;
593
		return g_format_size_for_display (size_bytes);
594
	}
595
}
596
1.1.7 by Luis Medinas
Import upstream version 0.7.0
597
static void
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
598
brasero_project_update_project_size (BraseroProject *project,
599
				     guint64 sectors)
600
{
601
	GtkWidget *status;
602
	gchar *string;
603
	gchar *size;
604
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
605
	status = brasero_app_get_statusbar2 (brasero_app_get_default ());
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
606
607
	if (!project->priv->status_ctx)
608
		project->priv->status_ctx = gtk_statusbar_get_context_id (GTK_STATUSBAR (status),
609
									  "size_project");
610
611
	gtk_statusbar_pop (GTK_STATUSBAR (status), project->priv->status_ctx);
612
1.1.20 by Pedro Fragoso
Import upstream version 2.25.92
613
	string = brasero_project_get_sectors_string (sectors,
614
						     !BRASERO_IS_DATA_DISC (project->priv->current));
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
615
	if (project->priv->merging) {
616
		gchar *medium_string;
617
		BraseroMedium *medium;
618
		gint64 free_space = 0;
619
620
		medium = brasero_data_disc_get_loaded_medium (BRASERO_DATA_DISC (project->priv->current));
621
		brasero_medium_get_free_space (medium,
622
					       &free_space,
623
					       NULL);
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
624
625
		medium_string = g_format_size_for_display (free_space);
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
626
		/* Translators: first %s is the size of the project and the 
627
		 * second %s is the remaining free space on the disc that is
628
		 * used for multisession */
629
		size = g_strdup_printf (_("Project estimated size: %s/%s"),
630
					string,
631
					medium_string);
632
		g_free (medium_string);
633
	}
634
	else
635
		size = g_strdup_printf (_("Project estimated size: %s"), string);
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
636
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
637
	g_free (string);
638
639
	gtk_statusbar_push (GTK_STATUSBAR (status), project->priv->status_ctx, size);
640
	g_free (size);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
641
}
642
643
static void
644
brasero_project_size_changed_cb (BraseroDisc *disc,
645
			         gint64 sectors,
646
			         BraseroProject *project)
647
{
648
	project->priv->sectors = sectors;
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
649
	brasero_project_update_project_size (project, sectors);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
650
}
651
652
static void
653
brasero_project_flags_changed_cb (BraseroDisc *disc,
654
				  BraseroBurnFlag flags,
655
				  BraseroProject *project)
656
{
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
657
	gboolean merging;
658
659
	merging = (flags & BRASERO_BURN_FLAG_MERGE) != 0;
660
661
	/* see if the project name should be updated */
662
	brasero_project_name_set_multisession_medium (BRASERO_PROJECT_NAME (project->priv->name_display),
663
						      brasero_data_disc_get_loaded_medium (BRASERO_DATA_DISC (disc)));
664
665
	/* we just need to know if MERGE flag is on */
666
	project->priv->merging = merging;
667
	brasero_project_update_project_size (project, project->priv->sectors);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
668
}
669
670
/***************************** URIContainer ************************************/
671
static void
672
brasero_project_selection_changed_cb (BraseroDisc *disc,
673
				      BraseroProject *project)
674
{
675
	project->priv->selected_uris = brasero_disc_get_selected_uri (project->priv->current, NULL);
676
	brasero_project_set_remove_button_state (project);
677
	brasero_uri_container_uri_selected (BRASERO_URI_CONTAINER (project));
678
}
679
680
static gchar *
681
brasero_project_get_selected_uri (BraseroURIContainer *container)
682
{
683
	BraseroProject *project;
684
	gchar *uri = NULL;
685
686
	project = BRASERO_PROJECT (container);
687
688
	/* if we are burning we better not return anything so as to stop 
689
	 * preview widget from carrying on to play */
690
	if (project->priv->is_burning)
691
		return NULL;
692
693
	if (brasero_disc_get_selected_uri (project->priv->current, &uri))
694
		return uri;
695
696
	return NULL;
697
}
698
699
static gboolean
700
brasero_project_get_boundaries (BraseroURIContainer *container,
701
				gint64 *start,
702
				gint64 *end)
703
{
704
	BraseroProject *project;
705
706
	project = BRASERO_PROJECT (container);
707
708
	/* if we are burning we better not return anything so as to stop 
709
	 * preview widget from carrying on to play */
710
	if (project->priv->is_burning)
711
		return FALSE;
712
713
	return brasero_disc_get_boundaries (project->priv->current,
714
					    start,
715
					    end);
716
}
717
718
/******************** useful function to wait when burning/saving **************/
719
static gboolean
720
_wait_for_ready_state (GtkWidget *dialog)
721
{
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
722
	gchar *current_task = NULL;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
723
	GtkProgressBar *progress;
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
724
	BraseroDiscResult status;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
725
	BraseroProject *project;
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
726
	gint remaining = 0;
727
	gint initial;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
728
729
	project = g_object_get_data (G_OBJECT (dialog), "Project");
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
730
	if (project->priv->oversized
731
	|| !project->priv->current
732
	|| !project->priv->project_status) {
1.1.7 by Luis Medinas
Import upstream version 0.7.0
733
		gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
734
		return FALSE;
735
	}
736
737
	progress = g_object_get_data (G_OBJECT (dialog), "ProgressBar");
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
738
	initial = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dialog), "Remaining"));
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
739
	status = brasero_disc_get_status (project->priv->current, &remaining, &current_task);
740
	if (status == BRASERO_DISC_NOT_READY || status == BRASERO_DISC_LOADING) {
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
741
		gchar *string;
742
		gchar *size_str;
743
744
		if (initial <= 0 || remaining <= 0)
745
			gtk_progress_bar_pulse (progress);
746
		else
747
			gtk_progress_bar_set_fraction (progress, (gdouble) ((gdouble) (initial - remaining) / (gdouble) initial));
748
749
		if (current_task) {
750
			GtkWidget *current_action;
751
752
			current_action = g_object_get_data (G_OBJECT (dialog), "CurrentAction");
753
			string = g_strdup_printf ("<i>%s</i>", current_task);
754
			g_free (current_task);
755
756
			gtk_label_set_markup (GTK_LABEL (current_action), string);
757
			g_free (string);
758
		}
759
1.1.20 by Pedro Fragoso
Import upstream version 2.25.92
760
		string = brasero_project_get_sectors_string (project->priv->sectors,
761
							     !BRASERO_IS_DATA_DISC (project->priv->current));
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
762
763
		size_str = g_strdup_printf (_("Project estimated size: %s"), string);
764
		g_free (string);
765
766
		gtk_progress_bar_set_text (progress, size_str);
767
		g_free (size_str);
768
1.1.7 by Luis Medinas
Import upstream version 0.7.0
769
		return TRUE;
770
	}
771
772
	gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
773
	return FALSE;
774
}
775
776
static BraseroDiscResult
777
brasero_project_check_status (BraseroProject *project,
778
			      BraseroDisc *disc)
779
{
780
	int id;
781
	int answer;
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
782
	GtkWidget *box;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
783
	GtkWidget *dialog;
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
784
	gchar *current_task;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
785
	GtkWidget *progress;
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
786
	gint remaining = -1;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
787
	BraseroDiscResult result;
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
788
	GtkWidget *current_action;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
789
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
790
	current_task = NULL;
791
	result = brasero_disc_get_status (disc, &remaining, &current_task);
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
792
	if (result != BRASERO_DISC_NOT_READY && result != BRASERO_DISC_LOADING)
1.1.7 by Luis Medinas
Import upstream version 0.7.0
793
		return result;
794
795
	/* we are not ready to create tracks presumably because
796
	 * data or audio has not finished to explore a directory
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
797
	 * or get the metadata of a song or a film
798
	 */
1.1.7 by Luis Medinas
Import upstream version 0.7.0
799
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
800
	/* This dialog can run as a standalone window when run from nautilus
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
801
	 * to burn burn:// URI contents.
802
	 */
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
803
	dialog = brasero_app_dialog (brasero_app_get_default (),
1.1.17 by Pedro Fragoso
Import upstream version 2.25.90
804
				     _("Please wait until the estimation of the project size is completed."),
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
805
				     GTK_BUTTONS_CANCEL,
806
				     GTK_MESSAGE_OTHER);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
807
808
	gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
809
						  _("All files from the project need to be analysed to complete this operation."));
810
811
	gtk_window_set_title (GTK_WINDOW (dialog), _("Project Size Estimation"));
812
813
	box = gtk_vbox_new (FALSE, 4);
814
	gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dialog)->vbox),
815
			  box,
816
			  TRUE,
817
			  TRUE,
818
			  0);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
819
820
	progress = gtk_progress_bar_new ();
821
	gtk_progress_bar_set_text (GTK_PROGRESS_BAR (progress), " ");
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
822
	gtk_box_pack_start (GTK_BOX (box),
823
			    progress,
824
			    TRUE,
825
			    TRUE,
826
			    0);
827
828
	if (current_task) {
829
		gchar *string;
830
831
		string = g_strdup_printf ("<i>%s</i>", current_task);
832
		g_free (current_task);
833
834
		current_action = gtk_label_new (string);
835
		g_free (string);
836
	}
837
	else
838
		current_action = gtk_label_new ("");
839
840
	gtk_label_set_use_markup (GTK_LABEL (current_action), TRUE);
841
	gtk_misc_set_alignment (GTK_MISC (current_action), 0.0, 0.5);
842
	gtk_box_pack_start (GTK_BOX (box),
843
			    current_action,
844
			    FALSE,
845
			    TRUE,
846
			    0);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
847
848
	gtk_widget_show_all (dialog);
849
	gtk_progress_bar_pulse (GTK_PROGRESS_BAR (progress));
850
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
851
	g_object_set_data (G_OBJECT (dialog), "CurrentAction", current_action);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
852
	g_object_set_data (G_OBJECT (dialog), "ProgressBar", progress);
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
853
	g_object_set_data (G_OBJECT (dialog), "Remaining", GINT_TO_POINTER (remaining));
1.1.7 by Luis Medinas
Import upstream version 0.7.0
854
	g_object_set_data (G_OBJECT (dialog), "Project", project);
855
856
	id = g_timeout_add (100,
857
			    (GSourceFunc) _wait_for_ready_state,
858
		            dialog);
859
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
860
	project->priv->project_status = dialog;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
861
	answer = gtk_dialog_run (GTK_DIALOG (dialog));
862
	g_source_remove (id);
863
864
	gtk_widget_destroy (dialog);
865
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
866
	if (!project->priv->project_status)
867
		return BRASERO_DISC_CANCELLED;
868
869
	project->priv->project_status = NULL;
870
1.1.7 by Luis Medinas
Import upstream version 0.7.0
871
	if (answer != GTK_RESPONSE_OK)
872
		return BRASERO_DISC_CANCELLED;
873
	else if (project->priv->oversized)
874
		return BRASERO_DISC_ERROR_SIZE;
875
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
876
	return brasero_disc_get_status (disc, NULL, NULL);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
877
}
878
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
879
/******************************** cover ****************************************/
880
void
881
brasero_project_set_cover_specifics (BraseroProject *self,
882
				     BraseroJacketEdit *cover)
883
{
884
	BraseroBurnSession *session;
885
886
	if (!BRASERO_IS_AUDIO_DISC (self->priv->current))
887
		return;
888
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
889
	session = BRASERO_BURN_SESSION (brasero_session_cfg_new ());
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
890
	brasero_disc_set_session_param (BRASERO_DISC (self->priv->current), session);
891
	brasero_disc_set_session_contents (BRASERO_DISC (self->priv->current), session);
892
	brasero_jacket_edit_set_audio_tracks (BRASERO_JACKET_EDIT (cover),
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
893
					      gtk_entry_get_text (GTK_ENTRY (self->priv->name_display)),
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
894
					      self->priv->cover,
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
895
					      brasero_burn_session_get_tracks (session));
896
	g_object_unref (session);
897
}
898
1.1.7 by Luis Medinas
Import upstream version 0.7.0
899
/******************************** burning **************************************/
900
static void
901
brasero_project_no_song_dialog (BraseroProject *project)
902
{
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
903
	brasero_app_alert (brasero_app_get_default (),
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
904
			   _("Please add songs to the project."),
905
			   _("The project is empty"),
906
			   GTK_MESSAGE_WARNING);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
907
}
908
909
static void
910
brasero_project_no_file_dialog (BraseroProject *project)
911
{
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
912
	brasero_app_alert (brasero_app_get_default (),
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
913
			   _("Please add files to the project."),
914
			   _("The project is empty"),
915
			   GTK_MESSAGE_WARNING);
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
916
}
917
1.1.7 by Luis Medinas
Import upstream version 0.7.0
918
void
919
brasero_project_burn (BraseroProject *project)
920
{
921
	BraseroBurnSession *session;
922
	BraseroDiscResult result;
923
	GtkWidget *dialog;
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
924
	gboolean success;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
925
926
	result = brasero_project_check_status (project, project->priv->current);
927
	if (result == BRASERO_DISC_CANCELLED)
928
		return;
929
930
	if (result == BRASERO_DISC_ERROR_SIZE)
931
		return;
932
933
	if (result == BRASERO_DISC_ERROR_EMPTY_SELECTION) {
934
		if (BRASERO_IS_AUDIO_DISC (project->priv->current))
935
			brasero_project_no_song_dialog (project);
936
		else
937
			brasero_project_no_file_dialog (project);
938
939
		return;
940
	}
941
942
	if (result != BRASERO_DISC_OK)
943
		return;
944
945
	project->priv->is_burning = 1;
946
947
	/* This is to stop the preview widget from playing */
948
	brasero_uri_container_uri_selected (BRASERO_URI_CONTAINER (project));
949
950
	/* setup, show, and run options dialog */
951
	dialog = brasero_disc_option_dialog_new ();
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
952
953
	if (!brasero_app_is_running (brasero_app_get_default ())) {
954
		const gchar *label;
955
956
		/* Set the label for the session in the burn option dialog but
957
		 * only if we were started to burn a project (like through
958
		 * nautilus). */
959
		label = gtk_entry_get_text (GTK_ENTRY (project->priv->name_display));
960
961
		session = brasero_burn_options_get_session (BRASERO_BURN_OPTIONS (dialog));
962
		brasero_burn_session_set_label (session, label);
963
		g_object_unref (session);
964
	}
965
1.1.7 by Luis Medinas
Import upstream version 0.7.0
966
	brasero_disc_option_dialog_set_disc (BRASERO_DISC_OPTION_DIALOG (dialog),
967
					     project->priv->current);
968
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
969
	brasero_app_set_toplevel (brasero_app_get_default (), GTK_WINDOW (dialog));
1.1.7 by Luis Medinas
Import upstream version 0.7.0
970
971
	result = gtk_dialog_run (GTK_DIALOG (dialog));
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
972
	if (result != GTK_RESPONSE_OK) {
973
		gtk_widget_destroy (dialog);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
974
		goto end;
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
975
	}
1.1.7 by Luis Medinas
Import upstream version 0.7.0
976
977
	session = brasero_disc_option_dialog_get_session (BRASERO_DISC_OPTION_DIALOG (dialog));
978
	gtk_widget_destroy (dialog);
979
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
980
	if (brasero_app_is_running (brasero_app_get_default ())) {
981
		const gchar *label;
982
983
		/* Set the label for the session but only if we weren't started
984
		 * to burn a project (like through nautilus). */
985
		label = gtk_entry_get_text (GTK_ENTRY (project->priv->name_display));
986
		brasero_burn_session_set_label (session, label);
987
	}
1.1.7 by Luis Medinas
Import upstream version 0.7.0
988
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
989
	if (project->priv->cover) {
990
		GValue *value;
991
992
		value = g_new0 (GValue, 1);
993
		g_value_init (value, G_TYPE_STRING);
994
		g_value_set_string (value, project->priv->cover);
995
		brasero_burn_session_tag_add (session,
996
					      BRASERO_COVER_URI,
997
					      value);
998
	}
999
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1000
	/* now setup the burn dialog */
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
1001
	success = brasero_app_burn (brasero_app_get_default (), session);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1002
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1003
    	project->priv->burnt = success;
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1004
	g_object_unref (session);
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1005
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1006
end:
1007
1008
	project->priv->is_burning = 0;
1009
}
1010
1011
/********************************     ******************************************/
1012
static void
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
1013
brasero_project_switch (BraseroProject *project, BraseroProjectType type)
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1014
{
1015
	GtkAction *action;
1016
	GConfClient *client;
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1017
	
1018
	if (project->priv->project_status) {
1019
		gtk_widget_hide (project->priv->project_status);
1020
		gtk_dialog_response (GTK_DIALOG (project->priv->project_status),
1021
				     GTK_RESPONSE_CANCEL);
1022
		project->priv->project_status = NULL;
1023
	}
1024
1025
	if (project->priv->current)
1026
		brasero_disc_reset (project->priv->current);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1027
1028
	if (project->priv->chooser) {
1029
		gtk_widget_destroy (project->priv->chooser);
1030
		project->priv->chooser = NULL;
1031
	}
1032
1033
	project->priv->empty = 1;
1034
    	project->priv->burnt = 0;
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1035
	project->priv->merging = 0;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1036
	project->priv->modified = 0;
1037
1038
	if (project->priv->project) {
1039
		g_free (project->priv->project);
1040
		project->priv->project = NULL;
1041
	}
1042
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1043
	if (project->priv->cover) {
1044
		g_free (project->priv->cover);
1045
		project->priv->cover = NULL;
1046
	}
1047
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1048
	client = gconf_client_get_default ();
1049
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1050
	/* remove the buttons from the "toolbar" */
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1051
	if (project->priv->merge_id)
1052
		gtk_ui_manager_remove_ui (project->priv->manager,
1053
					  project->priv->merge_id);
1054
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
1055
	if (type == BRASERO_PROJECT_TYPE_AUDIO) {
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1056
		project->priv->current = BRASERO_DISC (project->priv->audio);
1057
		project->priv->merge_id = brasero_disc_add_ui (project->priv->current,
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1058
							       project->priv->manager,
1059
							       project->priv->message);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1060
1061
		gtk_notebook_set_current_page (GTK_NOTEBOOK (project->priv->discs), 0);
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1062
		brasero_project_update_project_size (project, 0);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1063
	}
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
1064
	else if (type == BRASERO_PROJECT_TYPE_DATA) {
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1065
		project->priv->current = BRASERO_DISC (project->priv->data);
1066
		project->priv->merge_id = brasero_disc_add_ui (project->priv->current,
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1067
							       project->priv->manager,
1068
							       project->priv->message);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1069
1070
		gtk_notebook_set_current_page (GTK_NOTEBOOK (project->priv->discs), 1);
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1071
		brasero_project_update_project_size (project, 0);
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
1072
	}
1073
	else if (type == BRASERO_PROJECT_TYPE_VIDEO) {
1074
		project->priv->current = BRASERO_DISC (project->priv->video);
1075
		project->priv->merge_id = brasero_disc_add_ui (project->priv->current,
1076
							       project->priv->manager,
1077
							       project->priv->message);
1078
1079
		gtk_notebook_set_current_page (GTK_NOTEBOOK (project->priv->discs), 2);
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1080
		brasero_project_update_project_size (project, 0);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1081
	}
1082
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1083
	brasero_notify_message_remove (BRASERO_NOTIFY (project->priv->message), BRASERO_NOTIFY_CONTEXT_SIZE);
1084
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1085
	/* update the menus */
1086
	action = gtk_action_group_get_action (project->priv->project_group, "Add");
1087
	gtk_action_set_visible (action, TRUE);
1088
	gtk_action_set_sensitive (action, TRUE);
1089
	action = gtk_action_group_get_action (project->priv->project_group, "DeleteProject");
1090
	gtk_action_set_visible (action, TRUE);
1091
	gtk_action_set_sensitive (action, FALSE);
1092
	action = gtk_action_group_get_action (project->priv->project_group, "DeleteAll");
1093
	gtk_action_set_visible (action, TRUE);
1094
	gtk_action_set_sensitive (action, FALSE);
1095
	action = gtk_action_group_get_action (project->priv->project_group, "SaveAs");
1096
	gtk_action_set_sensitive (action, TRUE);
1097
	action = gtk_action_group_get_action (project->priv->project_group, "Save");
1098
	gtk_action_set_sensitive (action, FALSE);
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1099
1100
	brasero_project_name_set_type (BRASERO_PROJECT_NAME (project->priv->name_display), type);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1101
}
1102
1103
void
1104
brasero_project_set_audio (BraseroProject *project, GSList *uris)
1105
{
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
1106
	brasero_project_switch (project, BRASERO_PROJECT_TYPE_AUDIO);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1107
1108
	for (; uris; uris = uris->next) {
1109
		gchar *uri;
1110
1111
	    	uri = uris->data;
1112
		brasero_disc_add_uri (project->priv->current, uri);
1113
	}
1114
}
1115
1116
void
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1117
brasero_project_set_data (BraseroProject *project,
1118
			  GSList *uris)
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1119
{
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
1120
	brasero_project_switch (project, BRASERO_PROJECT_TYPE_DATA);
1121
1122
	for (; uris; uris = uris->next) {
1123
		gchar *uri;
1124
1125
	    	uri = uris->data;
1126
		brasero_disc_add_uri (project->priv->current, uri);
1127
	}
1128
}
1129
1130
void
1131
brasero_project_set_video (BraseroProject *project, GSList *uris)
1132
{
1133
	brasero_project_switch (project, BRASERO_PROJECT_TYPE_VIDEO);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1134
1135
	for (; uris; uris = uris->next) {
1136
		gchar *uri;
1137
1138
	    	uri = uris->data;
1139
		brasero_disc_add_uri (project->priv->current, uri);
1140
	}
1141
}
1142
1143
gboolean
1144
brasero_project_confirm_switch (BraseroProject *project)
1145
{
1146
	GtkWidget *dialog;
1147
	GtkResponseType answer;
1148
1149
	if (project->priv->project) {
1150
		if (!project->priv->modified)
1151
			return TRUE;
1152
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
1153
		dialog = brasero_app_dialog (brasero_app_get_default (),
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1154
					     _("Do you really want to create a new project and discard the changes to current one?"),
1155
					     GTK_BUTTONS_CANCEL,
1156
					     GTK_MESSAGE_WARNING);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1157
1158
		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1159
							  _("If you choose to create a new project, all changes made will be lost."));
1160
		gtk_dialog_add_button (GTK_DIALOG (dialog),
1161
				       _("_Discard Changes"), GTK_RESPONSE_OK);
1162
1163
	}
1164
	else {
1165
		if (project->priv->empty)
1166
			return TRUE;
1167
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
1168
		dialog = brasero_app_dialog (brasero_app_get_default (),
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1169
					     _("Do you really want to create a new project and discard the current one?"),
1170
					     GTK_BUTTONS_CANCEL,
1171
					     GTK_MESSAGE_WARNING);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1172
1173
		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1174
							  _("If you choose to create a new project, "
1175
							    "all files already added will be discarded. "
1176
							    "Note that files will not be deleted from their own location, "
1177
							    "just no longer listed here."));
1178
		gtk_dialog_add_button (GTK_DIALOG (dialog),
1179
				       _("_Discard Project"), GTK_RESPONSE_OK);
1180
	}
1181
1182
	answer = gtk_dialog_run (GTK_DIALOG (dialog));
1183
	gtk_widget_destroy (dialog);
1184
1185
	if (answer != GTK_RESPONSE_OK)
1186
		return FALSE;
1187
1188
	return TRUE;
1189
}
1190
1191
void
1192
brasero_project_set_none (BraseroProject *project)
1193
{
1194
	GtkAction *action;
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1195
	GtkWidget *status;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1196
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1197
	if (project->priv->project_status) {
1198
		gtk_widget_hide (project->priv->project_status);
1199
		gtk_dialog_response (GTK_DIALOG (project->priv->project_status),
1200
				     GTK_RESPONSE_CANCEL);
1201
		project->priv->project_status = NULL;
1202
	}
1203
1204
	if (project->priv->chooser) {
1205
		gtk_widget_destroy (project->priv->chooser);
1206
		project->priv->chooser = NULL;
1207
	}
1208
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1209
	if (project->priv->project) {
1210
		g_free (project->priv->project);
1211
		project->priv->project = NULL;
1212
	}
1213
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1214
	if (project->priv->cover) {
1215
		g_free (project->priv->cover);
1216
		project->priv->cover = NULL;
1217
	}
1218
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1219
	if (project->priv->chooser) {
1220
		gtk_widget_destroy (project->priv->chooser);
1221
		project->priv->chooser = NULL;
1222
	}
1223
1224
	if (project->priv->current)
1225
		brasero_disc_reset (project->priv->current);
1226
1227
	project->priv->current = NULL;
1228
1229
	/* update buttons/menus */
1230
	action = gtk_action_group_get_action (project->priv->project_group, "Add");
1231
	gtk_action_set_visible (action, FALSE);
1232
	action = gtk_action_group_get_action (project->priv->project_group, "DeleteProject");
1233
	gtk_action_set_visible (action, FALSE);
1234
	action = gtk_action_group_get_action (project->priv->project_group, "DeleteAll");
1235
	gtk_action_set_visible (action, FALSE);
1236
	action = gtk_action_group_get_action (project->priv->project_group, "SaveAs");
1237
	gtk_action_set_sensitive (action, FALSE);
1238
	action = gtk_action_group_get_action (project->priv->project_group, "Save");
1239
	gtk_action_set_sensitive (action, FALSE);
1240
1241
	if (project->priv->merge_id)
1242
		gtk_ui_manager_remove_ui (project->priv->manager,
1243
					  project->priv->merge_id);
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1244
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
1245
	status = brasero_app_get_statusbar2 (brasero_app_get_default ());
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1246
1247
	if (project->priv->status_ctx)
1248
		gtk_statusbar_pop (GTK_STATUSBAR (status), project->priv->status_ctx);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1249
}
1250
1251
/********************* update the appearance of menus and buttons **************/
1252
static void
1253
brasero_project_contents_changed_cb (BraseroDisc *disc,
1254
				     gint nb_files,
1255
				     BraseroProject *project)
1256
{
1257
	GtkAction *action;
1258
	gboolean sensitive;
1259
1260
	project->priv->empty = (nb_files == 0);
1261
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1262
	if (brasero_disc_get_status (disc, NULL, NULL) != BRASERO_DISC_LOADING)
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1263
		project->priv->modified = 1;
1264
1265
	brasero_project_set_remove_button_state (project);
1266
	brasero_project_set_add_button_state (project);
1267
1268
	action = gtk_action_group_get_action (project->priv->project_group, "DeleteAll");
1269
	gtk_action_set_sensitive (action, (project->priv->empty == FALSE));
1270
1271
	/* the following button/action states depend on the project size too */
1272
	sensitive = (project->priv->oversized == 0 &&
1273
		     project->priv->empty == 0);
1274
1275
	action = gtk_action_group_get_action (project->priv->project_group, "Burn");
1276
	gtk_action_set_sensitive (action, sensitive);
1277
	gtk_widget_set_sensitive (project->priv->burn, sensitive);
1278
1279
	/* the state of the following depends on the existence of an opened project */
1280
	action = gtk_action_group_get_action (project->priv->project_group, "Save");
1281
	if (project->priv->modified)
1282
		gtk_action_set_sensitive (action, TRUE);
1283
	else
1284
		gtk_action_set_sensitive (action, FALSE);
1285
}
1286
1287
/**************************** manage the relations with the sources ************/
1288
static void
1289
brasero_project_transfer_uris_from_src (BraseroProject *project)
1290
{
1291
	gchar **uris;
1292
	gchar **uri;
1293
1294
	if (!project->priv->current_source)
1295
		return;
1296
1297
	uris = brasero_uri_container_get_selected_uris (project->priv->current_source);
1298
	if (!uris)
1299
		return;
1300
1301
	uri = uris;
1302
	while (*uri) {
1303
		brasero_disc_add_uri (project->priv->current, *uri);
1304
		uri ++;
1305
	}
1306
1307
	g_strfreev (uris);
1308
}
1309
1310
static void
1311
brasero_project_source_uri_activated_cb (BraseroURIContainer *container,
1312
					 BraseroProject *project)
1313
{
1314
	brasero_project_transfer_uris_from_src (project);
1315
}
1316
1317
static void
1318
brasero_project_source_uri_selected_cb (BraseroURIContainer *container,
1319
					BraseroProject *project)
1320
{
1321
	brasero_project_set_add_button_state (project);
1322
}
1323
1324
void
1325
brasero_project_set_source (BraseroProject *project,
1326
			    BraseroURIContainer *source)
1327
{
1328
	if (project->priv->activated_id) {
1329
		g_signal_handler_disconnect (project->priv->current_source,
1330
					     project->priv->activated_id);
1331
		project->priv->activated_id = 0;
1332
	}
1333
1334
	if (project->priv->selected_id) {
1335
		g_signal_handler_disconnect (project->priv->current_source,
1336
					     project->priv->selected_id);
1337
		project->priv->selected_id = 0;
1338
	}
1339
1340
	project->priv->current_source = source;
1341
1342
	if (source) {
1343
		project->priv->activated_id = g_signal_connect (source,
1344
							        "uri-activated",
1345
							        G_CALLBACK (brasero_project_source_uri_activated_cb),
1346
							        project);
1347
		project->priv->selected_id = g_signal_connect (source,
1348
							       "uri-selected",
1349
							       G_CALLBACK (brasero_project_source_uri_selected_cb),
1350
							       project);
1351
	}
1352
1353
	brasero_project_set_add_button_state (project);
1354
}
1355
1356
/******************************* menus/buttons *********************************/
1357
static void
1358
brasero_project_save_cb (GtkAction *action, BraseroProject *project)
1359
{
1360
	brasero_project_save_project (project);
1361
}
1362
1363
static void
1364
brasero_project_save_as_cb (GtkAction *action, BraseroProject *project)
1365
{
1366
	brasero_project_save_project_as (project);
1367
}
1368
1369
static void
1370
brasero_project_file_chooser_activated_cb (GtkWidget *chooser,
1371
					   BraseroProject *project)
1372
{
1373
	GSList *uris;
1374
	GSList *iter;
1375
1376
	uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (chooser));
1377
	for (iter = uris; iter; iter = iter->next) {
1378
		gchar *uri;
1379
1380
		uri = iter->data;
1381
		brasero_disc_add_uri (project->priv->current, uri);
1382
	}
1383
	g_slist_foreach (uris, (GFunc) g_free, NULL);
1384
	g_slist_free (uris);
1385
1386
	gtk_widget_destroy (GTK_WIDGET (project->priv->chooser));
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1387
	project->priv->chooser = NULL;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1388
}
1389
1390
static void
1391
brasero_project_file_chooser_response_cb (GtkWidget *chooser,
1392
					  GtkResponseType response,
1393
					  BraseroProject *project)
1394
{
1395
	GSList *uris;
1396
	GSList *iter;
1397
1.1.12 by Pedro Fragoso
Import upstream version 0.8.2
1398
	if (response != BRASERO_RESPONSE_ADD) {
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1399
		gtk_widget_destroy (chooser);
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1400
		project->priv->chooser = NULL;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1401
		return;
1402
	}
1403
1404
	uris = gtk_file_chooser_get_uris (GTK_FILE_CHOOSER (chooser));
1405
	for (iter = uris; iter; iter = iter->next) {
1406
		gchar *uri;
1407
1408
		uri = iter->data;
1409
		brasero_disc_add_uri (project->priv->current, uri);
1410
	}
1411
	g_slist_foreach (uris, (GFunc) g_free, NULL);
1412
	g_slist_free (uris);
1413
1414
	gtk_widget_destroy (GTK_WIDGET (project->priv->chooser));
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1415
	project->priv->chooser = NULL;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1416
}
1417
1418
static void
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1419
brasero_project_preview_ready (BraseroPlayer *player,
1420
			       GtkFileChooser *chooser)
1421
{
1422
	gtk_file_chooser_set_preview_widget_active (chooser, TRUE);
1423
}
1424
1425
static void
1426
brasero_project_update_preview (GtkFileChooser *chooser,
1427
				BraseroPlayer *player)
1428
{
1429
	gchar *uri;
1430
1431
	gtk_file_chooser_set_preview_widget_active (chooser, FALSE);
1432
1433
	uri = gtk_file_chooser_get_preview_uri (chooser);
1434
	brasero_player_set_uri (player, uri);
1435
	g_free (uri);
1436
}
1437
1438
static void
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1439
brasero_project_add_uris_cb (GtkAction *action,
1440
			     BraseroProject *project)
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1441
{
1442
	GtkWidget *toplevel;
1443
	GtkFileFilter *filter;
1444
1445
	if (project->priv->current_source) {
1446
		brasero_project_transfer_uris_from_src (project);
1447
		return;
1448
	}
1449
1450
	toplevel = gtk_widget_get_toplevel (GTK_WIDGET (project));
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1451
	project->priv->chooser = gtk_file_chooser_dialog_new (_("Select Files"),
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1452
							      GTK_WINDOW (toplevel),
1453
							      GTK_FILE_CHOOSER_ACTION_OPEN,
1454
							      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1455
							      NULL);
1456
	gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (project->priv->chooser), TRUE);
1457
	gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (project->priv->chooser), TRUE);
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1458
	gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (project->priv->chooser), g_get_home_dir ());
1459
	brasero_file_chooser_customize (project->priv->chooser, NULL);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1460
	gtk_widget_show (project->priv->chooser);
1461
1.1.12 by Pedro Fragoso
Import upstream version 0.8.2
1462
	/* This is to work around a bug in GTK+ which doesn't want to add "Add"
1463
	 * button or anything that is not "Open" or "Cancel" buttons */
1464
	/* Just for the record, file chooser creation uses all GtkResponseType
1465
	 * that are already defined for internal use like GTK_RESPONSE_OK,
1466
	 * *_APPLY and so on (usually to open directories, not add them). So we
1467
	 * have to define on custom here. */
1468
	gtk_dialog_add_button (GTK_DIALOG (project->priv->chooser),
1469
			       GTK_STOCK_ADD,
1470
			       BRASERO_RESPONSE_ADD);
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1471
	gtk_dialog_set_default_response (GTK_DIALOG (project->priv->chooser),
1472
					 BRASERO_RESPONSE_ADD);
1.1.12 by Pedro Fragoso
Import upstream version 0.8.2
1473
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1474
	g_signal_connect (project->priv->chooser,
1475
			  "file-activated",
1476
			  G_CALLBACK (brasero_project_file_chooser_activated_cb),
1477
			  project);
1478
	g_signal_connect (project->priv->chooser,
1479
			  "response",
1480
			  G_CALLBACK (brasero_project_file_chooser_response_cb),
1481
			  project);
1482
	g_signal_connect (project->priv->chooser,
1483
			  "close",
1484
			  G_CALLBACK (brasero_project_file_chooser_activated_cb),
1485
			  project);
1486
1487
	filter = gtk_file_filter_new ();
1488
	gtk_file_filter_set_name (filter, _("All files"));
1489
	gtk_file_filter_add_pattern (filter, "*");
1490
	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (project->priv->chooser), filter);
1491
1492
	filter = gtk_file_filter_new ();
1493
	gtk_file_filter_set_name (filter, _("Audio files only"));
1494
	gtk_file_filter_add_mime_type (filter, "audio/*");
1495
	gtk_file_filter_add_mime_type (filter, "application/ogg");
1496
	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (project->priv->chooser), filter);
1497
1498
	if (BRASERO_IS_AUDIO_DISC (project->priv->current))
1499
		gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (project->priv->chooser), filter);
1500
1501
	filter = gtk_file_filter_new ();
1502
	gtk_file_filter_set_name (filter, _("Movies only"));
1503
	gtk_file_filter_add_mime_type (filter, "video/*");
1504
	gtk_file_filter_add_mime_type (filter, "application/ogg");
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1505
	gtk_file_filter_add_mime_type (filter, "application/x-flash-video");
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1506
	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (project->priv->chooser), filter);
1507
1508
	filter = gtk_file_filter_new ();
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1509
	/* Translators: this is an image, a picture, not a "Disc Image" */
1.1.20 by Pedro Fragoso
Import upstream version 2.25.92
1510
	gtk_file_filter_set_name (filter, C_("picture", "Image files only"));
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1511
	gtk_file_filter_add_mime_type (filter, "image/*");
1512
	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (project->priv->chooser), filter);
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1513
1514
#ifdef BUILD_PREVIEW
1515
1516
	GConfClient *client;
1517
	GtkWidget *player;
1518
	gboolean res;
1519
1520
	client = gconf_client_get_default ();
1521
	res = gconf_client_get_bool (client, BRASERO_KEY_SHOW_PREVIEW, NULL);
1522
	g_object_unref (client);
1523
1524
	if (!res)
1525
		return;
1526
1527
	/* if preview is activated add it */
1528
	player = brasero_player_new ();
1529
1530
	gtk_widget_show (player);
1531
	gtk_file_chooser_set_preview_widget_active (GTK_FILE_CHOOSER (project->priv->chooser), FALSE);
1532
	gtk_file_chooser_set_use_preview_label (GTK_FILE_CHOOSER (project->priv->chooser), FALSE);
1533
	gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER (project->priv->chooser), player);
1534
1535
	g_signal_connect (project->priv->chooser,
1536
			  "update-preview",
1537
			  G_CALLBACK (brasero_project_update_preview),
1538
			  player);
1539
1540
	g_signal_connect (player,
1541
			  "ready",
1542
			  G_CALLBACK (brasero_project_preview_ready),
1543
			  project->priv->chooser);
1544
#endif
1545
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1546
}
1547
1548
static void
1549
brasero_project_remove_selected_uris_cb (GtkAction *action, BraseroProject *project)
1550
{
1551
	brasero_disc_delete_selected (BRASERO_DISC (project->priv->current));
1552
}
1553
1554
static void
1555
brasero_project_empty_cb (GtkAction *action, BraseroProject *project)
1556
{
1557
	if (!project->priv->empty) {
1558
		GtkWidget *dialog;
1559
		GtkResponseType answer;
1560
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
1561
		dialog = brasero_app_dialog (brasero_app_get_default (),
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1562
					      _("Do you really want to empty the current project?"),
1563
					     GTK_BUTTONS_CANCEL,
1564
					     GTK_MESSAGE_WARNING);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1565
1566
		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1567
							  _("Emptying a project will remove all files already added. "
1568
							    "All the work will be lost. "
1569
							    "Note that files will not be deleted from their own location, "
1570
							    "just no longer listed here."));
1571
		gtk_dialog_add_button (GTK_DIALOG (dialog),
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1572
					/* Translators: "empty" is a verb here */
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1573
				       _("E_mpty Project"),
1574
				       GTK_RESPONSE_OK);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1575
1576
		answer = gtk_dialog_run (GTK_DIALOG (dialog));
1577
		gtk_widget_destroy (dialog);
1578
1579
		if (answer != GTK_RESPONSE_OK)
1580
			return;
1581
	}
1582
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
1583
	brasero_disc_clear (BRASERO_DISC (project->priv->current));
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1584
}
1585
1586
static void
1587
brasero_project_burn_cb (GtkAction *action, BraseroProject *project)
1588
{
1589
	brasero_project_burn (project);
1590
}
1591
1592
static void
1593
brasero_project_burn_clicked_cb (GtkButton *button, BraseroProject *project)
1594
{
1595
	brasero_project_burn (project);
1596
}
1597
1598
void
1599
brasero_project_register_ui (BraseroProject *project, GtkUIManager *manager)
1600
{
1601
	GError *error = NULL;
1602
	GtkAction *action;
1603
1604
	/* menus */
1605
	project->priv->project_group = gtk_action_group_new ("ProjectActions1");
1606
	gtk_action_group_set_translation_domain (project->priv->project_group, GETTEXT_PACKAGE);
1607
	gtk_action_group_add_actions (project->priv->project_group,
1608
				      entries,
1609
				      G_N_ELEMENTS (entries),
1610
				      project);
1611
1612
	gtk_ui_manager_insert_action_group (manager, project->priv->project_group, 0);
1613
	if (!gtk_ui_manager_add_ui_from_string (manager,
1614
						description,
1615
						-1,
1616
						&error)) {
1617
		g_message ("building menus/toolbar failed: %s", error->message);
1618
		g_error_free (error);
1619
	}
1620
	
1621
	action = gtk_action_group_get_action (project->priv->project_group, "Save");
1622
	g_object_set (action,
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1623
		      "short-label", _("_Save"), /* for toolbar buttons */
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1624
		      NULL);
1625
	gtk_action_set_sensitive (action, FALSE);
1626
	action = gtk_action_group_get_action (project->priv->project_group, "SaveAs");
1627
	gtk_action_set_sensitive (action, FALSE);
1628
1629
	action = gtk_action_group_get_action (project->priv->project_group, "Burn");
1630
	gtk_action_set_sensitive (action, FALSE);
1631
	action = gtk_action_group_get_action (project->priv->project_group, "Add");
1632
	gtk_action_set_sensitive (action, FALSE);
1633
	g_object_set (action,
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1634
		      "short-label", _("_Add"), /* for toolbar buttons */
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1635
		      NULL);
1636
	action = gtk_action_group_get_action (project->priv->project_group, "DeleteProject");
1637
	gtk_action_set_sensitive (action, FALSE);
1638
	g_object_set (action,
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1639
		      "short-label", _("_Remove"), /* for toolbar buttons */
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1640
		      NULL);
1641
	action = gtk_action_group_get_action (project->priv->project_group, "DeleteAll");
1642
	gtk_action_set_sensitive (action, FALSE);
1643
1644
	project->priv->manager = manager;
1645
}
1646
1647
/******************************* common to save/open ***************************/
1648
static void
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1649
brasero_project_add_to_recents (BraseroProject *project,
1650
				const gchar *uri,
1651
				gboolean is_project)
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1652
{
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1653
   	GtkRecentManager *recent;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1654
	gchar *groups [] = { "brasero", NULL };
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1655
	gchar *open_playlist = "brasero -l %u";
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1656
	GtkRecentData recent_data = { NULL,
1657
				      NULL,
1658
				      "application/x-brasero",
1659
				      "brasero",
1660
				      "brasero -p %u",
1661
				      groups,
1662
				      FALSE };
1663
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1664
    	recent = gtk_recent_manager_get_default ();
1665
1666
	if (is_project)
1667
		recent_data.app_exec = open_playlist;
1668
1669
    	gtk_recent_manager_add_full (recent, uri, &recent_data);
1670
}
1671
1672
static void
1673
brasero_project_set_uri (BraseroProject *project,
1674
			 const gchar *uri,
1675
			 BraseroProjectType type)
1676
{
1677
     	gchar *name;
1678
	gchar *title;
1679
	GtkAction *action;
1680
	GtkWidget *toplevel;
1681
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1682
	/* possibly reset the name of the project */
1683
	if (uri) {
1684
		if (project->priv->project)
1685
			g_free (project->priv->project);
1686
1687
		project->priv->project = g_strdup (uri);
1688
	}
1689
1690
	uri = uri ? uri : project->priv->project;
1691
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1692
	/* add it to recent manager */
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
1693
	if (brasero_app_is_running (brasero_app_get_default ()))
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1694
		brasero_project_add_to_recents (project, uri, TRUE);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1695
1696
	/* update the name of the main window */
1697
    	BRASERO_GET_BASENAME_FOR_DISPLAY (uri, name);
1698
	if (type == BRASERO_PROJECT_TYPE_DATA)
1.1.20 by Pedro Fragoso
Import upstream version 2.25.92
1699
		/* Translators: %s is the name of the project */
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1700
		title = g_strdup_printf (_("Brasero - %s (Data Disc)"), name);
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
1701
	else if (type == BRASERO_PROJECT_TYPE_AUDIO)
1.1.20 by Pedro Fragoso
Import upstream version 2.25.92
1702
		/* Translators: %s is the name of the project */
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1703
		title = g_strdup_printf (_("Brasero - %s (Audio Disc)"), name);
1.1.16 by Pedro Fragoso
Import upstream version 0.9.1
1704
	else if (type == BRASERO_PROJECT_TYPE_VIDEO)
1.1.20 by Pedro Fragoso
Import upstream version 2.25.92
1705
		/* Translators: %s is the name of the project */
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
1706
		title = g_strdup_printf (_("Brasero - %s (Video Disc)"), name);
1707
	else
1708
		title = NULL;
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1709
 
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
1710
	g_free (name);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1711
1.1.16 by Pedro Fragoso
Import upstream version 0.9.1
1712
	toplevel = gtk_widget_get_toplevel (GTK_WIDGET (project));
1713
	if (toplevel)
1714
		gtk_window_set_title (GTK_WINDOW (toplevel), title);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1715
	g_free (title);
1716
1717
	/* update the menus */
1718
	action = gtk_action_group_get_action (project->priv->project_group, "Save");
1719
	gtk_action_set_sensitive (action, FALSE);
1720
}
1721
1722
/******************************* Projects **************************************/
1723
BraseroProjectType
1724
brasero_project_open_project (BraseroProject *project,
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1725
			      BraseroDiscTrack *track,
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1726
			      const gchar *uri)	/* escaped */
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1727
{
1728
	BraseroProjectType type;
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1729
1730
	if (!track)
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1731
		return BRASERO_PROJECT_TYPE_INVALID;
1732
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1733
	brasero_project_update_project_size (project, 0);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1734
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1735
	if (track->type == BRASERO_PROJECT_TYPE_AUDIO)
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1736
		type = BRASERO_PROJECT_TYPE_AUDIO;
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1737
	else if (track->type == BRASERO_PROJECT_TYPE_DATA)
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1738
		type = BRASERO_PROJECT_TYPE_DATA;
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1739
	else if (track->type == BRASERO_PROJECT_TYPE_VIDEO)
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
1740
		type = BRASERO_PROJECT_TYPE_VIDEO;
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1741
	else
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1742
		return BRASERO_PROJECT_TYPE_INVALID;
1743
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
1744
	brasero_project_switch (project, type);
1745
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1746
	if (track->label) {
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1747
		g_signal_handlers_block_by_func (project->priv->name_display,
1748
						 brasero_project_name_changed_cb,
1749
						 project);
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1750
		gtk_entry_set_text (GTK_ENTRY (project->priv->name_display), track->label);
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1751
		g_signal_handlers_unblock_by_func (project->priv->name_display,
1752
						   brasero_project_name_changed_cb,
1753
						   project);
1754
	}
1755
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1756
	if (track->cover) {
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1757
		if (project->priv->cover)
1758
			g_free (project->priv->cover);
1759
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1760
		project->priv->cover = g_strdup (track->cover);
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1761
	}
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1762
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1763
	brasero_disc_load_track (project->priv->current, track);
1764
	project->priv->modified = 0;
1765
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1766
	if (uri)
1767
		brasero_project_set_uri (project, uri, type);
1768
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
1769
	return type;
1770
}
1771
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1772
BraseroProjectType
1773
brasero_project_load_session (BraseroProject *project, const gchar *uri)
1774
{
1775
	BraseroDiscTrack *track = NULL;
1776
	BraseroProjectType type;
1777
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1778
	if (!brasero_project_open_project_xml (uri, &track, FALSE))
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1779
		return BRASERO_PROJECT_TYPE_INVALID;
1780
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1781
	if (track->type == BRASERO_PROJECT_TYPE_AUDIO)
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1782
		type = BRASERO_PROJECT_TYPE_AUDIO;
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1783
	else if (track->type == BRASERO_PROJECT_TYPE_DATA)
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1784
		type = BRASERO_PROJECT_TYPE_DATA;
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1785
	else if (track->type == BRASERO_PROJECT_TYPE_VIDEO)
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
1786
		type = BRASERO_PROJECT_TYPE_VIDEO;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1787
	else {
1788
	    	brasero_track_free (track);
1789
		return BRASERO_PROJECT_TYPE_INVALID;
1790
	}
1791
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
1792
	brasero_project_switch (project, type);
1793
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1794
	g_signal_handlers_block_by_func (project->priv->name_display,
1795
					 brasero_project_name_changed_cb,
1796
					 project);
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
1797
	gtk_entry_set_text (GTK_ENTRY (project->priv->name_display), (gchar *) track->label);
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1798
	g_signal_handlers_unblock_by_func (project->priv->name_display,
1799
					   brasero_project_name_changed_cb,
1800
					   project);
1801
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1802
	brasero_disc_load_track (project->priv->current, track);
1803
	brasero_track_free (track);
1804
1805
	project->priv->modified = 0;
1806
1807
    	return type;
1808
}
1809
1810
/******************************** save project *********************************/
1811
static void
1812
brasero_project_not_saved_dialog (BraseroProject *project)
1813
{
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
1814
	xmlError *error;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1815
1816
	error = xmlGetLastError ();
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
1817
	brasero_app_alert (brasero_app_get_default (),
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1818
			   _("Your project has not been saved."),
1819
			   error? error->message:_("An unknown error occured"),
1820
			   GTK_MESSAGE_ERROR);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1821
	xmlResetLastError ();
1822
}
1823
1824
static GtkResponseType
1825
brasero_project_save_project_dialog (BraseroProject *project,
1826
				     gboolean show_cancel)
1827
{
1828
	GtkWidget *dialog;
1829
	GtkResponseType result;
1830
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
1831
	dialog = brasero_app_dialog (brasero_app_get_default (),
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1832
				     _("Save the changes of current project before closing?"),
1833
				     GTK_BUTTONS_NONE,
1834
				     GTK_MESSAGE_WARNING);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1835
1836
	gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1837
						  _("If you don't save, changes will be permanently lost."));
1838
1839
	if (show_cancel)
1840
		gtk_dialog_add_buttons (GTK_DIALOG (dialog),
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1841
					_("Cl_ose Without Saving"), GTK_RESPONSE_NO,
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1842
					GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1843
					GTK_STOCK_SAVE, GTK_RESPONSE_YES,
1844
					NULL);
1845
	else
1846
		gtk_dialog_add_buttons (GTK_DIALOG (dialog),
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1847
					_("Cl_ose Without Saving"), GTK_RESPONSE_NO,
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1848
					GTK_STOCK_SAVE, GTK_RESPONSE_YES,
1849
					NULL);
1850
1851
	result = gtk_dialog_run (GTK_DIALOG (dialog));
1852
	gtk_widget_destroy (dialog);
1853
1854
	if (result == GTK_RESPONSE_CANCEL)
1855
		return GTK_RESPONSE_CANCEL;
1856
1857
	if (show_cancel && result == GTK_RESPONSE_DELETE_EVENT)
1858
		return GTK_RESPONSE_CANCEL;
1859
1860
	if (result != GTK_RESPONSE_YES)
1861
		return GTK_RESPONSE_NO;
1862
1863
	return GTK_RESPONSE_YES;
1864
}
1865
1866
static gboolean
1867
_save_audio_track_xml (xmlTextWriter *project,
1868
		       BraseroDiscTrack *track)
1869
{
1870
	GSList *iter;
1871
	gint success;
1872
1873
	for (iter = track->contents.tracks; iter; iter = iter->next) {
1874
		BraseroDiscSong *song;
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1875
		BraseroSongInfo *info;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1876
		xmlChar *escaped;
1877
		gchar *start;
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1878
		gchar *isrc;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1879
		gchar *end;
1880
1881
		song = iter->data;
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1882
		info = song->info;
1883
1.1.12 by Pedro Fragoso
Import upstream version 0.8.2
1884
		escaped = (unsigned char *) g_uri_escape_string (song->uri, NULL, FALSE);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1885
		success = xmlTextWriterWriteElement (project,
1886
						    (xmlChar *) "uri",
1887
						     escaped);
1888
		g_free (escaped);
1889
1890
		if (success == -1)
1891
			return FALSE;
1892
1893
		if (song->gap) {
1894
			gchar *silence;
1895
1896
			silence = g_strdup_printf ("%"G_GINT64_FORMAT, song->gap);
1897
			success = xmlTextWriterWriteElement (project,
1898
							     (xmlChar *) "silence",
1899
							     (xmlChar *) silence);
1900
1901
			g_free (silence);
1902
			if (success == -1)
1903
				return FALSE;
1904
		}
1905
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
1906
		if (song->end > 0) {
1907
			/* start of the song */
1908
			start = g_strdup_printf ("%"G_GINT64_FORMAT, song->start);
1909
			success = xmlTextWriterWriteElement (project,
1910
							     (xmlChar *) "start",
1911
							     (xmlChar *) start);
1912
1913
			g_free (start);
1914
			if (success == -1)
1915
				return FALSE;
1916
1917
			/* end of the song */
1918
			end = g_strdup_printf ("%"G_GINT64_FORMAT, song->end);
1919
			success = xmlTextWriterWriteElement (project,
1920
							     (xmlChar *) "end",
1921
							     (xmlChar *) end);
1922
1923
			g_free (end);
1924
			if (success == -1)
1925
				return FALSE;
1926
		}
1927
1928
		if (!info)
1929
			continue;
1930
1931
		if (info->title) {
1932
			escaped = (unsigned char *) g_uri_escape_string (info->title, NULL, FALSE);
1933
			success = xmlTextWriterWriteElement (project,
1934
							    (xmlChar *) "title",
1935
							     escaped);
1936
			g_free (escaped);
1937
1938
			if (success == -1)
1939
				return FALSE;
1940
		}
1941
1942
		if (info->artist) {
1943
			escaped = (unsigned char *) g_uri_escape_string (info->artist, NULL, FALSE);
1944
			success = xmlTextWriterWriteElement (project,
1945
							    (xmlChar *) "artist",
1946
							     escaped);
1947
			g_free (escaped);
1948
1949
			if (success == -1)
1950
				return FALSE;
1951
		}
1952
1953
		if (info->composer) {
1954
			escaped = (unsigned char *) g_uri_escape_string (info->composer, NULL, FALSE);
1955
			success = xmlTextWriterWriteElement (project,
1956
							    (xmlChar *) "composer",
1957
							     escaped);
1958
			g_free (escaped);
1959
1960
			if (success == -1)
1961
				return FALSE;
1962
		}
1963
1964
		if (info->isrc) {
1965
			isrc = g_strdup_printf ("%d", info->isrc);
1966
			success = xmlTextWriterWriteElement (project,
1967
							     (xmlChar *) "isrc",
1968
							     (xmlChar *) isrc);
1969
1970
			g_free (isrc);
1971
			if (success == -1)
1972
				return FALSE;
1973
		}
1.1.7 by Luis Medinas
Import upstream version 0.7.0
1974
	}
1975
1976
	return TRUE;
1977
}
1978
1979
static gboolean
1980
_save_data_track_xml (xmlTextWriter *project,
1981
		      BraseroDiscTrack *track)
1982
{
1983
	gchar *uri;
1984
	gint success;
1985
	GSList *iter;
1986
	GSList *grafts;
1987
	BraseroGraftPt *graft;
1988
1989
	for (grafts = track->contents.data.grafts; grafts; grafts = grafts->next) {
1990
		graft = grafts->data;
1991
1992
		success = xmlTextWriterStartElement (project, (xmlChar *) "graft");
1993
		if (success < 0)
1994
			return FALSE;
1995
1996
		success = xmlTextWriterWriteElement (project, (xmlChar *) "path", (xmlChar *) graft->path);
1997
		if (success < 0)
1998
			return FALSE;
1999
2000
		if (graft->uri) {
2001
			xmlChar *escaped;
2002
1.1.12 by Pedro Fragoso
Import upstream version 0.8.2
2003
			escaped = (unsigned char *) g_uri_escape_string (graft->uri, NULL, FALSE);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2004
			success = xmlTextWriterWriteElement (project, (xmlChar *) "uri", escaped);
2005
			g_free (escaped);
2006
			if (success < 0)
2007
				return FALSE;
2008
		}
2009
2010
		success = xmlTextWriterEndElement (project); /* graft */
2011
		if (success < 0)
2012
			return FALSE;
2013
	}
2014
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2015
	/* save excluded uris */
2016
	for (iter = track->contents.data.excluded; iter; iter = iter->next) {
2017
		xmlChar *escaped;
2018
2019
		escaped = xmlURIEscapeStr ((xmlChar *) iter->data, NULL);
2020
		success = xmlTextWriterWriteElement (project, (xmlChar *) "excluded", (xmlChar *) escaped);
2021
		g_free (escaped);
2022
		if (success < 0)
2023
			return FALSE;
2024
	}
2025
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2026
	/* save restored uris */
2027
	for (iter = track->contents.data.restored; iter; iter = iter->next) {
2028
		uri = iter->data;
2029
		success = xmlTextWriterWriteElement (project, (xmlChar *) "restored", (xmlChar *) uri);
2030
		if (success < 0)
2031
			return FALSE;
2032
	}
2033
2034
	/* NOTE: we don't write symlinks and unreadable they are useless */
2035
	return TRUE;
2036
}
2037
2038
static gboolean 
2039
brasero_project_save_project_xml (BraseroProject *proj,
2040
				  const gchar *uri,
2041
				  BraseroDiscTrack *track,
2042
				  gboolean use_dialog)
2043
{
2044
	xmlTextWriter *project;
2045
	gboolean retval;
2046
	gint success;
2047
    	gchar *path;
2048
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
2049
	path = g_filename_from_uri (uri, NULL, NULL);
2050
	if (!path)
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2051
		return FALSE;
2052
2053
	project = xmlNewTextWriterFilename (path, 0);
2054
	if (!project) {
2055
		g_free (path);
2056
2057
	    	if (use_dialog)
2058
			brasero_project_not_saved_dialog (proj);
2059
2060
		return FALSE;
2061
	}
2062
2063
	xmlTextWriterSetIndent (project, 1);
2064
	xmlTextWriterSetIndentString (project, (xmlChar *) "\t");
2065
2066
	success = xmlTextWriterStartDocument (project,
2067
					      NULL,
2068
					      "UTF8",
2069
					      NULL);
2070
	if (success < 0)
2071
		goto error;
2072
2073
	success = xmlTextWriterStartElement (project, (xmlChar *) "braseroproject");
2074
	if (success < 0)
2075
		goto error;
2076
2077
	/* write the name of the version */
2078
	success = xmlTextWriterWriteElement (project,
2079
					     (xmlChar *) "version",
2080
					     (xmlChar *) BRASERO_PROJECT_VERSION);
2081
	if (success < 0)
2082
		goto error;
2083
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
2084
	success = xmlTextWriterWriteElement (project,
2085
					     (xmlChar *) "label",
2086
					     (xmlChar *) gtk_entry_get_text (GTK_ENTRY (proj->priv->name_display)));
2087
	if (success < 0)
2088
		goto error;
2089
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
2090
	if (proj->priv->cover) {
2091
		gchar *escaped;
2092
2093
		escaped = g_uri_escape_string (proj->priv->cover, NULL, FALSE);
2094
		success = xmlTextWriterWriteElement (project,
2095
						     (xmlChar *) "cover",
2096
						     (xmlChar *) escaped);
2097
		g_free (escaped);
2098
2099
		if (success < 0)
2100
			goto error;
2101
	}
2102
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2103
	success = xmlTextWriterStartElement (project, (xmlChar *) "track");
2104
	if (success < 0)
2105
		goto error;
2106
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
2107
	if (track->type == BRASERO_PROJECT_TYPE_AUDIO) {
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2108
		success = xmlTextWriterStartElement (project, (xmlChar *) "audio");
2109
		if (success < 0)
2110
			goto error;
2111
2112
		retval = _save_audio_track_xml (project, track);
2113
		if (!retval)
2114
			goto error;
2115
2116
		success = xmlTextWriterEndElement (project); /* audio */
2117
		if (success < 0)
2118
			goto error;
2119
	}
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
2120
	else if (track->type == BRASERO_PROJECT_TYPE_DATA) {
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2121
		success = xmlTextWriterStartElement (project, (xmlChar *) "data");
2122
		if (success < 0)
2123
			goto error;
2124
2125
		retval = _save_data_track_xml (project, track);
2126
		if (!retval)
2127
			goto error;
2128
2129
		success = xmlTextWriterEndElement (project); /* data */
2130
		if (success < 0)
2131
			goto error;
2132
	}
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
2133
	else  if (track->type == BRASERO_PROJECT_TYPE_VIDEO) {
1.1.11 by Pedro Fragoso
Import upstream version 0.8.1
2134
		success = xmlTextWriterStartElement (project, (xmlChar *) "video");
2135
		if (success < 0)
2136
			goto error;
2137
2138
		retval = _save_audio_track_xml (project, track);
2139
		if (!retval)
2140
			goto error;
2141
2142
		success = xmlTextWriterEndElement (project); /* audio */
2143
		if (success < 0)
2144
			goto error;
2145
	}
2146
	else
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2147
		retval = FALSE;
2148
2149
	success = xmlTextWriterEndElement (project); /* track */
2150
	if (success < 0)
2151
		goto error;
2152
2153
	success = xmlTextWriterEndElement (project); /* braseroproject */
2154
	if (success < 0)
2155
		goto error;
2156
2157
	xmlTextWriterEndDocument (project);
2158
	xmlFreeTextWriter (project);
2159
	g_free (path);
2160
	return TRUE;
2161
2162
error:
2163
2164
	xmlTextWriterEndDocument (project);
2165
	xmlFreeTextWriter (project);
2166
2167
	g_remove (path);
2168
	g_free (path);
2169
2170
    	if (use_dialog)
2171
		brasero_project_not_saved_dialog (proj);
2172
2173
	return FALSE;
2174
}
2175
2176
static gboolean
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2177
brasero_project_save_audio_project_plain_text (BraseroProject *proj,
2178
					       const gchar *uri,
2179
					       BraseroDiscTrack *track,
2180
					       gboolean use_dialog)
2181
{
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
2182
	const gchar *title;
2183
	guint written;
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2184
	GSList *iter;
2185
	gchar *path;
2186
	FILE *file;
2187
2188
    	path = g_filename_from_uri (uri, NULL, NULL);
2189
    	if (!path)
2190
		return FALSE;
2191
2192
	file = fopen (path, "w+");
2193
	g_free (path);
2194
	if (!file) {
2195
		if (use_dialog)
2196
			brasero_project_not_saved_dialog (proj);
2197
2198
		return FALSE;
2199
	}
2200
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
2201
	/* write title */
2202
	title = gtk_entry_get_text (GTK_ENTRY (proj->priv->name_display));
2203
	written = fwrite (title, strlen (title), 1, file);
2204
	if (written != 1)
2205
		goto error;
2206
2207
	written = fwrite ("\n", 1, 1, file);
2208
	if (written != 1)
2209
		goto error;
2210
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2211
	for (iter = track->contents.tracks; iter; iter = iter->next) {
2212
		BraseroDiscSong *song;
2213
		BraseroSongInfo *info;
2214
		gchar *time;
2215
2216
		song = iter->data;
2217
		info = song->info;
2218
2219
		written = fwrite (info->title, 1, strlen (info->title), file);
2220
		if (written != strlen (info->title))
2221
			goto error;
2222
1.1.20 by Pedro Fragoso
Import upstream version 2.25.92
2223
		time = brasero_units_get_time_string (song->end - song->start, TRUE, FALSE);
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2224
		if (time) {
2225
			written = fwrite ("\t", 1, 1, file);
2226
			if (written != 1)
2227
				goto error;
2228
2229
			written = fwrite (time, 1, strlen (time), file);
2230
			if (written != strlen (time)) {
2231
				g_free (time);
2232
				goto error;
2233
			}
2234
			g_free (time);
2235
		}
2236
2237
		if (info->artist) {
2238
			gchar *string;
2239
2240
			written = fwrite ("\t", 1, 1, file);
2241
			if (written != 1)
2242
				goto error;
2243
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
2244
			/* Translators: %s is an artist */
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
2245
			string = g_strdup_printf (" by %s", info->artist);
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2246
			written = fwrite (string, 1, strlen (string), file);
2247
			if (written != strlen (string)) {
2248
				g_free (string);
2249
				goto error;
2250
			}
2251
			g_free (string);
2252
		}
2253
2254
		written = fwrite ("\n(", 1, 2, file);
2255
		if (written != 2)
2256
			goto error;
2257
2258
		written = fwrite (song->uri, 1, strlen (song->uri), file);
2259
		if (written != strlen (song->uri))
2260
			goto error;
2261
2262
		written = fwrite (")", 1, 1, file);
2263
		if (written != 1)
2264
			goto error;
2265
2266
		written = fwrite ("\n\n", 1, 2, file);
2267
		if (written != 2)
2268
			goto error;
2269
	}
2270
2271
	fclose (file);
2272
	return TRUE;
2273
	
2274
error:
2275
	fclose (file);
2276
2277
    	if (use_dialog)
2278
		brasero_project_not_saved_dialog (proj);
2279
2280
	return FALSE;
2281
}
2282
2283
#ifdef BUILD_PLAYLIST
2284
2285
static void
2286
brasero_project_save_audio_playlist_entry (GtkTreeModel *model,
2287
					   GtkTreeIter *iter,
2288
					   gchar **uri,
2289
					   gchar **title,
2290
					   gboolean *custom_title,
2291
					   gpointer user_data)
2292
{
2293
	gtk_tree_model_get (model, iter,
2294
			    0, uri,
2295
			    1, title,
2296
			    2, custom_title,
2297
			    -1);
2298
}
2299
2300
static gboolean
2301
brasero_project_save_audio_project_playlist (BraseroProject *proj,
2302
					     const gchar *uri,
2303
					     BraseroProjectSave type,
2304
					     BraseroDiscTrack *track,
2305
					     gboolean use_dialog)
2306
{
2307
	TotemPlParserType pl_type;
2308
	TotemPlParser *parser;
2309
	GtkListStore *model;
2310
	GtkTreeIter t_iter;
2311
	gboolean result;
2312
	GSList *iter;
2313
	gchar *path;
2314
2315
    	path = g_filename_from_uri (uri, NULL, NULL);
2316
    	if (!path)
2317
		return FALSE;
2318
2319
	parser = totem_pl_parser_new ();
2320
2321
	/* create and populate treemodel */
2322
	model = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);
2323
	for (iter = track->contents.tracks; iter; iter = iter->next) {
2324
		BraseroDiscSong *song;
2325
		BraseroSongInfo *info;
2326
2327
		song = iter->data;
2328
		info = song->info;
2329
2330
		gtk_list_store_append (model, &t_iter);
2331
		gtk_list_store_set (model, &t_iter,
2332
				    0, song->uri,
2333
				    1, info->title,
2334
				    2, TRUE,
2335
				    -1);
2336
	}
2337
2338
	switch (type) {
2339
		case BRASERO_PROJECT_SAVE_PLAYLIST_M3U:
2340
			pl_type = TOTEM_PL_PARSER_M3U;
2341
			break;
2342
		case BRASERO_PROJECT_SAVE_PLAYLIST_XSPF:
2343
			pl_type = TOTEM_PL_PARSER_XSPF;
2344
			break;
2345
		case BRASERO_PROJECT_SAVE_PLAYLIST_IRIVER_PLA:
2346
			pl_type = TOTEM_PL_PARSER_IRIVER_PLA;
2347
			break;
2348
2349
		case BRASERO_PROJECT_SAVE_PLAYLIST_PLS:
2350
		default:
2351
			pl_type = TOTEM_PL_PARSER_PLS;
2352
			break;
2353
	}
2354
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
2355
	result = totem_pl_parser_write_with_title (parser,
2356
						   GTK_TREE_MODEL (model),
2357
						   brasero_project_save_audio_playlist_entry,
2358
						   path,
2359
						   gtk_entry_get_text (GTK_ENTRY (proj->priv->name_display)),
2360
						   pl_type,
2361
						   NULL,
2362
						   NULL);
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2363
	if (!result && use_dialog)
2364
		brasero_project_not_saved_dialog (proj);
2365
2366
	if (result)
2367
		brasero_project_add_to_recents (proj, uri, FALSE);
2368
2369
	g_object_unref (model);
2370
	g_object_unref (parser);
2371
	g_free (path);
2372
2373
	return result;
2374
}
2375
2376
#endif
2377
2378
static gboolean
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2379
brasero_project_save_project_real (BraseroProject *project,
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2380
				   const gchar *uri,
2381
				   BraseroProjectSave save_type)
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2382
{
2383
	BraseroDiscResult result;
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
2384
	BraseroProjectType type;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2385
	BraseroDiscTrack track;
2386
2387
	g_return_val_if_fail (uri != NULL || project->priv->project != NULL, FALSE);
2388
2389
	result = brasero_project_check_status (project, project->priv->current);
2390
	if (result != BRASERO_DISC_OK)
2391
		return FALSE;
2392
2393
	bzero (&track, sizeof (track));
2394
	result = brasero_disc_get_track (project->priv->current, &track);
2395
	if (result == BRASERO_DISC_ERROR_EMPTY_SELECTION) {
2396
		if (BRASERO_IS_AUDIO_DISC (project->priv->current))
2397
			brasero_project_no_song_dialog (project);
2398
		else if (BRASERO_IS_DATA_DISC (project->priv->current))
2399
			brasero_project_no_file_dialog (project);
2400
2401
		return FALSE;
2402
	}
2403
	else if (result != BRASERO_DISC_OK) {
2404
		brasero_project_not_saved_dialog (project);
2405
		return FALSE;
2406
	}
2407
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
2408
	if (track.type == BRASERO_PROJECT_TYPE_AUDIO)
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
2409
		type = BRASERO_PROJECT_TYPE_AUDIO;
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
2410
	else if (track.type == BRASERO_PROJECT_TYPE_DATA)
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
2411
		type = BRASERO_PROJECT_TYPE_DATA;
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
2412
	else if (track.type == BRASERO_PROJECT_TYPE_VIDEO)
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
2413
		type = BRASERO_PROJECT_TYPE_VIDEO;
2414
	else {
2415
		brasero_track_clear (&track);
2416
		return BRASERO_PROJECT_TYPE_INVALID;
2417
	}
2418
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
2419
	if (save_type == BRASERO_PROJECT_SAVE_XML
1.1.18 by Pedro Fragoso
Import upstream version 2.25.91
2420
	||  track.type == BRASERO_PROJECT_TYPE_DATA) {
1.1.14 by Pedro Fragoso
Import upstream version 0.8.4
2421
		brasero_project_set_uri (project, uri, type);
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2422
		if (!brasero_project_save_project_xml (project,
2423
						       uri ? uri : project->priv->project,
2424
						       &track,
2425
						       TRUE))
2426
			return FALSE;
2427
2428
		project->priv->modified = 0;
2429
	}
2430
	else if (save_type == BRASERO_PROJECT_SAVE_PLAIN) {
2431
		if (!brasero_project_save_audio_project_plain_text (project,
2432
								    uri,
2433
								    &track,
2434
								    TRUE))
2435
			return FALSE;
2436
	}
2437
2438
#ifdef BUILD_PLAYLIST
2439
2440
	else {
2441
		if (!brasero_project_save_audio_project_playlist (project,
2442
								  uri,
2443
								  save_type,
2444
								  &track,
2445
								  TRUE))
2446
			return FALSE;
2447
	}
2448
2449
#endif
2450
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2451
	brasero_track_clear (&track);
2452
	return TRUE;
2453
}
2454
2455
static gchar *
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2456
brasero_project_save_project_ask_for_path (BraseroProject *project,
2457
					   BraseroProjectSave *type)
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2458
{
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2459
	GtkWidget *combo = NULL;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2460
	GtkWidget *toplevel;
2461
	GtkWidget *chooser;
2462
	gchar *uri = NULL;
2463
	gint answer;
2464
2465
	toplevel = gtk_widget_get_toplevel (GTK_WIDGET (project));
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2466
	chooser = gtk_file_chooser_dialog_new (_("Save Current Project"),
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2467
					       GTK_WINDOW (toplevel),
2468
					       GTK_FILE_CHOOSER_ACTION_SAVE,
2469
					       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
2470
					       GTK_STOCK_SAVE, GTK_RESPONSE_OK,
2471
					       NULL);
2472
2473
	gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), TRUE);
2474
	gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
2475
					     g_get_home_dir ());
2476
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2477
	/* if the file chooser is an audio project offer the possibility to save
2478
	 * in plain text a list of the current displayed songs (only in save as
2479
	 * mode) */
2480
	if (type && BRASERO_IS_AUDIO_DISC (project->priv->current)) {
2481
		combo = gtk_combo_box_new_text ();
2482
		gtk_widget_show (combo);
2483
2484
		gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Save project as Brasero audio project"));
2485
		gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Save project as a plain text list"));
2486
2487
#ifdef BUILD_PLAYLIST
2488
2489
		gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Save project as a PLS playlist"));
2490
		gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Save project as an M3U playlist"));
2491
		gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Save project as a XSPF playlist"));
2492
		gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Save project as an IRIVER playlist"));
2493
2494
#endif
2495
2496
		gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
2497
		gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (chooser), combo);
2498
	}
2499
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2500
	gtk_widget_show (chooser);
2501
	answer = gtk_dialog_run (GTK_DIALOG (chooser));
2502
	if (answer == GTK_RESPONSE_OK) {
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2503
		if (combo)
2504
			*type = gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
2505
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2506
		uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (chooser));
2507
		if (*uri == '\0') {
2508
			g_free (uri);
2509
			uri = NULL;
2510
		}
2511
	}
2512
2513
	gtk_widget_destroy (chooser);
2514
	return uri;
2515
}
2516
2517
gboolean
2518
brasero_project_save_project (BraseroProject *project)
2519
{
2520
	gchar *uri = NULL;
2521
	gboolean result;
2522
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2523
	if (!project->priv->project && !(uri = brasero_project_save_project_ask_for_path (project, NULL)))
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2524
		return FALSE;
2525
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2526
	result = brasero_project_save_project_real (project, uri, BRASERO_PROJECT_SAVE_XML);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2527
	g_free (uri);
2528
2529
	return result;
2530
}
2531
2532
gboolean
2533
brasero_project_save_project_as (BraseroProject *project)
2534
{
1.1.13 by Pedro Fragoso
Import upstream version 0.8.3
2535
	BraseroProjectSave type = BRASERO_PROJECT_SAVE_XML;
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2536
	gboolean result;
2537
	gchar *uri;
2538
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2539
	uri = brasero_project_save_project_ask_for_path (project, &type);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2540
	if (!uri)
2541
		return FALSE;
2542
1.1.9 by Pedro Fragoso
Import upstream version 0.7.91
2543
	result = brasero_project_save_project_real (project, uri, type);
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2544
	g_free (uri);
2545
2546
	return result;
2547
}
2548
2549
/**
2550
 * NOTE: this function returns FALSE if it succeeds and TRUE otherwise.
2551
 * this value is mainly used by the session object to cancel or not the app
2552
 * closing
2553
 */
2554
2555
gboolean
2556
brasero_project_save_session (BraseroProject *project,
2557
			      const gchar *uri,
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
2558
			      gchar **saved_uri,
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2559
			      gboolean show_cancel)
2560
{
2561
    	BraseroDiscTrack track;
2562
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
2563
	if (!project->priv->current) {
2564
		if (saved_uri)
2565
			*saved_uri = NULL;
2566
2567
		return FALSE;
2568
	}
2569
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2570
	if (project->priv->project) {
2571
		GtkResponseType answer;
2572
2573
		if (!project->priv->modified) {
2574
			/* there is a saved project but unmodified.
2575
			 * No need to ask anything */
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
2576
			if (saved_uri)
2577
				*saved_uri = g_strdup (project->priv->project);
2578
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2579
			return FALSE;
2580
		}
2581
2582
		/* ask the user if he wants to save the changes */
2583
		answer = brasero_project_save_project_dialog (project, show_cancel);
2584
		if (answer == GTK_RESPONSE_CANCEL)
2585
			return TRUE;
2586
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
2587
		if (answer != GTK_RESPONSE_YES) {
2588
			if (saved_uri)
2589
				*saved_uri = NULL;
2590
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2591
			return FALSE;
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
2592
		}
2593
2594
		if (!brasero_project_save_project_real (project, NULL, BRASERO_PROJECT_SAVE_XML))
2595
			return TRUE;
2596
2597
		if (saved_uri)
2598
			*saved_uri = g_strdup (project->priv->project);
2599
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2600
		return FALSE;
2601
	}
2602
2603
	if (project->priv->empty) {
2604
		/* the project is empty anyway. No need to ask anything.
2605
		 * return FALSE since this is not a tmp project */
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
2606
		if (saved_uri)
2607
			*saved_uri = NULL;
2608
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2609
		return FALSE;
2610
	}
2611
2612
    	if (project->priv->burnt) {
2613
		GtkResponseType answer;
2614
2615
		/* the project wasn't saved but burnt ask if the user wants to
2616
		 * keep it for another time by saving it */
2617
		answer = brasero_project_save_project_dialog (project, show_cancel);
2618
		if (answer == GTK_RESPONSE_CANCEL)
2619
			return TRUE;
2620
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
2621
		if (answer != GTK_RESPONSE_YES) {
2622
			if (saved_uri)
2623
				*saved_uri = NULL;
2624
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2625
			return FALSE;
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
2626
		}
2627
2628
		if (!brasero_project_save_project_as (project))
2629
			return TRUE;
2630
2631
		if (saved_uri)
2632
			*saved_uri = g_strdup (project->priv->project);
2633
2634
		return FALSE;
2635
	}
2636
2637
    	if (!uri) {
2638
		if (saved_uri)
2639
			*saved_uri = NULL;
2640
2641
		return FALSE;
2642
	}
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2643
2644
    	bzero (&track, sizeof (track));
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
2645
	if (brasero_disc_get_track (project->priv->current, &track) == BRASERO_DISC_OK) {
2646
		if (!brasero_project_save_project_xml (project,
2647
						       uri,
2648
						       &track,
2649
						       FALSE))
2650
			return TRUE;
2651
	}
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2652
2653
	brasero_track_clear (&track);
2654
1.1.15 by Pedro Fragoso
Import upstream version 0.9.0
2655
	if (saved_uri)
2656
		*saved_uri = g_strdup (uri);
2657
1.1.7 by Luis Medinas
Import upstream version 0.7.0
2658
    	return FALSE;
2659
}