~ubuntu-branches/debian/wheezy/brasero/wheezy

« back to all changes in this revision

Viewing changes to src/brasero-video-disc.c

  • Committer: Bazaar Package Importer
  • Author(s): Josselin Mouette, Pedro Fragoso, Luca Bruno, Josselin Mouette, Emilio Pozuelo Monfort
  • Date: 2009-06-24 18:59:46 UTC
  • mfrom: (1.2.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624185946-iyxkgf3gjptir5y3
Tags: 2.26.2-1
[ Pedro Fragoso ]
* Add myself to Maintainer field
  - Thanks Ondřej Surý
* New upstream version (Closes: #528945)
  - Split package into brasero, libbrasero-media0 and libbrasero-dev
  - Add Replaces to libbrasero-media0
  - Bump libgtk to 2.14.0
  - Remove libnotify Build-dep
  - Add Build-dep libnautilus-extension-dev (>= 2.22.2)
    and install it.
  - Add Build-dep to libsm-dev
  - Add Build-dep on intltool
* Install omf files to prevent crash on Help
* Move gstreamer0.10-plugins-bad to Suggests, and add
  dvdauthor and vcdimager
* Recommends gvfs (Closes: #491827)
* Pass --disable-scrollkeeper in DEB_CONFIGURE_EXTRA_FLAGS
* debian/patches/007-fix-gnome-doc-utils-path.patch:
  - Removed, not needed anymore
* debian/patches/008-fix-volume-identifier-crash.patch:
  - Removed, merged upstream
* debian/patches/011_nautilus_menu_move.patch:
 - Move CD/DVD Creator Menu to Acessories, taken from Ubuntu

[ Luca Bruno ]
* debian/control.in:
  - Add Build-Depend gtk-doc-tools 1.9.
* debian/patches/006-fix-libdvdcss.patch:
  - Removed as applied upstream.

[ Josselin Mouette ]
* New upstream release.
* Update build-dependencies.
* Move the translations and data to a new brasero-common package.
* Rewrite the descriptions.
* Add -dev depends to the development package.
* Remove inappropriate recommends in the library package.
* Let’s not forget dvd+rw-tools so that we can write DVDs too.
* Rework dependencies accordingly.
* Put the nautilus extension in brasero.
* Conflict against nautilus-cd-burner to avoid having two burning 
  extensions.
* Include clean-la.mk and gnome-version.mk; build-depend on 
  gnome-pkg-tools 0.7.
* Don’t run dh_makeshlibs on brasero and libbrasero-plugins.
* 011_nautilus_menu_move.patch: add NoDisplay=true, this icon is 
  duplicating existing functionality (brasero icon in sound&video 
  menu, and nautilus autorun).
* Update list of copyright holders.

[ Emilio Pozuelo Monfort ]
* debian/copyright: updated.

[ Josselin Mouette ]
* copyright: improve indentation, and point to versioned LGPL.
* 090_relibtoolize.patch: add a relibtoolization patch to avoid the 
  rpath crap.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 
2
/*
 
3
 * brasero
 
4
 * Copyright (C) Philippe Rouquier 2005-2008 <bonfire-app@wanadoo.fr>
 
5
 * 
 
6
 * brasero is free software: you can redistribute it and/or modify it
 
7
 * under the terms of the GNU General Public License as published by the
 
8
 * Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 * 
 
11
 * brasero is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
14
 * See the GNU General Public License for more details.
 
15
 * 
 
16
 * You should have received a copy of the GNU General Public License along
 
17
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#ifdef HAVE_CONFIG_H
 
21
#  include <config.h>
 
22
#endif
 
23
 
 
24
#include <string.h>
 
25
 
 
26
#include <glib.h>
 
27
#include <glib/gi18n-lib.h>
 
28
 
 
29
#include <gdk/gdkkeysyms.h>
 
30
 
 
31
#include <gtk/gtk.h>
 
32
 
 
33
#include "eggtreemultidnd.h"
 
34
 
 
35
#include "burn-debug.h"
 
36
#include "brasero-app.h"
 
37
#include "brasero-disc.h"
 
38
#include "brasero-io.h"
 
39
#include "brasero-utils.h"
 
40
#include "brasero-video-disc.h"
 
41
#include "brasero-video-project.h"
 
42
#include "brasero-video-tree-model.h"
 
43
#include "brasero-multi-song-props.h"
 
44
#include "brasero-song-properties.h"
 
45
#include "brasero-session-cfg.h"
 
46
 
 
47
typedef struct _BraseroVideoDiscPrivate BraseroVideoDiscPrivate;
 
48
struct _BraseroVideoDiscPrivate
 
49
{
 
50
        GtkWidget *notebook;
 
51
        GtkWidget *tree;
 
52
 
 
53
        GtkWidget *message;
 
54
        GtkUIManager *manager;
 
55
        GtkActionGroup *disc_group;
 
56
 
 
57
        guint reject_files:1;
 
58
        guint editing:1;
 
59
        guint loading:1;
 
60
};
 
61
 
 
62
#define BRASERO_VIDEO_DISC_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_VIDEO_DISC, BraseroVideoDiscPrivate))
 
63
 
 
64
static void
 
65
brasero_video_disc_iface_disc_init (BraseroDiscIface *iface);
 
66
 
 
67
G_DEFINE_TYPE_WITH_CODE (BraseroVideoDisc,
 
68
                         brasero_video_disc,
 
69
                         GTK_TYPE_VBOX,
 
70
                         G_IMPLEMENT_INTERFACE (BRASERO_TYPE_DISC,
 
71
                                                brasero_video_disc_iface_disc_init));
 
72
 
 
73
enum {
 
74
        PROP_NONE,
 
75
        PROP_REJECT_FILE,
 
76
};
 
77
 
 
78
static void
 
79
brasero_video_disc_edit_information_cb (GtkAction *action,
 
80
                                        BraseroVideoDisc *disc);
 
81
static void
 
82
brasero_video_disc_open_activated_cb (GtkAction *action,
 
83
                                      BraseroVideoDisc *disc);
 
84
static void
 
85
brasero_video_disc_delete_activated_cb (GtkAction *action,
 
86
                                        BraseroVideoDisc *disc);
 
87
static void
 
88
brasero_video_disc_paste_activated_cb (GtkAction *action,
 
89
                                       BraseroVideoDisc *disc);
 
90
 
 
91
static GtkActionEntry entries[] = {
 
92
        {"ContextualMenu", NULL, N_("Menu")},
 
93
        {"OpenVideo", GTK_STOCK_OPEN, NULL, NULL, N_("Open the selected video"),
 
94
         G_CALLBACK (brasero_video_disc_open_activated_cb)},
 
95
        {"EditVideo", GTK_STOCK_PROPERTIES, N_("_Edit Information..."), NULL, N_("Edit the video information (start, end, author, ...)"),
 
96
         G_CALLBACK (brasero_video_disc_edit_information_cb)},
 
97
        {"DeleteVideo", GTK_STOCK_REMOVE, NULL, NULL, N_("Remove the selected videos from the project"),
 
98
         G_CALLBACK (brasero_video_disc_delete_activated_cb)},
 
99
        {"PasteVideo", GTK_STOCK_PASTE, NULL, NULL, N_("Add the files stored in the clipboard"),
 
100
         G_CALLBACK (brasero_video_disc_paste_activated_cb)},
 
101
/*      {"Split", "transform-crop-and-resize", N_("_Split Track..."), NULL, N_("Split the selected track"),
 
102
         G_CALLBACK (brasero_video_disc_split_cb)} */
 
103
};
 
104
 
 
105
static const gchar *description = {
 
106
        "<ui>"
 
107
        "<menubar name='menubar' >"
 
108
                "<menu action='EditMenu'>"
 
109
/*              "<placeholder name='EditPlaceholder'>"
 
110
                        "<menuitem action='Split'/>"
 
111
                "</placeholder>"
 
112
*/              "</menu>"
 
113
        "</menubar>"
 
114
        "<popup action='ContextMenu'>"
 
115
                "<menuitem action='OpenVideo'/>"
 
116
                "<menuitem action='DeleteVideo'/>"
 
117
                "<separator/>"
 
118
                "<menuitem action='PasteVideo'/>"
 
119
/*              "<separator/>"
 
120
                "<menuitem action='Split'/>"
 
121
*/              "<separator/>"
 
122
                "<menuitem action='EditVideo'/>"
 
123
        "</popup>"
 
124
/*      "<toolbar name='Toolbar'>"
 
125
                "<placeholder name='DiscButtonPlaceholder'>"
 
126
                        "<separator/>"
 
127
                        "<toolitem action='Split'/>"
 
128
                "</placeholder>"
 
129
        "</toolbar>"
 
130
*/      "</ui>"
 
131
};
 
132
 
 
133
enum {
 
134
        TREE_MODEL_ROW          = 150,
 
135
        TARGET_URIS_LIST,
 
136
};
 
137
 
 
138
static GtkTargetEntry ntables_cd [] = {
 
139
        {BRASERO_DND_TARGET_SELF_FILE_NODES, GTK_TARGET_SAME_WIDGET, TREE_MODEL_ROW},
 
140
        {"text/uri-list", 0, TARGET_URIS_LIST}
 
141
};
 
142
static guint nb_targets_cd = sizeof (ntables_cd) / sizeof (ntables_cd[0]);
 
143
 
 
144
static GtkTargetEntry ntables_source [] = {
 
145
        {BRASERO_DND_TARGET_SELF_FILE_NODES, GTK_TARGET_SAME_WIDGET, TREE_MODEL_ROW},
 
146
};
 
147
 
 
148
static guint nb_targets_source = sizeof (ntables_source) / sizeof (ntables_source[0]);
 
149
 
 
150
 
 
151
/**
 
152
 * Row name edition
 
153
 */
 
154
 
 
155
static void
 
156
brasero_video_disc_name_editing_started_cb (GtkCellRenderer *renderer,
 
157
                                            GtkCellEditable *editable,
 
158
                                            gchar *path,
 
159
                                            BraseroVideoDisc *disc)
 
160
{
 
161
        BraseroVideoDiscPrivate *priv;
 
162
 
 
163
        priv = BRASERO_VIDEO_DISC_PRIVATE (disc);
 
164
        priv->editing = 1;
 
165
}
 
166
 
 
167
static void
 
168
brasero_video_disc_name_editing_canceled_cb (GtkCellRenderer *renderer,
 
169
                                             BraseroVideoDisc *disc)
 
170
{
 
171
        BraseroVideoDiscPrivate *priv;
 
172
 
 
173
        priv = BRASERO_VIDEO_DISC_PRIVATE (disc);
 
174
        priv->editing = 0;
 
175
}
 
176
 
 
177
static void
 
178
brasero_video_disc_name_edited_cb (GtkCellRendererText *cellrenderertext,
 
179
                                   gchar *path_string,
 
180
                                   gchar *text,
 
181
                                   BraseroVideoDisc *self)
 
182
{
 
183
        BraseroVideoDiscPrivate *priv;
 
184
        BraseroVideoProject *project;
 
185
        BraseroVideoFile *file;
 
186
        GtkTreePath *path;
 
187
        GtkTreeIter row;
 
188
 
 
189
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
190
 
 
191
        priv->editing = 0;
 
192
 
 
193
        path = gtk_tree_path_new_from_string (path_string);
 
194
        project = BRASERO_VIDEO_PROJECT (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree)));
 
195
 
 
196
        /* see if this is still a valid path. It can happen a user removes it
 
197
         * while the name of the row is being edited */
 
198
        if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (project), &row, path)) {
 
199
                gtk_tree_path_free (path);
 
200
                return;
 
201
        }
 
