this will break all functionality for now
authorElias Woods <EliasWoods@gmail.com>
Fri, 25 Jun 2010 08:28:26 +0000 (04:28 -0400)
committerElias Woods <EliasWoods@gmail.com>
Fri, 25 Jun 2010 08:28:26 +0000 (04:28 -0400)
Groove.pro.user
groove.cpp
groove.h
gscom.cpp
playlist.cpp
playlist.h
splayer.cpp
splayer.h

index ae0586c..334fa29 100644 (file)
     </valuemap>
     <value key="Qt4ProjectManager.MaemoRunConfiguration.DeviceId" type="qulonglong">1</value>
     <valuemap key="Qt4ProjectManager.MaemoRunConfiguration.LastDeployed" type="QVariantMap">
-     <value key="192.168.1.3" type="QDateTime">2010-06-24T03:15:04</value>
+     <value key="192.168.1.3" type="QDateTime">2010-06-25T04:22:04</value>
     </valuemap>
     <value key="Qt4ProjectManager.MaemoRunConfiguration.Simulator" type="QString"></value>
    </valuemap>
index a63602d..050a743 100644 (file)
@@ -74,9 +74,11 @@ groove::groove(QWidget *parent) :
     connect(pushMenu,SIGNAL(triggered(QAction*)),this,SLOT(changeS(QAction*)));
     connect(dButton,SIGNAL(clicked()),this, SLOT(play()));
     connect(stopButton,SIGNAL(clicked()),this,SLOT(stop()));
-    connect(gs,SIGNAL(sKeyFound()),this,SLOT(startP()));
     connect(moreButton,SIGNAL(clicked()),this,SLOT(moreB()));
     //connect(rotator,SIGNAL(orientationChanged(Orientation)),this,SLOT(orientationChanged()));
+    pl = new playlist();
+    pl->setGscom(gs);
+    player->setPlaylist(pl);
 }
 void groove::search()
 {
@@ -132,23 +134,11 @@ void groove::play()
         if(item == 0)
             return;
         //gs->getSong();
-        gs->getSong(item->text());
+        player->play(pl->addSong(item));
     }
     //selected.
     //if
 }
-void groove::startP()
-{
-    if(!gs->sku.isValid())
-        return;
-    player->~sPlayer();
-    player = new sPlayer();
-#ifdef Q_WS_MAEMO_5
-    player->play(gs->streamID,gs->sku,rot->currentOrientation());
-#else
-    player->play(gs->streamID,gs->sku);
-#endif
-}
 void groove::stop()
 {
     player->stop();
index 9a473c8..5741d03 100644 (file)
--- a/groove.h
+++ b/groove.h
@@ -5,6 +5,7 @@
 #include "splayer.h"
 #include "qmaemo5rotator.h"
 #include <QMenuBar>
+#include "playlist.h"
 
 class groove : public QWidget
 {
@@ -19,7 +20,6 @@ public slots:
     void finishedS();
     void changeS( QAction * action);
     void play();
-    void startP();
     void stop();
     void moreB();
     void orientationChanged();
@@ -35,6 +35,7 @@ private:
     bool portrait;
     gscom *gs;
     QMaemo5Rotator *rot;
+    playlist *pl;
 
 };
 
index 733d679..1069350 100644 (file)
--- a/gscom.cpp
+++ b/gscom.cpp
@@ -19,7 +19,7 @@ gscom::gscom()
     model->setHorizontalHeaderLabels(
         QStringList() << "Online");
     addDebugMsg("You may now search for a song");
-    addProgressbar("test");
+    //addProgressbar("test");
     //getSessionKey();
 }
 
index 10e1e26..fbcf8f4 100644 (file)
@@ -6,11 +6,70 @@ playlist::playlist(QObject *parent) :
    manager = new QNetworkAccessManager();
    this->currentdownloaditem = -1;
    pList = new QList<songElement *>;
+   this->currentplayingitem =-1;
 }
