stack->addWidget(pwindow);
stack->setCurrentWidget(resultView);
connect(bBar,SIGNAL(list()),this,SLOT(togglePlaylist()));
+ pwindow->setModel(pl);
}
void groove::togglePlaylist()
{
qDebug() << s;
resultView->setModel(gs->getSongModel(s));
+ this->stack->setCurrentWidget(this->resultView);
}
void groove::search()
if(item == 0)
return;
//gs->getSong();
- player->play(pl->addSong(item));
+ player->play(pl->addSong(item,model->item(selected.first().row(),0)->text()));
}
//selected.
//if
//gs->getSong();
if(pl->currentplaying() == -1)
{
- player->play(pl->addSong(item));
+ player->play(pl->addSong(item,model->item(selected.first().row(),0)->text()));
}
else
- pl->addSong(item);
+ pl->addSong(item,model->item(selected.first().row(),0)->text());
model->item(selected.first().row(),1)->setText("Added to Playlist");;
- pwindow->addSong(model->item(selected.first().row(),0)->text());
+ //pwindow->addSong(model->item(selected.first().row(),0)->text());
}
}
#include "playlist.h"
playlist::playlist(QObject *parent) :
- QObject(parent)
+ QAbstractTableModel(parent)
{
manager = new QNetworkAccessManager();
this->currentdownloaditem = -1;
this->currentSkeyItem = -1;
this->reply = NULL;
}
+
+//Implemented model class information
+QVariant playlist::data(const QModelIndex &index, int role) const
+{
+ QVariant dat;
+ playlist* play = (playlist *)index.model();
+ if(play->existAt(index.row()))
+ {
+ if (!index.isValid())
+ return QVariant();
+ if (role == Qt::TextAlignmentRole) {
+ return int(Qt::AlignRight | Qt::AlignVCenter);
+ } else if (role == Qt::DisplayRole) {
+ switch(index.column())
+ {
+ case sName:
+ dat = QVariant(*play->pList->at(index.row())->name);
+ break;
+ case sID:
+ dat = QVariant(*play->pList->at(index.row())->songId);
+ break;
+ case sKey:
+ dat = QVariant(*play->pList->at(index.row())->streamkey);
+ break;
+ case sDownloaded:
+ dat = QVariant(play->pList->at(index.row())->downloaded);
+ break;
+ case sReady:
+ dat = QVariant(play->pList->at(index.row())->bufferready);
+ break;
+ case sURL:
+ dat = QVariant(play->pList->at(index.row())->server->toString());
+ break;
+ case sPlayed:
+ dat = QVariant(play->pList->at(index.row())->played);
+ break;
+ default:
+ dat = QVariant();
+ }
+ } else
+ dat = QVariant();
+ }
+ else
+ dat = QVariant();
+ return dat;
+}
+int playlist::rowCount(const QModelIndex &) const
+{
+ return pList->size();
+}
+int playlist::columnCount(const QModelIndex &) const
+{
+ return PLAYLISTENUMS;
+}
+
+
QList<playlist::songElement *>* playlist::getList()
{
return pList;
this->currentSkeyItem = -1;
}
-int playlist::addSong(QStandardItem *item)
+int playlist::addSong(QStandardItem *item, QString name)
{
playlist::songElement *newelement = new playlist::songElement;
+ newelement->name = new QString(name);
newelement->buffer = new QBuffer();
newelement->downloaded =false;
newelement->songId = new QString(item->text());
newelement->type = playlist::EStream;
pList->append(newelement);
gs->getSong(item->text());
-
+ emit this->rowsInserted(QModelIndex(),pList->size(),pList->size());
this->currentSkeyItem = pList->size()-1;
emit this->freeze(true);
return pList->size()-1;
#include <QList>
#include <QSignalMapper>
#include <gscom.h>
-class playlist : public QObject
+class playlist : public QAbstractTableModel
{
Q_OBJECT
public:
Aborted = 1,
Other =2
};
+ //this Enum MUST BE sequantial
+ //And when changed must update the length
+#define PLAYLISTENUMS 8
+ enum coulmnStruct
+ {
+ sName,
+ sID,
+ sKey,
+ sURL,
+ sBuff,
+ sDownloaded,
+ sPlayed,
+ sReady,
+ };
+
struct songElement
{
+ QString *name;
QString *songId;
QString *streamkey;
QUrl *server;
};
QList<songElement *>* getList();
explicit playlist(QObject *parent = 0);
- int addSong(QStandardItem *item);
- QList<QStandardItem *> getPlaylist();
+ int addSong(QStandardItem *item,QString name);
void removeSong(int position);
void getSong(int position);
QIODevice * getBuffer(int position);
void beginDownload(int position);
bool existAt(int position);
+ //Implemented virtual classes for Model View
+ QVariant data(const QModelIndex &index, int role) const;
+ int columnCount(const QModelIndex &parent) const;
+ int rowCount(const QModelIndex &parent) const;
+
signals:
void downloadProgress(int position, qint64 d, qint64 t);
void bufferReady(int position);
void sFailure(int position,failType);
void downloadComplete(int position);
void freeze(bool);
+ //void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
+ void rowsInserted ( const QModelIndex & parent, int start, int end );
public slots:
private slots:
#include "pwin.h"
+#include "playlist.h"
#include "ui_pwin.h"
pWin::pWin(QWidget *parent) :
ui(new Ui::pWin)
{
ui->setupUi(this);
+
+
}
pWin::~pWin()
{
delete ui;
}
-void pWin::addSong(QString name)
+void pWin::setModel(QAbstractItemModel *m)
{
- ui->listWidget->addItem(name);
+ ui->tabv->setModel(m);
+ //By Default hide all columns
+ for(int i = 0; i < PLAYLISTENUMS; i++)
+ {
+ ui->tabv->hideColumn(i);
+ }
+ //Only show the song name column
+ ui->tabv->showColumn(playlist::sName);
}
#define PWIN_H
#include <QWidget>
+#include <QtGui>
namespace Ui {
class pWin;
Q_OBJECT
public:
- void addSong(QString name);
+ void setModel(QAbstractItemModel *name);
explicit pWin(QWidget *parent = 0);
~pWin();
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
- <widget class="QListWidget" name="listWidget">
- <property name="dragDropMode">
- <enum>QAbstractItemView::InternalMove</enum>
- </property>
- <property name="selectionBehavior">
- <enum>QAbstractItemView::SelectRows</enum>
- </property>
- <item>
- <property name="text">
- <string>New Item</string>
- </property>
- <property name="icon">
- <iconset resource="res.qrc">
- <normaloff>:/groove/icons/general_forward.png</normaloff>:/groove/icons/general_forward.png</iconset>
- </property>
- </item>
- </widget>
- </item>
- <item>
- <layout class="QVBoxLayout" name="verticalLayout"/>
+ <widget class="QTableView" name="tabv"/>
</item>
</layout>
</widget>
- <resources>
- <include location="res.qrc"/>
- </resources>
+ <resources/>
<connections/>
</ui>