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 QTabWidget *tab = new QTabWidget();
72 tab->addTab(resultView,"Search Results");
74 vlayout->addWidget(tab);
75 //vlayout->addLayout(bottomLayout);
76 bBar = new bottomBar();
77 vlayout->addWidget(bBar);
78 vlayout->setSpacing(0);
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 tab->addTab(pwindow,"Playlist");
120 void groove::performSearch(QString s)
123 resultView->setModel(gs->getSongModel(s));
126 void groove::search()
128 if(!lineEdit->text().isEmpty())
130 if(lineEdit->isEnabled())
133 if(sMethod->text().compare("Song:")==0)
134 resultView->setModel(gs->getSongModel(lineEdit->text()));
135 else if(sMethod->text().compare("Artist:")==0)
136 resultView->setModel(gs->getArtistModel(lineEdit->text()));
137 else if(sMethod->text().compare("Album")==0)
138 resultView->setModel(gs->getAlbumModel(lineEdit->text()));
143 button->setText("Stop");
144 lineEdit->setDisabled(true);
148 resultView->setModel(model);
149 button->setText("Search");
150 resultView->setColumnWidth(0,resultView->viewport()->width()/2);
151 resultView->setColumnWidth(1,resultView->viewport()->width()/2);
152 lineEdit->setDisabled(false);
156 void groove::finishedS()
158 model = gs->getModel();
159 resultView->setModel(model);
160 button->setText("Search");
161 resultView->setColumnWidth(0,resultView->viewport()->width()/2);
162 resultView->setColumnWidth(1,resultView->viewport()->width()/2);
163 lineEdit->setDisabled(false);
164 resultView->setColumnHidden(2,true);
166 void groove::changeS( QAction * action)
168 sMethod->setText(action->text());
169 sMethod->setMaximumWidth(sMethod->sizeHint().rwidth());
172 void groove::showOthers()
174 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
175 QDBusConnection c = QDBusConnection::sessionBus();
176 QDBusMessage m = QDBusMessage::createSignal("/", "com.nokia.hildon_desktop", "exit_app_view");
184 QModelIndexList selected = resultView->selectionModel()->selectedRows(0);
185 if(!selected.isEmpty())
187 QStandardItem *item = model->item(selected.first().row(),2);
191 player->play(pl->addSong(item));
196 void groove::addSongPlaylist()
198 QModelIndexList selected = resultView->selectionModel()->selectedRows(0);
199 if(!selected.isEmpty())
201 QStandardItem *item = model->item(selected.first().row(),2);
205 if(pl->currentplaying() == -1)
207 player->play(pl->addSong(item));
211 model->item(selected.first().row(),1)->setText("Added to Playlist");;
212 pwindow->addSong(model->item(selected.first().row(),0)->text());
224 qDebug() << "He pressed the button";
226 void groove::progressUpdate(int p, qint64 d, qint64 t)
228 //if(!pd->isHidden())
230 bBar->setPlaybackProgress(d,t);
234 void groove::orientationChanged()
237 QRect screenGeometry = QApplication::desktop()->screenGeometry();
238 if (screenGeometry.width() > screenGeometry.height())