2 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
3 #include "qmaemo5rotator.h"
7 groove::groove(QWidget *parent) :
10 mBar = new QMenuBar();
11 //mBar->addAction("test");
12 sMethod = new QPushButton("Song:");
13 lineEdit = new QLineEdit("");
14 player = new sPlayer();
15 QHBoxLayout *layout = new QHBoxLayout();
16 QVBoxLayout *vlayout = new QVBoxLayout();
17 QHBoxLayout *bottomLayout = new QHBoxLayout();
18 button = new QPushButton("Search");
19 QPushButton *dButton = new QPushButton("Queue");
20 QPushButton *stopButton = new QPushButton("Pause");
21 QPushButton *moreButton = new QPushButton("...");
22 QPushButton *nextB = new QPushButton("->");
23 topBar *ok = new topBar(this);
24 resultView = new QTableView();
25 QMenu *pushMenu = new QMenu();
28 lineEdit->setDisabled(true);
29 pushMenu->addAction("Song:");
30 //pushMenu->addAction("Artist:");
31 //pushMenu->addAction("Album:");
32 QMenu *moreAction = new QMenu();
33 //moreAction->addAction("Playlist");
34 connect(moreAction->addAction("Play Now"),SIGNAL(triggered()),this,SLOT(play()));
35 //connect(moreAction->addAction("Show download Progress"),SIGNAL(triggered()),pd,SLOT(show()));
36 moreButton->setMenu(moreAction);
38 //sMethod->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Maximum);
39 sMethod->setMaximumWidth(sMethod->sizeHint().rwidth());
40 sMethod->setMenu(pushMenu);
41 model = new QStandardItemModel();
42 model->setHorizontalHeaderLabels(
43 QStringList() << "Please wait for initialization"
45 resultView->setModel(model);
46 resultView->verticalHeader()->hide();
47 resultView->horizontalHeader()->setStretchLastSection(true);
48 resultView->setSelectionBehavior(QAbstractItemView::SelectRows);
49 resultView->setSelectionMode(QAbstractItemView::SingleSelection);
50 resultView->setEditTriggers(QAbstractItemView::NoEditTriggers);
51 resultView->setColumnHidden(2,true);
52 resultView->setColumnHidden(3,true);
53 resultView->setAutoScroll(false);
54 resultView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
55 /*QPalette pal = resultView->palette();
56 pal.setBrush(QPalette::Highlight,QBrush(Qt::transparent,Qt::NoBrush));
57 resultView->setPalette(pal);*/
59 layout->addWidget(sMethod);
60 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
61 rot = new QMaemo5Rotator(QMaemo5Rotator::AutomaticBehavior,this);
63 //this->setAttribute(Qt::WA_Maemo5AutoOrientation);
64 layout->addWidget(lineEdit);
65 layout->addWidget(button);
66 vlayout->addWidget(ok);
67 //vlayout->addLayout(layout);
68 vlayout->addWidget(resultView);
69 //vlayout->addLayout(bottomLayout);
70 bBar = new bottomBar();
71 vlayout->addWidget(bBar);
72 vlayout->setSpacing(0);
73 bottomLayout->addWidget(dButton);
74 bottomLayout->addWidget(stopButton);
75 bottomLayout->addWidget(nextB);
76 bottomLayout->addWidget(moreButton);
77 vlayout->setMenuBar(mBar);
78 vlayout->setContentsMargins(QMargins());
80 setWindowTitle("Groove");
81 //Create New Grooveshark connection
84 connect(button, SIGNAL(clicked()), this, SLOT(search()));
85 connect(gs, SIGNAL(finishedSearch()), this, SLOT(finishedS()));
86 connect(lineEdit,SIGNAL(returnPressed()),this, SLOT(search()));
87 connect(pushMenu,SIGNAL(triggered(QAction*)),this,SLOT(changeS(QAction*)));
88 connect(dButton,SIGNAL(clicked()),this, SLOT(addSongPlaylist()));
89 connect(stopButton,SIGNAL(clicked()),this,SLOT(stop()));
90 connect(moreButton,SIGNAL(clicked()),this,SLOT(moreB()));
91 //connect(rotator,SIGNAL(orientationChanged(Orientation)),this,SLOT(orientationChanged()));
92 pl = new playlist(this);
94 player->setPlaylist(pl);
95 connect(pl,SIGNAL(downloadProgress(int,qint64,qint64)),this,SLOT(progressUpdate(int,qint64,qint64)));
96 //connect(pl,SIGNAL(bufferReady(int)),pd,SLOT(close()));
97 connect(pl,SIGNAL(freeze(bool)),resultView,SLOT(setDisabled(bool)));
98 connect(pl,SIGNAL(freeze(bool)),pushMenu,SLOT(setDisabled(bool)));
99 connect(pl,SIGNAL(freeze(bool)),dButton,SLOT(setDisabled(bool)));
100 connect(nextB,SIGNAL(clicked()),player,SLOT(playNext()));
101 connect(ok,SIGNAL(changeTask()),this,SLOT(showOthers()));
102 connect(ok,SIGNAL(searchRequest(QString)),this,SLOT(performSearch(QString)));
103 connect(ok,SIGNAL(closeApp()),this,SLOT(close()));
104 connect(bBar,SIGNAL(addB()),this,SLOT(addSongPlaylist()));
105 connect(bBar,SIGNAL(nextB()),player,SLOT(playNext()));
106 connect(bBar,SIGNAL(pause()),this,SLOT(stop()));
107 connect(bBar,SIGNAL(back()),player,SLOT(back()));
108 bBar->setPlaybackProgress(100,100);
111 void groove::performSearch(QString s)
114 resultView->setModel(gs->getSongModel(s));
117 void groove::search()
119 if(!lineEdit->text().isEmpty())
121 if(lineEdit->isEnabled())
124 if(sMethod->text().compare("Song:")==0)
125 resultView->setModel(gs->getSongModel(lineEdit->text()));
126 else if(sMethod->text().compare("Artist:")==0)
127 resultView->setModel(gs->getArtistModel(lineEdit->text()));
128 else if(sMethod->text().compare("Album")==0)
129 resultView->setModel(gs->getAlbumModel(lineEdit->text()));
134 button->setText("Stop");
135 lineEdit->setDisabled(true);
139 resultView->setModel(model);
140 button->setText("Search");
141 resultView->setColumnWidth(0,resultView->viewport()->width()/2);
142 resultView->setColumnWidth(1,resultView->viewport()->width()/2);
143 lineEdit->setDisabled(false);
147 void groove::finishedS()
149 model = gs->getModel();
150 resultView->setModel(model);
151 button->setText("Search");
152 resultView->setColumnWidth(0,resultView->viewport()->width()/2);
153 resultView->setColumnWidth(1,resultView->viewport()->width()/2);
154 lineEdit->setDisabled(false);
155 resultView->setColumnHidden(2,true);
157 void groove::changeS( QAction * action)
159 sMethod->setText(action->text());
160 sMethod->setMaximumWidth(sMethod->sizeHint().rwidth());
162 void groove::showOthers()
164 QDBusConnection c = QDBusConnection::sessionBus();
165 QDBusMessage m = QDBusMessage::createSignal("/", "com.nokia.hildon_desktop", "exit_app_view");
171 QModelIndexList selected = resultView->selectionModel()->selectedRows(0);
172 if(!selected.isEmpty())
174 QStandardItem *item = model->item(selected.first().row(),2);
178 player->play(pl->addSong(item));
183 void groove::addSongPlaylist()
185 QModelIndexList selected = resultView->selectionModel()->selectedRows(0);
186 if(!selected.isEmpty())
188 QStandardItem *item = model->item(selected.first().row(),2);
192 if(pl->currentplaying() == -1)
194 player->play(pl->addSong(item));
198 model->item(selected.first().row(),1)->setText("Added to Playlist");;
208 qDebug() << "He pressed the button";
210 void groove::progressUpdate(int p, qint64 d, qint64 t)
212 //if(!pd->isHidden())
214 bBar->setPlaybackProgress(d,t);
218 void groove::orientationChanged()
221 QRect screenGeometry = QApplication::desktop()->screenGeometry();
222 if (screenGeometry.width() > screenGeometry.height())