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{
|
2018-04-05 21:54:49 +03:00
|
|
|
if(playList->isEmpty() || playList->currentIndex() < 0)
|
2018-04-02 01:03:27 +03:00
|
|
|
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{
|
2018-04-05 21:54:49 +03:00
|
|
|
if(playList->isEmpty() || playList->currentIndex() < 0)
|
2018-04-02 01:03:27 +03:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return &playListInfo[playList->currentIndex()];
|
2018-03-29 22:02:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int PlayList::size()const{
|
|
|
|
return playList->mediaCount();
|
|
|
|
}
|
|
|
|
|
2018-04-05 21:54:49 +03:00
|
|
|
int PlayList::find(const SongHeader &header)const{
|
|
|
|
for(int i = 0; i < playList->mediaCount(); ++i) {
|
|
|
|
if(header == playList->media(i)) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PlayList::selectSong(int index){
|
|
|
|
if(playList->mediaCount() <= index || index < 0){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
playList->setCurrentIndex(index);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PlayList::selectSong(const SongHeader &header){
|
|
|
|
return selectSong(find(header));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-03-29 22:02:03 +03:00
|
|
|
PlayList::~PlayList(){
|
2018-04-02 01:03:27 +03:00
|
|
|
delete playList;
|
2018-03-29 22:02:03 +03:00
|
|
|
}
|