X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=playlist.cpp;h=3c9f6ea03a15caa6028c82c577357595c894acd0;hb=59ffc920954b530fd1b867f5edf9d5d910510636;hp=4fbdad7f0beb6f60fbd4799dd1a0fe48e1544038;hpb=e006b301436516a819a53aa4aa5ca8f79625ebfa;p=groove diff --git a/playlist.cpp b/playlist.cpp index 4fbdad7..3c9f6ea 100644 --- a/playlist.cpp +++ b/playlist.cpp @@ -8,6 +8,7 @@ playlist::playlist(QObject *parent) : pList = new QList; this->currentplayingitem = -1; this->currentSkeyItem = -1; + this->reply = NULL; } void playlist::markPlayed(int position) { @@ -16,9 +17,13 @@ void playlist::markPlayed(int position) } void playlist::freeMemory(int position) { - pList->at(position)->buffer->~QBuffer(); + delete pList->at(position)->buffer; pList->at(position)->buffer = new QBuffer(); } +bool playlist::existAt(int position) +{ + return (pList->size() > position); +} int playlist::currentplaying() { @@ -26,7 +31,10 @@ int playlist::currentplaying() } bool playlist::bReady(int b) { - return pList->at(b)->bufferready; + if(pList->size() > b) + return pList->at(b)->bufferready; + else + return false; } void playlist::setBufferRdy(int b) { @@ -64,14 +72,25 @@ void playlist::beginDownload(int position) qDebug() << pList->at(currentdownloaditem)->server; req.setHeader(req.ContentTypeHeader,QVariant("application/x-www-form-urlencoded")); if(reply) - reply->~QNetworkReply(); + { + reply->disconnect(); + reply->deleteLater(); + } reply = manager->post(req,QString("streamKey=" + pList->at(this->currentdownloaditem)->streamkey->toAscii()).toAscii()); pList->at(this->currentdownloaditem)->buffer->open(QBuffer::ReadWrite | QBuffer::Truncate); connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(downloadSlot(qint64,qint64))); connect(reply,SIGNAL(finished()),this,SLOT(networkReplyFinish())); connect(this,SIGNAL(downloadComplete(int)),this,SLOT(downloadDone(int))); + connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(getNError(QNetworkReply::NetworkError))); startStreamT = QTime::currentTime(); } +void playlist::getNError(QNetworkReply::NetworkError error) +{ + qDebug() << "Network Error (if this is 99 then it will retry" << error; + if(error == QNetworkReply::UnknownNetworkError) + beginDownload(this->currentdownloaditem); + +} void playlist::setGscom(gscom *comm) { @@ -80,7 +99,7 @@ void playlist::setGscom(gscom *comm) } void playlist::skeyFound() { - emit this->unfreeze(); + emit this->freeze(false); pList->at(this->currentSkeyItem)->streamkey = new QString(gs->streamID); pList->at(this->currentSkeyItem)->server = new QUrl(gs->sku); if(this->currentdownloaditem == -1) @@ -88,6 +107,7 @@ void playlist::skeyFound() else if(this->currentplaying() == this->currentSkeyItem) this->beginDownload(this->currentSkeyItem); + this->currentSkeyItem = -1; } int playlist::addSong(QStandardItem *item) @@ -103,14 +123,15 @@ int playlist::addSong(QStandardItem *item) newelement->type = playlist::EStream; pList->append(newelement); gs->getSong(item->text()); - emit this->freeze(); + this->currentSkeyItem = pList->size()-1; + emit this->freeze(true); return pList->size()-1; } void playlist::downloadDone(int position) { - if(pList->size() < position+1) + if(this->existAt(position+1) && this->currentSkeyItem == -1) beginDownload(position+1); else this->currentdownloaditem = -1; @@ -125,10 +146,17 @@ void playlist::networkReplyFinish() QNetworkRequest req; req.setUrl(url.toUrl()); qDebug() << url; + if(reply) + { + reply->disconnect(); + reply->deleteLater(); + } reply = manager->get(req); startStreamT = QTime::currentTime(); //connect(reply,SIGNAL(finished()),this,SLOT(start())); connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(downloadSlot(qint64,qint64))); + connect(reply,SIGNAL(finished()),this,SLOT(networkReplyFinish())); + connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(getNError(QNetworkReply::NetworkError))); } } @@ -138,20 +166,23 @@ void playlist::downloadSlot(qint64 b, qint64 t) if(t != 0) { emit this->downloadProgress(this->currentdownloaditem,b,t); - pList->at(this->currentdownloaditem)->buffer->buffer().append(reply->readAll()); - //qDebug() << !pList->at(this->currentdownloaditem)->bufferready << this->currentdownloaditem; - if ( b >= t*0.05 && !pList->at(this->currentdownloaditem)->bufferready) - //if(!pList->at(currentdownloaditem)->bufferready && b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024 >= 10) + if(existAt(this->currentdownloaditem)) { - this->setBufferRdy(this->currentdownloaditem); - emit this->bufferReady(this->currentdownloaditem); + pList->at(this->currentdownloaditem)->buffer->buffer().append(reply->readAll()); + //qDebug() << !pList->at(this->currentdownloaditem)->bufferready << this->currentdownloaditem; + if ( b >= t*0.05 && !pList->at(this->currentdownloaditem)->bufferready) + //if(!pList->at(currentdownloaditem)->bufferready && b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024 >= 10) + { + this->setBufferRdy(this->currentdownloaditem); + emit this->bufferReady(this->currentdownloaditem); - qDebug() << "Buffer Ready"; - } - if (b==t) - { + qDebug() << "Buffer Ready"; + } + if (b==t) + { emit this->downloadComplete(this->currentdownloaditem); //emit this->bufferReady(this->currentdownloaditem); + } } } }