2 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
3 #include "qmaemo5rotator.h"
8 groove::groove(QWidget *parent) :
11 mBar = new QMenuBar();
12 //mBar->addAction("test");
13 sMethod = new QPushButton("Song:");
14 lineEdit = new QLineEdit("");
15 player = new sPlayer();
16 QHBoxLayout *layout = new QHBoxLayout();
17 QVBoxLayout *vlayout = new QVBoxLayout();
18 QHBoxLayout *bottomLayout = new QHBoxLayout();
19 button = new QPushButton("Search");
20 QPushButton *dButton = new QPushButton("Queue");
21 QPushButton *stopButton = new QPushButton("Pause");
22 QPushButton *moreButton = new QPushButton("...");
23 QPushButton *nextB = new QPushButton("->");
24 topBar *ok = new topBar(this);
25 resultView = new QTableView();
26 QMenu *pushMenu = new QMenu();
29 lineEdit->setDisabled(true);
30 pushMenu->addAction("Song:");
31 //pushMenu->addAction("Artist:");
32 //pushMenu->addAction("Album:");
33 pd = new grooveProgressBar(this);
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 /*QPalette pal = resultView->palette();
58 pal.setBrush(QPalette::Highlight,QBrush(Qt::transparent,Qt::NoBrush));
59 resultView->setPalette(pal);*/
61 layout->addWidget(sMethod);
62 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
63 rot = new QMaemo5Rotator(QMaemo5Rotator::AutomaticBehavior,this);
65 //this->setAttribute(Qt::WA_Maemo5AutoOrientation);
66 layout->addWidget(lineEdit);
67 layout->addWidget(button);
68 vlayout->addWidget(ok);
69 //vlayout->addLayout(layout);
70 vlayout->addWidget(resultView);
71 //vlayout->addLayout(bottomLayout);
72 bottomBar *bBar = new bottomBar();
73 vlayout->addWidget(bBar);
74 vlayout->setSpacing(0);
75 bottomLayout->addWidget(dButton);
76 bottomLayout->addWidget(stopButton);
77 bottomLayout->addWidget(nextB);
78 bottomLayout->addWidget(moreButton);
79 vlayout->setMenuBar(mBar);
80 vlayout->setContentsMargins(QMargins());
82 setWindowTitle("Groove");
83 //Create New Grooveshark connection
86 connect(button, SIGNAL(clicked()), this, SLOT(search()));
87 connect(gs, SIGNAL(finishedSearch()), this, SLOT(finishedS()));
88 connect(lineEdit,SIGNAL(returnPressed()),this, SLOT(search()));
89 connect(pushMenu,SIGNAL(triggered(QAction*)),this,SLOT(changeS(QAction*)));
90 connect(dButton,SIGNAL(clicked()),this, SLOT(addSongPlaylist()));
91 connect(stopButton,SIGNAL(clicked()),this,SLOT(stop()));
92 connect(moreButton,SIGNAL(clicked()),this,SLOT(moreB()));
93 //connect(rotator,SIGNAL(orientationChanged(Orientation)),this,SLOT(orientationChanged()));
96 player->setPlaylist(pl);
97 connect(pl,SIGNAL(downloadProgress(int,qint64,qint64)),this,SLOT(progressUpdate(int,qint64,qint64)));
98 connect(pl,SIGNAL(bufferReady(int)),pd,SLOT(close()));
99 connect(pl,SIGNAL(freeze(bool)),resultView,SLOT(setDisabled(bool)));
100 connect(pl,SIGNAL(freeze(bool)),pushMenu,SLOT(setDisabled(bool)));
101 connect(pl,SIGNAL(freeze(bool)),dButton,SLOT(setDisabled(bool)));
102 connect(nextB,SIGNAL(clicked()),player,SLOT(playNext()));
103 connect(ok,SIGNAL(changeTask()),this,SLOT(showOthers()));
104 connect(ok,SIGNAL(searchRequest(QString)),this,SLOT(performSearch(QString)));
105 connect(ok,SIGNAL(closeApp()),this,SLOT(close()));
106 connect(bBar,SIGNAL(addB()),this,SLOT(addSongPlaylist()));
108 void groove::performSearch(QString s)
111 resultView->setModel(gs->getSongModel(s));
114 void groove::search()
116 if(!lineEdit->text().isEmpty())
118 if(lineEdit->isEnabled())
121 if(sMethod->text().compare("Song:")==0)
122 resultView->setModel(gs->getSongModel(lineEdit->text()));
123 else if(sMethod->text().compare("Artist:")==0)
124 resultView->setModel(gs->getArtistModel(lineEdit->text()));
125 else if(sMethod->text().compare("Album")==0)
126 resultView->setModel(gs->getAlbumModel(lineEdit->text()));
131 button->setText("Stop");
132 lineEdit->setDisabled(true);
136 resultView->setModel(model);
137 button->setText("Search");
138 resultView->setColumnWidth(0,resultView->viewport()->width()/2);
139 resultView->setColumnWidth(1,resultView->viewport()->width()/2);
140 lineEdit->setDisabled(false);
144 void groove::finishedS()
146 model = gs->getModel();
147 resultView->setModel(model);
148 button->setText("Search");
149 resultView->setColumnWidth(0,resultView->viewport()->width()/2);
150 resultView->setColumnWidth(1,resultView->viewport()->width()/2);
151 lineEdit->setDisabled(false);
152 resultView->setColumnHidden(2,true);
154 void groove::changeS( QAction * action)
156 sMethod->setText(action->text());
157 sMethod->setMaximumWidth(sMethod->sizeHint().rwidth());
159 void groove::showOthers()
161 QDBusConnection c = QDBusConnection::sessionBus();
162 QDBusMessage m = QDBusMessage::createSignal("/", "com.nokia.hildon_desktop", "exit_app_view");
168 QModelIndexList selected = resultView->selectionModel()->selectedRows(0);
169 if(!selected.isEmpty())
171 QStandardItem *item = model->item(selected.first().row(),2);
175 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));
201 model->item(selected.first().row(),1)->setText("Added to Playlist");;
211 qDebug() << "He pressed the button";
213 void groove::progressUpdate(int p, qint64 d, qint64 t)
215 //if(!pd->isHidden())
224 void groove::orientationChanged()
227 QRect screenGeometry = QApplication::desktop()->screenGeometry();
228 if (screenGeometry.width() > screenGeometry.height())