Web radio plugin #48
@@ -1,16 +1,22 @@
|
||||
#include "webradiodialog.h"
|
||||
#include "ui_webradiodialog.h"
|
||||
|
||||
#include <QMediaPlayer>
|
||||
#include "mainwindow.h"
|
||||
#include "zeiterfassungsettings.h"
|
||||
|
||||
WebRadioDialog::WebRadioDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
WebRadioDialog::WebRadioDialog(MainWindow &mainWindow) :
|
||||
QDialog(&mainWindow),
|
||||
ui(new Ui::WebRadioDialog),
|
||||
m_mainWindow(mainWindow),
|
||||
m_player(new QMediaPlayer(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.trap.fm:6002"),
|
||||
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/clt.mp3"),
|
||||
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, m_player, &QMediaPlayer::play);
|
||||
connect(ui->pushButtonPlay, &QAbstractButton::pressed, this, &WebRadioDialog::play);
|
||||
connect(ui->pushButtonPause, &QAbstractButton::pressed, m_player, &QMediaPlayer::pause);
|
||||
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; });
|
||||
connect(m_player, &QMediaPlayer::mediaStatusChanged, [](QMediaPlayer::MediaStatus status){ qDebug() << status; });
|
||||
connect(m_player, static_cast<void(QMediaPlayer::*)(QMediaPlayer::Error)>(&QMediaPlayer::error),
|
||||
[](QMediaPlayer::Error error){ qDebug() << error; });
|
||||
connect(m_player, SIGNAL(volumeChanged(int)), ui->horizontalSlider, SLOT(setValue(int)));
|
||||
|
||||
Q_EMIT m_player->volumeChanged(m_player->volume());
|
||||
m_player->setVolume(m_mainWindow.settings().value(QStringLiteral("WebRadioPlugin/volume"), 100).toInt());
|
||||
ui->horizontalSlider->setValue(m_player->volume());
|
||||
connect(ui->horizontalSlider, &QAbstractSlider::valueChanged, this, &WebRadioDialog::volumeChanged);
|
||||
}
|
||||
|
||||
WebRadioDialog::~WebRadioDialog()
|
||||
@@ -50,7 +53,35 @@ WebRadioDialog::~WebRadioDialog()
|
||||
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()
|
||||
{
|
||||
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
|
||||
|
||||
#include <QDialog>
|
||||
#include <QMediaPlayer>
|
||||
|
||||
class QMediaPlayer;
|
||||
class MainWindow;
|
||||
|
||||
namespace Ui { class WebRadioDialog; }
|
||||
|
||||
@@ -12,15 +13,21 @@ class WebRadioDialog : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WebRadioDialog(QWidget *parent = 0);
|
||||
explicit WebRadioDialog(MainWindow &mainWindow);
|
||||
~WebRadioDialog();
|
||||
|
||||
private Q_SLOTS:
|
||||
void stateChanged(QMediaPlayer::State newState);
|
||||
void mediaStatusChanged(QMediaPlayer::MediaStatus status);
|
||||
void error(QMediaPlayer::Error error);
|
||||
|
||||
void volumeChanged(int volume);
|
||||
void play();
|
||||
|
||||
private:
|
||||
Ui::WebRadioDialog *ui;
|
||||
|
||||
MainWindow &m_mainWindow;
|
||||
QMediaPlayer *m_player;
|
||||
};
|
||||
|
||||
|
@@ -6,104 +6,85 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>539</width>
|
||||
<height>300</height>
|
||||
<width>494</width>
|
||||
<height>155</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
<string>Radio</string>
|
||||
</property>
|
||||
<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">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close</set>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButtonPlay">
|
||||
<property name="geometry">
|
||||
<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>
|
||||
<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">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
|
@@ -33,7 +33,7 @@ WebRadioPlugin::WebRadioPlugin(QObject *parent) :
|
||||
|
||||
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")),
|
||||
tr("Play webradio"), dialog, &QWidget::show);
|
||||
}
|
||||
|
Reference in New Issue
Block a user