202
 
 
203
        file = brasero_video_tree_model_path_to_file (BRASERO_VIDEO_TREE_MODEL (project), path);
 
204
        gtk_tree_path_free (path);
 
205
 
 
206
        brasero_video_project_rename (project, file, text);
 
207
}
 
208
 
 
209
static void
 
210
brasero_video_disc_vfs_activity_changed (BraseroVideoProject *project,
 
211
                                         gboolean activity,
 
212
                                         BraseroVideoDisc *self)
 
213
{
 
214
        GdkCursor *cursor;
 
215
        BraseroVideoDiscPrivate *priv;
 
216
 
 
217
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
218
 
 
219
        if (!GTK_WIDGET (self)->window)
 
220
                return;
 
221
 
 
222
        if (activity) {
 
223
                cursor = gdk_cursor_new (GDK_WATCH);
 
224
                gdk_window_set_cursor (GTK_WIDGET (self)->window, cursor);
 
225
                gdk_cursor_unref (cursor);
 
226
        }
 
227
        else
 
228
                gdk_window_set_cursor (GTK_WIDGET (self)->window, NULL);
 
229
}
 
230
 
 
231
static gboolean
 
232
brasero_video_disc_directory_dialog (BraseroVideoProject *project,
 
233
                                     const gchar *uri,
 
234
                                     BraseroVideoDisc *self)
 
235
{
 
236
        gint answer;
 
237
        GtkWidget *dialog;
 
238
 
 
239
        dialog = brasero_app_dialog (brasero_app_get_default (),
 
240
                                     _("Do you want to search for video files inside the directory?"),
 
241
                                     GTK_BUTTONS_NONE,
 
242
                                     GTK_MESSAGE_WARNING);
 
243
 
 
244
        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
 
245
                                                  _("Directories cannot be added to video discs."));
 
246
 
 
247
        gtk_dialog_add_buttons (GTK_DIALOG (dialog),
 
248
                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
 
249
                                _("_Search Directory"), GTK_RESPONSE_OK,
 
250
                                NULL);
 
251
 
 
252
        gtk_widget_show_all (dialog);
 
253
        answer = gtk_dialog_run (GTK_DIALOG (dialog));
 
254
        gtk_widget_destroy (dialog);
 
255
 
 
256
        if (answer != GTK_RESPONSE_OK)
 
257
                return FALSE;
 
258
 
 
259
        return TRUE;
 
260
}
 
261
 
 
262
static void
 
263
brasero_video_disc_unreadable_uri_dialog (BraseroVideoProject *project,
 
264
                                          GError *error,
 
265
                                          const gchar *uri,
 
266
                                          BraseroVideoDisc *self)
 
267
{
 
268
        gchar *primary;
 
269
        gchar *name;
 
270
 
 
271
        name = g_filename_display_basename (uri);
 
272
        primary = g_strdup_printf (_("\"%s\" could not be opened."), name);
 
273
        brasero_app_alert (brasero_app_get_default (),
 
274
                           primary,
 
275
                           error->message,
 
276
                           GTK_MESSAGE_ERROR);
 
277
        g_free (primary);
 
278
        g_free (name);
 
279
}
 
280
 
 
281
static void
 
282
brasero_video_disc_not_video_dialog (BraseroVideoProject *project,
 
283
                                     const gchar *uri,
 
284
                                     BraseroVideoDisc *self)
 
285
{
 
286
        gchar *primary;
 
287
        gchar *name;
 
288
 
 
289
        BRASERO_GET_BASENAME_FOR_DISPLAY (uri, name);
 
290
        primary = g_strdup_printf (_("\"%s\" does not have a suitable type for video projects."), name);
 
291
        brasero_app_alert (brasero_app_get_default (),
 
292
                           primary,
 
293
                           _("Please only add files with video contents"),
 
294
                           GTK_MESSAGE_ERROR);
 
295
        g_free (primary);
 
296
        g_free (name);
 
297
}
 
298
 
 
299
static BraseroDiscResult
 
300
brasero_video_disc_add_uri_real (BraseroVideoDisc *self,
 
301
                                 const gchar *uri,
 
302
                                 gint pos,
 
303
                                 gint64 start,
 
304
                                 gint64 end,
 
305
                                 GtkTreePath **path_return)
 
306
{
 
307
        BraseroVideoFile *file;
 
308
        BraseroVideoProject *project;
 
309
        BraseroVideoDiscPrivate *priv;
 
310
        BraseroVideoFile *sibling = NULL;
 
311
 
 
312
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
313
        if (priv->reject_files)
 
314
                return BRASERO_DISC_NOT_READY;
 
315
 
 
316
        project = BRASERO_VIDEO_PROJECT (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree)));
 
