2 #include "qmaemo5rotator.h"
5 groove::groove(QWidget *parent) :
9 //mBar->addAction("test");
10 sMethod = new QPushButton("Song:");
11 lineEdit = new QLineEdit("");
12 player = new sPlayer();
13 QHBoxLayout *layout = new QHBoxLayout();
14 QVBoxLayout *vlayout = new QVBoxLayout();
15 QHBoxLayout *bottomLayout = new QHBoxLayout();
16 button = new QPushButton("Search");
17 QPushButton *dButton = new QPushButton("Play");
18 QPushButton *stopButton = new QPushButton("Stop");
19 QPushButton *moreButton = new QPushButton("...");
20 resultView = new QTableView();
21 QMenu *pushMenu = new QMenu();
24 lineEdit->setDisabled(true);
25 pushMenu->addAction("Song:");
26 //pushMenu->addAction("Artist:");
27 //pushMenu->addAction("Album:");
28 pd = new grooveProgressBar(this);
30 QMenu *moreAction = new QMenu();
31 moreAction->addAction("Playlist");
32 connect(moreAction->addAction("Add current song to playlist"),SIGNAL(triggered()),this,SLOT(addSongPlaylist()));
33 connect(moreAction->addAction("Show download Progress"),SIGNAL(triggered()),pd,SLOT(show()));
34 moreButton->setMenu(moreAction);
36 //sMethod->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Maximum);
37 sMethod->setMaximumWidth(sMethod->sizeHint().rwidth());
38 sMethod->setMenu(pushMenu);
39 model = new QStandardItemModel();
40 model->setHorizontalHeaderLabels(
41 QStringList() << "Please wait for initialization"
43 resultView->setModel(model);
44 resultView->verticalHeader()->hide();
45 resultView->horizontalHeader()->setStretchLastSection(true);
46 resultView->setSelectionBehavior(QAbstractItemView::SelectRows);
47 resultView->setSelectionMode(QAbstractItemView::SingleSelection);
48 resultView->setEditTriggers(QAbstractItemView::NoEditTriggers);
49 resultView->setColumnHidden(2,true);
50 resultView->setColumnHidden(3,true);
51 resultView->setAutoScroll(false);
52 /*QPalette pal = resultView->palette();
53 pal.setBrush(QPalette::Highlight,QBrush(Qt::transparent,Qt::NoBrush));
54 resultView->setPalette(pal);*/
56 layout->addWidget(sMethod);
57 rot = new QMaemo5Rotator(QMaemo5Rotator::AutomaticBehavior,this);
58 layout->addWidget(lineEdit);
59 layout->addWidget(button);
60 vlayout->addLayout(layout);
61 vlayout->addWidget(resultView);
62 vlayout->addLayout(bottomLayout);
63 bottomLayout->addWidget(dButton);
64 bottomLayout->addWidget(stopButton);
65 bottomLayout->addWidget(moreButton);
66 vlayout->setMenuBar(mBar);
68 setWindowTitle("GrooveShark");
69 //Create New Grooveshark connection
72 connect(button, SIGNAL(clicked()), this, SLOT(search()));
73 connect(gs, SIGNAL(finishedSearch()), this, SLOT(finishedS()));
74 connect(lineEdit,SIGNAL(returnPressed()),this, SLOT(search()));
75 connect(pushMenu,SIGNAL(triggered(QAction*)),this,SLOT(changeS(QAction*)));
76 connect(dButton,SIGNAL(clicked()),this, SLOT(play()));
77 connect(stopButton,SIGNAL(clicked()),this,SLOT(stop()));
78 connect(moreButton,SIGNAL(clicked()),this,SLOT(moreB()));
79 //connect(rotator,SIGNAL(orientationChanged(Orientation)),this,SLOT(orientationChanged()));
82 player->setPlaylist(pl);
83 connect(pl,SIGNAL(downloadProgress(int,qint64,qint64)),this,SLOT(progressUpdate(int,qint64,qint64)));
84 connect(pl,SIGNAL(bufferReady(int)),pd,SLOT(close()));
88 if(!lineEdit->text().isEmpty())
90 if(lineEdit->isEnabled())
93 if(sMethod->text().compare("Song:")==0)
94 resultView->setModel(gs->getSongModel(lineEdit->text()));
95 else if(sMethod->text().compare("Artist:")==0)
96 resultView->setModel(gs->getArtistModel(lineEdit->text()));
97 else if(sMethod->text().compare("Album")==0)
98 resultView->setModel(gs->getAlbumModel(lineEdit->text()));
103 button->setText("Stop");
104 lineEdit->setDisabled(true);
108 resultView->setModel(model);
109 button->setText("Search");
110 resultView->setColumnWidth(0,resultView->viewport()->width()/2);
111 resultView->setColumnWidth(1,resultView->viewport()->width()/2);
112 lineEdit->setDisabled(false);
116 void groove::finishedS()
118 model = gs->getModel();
119 resultView->setModel(model);
120 button->setText("Search");
121 resultView->setColumnWidth(0,resultView->viewport()->width()/2);
122 resultView->setColumnWidth(1,resultView->viewport()->width()/2);
123 lineEdit->setDisabled(false);
124 resultView->setColumnHidden(2,true);
126 void groove::changeS( QAction * action)
128 sMethod->setText(action->text());
129 sMethod->setMaximumWidth(sMethod->sizeHint().rwidth());
133 QModelIndexList selected = resultView->selectionModel()->selectedRows(0);
134 if(!selected.isEmpty())
136 QStandardItem *item = model->item(selected.first().row(),2);
140 player->play(pl->addSong(item));
148 void groove::addSongPlaylist()
150 QModelIndexList selected = resultView->selectionModel()->selectedRows(0);
151 if(!selected.isEmpty())
153 QStandardItem *item = model->item(selected.first().row(),2);
157 if(pl->currentplaying() == -1)
159 player->play(pl->addSong(item));
166 model->item(selected.first().row(),1)->setText("Added to Playlist");;
176 qDebug() << "He pressed the button";
178 void groove::progressUpdate(int p, qint64 d, qint64 t)
180 //if(!pd->isHidden())
187 void groove::orientationChanged()
190 QRect screenGeometry = QApplication::desktop()->screenGeometry();
191 if (screenGeometry.width() > screenGeometry.height())