+void playlist::markPlayed(int position)
+{
+    pList->at(position)->played = true;
+    this->freeMemory(position);
+}
+void playlist::freeMemory(int position)
+{
+   pList->at(position)->buffer->~QBuffer();
+   pList->at(position)->buffer = new QBuffer();
+}
+
+int playlist::currentplaying()
+{
+    return this->currentplayingitem;
+}
+bool playlist::bReady(int b)
+{
+    return pList->at(b)->bufferready;
+}
+void playlist::setBufferRdy(int b)
+{
+    pList->at(b)->bufferready = true;
+}
+bool playlist::setCurrentPlaying(int position)
+{
+    if(pList->size() > position)
+    {
+        this->currentplayingitem = position;
+        /*if(pList->at(position)->bufferready == false &&)
+        {
+            if(!pList->at(position)->downloaded)
+                this->beginDownload(position);
+        }
+        else
+            emit this->bufferReady(position);
+        */
+        return true;
+    }
+    else
+        return false;
+}
+QIODevice * playlist::getBuffer(int position)
+{
+    return pList->at(position)->buffer;
+}
+
 void playlist::beginDownload(int position)
 {
-    startStreamT = QTime::currentTime();
     this->currentdownloaditem = position;
+    qDebug() << "StartDownlaod:" << pList->at(position)->songId;
+    QNetworkRequest req;
+    req.setUrl(*pList->at(currentdownloaditem)->server);
+    qDebug() << pList->at(currentdownloaditem)->server;
+    req.setHeader(req.ContentTypeHeader,QVariant("application/x-www-form-urlencoded"));
+    if(reply)
+        reply->~QNetworkReply();
+    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)));
+    startStreamT = QTime::currentTime();
 }
 
 void playlist::setGscom(gscom *comm)
@@ -25,24 +84,26 @@ void playlist::skeyFound()
     pList->at(this->currentSkeyItem)->server = new QUrl(gs->sku);
     if(this->currentdownloaditem == -1)
         this->beginDownload(this->currentSkeyItem);
+    else
+        if(this->currentplaying() == this->currentSkeyItem)
+            this->beginDownload(this->currentplayingitem);
 }
 
-void playlist::addSong(QStandardItem item)
+int playlist::addSong(QStandardItem *item)
 {
-
     playlist::songElement *newelement = new playlist::songElement;
     newelement->buffer = new QBuffer();
     newelement->downloaded =false;
-    newelement->songId = new QString(item.text());
+    newelement->songId = new QString(item->text());
     newelement->played = false;
     newelement->server = new QUrl();
     newelement->streamkey = new QString("noneatm");
     newelement->bufferready = false;
     newelement->type = playlist::EStream;
     pList->append(newelement);
-    gs->getSong(item.text());
+    gs->getSong(item->text());
     emit this->freeze();
-    //this->currentdownloaditem = pList->size()-1;
+    return pList->size()-1;
 }
 
 void playlist::downloadDone(int position)
@@ -53,54 +114,40 @@ void playlist::downloadDone(int position)
         this->currentdownloaditem = -1;
     pList->at(position)->downloaded = true;
 }
+void playlist::networkReplyFinish()
+{
+    qDebug() << "finish";
+    QVariant url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
+    if(url.toUrl().isValid())
+    {
+        QNetworkRequest req;
+        req.setUrl(url.toUrl());
+        qDebug() << url;
+        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)));
+    }
+}
 
 void playlist::downloadSlot(qint64 b, qint64 t)
 {
     //qDebug() << "Download: " << b << "Total: " << t;
-    if(b == 0 && t == 0)
-    {
-        QVariant url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
-        if(url.toUrl().isValid())
-        {
-            QNetworkRequest req;
-            req.setUrl(url.toUrl());
-            qDebug() << url;
-            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)));
-        }
-        else
-        {
-            //buffer->close();
-            emit this->sFailure(this->currentdownloaditem,playlist::Other);
-            reply->close();
-        }
-    }
-    else
+    if(t != 0)
     {
         emit this->downloadProgress(this->currentdownloaditem,b,t);
         pList->at(this->currentdownloaditem)->buffer->buffer().append(reply->readAll());
-        //qDebug() << buffer->bytesAvailable();
-
-        /*
-        //buffer->seek(b);
-        qint64 last = buffer->pos();
-        buffer->seek(buffer->bytesAvailable()+buffer->pos());
-        qDebug() << buffer->write(reply->readAll());
-        qDebug() << buffer->pos();
-        //buffer->putChar()
-        buffer->seek(last);
-        //buffer->data().append(reply->readAll());*/
-        //qDebug() << "Download speed (KB/S): " << b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024;
         if ( b >= t*0.05 && !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)
         {
             emit this->downloadComplete(this->currentdownloaditem);
+            //emit this->bufferReady(this->currentdownloaditem);
         }
     }
 }
index 829707f..17895ee 100644 (file)
@@ -19,17 +19,21 @@ public:
         Other =2
     };
     explicit playlist(QObject *parent = 0);
