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->addWidget(ok);
70 //vlayout->addLayout(layout);
71 stack = new QStackedWidget();
72 stack->addWidget(resultView);
74 vlayout->addWidget(stack);
75 //vlayout->addLayout(bottomLayout);
76 bBar = new bottomBar();
77 vlayout->addWidget(bBar);
79 /*bottomLayout->addWidget(dButton);
80 bottomLayout->addWidget(stopButton);
81 bottomLayout->addWidget(nextB);
82 bottomLayout->addWidget(moreButton);*/
83 vlayout->setMenuBar(mBar);
84 vlayout->setContentsMargins(QMargins());
86 setWindowTitle("Groove");
87 //Create New Grooveshark connection
90 connect(button, SIGNAL(clicked()), this, SLOT(search()));
91 connect(gs, SIGNAL(finishedSearch()), this, SLOT(finishedS()));
92 connect(lineEdit,SIGNAL(returnPressed()),this, SLOT(search()));
93 connect(pushMenu,SIGNAL(triggered(QAction*)),this,SLOT(changeS(QAction*)));
94 connect(dButton,SIGNAL(clicked()),this, SLOT(addSongPlaylist()));
95 connect(stopButton,SIGNAL(clicked()),this,SLOT(stop()));
96 connect(moreButton,SIGNAL(clicked()),this,SLOT(moreB()));
97 //connect(rotator,SIGNAL(orientationChanged(Orientation)),this,SLOT(orientationChanged()));
98 pl = new playlist(this);
100 player->setPlaylist(pl);
101 connect(pl,SIGNAL(downloadProgress(int,qint64,qint64)),this,SLOT(progressUpdate(int,qint64,qint64)));
102 //connect(pl,SIGNAL(bufferReady(int)),pd,SLOT(close()));
103 connect(pl,SIGNAL(freeze(bool)),resultView,SLOT(setDisabled(bool)));
104 connect(pl,SIGNAL(freeze(bool)),pushMenu,SLOT(setDisabled(bool)));
105 connect(pl,SIGNAL(freeze(bool)),dButton,SLOT(setDisabled(bool)));
106 connect(nextB,SIGNAL(clicked()),player,SLOT(playNext()));
107 connect(ok,SIGNAL(changeTask()),this,SLOT(showOthers()));
108 connect(ok,SIGNAL(searchRequest(QString)),this,SLOT(performSearch(QString)));
109 connect(ok,SIGNAL(closeApp()),this,SLOT(close()));
110 connect(bBar,SIGNAL(addB()),this,SLOT(addSongPlaylist()));
111 connect(bBar,SIGNAL(nextB()),player,SLOT(playNext()));
112 connect(bBar,SIGNAL(pause()),this,SLOT(stop()));
114 connect(bBar,SIGNAL(back()),player,SLOT(back()));
115 bBar->setPlaybackProgress(100,100);
116 pwindow = new pWin();
117 stack->addWidget(pwindow);
118 stack->setCurrentWidget(resultView);
119 connect(bBar,SIGNAL(list()),this,SLOT(togglePlaylist()));
122 void groove::togglePlaylist()
124 if(stack->currentWidget()==pwindow)
125 stack->setCurrentWidget(resultView);
127 stack->setCurrentWidget(pwindow);
130 void groove::performSearch(QString s)
133 resultView->setModel(gs->getSongModel(s));
136 void groove::search()
138 if(!lineEdit->text().isEmpty())
140 if(lineEdit->isEnabled())
143 if(sMethod->text().compare("Song:")==0)
144 resultView->setModel(gs->getSongModel(lineEdit->text()));
145 else if(sMethod->text().compare("Artist:")==0)
146 resultView->setModel(gs->getArtistModel(lineEdit->text()));
147 else if(sMethod->text().compare("Album")==0)
148 resultView->setModel(gs->getAlbumModel(lineEdit->text()));
153 button->setText("Stop");
154 lineEdit->setDisabled(true);
158 resultView->setModel(model);
159 button->setText("Search");
160 resultView->setColumnWidth(0,resultView->viewport()->width()/2);
161 resultView->setColumnWidth(1,resultView->viewport()->width()/2);
162 lineEdit->setDisabled(false);
166 void groove::finishedS()
168 model = gs->getModel();
169 resultView->setModel(model);
170 button->setText("Search");
171 resultView->setColumnWidth(0,resultView->viewport()->width()/2);
172 resultView->setColumnWidth(1,resultView->viewport()->width()/2);
173 lineEdit->setDisabled(false);
174 resultView->setColumnHidden(2,true);
176 void groove::changeS( QAction * action)
178 sMethod->setText(action->text());
179 sMethod->setMaximumWidth(sMethod->sizeHint().rwidth());
182 void groove::showOthers()
184 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
185 QDBusConnection c = QDBusConnection::sessionBus();
186 QDBusMessage m = QDBusMessage::createSignal("/", "com.nokia.hildon_desktop", "exit_app_view");
194 QModelIndexList selected = resultView->selectionModel()->selectedRows(0);
195 if(!selected.isEmpty())
197 QStandardItem *item = model->item(selected.first().row(),2);
201 player->play(pl->addSong(item));
206 void groove::addSongPlaylist()
208 QModelIndexList selected = resultView->selectionModel()->selectedRows(0);
209 if(!selected.isEmpty())
211 QStandardItem *item = model->item(selected.first().row(),2);
215 if(pl->currentplaying() == -1)
217 player->play(pl->addSong(item));
221 model->item(selected.first().row(),1)->setText("Added to Playlist");;
222 pwindow->addSong(model->item(selected.first().row(),0)->text());
234 qDebug() << "He pressed the button";
236 void groove::progressUpdate(int p, qint64 d, qint64 t)
238 //if(!pd->isHidden())
240 bBar->setPlaybackProgress(d,t);
244 void groove::orientationChanged()
247 QRect screenGeometry = QApplication::desktop()->screenGeometry();
248 if (screenGeometry.width() > screenGeometry.height())