317
 
 
318
        if (pos > 0) {
 
319
                GtkTreePath *treepath;
 
320
 
 
321
                treepath = gtk_tree_path_new ();
 
322
                gtk_tree_path_append_index (treepath, pos);
 
323
                sibling = brasero_video_tree_model_path_to_file (BRASERO_VIDEO_TREE_MODEL (project), treepath);
 
324
                gtk_tree_path_free (treepath);
 
325
        }
 
326
 
 
327
        file = brasero_video_project_add_uri (project,
 
328
                                              uri,
 
329
                                              NULL,
 
330
                                              sibling,
 
331
                                              start,
 
332
                                              end);
 
333
        if (path_return && file)
 
334
                *path_return = brasero_video_tree_model_file_to_path (BRASERO_VIDEO_TREE_MODEL (project), file);
 
335
 
 
336
        gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), 1);
 
337
 
 
338
        return BRASERO_DISC_OK;
 
339
}
 
340
 
 
341
static BraseroDiscResult
 
342
brasero_video_disc_add_uri (BraseroDisc *self,
 
343
                            const gchar *uri)
 
344
{
 
345
        BraseroVideoDiscPrivate *priv;
 
346
        GtkTreePath *treepath = NULL;
 
347
        BraseroDiscResult result;
 
348
 
 
349
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
350
        result = brasero_video_disc_add_uri_real (BRASERO_VIDEO_DISC (self),
 
351
                                                  uri,
 
352
                                                  -1,
 
353
                                                  -1,
 
354
                                                  -1,
 
355
                                                  &treepath);
 
356
 
 
357
        if (treepath) {
 
358
                gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->tree),
 
359
                                              treepath,
 
360
                                              NULL,
 
361
                                              TRUE,
 
362
                                              0.5,
 
363
                                              0.5);
 
364
                gtk_tree_path_free (treepath);
 
365
        }
 
366
 
 
367
        return result;
 
368
}
 
369
 
 
370
static void
 
371
brasero_video_disc_delete_selected (BraseroDisc *self)
 
372
{
 
373
        BraseroVideoDiscPrivate *priv;
 
374
        GtkTreeSelection *selection;
 
375
        GtkTreeModel *model;
 
376
        GList *selected;
 
377
        GList *iter;
 
378
 
 
379
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
380
 
 
381
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree));
 
382
 
 
383
        selected = gtk_tree_selection_get_selected_rows (selection, &model);
 
384
        selected = g_list_reverse (selected);
 
385
        for (iter = selected; iter; iter = iter->next) {
 
386
                BraseroVideoFile *file;
 
387
                GtkTreePath *treepath;
 
388
 
 
389
                treepath = iter->data;
 
390
 
 
391
                file = brasero_video_tree_model_path_to_file (BRASERO_VIDEO_TREE_MODEL (model), treepath);
 
392
                gtk_tree_path_free (treepath);
 
393
 
 
394
                if (!file)
 
395
                        continue;
 
396
 
 
397
                brasero_video_project_remove_file (BRASERO_VIDEO_PROJECT (model), file);
 
398
        }
 
399
        g_list_free (selected);
 
400
}
 
401
 
 
402
static gboolean
 
403
brasero_video_disc_get_selected_uri (BraseroDisc *self,
 
404
                                     gchar **uri)
 
405
{
 
406
        GList *selected;
 
407
        GtkTreeModel *model;
 
408
        GtkTreeSelection *selection;
 
409
        BraseroVideoDiscPrivate *priv;
 
410
 
 
411
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
412
 
 
413
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree));
 
414
        selected = gtk_tree_selection_get_selected_rows (selection, &model);
 
415
        if (!selected)
 
416
                return FALSE;
 
417
 
 
418
        if (uri) {
 
419
                BraseroVideoFile *file;
 
420
                GtkTreePath *treepath;
 
421
 
 
422
                treepath = selected->data;
 
423
                file = brasero_video_tree_model_path_to_file (BRASERO_VIDEO_TREE_MODEL (model), treepath);
 
424
                if (file)
 
425
                        *uri = g_strdup (file->uri);
 
426
                else
 
427
                        *uri = NULL;
 
428
        }
 
429
 
 
430
        g_list_foreach (selected, (GFunc) gtk_tree_path_free, NULL);
 
431
        g_list_free (selected);
 
432
 
 
433
        return TRUE;
 
434
}
 
435
 
 
436
static void
 
437
brasero_video_disc_selection_changed_cb (GtkTreeSelection *selection,
 
438
                                         BraseroVideoDisc *self)
 
439
{
 
440
        brasero_disc_selection_changed (BRASERO_DISC (self));
 
441
}
 
442
 
 
443
static gboolean
 
444
brasero_video_disc_selection_function (GtkTreeSelection *selection,
 
445
                                       GtkTreeModel *model,
 
446
                                       GtkTreePath *treepath,
 
447
                                       gboolean path_currently_selected,
 
448
                                       gpointer NULL_data)
 
449
{
 
450
        BraseroVideoFile *file;
 
451
 
 
452
        file = brasero_video_tree_model_path_to_file (BRASERO_VIDEO_TREE_MODEL (model), treepath);
 
453
        if (file)
 
454
                file->editable = !path_currently_selected;
 
455
 
 
456
        return TRUE;
 
457
}
 
458
 
 
459
 
 
460
/**
 
461
 * Callback for menu
 
462
 */
 
463
 
 
464
static gboolean
 
465
brasero_video_disc_rename_songs (GtkTreeModel *model,
 
466
                                 GtkTreeIter *iter,
 
467
                                 GtkTreePath *treepath,
 
468
                                 const gchar *old_name,
 
469
                                 const gchar *new_name)
 
470
{
 
471
        BraseroVideoFile *file;
 
472
 
 
473
        file = brasero_video_tree_model_path_to_file (BRASERO_VIDEO_TREE_MODEL (model), treepath);
 
474
        if (!file)
 
475
                return FALSE;
 
476
 
 
477
        if (file->info->title)
 
478
                g_free (file->info->title);
 
479
 
 
480
        file->info->title = g_strdup (new_name);
 
481
        return TRUE;
 
482
}
 
483
 
 
484
static void
 
485
brasero_video_disc_edit_song_properties_list (BraseroVideoDisc *self,
 
486
                                              GList *list)
 
487
{
 
488
        gint isrc;
 
489
        GList *item;
 
490
        GList *copy;
 
491
        GtkWidget *props;
 
492
        GtkWidget *toplevel;
 
493
        GtkTreeModel *model;
 
494
        gchar *artist = NULL;
 
495
        gchar *composer = NULL;
 
496
        GtkResponseType result;
 
497
        BraseroVideoDiscPrivate *priv;
 
498
 
 
499
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
500
 
 
501
        if (!g_list_length (list))
 
502
                return;
 
503
 
 
504
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree));
 
505
 
 
506
        toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
 
507
        props = brasero_multi_song_props_new ();
 
508
        brasero_multi_song_props_set_show_gap (BRASERO_MULTI_SONG_PROPS (props), FALSE);
 
509
 
 
510
        gtk_window_set_transient_for (GTK_WINDOW (props),
 
511
                                      GTK_WINDOW (toplevel));
 
512
        gtk_window_set_modal (GTK_WINDOW (props), TRUE);
 
513
        gtk_window_set_position (GTK_WINDOW (props),
 
514
                                 GTK_WIN_POS_CENTER_ON_PARENT);
 
515
 
 
516
        gtk_widget_show (GTK_WIDGET (props));
 
517
        result = gtk_dialog_run (GTK_DIALOG (props));
 
518
        gtk_widget_hide (GTK_WIDGET (props));
 
519
        if (result != GTK_RESPONSE_ACCEPT)
 
520
                goto end;
 
521
 
 
522
        brasero_multi_song_props_set_rename_callback (BRASERO_MULTI_SONG_PROPS (props),
 
523
                                                      gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree)),
 
524
                                                      BRASERO_VIDEO_TREE_MODEL_NAME,
 
525
                                                      brasero_video_disc_rename_songs);
 
