|
@@ -1,16 +1,36 @@
|
1
|
1
|
#include "mainwindow.h"
|
2
|
2
|
#include "ui_mainwindow.h"
|
3
|
|
-#include <yaml-cpp/yaml.h>
|
|
3
|
+#include <QMenu>
|
4
|
4
|
|
5
|
|
-MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)//, buf(&tmp)
|
|
5
|
+void clearLayout(QLayout *layout)
|
|
6
|
+{
|
|
7
|
+ QLayoutItem *item;
|
|
8
|
+ while((item = layout->takeAt(0))) {
|
|
9
|
+ if (item->layout()) {
|
|
10
|
+ clearLayout(item->layout());
|
|
11
|
+ delete item->layout();
|
|
12
|
+ }
|
|
13
|
+ if (item->widget()) {
|
|
14
|
+ delete item->widget();
|
|
15
|
+ }
|
|
16
|
+ delete item;
|
|
17
|
+ }
|
|
18
|
+}
|
|
19
|
+
|
|
20
|
+MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), nrj(0)
|
6
|
21
|
{
|
7
|
22
|
ui->setupUi(this);
|
|
23
|
+ tray = new QSystemTrayIcon(this);
|
|
24
|
+ QMenu* menu = new QMenu(this);
|
|
25
|
+ menu->addAction("Quit", qApp, SLOT(quit()));
|
|
26
|
+ tray->setContextMenu(menu);
|
|
27
|
+ connect(tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(sysTrayActivated(QSystemTrayIcon::ActivationReason)));
|
8
|
28
|
|
9
|
|
- currentRadio = 0;
|
10
|
|
- nrj = new NRJ(this);
|
11
|
|
- connect(nrj, SIGNAL(setupFinished()), this, SLOT(setupFinished()));
|
12
|
|
- nrj->setupPlayer();
|
|
29
|
+ connect(ui->comboWebRadio, SIGNAL(currentIndexChanged(int)), this, SLOT(setWebRadio(int)));
|
13
|
30
|
|
|
31
|
+ ui->comboWebRadio->addItem("Nostalgie", "nosta");
|
|
32
|
+ ui->comboWebRadio->addItem("NRJ", "nrj");
|
|
33
|
+ ui->comboWebRadio->addItem("Cherie FM", "cfm");
|
14
|
34
|
}
|
15
|
35
|
|
16
|
36
|
MainWindow::~MainWindow()
|
|
@@ -18,6 +38,12 @@ MainWindow::~MainWindow()
|
18
|
38
|
delete ui;
|
19
|
39
|
}
|
20
|
40
|
|
|
41
|
+void MainWindow::MainWindow::closeEvent(QCloseEvent *event)
|
|
42
|
+{
|
|
43
|
+ event->ignore();
|
|
44
|
+ hide();
|
|
45
|
+}
|
|
46
|
+
|
21
|
47
|
void MainWindow::setupFinished()
|
22
|
48
|
{
|
23
|
49
|
int i = 0;
|
|
@@ -45,3 +71,27 @@ void MainWindow::radioChanged(Radio *r)
|
45
|
71
|
currentRadio->startStream();
|
46
|
72
|
}
|
47
|
73
|
}
|
|
74
|
+
|
|
75
|
+void MainWindow::setWebRadio(int i)
|
|
76
|
+{
|
|
77
|
+ QString radio = ui->comboWebRadio->itemData(i).toString();
|
|
78
|
+ tray->setIcon(QIcon(":/" + radio + ".ico"));
|
|
79
|
+ tray->show();
|
|
80
|
+ clearLayout(ui->layRadios);
|
|
81
|
+ if (nrj)
|
|
82
|
+ {
|
|
83
|
+ nrj->disconnect();
|
|
84
|
+ nrj->deleteLater();
|
|
85
|
+ }
|
|
86
|
+ currentRadio = 0;
|
|
87
|
+ nrj = new NRJ(this);
|
|
88
|
+ connect(nrj, SIGNAL(setupFinished()), this, SLOT(setupFinished()));
|
|
89
|
+ nrj->setRadio(radio);
|
|
90
|
+ nrj->setupPlayer();
|
|
91
|
+}
|
|
92
|
+
|
|
93
|
+void MainWindow::sysTrayActivated(QSystemTrayIcon::ActivationReason r)
|
|
94
|
+{
|
|
95
|
+ if (r == QSystemTrayIcon::DoubleClick)
|
|
96
|
+ setVisible(!isVisible());
|
|
97
|
+}
|