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 vlayout->addWidget(resultView);
72 //vlayout->addLayout(bottomLayout);
73 bBar = new bottomBar();
74 vlayout->addWidget(bBar);
75 vlayout->setSpacing(0);
76 bottomLayout->addWidget(dButton);
77 bottomLayout->addWidget(stopButton);
78 bottomLayout->addWidget(nextB);
79 bottomLayout->addWidget(moreButton);
80 vlayout->setMenuBar(mBar);
81 vlayout->setContentsMargins(QMargins());
83 setWindowTitle("Groove");
84 //Create New Grooveshark connection
87 connect(button, SIGNAL(clicked()), this, SLOT(search()));
88 connect(gs, SIGNAL(finishedSearch()), this, SLOT(finishedS()));
89 connect(lineEdit,SIGNAL(returnPressed()),this, SLOT(search()));
90 connect(pushMenu,SIGNAL(triggered(QAction*)),this,SLOT(changeS(QAction*)));
91 connect(dButton,SIGNAL(clicked()),this, SLOT(addSongPlaylist()));
92 connect(stopButton,SIGNAL(clicked()),this,SLOT(stop()));
93 connect(moreButton,SIGNAL(clicked()),this,SLOT(moreB()));
94 //connect(rotator,SIGNAL(orientationChanged(Orientation)),this,SLOT(orientationChanged()));
95 pl = new playlist(this);
97 player->setPlaylist(pl);
98 connect(pl,SIGNAL(downloadProgress(int,qint64,qint64)),this,SLOT(progressUpdate(int,qint64,qint64)));
99 //connect(pl,SIGNAL(bufferReady(int)),pd,SLOT(close()));
100 connect(pl,SIGNAL(freeze(bool)),resultView,SLOT(setDisabled(bool)));
101 connect(pl,SIGNAL(freeze(bool)),pushMenu,SLOT(setDisabled(bool)));
102 connect(pl,SIGNAL(freeze(bool)),dButton,SLOT(setDisabled(bool)));
103 connect(nextB,SIGNAL(clicked()),player,SLOT(playNext()));
104 connect(ok,SIGNAL(changeTask()),this,SLOT(showOthers()));
105 connect(ok,SIGNAL(searchRequest(QString)),this,SLOT(performSearch(QString)));
106 connect(ok,SIGNAL(closeApp()),this,SLOT(close()));
107 connect(bBar,SIGNAL(addB()),this,SLOT(addSongPlaylist()));
108 connect(bBar,SIGNAL(nextB()),player,SLOT(playNext()));
109 connect(bBar,SIGNAL(pause()),this,SLOT(stop()));
111 connect(bBar,SIGNAL(back()),player,SLOT(back()));
112 bBar->setPlaybackProgress(100,100);
113 //pwindow = new pListWin(0);
117 void groove::performSearch(QString s)
120 resultView->setModel(gs->getSongModel(s));
123 void groove::search()
125 if(!lineEdit->text().isEmpty())
127 if(lineEdit->isEnabled())
130 if(sMethod->text().compare("Song:")==0)
131 resultView->setModel(gs->getSongModel(lineEdit->text()));
132 else if(sMethod->text().compare("Artist:")==0)
133 resultView->setModel(gs->getArtistModel(lineEdit->text()));
134 else if(sMethod->text().compare("Album")==0)
135 resultView->setModel(gs->getAlbumModel(lineEdit->text()));
140 button->setText("Stop");
141 lineEdit->setDisabled(true);
145 resultView->setModel(model);
146 button->setText("Search");
147 resultView->setColumnWidth(0,resultView->viewport()->width()/2);
148 resultView->setColumnWidth(1,resultView->viewport()->width()/2);
149 lineEdit->setDisabled(false);
153 void groove::finishedS()
155 model = gs->getModel();
156 resultView->setModel(model);
157 button->setText("Search");
158 resultView->setColumnWidth(0,resultView->viewport()->width()/2);
159 resultView->setColumnWidth(1,resultView->viewport()->width()/2);
160 lineEdit->setDisabled(false);
161 resultView->setColumnHidden(2,true);
163 void groove::changeS( QAction * action)
165 sMethod->setText(action->text());
166 sMethod->setMaximumWidth(sMethod->sizeHint().rwidth());
169 void groove::showOthers()
171 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
172 QDBusConnection c = QDBusConnection::sessionBus();
173 QDBusMessage m = QDBusMessage::createSignal("/", "com.nokia.hildon_desktop", "exit_app_view");
181 QModelIndexList selected = resultView->selectionModel()->selectedRows(0);
182 if(!selected.isEmpty())
184 QStandardItem *item = model->item(selected.first().row(),2);
188 player->play(pl->addSong(item));
193 void groove::addSongPlaylist()
195 QModelIndexList selected = resultView->selectionModel()->selectedRows(0);
196 if(!selected.isEmpty())
198 QStandardItem *item = model->item(selected.first().row(),2);
202 if(pl->currentplaying() == -1)
204 player->play(pl->addSong(item));
208 model->item(selected.first().row(),1)->setText("Added to Playlist");;
210 //pwindow->updateList();
220 qDebug() << "He pressed the button";
222 void groove::progressUpdate(int p, qint64 d, qint64 t)
224 //if(!pd->isHidden())
226 bBar->setPlaybackProgress(d,t);
230 void groove::orientationChanged()
233 QRect screenGeometry = QApplication::desktop()->screenGeometry();
234 if (screenGeometry.width() > screenGeometry.height())