526
 
 
527
        brasero_multi_song_props_get_properties (BRASERO_MULTI_SONG_PROPS (props),
 
528
                                                 &artist,
 
529
                                                 &composer,
 
530
                                                 &isrc,
 
531
                                                 NULL);
 
532
 
 
533
        /* start by the end in case we add silences since then the next
 
534
         * treepaths will be wrong */
 
535
        copy = g_list_copy (list);
 
536
        copy = g_list_reverse (copy);
 
537
 
 
538
        for (item = copy; item; item = item->next) {
 
539
                GtkTreePath *treepath;
 
540
                BraseroVideoFile *file;
 
541
 
 
542
                treepath = item->data;
 
543
                file = brasero_video_tree_model_path_to_file (BRASERO_VIDEO_TREE_MODEL (model), treepath);
 
544
                if (!file)
 
545
                        continue;
 
546
 
 
547
                if (artist) {
 
548
                        g_free (file->info->artist);
 
549
                        file->info->artist = g_strdup (artist);
 
550
                }
 
551
 
 
552
                if (composer) {
 
553
                        g_free (file->info->composer);
 
554
                        file->info->composer = g_strdup (composer);
 
555
                }
 
556
 
 
557
                if (isrc > 0)
 
558
                        file->info->isrc = isrc;
 
559
        }
 
560
 
 
561
        g_list_free (copy);
 
562
        g_free (artist);
 
563
        g_free (composer);
 
564
end:
 
565
 
 
566
        gtk_widget_destroy (props);
 
567
}
 
568
 
 
569
static void
 
570
brasero_video_disc_edit_song_properties_file (BraseroVideoDisc *self,
 
571
                                              BraseroVideoFile *file)
 
572
{
 
573
        gint isrc;
 
574
        gint64 end;
 
575
        gint64 start;
 
576
        gchar *title;
 
577
        gchar *artist;
 
578
        gchar *composer;
 
579
        GtkWidget *props;
 
580
        GtkWidget *toplevel;
 
581
        GtkTreeModel *model;
 
582
        GtkResponseType result;
 
583
        BraseroVideoDiscPrivate *priv;
 
584
 
 
585
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
586
 
 
587
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree));
 
588
        toplevel = gtk_widget_get_toplevel (GTK_WIDGET (self));
 
589
 
 
590
        props = brasero_song_props_new ();
 
591
        brasero_song_props_set_properties (BRASERO_SONG_PROPS (props),
 
592
                                           -1,
 
593
                                           file->info->artist,
 
594
                                           file->info->title,
 
595
                                           file->info->composer,
 
596
                                           file->info->isrc,
 
597
                                           file->end - file->start,
 
598
                                           file->start,
 
599
                                           file->end,
 
600
                                           -1);
 
601
 
 
602
        gtk_window_set_transient_for (GTK_WINDOW (props),
 
603
                                      GTK_WINDOW (toplevel));
 
604
        gtk_window_set_modal (GTK_WINDOW (props), TRUE);
 
605
        gtk_window_set_position (GTK_WINDOW (props),
 
606
                                 GTK_WIN_POS_CENTER_ON_PARENT);
 
607
 
 
608
        gtk_widget_show (GTK_WIDGET (props));
 
609
        result = gtk_dialog_run (GTK_DIALOG (props));
 
610
        gtk_widget_hide (GTK_WIDGET (props));
 
611
        if (result != GTK_RESPONSE_ACCEPT)
 
612
                goto end;
 
613
 
 
614
        brasero_song_props_get_properties (BRASERO_SONG_PROPS (props),
 
615
                                           &artist,
 
616
                                           &title,
 
617
                                           &composer,
 
618
                                           &isrc,
 
619
                                           &start,
 
620
                                           &end,
 
621
                                           NULL);
 
622
 
 
623
        if (title) {
 
624
                if (file->info->title)
 
625
                        g_free (file->info->title);
 
626
 
 
627
                file->info->title = title;
 
628
                file->title_set = TRUE;
 
629
        }
 
630
 
 
631
        if (artist) {
 
632
                if (file->info->artist)
 
633
                        g_free (file->info->artist);
 
634
 
 
635
                file->info->artist = artist;
 
636
                file->artist_set = TRUE;
 
637
        }
 
638
 
 
639
        if (composer) {
 
640
                if (file->info->composer)
 
641
                        g_free (file->info->composer);
 
642
 
 
643
                file->info->composer = composer;
 
644
                file->composer_set = TRUE;
 
645
        }
 
646
 
 
647
        if (isrc) {
 
648
                file->info->isrc = isrc;
 
649
                file->isrc_set = TRUE;
 
650
        }
 
651
 
 
652
        brasero_video_project_resize_file (BRASERO_VIDEO_PROJECT (model), file, start, end);
 
653
 
 
654
end:
 
655
 
 
656
        gtk_widget_destroy (props);
 
657
}
 
658
 
 
659
static void
 
660
brasero_video_disc_edit_information_cb (GtkAction *action,
 
661
                                        BraseroVideoDisc *self)
 
662
{
 
663
        GList *list;
 
664
        GtkTreeModel *model;
 
665
        GtkTreeSelection *selection;
 
666
        BraseroVideoDiscPrivate *priv;
 
667
 
 
668
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
669
 
 
670
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree));
 
671
        list = gtk_tree_selection_get_selected_rows (selection, &model);
 
672
 
 
673
        if (!list)
 
674
                return;
 
675
 
 
676
        if (g_list_length (list) == 1) {
 
677
                BraseroVideoFile *file;
 
678
                GtkTreePath *treepath;
 
679
 
 
680
                treepath = list->data;
 
681
 
 
682
                file = brasero_video_tree_model_path_to_file (BRASERO_VIDEO_TREE_MODEL (model), treepath);
 
683
                if (file)
 
684
                        brasero_video_disc_edit_song_properties_file (self, file);
 
685
        }
 
686
        else
 
687
                brasero_video_disc_edit_song_properties_list (self, list);
 
688
 
 
689
        g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL);
 
690
        g_list_free (list);
 
691
}
 
692
 
 
693
static void
 
694
brasero_video_disc_open_file (BraseroVideoDisc *self)
 
695
{
 
696
        GList *item, *list;
 
697
        GSList *uris = NULL;
 
698
        GtkTreeModel *model;
 
699
        GtkTreePath *treepath;
 
700
        GtkTreeSelection *selection;
 
701
        BraseroVideoDiscPrivate *priv;
 
702
 
 
703
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
704
 
 
705
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree));
 
706
        list = gtk_tree_selection_get_selected_rows (selection, &model);
 
707
 
 
708
        for (item = list; item; item = item->next) {
 
709
                BraseroVideoFile *file;
 
710
 
 
711
                treepath = item->data;
 
712
                file = brasero_video_tree_model_path_to_file (BRASERO_VIDEO_TREE_MODEL (model), treepath);
 
713
                gtk_tree_path_free (treepath);
 
714
 
 
715
                if (!file)
 
716
                        continue;
 
717
 
 
718
                if (file->uri)
 
719
                        uris = g_slist_prepend (uris, file->uri);
 
720
        }
 
721
        g_list_free (list);
 
722
 
 
723
        brasero_utils_launch_app (GTK_WIDGET (self), uris);
 
724
        g_slist_free (uris);
 
725
}
 
726
 
 
727
static void
 
728
brasero_video_disc_open_activated_cb (GtkAction *action,
 
729
                                      BraseroVideoDisc *self)
 
730
{
 
731
        brasero_video_disc_open_file (self);
 
732
}
 
733
 
 
734
static void
 
735
brasero_video_disc_clipboard_text_cb (GtkClipboard *clipboard,
 
736
                                      const gchar *text,
 
737
                                      BraseroVideoDisc *self)
 
738
{
 
739
        gchar **array;
 
740
        gchar **item;
 
741
 
 
742
        if (!text)
 
743
                return;
 
744
 
 
745
        array = g_uri_list_extract_uris (text);
 
746
        item = array;
 
747
        while (*item) {
 
748
                if (**item != '\0') {
 
749
                        GFile *file;
 
750
                        gchar *uri;
 
751
 
 
752
                        file = g_file_new_for_commandline_arg (*item);
 
753
                        uri = g_file_get_uri (file);
 
754
                        g_object_unref (file);
 
755
 
 
756
                        brasero_video_disc_add_uri_real (self,
 
757
                                                         uri,
 
758
                                                         -1,
 
759
                                                         -1,
 
760
                                                         -1,
 
761
                                                         NULL);
 
762
                        g_free (uri);
 
763
                }
 
764
 
 
765
                item++;
 
766
        }
 
767
        g_strfreev (array);
 
768
}
 
