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

« back to all changes in this revision

Viewing changes to nautilus/nautilus-burn-extension.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: nil; c-basic-offset: 8; tab-width: 8 -*-
 
2
 *
 
3
 * Copyright (C) 2003 Novell, Inc.
 
4
 * Copyright (C) 2003-2004 Red Hat, Inc.
 
5
 * Copyright (C) 2005 William Jon McCann <mccann@jhu.edu>
 
6
 * Copyright (C) 2008 Philippe Rouquier <bonfire-app@wanadoo.fr> (modified to work with brasero)
 
7
 *
 
8
 * This program is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU General Public License as
 
10
 * published by the Free Software Foundation; either version 2 of the
 
11
 * License, or (at your option) any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public
 
19
 * License along with this program; if not, write to the
 
20
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
21
 * Boston, MA 02111-1307, USA.
 
22
 *
 
23
 */
 
24
 
 
25
#include "config.h"
 
26
 
 
27
#include <stdlib.h>
 
28
#include <string.h>
 
29
#include <glib/gi18n-lib.h>
 
30
#include <gdk/gdkx.h>
 
31
#include <gtk/gtk.h>
 
32
#include <libnautilus-extension/nautilus-menu-provider.h>
 
33
#include <libnautilus-extension/nautilus-location-widget-provider.h>
 
34
 
 
35
#include "brasero-media.h"
 
36
#include "brasero-medium-monitor.h"
 
37
#include "brasero-drive.h"
 
38
#include "brasero-medium.h"
 
39
#include "nautilus-burn-bar.h"
 
40
 
 
41
#define BURN_URI "burn:///"
 
42
 
 
43
#define NAUTILUS_TYPE_DISC_BURN  (nautilus_disc_burn_get_type ())
 
44
#define NAUTILUS_DISC_BURN(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), NAUTILUS_TYPE_DISC_BURN, NautilusDiscBurn))
 
45
#define NAUTILUS_IS_DISC_BURN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), NAUTILUS_TYPE_DISC_BURN))
 
46
 
 
47
typedef struct _NautilusDiscBurnPrivate NautilusDiscBurnPrivate;
 
48
 
 
49
typedef struct
 
50
{
 
51
        GObject              parent_slot;
 
52
        NautilusDiscBurnPrivate *priv;
 
53
} NautilusDiscBurn;
 
54
 
 
55
typedef struct
 
56
{
 
57
        GObjectClass parent_slot;
 
58
} NautilusDiscBurnClass;
 
59
 
 
60
#define NAUTILUS_DISC_BURN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAUTILUS_TYPE_DISC_BURN, NautilusDiscBurnPrivate))
 
61
 
 
62
struct _NautilusDiscBurnPrivate
 
63
{
 
64
        GFileMonitor *burn_monitor;
 
65
        guint         empty : 1;
 
66
 
 
67
        guint         start_monitor_id;
 
68
        guint         empty_update_id;
 
69
 
 
70
        GSList       *widget_list;
 
71
};
 
72
 
 
73
static GType nautilus_disc_burn_get_type      (void);
 
74
static void  nautilus_disc_burn_register_type (GTypeModule *module);
 
75
 
 
76
static GObjectClass *parent_class;
 
77
 
 
78
//#define DEBUG_PRINT(format_MACRO,...)           g_print (format_MACRO, ##__VA_ARGS__);
 
79
#define DEBUG_PRINT(format_MACRO,...)             
 
80
 
 
81
static void
 
82
launch_process (GPtrArray *argv, GtkWindow *parent)
 
83
{
 
84
        GtkWidget *dialog;
 
85
        GError *error;
 
86
        gchar **args;
 
87
 
 
88
        if (parent && GTK_WIDGET (parent)->window) {
 
89
                guint xid;
 
90
 
 
91
                xid = gdk_x11_drawable_get_xid (GDK_DRAWABLE (GTK_WIDGET (parent)->window));
 
92
                if (xid > 0) {
 
93
                        g_ptr_array_add (argv, g_strdup ("-x"));
 
94
                        g_ptr_array_add (argv, g_strdup_printf ("%d", xid));
 
95
                }
 
96
        }
 
97
 
 
98
        error = NULL;
 
99
        g_ptr_array_add (argv, NULL);
 
100
        args = (gchar **) g_ptr_array_free (argv, FALSE);
 
101
        if (!g_spawn_async (NULL,
 
102
                            args, NULL,
 
103
                            0,
 
104
                            NULL, NULL,
 
105
                            NULL,
 
106
                            &error)) {
 
107
 
 
108
                dialog = gtk_message_dialog_new (parent,
 
109
                                                 GTK_DIALOG_MODAL,
 
110
                                                 GTK_MESSAGE_WARNING,
 
111
                                                 GTK_BUTTONS_OK,
 
112
                                                 _("Unable to launch the cd burner application"));
 
113
 
 
114
                gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
 
115
                                                          "%s",
 
116
                                                          error->message);
 
117
 
 
118
                gtk_dialog_run (GTK_DIALOG (dialog));
 
119
                gtk_widget_destroy (dialog);
 
120
 
 
121
 
 
122
                g_error_free (error);
 
123
        }
 
