Browse Source

system tray

master
Robin Thoni 8 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,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
+}

+ 7
- 1
mainwindow.h View File

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

+ 6
- 19
mainwindow.ui View File

@@ -11,11 +11,7 @@
11 11
    </rect>
12 12
   </property>
13 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 15
   </property>
20 16
   <widget class="QWidget" name="centralWidget">
21 17
    <layout class="QGridLayout" name="gridLayout">
@@ -35,8 +31,8 @@
35 31
         <rect>
36 32
          <x>0</x>
37 33
          <y>0</y>
38
-         <width>605</width>
39
-         <height>299</height>
34
+         <width>624</width>
35
+         <height>268</height>
40 36
         </rect>
41 37
        </property>
42 38
        <layout class="QGridLayout" name="layRadios">
@@ -47,15 +43,8 @@
47 43
       </widget>
48 44
      </widget>
49 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 48
     </item>
60 49
    </layout>
61 50
   </widget>
@@ -70,8 +59,6 @@
70 59
    <container>1</container>
71 60
   </customwidget>
72 61
  </customwidgets>
73
- <resources>
74
-  <include location="rc.qrc"/>
75
- </resources>
62
+ <resources/>
76 63
  <connections/>
77 64
 </ui>

Loading…
Cancel
Save