769
 
 
770
static void
 
771
brasero_video_disc_clipboard_targets_cb (GtkClipboard *clipboard,
 
772
                                         GdkAtom *atoms,
 
773
                                         gint n_atoms,
 
774
                                         BraseroVideoDisc *self)
 
775
{
 
776
        if (brasero_clipboard_selection_may_have_uri (atoms, n_atoms))
 
777
                gtk_clipboard_request_text (clipboard,
 
778
                                            (GtkClipboardTextReceivedFunc) brasero_video_disc_clipboard_text_cb,
 
779
                                            self);
 
780
}
 
781
 
 
782
static void
 
783
brasero_video_disc_paste_activated_cb (GtkAction *action,
 
784
                                       BraseroVideoDisc *self)
 
785
{
 
786
        GtkClipboard *clipboard;
 
787
 
 
788
        clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
 
789
        gtk_clipboard_request_targets (clipboard,
 
790
                                       (GtkClipboardTargetsReceivedFunc) brasero_video_disc_clipboard_targets_cb,
 
791
                                       self);
 
792
}
 
793
 
 
794
static void
 
795
brasero_video_disc_delete_activated_cb (GtkAction *action,
 
796
                                        BraseroVideoDisc *self)
 
797
{
 
798
        brasero_video_disc_delete_selected (BRASERO_DISC (self));
 
799
}
 
800
 
 
801
static gboolean
 
802
brasero_video_disc_button_pressed_cb (GtkTreeView *tree,
 
803
                                      GdkEventButton *event,
 
804
                                      BraseroVideoDisc *self)
 
805
{
 
806
        GtkWidgetClass *widget_class;
 
807
        BraseroVideoDiscPrivate *priv;
 
808
 
 
809
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
810
 
 
811
        widget_class = GTK_WIDGET_GET_CLASS (tree);
 
812
 
 
813
        if (event->button == 3) {
 
814
                GtkTreeSelection *selection;
 
815
                GtkTreePath *path = NULL;
 
816
                GtkWidget *widget;
 
817
 
 
818
                gtk_tree_view_get_path_at_pos (tree,
 
819
                                               event->x,
 
820
                                               event->y,
 
821
                                               &path,
 
822
                                               NULL,
 
823
                                               NULL,
 
824
                                               NULL);
 
825
 
 
826
                selection = gtk_tree_view_get_selection (tree);
 
827
 
 
828
                /* Don't update the selection if the right click was on one of
 
829
                 * the already selected rows */
 
830
                if (!path || !gtk_tree_selection_path_is_selected (selection, path))
 
831
                        widget_class->button_press_event (GTK_WIDGET (tree), event);
 
832
 
 
833
                widget = gtk_ui_manager_get_widget (priv->manager, "/ContextMenu/PasteAudio");
 
834
                if (widget) {
 
835
                        if (gtk_clipboard_wait_is_text_available (gtk_clipboard_get (GDK_SELECTION_CLIPBOARD)))
 
836
                                gtk_widget_set_sensitive (widget, TRUE);
 
837
                        else
 
838
                                gtk_widget_set_sensitive (widget, FALSE);
 
839
                }
 
840
 
 
841
                widget = gtk_ui_manager_get_widget (priv->manager,"/ContextMenu");
 
842
                gtk_menu_popup (GTK_MENU (widget),
 
843
                                NULL,
 
844
                                NULL,
 
845
                                NULL,
 
846
                                NULL,
 
847
                                event->button,
 
848
                                event->time);
 
849
                return TRUE;
 
850
        }
 
851
        else if (event->button == 1) {
 
852
                gboolean result;
 
853
                GtkTreePath *treepath = NULL;
 
854
 
 
855
                result = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (tree),
 
856
                                                        event->x,
 
857
                                                        event->y,
 
858
                                                        &treepath,
 
859
                                                        NULL,
 
860
                                                        NULL,
 
861
                                                        NULL);
 
862
 
 
863
                /* we call the default handler for the treeview before everything else
 
864
                 * so it can update itself (paticularly its selection) before we have
 
865
                 * a look at it */
 
866
                widget_class->button_press_event (GTK_WIDGET (tree), event);
 
867
                
 
868
                if (!treepath) {
 
869
                        GtkTreeSelection *selection;
 
870
 
 
871
                        /* This is to deselect any row when selecting a 
 
872
                         * row that cannot be selected or in an empty
 
873
                         * part */
 
874
                        selection = gtk_tree_view_get_selection (tree);
 
875
                        gtk_tree_selection_unselect_all (selection);
 
876
                        return FALSE;
 
877
                }
 
878
        
 
879
                if (!result)
 
880
                        return FALSE;
 
881
 
 
882
                brasero_disc_selection_changed (BRASERO_DISC (self));
 
883
                if (event->type == GDK_2BUTTON_PRESS) {
 
884
                        BraseroVideoFile *file;
 
885
                        GtkTreeModel *model;
 
886
 
 
887
                        model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree));
 
888
                        file = brasero_video_tree_model_path_to_file (BRASERO_VIDEO_TREE_MODEL (model), treepath);
 
889
                        if (file)
 
890
                                brasero_video_disc_edit_song_properties_file (self, file);
 
891
                }
 
892
        }
 
893
 
 
894
        return TRUE;
 
895
}
 
896
 
 
897
static guint
 
898
brasero_video_disc_add_ui (BraseroDisc *disc,
 
899
                           GtkUIManager *manager,
 
900
                           GtkWidget *message)
 
901
{
 
902
        BraseroVideoDiscPrivate *priv;
 
903
        GError *error = NULL;
 
904
        guint merge_id;
 
905
 
 
906
        priv = BRASERO_VIDEO_DISC_PRIVATE (disc);
 
907
 
 
908
        if (priv->message) {
 
909
                g_object_unref (priv->message);
 
910
                priv->message = NULL;
 
911
        }
 
912
 
 
913
        priv->message = message;
 
914
        g_object_ref (message);
 
915
 
 
916
        if (!priv->disc_group) {
 
917
                priv->disc_group = gtk_action_group_new (BRASERO_DISC_ACTION);
 
918
                gtk_action_group_set_translation_domain (priv->disc_group, GETTEXT_PACKAGE);
 
919
                gtk_action_group_add_actions (priv->disc_group,
 
920
                                              entries,
 
921
                                              G_N_ELEMENTS (entries),
 
922
                                              disc);
 
923
/*              gtk_action_group_add_toggle_actions (priv->disc_group,
 
924
                                                     toggle_entries,
 
925
                                                     G_N_ELEMENTS (toggle_entries),
 
926
                                                     disc);     */
 
927
                gtk_ui_manager_insert_action_group (manager,
 
928
                                                    priv->disc_group,
 
929
                                                    0);
 
930
        }
 
931
 
 
932
        merge_id = gtk_ui_manager_add_ui_from_string (manager,
 
933
                                                      description,
 
934
                                                      -1,
 
935
                                                      &error);
 
936
        if (!merge_id) {
 
937
                BRASERO_BURN_LOG ("Adding ui elements failed: %s", error->message);
 
938
                g_error_free (error);
 
939
                return 0;
 
940
        }
 
941
 
 
942
        priv->manager = manager;
 
943
        g_object_ref (manager);
 
944
        return merge_id;
 
945
}
 
946
 
 
947
static void
 
948
brasero_video_disc_rename_activated (BraseroVideoDisc *self)
 
949
{
 
950
        BraseroVideoDiscPrivate *priv;
 
951
        GtkTreeSelection *selection;
 
952
        GtkTreeViewColumn *column;
 
953
        GtkTreePath *treepath;
 
954
        GtkTreeModel *model;
 
955
        GList *list;
 
956
 
 
957
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
958
 
 
959
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree));
 
960
        list = gtk_tree_selection_get_selected_rows (selection, &model);
 