124
 
 
125
        g_strfreev (args);
 
126
}
 
127
 
 
128
static void
 
129
launch_brasero_on_window (GtkWindow *window)
 
130
{
 
131
        int i;
 
132
        GPtrArray        *argv = NULL;
 
133
 
 
134
        argv = g_ptr_array_new ();
 
135
        g_ptr_array_add (argv, g_build_filename (BINDIR, "brasero", NULL));
 
136
        g_ptr_array_add (argv, g_strdup ("-n"));
 
137
 
 
138
        launch_process (argv, window);
 
139
}
 
140
 
 
141
static void
 
142
write_activate_cb (NautilusMenuItem *item,
 
143
                   gpointer          user_data)
 
144
{
 
145
        launch_brasero_on_window (GTK_WINDOW (user_data));
 
146
}
 
147
 
 
148
static void
 
149
write_iso_activate_cb (NautilusMenuItem *item,
 
150
                       gpointer          user_data)
 
151
{
 
152
        NautilusFileInfo *file_info;
 
153
        GPtrArray        *argv = NULL;
 
154
        char             *uri;
 
155
        char             *image_path;
 
156
        int               i;
 
157
 
 
158
        file_info = g_object_get_data (G_OBJECT (item), "file_info");
 
159
 
 
160
        uri = nautilus_file_info_get_uri (file_info);
 
161
        image_path = g_filename_from_uri (uri, NULL, NULL);
 
162
 
 
163
        if (image_path == NULL) {
 
164
                g_warning ("Can not get local path for URI %s", uri);
 
165
                g_free (uri);
 
166
                return;
 
167
        }
 
168
 
 
169
        g_free (uri);
 
170
 
 
171
        argv = g_ptr_array_new ();
 
172
        g_ptr_array_add (argv, g_build_filename (BINDIR, "brasero", NULL));
 
173
        g_ptr_array_add (argv, g_strdup ("-i"));
 
174
        g_ptr_array_add (argv, image_path);
 
175
 
 
176
        launch_process (argv, GTK_WINDOW (user_data));
 
177
}
 
178
 
 
179
static void
 
180
copy_disc_activate_cb (NautilusMenuItem *item,
 
181
                       gpointer          user_data)
 
182
{
 
183
        int               i;
 
184
        GPtrArray        *argv = NULL;
 
185
        char             *device_path;
 
186
 
 
187
        device_path = g_object_get_data (G_OBJECT (item), "drive_device_path");
 
188
 
 
189
        if (!device_path) {
 
190
                g_warning ("Drive device path not specified");
 
191
                return;
 
192
        }
 
193
 
 
194
        argv = g_ptr_array_new ();
 
195
        g_ptr_array_add (argv, g_build_filename (BINDIR, "brasero", NULL));
 
196
        g_ptr_array_add (argv, g_strdup ("-c"));
 
197
        g_ptr_array_add (argv, g_strdup (device_path));
 
198
 
 
199
        launch_process (argv, GTK_WINDOW (user_data));
 
200
}
 
201
 
 
202
static void
 
203
blank_disc_activate_cb (NautilusMenuItem *item,
 
204
                        gpointer          user_data)
 
205
{
 
206
        int               i;
 
207
        GPtrArray        *argv = NULL;
 
208
        char             *device_path;
 
209
 
 
210
        device_path = g_object_get_data (G_OBJECT (item), "drive_device_path");
 
211
 
 
212
        if (!device_path) {
 
213
                g_warning ("Drive device path not specified");
 
214
                return;
 
215
        }
 
216
 
 
217
        argv = g_ptr_array_new ();
 
218
        g_ptr_array_add (argv, g_build_filename (BINDIR, "brasero", NULL));
 
219
        g_ptr_array_add (argv, g_strdup ("-b"));
 
220
        g_ptr_array_add (argv, g_strdup (device_path));
 
221
 
 
222
        launch_process (argv, GTK_WINDOW (user_data));
 
223
}
 
