WebRadioDialog now stores last used radio station in config
This commit is contained in:
@@ -1,16 +1,22 @@
|
|||||||
#include "webradiodialog.h"
|
#include "webradiodialog.h"
|
||||||
#include "ui_webradiodialog.h"
|
#include "ui_webradiodialog.h"
|
||||||
|
|
||||||
#include <QMediaPlayer>
|
#include "mainwindow.h"
|
||||||
|
#include "zeiterfassungsettings.h"
|
||||||
|
|
||||||
WebRadioDialog::WebRadioDialog(QWidget *parent) :
|
WebRadioDialog::WebRadioDialog(MainWindow &mainWindow) :
|
||||||
QDialog(parent),
|
QDialog(&mainWindow),
|
||||||
ui(new Ui::WebRadioDialog),
|
ui(new Ui::WebRadioDialog),
|
||||||
|
m_mainWindow(mainWindow),
|
||||||
m_player(new QMediaPlayer(this))
|
m_player(new QMediaPlayer(this))
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
for(const auto &url : QStringList {
|
connect(m_player, &QMediaPlayer::stateChanged, this, &WebRadioDialog::stateChanged);
|
||||||
|
connect(m_player, &QMediaPlayer::mediaStatusChanged, this, &WebRadioDialog::mediaStatusChanged);
|
||||||
|
connect(m_player, static_cast<void(QMediaPlayer::*)(QMediaPlayer::Error)>(&QMediaPlayer::error), this, &WebRadioDialog::error);
|
||||||
|
|
||||||
|
for(const auto &url : m_mainWindow.settings().value(QStringLiteral("WebRadioPlugin/urls"), QStringList {
|
||||||
QStringLiteral("http://stream.drumandbass.fm:9002"),
|
QStringLiteral("http://stream.drumandbass.fm:9002"),
|
||||||
QStringLiteral("http://stream.trap.fm:6002"),
|
QStringLiteral("http://stream.trap.fm:6002"),
|
||||||
QStringLiteral("http://stream.dubbase.fm:7002"),
|
QStringLiteral("http://stream.dubbase.fm:7002"),
|
||||||
@@ -22,27 +28,24 @@ WebRadioDialog::WebRadioDialog(QWidget *parent) :
|
|||||||
QStringLiteral("http://lw1.mp3.tb-group.fm/ct.mp3"),
|
QStringLiteral("http://lw1.mp3.tb-group.fm/ct.mp3"),
|
||||||
QStringLiteral("http://lw1.mp3.tb-group.fm/clt.mp3"),
|
QStringLiteral("http://lw1.mp3.tb-group.fm/clt.mp3"),
|
||||||
QStringLiteral("https://live.helsinki.at:8088/live160.ogg")
|
QStringLiteral("https://live.helsinki.at:8088/live160.ogg")
|
||||||
})
|
}).toStringList())
|
||||||
{
|
{
|
||||||
ui->comboBox->addItem(url);
|
ui->comboBox->addItem(url, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(ui->comboBox, &QComboBox::currentTextChanged, this, [=](const QString &url){ m_player->setMedia(QMediaContent(QUrl(url))); });
|
auto lastUrl = m_mainWindow.settings().value(QStringLiteral("WebRadioPlugin/lastUrl")).toString();
|
||||||
|
qDebug() << lastUrl;
|
||||||
|
auto index = ui->comboBox->findData(lastUrl);
|
||||||
|
qDebug() << index;
|
||||||
|
ui->comboBox->setCurrentIndex(index);
|
||||||
|
|
||||||
Q_EMIT ui->comboBox->currentTextChanged(ui->comboBox->currentText());
|
connect(ui->pushButtonPlay, &QAbstractButton::pressed, this, &WebRadioDialog::play);
|
||||||
|
|
||||||
connect(ui->pushButtonPlay, &QAbstractButton::pressed, m_player, &QMediaPlayer::play);
|
|
||||||
connect(ui->pushButtonPause, &QAbstractButton::pressed, m_player, &QMediaPlayer::pause);
|
connect(ui->pushButtonPause, &QAbstractButton::pressed, m_player, &QMediaPlayer::pause);
|
||||||
connect(ui->pushButtonStop, &QAbstractButton::pressed, m_player, &QMediaPlayer::stop);
|
connect(ui->pushButtonStop, &QAbstractButton::pressed, m_player, &QMediaPlayer::stop);
|
||||||
connect(ui->horizontalSlider, &QAbstractSlider::valueChanged, m_player, &QMediaPlayer::setVolume);
|
|
||||||
|
|
||||||
connect(m_player, &QMediaPlayer::stateChanged, [](QMediaPlayer::State newState){ qDebug() << newState; });
|
m_player->setVolume(m_mainWindow.settings().value(QStringLiteral("WebRadioPlugin/volume"), 100).toInt());
|
||||||
connect(m_player, &QMediaPlayer::mediaStatusChanged, [](QMediaPlayer::MediaStatus status){ qDebug() << status; });
|
ui->horizontalSlider->setValue(m_player->volume());
|
||||||
connect(m_player, static_cast<void(QMediaPlayer::*)(QMediaPlayer::Error)>(&QMediaPlayer::error),
|
connect(ui->horizontalSlider, &QAbstractSlider::valueChanged, this, &WebRadioDialog::volumeChanged);
|
||||||
[](QMediaPlayer::Error error){ qDebug() << error; });
|
|
||||||
connect(m_player, SIGNAL(volumeChanged(int)), ui->horizontalSlider, SLOT(setValue(int)));
|
|
||||||
|
|
||||||
Q_EMIT m_player->volumeChanged(m_player->volume());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WebRadioDialog::~WebRadioDialog()
|
WebRadioDialog::~WebRadioDialog()
|
||||||
@@ -50,7 +53,35 @@ WebRadioDialog::~WebRadioDialog()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebRadioDialog::stateChanged(QMediaPlayer::State newState)
|
||||||
|
{
|
||||||
|
qDebug() << newState;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebRadioDialog::mediaStatusChanged(QMediaPlayer::MediaStatus status)
|
||||||
|
{
|
||||||
|
qDebug() << status;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebRadioDialog::error(QMediaPlayer::Error error)
|
||||||
|
{
|
||||||
|
qDebug() << error;
|
||||||
|
}
|
||||||
|
|
||||||
void WebRadioDialog::play()
|
void WebRadioDialog::play()
|
||||||
{
|
{
|
||||||
|
qDebug() << "called";
|
||||||
|
if(ui->comboBox->currentIndex() == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_mainWindow.settings().setValue(QStringLiteral("WebRadioPlugin/lastUrl"), ui->comboBox->currentData().toString());
|
||||||
|
|
||||||
|
m_player->setMedia(QMediaContent(QUrl(ui->comboBox->currentData().toString())));
|
||||||
|
m_player->play();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebRadioDialog::volumeChanged(int volume)
|
||||||
|
{
|
||||||
|
m_mainWindow.settings().setValue(QStringLiteral("WebRadioPlugin/volume"), volume);
|
||||||
|
m_player->setVolume(volume);
|
||||||
}
|
}
|
||||||
|
@@ -2,8 +2,9 @@
|
|||||||
#define WEBRADIODIALOG_H
|
#define WEBRADIODIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QMediaPlayer>
|
||||||
|
|
||||||
class QMediaPlayer;
|
class MainWindow;
|
||||||
|
|
||||||
namespace Ui { class WebRadioDialog; }
|
namespace Ui { class WebRadioDialog; }
|
||||||
|
|
||||||
@@ -12,15 +13,21 @@ class WebRadioDialog : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit WebRadioDialog(QWidget *parent = 0);
|
explicit WebRadioDialog(MainWindow &mainWindow);
|
||||||
~WebRadioDialog();
|
~WebRadioDialog();
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
|
void stateChanged(QMediaPlayer::State newState);
|
||||||
|
void mediaStatusChanged(QMediaPlayer::MediaStatus status);
|
||||||
|
void error(QMediaPlayer::Error error);
|
||||||
|
|
||||||
|
void volumeChanged(int volume);
|
||||||
void play();
|
void play();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::WebRadioDialog *ui;
|
Ui::WebRadioDialog *ui;
|
||||||
|
|
||||||
|
MainWindow &m_mainWindow;
|
||||||
QMediaPlayer *m_player;
|
QMediaPlayer *m_player;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -6,22 +6,76 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>539</width>
|
<width>494</width>
|
||||||
<height>300</height>
|
<height>155</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Dialog</string>
|
<string>Radio</string>
|
||||||
</property>
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="comboBox"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButtonPlay">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>play()</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButtonPause">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>pause()</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButtonStop">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>50</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>stop()</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSlider" name="horizontalSlider">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>30</x>
|
|
||||||
<y>240</y>
|
|
||||||
<width>341</width>
|
|
||||||
<height>32</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
@@ -29,81 +83,8 @@
|
|||||||
<set>QDialogButtonBox::Close</set>
|
<set>QDialogButtonBox::Close</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QPushButton" name="pushButtonPlay">
|
</item>
|
||||||
<property name="geometry">
|
</layout>
|
||||||
<rect>
|
|
||||||
<x>20</x>
|
|
||||||
<y>60</y>
|
|
||||||
<width>131</width>
|
|
||||||
<height>51</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>play()</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QProgressBar" name="progressBar">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>50</x>
|
|
||||||
<y>160</y>
|
|
||||||
<width>351</width>
|
|
||||||
<height>23</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="value">
|
|
||||||
<number>24</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QPushButton" name="pushButtonPause">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>160</x>
|
|
||||||
<y>60</y>
|
|
||||||
<width>131</width>
|
|
||||||
<height>51</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>pause()</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QPushButton" name="pushButtonStop">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>300</x>
|
|
||||||
<y>60</y>
|
|
||||||
<width>131</width>
|
|
||||||
<height>51</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>stop()</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QSlider" name="horizontalSlider">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>270</x>
|
|
||||||
<y>130</y>
|
|
||||||
<width>160</width>
|
|
||||||
<height>16</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
<widget class="QComboBox" name="comboBox">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>40</x>
|
|
||||||
<y>20</y>
|
|
||||||
<width>271</width>
|
|
||||||
<height>25</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<connections>
|
||||||
|
@@ -33,7 +33,7 @@ WebRadioPlugin::WebRadioPlugin(QObject *parent) :
|
|||||||
|
|
||||||
void WebRadioPlugin::attachTo(MainWindow &mainWindow)
|
void WebRadioPlugin::attachTo(MainWindow &mainWindow)
|
||||||
{
|
{
|
||||||
auto dialog = new WebRadioDialog(&mainWindow);
|
auto dialog = new WebRadioDialog(mainWindow);
|
||||||
mainWindow.menuTools()->addAction(QIcon(QStringLiteral(":/zeiterfassung/plugins/webradioplugin/images/web-radio.png")),
|
mainWindow.menuTools()->addAction(QIcon(QStringLiteral(":/zeiterfassung/plugins/webradioplugin/images/web-radio.png")),
|
||||||
tr("Play webradio"), dialog, &QWidget::show);
|
tr("Play webradio"), dialog, &QWidget::show);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user