1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
//===========================================
// Lumina-Desktop source code
// Copyright (c) 2017, Ken Moore
// Available under the 3-clause BSD license
// See the LICENSE file for full details
//===========================================
#include "mainUI.h"
#include "ui_mainUI.h"
#include <QDebug>
#include <LuminaXDG.h>
#include <QDesktopServices>
#include <QUrl>
MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI()){
ui->setupUi(this);
closing = false;
//Any special UI changes
QWidget *spacer = new QWidget(this);
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
ui->toolBar->insertWidget(ui->actionVolUp, spacer);
//Setup an action group for the various modes/streams
QButtonGroup *grp = new QButtonGroup(this);
grp->addButton(ui->radio_local);
grp->addButton(ui->radio_pandora);
grp->setExclusive(true);
setupPandora();
ui->radio_pandora->setChecked(true);
setupTrayIcon();
setupConnections();
setupIcons();
PlayerTypeChanged();
SYSTRAY->show();
}
MainUI::~MainUI(){
}
void MainUI::loadArguments(QStringList){
}
// ==== PRIVATE ====
void MainUI::setupPandora(){
PANDORA = new PianoBarProcess(this);
connect(PANDORA, SIGNAL(currentStateChanged(PianoBarProcess::State)), this, SLOT(PandoraStateChanged(PianoBarProcess::State)) );
connect(PANDORA, SIGNAL(NewInformation(QString)), this, SLOT(NewPandoraInfo(QString)) );
connect(PANDORA, SIGNAL(NowPlayingStation(QString, QString)), this, SLOT(PandoraStationChanged(QString)) );
connect(PANDORA, SIGNAL(NowPlayingSong(bool, QString,QString,QString, QString, QString)), this, SLOT(PandoraSongChanged(bool, QString, QString, QString, QString, QString)) );
connect(PANDORA, SIGNAL(TimeUpdate(int, int)), this, SLOT(PandoraTimeUpdate(int,int)) );
connect(PANDORA, SIGNAL(NewList(QStringList)), this, SLOT(PandoraListInfo(QStringList)) );
connect(PANDORA, SIGNAL(StationListChanged(QStringList)), this, SLOT(PandoraStationListChanged(QStringList)) );
//Setup a couple of the option lists
ui->combo_pandora_quality->clear();
ui->combo_pandora_quality->addItem(tr("Low"),"low");
ui->combo_pandora_quality->addItem(tr("Medium"), "medium");
ui->combo_pandora_quality->addItem(tr("High"),"high");
//Now load the current settings into the UI
int qual = ui->combo_pandora_quality->findData(PANDORA->audioQuality());
if(qual>=0){ ui->combo_pandora_quality->setCurrentIndex(qual); }
else{ ui->combo_pandora_quality->setCurrentIndex(1); } //medium quality by default
ui->line_pandora_email->setText( PANDORA->email() );
ui->line_pandora_pass->setText( PANDORA->password() );
ui->line_pandora_proxy->setText( PANDORA->proxy() );
ui->line_pandora_cproxy->setText( PANDORA->controlProxy() );
//Make sure the interface is enabled/disabled as needed
PandoraStateChanged(PANDORA->currentState());
ui->progress_pandora->setRange(0,1);
ui->progress_pandora->setValue(0);
//Setup the menu for new stations
QMenu *tmp = new QMenu(this);
tmp->addAction(ui->action_pandora_newstation_song);
tmp->addAction(ui->action_pandora_newstation_artist);
ui->tool_pandora_stationadd->setMenu( tmp );
}
void MainUI::setupConnections(){
connect(ui->radio_local, SIGNAL(toggled(bool)), this, SLOT(PlayerTypeChanged(bool)) );
connect(ui->radio_pandora, SIGNAL(toggled(bool)), this, SLOT(PlayerTypeChanged(bool)) );
connect(ui->actionPlay, SIGNAL(triggered()), this, SLOT(playToggled()) );
connect(ui->actionPause, SIGNAL(triggered()), this, SLOT(pauseToggled()) );
connect(ui->actionStop, SIGNAL(triggered()), this, SLOT(stopToggled()) );
connect(ui->actionNext, SIGNAL(triggered()), this, SLOT(nextToggled()) );
connect(ui->actionBack, SIGNAL(triggered()), this, SLOT(backToggled()) );
connect(ui->actionVolUp, SIGNAL(triggered()), this, SLOT(volupToggled()) );
connect(ui->actionVolDown, SIGNAL(triggered()), this, SLOT(voldownToggled()) );
connect(ui->actionClose, SIGNAL(triggered()), this, SLOT(closeApplication()) );
connect(ui->push_pandora_apply, SIGNAL(clicked()), this, SLOT(applyPandoraSettings()) );
connect(ui->combo_pandora_station, SIGNAL(activated(QString)), this, SLOT(changePandoraStation(QString)) );
connect(ui->tool_pandora_ban, SIGNAL(clicked()), PANDORA, SLOT(banSong()) );
connect(ui->tool_pandora_love, SIGNAL(clicked()), PANDORA, SLOT(loveSong()) );
connect(ui->tool_pandora_tired, SIGNAL(clicked()), PANDORA, SLOT(tiredSong()) );
connect(ui->tool_pandora_info, SIGNAL(clicked()), this, SLOT(showPandoraSongInfo()) );
connect(ui->tool_pandora_stationrm, SIGNAL(clicked()), PANDORA, SLOT(deleteCurrentStation()) );
connect(ui->action_pandora_newstation_artist, SIGNAL(triggered()), PANDORA, SLOT(createStationFromCurrentArtist()) );
connect(ui->action_pandora_newstation_song, SIGNAL(triggered()), PANDORA, SLOT(createStationFromCurrentSong()) );
connect(SYSTRAY, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(trayClicked(QSystemTrayIcon::ActivationReason)) );
connect(SYSTRAY, SIGNAL(messageClicked()), this, SLOT(showNormal()) );
}
void MainUI::setupIcons(){
ui->actionClose->setIcon( LXDG::findIcon("application-close","dialog-close") );
ui->actionPlay->setIcon( LXDG::findIcon("media-playback-start","") );
ui->actionPause->setIcon( LXDG::findIcon("media-playback-pause","") );
ui->actionStop->setIcon( LXDG::findIcon("media-playback-stop","") );
ui->actionNext->setIcon( LXDG::findIcon("media-skip-forward","") );
ui->actionBack->setIcon( LXDG::findIcon("media-skip-backward","") );
//Pandora Pages
ui->push_pandora_apply->setIcon( LXDG::findIcon("dialog-ok-apply","dialog-ok") );
ui->tool_pandora_ban->setIcon( LXDG::findIcon("dialog-cancel","") );
ui->tool_pandora_info->setIcon( LXDG::findIcon("help-about","") );
ui->tool_pandora_love->setIcon( LXDG::findIcon("emblem-favorite","") );
ui->tool_pandora_tired->setIcon( LXDG::findIcon("flag-yellow","flag") );
ui->tool_pandora_stationrm->setIcon( LXDG::findIcon("list-remove","") );
ui->tool_pandora_stationadd->setIcon( LXDG::findIcon("list-add","") );
ui->action_pandora_newstation_artist->setIcon( LXDG::findIcon("list-add-user","") );
ui->action_pandora_newstation_song->setIcon( LXDG::findIcon("audio-x-generic","") );
}
void MainUI::setupTrayIcon(){
SYSTRAY = new QSystemTrayIcon(this);
QMenu *tmp = new QMenu(this);
SYSTRAY->setContextMenu(tmp);
tmp->addAction(ui->actionPlay);
tmp->addAction(ui->actionPause);
tmp->addAction(ui->actionStop);
tmp->addAction(ui->actionBack);
tmp->addAction(ui->actionNext);
tmp->addSeparator();
tmp->addAction(ui->actionClose);
}
void MainUI::closeTrayIcon(){
}
// ==== PRIVATE SLOTS ====
void MainUI::closeApplication(){
closing = true;
if(PANDORA->currentState()!= PianoBarProcess::Stopped){
PANDORA->closePianoBar();
this->hide();
QTimer::singleShot(500, this, SLOT(close()) );
}else{
this->close();
}
}
void MainUI::PlayerTypeChanged(bool active){
if(!active){ return; } //this gets rid of the "extra" signals from the radio button functionality (1 signal from each button on change)
if(ui->radio_pandora->isChecked()){
ui->stackedWidget->setCurrentWidget(ui->page_pandora);
PandoraStateChanged(PANDORA->currentState());
SYSTRAY->setIcon( QIcon(":pandora") );
this->setWindowIcon( QIcon(":pandora") );
this->setWindowTitle( tr("Pandora Radio") );
}else{
ui->stackedWidget->setCurrentWidget(ui->page_local);
SYSTRAY->setIcon( LXDG::findIcon("audio-x-generic","") );
this->setWindowIcon( LXDG::findIcon("audio-x-generic","") );
this->setWindowTitle( tr("Media Player") );
}
//Now close down any currently running streams as needed
if(!ui->radio_pandora->isChecked() && PANDORA->currentState()!=PianoBarProcess::Stopped){ PANDORA->closePianoBar(); }
//Now hide/deactivate any toolbar buttons which are not used
ui->actionBack->setVisible(!ui->radio_pandora->isChecked());
}
//Toolbar actions
void MainUI::playToggled(){
if(ui->radio_pandora->isChecked()){
PANDORA->play();
}
}
void MainUI::pauseToggled(){
if(ui->radio_pandora->isChecked()){
PANDORA->pause();
}
}
void MainUI::stopToggled(){
if(ui->radio_pandora->isChecked()){
PANDORA->closePianoBar();
}
}
void MainUI::nextToggled(){
if(ui->radio_pandora->isChecked()){
PANDORA->skipSong();
}
}
void MainUI::backToggled(){
}
void MainUI::volupToggled(){
}
void MainUI::voldownToggled(){
}
//Pandora Options
void MainUI::showPandoraSongInfo(){
QDesktopServices::openUrl( QUrl(ui->tool_pandora_info->whatsThis()) );
}
void MainUI::changePandoraStation(QString station){
if(station == PANDORA->currentStation()){ return; }
qDebug() << "[CHANGE STATION]" << station << "from:" << PANDORA->currentStation();
PANDORA->setCurrentStation(station);
}
void MainUI::applyPandoraSettings(){
PANDORA->setLogin(ui->line_pandora_email->text(), ui->line_pandora_pass->text());
PANDORA->setAudioQuality(ui->combo_pandora_quality->currentData().toString());
PANDORA->setProxy(ui->line_pandora_proxy->text());
PANDORA->setControlProxy(ui->line_pandora_cproxy->text());
}
//Pandora Process Feedback
void MainUI::PandoraStateChanged(PianoBarProcess::State state){
//qDebug() << "[STATE CHANGE]" << state;
ui->actionPlay->setVisible(state != PianoBarProcess::Running);
ui->actionPause->setVisible(state == PianoBarProcess::Running);
ui->actionStop->setVisible(state != PianoBarProcess::Stopped);
ui->actionBack->setVisible(false); //never available for Pandora streams
ui->actionNext->setVisible(state!=PianoBarProcess::Stopped);
ui->tabWidget_pandora->setTabEnabled(0, state !=PianoBarProcess::Stopped);
if(!ui->tabWidget_pandora->isTabEnabled(0) && ui->tabWidget_pandora->currentIndex()==0){
ui->tabWidget_pandora->setCurrentWidget(ui->tab_pandora_settings);
}else if(state == PianoBarProcess::Running){
ui->tabWidget_pandora->setCurrentWidget(ui->tab_pandora_playing);
}
}
void MainUI::NewPandoraInfo(QString info){
//qDebug() << "[INFO]" << info;
ui->statusbar->showMessage(info, 2000);
}
void MainUI::PandoraStationChanged(QString station){
qDebug() << "[STATION CHANGE]" << station;
int index = ui->combo_pandora_station->findText( station );
if(index>=0){
qDebug() <<" [FOUND]" << ui->combo_pandora_station->itemText(index);
ui->combo_pandora_station->setCurrentIndex(index);
}else{
//Could not find the station in the current list - need to update that first
qDebug() <<" [NOT FOUND]";
PandoraStationListChanged(PANDORA->stations());
}
}
void MainUI::PandoraSongChanged(bool isLoved, QString title, QString artist, QString album, QString detailsURL, QString fromStation){
//qDebug() << "[SONG CHANGE]" << isLoved << title << artist << album << detailsURL << fromStation;
ui->tool_pandora_info->setWhatsThis(detailsURL);
ui->tool_pandora_love->setChecked(isLoved);
ui->tool_pandora_love->setEnabled(!isLoved); //pianobar cannot "unlove" a song
ui->label_pandora_album->setText(album);
ui->label_pandora_artist->setText(artist);
ui->label_pandora_title->setText(title);
ui->progress_pandora->setRange(0,1);
ui->progress_pandora->setValue(0);
ui->progress_pandora->setFormat("");
if(ui->action_showNotifications->isChecked()){
QString msg = QString(tr("%1\nBy %2 on %3")).arg(title, artist, album);
SYSTRAY->showMessage(tr("Now Playing"), msg, QSystemTrayIcon::NoIcon, 1500); //1.5 seconds
}
}
void MainUI::PandoraTimeUpdate(int curS, int totS){
//qDebug() << "[TIME UPDATE]" << curS << "/" << totS;
ui->progress_pandora->setRange(0, totS);
ui->progress_pandora->setValue(curS);
QString time = QTime(0, curS/60, curS%60,0).toString("m:ss") + "/" + QTime(0, totS/60, totS%60,0).toString("m:ss");
ui->progress_pandora->setFormat(time);
}
void MainUI::PandoraStationListChanged(QStringList list){
qDebug() << "[STATION LIST]" << list;
ui->combo_pandora_station->clear();
if(list.isEmpty()){ return; }
ui->combo_pandora_station->addItems(list);
int index = ui->combo_pandora_station->findText( PANDORA->currentStation() );
qDebug() << "[CURRENT STATION]" << PANDORA->currentStation() << index;
if(index>=0){ ui->combo_pandora_station->setCurrentIndex(index); }
}
void MainUI::PandoraListInfo(QStringList list){
qDebug() << "[LIST INFO]" << list;
}
//System Tray interactions
void MainUI::toggleVisibility(){
if(this->isVisible()){ this->hide(); }
else{ this->showNormal(); }
}
void MainUI::trayClicked(QSystemTrayIcon::ActivationReason rsn){
if(rsn == QSystemTrayIcon::Context){
SYSTRAY->contextMenu()->popup(QCursor::pos());
}else{
toggleVisibility();
}
}
void MainUI::closeEvent(QCloseEvent *ev){
if(!closing){
//Check if we have audio playing to determine if we should just minimize instead
if(ui->action_closeToTray->isChecked()){
closing = (PANDORA->currentState()!=PianoBarProcess::Running);
}else if(PANDORA->currentState()!=PianoBarProcess::Stopped){
//Make sure we close the stream down first
PANDORA->closePianoBar();
QTimer::singleShot(500, this, SLOT(close()) ); //try again in a moment
}else{
closing = true;
}
}
if(closing){ QMainWindow::closeEvent(ev); } //normal close procedure
else{
ev->ignore();
this->hide();
}
}
|