~ubuntu-branches/ubuntu/wily/totem-pl-parser/wily

« back to all changes in this revision

Viewing changes to plparse/totem-disc.c

  • Committer: Package Import Robot
  • Author(s): Michael Biebl
  • Date: 2012-03-09 13:39:14 UTC
  • mfrom: (1.4.16) (1.5.12 sid)
  • Revision ID: package-import@ubuntu.com-20120309133914-e6iab9fcyg8cmw33
Tags: 3.2.0-1
* New upstream release.
* debian/patches/01-libquvi-0.4.patch: Removed, merged upstream.
* debian/control.in: Bump (Build-)Depends on libglib2.0-dev to (>= 2.31.0).

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
#include <glib/gi18n.h>
59
59
#include <gio/gio.h>
60
60
 
 
61
#ifdef HAVE_LIBARCHIVE
 
62
#include <archive.h>
 
63
#include <archive_entry.h>
 
64
#endif /* HAVE_ARCHIVE */
 
65
 
61
66
#include "totem-disc.h"
62
67
#include "totem-pl-parser.h"
63
68
 
96
101
static char *
97
102
totem_resolve_symlink (const char *device, GError **error)
98
103
{
99
 
  char *dir, *link;
 
104
  char *dir, *_link;
100
105
  char *f;
101
106
  char *f1;
102
107
 
103
108
  f = g_strdup (device);
104
109
  while (g_file_test (f, G_FILE_TEST_IS_SYMLINK)) {
105
 
    link = g_file_read_link (f, error);
106
 
    if(link == NULL) {
 
110
    _link = g_file_read_link (f, error);
 
111
    if (_link == NULL) {
107
112
      g_free (f);
108
113
      return NULL;
109
114
    }
110
115
 
111
116
    dir = g_path_get_dirname (f);
112
 
    f1 = g_build_filename (dir, link, NULL);
 
117
    f1 = g_build_filename (dir, _link, NULL);
113
118
    g_free (dir);
114
119
    g_free (f);
115
120
    f = f1;
261
266
  return FALSE;
262
267
}
263
268
 
264
 
static char *
265
 
cd_cache_uri_to_archive (const char *uri)
266
 
{
267
 
  char *escaped, *escaped2, *retval;
268
 
 
269
 
  escaped = g_uri_escape_string (uri, NULL, FALSE);
270
 
  escaped2 = g_uri_escape_string (escaped, NULL, FALSE);
271
 
  g_free (escaped);
272
 
  retval = g_strdup_printf ("archive://%s/", escaped2);
273
 
  g_free (escaped2);
274
 
 
275
 
  return retval;
276
 
}
277
 
 
278
 
static void
279
 
cd_cache_mount_archive_callback (GObject *source_object,
280
 
                                 GAsyncResult *res,
281
 
                                 CdCacheCallbackData *data)
282
 
{
283
 
  data->result = g_file_mount_enclosing_volume_finish (G_FILE (source_object), res, &data->error);
284
 
  data->called = TRUE;
 
269
static gboolean
 
270
cd_cache_check_archive (CdCache *cache,
 
271
                        const char *filename,
 
272
                        GError **error)
 
273
{
 
274
#ifndef HAVE_LIBARCHIVE
 
275
  g_set_error (error, TOTEM_PL_PARSER_ERROR, TOTEM_PL_PARSER_ERROR_MOUNT_FAILED,
 
276
               _("Failed to mount %s."), filename);
 
277
  return FALSE;
 
278
#else
 
279
  struct archive *a;
 
280
  struct archive_entry *entry;
 
281
  const char * content_types[] = { NULL, NULL };
 
282
  int r;
 
283
 
 
284
  a = archive_read_new();
 
285
  archive_read_support_compression_all(a);
 
286
  archive_read_support_format_all(a);
 
287
  r = archive_read_open_filename(a, filename, 10240);
 
288
  if (r != ARCHIVE_OK) {
 
289
    g_set_error (error, TOTEM_PL_PARSER_ERROR, TOTEM_PL_PARSER_ERROR_MOUNT_FAILED,
 
290
                 _("Failed to mount %s."), filename);
 
291
    return FALSE;
 
292
  }
 
293
  while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
 
294
    const char *name;
 
295
 
 
296
    name = archive_entry_pathname (entry);
 
297
    if (g_ascii_strcasecmp (name, "VIDEO_TS/VIDEO_TS.IFO") == 0) {
 
298
      content_types[0] = "x-content/video-dvd";
 
299
      cache->content_types = g_strdupv ((gchar**) content_types);
 
300
      break;
 
301
    } else if (g_ascii_strcasecmp (name, "mpegav/AVSEQ01.DAT") == 0) {
 
302
      content_types[0] = "x-content/video-vcd";
 
303
      cache->content_types = g_strdupv ((gchar**) content_types);
 
304
      break;
 
305
    } else if (g_ascii_strcasecmp (name, "MPEG2/AVSEQ01.MPG") == 0) {
 
306
      content_types[0] = "x-content/video-svcd";
 
307
      cache->content_types = g_strdupv ((gchar**) content_types);
 
308
      break;
 
309
    }
 
310
    archive_read_data_skip(a);
 
311
  }
 
312
  r = archive_read_finish(a);
 
313
  if (r != ARCHIVE_OK) {
 
314
    g_set_error (error, TOTEM_PL_PARSER_ERROR, TOTEM_PL_PARSER_ERROR_MOUNT_FAILED,
 
315
                 _("Failed to mount %s."), filename);
 
316
    return FALSE;
 
317
  }
 
318
  return TRUE;
 
319
#endif
285
320
}
286
321
 
287
322
static CdCache *
320
355
 
321
356
    return cache;
322
357
  } else if (g_file_test (local, G_FILE_TEST_IS_REGULAR)) {
323
 
    GMount *mount;
324
 
    GError *err = NULL;
325
 
    char *uri, *archive_path;
326
 
 
327
358
    cache = g_new0 (CdCache, 1);
328
359
    cache->is_iso = TRUE;
329
360
    cache->is_media = FALSE;
330
361
 
331
 
    uri = g_file_get_uri (file);
332
362
    g_object_unref (file);
333
 
    archive_path = cd_cache_uri_to_archive (uri);
334
 
    g_free (uri);
 
363
 
 
364
    if (cd_cache_check_archive (cache, local, error) == FALSE) {
 
365
      cd_cache_free (cache);
 
366
      return FALSE;
 
367
    }
 
368
 
335
369
    cache->device = local;
336
 
 
337
 
    cache->iso_file = g_file_new_for_uri (archive_path);
338
 
    g_free (archive_path);
339
 
 
340
 
    mount = g_file_find_enclosing_mount (cache->iso_file, NULL, &err);
341
 
    if (mount == NULL && g_error_matches (err, G_IO_ERROR, G_IO_ERROR_NOT_MOUNTED)) {
342
 
      CdCacheCallbackData data;
343
 
 
344
 
      memset (&data, 0, sizeof(data));
345
 
      data.cache = cache;
346
 
      g_file_mount_enclosing_volume (cache->iso_file,
347
 
                                     G_MOUNT_MOUNT_NONE,
348
 
                                     NULL,
349
 
                                     NULL,
350
 
                                     (GAsyncReadyCallback) cd_cache_mount_archive_callback,
351
 
                                     &data);
352
 
      while (!data.called) g_main_context_iteration (NULL, TRUE);
353
 
 
354
 
      if (!data.result) {
355
 
        if (data.error) {
356
 
          g_propagate_error (error, data.error);
357
 
        } else {
358
 
          g_set_error (error, TOTEM_PL_PARSER_ERROR, TOTEM_PL_PARSER_ERROR_MOUNT_FAILED,
359
 
                       _("Failed to mount %s."), cache->device);
360
 
        }
361
 
        cd_cache_free (cache);
362
 
        return FALSE;
363
 
      }
364
 
      self_mounted = TRUE;
365
 
    } else if (mount == NULL) {
366
 
      cd_cache_free (cache);
367
 
      return FALSE;
368
 
    } else {
369
 
      g_object_unref (mount);
370
 
    }
371
 
 
372
 
    cache->content_types = g_content_type_guess_for_tree (cache->iso_file);
373
 
    cache->mountpoint = g_file_get_path (cache->iso_file);
374
 
    cache->self_mounted = self_mounted;
375
 
    cache->mounted = TRUE;
 
370
    cache->self_mounted = FALSE;
 
371
    cache->mounted = FALSE;
376
372
 
377
373
    return cache;
378
374
  }
468
464
  GFile *root;
469
465
 
470
466
  /* already opened? */
471
 
  if (cache->mounted || cache->is_media == FALSE)
 
467
  if (cache->mounted || cache->is_media == FALSE || cache->is_iso)
472
468
    return TRUE;
473
469
 
474
470
  /* check for mounting - assume we'll mount ourselves */
569
565
                       GError **error)
