void PlaylistHandler::redefinePlaylist(std::string playlistName, std::vector<Song*> songs) { checkInit(); QDomElement playlist = getPlaylistFromName(playlistName); QDomNode node = playlist.firstChild(); std::vector<QDomElement> removeVector; while (!node.isNull()) { QDomElement element = node.toElement(); if (!element.isNull() && element.tagName() == "Song") { removeVector.push_back(element); } node = node.nextSibling(); } for (unsigned int i = 0; i < removeVector.size(); i++) { playlist.removeChild(removeVector.at(i)); } for (unsigned int i = 0; i < songs.size(); i++) { Song* song = songs.at(i); QDomElement songElement = doc.createElement("Song"); songElement.setAttribute("SongName", QString::fromStdString(song->getSongName())); songElement.setAttribute("ArtistName", QString::fromStdString(song->getArtistName())); songElement.setAttribute("AlbumName", QString::fromStdString(song->getAlbumName())); songElement.setAttribute("SongId", song->getSongId()); songElement.setAttribute("ArtistId", song->getArtistId()); songElement.setAttribute("AlbumId", song->getAlbumId()); songElement.setAttribute("CoverArtFilename", QString::fromStdString(song->getCoverArtFilename())); playlist.appendChild(songElement); } save(); emit songsChanged(playlistName, getSongs(playlistName)); }
void PlaylistHandler::removeSong(Song *song, std::string playlistName) { checkInit(); QDomElement playlist = getPlaylistFromName(playlistName); QDomNode node = playlist.firstChild(); QDomNode removalNode; while (!node.isNull()) { QDomElement element = node.toElement(); if (!element.isNull() && element.tagName() == "Song" && element.attribute("SongId").toStdString() == boost::lexical_cast<std::string>(song->getSongId())) { removalNode = node; } node = node.nextSibling(); } playlist.removeChild(removalNode); save(); emit songsChanged(playlistName, getSongs(playlistName)); }
bool PlaylistHandler::addEntry(Song *song, std::string playlistName) { checkInit(); QDomElement playlist = getPlaylistFromName(playlistName); QDomNode node = playlist.firstChild(); while (!node.isNull()) { QDomElement element = node.toElement(); if (!element.isNull() && element.tagName() == "Song" && element.attribute("SongId").toStdString() == boost::lexical_cast<std::string>(song->getSongId())) return false; node = node.nextSibling(); } QDomElement songElement = doc.createElement("Song"); songElement.setAttribute("SongName", QString::fromStdString(song->getSongName())); songElement.setAttribute("ArtistName", QString::fromStdString(song->getArtistName())); songElement.setAttribute("AlbumName", QString::fromStdString(song->getAlbumName())); songElement.setAttribute("SongId", song->getSongId()); songElement.setAttribute("ArtistId", song->getArtistId()); songElement.setAttribute("AlbumId", song->getAlbumId()); songElement.setAttribute("CoverArtFilename", QString::fromStdString(song->getCoverArtFilename())); playlist.appendChild(songElement); save(); emit songsChanged(playlistName, getSongs(playlistName)); return true; }
Status DB::getSongs(ResultSet<Song>& rs) { return getSongs(rs, ReadOptions()); }