Browse Source

system tray

master
Robin Thoni 9 years ago
parent
commit
6d7cc286c1
4 changed files with 69 additions and 26 deletions
  1. BIN
      favicon.ico
  2. 56
    6
      mainwindow.cpp
  3. 7
    1
      mainwindow.h
  4. 6
    19
      mainwindow.ui

BIN
favicon.ico View File


+ 56
- 6
mainwindow.cpp View File

1
 #include "mainwindow.h"
1
 #include "mainwindow.h"
2
 #include "ui_mainwindow.h"
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
     ui->setupUi(this);
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
 MainWindow::~MainWindow()
36
 MainWindow::~MainWindow()
18
     delete ui;
38
     delete ui;
19
 }
39
 }
20
 
40
 
41
+void MainWindow::MainWindow::closeEvent(QCloseEvent *event)
42
+{
43
+    event->ignore();
44
+    hide();
45
+}
46
+
21
 void MainWindow::setupFinished()
47
 void MainWindow::setupFinished()
22
 {
48
 {
23
     int i = 0;
49
     int i = 0;
45
         currentRadio->startStream();
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
+}

+ 7
- 1
mainwindow.h View File

7
 #include "radiowidget.h"
7
 #include "radiowidget.h"
8
 #include "radio.h"
8
 #include "radio.h"
9
 #include <QDebug>
9
 #include <QDebug>
10
-#include <QAudioOutput>
10
+#include <QSystemTrayIcon>
11
 
11
 
12
 namespace Ui {
12
 namespace Ui {
13
 class MainWindow;
13
 class MainWindow;
21
     explicit MainWindow(QWidget *parent = 0);
21
     explicit MainWindow(QWidget *parent = 0);
22
     ~MainWindow();
22
     ~MainWindow();
23
 
23
 
24
+protected:
25
+    void closeEvent(QCloseEvent *event);
26
+
24
 private slots:
27
 private slots:
25
     void setupFinished();
28
     void setupFinished();
26
     void radioChanged(Radio* r);
29
     void radioChanged(Radio* r);
30
+    void setWebRadio(int i);
31
+    void sysTrayActivated(QSystemTrayIcon::ActivationReason r);
27
 
32
 
28
 private:
33
 private:
29
     Ui::MainWindow *ui;
34
     Ui::MainWindow *ui;
30
     NRJ* nrj;
35
     NRJ* nrj;
31
     Radio* currentRadio;
36
     Radio* currentRadio;
37
+    QSystemTrayIcon* tray;
32
 
38
 
33
 };
39
 };
34
 
40
 

+ 6
- 19
mainwindow.ui View File

11
    </rect>
11
    </rect>
12
   </property>
12
   </property>
13
   <property name="windowTitle">
13
   <property name="windowTitle">
14
-   <string>NRJ</string>
15
-  </property>
16
-  <property name="windowIcon">
17
-   <iconset resource="rc.qrc">
18
-    <normaloff>:/favicon.ico</normaloff>:/favicon.ico</iconset>
14
+   <string>Web Radio</string>
19
   </property>
15
   </property>
20
   <widget class="QWidget" name="centralWidget">
16
   <widget class="QWidget" name="centralWidget">
21
    <layout class="QGridLayout" name="gridLayout">
17
    <layout class="QGridLayout" name="gridLayout">
35
         <rect>
31
         <rect>
36
          <x>0</x>
32
          <x>0</x>
37
          <y>0</y>
33
          <y>0</y>
38
-         <width>605</width>
39
-         <height>299</height>
34
+         <width>624</width>
35
+         <height>268</height>
40
         </rect>
36
         </rect>
41
        </property>
37
        </property>
42
        <layout class="QGridLayout" name="layRadios">
38
        <layout class="QGridLayout" name="layRadios">
47
       </widget>
43
       </widget>
48
      </widget>
44
      </widget>
49
     </item>
45
     </item>
50
-    <item row="0" column="1">
51
-     <widget class="QFrame" name="radioFrame">
52
-      <property name="frameShape">
53
-       <enum>QFrame::StyledPanel</enum>
54
-      </property>
55
-      <property name="frameShadow">
56
-       <enum>QFrame::Raised</enum>
57
-      </property>
58
-     </widget>
46
+    <item row="1" column="0">
47
+     <widget class="QComboBox" name="comboWebRadio"/>
59
     </item>
48
     </item>
60
    </layout>
49
    </layout>
61
   </widget>
50
   </widget>
70
    <container>1</container>
59
    <container>1</container>
71
   </customwidget>
60
   </customwidget>
72
  </customwidgets>
61
  </customwidgets>
73
- <resources>
74
-  <include location="rc.qrc"/>
75
- </resources>
62
+ <resources/>
76
  <connections/>
63
  <connections/>
77
 </ui>
64
 </ui>

Loading…
Cancel
Save