961
 
 
962
        for (; list; list = g_list_remove (list, treepath)) {
 
963
                treepath = list->data;
 
964
 
 
965
                gtk_widget_grab_focus (priv->tree);
 
966
                column = gtk_tree_view_get_column (GTK_TREE_VIEW (priv->tree), 0);
 
967
                gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (priv->tree),
 
968
                                              treepath,
 
969
                                              NULL,
 
970
                                              TRUE,
 
971
                                              0.5,
 
972
                                              0.5);
 
973
                gtk_tree_view_set_cursor (GTK_TREE_VIEW (priv->tree),
 
974
                                          treepath,
 
975
                                          column,
 
976
                                          TRUE);
 
977
 
 
978
                gtk_tree_path_free (treepath);
 
979
        }
 
980
}
 
981
 
 
982
static gboolean
 
983
brasero_video_disc_key_released_cb (GtkTreeView *tree,
 
984
                                    GdkEventKey *event,
 
985
                                    BraseroVideoDisc *self)
 
986
{
 
987
        BraseroVideoDiscPrivate *priv;
 
988
 
 
989
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
990
        if (priv->editing)
 
991
                return FALSE;
 
992
 
 
993
        if (event->keyval == GDK_KP_Delete || event->keyval == GDK_Delete) {
 
994
                brasero_video_disc_delete_selected (BRASERO_DISC (self));
 
995
        }
 
996
        else if (event->keyval == GDK_F2)
 
997
                brasero_video_disc_rename_activated (self);
 
998
 
 
999
        return FALSE;
 
1000
}
 
1001
 
 
1002
static void
 
1003
brasero_video_disc_row_deleted_cb (GtkTreeModel *model,
 
1004
                                   GtkTreePath *path,
 
1005
                                   BraseroVideoDisc *self)
 
1006
{
 
1007
        BraseroVideoProject *project;
 
1008
        BraseroVideoDiscPrivate *priv;
 
1009
 
 
1010
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
1011
        project = BRASERO_VIDEO_PROJECT (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree)));
 
1012
        brasero_disc_contents_changed (BRASERO_DISC (self),
 
1013
                                       brasero_video_project_get_file_num (BRASERO_VIDEO_PROJECT (model)));
 
1014
}
 
1015
 
 
1016
static void
 
1017
brasero_video_disc_row_inserted_cb (GtkTreeModel *model,
 
1018
                                    GtkTreePath *path,
 
1019
                                    GtkTreeIter *iter,
 
1020
                                    BraseroVideoDisc *self)
 
1021
{
 
1022
        BraseroVideoProject *project;
 
1023
        BraseroVideoDiscPrivate *priv;
 
1024
 
 
1025
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
1026
        project = BRASERO_VIDEO_PROJECT (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree)));
 
1027
        brasero_disc_contents_changed (BRASERO_DISC (self),
 
1028
                                       brasero_video_project_get_file_num (BRASERO_VIDEO_PROJECT (model)));
 
1029
}
 
1030
 
 
1031
static void
 
1032
brasero_video_disc_row_changed_cb (GtkTreeModel *model,
 
1033
                                   GtkTreePath *path,
 
1034
                                   GtkTreeIter *iter,
 
1035
                                   BraseroVideoDisc *self)
 
1036
{
 
1037
        BraseroVideoProject *project;
 
1038
        BraseroVideoDiscPrivate *priv;
 
1039
 
 
1040
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
1041
        project = BRASERO_VIDEO_PROJECT (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree)));
 
1042
        brasero_disc_contents_changed (BRASERO_DISC (self),
 
1043
                                       brasero_video_project_get_file_num (BRASERO_VIDEO_PROJECT (model)));
 
1044
}
 
1045
 
 
1046
static void
 
1047
brasero_video_disc_size_changed_cb (BraseroVideoProject *project,
 
1048
                                    BraseroVideoDisc *self)
 
1049
{
 
1050
        brasero_disc_size_changed (BRASERO_DISC (self), brasero_video_project_get_size (project));
 
1051
}
 
1052
 
 
1053
static void
 
1054
brasero_video_disc_init (BraseroVideoDisc *object)
 
1055
{
 
1056
        BraseroVideoDiscPrivate *priv;
 
1057
        GtkTreeSelection *selection;
 
1058
        GtkTreeViewColumn *column;
 
1059
        GtkCellRenderer *renderer;
 
1060
        GtkTreeModel *model;
 
1061
        GtkWidget *mainbox;
 
1062
        GtkWidget *scroll;
 
1063
 
 
1064
        priv = BRASERO_VIDEO_DISC_PRIVATE (object);
 
1065
 
 
1066
        /* the information displayed about how to use this tree */
 
1067
        priv->notebook = brasero_disc_get_use_info_notebook ();
 
1068
        gtk_widget_show (priv->notebook);
 
1069
        gtk_box_pack_start (GTK_BOX (object), priv->notebook, TRUE, TRUE, 0);
 
1070
 
 
1071
        mainbox = gtk_vbox_new (FALSE, 12);
 
1072
        gtk_widget_show (mainbox);
 
1073
        gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), mainbox, NULL);
 
1074
        gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), 0);
 
1075
 
 
1076
        /* Tree */
 
1077
        model = GTK_TREE_MODEL (brasero_video_tree_model_new ());
 
1078
 
 
1079
        g_signal_connect (G_OBJECT (model),
 
1080
                          "row-deleted",
 
1081
                          G_CALLBACK (brasero_video_disc_row_deleted_cb),
 
1082
                          object);
 
1083
        g_signal_connect (G_OBJECT (model),
 
1084
                          "row-inserted",
 
1085
                          G_CALLBACK (brasero_video_disc_row_inserted_cb),
 
1086
                          object);
 
1087
        g_signal_connect (G_OBJECT (model),
 
1088
                          "row-changed",
 
1089
                          G_CALLBACK (brasero_video_disc_row_changed_cb),
 
1090
                          object);
 
1091
 
 
1092
        g_signal_connect (G_OBJECT (model),
 
1093
                          "size-changed",
 
1094
                          G_CALLBACK (brasero_video_disc_size_changed_cb),
 
1095
                          object);
 
1096
        g_signal_connect (G_OBJECT (model),
 
1097
                          "not-video-uri",
 
1098
                          G_CALLBACK (brasero_video_disc_not_video_dialog),
 
1099
                          object);
 
1100
        g_signal_connect (G_OBJECT (model),
 
1101
                          "directory-uri",
 
1102
                          G_CALLBACK (brasero_video_disc_directory_dialog),
 
1103
                          object);
 
1104
        g_signal_connect (G_OBJECT (model),
 
1105
                          "unreadable-uri",
 
1106
                          G_CALLBACK (brasero_video_disc_unreadable_uri_dialog),
 
1107
                          object);
 
1108
        g_signal_connect (G_OBJECT (model),
 
1109
                          "vfs-activity",
 
1110
                          G_CALLBACK (brasero_video_disc_vfs_activity_changed),
 
1111
                          object);
 
1112
 
 
1113
        priv->tree = gtk_tree_view_new_with_model (model);
 
1114
        egg_tree_multi_drag_add_drag_support (GTK_TREE_VIEW (priv->tree));
 
1115
        g_object_unref (G_OBJECT (model));
 
1116
        gtk_widget_show (priv->tree);
 
1117
 
 
1118
        g_signal_connect (priv->tree,
 
1119
                          "button-press-event",
 
1120
                          G_CALLBACK (brasero_video_disc_button_pressed_cb),
 
1121
                          object);
 
1122
        g_signal_connect (priv->tree,
 
1123
                          "key-release-event",
 
1124
                          G_CALLBACK (brasero_video_disc_key_released_cb),
 
1125
                          object);
 
1126
 
 
1127
        gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (priv->tree), TRUE);
 
1128
        gtk_tree_view_set_rubber_banding (GTK_TREE_VIEW (priv->tree), TRUE);
 
1129
 
 
1130
        /* columns */
 
1131
        column = gtk_tree_view_column_new ();
 
1132
        gtk_tree_view_column_set_resizable (column, TRUE);
 
1133
        gtk_tree_view_column_set_min_width (column, 200);
 
