core/playlists/user: Add support for renaming playlists
Users may make typos in naming playlists, or they might think up better names for playlists later. Let's be friendly and give users a way to change playlist names if desired. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
042cddb65b
commit
e773ae6f82
|
@ -156,3 +156,22 @@ void pl_user_delete_track(struct track *track)
|
||||||
playlist_generic_remove(playlist, track);
|
playlist_generic_remove(playlist, track);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool pl_user_rename(struct playlist *playlist, const gchar *name)
|
||||||
|
{
|
||||||
|
struct db_entry *dbe;
|
||||||
|
|
||||||
|
if (!playlist || db_get(&user_db, name))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
dbe = db_get(&user_db, playlist->pl_name);
|
||||||
|
if (!dbe)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
g_free(playlist->pl_name);
|
||||||
|
playlist->pl_name = g_strdup(name);
|
||||||
|
db_rekey(&user_db, dbe);
|
||||||
|
|
||||||
|
pl_user_save();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
|
@ -26,5 +26,8 @@ void pl_user_deinit();
|
||||||
/* Called to tell user playlists that a track is getting deleted. */
|
/* Called to tell user playlists that a track is getting deleted. */
|
||||||
void pl_user_delete_track(struct track *);
|
void pl_user_delete_track(struct track *);
|
||||||
|
|
||||||
|
/* Called to rename a user playlist. */
|
||||||
|
bool pl_user_rename(struct playlist *, const gchar *);
|
||||||
|
|
||||||
struct database *pl_user_db_get();
|
struct database *pl_user_db_get();
|
||||||
#endif /* OCARINA_CORE_PLAYLISTS_USER_H */
|
#endif /* OCARINA_CORE_PLAYLISTS_USER_H */
|
||||||
|
|
|
@ -62,6 +62,14 @@ void test_user()
|
||||||
playlist = playlist_lookup(PL_USER, "Test Playlist");
|
playlist = playlist_lookup(PL_USER, "Test Playlist");
|
||||||
g_assert_nonnull(playlist);
|
g_assert_nonnull(playlist);
|
||||||
|
|
||||||
|
g_assert_false(pl_user_rename(NULL, "Null Playlist"));
|
||||||
|
g_assert_true( pl_user_rename(playlist, "New Playlist Name"));
|
||||||
|
g_assert_null(playlist_lookup(PL_USER, "Test Playlist"));
|
||||||
|
g_assert_cmpstr(playlist->pl_name, ==, "New Playlist Name");
|
||||||
|
|
||||||
|
g_assert_nonnull(playlist_new(PL_USER, "Test Playlist"));
|
||||||
|
g_assert_false(pl_user_rename(playlist, "Test Playlist"));
|
||||||
|
|
||||||
g_assert_cmpuint(playlist_size(playlist), ==, 1);
|
g_assert_cmpuint(playlist_size(playlist), ==, 1);
|
||||||
g_assert_true( playlist_has( playlist, track_get(0)));
|
g_assert_true( playlist_has( playlist, track_get(0)));
|
||||||
g_assert_true( playlist_remove(playlist, track_get(0)));
|
g_assert_true( playlist_remove(playlist, track_get(0)));
|
||||||
|
@ -69,6 +77,8 @@ void test_user()
|
||||||
g_assert_false(playlist_has( playlist, track_get(0)));
|
g_assert_false(playlist_has( playlist, track_get(0)));
|
||||||
g_assert_cmpuint(playlist_size(playlist), ==, 0);
|
g_assert_cmpuint(playlist_size(playlist), ==, 0);
|
||||||
|
|
||||||
|
g_assert_true(playlist_delete(playlist));
|
||||||
|
playlist = playlist_lookup(PL_USER, "Test Playlist");
|
||||||
g_assert_true(playlist_delete(playlist));
|
g_assert_true(playlist_delete(playlist));
|
||||||
g_assert_cmpuint(db->db_size, ==, 0);
|
g_assert_cmpuint(db->db_size, ==, 0);
|
||||||
g_assert_cmpuint(db_actual_size(db), ==, 0);
|
g_assert_cmpuint(db_actual_size(db), ==, 0);
|
||||||
|
|
Loading…
Reference in New Issue