Playlist support (basic) and download progress dialogs
[groove] / groove.cpp
index 02bda40..e857651 100644 (file)
@@ -1,5 +1,5 @@
 #include "groove.h"
-
+#include "qmaemo5rotator.h"
 
 
 groove::groove(QWidget *parent) :
@@ -16,7 +16,7 @@ groove::groove(QWidget *parent) :
     button = new QPushButton("Search");
     QPushButton *dButton = new QPushButton("Play");
     QPushButton *stopButton = new QPushButton("Stop");
-    QPushButton *moreButton = new QPushButton();
+    QPushButton *moreButton = new QPushButton("...");
     resultView = new QTableView();
     QMenu *pushMenu = new QMenu();
     //showFullScreen();
@@ -25,6 +25,13 @@ groove::groove(QWidget *parent) :
     pushMenu->addAction("Song:");
     //pushMenu->addAction("Artist:");
     //pushMenu->addAction("Album:");
+    pd = new grooveProgressBar(this);
+    pd->hide();
+    QMenu *moreAction = new QMenu();
+    moreAction->addAction("Playlist");
+    connect(moreAction->addAction("Add current song to playlist"),SIGNAL(triggered()),this,SLOT(addSongPlaylist()));
+    connect(moreAction->addAction("Show download Progress"),SIGNAL(triggered()),pd,SLOT(show()));
+    moreButton->setMenu(moreAction);
 
     //sMethod->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Maximum);
     sMethod->setMaximumWidth(sMethod->sizeHint().rwidth());
@@ -45,8 +52,9 @@ groove::groove(QWidget *parent) :
     /*QPalette pal = resultView->palette();
     pal.setBrush(QPalette::Highlight,QBrush(Qt::transparent,Qt::NoBrush));
     resultView->setPalette(pal);*/
-
+    portrait = false;
     layout->addWidget(sMethod);
+    rot = new QMaemo5Rotator(QMaemo5Rotator::AutomaticBehavior,this);
     layout->addWidget(lineEdit);
     layout->addWidget(button);
     vlayout->addLayout(layout);
@@ -66,7 +74,14 @@ groove::groove(QWidget *parent) :
     connect(lineEdit,SIGNAL(returnPressed()),this, SLOT(search()));
     connect(pushMenu,SIGNAL(triggered(QAction*)),this,SLOT(changeS(QAction*)));
     connect(dButton,SIGNAL(clicked()),this, SLOT(play()));
-    connect(gs,SIGNAL(sKeyFound()),this,SLOT(startP()));
+    connect(stopButton,SIGNAL(clicked()),this,SLOT(stop()));
+    connect(moreButton,SIGNAL(clicked()),this,SLOT(moreB()));
+    //connect(rotator,SIGNAL(orientationChanged(Orientation)),this,SLOT(orientationChanged()));
+    pl = new playlist();
+    pl->setGscom(gs);
+    player->setPlaylist(pl);
+    connect(pl,SIGNAL(downloadProgress(int,qint64,qint64)),this,SLOT(progressUpdate(int,qint64,qint64)));
+    connect(pl,SIGNAL(bufferReady(int)),pd,SLOT(close()));
 }
 void groove::search()
 {
@@ -122,17 +137,60 @@ void groove::play()
         if(item == 0)
             return;
         //gs->getSong();
-        gs->getSong(item->text());
+        player->play(pl->addSong(item));
+        pd->setMaximum(100);
+        pd->setValue(0);
+        pd->show();
     }
     //selected.
     //if
 }
-void groove::startP()
+void groove::addSongPlaylist()
 {
-    if(!gs->sku.isValid())
-        return;
-    player->~sPlayer();
-    player = new sPlayer();
-    player->play(gs->streamID,gs->sku);
+    QModelIndexList selected = resultView->selectionModel()->selectedRows(0);
+    if(!selected.isEmpty())
+    {
+        QStandardItem *item = model->item(selected.first().row(),2);
+        if(item == 0)
+            return;
+        //gs->getSong();
+        if(pl->currentplaying() == -1)
+        {
+            player->play(pl->addSong(item));
+        }
+        else
+            pl->addSong(item);
+        pd->setMaximum(100);
+        pd->setValue(0);
+        pd->show();
+        model->item(selected.first().row(),1)->setText("Added to Playlist");;
+    }
+}
 
+void groove::stop()
+{
+    player->stop();
+}
+void groove::moreB()
+{
+    qDebug() << "He pressed the button";
+}
+void groove::progressUpdate(int p, qint64 d, qint64 t)
+{
+    //if(!pd->isHidden())
+    //{
+        pd->setMaximum(t);
+        pd->setValue(d);
+    //}
+}
+
+void groove::orientationChanged()
+{
+#ifdef Q_WS_MAEMO_5
+    QRect screenGeometry = QApplication::desktop()->screenGeometry();
+    if (screenGeometry.width() > screenGeometry.height())
+        portrait = false;
+    else
+        portrait = true;
+#endif
 }