Ejemplo n.º 1
0
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));
}
Ejemplo n.º 2
0
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));
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
 Status DB::getSongs(ResultSet<Song>& rs)     { return getSongs(rs, ReadOptions()); }