Rabbit Remote Control 0.0.34
Loading...
Searching...
No Matches
DlgPlayer.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include <QCamera>
4#include <QCameraDevice>
5#include <QMediaDevices>
6#include <QAudioDevice>
7#include <QFileDialog>
8#include <QStandardPaths>
9#include <QMediaRecorder>
10#include <QMediaFormat>
11#include <QLoggingCategory>
12#include <QScreen>
13#include <QGuiApplication>
14#include <QMessageBox>
15
16#include "DlgPlayer.h"
17#include "ui_DlgPlayer.h"
18
19static Q_LOGGING_CATEGORY(log, "Player.Connect")
20CDlgPlayer::CDlgPlayer(CParameterPlayer *pPara, QWidget *parent)
21 : QDialog(parent)
22 , ui(new Ui::CDlgPlayer)
23 , m_pParameters(pPara)
24{
25 ui->setupUi(this);
26
27 if(!m_pParameters->GetName().isEmpty())
28 ui->leName->setText(m_pParameters->GetName());
29
30 foreach(auto ai, QMediaDevices::audioInputs())
31 {
32 ui->cmbAudioInput->addItem(ai.description());
33 }
34 ui->gbAudioInput->setCheckable(true);
35 if(QMediaDevices::audioInputs().size() > 0)
36 ui->gbAudioInput->setChecked(m_pParameters->GetEnableAudioInput());
37 else {
38 ui->gbAudioInput->setEnabled(false);
39 ui->gbAudioInput->setChecked(false);
40 }
41 if(m_pParameters->GetAudioInput() != -1)
42 ui->cmbAudioInput->setCurrentIndex(m_pParameters->GetAudioInput());
43 ui->cbAudioInputMuted->setChecked(m_pParameters->GetAudioInputMuted());
44 ui->dsAudioInputVolume->setValue(m_pParameters->GetAudioInputVolume());
45
46 foreach(auto ao, QMediaDevices::audioOutputs())
47 ui->cmbAudioOutput->addItem(ao.description());
48 ui->gbAudioOutput->setCheckable(true);
49 if(QMediaDevices::audioOutputs().size() > 0)
50 ui->gbAudioOutput->setChecked(m_pParameters->GetEnableAudioOutput());
51 else {
52 ui->gbAudioOutput->setEnabled(false);
53 ui->gbAudioOutput->setChecked(false);
54 }
55 if(m_pParameters->GetAudioOutput() != -1)
56 ui->cmbAudioOutput->setCurrentIndex(m_pParameters->GetAudioOutput());
57 ui->cbAudioOutputMuted->setCheckable(true);
58 ui->cbAudioOutputMuted->setChecked(m_pParameters->GetAudioOutputMuted());
59 ui->dsAudioOutputVolume->setValue(m_pParameters->GetAudioOutputVolume());
60
61 if(QMediaDevices::videoInputs().size() > 0)
62 {
63 ui->cmbType->addItem(tr("Camera"), (int)CParameterPlayer::TYPE::Camera);
64 foreach(const QCameraDevice &cameraDevice, QMediaDevices::videoInputs()) {
65 ui->cmbCamera->addItem(cameraDevice.description());
66 }
67 if(m_pParameters->GetCamera() > -1)
68 ui->cmbCamera->setCurrentIndex(m_pParameters->GetCamera());
69 }
70
71 ui->cmbType->addItem(tr("Url"), (int)CParameterPlayer::TYPE::Url);
72 ui->leUrl->setText(m_pParameters->GetUrl());
73
74 int nIndex = ui->cmbType->findData((int)m_pParameters->GetType());
75 if(-1 < nIndex) {
76 ui->cmbType->setCurrentIndex(nIndex);
77 on_cmbType_currentIndexChanged(nIndex);
78 }
79
80 m_pRecordUI = new CParameterRecordUI(ui->tabWidget);
81 m_pRecordUI->SetParameter(&m_pParameters->m_Record);
82 ui->tabWidget->addTab(m_pRecordUI, m_pRecordUI->windowIcon(), m_pRecordUI->windowTitle());
83}
84
85CDlgPlayer::~CDlgPlayer()
86{
87 delete ui;
88}
89
90void CDlgPlayer::accept()
91{
92 int nRet = 0;
93
94 if(!ui->leName->text().isEmpty())
95 m_pParameters->SetName(ui->leName->text());
96 if((ui->cmbType->currentData().value<CParameterPlayer::TYPE>()
97 == CParameterPlayer::TYPE::Url) && ui->leUrl->text().isEmpty()) {
98 ui->leUrl->setFocus();
99 ui->tabWidget->setCurrentIndex(0);
100 QString szErr = tr("The url is empty. please set!");
101 QMessageBox::critical(this, tr("Error"), szErr);
102 qCritical(log) << szErr;
103 return;
104 }
105
106 if(!m_pRecordUI->CheckValidity(true)) {
107 ui->tabWidget->setCurrentWidget(m_pRecordUI);
108 return;
109 }
110
111 m_pParameters->SetType(
112 ui->cmbType->currentData().value<CParameterPlayer::TYPE>());
113 m_pParameters->SetUrl(ui->leUrl->text());
114 m_pParameters->SetCamera(ui->cmbCamera->currentIndex());
115 switch(m_pParameters->GetType()) {
116 case CParameterPlayer::TYPE::Camera: {
117 int nIndex = m_pParameters->GetCamera();
118 if(-1 < nIndex && nIndex < QMediaDevices::videoInputs().size())
119 if(ui->leName->text().isEmpty())
120 m_pParameters->SetName(
121 tr("Camera: ")
122 + QMediaDevices::videoInputs().at(nIndex).description());
123 break;
124 }
125 case CParameterPlayer::TYPE::Url:
126 QFileInfo fi(m_pParameters->GetUrl());
127 if(ui->leName->text().isEmpty())
128 m_pParameters->SetName(tr("Url: ") + fi.fileName());
129 break;
130 }
131
132 m_pParameters->SetEnableAudioInput(ui->gbAudioInput->isChecked());
133 m_pParameters->SetAudioInput(ui->cmbAudioInput->currentIndex());
134 m_pParameters->SetAudioInputMuted(ui->cbAudioInputMuted->isChecked());
135 m_pParameters->SetAudioInputVolume(ui->dsAudioInputVolume->value());
136 m_pParameters->SetEnableAudioOutput(ui->gbAudioOutput->isChecked());
137 m_pParameters->SetAudioOutput(ui->cmbAudioOutput->currentIndex());
138 m_pParameters->SetAudioOutputMuted(ui->cbAudioOutputMuted->isChecked());
139 m_pParameters->SetAudioOutputVolume(ui->dsAudioOutputVolume->value());
140
141 nRet = m_pRecordUI->Accept();
142 if(nRet)
143 return;
144
145 QDialog::accept();
146}
147
148void CDlgPlayer::on_cmbType_currentIndexChanged(int index)
149{
150 ui->cmbCamera->setVisible(false);
151 ui->leUrl->setVisible(false);
152 ui->pbUrlBrowse->setVisible(false);
153
154 CParameterPlayer::TYPE type
155 = (CParameterPlayer::TYPE)ui->cmbType->itemData(index).toInt();
156 switch(type) {
157 case CParameterPlayer::TYPE::Camera:
158 ui->cmbCamera->setVisible(true);
159 ui->gbAudioInput->setChecked(true);
160 break;
161 case CParameterPlayer::TYPE::Url:
162 ui->leUrl->setVisible(true);
163 ui->pbUrlBrowse->setVisible(true);
164 ui->gbAudioInput->setChecked(false);
165 break;
166 default:
167 break;
168 }
169}
170
171void CDlgPlayer::on_pbUrlBrowse_clicked()
172{
173 /*
174 QMediaRecorder recorder;
175 auto formats = recorder.mediaFormat().supportedFileFormats(QMediaFormat::Decode);
176 qDebug(log) << "Support file formats:" << formats;
177 foreach(auto f, formats) {
178 qDebug(log) << "File format name:" << QMediaFormat::fileFormatName(f);
179 } //*/
180 QString szFilter(tr("Media files(* wmv *.aac *.WebM *.mtk *.ogg *.mp4 *.mov *.avi);;All files(*.*)"));
181 QString szFile = QFileDialog::getOpenFileName(
182 this, tr("Open file"),
183 QStandardPaths::writableLocation(QStandardPaths::MoviesLocation),
184 szFilter);
185 if(!szFile.isEmpty())
186 ui->leUrl->setText(szFile);
187}
virtual bool CheckValidity(bool validity=false)
Check parameters validity.