MythTV  master
setupwizard_video.cpp
Go to the documentation of this file.
1 // Qt
2 #include <QFileInfo>
3 #include <QString>
4 #include <QVariant>
5 
6 // MythTV
7 #include "libmyth/mythcontext.h"
10 #include "libmythbase/mythdirs.h"
11 #include "libmythbase/remotefile.h"
14 
15 // MythFrontend
16 #include "setupwizard_audio.h"
17 #include "setupwizard_general.h"
18 #include "setupwizard_video.h"
19 
20 const QString VIDEO_SAMPLE_HD_LOCATION =
21  QString("http://services.mythtv.org/samples/video/?sample=HD");
22 const QString VIDEO_SAMPLE_SD_LOCATION =
23  QString("http://services.mythtv.org/samples/video/?sample=SD");
24 const QString VIDEO_SAMPLE_HD_FILENAME =
25  QString("mythtv_video_test_HD_19000Kbps_H264.mkv");
26 const QString VIDEO_SAMPLE_SD_FILENAME =
27  QString("mythtv_video_test_SD_6000Kbps_H264.mkv");
28 
30  MythScreenType *general,
31  MythScreenType *audio, const char *name)
32  : MythScreenType(parent, name),
33  m_generalScreen(general), m_audioScreen(audio)
34 {
35  m_popupStack = GetMythMainWindow()->GetStack("popup stack");
36 
38 }
39 
41 {
42  // Load the theme for this screen
43  bool foundtheme = LoadWindowFromXML("config-ui.xml", "videowizard", this);
44  if (!foundtheme)
45  return false;
46 
48  dynamic_cast<MythUIButtonList *> (GetChild("playbackprofiles"));
49 
50  m_testSDButton = dynamic_cast<MythUIButton *> (GetChild("testsd"));
51  m_testHDButton = dynamic_cast<MythUIButton *> (GetChild("testhd"));
52 
53  m_nextButton = dynamic_cast<MythUIButton *> (GetChild("next"));
54  m_prevButton = dynamic_cast<MythUIButton *> (GetChild("previous"));
55 
58  {
59  LOG(VB_GENERAL, LOG_ERR, "Theme is missing critical theme elements.");
60  return false;
61  }
62 
63  m_playbackProfileButtonList->SetHelpText( tr("Select from one of the "
64  "preconfigured playback profiles. When "
65  "satisfied, you can test Standard Definition "
66  "and High Definition playback with the selected "
67  "profile before moving on.") );
68  m_testSDButton->SetHelpText( tr("Test your playback settings with Standard "
69  "Definition content. (480p)") );
70  m_testHDButton->SetHelpText( tr("Test your playback settings with High "
71  "Definition content (1080p).") );
72  m_nextButton->SetHelpText( tr("Save these changes and move on to the "
73  "next configuration step.") );
74  m_prevButton->SetHelpText(tr("Return to the previous configuration step."));
75 
80 
82  loadData();
83 
84  return true;
85 }
86 
88 {
90 }
91 
93 {
94  QStringList profiles = MythVideoProfile::GetProfiles(gCoreContext->GetHostName());
95 
96  for (const auto & prof : qAsConst(profiles))
97  {
98  auto *item = new MythUIButtonListItem(m_playbackProfileButtonList, prof);
99  item->SetData(prof);
100  }
101 
103  if (!currentpbp.isEmpty())
104  {
105  MythUIButtonListItem *set =
108  }
109 }
110 
112 {
113  save();
114 
115  if (m_audioScreen)
116  {
117  m_audioScreen->Close();
118  m_audioScreen = nullptr;
119  }
120 
121  if (m_generalScreen)
122  {
124  m_generalScreen = nullptr;
125  }
126 
127  Close();
128 }
129 
131 {
132  QString desiredpbp =
135 }
136 
138 {
139  Close();
140 }
141 
142 bool VideoSetupWizard::keyPressEvent(QKeyEvent *event)
143 {
144  if (GetFocusWidget()->keyPressEvent(event))
145  return true;
146 
147  bool handled = false;
148 
150  handled = true;
151 
152  return handled;
153 }
154 
156 {
157  QString sdtestfile = generate_file_url("Temp",
160  QString desiredpbp =
162  QString desc = tr("A short test of your system's playback of "
163  "Standard Definition content with the %1 profile.")
164  .arg(desiredpbp);
165  QString title = tr("Standard Definition Playback Test");
166 
167  if (!RemoteFile::Exists(sdtestfile))
168  {
171  }
172  else
173  playVideoTest(desc, title, sdtestfile);
174 }
175 
177 {
178  QString hdtestfile = generate_file_url("Temp",
181  QString desiredpbp =
183  QString desc = tr("A short test of your system's playback of "
184  "High Definition content with the %1 profile.")
185  .arg(desiredpbp);
186  QString title = tr("High Definition Playback Test");
187 
188  if (!RemoteFile::Exists(hdtestfile))
189  {
192  }
193  else
194  playVideoTest(desc, title, hdtestfile);
195 }
196 
197 void VideoSetupWizard::playVideoTest(const QString& desc, const QString& title, const QString& file)
198 {
199  QString desiredpbp =
202 
204  GetMythMainWindow()->HandleMedia("Internal", file, desc, title);
206 }
207 
208 void VideoSetupWizard::DownloadSample(const QString& url, const QString& dest)
209 {
211  m_downloadFile = RemoteDownloadFile(url, "Temp", dest);
212 }
213 
215 {
216  QString message = tr("Downloading Video Sample...");
218  m_popupStack, "sampledownloadprogressdialog");
219 
220  if (m_progressDialog->Create())
221  {
223  }
224  else
225  {
226  delete m_progressDialog;
227  m_progressDialog = nullptr;
228  }
229 }
230 
232 {
233  if (e->type() == MythEvent::MythEventMessage)
234  {
235  auto *me = dynamic_cast<MythEvent *>(e);
236  if (me == nullptr)
237  return;
238 
239 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
240  QStringList tokens = me->Message().split(" ", QString::SkipEmptyParts);
241 #else
242  QStringList tokens = me->Message().split(" ", Qt::SkipEmptyParts);
243 #endif
244  if (tokens.isEmpty())
245  return;
246 
247  if (tokens[0] == "DOWNLOAD_FILE")
248  {
249  QStringList args = me->ExtraDataList();
250  if ((tokens.size() != 2) ||
251  (args[1] != m_downloadFile))
252  return;
253 
254  if (tokens[1] == "UPDATE")
255  {
256  QString message = tr("Downloading Video Sample...\n"
257  "(%1 of %2 MB)")
258  .arg(QString::number(args[2].toInt() / 1024.0 / 1024.0, 'f', 2),
259  QString::number(args[3].toInt() / 1024.0 / 1024.0, 'f', 2));
260  m_progressDialog->SetMessage(message);
261  m_progressDialog->SetTotal(args[3].toInt());
262  m_progressDialog->SetProgress(args[2].toInt());
263  }
264  else if (tokens[1] == "FINISHED")
265  {
266  int fileSize = args[2].toInt();
267  int errorCode = args[4].toInt();
268 
269  if (m_progressDialog)
271 
272  if ((m_downloadFile.startsWith("myth://")))
273  {
274  if ((errorCode == 0) &&
275  (fileSize > 0))
276  {
278  testHDVideo();
279  else if (m_testType == ttStandardDefinition)
280  testSDVideo();
281  }
282  else
283  {
284  ShowOkPopup(tr("Error downloading sample to backend."));
285  }
286  }
287  }
288  }
289  }
290 }
MythUIButton::Clicked
void Clicked()
VideoSetupWizard::m_generalScreen
MythScreenType * m_generalScreen
Definition: setupwizard_video.h:46
VideoSetupWizard::~VideoSetupWizard
~VideoSetupWizard() override
Definition: setupwizard_video.cpp:87
build_compdb.args
args
Definition: build_compdb.py:11
MythUIProgressDialog::Create
bool Create(void) override
Definition: mythprogressdialog.cpp:130
generate_file_url
QString generate_file_url(const QString &storage_group, const QString &host, const QString &path)
Definition: videoutils.h:65
VIDEO_SAMPLE_HD_LOCATION
const QString VIDEO_SAMPLE_HD_LOCATION
Definition: setupwizard_video.cpp:20
build_compdb.dest
dest
Definition: build_compdb.py:9
MythEvent::MythEventMessage
static Type MythEventMessage
Definition: mythevent.h:79
MythUIButtonList::GetItemCurrent
MythUIButtonListItem * GetItemCurrent() const
Definition: mythuibuttonlist.cpp:1587
MythCoreContext::GetMasterHostName
QString GetMasterHostName(void)
Definition: mythcorecontext.cpp:811
VideoSetupWizard::playVideoTest
void playVideoTest(const QString &desc, const QString &title, const QString &file)
Definition: setupwizard_video.cpp:197
VideoSetupWizard::ttHighDefinition
@ ttHighDefinition
Definition: setupwizard_video.h:39
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:386
RemoteFile::Exists
static bool Exists(const QString &url, struct stat *fileinfo)
Definition: remotefile.cpp:462
VideoSetupWizard::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: setupwizard_video.cpp:142
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:133
VideoSetupWizard::testSDVideo
void testSDVideo(void)
Definition: setupwizard_video.cpp:155
VideoSetupWizard::initProgressDialog
void initProgressDialog()
Definition: setupwizard_video.cpp:214
VIDEO_SAMPLE_HD_FILENAME
const QString VIDEO_SAMPLE_HD_FILENAME
Definition: setupwizard_video.cpp:24
VIDEO_SAMPLE_SD_FILENAME
const QString VIDEO_SAMPLE_SD_FILENAME
Definition: setupwizard_video.cpp:26
MythEvent
This class is used as a container for messages.
Definition: mythevent.h:16
mythcoreutil.h
VideoSetupWizard::Create
bool Create(void) override
Definition: setupwizard_video.cpp:40
setupwizard_general.h
MythScreenStack
Definition: mythscreenstack.h:16
mythdbcon.h
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
VideoSetupWizard::save
void save(void)
Definition: setupwizard_video.cpp:130
build_compdb.file
file
Definition: build_compdb.py:55
mythdirs.h
MythUIProgressDialog::SetMessage
void SetMessage(const QString &message)
Definition: mythprogressdialog.cpp:205
setupwizard_video.h
mythprogressdialog.h
MythEvent::Message
const QString & Message() const
Definition: mythevent.h:65
MythMainWindow::HandleMedia
bool HandleMedia(const QString &Handler, const QString &Mrl, const QString &Plot="", const QString &Title="", const QString &Subtitle="", const QString &Director="", int Season=0, int Episode=0, const QString &Inetref="", std::chrono::minutes LenMins=2h, const QString &Year="1895", const QString &Id="", bool UseBookmarks=false)
Definition: mythmainwindow.cpp:1489
VideoSetupWizard::customEvent
void customEvent(QEvent *e) override
Definition: setupwizard_video.cpp:231
VIDEO_SAMPLE_SD_LOCATION
const QString VIDEO_SAMPLE_SD_LOCATION
Definition: setupwizard_video.cpp:22
MythUIButtonList::GetItemByData
MythUIButtonListItem * GetItemByData(const QVariant &data)
Definition: mythuibuttonlist.cpp:1681
VideoSetupWizard::ttStandardDefinition
@ ttStandardDefinition
Definition: setupwizard_video.h:40
MythScreenType::GetFocusWidget
MythUIType * GetFocusWidget(void) const
Definition: mythscreentype.cpp:113
VideoSetupWizard::m_downloadFile
QString m_downloadFile
Definition: setupwizard_video.h:43
MythObservable::addListener
void addListener(QObject *listener)
Add a listener to the observable.
Definition: mythobservable.cpp:38
MythUIButtonListItem
Definition: mythuibuttonlist.h:41
MythVideoProfile::GetProfiles
static QStringList GetProfiles(const QString &HostName)
Definition: mythvideoprofile.cpp:865
VideoSetupWizard::m_playbackProfileButtonList
MythUIButtonList * m_playbackProfileButtonList
Definition: setupwizard_video.h:49
remotefile.h
MythUIProgressDialog
Definition: mythprogressdialog.h:59
MythUIProgressDialog::SetProgress
void SetProgress(uint count)
Definition: mythprogressdialog.cpp:199
MythUIType::SetHelpText
void SetHelpText(const QString &text)
Definition: mythuitype.h:175
VideoSetupWizard::slotPrevious
void slotPrevious(void)
Definition: setupwizard_video.cpp:137
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:206
MythUIButton
A single button widget.
Definition: mythuibutton.h:21
VideoSetupWizard::m_progressDialog
MythUIProgressDialog * m_progressDialog
Definition: setupwizard_video.h:51
VideoSetupWizard::VideoSetupWizard
VideoSetupWizard(MythScreenStack *parent, MythScreenType *general, MythScreenType *audio, const char *name=nullptr)
Definition: setupwizard_video.cpp:29
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:59
MythVideoProfile::SetDefaultProfileName
static void SetDefaultProfileName(const QString &ProfileName, const QString &HostName)
Definition: mythvideoprofile.cpp:903
setupwizard_audio.h
VideoSetupWizard::m_nextButton
MythUIButton * m_nextButton
Definition: setupwizard_video.h:56
MythUIButtonListItem::GetText
QString GetText(const QString &name="") const
Definition: mythuibuttonlist.cpp:3315
VideoSetupWizard::m_testType
TestType m_testType
Definition: setupwizard_video.h:44
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:404
VideoSetupWizard::m_prevButton
MythUIButton * m_prevButton
Definition: setupwizard_video.h:57
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:695
MythUIProgressDialog::SetTotal
void SetTotal(uint total)
Definition: mythprogressdialog.cpp:193
MythVideoProfile::GetDefaultProfileName
static QString GetDefaultProfileName(const QString &HostName)
Definition: mythvideoprofile.cpp:884
mythcontext.h
VideoSetupWizard::slotNext
void slotNext(void)
Definition: setupwizard_video.cpp:111
VideoSetupWizard::testHDVideo
void testHDVideo(void)
Definition: setupwizard_video.cpp:176
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:102
MythUIButtonList::SetItemCurrent
void SetItemCurrent(MythUIButtonListItem *item)
Definition: mythuibuttonlist.cpp:1554
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:320
MythCoreContext::GetHostName
QString GetHostName(void)
Definition: mythcorecontext.cpp:842
VideoSetupWizard::m_testSDButton
MythUIButton * m_testSDButton
Definition: setupwizard_video.h:53
VideoSetupWizard::loadData
void loadData(void)
Definition: setupwizard_video.cpp:92
VideoSetupWizard::DownloadSample
void DownloadSample(const QString &url, const QString &dest)
Definition: setupwizard_video.cpp:208
VideoSetupWizard::m_testHDButton
MythUIButton * m_testHDButton
Definition: setupwizard_video.h:54
MythUIButtonList
List widget, displays list items in a variety of themeable arrangements and can trigger signals when ...
Definition: mythuibuttonlist.h:191
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:50
ShowOkPopup
MythConfirmationDialog * ShowOkPopup(const QString &message, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
Definition: mythdialogbox.cpp:563
RemoteDownloadFile
QString RemoteDownloadFile(const QString &url, const QString &storageGroup, const QString &filename)
Definition: mythcoreutil.cpp:91
VideoSetupWizard::m_audioScreen
MythScreenType * m_audioScreen
Definition: setupwizard_video.h:47
MythObservable::removeListener
void removeListener(QObject *listener)
Remove a listener to the observable.
Definition: mythobservable.cpp:55
videoutils.h
VideoSetupWizard::m_popupStack
MythScreenStack * m_popupStack
Definition: setupwizard_video.h:50