2018-03-29 22:02:03 +03:00
|
|
|
#include "playlist.h"
|
|
|
|
|
2018-04-02 01:03:27 +03:00
|
|
|
PlayList::PlayList()
|
2018-03-29 22:02:03 +03:00
|
|
|
{
|
|
|
|
playListInfo.clear();
|
2018-04-02 01:03:27 +03:00
|
|
|
playList = new QMediaPlaylist();
|
2018-03-29 22:02:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
QList<SongStorage>* PlayList::getInfo(){
|
|
|
|
return &playListInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMediaPlaylist* PlayList::getList(){
|
|
|
|
return playList;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayList::clear(){
|
|
|
|
playList->clear();
|
|
|
|
playListInfo.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PlayList::addMedia(const SongStorage &song){
|
|
|
|
if(!song.isValid())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(!playList->addMedia(song.toMedia()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
playListInfo.push_back(song);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-02 01:03:27 +03:00
|
|
|
void PlayList::next()const{
|
|
|
|
playList->next();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayList::prev()const{
|
|
|
|
playList->previous();
|
|
|
|
}
|
|
|
|
|
2018-03-29 22:02:03 +03:00
|
|
|
bool PlayList::isValid()const{
|
|
|
|
return playListInfo.size() == playList->mediaCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PlayList::isEmpty()const{
|
|
|
|
return playList->isEmpty() && playListInfo.isEmpty();
|
|
|
|
}
|
|
|
|
|
2018-04-02 01:03:27 +03:00
|
|
|
const SongHeader *PlayList::currentHeader()const{
|
|
|
|
if(playList->isEmpty())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return static_cast<const SongHeader*>(&playListInfo[playList->currentIndex()]);
|
2018-03-29 22:02:03 +03:00
|
|
|
}
|
|
|
|
|
2018-04-02 01:03:27 +03:00
|
|
|
const SongStorage *PlayList::currentSong()const{
|
|
|
|
if(playList->isEmpty())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return &playListInfo[playList->currentIndex()];
|
2018-03-29 22:02:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int PlayList::size()const{
|
|
|
|
return playList->mediaCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayList::~PlayList(){
|
2018-04-02 01:03:27 +03:00
|
|
|
delete playList;
|
2018-03-29 22:02:03 +03:00
|
|
|
}
|