~ubuntu-branches/ubuntu/oneiric/rhythmbox/oneiric

« back to all changes in this revision

Viewing changes to sources/rb-removable-media-source.c

  • Committer: Bazaar Package Importer
  • Author(s): Rico Tzschichholz
  • Date: 2011-07-29 16:41:38 UTC
  • mto: This revision was merged to the branch mainline in revision 191.
  • Revision ID: james.westby@ubuntu.com-20110729164138-wwicy8nqalm18ck7
Tags: upstream-2.90.1~20110802
ImportĀ upstreamĀ versionĀ 2.90.1~20110802

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
#include <glib/gi18n.h>
45
45
#include <gtk/gtk.h>
 
46
#include <gst/pbutils/encoding-target.h>
46
47
 
47
48
#include "rhythmdb.h"
48
 
#include "eel-gconf-extensions.h"
49
49
#include "rb-removable-media-source.h"
50
50
#include "rb-removable-media-manager.h"
51
51
#include "rb-encoder.h"
57
57
#include "rb-track-transfer-batch.h"
58
58
#include "rb-track-transfer-queue.h"
59
59
 
60
 
#if !GLIB_CHECK_VERSION(2,22,0)
61
 
#define g_mount_unmount_with_operation_finish g_mount_unmount_finish
62
 
#define g_mount_unmount_with_operation(m,f,mo,ca,cb,ud) g_mount_unmount(m,f,ca,cb,ud)
63
 
 
64
 
#define g_mount_eject_with_operation_finish g_mount_eject_finish
65
 
#define g_mount_eject_with_operation(m,f,mo,ca,cb,ud) g_mount_eject(m,f,ca,cb,ud)
66
 
 
67
 
#define g_volume_eject_with_operation_finish g_volume_eject_finish
68
 
#define g_volume_eject_with_operation(v,f,mo,ca,cb,ud) g_volume_eject(v,f,ca,cb,ud)
69
 
#endif
70
 
 
71
 
 
72
60
/* arbitrary length limit for file extensions */
73
61
#define EXTENSION_LENGTH_LIMIT  8
74
62
 
99
87
{
100
88
        GVolume *volume;
101
89
        GMount *mount;
 
90
        GstEncodingTarget *encoding_target;
102
91
} RBRemovableMediaSourcePrivate;
103
92
 
104
93
G_DEFINE_TYPE (RBRemovableMediaSource, rb_removable_media_source, RB_TYPE_BROWSER_SOURCE)
109
98
        PROP_0,
110
99
        PROP_VOLUME,
111
100
        PROP_MOUNT,
 
101
        PROP_ENCODING_TARGET
112
102
};
113
103
 
114
104
static void
138
128
        source_class->impl_uri_is_source = impl_uri_is_source;
139
129
        source_class->impl_get_delete_action = impl_get_delete_action;
140
130
 
141
 
        browser_source_class->impl_get_paned_key = NULL;
142
131
        browser_source_class->impl_has_drop_support = (RBBrowserSourceFeatureFunc) rb_false_function;
143
132
 
144
133
        klass->impl_should_paste = impl_should_paste;
169
158
                                                              "GIO Mount",
170
159
                                                              G_TYPE_MOUNT,
171
160
                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 
161
        /**
 
162
         * RBRemovableMediaSource:encoding-target
 
163
         *
 
164
         * The #GstEncodingTarget for this device
 
165
         */
 
166
        g_object_class_install_property (object_class,
 
167
                                         PROP_ENCODING_TARGET,
 
168
                                         gst_param_spec_mini_object ("encoding-target",
 
169
                                                                     "encoding target",
 
170
                                                                     "GstEncodingTarget",
 
171
                                                                     GST_TYPE_ENCODING_TARGET,
 
172
                                                                     G_PARAM_READWRITE));
172
173
 
173
174
        g_type_class_add_private (klass, sizeof (RBRemovableMediaSourcePrivate));
174
175
}
294
295
                        g_object_ref (priv->mount);
295
296
                }
296
297
                break;
 
298
        case PROP_ENCODING_TARGET:
 