224
 
 
225
static void
 
226
check_disc_activate_cb (NautilusMenuItem *item,
 
227
                        gpointer          user_data)
 
228
{
 
229
        int               i;
 
230
        GPtrArray        *argv = NULL;
 
231
        char             *device_path;
 
232
 
 
233
        device_path = g_object_get_data (G_OBJECT (item), "drive_device_path");
 
234
 
 
235
        if (!device_path) {
 
236
                g_warning ("Drive device path not specified");
 
237
                return;
 
238
        }
 
239
 
 
240
        argv = g_ptr_array_new ();
 
241
        g_ptr_array_add (argv, g_build_filename (BINDIR, "brasero", NULL));
 
242
        g_ptr_array_add (argv, g_strdup ("-k"));
 
243
        g_ptr_array_add (argv, g_strdup (device_path));
 
244
 
 
245
        launch_process (argv, GTK_WINDOW (user_data));
 
246
}
 
247
 
 
248
static gboolean
 
249
volume_is_blank (GVolume *volume)
 
250
{
 
251
        BraseroMediumMonitor *monitor;
 
252
        BraseroMedium        *medium;
 
253
        BraseroDrive         *drive;
 
254
        gchar                *device;
 
255
        gboolean              is_blank;
 
256
 
 
257
        is_blank = FALSE;
 
258
 
 
259
        device = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
 
260
        if (!device)
 
261
                return FALSE;
 
262
 
 
263
        DEBUG_PRINT ("Got device: %s\n", device);
 
264
 
 
265
        monitor = brasero_medium_monitor_get_default ();
 
266
        drive = brasero_medium_monitor_get_drive (monitor, device);
 
267
        g_object_unref (monitor);
 
268
        g_free (device);
 
269
 
 
270
        if (drive == NULL)
 
271
                return FALSE;
 
272
 
 
273
        medium = brasero_drive_get_medium (drive);
 
274
        is_blank = (brasero_medium_get_status (medium) & BRASERO_MEDIUM_BLANK);
 
275
        g_object_unref (drive);
 
276
 
 
277
        return is_blank;
 
278
}
 
279
 
 
280
static GVolume *
 
281
drive_get_first_volume (GDrive *drive)
 
282
{
 
283
        GVolume *volume;
 
284
        GList   *volumes;
 
285
 
 
286
        volumes = g_drive_get_volumes (drive);
 
287
 
 
288
        volume = g_list_nth_data (volumes, 0);
 
289
 
 
290
        if (volume != NULL) {
 
291
                g_object_ref (volume);
 
292
        }
 
293
 
 
294
        g_list_foreach (volumes, (GFunc) g_object_unref, NULL);
 
295
        g_list_free (volumes);
 
296
 
 
297
        return volume;
 
298
}
 
299
 
 
300
static gboolean
 
301
drive_is_cd_device (GDrive *gdrive)
 
