Rabbit Remote Control 0.0.32
Loading...
Searching...
No Matches
ConnecterPlayer.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include <QLoggingCategory>
4#include "ConnecterPlayer.h"
5#include "ConnectPlayer.h"
6#include "DlgPlayer.h"
7#include "PluginClient.h"
8
9static Q_LOGGING_CATEGORY(log, "Player.Connecter")
10
12 : CConnecterThread(plugin)
13{
14 qDebug(log) << Q_FUNC_INFO;
15}
16
17CConnecterPlayer::~CConnecterPlayer()
18{
19 qDebug(log) << Q_FUNC_INFO;
20}
21
23{
24 return 0;
25}
26
28{
29 qDebug(log) << Q_FUNC_INFO;
30 int nRet = 0;
31
32 nRet = SetParameter(&m_Parameters);
33 if(nRet) return nRet;
35 return nRet;
36}
37
38int CConnecterPlayer::InitialMenu()
39{
40 bool check = false;
41 int nRet = 0;
42
43#if HAVE_QT6_RECORD
44 m_pRecord = new QAction(
45 QIcon::fromTheme("media-record"), tr("Record"), &m_Menu);
46 m_pRecord->setCheckable(true);
47 check = connect(m_pRecord, SIGNAL(toggled(bool)),
48 this, SLOT(slotRecord(bool)));
49 Q_ASSERT(check);
50
51 m_pRecordPause = new QAction(
52 QIcon::fromTheme("media-playback-pause"), tr("Record pause"), &m_Menu);
53 m_pRecordPause->setCheckable(true);
54 m_pRecordPause->setEnabled(false);
55 check = connect(m_pRecordPause, SIGNAL(toggled(bool)),
56 this, SIGNAL(sigRecordPause(bool)));
57 Q_ASSERT(check);
58#endif
59
60 m_pScreenShot = new QAction(QIcon::fromTheme("camera-photo"),
61 tr("ScreenShot"), &m_Menu);
62 check = connect(m_pScreenShot, SIGNAL(triggered()),
63 this, SLOT(slotScreenShot()));
64 Q_ASSERT(check);
65
66#ifdef HAVE_QVideoWidget
67 m_Menu.addAction(m_Player.m_paStart);
68 check = connect(this, &CConnecterPlayer::sigConnected,
69 m_Player.m_paStart, &QAction::toggle);
70 Q_ASSERT(check);
71 check = connect(m_Player.m_paStart, SIGNAL(toggled(bool)),
72 this, SIGNAL(sigStart(bool)));
73 Q_ASSERT(check);
74
75 m_Menu.addAction(m_Player.m_paPause);
76 check = connect(m_Player.m_paPause, SIGNAL(toggled(bool)),
77 this, SIGNAL(sigPause(bool)));
78 Q_ASSERT(check);
79
80#if HAVE_QT6_RECORD
81 m_Menu.addAction(m_Player.m_paRecord);
82 check = connect(m_Player.m_paRecord, SIGNAL(toggled(bool)),
83 m_pRecord ,SIGNAL(toggled(bool)));
84 Q_ASSERT(check);
85
86 m_Menu.addAction(m_Player.m_paRecordPause);
87 check = connect(m_Player.m_paRecordPause, SIGNAL(toggled(bool)),
88 m_pRecordPause, SIGNAL(toggled(bool)));
89 Q_ASSERT(check);
90#endif
91
92 m_Menu.addAction(m_Player.m_paScreenShot);
93 check = connect(m_Player.m_paScreenShot, &QAction::triggered,
94 m_pScreenShot, &QAction::triggered);
95 Q_ASSERT(check);
96
97 m_Menu.addSeparator();
98
99 m_Menu.addAction(m_Player.m_paSettings);
100 check = connect(m_Player.m_paSettings, &QAction::triggered,
101 m_pSettings, &QAction::triggered);
102 Q_ASSERT(check);
103
104 check = connect(this, &CConnecterPlayer::sigConnected,
105 this, [&](){
106 m_Player.SetParameter(&m_Parameters);
107 });
108 Q_ASSERT(check);
109 check = connect(&m_Player, SIGNAL(sigChangePosition(qint64)),
110 this, SIGNAL(sigChangePosition(qint64)));
111 Q_ASSERT(check);
112#else
113 QAction* pStart = m_Menu.addAction(
114 QIcon::fromTheme("media-playback-start"), tr("Start"));
115 pStart->setCheckable(true);
116 check = connect(this, &CConnecterPlayer::sigConnected,
117 pStart, &QAction::toggle);
118 Q_ASSERT(check);
119 check = connect(pStart, &QAction::toggled,
120 this, [&](bool checked){
121 QAction* p = qobject_cast<QAction*>(sender());
122 if(!p) return;
123 if(p->isChecked()) {
124 p->setIcon(QIcon::fromTheme("media-playback-stop"));
125 p->setText(tr("Stop"));
126 m_pPause->setEnabled(true);
127 m_pPause->setChecked(false);
128 m_pScreenShot->setEnabled(true);
129#if HAVE_QT6_RECORD
130 m_pRecord->setEnabled(true);
131 m_pRecord->setChecked(false);
132 m_pRecordPause->setEnabled(true);
133 m_pRecordPause->setChecked(false);
134#endif
135 } else {
136 p->setIcon(QIcon::fromTheme("media-playback-start"));
137 p->setText(tr("Start"));
138 m_pPause->setEnabled(false);
139 m_pPause->setChecked(false);
140 m_pScreenShot->setEnabled(false);
141#if HAVE_QT6_RECORD
142 m_pRecord->setEnabled(false);
143 m_pRecord->setChecked(false);
144 m_pRecordPause->setEnabled(false);
145 m_pRecordPause->setChecked(false);
146#endif
147 }
148 emit sigStart(checked);
149 });
150 Q_ASSERT(check);
151 m_pPause = m_Menu.addAction(
152 QIcon::fromTheme("media-playback-pause"), tr("pause"));
153 m_pPause->setCheckable(true);
154 check = connect(m_pPause, SIGNAL(toggled(bool)),
155 this, SIGNAL(sigPause(bool)));
156 Q_ASSERT(check);
157#if HAVE_QT6_RECORD
158 m_Menu.addAction(m_pRecord);
159 m_Menu.addAction(m_pRecordPause);
160#endif
161 m_Menu.addAction(m_pScreenShot);
162 m_Menu.addSeparator();
163 m_Menu.addAction(m_pSettings);
164#endif
165 return nRet;
166}
167
169{
170 qDebug(log) << Q_FUNC_INFO;
171 int nRet = 0;
173 return nRet;
174}
175
177{
178 QDialog* pDlg = new CDlgPlayer(&m_Parameters, parent);
179 return pDlg;
180}
181
183{
184 CConnect* p = new CConnectPlayer(this);
185 return p;
186}
187
188void CConnecterPlayer::slotScreenShot()
189{
190 emit sigScreenShot();
191}
192
193#if HAVE_QVideoWidget
195{
196 return &m_Player;
197}
198
199QVideoSink *CConnecterPlayer::GetVideoSink()
200{
201 return m_Player.videoSink();
202}
203
204void CConnecterPlayer::slotPositionChanged(qint64 pos, qint64 duration)
205{
206 m_Player.slotPositionChanged(pos, duration);
207}
208
209void CConnecterPlayer::slotPlaybackError(
210 QMediaPlayer::Error error, const QString &errorString)
211{
212 if(m_Player.m_paStart->isChecked())
213 m_Player.m_paStart->setChecked(false);
214}
215
216void CConnecterPlayer::slotPlaybackStateChanged(QMediaPlayer::PlaybackState state)
217{
218 if(QMediaPlayer::StoppedState == state
219 && m_Player.m_paStart->isChecked())
220 m_Player.m_paStart->setChecked(false);
221}
222
223#if HAVE_QT6_RECORD
224void CConnecterPlayer::slotRecordStateChanged(QMediaRecorder::RecorderState state)
225{
226 if(QMediaRecorder::StoppedState == state
227 && m_Player.m_paRecord->isCheckable())
228 m_Player.m_paRecord->setChecked(false);
229}
230#endif
231
232#endif
Connect interface.
Definition Connect.h:45
virtual qint16 Version() override
Version.
virtual int Clean() override
Clean parameters and resource.
virtual CConnect * InstanceConnect() override
New connect.
virtual QDialog * OnOpenDialogSettings(QWidget *parent) override
Open settgins dialog.
virtual int Initial() override
Initial parameters and resource.
It starts a background thread by default.
virtual int Initial() override
Initial parameters and resource.
virtual int Clean() override
Clean parameters and resource.
void sigConnected()
Successful connection signal.
virtual QWidget * GetViewer()=0
Get Viewer.
The plugin interface.