2 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
3 #include "qmaemo5rotator.h"
8 groove::groove(QWidget *parent) :
11 //mpg = new mpgplayer();
13 mBar = new QMenuBar();
14 //mBar->addAction("test");
15 sMethod = new QPushButton("Song:");
16 lineEdit = new QLineEdit("");
17 player = new sPlayer();
18 QHBoxLayout *layout = new QHBoxLayout();
19 QVBoxLayout *vlayout = new QVBoxLayout();
20 //QHBoxLayout *bottomLayout = new QHBoxLayout();
21 button = new QPushButton("Search");
22 QPushButton *dButton = new QPushButton("Queue");
23 QPushButton *stopButton = new QPushButton("Pause");
24 QPushButton *moreButton = new QPushButton("...");
25 QPushButton *nextB = new QPushButton("->");
26 topBar *ok = new topBar(this);
27 resultView = new QTableView();
28 QMenu *pushMenu = new QMenu();
31 lineEdit->setDisabled(true);
32 pushMenu->addAction("Song:");
33 //pushMenu->addAction("Artist:");
34 //pushMenu->addAction("Album:");
35 QMenu *moreAction = new QMenu();
36 //moreAction->addAction("Playlist");
37 connect(moreAction->addAction("Play Now"),SIGNAL(triggered()),this,SLOT(play()));
38 //connect(moreAction->addAction("Show download Progress"),SIGNAL(triggered()),pd,SLOT(show()));
39 moreButton->setMenu(moreAction);
41 //sMethod->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Maximum);
42 sMethod->setMaximumWidth(sMethod->sizeHint().rwidth());
43 sMethod->setMenu(pushMenu);
44 model = new QStandardItemModel();
45 model->setHorizontalHeaderLabels(
46 QStringList() << "Please wait for initialization"
48 resultView->setModel(model);
49 resultView->verticalHeader()->hide();
50 resultView->horizontalHeader()->setStretchLastSection(true);
51 resultView->setSelectionBehavior(QAbstractItemView::SelectRows);
52 resultView->setSelectionMode(QAbstractItemView::SingleSelection);
53 resultView->setEditTriggers(QAbstractItemView::NoEditTriggers);
54 resultView->setColumnHidden(2,true);
55 resultView->setColumnHidden(3,true);
56 resultView->setAutoScroll(false);
57 resultView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
58 /*QPalette pal = resultView->palette();
59 pal.setBrush(QPalette::Highlight,QBrush(Qt::transparent,Qt::NoBrush));
60 resultView->setPalette(pal);*/
62 layout->addWidget(sMethod);
63 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
64 rot = new QMaemo5Rotator(QMaemo5Rotator::AutomaticBehavior,this);
66 //this->setAttribute(Qt::WA_Maemo5AutoOrientation);
67 layout->addWidget(lineEdit);
68 layout->addWidget(button);
69 vlayout->setContentsMargins(QMargins(0,0,0,0));
70 //vlayout->setMargin(0);
71 vlayout->setSpacing(0);
72 vlayout->addWidget(ok);
73 //vlayout->addLayout(layout);
74 stack = new QStackedWidget();
75 stack->addWidget(resultView);
77 vlayout->addWidget(stack);
78 //vlayout->addLayout(bottomLayout);
79 bBar = new bottomBar();
80 vlayout->addWidget(bBar);
82 /*bottomLayout->addWidget(dButton);
83 bottomLayout->addWidget(stopButton);
84 bottomLayout->addWidget(nextB);
85 bottomLayout->addWidget(moreButton);*/
86 vlayout->setMenuBar(mBar);
88 setWindowTitle("Groove");
89 //Create New Grooveshark connection
92 connect(button, SIGNAL(clicked()), this, SLOT(search()));
93 connect(gs, SIGNAL(finishedSearch()), this, SLOT(finishedS()));
94 connect(lineEdit,SIGNAL(returnPressed()),this, SLOT(search()));
95 connect(pushMenu,SIGNAL(triggered(QAction*)),this,SLOT(changeS(QAction*)));
96 connect(dButton,SIGNAL(clicked()),this, SLOT(addSongPlaylist()));
97 connect(stopButton,SIGNAL(clicked()),this,SLOT(stop()));
98 connect(moreButton,SIGNAL(clicked()),this,SLOT(moreB()));
99 //connect(rotator,SIGNAL(orientationChanged(Orientation)),this,SLOT(orientationChanged()));
100 pl = new playlist(this);
102 player->setPlaylist(pl);
103 connect(pl,SIGNAL(downloadProgress(int,qint64,qint64)),this,SLOT(progressUpdate(int,qint64,qint64)));
104 //connect(pl,SIGNAL(bufferReady(int)),pd,SLOT(close()));
105 connect(pl,SIGNAL(freeze(bool)),resultView,SLOT(setDisabled(bool)));
106 connect(pl,SIGNAL(freeze(bool)),pushMenu,SLOT(setDisabled(bool)));
107 connect(pl,SIGNAL(freeze(bool)),dButton,SLOT(setDisabled(bool)));
108 connect(nextB,SIGNAL(clicked()),player,SLOT(playNext()));
109 connect(ok,SIGNAL(changeTask()),this,SLOT(showOthers()));
110 connect(ok,SIGNAL(searchRequest(QString)),this,SLOT(performSearch(QString)));
111 connect(ok,SIGNAL(closeApp()),this,SLOT(close()));
112 connect(bBar,SIGNAL(addB()),this,SLOT(addSongPlaylist()));
113 connect(bBar,SIGNAL(nextB()),player,SLOT(playNext()));
114 connect(bBar,SIGNAL(pause()),this,SLOT(stop()));
116 connect(bBar,SIGNAL(back()),player,SLOT(back()));
117 bBar->setPlaybackProgress(100,100);
118 pwindow = new pWin();
119 stack->addWidget(pwindow);
120 stack->setCurrentWidget(resultView);
121 connect(bBar,SIGNAL(list()),this,SLOT(togglePlaylist()));
122 pwindow->setModel(pl);
125 void groove::togglePlaylist()
127 if(stack->currentWidget()==pwindow)
128 stack->setCurrentWidget(resultView);
130 stack->setCurrentWidget(pwindow);
133 void groove::performSearch(QString s)
136 resultView->setModel(gs->getSongModel(s));
137 this->stack->setCurrentWidget(this->resultView);
140 void groove::search()
142 if(!lineEdit->text().isEmpty())
144 if(lineEdit->isEnabled())
147 if(sMethod->text().compare("Song:")==0)
148 resultView->setModel(gs->getSongModel(lineEdit->text()));
149 else if(sMethod->text().compare("Artist:")==0)
150 resultView->setModel(gs->getArtistModel(lineEdit->text()));
151 else if(sMethod->text().compare("Album")==0)
152 resultView->setModel(gs->getAlbumModel(lineEdit->text()));
157 button->setText("Stop");
158 lineEdit->setDisabled(true);
162 resultView->setModel(model);
163 button->setText("Search");
164 resultView->setColumnWidth(0,resultView->viewport()->width()/2);
165 resultView->setColumnWidth(1,resultView->viewport()->width()/2);
166 lineEdit->setDisabled(false);
170 void groove::finishedS()
172 model = gs->getModel();
173 resultView->setModel(model);
174 button->setText("Search");
175 resultView->setColumnWidth(0,resultView->maximumViewportSize().width()/2);
176 resultView->setColumnWidth(1,resultView->maximumViewportSize().width()/2);
177 lineEdit->setDisabled(false);
178 resultView->setColumnHidden(2,true);
180 void groove::changeS( QAction * action)
182 sMethod->setText(action->text());
183 sMethod->setMaximumWidth(sMethod->sizeHint().rwidth());
186 void groove::showOthers()
188 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
189 QDBusConnection c = QDBusConnection::sessionBus();
190 QDBusMessage m = QDBusMessage::createSignal("/", "com.nokia.hildon_desktop", "exit_app_view");
198 QModelIndexList selected = resultView->selectionModel()->selectedRows(0);
199 if(!selected.isEmpty())
201 QStandardItem *item = model->item(selected.first().row(),2);
205 player->play(pl->addSong(item,model->item(selected.first().row(),0)->text()));
210 void groove::addSongPlaylist()
212 QModelIndexList selected = resultView->selectionModel()->selectedRows(0);
213 if(!selected.isEmpty())
215 QStandardItem *item = model->item(selected.first().row(),2);
219 if(pl->currentplaying() == -1)
221 player->play(pl->addSong(item,model->item(selected.first().row(),0)->text()));
224 pl->addSong(item,model->item(selected.first().row(),0)->text());
225 model->item(selected.first().row(),1)->setText("Added to Playlist");;
226 //pwindow->addSong(model->item(selected.first().row(),0)->text());
238 qDebug() << "He pressed the button";
240 void groove::progressUpdate(int p, qint64 d, qint64 t)
242 //if(!pd->isHidden())
244 bBar->setPlaybackProgress(d,t);
247 void groove::resizeEvent(QResizeEvent *)
249 if(resultView->isColumnHidden(2))
251 resultView->setColumnWidth(0,resultView->maximumViewportSize().width()/2);
252 resultView->setColumnWidth(1,resultView->maximumViewportSize().width()/2);
255 resultView->setColumnWidth(0,resultView->maximumViewportSize().width());
258 void groove::orientationChanged()
261 QRect screenGeometry = QApplication::desktop()->screenGeometry();
262 if (screenGeometry.width() > screenGeometry.height())