302
{
 
303
        BraseroMediumMonitor *monitor;
 
304
        BraseroDrive         *drive;
 
305
        gchar                *device;
 
306
 
 
307
        device = g_drive_get_identifier (gdrive, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
 
308
        if (!device)
 
309
                return FALSE;
 
310
 
 
311
        DEBUG_PRINT ("Got device: %s\n", device);
 
312
 
 
313
        monitor = brasero_medium_monitor_get_default ();
 
314
        drive = brasero_medium_monitor_get_drive (monitor, device);
 
315
        g_object_unref (monitor);
 
316
        g_free (device);
 
317
 
 
318
        if (drive == NULL)
 
319
                return FALSE;
 
320
        
 
321
        g_object_unref (drive);
 
322
        return TRUE;
 
323
}
 
324
 
 
325
static GList *
 
326
nautilus_disc_burn_get_file_items (NautilusMenuProvider *provider,
 
327
                                   GtkWidget            *window,
 
328
                                   GList                *selection)
 
329
{
 
330
        GList            *items = NULL;
 
331
        NautilusMenuItem *item;
 
332
        NautilusFileInfo *file_info;
 
333
        GFile            *file;
 
334
        GMount           *mount;
 
335
        GVolume          *volume;
 
336
        GDrive           *drive;
 
337
        char             *mime_type;
 
338
        gboolean          is_iso;
 
339
 
 
340
        DEBUG_PRINT ("Getting file items\n");
 
341
 
 
342
        if (!selection || selection->next != NULL) {
 
343
                return NULL;
 
344
        }
 
345
 
 
346
        file_info = NAUTILUS_FILE_INFO (selection->data);
 
347
 
 
348
        if (nautilus_file_info_is_gone (file_info)) {
 
349
                return NULL;
 
350
        }
 
351
 
 
352
        file = nautilus_file_info_get_location (file_info);
 
353
 
 
354
        if (file == NULL) {
 
355
                DEBUG_PRINT ("No file found\n");
 
356
                return NULL;
 
357
        }
 
358
 
 
359
        mime_type = nautilus_file_info_get_mime_type (file_info);
 
360
        DEBUG_PRINT ("Mime type: %s\n", mime_type);
 
361
        if (! mime_type) {
 
362
                g_object_unref (file);
 
363
                return NULL;
 
364
        }
 
365
 
 
366
        is_iso = (strcmp (mime_type, "application/x-iso-image") == 0)
 
367
                || (strcmp (mime_type, "application/x-cd-image") == 0)
 
368
                || (strcmp (mime_type, "application/x-cue") == 0)
 
369
                || (strcmp (mime_type, "application/x-toc") == 0)
 
370
                || (strcmp (mime_type, "application/x-cdrdao-toc") == 0);
 
371
 
 
372
        if (is_iso) {
 
373
                /* Whether or not this file is local is not a problem */
 
374
                item = nautilus_menu_item_new ("NautilusDiscBurn::write_iso",
 
375
                                               _("_Write to Disc..."),
 
376
                                               _("Write disc image to a CD or DVD disc"),
 
377
                                               "media-optical-data-new");
 
378
                g_object_set_data (G_OBJECT (item), "file_info", file_info);
 
379
                g_object_set_data (G_OBJECT (item), "window", window);
 
380
                g_signal_connect (item, "activate",
 
381
                                  G_CALLBACK (write_iso_activate_cb), window);
 
382
                items = g_list_append (items, item);
 
383
        }
 
384
 
 
385
        /*
 
386
         * We handle two cases here.  The selection is:
 
387
         *  A) a volume
 
388
         *  B) a drive
 
389
         *
 
390
         * This is because there is very little distinction between
 
391
         * the two for CD/DVD media
 
392
         */
 
393
 
 
394
        drive = NULL;
 
395
        volume = NULL;
 
396
 
 
397
        mount = nautilus_file_info_get_mount (file_info);
 
398
        if (mount != NULL) {
 
399
                drive = g_mount_get_drive (mount);
 
400
                volume = g_mount_get_volume (mount);
 
401
        } else {
 
402
                char *uri = g_file_get_uri (file);
 
403
                DEBUG_PRINT ("Mount not found: %s\n", uri);
 
404
                g_free (uri);
 
405
        }
 
406
 
 
407
        if (drive == NULL && volume != NULL) {
 
408
                /* case A */
 
409
                drive = g_volume_get_drive (volume);
 
410
        } else if (volume == NULL && drive != NULL) {
 
411
                /* case B */
 
412
                volume = drive_get_first_volume (drive);
 
413
                if (volume == NULL) {
 
414
                        DEBUG_PRINT ("Volume not found\n");
 
415
                }
 
416
        }
 
417
 
 
418
        if (drive != NULL
 
419
            && volume != NULL
 
420
            && drive_is_cd_device (drive)
 
421
            && ! volume_is_blank (volume)) {
 
422
                char *device_path;
 
423
 
 
424
                device_path = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
 
425
 
 
426
                /* user may want to copy it ... */
 
427
                item = nautilus_menu_item_new ("NautilusDiscBurn::copy_disc",
 
428
                                               _("_Copy Disc..."),
 
429
                                               _("Create a copy of this CD or DVD disc"),
 
430
                                               "media-optical-copy");
 
431
                g_object_set_data (G_OBJECT (item), "file_info", file_info);
 
432
                g_object_set_data (G_OBJECT (item), "window", window);
 
433
                g_object_set_data_full (G_OBJECT (item), "drive_device_path", g_strdup (device_path), g_free);
 
434
                g_signal_connect (item, "activate",
 
435
                                  G_CALLBACK (copy_disc_activate_cb), window);
 
436
                items = g_list_append (items, item);
 
437
 
 
438
                /* ... or if it's a rewritable medium to blank it ... */
 
439
                item = nautilus_menu_item_new ("NautilusDiscBurn::blank_disc",
 
440
                                               _("_Blank Disc..."),
 
441
                                               _("Blank this CD or DVD disc"),
 
442
                                               "media-optical-blank");
 
443
                g_object_set_data (G_OBJECT (item), "file_info", file_info);
 
444
                g_object_set_data (G_OBJECT (item), "window", window);
 
445
                g_object_set_data_full (G_OBJECT (item), "drive_device_path", g_strdup (device_path), g_free);
 
446
                g_signal_connect (item, "activate",
 
447
                                  G_CALLBACK (blank_disc_activate_cb), window);
 
448
                items = g_list_append (items, item);
 
449
 
 
450
                /* ... or verify medium. */
 
451
                item = nautilus_menu_item_new ("NautilusDiscBurn::check_disc",
 
452
                                               _("_Check Disc..."),
 
453
                                               _("Check the data integrity on this CD or DVD disc"),
 
454
                                               NULL);
 
455
                g_object_set_data (G_OBJECT (item), "file_info", file_info);
 
456
                g_object_set_data (G_OBJECT (item), "window", window);
 
457
                g_object_set_data_full (G_OBJECT (item), "drive_device_path", g_strdup (device_path), g_free);
 
458
                g_signal_connect (item, "activate",
 
459
                                  G_CALLBACK (check_disc_activate_cb), window);
 
460
                items = g_list_append (items, item);
 
461
 
 
462
                g_free (device_path);
 
463
        }
 
464
 
 
465
        g_object_unref (file);
 
466
 
 
467
        if (drive != NULL) {
 
468
                g_object_unref (drive);
 
469
        }
 
470
        if (volume != NULL) {
 
471
                g_object_unref (volume);
 
472
        }
 
473
 
 
474
        g_free (mime_type);
 
475
 
 
476
        DEBUG_PRINT ("Items returned\n");
 
477
        return items;
 
478
}
 
479
 
 
480
static GList *
 
481
nautilus_disc_burn_get_background_items (NautilusMenuProvider *provider,
 
482
                                         GtkWidget            *window,
 
483
                                         NautilusFileInfo     *current_folder)
 
484
{
 
485
        GList *items;
 
486
        char  *scheme;
 
487
 
 
488
        items = NULL;
 
489
 
 
490
        scheme = nautilus_file_info_get_uri_scheme (current_folder);
 
491
 
 
492
        if (strcmp (scheme, "burn") == 0) {
 
493
                NautilusMenuItem *item;
 
494
 
 
495
                item = nautilus_menu_item_new ("NautilusDiscBurn::write_menu",
 
496
                                               _("_Write to Disc..."),
 
497
                                               _("Write contents to a CD or DVD disc"),
 
498
                                               "brasero");
 
499
                g_signal_connect (item, "activate",
 
500
                                  G_CALLBACK (write_activate_cb),
 
501
                                  window);
 
502
                items = g_list_append (items, item);
 
503
 
 
504
                g_object_set (item, "sensitive", ! NAUTILUS_DISC_BURN (provider)->priv->empty, NULL);
 
505
        }
 
506
 
 
507
        g_free (scheme);
 
508
 
 
509
        return items;
 
510
}
 
511
 
 
512
static GList *
 
513
nautilus_disc_burn_get_toolbar_items (NautilusMenuProvider *provider,
 
514
                                      GtkWidget            *window,
 
515
                                      NautilusFileInfo     *current_folder)
 
516
{
 
517
        GList *items;
 
518
 
 
519
        items = NULL;
 
520
 
 
521
        return items;
 
522
}
 
523
 
 
524
static void
 
525
nautilus_disc_burn_menu_provider_iface_init (NautilusMenuProviderIface *iface)
 
526
{
 
527
        iface->get_file_items = nautilus_disc_burn_get_file_items;
 
528
        iface->get_background_items = nautilus_disc_burn_get_background_items;
 
529
        iface->get_toolbar_items = nautilus_disc_burn_get_toolbar_items;
 
530
}
 
531
 
 
532
static void
 
533
bar_activated_cb (NautilusDiscBurnBar *bar,
 
534
                  gpointer         data)
 
535
{
 
536
        launch_brasero_on_window (GTK_WINDOW (data));
 
537
}
 
538
 
 
539
static gboolean
 
540
dir_is_empty (const char *uri)
 
541
{
 
542
        GFile           *file;
 
543
        GFileEnumerator *enumerator;
 
544
        GError          *error;
 
545
        gboolean         found_file;
 
546
 
 
547
        file = g_file_new_for_uri (uri);
 
548
 
 
549
        error = NULL;
 
550
        enumerator = g_file_enumerate_children (file,
 
551
                                                G_FILE_ATTRIBUTE_STANDARD_NAME ","
 
552
                                                G_FILE_ATTRIBUTE_STANDARD_TYPE ","
 
553
                                                G_FILE_ATTRIBUTE_ACCESS_CAN_READ,
 
554
                                                0,
 
555
                                                NULL,
 
556
                                                &error);
 
557
        if (enumerator == NULL) {
 
558
                DEBUG_PRINT ("Could not open burn uri %s: %s\n",
 
559
                             uri,
 
560
                             error->message);
 
561
                g_error_free (error);
 
562
                return TRUE;
 
563
        }
 
564
 
 
565
        found_file = FALSE;
 
566
 
 
567
        while (TRUE) {
 
568
                GFileInfo *info;
 
569
 
 
570
                info = g_file_enumerator_next_file (enumerator, NULL, NULL);
 
571
                if (info == NULL) {
 
572
                        break;
 
573
                }
 
574
 
 
575
                g_object_unref (info);
 
576
 
 
577
                found_file = TRUE;
 
578
                break;
 
579
        }
 
580
 
 
581
        g_object_unref (enumerator);
 
582
        g_object_unref (file);
 
583
 
 
584
        return !found_file;
 
585
}
 
586
 
 
587
static void
 
588
destroyed_callback (GtkWidget    *widget,
 
589
                    NautilusDiscBurn *burn)
 
590
{
 
591
        burn->priv->widget_list = g_slist_remove (burn->priv->widget_list, widget);
 
592
}
 
593
 
 
594
static void
 
595
sense_widget (NautilusDiscBurn *burn,
 
596
              GtkWidget    *widget)
 
597
{
 
598
        gtk_widget_set_sensitive (widget, !burn->priv->empty);
 
599
 
 
600
        burn->priv->widget_list = g_slist_prepend (burn->priv->widget_list, widget);
 
601
 
 
602
        g_signal_connect (widget, "destroy",
 
603
                          G_CALLBACK (destroyed_callback),
 
604
                          burn);
 
605
}
 
606
 
 
607
static GtkWidget *
 
608
nautilus_disc_burn_get_location_widget (NautilusLocationWidgetProvider *iface,
 
609
                                        const char                     *uri,
 
610
                                        GtkWidget                      *window)
 
611
{
 
612
        if (g_str_has_prefix (uri, "burn:")) {
 
613
                GtkWidget    *bar;
 
614
                NautilusDiscBurn *burn;
 
615
 
 
616
                DEBUG_PRINT ("Get location widget for burn\n");
 
617
 
 
618
                burn = NAUTILUS_DISC_BURN (iface);
 
619
 
 
620
                bar = nautilus_disc_burn_bar_new ();
 
621
 
 
622
                sense_widget (burn, nautilus_disc_burn_bar_get_button (NAUTILUS_DISC_BURN_BAR (bar)));
 
623
 
 
624
                g_signal_connect (bar, "activate",
 
625
                                  G_CALLBACK (bar_activated_cb),
 
626
                                  window);
 
627
 
 
628
                gtk_widget_show (bar);
 
629
 
 
630
                return bar;
 
631
        }
 
632
 
 
633
        return NULL;
 
634
}
 
635
 
 
636
static void
 
637
nautilus_disc_burn_location_widget_provider_iface_init (NautilusLocationWidgetProviderIface *iface)
 
638
{
 
639
        iface->get_widget = nautilus_disc_burn_get_location_widget;
 
640
}
 
641
 
 
642
static void
 
643
update_widget_sensitivity (GtkWidget    *widget,
 
644
                           NautilusDiscBurn *burn)
 
645
{
 
646
        gtk_widget_set_sensitive (widget, !burn->priv->empty);
 
647
}
 
648
 
 
649
static gboolean
 
650
update_empty_idle (NautilusDiscBurn *burn)
 
651
{
 
652
        gboolean is_empty;
 
653
 
 
654
        burn->priv->empty_update_id = 0;
 
655
 
 
656
        is_empty = dir_is_empty (BURN_URI);
 
657
 
 
658
        DEBUG_PRINT ("Dir is %s\n", is_empty ? "empty" : "not empty");
 
659
 
 
660
        if (burn->priv->empty != is_empty) {
 
661
                burn->priv->empty = is_empty;
 
662
                /* update bar */
 
663
                g_slist_foreach (burn->priv->widget_list, (GFunc)update_widget_sensitivity, burn);
 
664
 
 
665
                /* Trigger update for menu items */
 
666
                nautilus_menu_provider_emit_items_updated_signal (NAUTILUS_MENU_PROVIDER (burn));
 
667
        }
 
668
 
 
669
        return FALSE;
 
670
}
 
671
 
 
672
static void
 
673
queue_update_empty (NautilusDiscBurn *burn)
 
674
{
 
675
        if (burn->priv->empty_update_id != 0) {
 
676
                g_source_remove (burn->priv->empty_update_id);
 
677
        }
 
678
 
 
679
        burn->priv->empty_update_id = g_idle_add ((GSourceFunc)update_empty_idle, burn);
 
680
}
 
681
 
 
682
static void
 
683
burn_monitor_cb (GFileMonitor     *monitor,
 
684
                 GFile            *file,
 
685
                 GFile            *other_file,
 
686
                 GFileMonitorEvent event_type,
 
687
                 NautilusDiscBurn     *burn)
 
688
{
 
689
        DEBUG_PRINT ("Monitor callback type %d\n", event_type);
 
690
 
 
691
        /* only queue the action if it has a chance of changing the state */
 
692
        if (event_type == G_FILE_MONITOR_EVENT_CREATED) {
 
693
                if (burn->priv->empty) {
 
694
                        queue_update_empty (burn);
 
695
                }
 
696
        } else if (event_type == G_FILE_MONITOR_EVENT_DELETED) {
 
697
                if (! burn->priv->empty) {
 
698
                        queue_update_empty (burn);
 
699
                }
 
700
        }
 
701
}
 
702
 
 
703
static gboolean
 
704
start_monitor (NautilusDiscBurn *burn)
 
705
{
 
706
        GFile  *file;
 
707
        GError *error;
 
708
 
 
709
        file = g_file_new_for_uri (BURN_URI);
 
710
 
 
711
        error = NULL;
 
712
        burn->priv->burn_monitor = g_file_monitor_directory (file,
 
713
                                                             G_FILE_MONITOR_NONE,
 
714
                                                             NULL,
 
715
                                                             &error);
 
716
        if (burn->priv->burn_monitor == NULL) {
 
717
                g_warning ("Unable to add monitor: %s", error->message);
 
718
                g_error_free (error);
 
719
                goto out;
 
720
        }
 
721
 
 
722
        DEBUG_PRINT ("Starting monitor for %s\n", BURN_URI);
 
723
        g_signal_connect (burn->priv->burn_monitor,
 
724
                          "changed",
 
725
                          G_CALLBACK (burn_monitor_cb),
 
726
                          burn);
 
727
 
 
728
        burn->priv->empty = dir_is_empty (BURN_URI);
 
729
 
 
730
        DEBUG_PRINT ("Init burn extension, empty: %d\n", burn->priv->empty);
 
731
 
 
732
 out:
 
733
        g_object_unref (file);
 
734
 
 
735
        burn->priv->start_monitor_id = 0;
 
736
 
 
737
        return FALSE;
 
738
}
 
739
 
 
740
static void
 
741
nautilus_disc_burn_instance_init (NautilusDiscBurn *burn)
 
742
{
 
743
        burn->priv = NAUTILUS_DISC_BURN_GET_PRIVATE (burn);
 
744
        burn->priv->start_monitor_id = g_timeout_add_seconds (1,
 
745
                                                              (GSourceFunc)start_monitor,
 
746
                                                              burn);
 
747
}
 
748
 
 
749
static void
 
750
nautilus_disc_burn_finalize (GObject *object)
 
751
{
 
752
        NautilusDiscBurn *burn;
 
753
 
 
754
        g_return_if_fail (object != NULL);
 
755
        g_return_if_fail (NAUTILUS_IS_DISC_BURN (object));
 
756
 
 
757
        DEBUG_PRINT ("Finalizing burn extension\n");
 
758
 
 
759
        burn = NAUTILUS_DISC_BURN (object);
 
760
 
 
761
        g_return_if_fail (burn->priv != NULL);
 
762
 
 
763
        if (burn->priv->empty_update_id > 0) {
 
764
                g_source_remove (burn->priv->empty_update_id);
 
765
        }
 
766
 
 
767
        if (burn->priv->start_monitor_id > 0) {
 
768
                g_source_remove (burn->priv->start_monitor_id);
 
769
        }
 
770
 
 
771
        if (burn->priv->burn_monitor != NULL) {
 
772
                g_file_monitor_cancel (burn->priv->burn_monitor);
 
773
        }
 
774
 
 
775
        if (burn->priv->widget_list != NULL) {
 
776
                g_slist_free (burn->priv->widget_list);
 
777
        }
 
778
 
 
779
        G_OBJECT_CLASS (parent_class)->finalize (object);
 
780
}
 
781
 
 
782
static void
 
783
nautilus_disc_burn_class_init (NautilusDiscBurnClass *klass)
 
784
{
 
785
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
786
 
 
787
        parent_class = g_type_class_peek_parent (klass);
 
788
 
 
789
        object_class->finalize = nautilus_disc_burn_finalize;
 
790
 
 
791
        g_type_class_add_private (klass, sizeof (NautilusDiscBurnPrivate));
 
792
}
 
793
 
 
794
static GType burn_type = 0;
 
795
 
 
796
static GType
 
797
nautilus_disc_burn_get_type (void)
 
798
{
 
799
        return burn_type;
 
800
}
 
801
 
 
802
static void
 
803
nautilus_disc_burn_register_type (GTypeModule *module)
 
804
{
 
805
        static const GTypeInfo info = {
 
806
                sizeof (NautilusDiscBurnClass),
 
807
                (GBaseInitFunc) NULL,
 
808
                (GBaseFinalizeFunc) NULL,
 
809
                (GClassInitFunc) nautilus_disc_burn_class_init,
 
810
                NULL,
 
811
                NULL,
 
812
                sizeof (NautilusDiscBurn),
 
813
                0,
 
814
                (GInstanceInitFunc) nautilus_disc_burn_instance_init,
 
815
        };
 
816
 
 
817
        static const GInterfaceInfo menu_provider_iface_info = {
 
818
                (GInterfaceInitFunc) nautilus_disc_burn_menu_provider_iface_init,
 
819
                NULL,
 
820
                NULL
 
821
        };
 
822
        static const GInterfaceInfo location_widget_provider_iface_info = {
 
823
                (GInterfaceInitFunc) nautilus_disc_burn_location_widget_provider_iface_init,
 
824
                NULL,
 
825
                NULL
 
826
        };
 
827
 
 
828
        burn_type = g_type_module_register_type (module,
 
829
                                                 G_TYPE_OBJECT,
 
830
                                                 "NautilusDiscBurn",
 
831
                                                 &info, 0);
 
832
 
 
833
        g_type_module_add_interface (module,
 
834
                                     burn_type,
 
835
                                     NAUTILUS_TYPE_MENU_PROVIDER,
 
836
                                     &menu_provider_iface_info);
 
837
        g_type_module_add_interface (module,
 
838
                                     burn_type,
 
839
                                     NAUTILUS_TYPE_LOCATION_WIDGET_PROVIDER,
 
840
                                     &location_widget_provider_iface_info);
 
841
}
 
842
 
 
843
void
 
844
nautilus_module_initialize (GTypeModule *module)
 
845
{
 
846
        DEBUG_PRINT ("Initializing nautilus disc recorder\n");
 
847
 
 
848
        brasero_media_library_start ();
 
849
        DEBUG_PRINT ("Libbrasero-media started\n");
 
850
 
 
851
        nautilus_disc_burn_register_type (module);
 
852
}
 
853
 
 
854
void
 
855
nautilus_module_shutdown (void)
 
856
{
 
857
        DEBUG_PRINT ("Shutting down nautilus disc recorder\n");
 
858
 
 
859
        /* Don't do that in case another module would need the library */
 
860
        //brasero_media_library_stop ();
 
861
}
 
862
 
 
863
void
 
864
nautilus_module_list_types (const GType **types,
 
865
                            int          *num_types)
 
866
{
 
867
        static GType type_list [1];
 
868
 
 
869
        type_list [0] = NAUTILUS_TYPE_DISC_BURN;
 
870
 
 
871
        *types = type_list;
 
872
        *num_types = 1;
 
873
}