12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QMenu>
-
- void clearLayout(QLayout *layout)
- {
- QLayoutItem *item;
- while((item = layout->takeAt(0))) {
- if (item->layout()) {
- clearLayout(item->layout());
- delete item->layout();
- }
- if (item->widget()) {
- delete item->widget();
- }
- delete item;
- }
- }
-
- MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), nrj(0)
- {
- ui->setupUi(this);
- tray = new QSystemTrayIcon(this);
- QMenu* menu = new QMenu(this);
- menu->addAction("Quit", qApp, SLOT(quit()));
- tray->setContextMenu(menu);
- connect(tray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(sysTrayActivated(QSystemTrayIcon::ActivationReason)));
-
- connect(ui->comboWebRadio, SIGNAL(currentIndexChanged(int)), this, SLOT(setWebRadio(int)));
-
- ui->comboWebRadio->addItem("Nostalgie", "nosta");
- ui->comboWebRadio->addItem("NRJ", "nrj");
- ui->comboWebRadio->addItem("Cherie FM", "cfm");
- }
-
- MainWindow::~MainWindow()
- {
- delete ui;
- }
-
- void MainWindow::MainWindow::closeEvent(QCloseEvent *event)
- {
- event->ignore();
- hide();
- }
-
- void MainWindow::setupFinished()
- {
- int i = 0;
- foreach(Radio* r, nrj->getRadios())
- {
- RadioWidget* w = new RadioWidget();
- ui->layRadios->addWidget(w, i / 2, i % 2);
- connect(w, SIGNAL(clicked(Radio*)), this, SLOT(radioChanged(Radio*)));
- w->setRadio(r);
- ++i;
- }
- nrj->getAllCur();
- }
-
- void MainWindow::radioChanged(Radio *r)
- {
- if(currentRadio != 0)
- {
- currentRadio->stopStream();
- currentRadio->disconnect(this);
- }
- currentRadio = r;
- if(currentRadio != 0)
- {
- currentRadio->startStream();
- }
- }
-
- void MainWindow::setWebRadio(int i)
- {
- QString radio = ui->comboWebRadio->itemData(i).toString();
- tray->setIcon(QIcon(":/" + radio + ".ico"));
- tray->show();
- clearLayout(ui->layRadios);
- if (nrj)
- {
- nrj->disconnect();
- nrj->deleteLater();
- }
- currentRadio = 0;
- nrj = new NRJ(this);
- connect(nrj, SIGNAL(setupFinished()), this, SLOT(setupFinished()));
- nrj->setRadio(radio);
- nrj->setupPlayer();
- }
-
- void MainWindow::sysTrayActivated(QSystemTrayIcon::ActivationReason r)
- {
- if (r == QSystemTrayIcon::DoubleClick)
- setVisible(!isVisible());
- }
|