1134
 
 
1135
        renderer = gtk_cell_renderer_pixbuf_new ();
 
1136
        gtk_tree_view_column_pack_start (column, renderer, FALSE);
 
1137
        gtk_tree_view_column_add_attribute (column, renderer,
 
1138
                                            "pixbuf", BRASERO_VIDEO_TREE_MODEL_MIME_ICON);
 
1139
 
 
1140
        renderer = gtk_cell_renderer_text_new ();
 
1141
        g_signal_connect (G_OBJECT (renderer), "edited",
 
1142
                          G_CALLBACK (brasero_video_disc_name_edited_cb), object);
 
1143
        g_signal_connect (G_OBJECT (renderer), "editing-started",
 
1144
                          G_CALLBACK (brasero_video_disc_name_editing_started_cb), object);
 
1145
        g_signal_connect (G_OBJECT (renderer), "editing-canceled",
 
1146
                          G_CALLBACK (brasero_video_disc_name_editing_canceled_cb), object);
 
1147
 
 
1148
        g_object_set (G_OBJECT (renderer),
 
1149
                      "mode", GTK_CELL_RENDERER_MODE_EDITABLE,
 
1150
                      "ellipsize-set", TRUE,
 
1151
                      "ellipsize", PANGO_ELLIPSIZE_END,
 
1152
                      NULL);
 
1153
 
 
1154
        gtk_tree_view_column_pack_end (column, renderer, TRUE);
 
1155
        gtk_tree_view_column_add_attribute (column, renderer,
 
1156
                                            "markup", BRASERO_VIDEO_TREE_MODEL_NAME);
 
1157
        gtk_tree_view_column_add_attribute (column, renderer,
 
1158
                                            "editable", BRASERO_VIDEO_TREE_MODEL_EDITABLE);
 
1159
        gtk_tree_view_column_set_title (column, _("Title"));
 
1160
        g_object_set (G_OBJECT (column),
 
1161
                      "expand", TRUE,
 
1162
                      "spacing", 4,
 
1163
                      NULL);
 
1164
        gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree),
 
1165
                                     column);
 
1166
 
 
1167
        gtk_tree_view_set_expander_column (GTK_TREE_VIEW (priv->tree),
 
1168
                                           column);
 
1169
 
 
1170
 
 
1171
        renderer = gtk_cell_renderer_text_new ();
 
1172
        column = gtk_tree_view_column_new ();
 
1173
        gtk_tree_view_column_pack_start (column, renderer, FALSE);
 
1174
 
 
1175
        gtk_tree_view_column_add_attribute (column, renderer,
 
1176
                                            "text", BRASERO_VIDEO_TREE_MODEL_SIZE);
 
1177
        gtk_tree_view_column_set_title (column, _("Size"));
 
1178
 
 
1179
        gtk_tree_view_append_column (GTK_TREE_VIEW (priv->tree), column);
 
1180
        gtk_tree_view_column_set_resizable (column, TRUE);
 
1181
        gtk_tree_view_column_set_expand (column, FALSE);
 
1182
 
 
1183
        /* selection */
 
1184
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree));
 
1185
        gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE);
 
1186
        g_signal_connect (selection,
 
1187
                          "changed",
 
1188
                          G_CALLBACK (brasero_video_disc_selection_changed_cb),
 
1189
                          object);
 
1190
        gtk_tree_selection_set_select_function (selection,
 
1191
                                                brasero_video_disc_selection_function,
 
1192
                                                NULL,
 
1193
                                                NULL);
 
1194
 
 
1195
        /* scroll */
 
1196
        scroll = gtk_scrolled_window_new (NULL, NULL);
 
1197
        gtk_widget_show (scroll);
 
1198
        gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll),
 
1199
                                             GTK_SHADOW_IN);
 
1200
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
 
1201
                                        GTK_POLICY_AUTOMATIC,
 
1202
                                        GTK_POLICY_AUTOMATIC);
 
1203
        gtk_container_add (GTK_CONTAINER (scroll), priv->tree);
 
1204
        gtk_box_pack_start (GTK_BOX (mainbox), scroll, TRUE, TRUE, 0);
 
1205
 
 
1206
        /* dnd */
 
1207
        gtk_tree_view_enable_model_drag_dest (GTK_TREE_VIEW
 
1208
                                              (priv->tree),
 
1209
                                              ntables_cd, nb_targets_cd,
 
1210
                                              GDK_ACTION_COPY |
 
1211
                                              GDK_ACTION_MOVE);
 
1212
 
 
1213
        gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (priv->tree),
 
1214
                                                GDK_BUTTON1_MASK,
 
1215
                                                ntables_source,
 
1216
                                                nb_targets_source,
 
1217
                                                GDK_ACTION_MOVE);
 
1218
}
 
1219
 
 
1220
static void
 
1221
brasero_video_disc_reset_real (BraseroVideoDisc *self)
 
1222
{
 
1223
        BraseroVideoProject *project;
 
1224
        BraseroVideoDiscPrivate *priv;
 
1225
 
 
1226
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
1227
        project = BRASERO_VIDEO_PROJECT (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree)));
 
1228
        brasero_video_project_reset (project);
 
1229
        brasero_video_disc_vfs_activity_changed (project, FALSE, self);
 
1230
}
 
1231
 
 
1232
static void
 
1233
brasero_video_disc_clear (BraseroDisc *disc)
 
1234
{
 
1235
        BraseroVideoDiscPrivate *priv;
 
1236
 
 
1237
        priv = BRASERO_VIDEO_DISC_PRIVATE (disc);
 
1238
 
 
1239
        brasero_video_disc_reset_real (BRASERO_VIDEO_DISC (disc));
 
1240
 
 
1241
        gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), 0);
 
1242
        brasero_disc_size_changed (disc, 0);
 
1243
}
 
1244
 
 
1245
static void
 
1246
brasero_video_disc_reset (BraseroDisc *disc)
 
1247
{
 
1248
        brasero_video_disc_reset_real (BRASERO_VIDEO_DISC (disc));
 
1249
}
 
1250
 
 
1251
static void
 
1252
brasero_video_disc_finalize (GObject *object)
 
1253
{
 
1254
        G_OBJECT_CLASS (brasero_video_disc_parent_class)->finalize (object);
 
1255
}
 
1256
 
 
1257
static void
 
1258
brasero_video_disc_get_property (GObject * object,
 
1259
                                 guint prop_id,
 
1260
                                 GValue * value,
 
1261
                                 GParamSpec * pspec)
 
1262
{
 
1263
        BraseroVideoDiscPrivate *priv;
 
1264
 
 
1265
        priv = BRASERO_VIDEO_DISC_PRIVATE (object);
 
1266
 
 
1267
        switch (prop_id) {
 
1268
        case PROP_REJECT_FILE:
 
1269
                g_value_set_boolean (value, priv->reject_files);
 
1270
                break;
 
1271
        default:
 
1272
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
1273
                break;
 
1274
        }
 
1275
}
 
1276
 
 
1277
static void
 
1278
brasero_video_disc_set_property (GObject * object,
 
1279
                                 guint prop_id,
 
1280
                                 const GValue * value,
 
1281
                                 GParamSpec * pspec)
 
1282
{
 
1283
        BraseroVideoDiscPrivate *priv;
 
1284
 
 
1285
        priv = BRASERO_VIDEO_DISC_PRIVATE (object);
 
1286
 
 
1287
        switch (prop_id) {
 
1288
        case PROP_REJECT_FILE:
 
1289
                priv->reject_files = g_value_get_boolean (value);
 
1290
                break;
 
1291
        default:
 
1292
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
1293
                break;
 
1294
        }
 
1295
}
 
1296
 
 
1297
static BraseroDiscResult
 
1298
brasero_video_disc_get_status (BraseroDisc *self,
 
1299
                               gint *remaining,
 
1300
                               gchar **current_task)
 
1301
{
 
1302
        BraseroVideoProject *project;
 
1303
        BraseroVideoDiscPrivate *priv;
 
1304
 
 
1305
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
1306
        project = BRASERO_VIDEO_PROJECT (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree)));
 
1307
        return brasero_video_project_get_status (project, remaining, current_task);
 
