All pastes #896793 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-02-08 23:23 UTC
rendered paste body
static gboolean
mtp_playlist_from_playlist_source (GtkTreeModel *model, RBStaticPlaylistSource *playlist,
					RBMtpSource *source)
{
	LIBMTP_playlist_t *pl = LIBMTP_new_playlist_t();
	RBMtpSourcePrivate *priv = MTP_SOURCE_GET_PRIVATE (source);
	GList *ids = NULL;
	GList *tmp;

	pl->playlist_id = (uint32_t) g_object_get_data (G_OBJECT (playlist), "mtp-playlist-id");
	
	g_object_get (G_OBJECT (playlist), "name", &pl->name, NULL);

	rb_debug ("Updating playlist from source %s with id %d",pl->name, pl->playlist_id);

	gtk_tree_model_foreach (GTK_TREE_MODEL (model), 
			(GtkTreeModelForeachFunc) add_playlist_entry_to_mtp_playlist, &ids);
	if (ids == NULL) {
		return FALSE;
		rb_debug ("Null list");
	}
		
	rb_debug ("GList length %d", g_list_length(ids));
	if (g_list_length (ids) < 1) {
		rb_debug ("No tracks in list... error!");
		return FALSE;
	}
	rb_debug ("  done iterating...");
	pl->no_tracks = (uint32_t) g_list_length (ids);
	rb_debug ("space for array");
	pl->tracks = (uint32_t *) malloc (sizeof (uint32_t) * pl->no_tracks);
	rb_debug("Put tracks in array");
	int i = 0;
	for (tmp = g_list_first (ids); tmp != NULL; tmp = tmp->next) {
		//tracks[i] = (uint32_t) malloc (sizeof (uint32_t));
		pl->tracks[i] = (uint32_t) GPOINTER_TO_INT (tmp->data);
		rb_debug ("  * track %d", pl->tracks[i]);
		i++;
	}
	rb_debug ("Done making track list for playlist %d", pl->playlist_id);
	//pl->tracks = tracks;

	if (priv->device_playlists == NULL) {
		pl->next = NULL;
	} else {
		rb_debug ("Finding next playlist");
		LIBMTP_playlist_t *list;
		list = priv->device_playlists;
		rb_debug ("Global data ok");
		while (list != NULL) {
			if (list->playlist_id == pl->playlist_id) {

				rb_debug ("Found the playlist to update");
				pl->next = list->next;

				if (LIBMTP_Update_Playlist (priv->device, pl) != 0) {
					rb_debug ("Couldn't update playlist");
					LIBMTP_Dump_Errorstack(priv->device);
					LIBMTP_Clear_Errorstack(priv->device);
					return FALSE;
				} else {
					rb_debug ("Successfully updated playlist");
					
				}
				
			}
			list = list->next;
		}
	}



			
	return TRUE;
}