-    void addSong(QStandardItem item);
-    void addSong(QString songid);
-    void addsong(QString streamkey, QUrl server);
+    int addSong(QStandardItem *item);
     QList<QStandardItem *> getPlaylist();
     void removeSong(int position);
     void getSong(int position);
     QIODevice * getBuffer(int position);
     bool isStream(int position);
-    void markComplete(int position);
+    void markPlayed(int position);
     void deleteSong(int position);
     void setGscom(gscom *comm);
+    void freeMemory(int position);
+    int currentplaying();
+    bool setCurrentPlaying(int position);
+    bool bReady(int b);
+    int findFirstNotPlayed();
+    void beginDownload(int position);
 
 signals:
     void downloadProgress(int position, qint64 d, qint64 t);
@@ -42,10 +46,13 @@ signals:
 public slots:
 private slots:
     void downloadSlot(qint64 d, qint64 t);
+    void networkReplyFinish();
     void downloadDone(int position);
     void skeyFound();
+    void setBufferRdy(int b);
 private:
-    void beginDownload(int position);
+
+
     enum elementType
     {
         EStream = 1,
@@ -64,6 +71,7 @@ private:
         bool played;
         bool bufferready;
     };
+    int currentplayingitem;
     int currentSkeyItem;
     QList<songElement *> *pList;
     QSignalMapper *mapper;
index 4b6b07e..a2349b2 100644 (file)
@@ -12,12 +12,26 @@ sPlayer::sPlayer(QObject *parent) :
     //reply = new QNetworkReply();
     internal = parent;
     //buffer->open(QIODevice::ReadWrite);
+    connect(media,SIGNAL(finished()),this,SLOT(markComplete()));
 }
+void sPlayer::setPlaylist(playlist *playList)
+{
+    this->pl = playList;
+    connect(pl,SIGNAL(bufferReady(int)),this,SLOT(start(int)));
+    connect(pl,SIGNAL(downloadProgress(int,qint64,qint64)),this,SLOT(putb(int,qint64,qint64)));
+    //connect(pl,SIGNAL(downloadComplete(int)),this,SLOT(start(int)));
+
+}
+void sPlayer::markComplete()
+{
+    pl->markPlayed(pl->currentplaying());
+    pl->setCurrentPlaying(-1);
+}
+
 sPlayer::~sPlayer()
 {
     manager->~QNetworkAccessManager();
     //reply->~QIODevice();
-    buffer->~QBuffer();
     media->~MediaNode();
 }
 void sPlayer::abortDownload()
@@ -25,131 +39,50 @@ void sPlayer::abortDownload()
     //pd->hide();
     //reply->abort();
 }
-void sPlayer::play(QString StreamKey, QUrl server, QMaemo5Rotator::Orientation orientation)
-{
-    this->play(StreamKey, server);
-#ifdef Q_WS_MAEMO_5
-    if(orientation == QMaemo5Rotator::PortraitOrientation)
-        pd->rot->setCurrentOrientation(orientation);
-#endif
-    //isPortrait = false; //just make the compilier happy on non-maemo
-}
 
-void sPlayer::play(QString StreamKey,QUrl server)
+void sPlayer::start(int p)
 {
-    if(playing)
-    {
-        //reply->abort();
-    }
-    pd = new grooveProgressBar();
-    //pd->setAttribute();
-    pd->show();
-    pd->setValue(0);
-    QNetworkRequest req;
-    req.setUrl(server);
-    qDebug() << server;
-    req.setHeader(req.ContentTypeHeader,QVariant("application/x-www-form-urlencoded"));
-    reply = manager->post(req,QString("streamKey=" + StreamKey.toAscii()).toAscii());
-    buffer->open(buffer->ReadWrite | buffer->Truncate);
-    connect(reply,SIGNAL(finished()),this,SLOT(start()));
-    connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(putb(qint64,qint64)));
-    //connect(pd,SIGNAL(canceled()),this,SLOT(abortDownload()));
-    media->stop();
-    playing = false;
-    startStreamT = QTime::currentTime();
-}
-void sPlayer::start()
-{
-    QVariant url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
-    if(url.toUrl().isValid())
-    {
-        QNetworkRequest req;
-        req.setUrl(url.toUrl());
-        qDebug() << url;
-        reply = manager->get(req);
-        connect(reply,SIGNAL(finished()),this,SLOT(start()));
-        connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(putb(qint64,qint64)));
-    }
-    else
-    {
-        if(!playing)
+    qDebug() << "got start play";
+    if(p == pl->currentplaying())
         {
             playing = true;
-            media->setCurrentSource(Phonon::MediaSource(buffer));
+            media->setCurrentSource(Phonon::MediaSource(pl->getBuffer(p)));
             media->play();
-            pd->hide();
             qDebug() << "Playing";
         }
-    }
-    /*else
+
+}
+void sPlayer::play()
+{
+    if(pl->currentplaying() != -1)
     {
-        media->stop();
-        buffer->close();
-        buffer->open(QIODevice::ReadWrite | QIODevice::Truncate);
-        buffer->write(reply->readAll());
-        reply->close();
-        media->setCurrentSource(Phonon::MediaSource(buffer));
-        media->play();
-    }*/
+        //pl->setCurrentPlaying(pl->findFirstNotPlayed());
+    }
+    else
+        return;
 }
