static gboolean start_next (RBTrackTransferBatch *batch) { GstEncodingProfile *profile = NULL; if (batch->priv->cancelled == TRUE) { return FALSE; } if (batch->priv->entries == NULL) { /* guess we must be done.. */ g_signal_emit (batch, signals[COMPLETE], 0); g_object_notify (G_OBJECT (batch), "task-outcome"); return FALSE; } batch->priv->current_fraction = 0.0; rb_debug ("%d entries remain in the batch", g_list_length (batch->priv->entries)); while ((batch->priv->entries != NULL) && (batch->priv->cancelled == FALSE)) { RhythmDBEntry *entry; guint64 filesize; gulong duration; double fraction; GList *n; char *media_type; char *extension; n = batch->priv->entries; batch->priv->entries = g_list_remove_link (batch->priv->entries, n); entry = (RhythmDBEntry *)n->data; g_list_free_1 (n); rb_debug ("attempting to transfer %s", rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION)); /* calculate the fraction of the transfer that this entry represents */ filesize = rhythmdb_entry_get_uint64 (entry, RHYTHMDB_PROP_FILE_SIZE); duration = rhythmdb_entry_get_ulong (entry, RHYTHMDB_PROP_DURATION); if (batch->priv->total_duration > 0) { g_assert (duration > 0); /* otherwise total_duration would be 0 */ fraction = ((double)duration) / (double) batch->priv->total_duration; } else if (batch->priv->total_size > 0) { g_assert (filesize > 0); /* otherwise total_size would be 0 */ fraction = ((double)filesize) / (double) batch->priv->total_size; } else { int count = g_list_length (batch->priv->entries) + g_list_length (batch->priv->done_entries) + 1; fraction = 1.0 / ((double)count); } profile = NULL; if (select_profile_for_entry (batch, entry, &profile, FALSE) == FALSE) { rb_debug ("skipping entry %s, can't find an encoding profile", rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION)); rhythmdb_entry_unref (entry); batch->priv->total_fraction += fraction; continue; } if (profile != NULL) { media_type = rb_gst_encoding_profile_get_media_type (profile); extension = g_strdup (rb_gst_media_type_to_extension (media_type)); rb_gst_encoding_profile_set_preset (profile, NULL); if (batch->priv->settings != NULL) { GVariant *preset_settings; char *active_preset; preset_settings = g_settings_get_value (batch->priv->settings, "media-type-presets"); active_preset = NULL; g_variant_lookup (preset_settings, media_type, "s", &active_preset); rb_debug ("setting preset %s for media type %s", active_preset, media_type); rb_gst_encoding_profile_set_preset (profile, active_preset); g_free (active_preset); } } else { media_type = rhythmdb_entry_dup_string (entry, RHYTHMDB_PROP_MEDIA_TYPE); extension = g_strdup (rb_gst_media_type_to_extension (media_type)); if (extension == NULL) { extension = get_extension_from_location (entry); } } g_free (batch->priv->current_dest_uri); batch->priv->current_dest_uri = NULL; g_signal_emit (batch, signals[GET_DEST_URI], 0, entry, media_type, extension, &batch->priv->current_dest_uri); g_free (media_type); g_free (extension); if (batch->priv->current_dest_uri == NULL) { rb_debug ("unable to build destination URI for %s, skipping", rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_LOCATION)); rhythmdb_entry_unref (entry); batch->priv->total_fraction += fraction; continue; } batch->priv->current = entry; batch->priv->current_entry_fraction = fraction; batch->priv->current_profile = profile; break; } if (batch->priv->current != NULL) { g_signal_emit (batch, signals[TRACK_STARTED], 0, batch->priv->current, batch->priv->current_dest_uri); start_encoding (batch, FALSE); g_object_notify (G_OBJECT (batch), "task-detail"); } return TRUE; }
static void pattern_label_update (void) { char *file_pattern, *path_pattern; char *file_value, *path_value, *example, *format; char *media_type; GstEncodingProfile *profile; /* Disable -Wdiscarded-quantifiers to prevent warnings as we're initalizing gchar* from const gchar*. This is safe as the strings are never changed. */ SJ_BEGIN_IGNORE_DISCARDED_QUANTIFIERS static const AlbumDetails sample_album = { .title = "Help!", /* title */ .artist = "The Beatles", /* artist */ .artist_sortname = "Beatles, The", /* artist_sortname */ .genre = NULL, /* genre */ .number = 0, /* number of tracks*/ .disc_number = 1, /* disc number */ .tracks = NULL, /* track list */ .release_date = NULL, /* release date */ .album_id = NULL, /* album ID */ .artist_id = NULL /* artist ID */ }; static const TrackDetails sample_track = { .album = (AlbumDetails*)&sample_album, /*album */ .number = 7, /* track number */ .title = "Ticket To Ride", /* title */ .artist = "The Beatles", /* artist */ .artist_sortname = "Beatles, The", /* artist_sortname */ .composer = "John Lennon and Paul McCartney", /* composer */ .composer_sortname = "Lennon, John", /* composer_sortname */ .duration = 0, /* duration */ .track_id = NULL, /* track ID */ .artist_id = NULL, /* artist ID */ }; SJ_END_IGNORE_DISCARDED_QUANTIFIERS g_object_get (sj_extractor, "profile", &profile, NULL); /* It's possible the profile isn't set, in which case do nothing */ if (!profile) { return; } media_type = rb_gst_encoding_profile_get_media_type (profile); gst_encoding_profile_unref (profile); /* TODO: sucky. Replace with get-gconf-key-with-default mojo */ file_pattern = g_settings_get_string (sj_settings, SJ_SETTINGS_FILE_PATTERN); if (file_pattern == NULL) { file_pattern = g_strdup (sj_get_default_file_pattern ()); } path_pattern = g_settings_get_string (sj_settings, SJ_SETTINGS_PATH_PATTERN); if (path_pattern == NULL) { path_pattern = g_strdup (sj_get_default_path_pattern ()); } file_value = filepath_parse_pattern (file_pattern, &sample_track); path_value = filepath_parse_pattern (path_pattern, &sample_track); example = g_build_filename (G_DIR_SEPARATOR_S, path_value, file_value, NULL); g_free (file_value); g_free (file_pattern); g_free (path_value); g_free (path_pattern); format = g_strconcat ("<small><i><b>", _("Example Path: "), "</b>", example, ".", rb_gst_media_type_to_extension (media_type), "</i></small>", NULL); g_free (example); g_free (media_type); gtk_label_set_markup (GTK_LABEL (path_example_label), format); g_free (format); } static void settings_changed_cb (GSettings *settings, const gchar *key, gpointer combo) { char *value; value = g_settings_get_string (settings, key); if (!gtk_combo_box_set_active_id (combo, value)) gtk_combo_box_set_active_id (combo, NULL); g_free (value); pattern_label_update (); } /** * Default device changed (either GSettings key or the widget) */ static void device_changed_cb (GSettings *settings, const gchar *key, gpointer user_data) { BraseroDrive *drive; BraseroMediumMonitor *monitor; char *value; g_return_if_fail (strcmp (key, SJ_SETTINGS_DEVICE) == 0); value = g_settings_get_string (settings, key); if ((value != NULL) && (*value != '\0')) { monitor = brasero_medium_monitor_get_default (); drive = brasero_medium_monitor_get_drive (monitor, value); brasero_drive_selection_set_active (BRASERO_DRIVE_SELECTION (cd_option), drive); g_object_unref (drive); g_object_unref (monitor); } else { /* FIXME: see the FIXME in sj-main.c around one of the * device_changed_cb calls for a way to fix this */ g_warn_if_reached(); } g_free (value); }