570
566
{
571
567
  /* We can't have audio CDs on disc, yet */
572
 
  if (cache->is_media == FALSE) {
 
568
  if (cache->is_media == FALSE)
573
569
    return MEDIA_TYPE_DATA;
574
 
  }
575
570
  if (!cd_cache_open_device (cache, error))
576
571
    return MEDIA_TYPE_ERROR;
577
 
 
578
572
  if (cd_cache_has_content_type (cache, "x-content/audio-cdda") != FALSE)
579
573
    return MEDIA_TYPE_CDDA;
580
574
 
590
584
    return MEDIA_TYPE_ERROR;
591
585
  if (!cd_cache_open_mountpoint (cache, error))
592
586
    return MEDIA_TYPE_ERROR;
593
 
  if (!cache->mountpoint)
594
 
    return MEDIA_TYPE_ERROR;
595
587
 
596
588
  if (cd_cache_has_content_type (cache, "x-content/video-vcd") != FALSE)
597
589
    return MEDIA_TYPE_VCD;
610
602
    return MEDIA_TYPE_ERROR;
611
603
  if (!cd_cache_open_mountpoint (cache, error))
612
604
    return MEDIA_TYPE_ERROR;
613
 
  if (!cache->mountpoint)
614
 
    return MEDIA_TYPE_ERROR;
615
605
 
616
606
  if (cd_cache_has_content_type (cache, "x-content/video-dvd") != FALSE)
617
607
    return MEDIA_TYPE_DVD;
821
811
        *mrl = g_strdup (cache->mountpoint);
822
812
    }
823
813
    break;
 
814
  case MEDIA_TYPE_ERROR:
 
815
  case MEDIA_TYPE_DVB:
824
816
  default:
825
817
    break;
826
818
  }
893
885
    return N_("DVD");
894
886
  case MEDIA_TYPE_DVB:
895
887
    return N_("Digital Television");
 
888
  case MEDIA_TYPE_ERROR:
 
889
  case MEDIA_TYPE_DATA:
896
890
  default:
897
891
    g_assert_not_reached ();
898
892
  }