1308
}
 
1309
 
 
1310
BraseroDiscResult
 
1311
brasero_video_disc_set_session_param (BraseroDisc *self,
 
1312
                                      BraseroBurnSession *session)
 
1313
{
 
1314
        BraseroVideoDiscPrivate *priv;
 
1315
        BraseroTrackType type;
 
1316
        GtkTreeModel *model;
 
1317
        GValue *value;
 
1318
 
 
1319
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
1320
 
 
1321
        type.type = BRASERO_TRACK_TYPE_AUDIO;
 
1322
        type.subtype.audio_format = BRASERO_AUDIO_FORMAT_UNDEFINED|BRASERO_VIDEO_FORMAT_UNDEFINED;
 
1323
        brasero_burn_session_set_input_type (session, &type);
 
1324
 
 
1325
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree));
 
1326
        value = g_new0 (GValue, 1);
 
1327
        g_value_init (value, G_TYPE_INT64);
 
1328
        g_value_set_int64 (value, brasero_video_project_get_size (BRASERO_VIDEO_PROJECT (model)));
 
1329
        brasero_burn_session_tag_add (session,
 
1330
                                      BRASERO_AUDIO_TRACK_SIZE_TAG,
 
1331
                                      value);
 
1332
        return BRASERO_BURN_OK;
 
1333
}
 
1334
 
 
1335
BraseroDiscResult
 
1336
brasero_video_disc_set_session_contents (BraseroDisc *self,
 
1337
                                         BraseroBurnSession *session)
 
1338
{
 
1339
        GSList *tracks, *iter;
 
1340
        BraseroVideoProject *project;
 
1341
        BraseroVideoDiscPrivate *priv;
 
1342
 
 
1343
        priv = BRASERO_VIDEO_DISC_PRIVATE (self);
 
1344
        project = BRASERO_VIDEO_PROJECT (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree)));
 
1345
        tracks = brasero_video_project_get_contents (project, FALSE);
 
1346
 
 
1347
        if (!tracks)
 
1348
                return BRASERO_DISC_ERROR_EMPTY_SELECTION;
 
1349
 
 
1350
        for (iter = tracks; iter; iter = iter->next) {
 
1351
                BraseroTrack *track;
 
1352
 
 
1353
                track = iter->data;
 
1354
                brasero_burn_session_add_track (session, track);
 
1355
 
 
1356
                /* It's good practice to unref the track afterwards as we don't
 
1357
                 * need it anymore. BraseroBurnSession refs it. */
 
1358
                brasero_track_unref (track);
 
1359
 
 
1360
        }
 
1361
        g_slist_free (tracks);
 
1362
        return BRASERO_DISC_OK;
 
1363
}
 
1364
 
 
1365
static BraseroDiscResult
 
1366
brasero_video_disc_get_track (BraseroDisc *disc,
 
1367
                              BraseroDiscTrack *disc_track)
 
1368
{
 
1369
        GSList *iter;
 
1370
        GSList *tracks;
 
1371
        BraseroVideoProject *project;
 
1372
        BraseroVideoDiscPrivate *priv;
 
1373
 
 
1374
        disc_track->type = BRASERO_PROJECT_TYPE_VIDEO;
 
1375
 
 
1376
        priv = BRASERO_VIDEO_DISC_PRIVATE (disc);
 
1377
        project = BRASERO_VIDEO_PROJECT (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree)));
 
1378
        tracks = brasero_video_project_get_contents (project, TRUE);
 
1379
 
 
1380
        for (iter = tracks; iter; iter = iter->next) {
 
1381
                BraseroDiscSong *song;
 
1382
                BraseroTrack *track;
 
1383
 
 
1384
                track = iter->data;
 
1385
 
 
1386
                song = g_new0 (BraseroDiscSong, 1);
 
1387
                song->uri = brasero_track_get_audio_source (track, TRUE);
 
1388
                song->start = brasero_track_get_audio_start (track);
 
1389
                song->end = brasero_track_get_audio_end (track);
 
1390
                song->info = brasero_song_info_copy (brasero_track_get_audio_info (track));
 
1391
 
 
1392
                disc_track->contents.tracks = g_slist_append (disc_track->contents.tracks, song);
 
1393
        }
 
1394
 
 
1395
        g_slist_foreach (tracks, (GFunc) brasero_track_unref, NULL);
 
1396
        g_slist_free (tracks);
 
1397
 
 
1398
        return BRASERO_DISC_OK;
 
1399
}
 
1400
 
 
1401
static BraseroDiscResult
 
1402
brasero_video_disc_load_track (BraseroDisc *disc,
 
1403
                               BraseroDiscTrack *track)
 
1404
{
 
1405
        GSList *iter;
 
1406
        BraseroVideoProject *project;
 
1407
        BraseroVideoDiscPrivate *priv;
 
1408
 
 
1409
        g_return_val_if_fail (track->type == BRASERO_PROJECT_TYPE_VIDEO, FALSE);
 
1410
 
 
1411
        if (track->contents.tracks == NULL)
 
1412
                return BRASERO_DISC_ERROR_EMPTY_SELECTION;
 
1413
 
 
1414
        priv = BRASERO_VIDEO_DISC_PRIVATE (disc);
 
1415
        project = BRASERO_VIDEO_PROJECT (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->tree)));
 
1416
        priv->loading = g_slist_length (track->contents.tracks);
 
1417
 
 
1418
        for (iter = track->contents.tracks; iter; iter = iter->next) {
 
1419
                BraseroDiscSong *song;
 
1420
 
 
1421
                song = iter->data;
 
1422
 
 
1423
                brasero_video_project_add_uri (BRASERO_VIDEO_PROJECT (project),
 
1424
                                               song->uri,
 
1425
                                               song->info,
 
1426
                                               NULL,
 
1427
                                               song->start,
 
1428
                                               song->end);
 
1429
        }
 
1430
        gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), 1);
 
1431
 
 
1432
        return BRASERO_DISC_OK;
 
1433
}
 
1434
 
 
1435
static void
 
1436
brasero_video_disc_iface_disc_init (BraseroDiscIface *iface)
 
1437
{
 
1438
        iface->add_uri = brasero_video_disc_add_uri;
 
1439
        iface->delete_selected = brasero_video_disc_delete_selected;
 
1440
        iface->clear = brasero_video_disc_clear;
 
1441
        iface->reset = brasero_video_disc_reset;
 
1442
 
 
1443
        iface->get_status = brasero_video_disc_get_status;
 
1444
        iface->set_session_param = brasero_video_disc_set_session_param;
 
1445
        iface->set_session_contents = brasero_video_disc_set_session_contents;
 
1446
 
 
1447
        iface->get_track = brasero_video_disc_get_track;
 
1448
        iface->load_track = brasero_video_disc_load_track;
 
1449
 
 
1450
        iface->get_selected_uri = brasero_video_disc_get_selected_uri;
 
1451
        iface->add_ui = brasero_video_disc_add_ui;
 
1452
}
 
1453
 
 
1454
static void
 
1455
brasero_video_disc_class_init (BraseroVideoDiscClass *klass)
 
1456
{
 
1457
        GObjectClass* object_class = G_OBJECT_CLASS (klass);
 
1458
 
 
1459
        g_type_class_add_private (klass, sizeof (BraseroVideoDiscPrivate));
 
1460
 
 
1461
        object_class->finalize = brasero_video_disc_finalize;
 
1462
        object_class->set_property = brasero_video_disc_set_property;
 
1463
        object_class->get_property = brasero_video_disc_get_property;
 
1464
 
 
1465
        g_object_class_install_property (object_class,
 
1466
                                         PROP_REJECT_FILE,
 
1467
                                         g_param_spec_boolean
 
1468
                                         ("reject-file",
 
1469
                                          "Whether it accepts files",
 
1470
                                          "Whether it accepts files",
 
1471
                                          FALSE,
 
1472
                                          G_PARAM_READWRITE));
 
1473
}
 
1474
 
 
1475
GtkWidget *
 
1476
brasero_video_disc_new (void)
 
1477
{
 
1478
        return g_object_new (BRASERO_TYPE_VIDEO_DISC, NULL);
 
1479
}
 
1480