+void sPlayer::play(int p)
+{
+    pl->setCurrentPlaying(p);
+    //pl->beginDownload(p);
+}
+
 void sPlayer::stop()
 {
+    pl->setCurrentPlaying(-1);
     media->stop();
+    playing = false;
 }
 
-void sPlayer::putb(qint64 b, qint64 t)
+void sPlayer::putb(int p, qint64 b, qint64 t)
 {
     //qDebug() << "Download: " << b << "Total: " << t;
-    if(b == 0 && t == 0)
+    if(p == pl->currentplaying())
     {
-        QVariant url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
-        if(url.toUrl().isValid())
-        {
-            QNetworkRequest req;
-            req.setUrl(url.toUrl());
-            qDebug() << url;
-            reply = manager->get(req);
-            connect(reply,SIGNAL(finished()),this,SLOT(start()));
-            connect(reply,SIGNAL(downloadProgress(qint64,qint64)),this,SLOT(putb(qint64,qint64)));
-        }
-        else
-        {
-            //buffer->close();
-            reply->close();
-        }
-    }
-    else
-    {
-        if(pd->maximum() != t)
-            pd->setMaximum(t);
-        pd->setValue(b);
-
-        buffer->buffer().append(reply->readAll());
-        //qDebug() << buffer->bytesAvailable();
-        if(playing)
+        if(pl->bReady(p))
         {
             StreamIO* stream = (StreamIO*) media->currentSource().stream();
-            stream->setStreamSize(buffer->size());
-        }
-
-        /*
-        //buffer->seek(b);
-        qint64 last = buffer->pos();
-        buffer->seek(buffer->bytesAvailable()+buffer->pos());
-        qDebug() << buffer->write(reply->readAll());
-        qDebug() << buffer->pos();
-        //buffer->putChar()
-        buffer->seek(last);
-        //buffer->data().append(reply->readAll());*/
-        //qDebug() << "Download speed (KB/S): " << b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024;
-        if ( b >= t*0.05 && !playing && b/(startStreamT.msecsTo(QTime::currentTime()) + 1)*100/1024 >= 10)
-        {
-            pd->hide();
-            playing = true;
-            //Start playback at 25% download
-            media->setCurrentSource(Phonon::MediaSource(buffer));
-            media->play();
-            qDebug() << "Playing";
+            stream->setStreamSize(pl->getBuffer(p)->size());
         }
     }
 }
index 239df92..5c3e18a 100644 (file)
--- a/splayer.h
+++ b/splayer.h
@@ -7,24 +7,29 @@
 #include "streamio.h"
 #include <QProgressDialog>
 #include "grooveprogressbar.h"
+#include "playlist.h"
 
 class sPlayer : public QObject
 {
     Q_OBJECT
 public:
     explicit sPlayer(QObject *parent = 0);
-    void play(QString StreamKey, QUrl server);
-    void play(QString StreamKey, QUrl server,QMaemo5Rotator::Orientation orientation);
+    void play(int p);
+    void playNext();
+    void play();
     void stop();
+    void setPlaylist(playlist *playList);
     ~sPlayer();
 
 signals:
     void finishedPlaying();
     void downloadComplete();
 public slots:
-    void start();
-    void putb(qint64,qint64);
+    void start(int p);
+    void putb(int p,qint64,qint64);
     void abortDownload();
+private slots:
+    void markComplete();
 private:
     QNetworkAccessManager *manager;
     Phonon::AudioOutput *audioOutput;
@@ -36,5 +41,6 @@ private:
     QObject *internal;
     QTime startStreamT;
     grooveProgressBar *pd;
+    playlist *pl;
 };
 #endif // SPLAYER_H