MAFW Manual |
---|
Adding elements to the playlist is done by using mafw_playlist_insert_item and specifying the index where the item should be inserted.
{ gchar *object_id = get_object_id(); mafw_playlist_insert_item(playlist, index, object_id, &error); g_free(oid); if (error != NULL) { /* Error handling */ } else { /* Elements insertion */ } }
A signal will be emitted whenever a playlist is modified. Notice that other MAFW based applications may be modifying the playlists in use by your application at any moment. By connecting to these signals, your application should be able to handle this situation properly:
{ g_signal_connect (playlist, "contents-changed", (GCallback) on_mafw_playlist_contents_changed, NULL); } static void on_mafw_playlist_contents_changed(MafwPlaylist *playlist, guint from, guint nremoved, guint nreplaced) { /* Update application accordingly */ }
This "contents-changed" signal is used to signal
changes of any kind. The from
parameter is the index of the
first element affected by the change, nremoved
is the number
of removed elements and nreplaced
represents the number of
elements replaced. For example, in case of insertion, the signal will
be emitted with the insertion index as from
, 0 as
nremoved
and 1 as nreplaced
. More information
is available in the Mafw API reference.
Also, the convenience function mafw\_playlist\_append\_item can be used to append items to the tail of a playlist.
As in the case of insertion, one only needs to call the method on the playlist proxy object with the index of the element to remove:
{ mafw_playlist_remove_item (playlist, (guint) index, &error); if (error != NULL) { /* Error handling */ } }
The signal received when modifying the playlist is the same as
when removing elements. In this case
nremoved
would be 1 and
nreplaced
would be the difference between the
number of elements in the playlist and the index of the removed
element plus the number of items that were removed (1). There
are more examples available in the Mafw API reference.
Moving one element from one index to another can be done by calling mafw_playlist_move_item :
{ mafw_playlist_move_item (playlist, 3, 1, &error); if (error != NULL) { /* Error handling */ } }
The example moves the element at position 3 to position 1, moving elements in positions 1 and 2 forward to positions 2 and 3. When invoking this method, the signal item-moved is emitted:
{ g_signal_connect (playlist, "item-moved", (GCallback) on_mafw_playlist_item_moved, NULL); } static void on_mafw_playlist_item_moved(MafwPlaylist *playlist, guint from, guint to) { /* Handle item movement */ }