X-Git-Url: http://git.maemo.org/git/?p=groove;a=blobdiff_plain;f=playlist.cpp;h=38eb57992335306bb64662cd2350fdf05693f77a;hp=3c9f6ea03a15caa6028c82c577357595c894acd0;hb=21d90a736479e9eb1615db46297dca25115d5ea0;hpb=dfc707053eff22b0af3a9f4b2a85c684d68a99aa diff --git a/playlist.cpp b/playlist.cpp index 3c9f6ea..38eb579 100644 --- a/playlist.cpp +++ b/playlist.cpp @@ -12,16 +12,23 @@ playlist::playlist(QObject *parent) : } void playlist::markPlayed(int position) { - pList->at(position)->played = true; - this->freeMemory(position); + if(0 <= position && position < pList->size()) + { + pList->at(position)->played = true; + this->freeMemory(position); + } } void playlist::freeMemory(int position) { + pList->at(position)->downloaded = false; + pList->at(position)->bufferready = false; delete pList->at(position)->buffer; pList->at(position)->buffer = new QBuffer(); } bool playlist::existAt(int position) { + if(position < 0) + return false; return (pList->size() > position); } @@ -40,11 +47,13 @@ void playlist::setBufferRdy(int b) { pList->at(b)->bufferready = true; } -bool playlist::setCurrentPlaying(int position) +void playlist::setCurrentPlaying(int position) { - if(pList->size() > position) + if(this->existAt(position)) { this->currentplayingitem = position; + if(!pList->at(position)->downloaded && this->currentdownloaditem != this->currentplayingitem) + this->beginDownload(position); /*if(pList->at(position)->bufferready == false &&) { if(!pList->at(position)->downloaded) @@ -53,10 +62,17 @@ bool playlist::setCurrentPlaying(int position) else emit this->bufferReady(position); */ - return true; + return; } else - return false; + { + if(position == -1) + { + this->currentplayingitem = -1; + } + else + return; + } } QIODevice * playlist::getBuffer(int position) { @@ -87,7 +103,7 @@ void playlist::beginDownload(int position) void playlist::getNError(QNetworkReply::NetworkError error) { qDebug() << "Network Error (if this is 99 then it will retry" << error; - if(error == QNetworkReply::UnknownNetworkError) + if(error == QNetworkReply::UnknownNetworkError && this->currentdownloaditem != -1) beginDownload(this->currentdownloaditem); } @@ -131,7 +147,7 @@ int playlist::addSong(QStandardItem *item) void playlist::downloadDone(int position) { - if(this->existAt(position+1) && this->currentSkeyItem == -1) + if(this->existAt(position+1) && this->currentSkeyItem == -1 && !pList->at(position+1)->downloaded && this->currentdownloaditem != position+1) beginDownload(position+1); else this->currentdownloaditem = -1;