Removing playlists

Playlist deletion is achieved through the MafwPlaylistManager object in a similar way as the creation of new playlists:

MafwPlaylistManager *manager;
MafwProxyPlaylist *playlist;
GError *error = NULL;

manager = mafw_playlist_manager_get ();
playlist = mafw_playlist_manager_get_playlist(manager, id,
					      &error);
if (error != NULL) {
  /* Playlist does not exist, error management */
}

mafw_playlist_manager_destroy_playlist(manager, playlist,
				       &error);
if (error != NULL) {
  /* Playlist could not be deleted, error management */
}

The first step is to obtain a reference to the playlist that has to be removed. After a reference has been obtained, mafw_playlist_manager_destroy_playlist is ready to remove it.

If playlist removal was not possible, the playlist manager can also emit the signal playlist-destruction-failed. In general, this happens when trying to remove playlists that are being used somewhere else in the application or when they are being used by some other application.

When an application wants to mark a playlist as being in use, it should call mafw_playlist_increment_use_count. When an application tries to remove a playlist which reference count is greater than zero, the operation will fail. Renderers should always increment the reference count of a playlist when it is assigned and decrement when it is unassigned.

As in the case of playlist creation, it is also a good idea to install a signal handler for "playlist-destroyed" so the application can deal with this situation properly. For example, another MAFW based application may attempt to destroy a playlist that your application is showing as available to the user in a playlist selection widget. Here is a code example that shows how to connect to this signal:

{
	g_signal_connect(manager, "playlist-destroyed",
			 G_CALLBACK(on_mafw_playlist_destroyed), NULL);
}

static void
on_mafw_playlist_destroyed (MafwPlaylistManager* manager,
			    MafwProxyPlaylist *playlist, gpointer user_data)
{
        /* Handle playlist removal */
}