299
                if (priv->encoding_target) {
 
300
                        g_object_unref (priv->encoding_target);
 
301
                }
 
302
                priv->encoding_target = GST_ENCODING_TARGET (gst_value_dup_mini_object (value));
 
303
                break;
297
304
        default:
298
305
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
299
306
                break;
315
322
        case PROP_MOUNT:
316
323
                g_value_set_object (value, priv->mount);
317
324
                break;
 
325
        case PROP_ENCODING_TARGET:
 
326
                g_value_set_object (value, priv->encoding_target);
 
327
                break;
318
328
        default:
319
329
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
320
330
                break;
389
399
impl_paste (RBSource *bsource, GList *entries)
390
400
{
391
401
        RBRemovableMediaSource *source = RB_REMOVABLE_MEDIA_SOURCE (bsource);
 
402
        RBRemovableMediaSourcePrivate *priv = REMOVABLE_MEDIA_SOURCE_GET_PRIVATE (bsource);
392
403
        RBTrackTransferQueue *xferq;
393
404
        RBShell *shell;
394
 
        GList *mime_types;
395
405
        GList *l;
396
406
        RhythmDBEntryType *our_entry_type;
397
407
        RBTrackTransferBatch *batch;
404
414
        g_object_get (shell, "track-transfer-queue", &xferq, NULL);
405
415
        g_object_unref (shell);
406
416
 
407
 
        mime_types = rb_removable_media_source_get_mime_types (source);
408
 
        batch = rb_track_transfer_batch_new (mime_types, NULL, NULL, G_OBJECT (source));
409
 
        rb_list_deep_free (mime_types);
 
417
        batch = rb_track_transfer_batch_new (priv->encoding_target, NULL, G_OBJECT (source));
410
418
 
411
419
        g_signal_connect_object (batch, "get-dest-uri", G_CALLBACK (get_dest_uri_cb), source, 0);
412
420
        g_signal_connect_object (batch, "track-done", G_CALLBACK (track_done_cb), source, 0);
609
617
 * rb_removable_media_source_build_dest_uri:
610
618
 * @source: an #RBRemovableMediaSource
611
619
 * @entry: the #RhythmDBEntry to build a URI for
612
 
 * @mimetype: destination media type
 
620
 * @media_type: destination media type
613
621
 * @extension: extension associated with destination media type
614
622
 *
615
623
 * Constructs a URI to use as the destination for a transfer or transcoding
626
634
char *
627
635
rb_removable_media_source_build_dest_uri (RBRemovableMediaSource *source,
628
636
                                          RhythmDBEntry *entry,
629
 
                                          const char *mimetype,
 
637
                                          const char *media_type,
630
638
                                          const char *extension)
631
639
{
632
640
        RBRemovableMediaSourceClass *klass = RB_REMOVABLE_MEDIA_SOURCE_GET_CLASS (source);
634
642
        char *sane_uri = NULL;
635
643
 
636
644
        if (klass->impl_build_dest_uri) {
637
 
                uri = klass->impl_build_dest_uri (source, entry, mimetype, extension);
 
645
                uri = klass->impl_build_dest_uri (source, entry, media_type, extension);
638
646
        } else {
639
647
                uri = NULL;
640
648
        }
644
652
        g_free(uri);
645
653
        uri = sane_uri;
646
654
 
647
 
        rb_debug ("Built dest URI for mime='%s', extension='%s': '%s'",
648
 
                  mimetype,
 
655
        rb_debug ("Built dest URI for media type='%s', extension='%s': '%s'",
 
656
                  media_type,
649
657
                  extension,
650
658
                  uri);
651
659
 
653
661
}
654
662
 
655
663
/**
656
 
 * rb_removable_media_source_get_mime_types:
657
 
 * @source: an #RBRemovableMediaSource
658
 
 *
659
 
 * Returns a #GList of allocated media type strings describing the
660
 
 * formats supported by the device.  If possible, these should be
661
 
 * sorted in order of preference, as the first entry in the list
662
 
 * for which an encoder is available will be used.
663
 
 *
664
 
 * Common media types include "audio/mpeg" for MP3, "application/ogg"
665
 
 * for Ogg Vorbis, "audio/x-flac" for FLAC, and "audio/x-aac" for
666
 
 * MP4/AAC.
667
 
 *
668
 
 * Return value: (element-type utf8) (transfer full): list of media types
669
 
 */
670
 
GList *
671
 
rb_removable_media_source_get_mime_types (RBRemovableMediaSource *source)
672
 
{
673
 
        RBRemovableMediaSourceClass *klass = RB_REMOVABLE_MEDIA_SOURCE_GET_CLASS (source);
674
 
 
675
 
        if (klass->impl_get_mime_types)
676
 
                return klass->impl_get_mime_types (source);
677
 
        else
678
 
                return NULL;
679
 
}
680
 
 
681
 
/**
682
664
 * rb_removable_media_source_get_format_descriptions:
683
665
 * @source: a #RBRemovableMediaSource
684
666
 *
691
673
GList *
692
674
rb_removable_media_source_get_format_descriptions (RBRemovableMediaSource *source)
693
675
{
694
 
        GList *mime;
 
676
        GstEncodingTarget *target;
 
677
        const GList *l;
695
678
        GList *desc = NULL;
696
 
        GList *t;
697
 
 
698
 
        mime = rb_removable_media_source_get_mime_types (source);
699
 
        for (t = mime; t != NULL; t = t->next) {
700
 
                const char *mimetype;
701
 
                char *content_type;
702
 
 
703
 
                mimetype = t->data;
704
 
                content_type = g_content_type_from_mime_type (mimetype);
705
 
                if (content_type != NULL) {
706
 
                        char *description;
707
 
                        description = g_content_type_get_description (content_type);
708
 
                        desc = g_list_append (desc, description);
709
 
                } else {
710
 
                        desc = g_list_append (desc, g_strdup (mimetype));
711
 
                }
 
679
        g_object_get (source, "encoding-target", &target, NULL);
 
680
        for (l = gst_encoding_target_get_profiles (target); l != NULL; l = l->next) {
 
681
                GstEncodingProfile *profile = l->data;
 
682
                desc = g_list_append (desc, g_strdup (gst_encoding_profile_get_description (profile)));
712
683
        }
713
 
 
714
 
        rb_list_deep_free (mime);
 
684
        g_object_unref (target);
715
685
        return desc;
716
686
}
717
687
 
817
787
 * @entry: the source #RhythmDBEntry for the transfer
818
788
 * @uri: the destination URI
819
789
 * @filesize: size of the destination file
820
 
 * @mimetype: media type of the destination file
 
790
 * @media_type: media type of the destination file
821
791
 *
822
792
 * This is called when a transfer to the device has completed.
823
793
 * If the source's impl_track_added method returns %TRUE, the destination
832
802
                                       RhythmDBEntry *entry,
833
803
                                       const char *uri,
834
804
                                       guint64 filesize,
835
 
                                       const char *mimetype)
 
805
                                       const char *media_type)
836
806
{
837
807
        RBRemovableMediaSourceClass *klass = RB_REMOVABLE_MEDIA_SOURCE_GET_CLASS (source);
838
808
        gboolean add_to_db = TRUE;
839
809
 
840
810
        if (klass->impl_track_added)
841
 
                add_to_db = klass->impl_track_added (source, entry, uri, filesize, mimetype);
 
811
                add_to_db = klass->impl_track_added (source, entry, uri, filesize, media_type);
842
812
 
843
813
        if (add_to_db) {
844
814
                RhythmDBEntryType *entry_type;
1050
1020
 * impl_build_dest_uri:
1051
1021
 * @source: the source
1052
1022
 * @entry: entry to build URI for
1053
 
 * @mimetype: destination media type
 
1023
 * @media_type: destination media type
1054
1024
 * @extension: extension for destination media type
1055
1025
 *
1056
1026
 * Return value: (transfer full): destination URI for the entry
1057
1027
 */
1058
 
 
1059
 
/**
1060
 
 * impl_get_mime_types:
1061
 
 * @source: the source
1062
 
 *
1063
 
 * Return value: (element-type utf8) (transfer full): list of media types
1064
 
 */