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
10 #include "libmythbase/mythdirs.h"
12 #include "libmythbase/remotefile.h"
13 #include "libmythbase/remoteutil.h"
16 
17 // MythFrontend
18 #include "setupwizard_audio.h"
19 #include "setupwizard_general.h"
20 #include "setupwizard_video.h"
21 
22 const QString VIDEO_SAMPLE_HD_LOCATION =
23  QString("http://services.mythtv.org/samples/video/?sample=HD");
24 const QString VIDEO_SAMPLE_SD_LOCATION =
25  QString("http://services.mythtv.org/samples/video/?sample=SD");
26 const QString VIDEO_SAMPLE_HD_FILENAME =
27  QString("mythtv_video_test_HD_19000Kbps_H264.mkv");
28 const QString VIDEO_SAMPLE_SD_FILENAME =
29  QString("mythtv_video_test_SD_6000Kbps_H264.mkv");
30 
32  MythScreenType *general,
33  MythScreenType *audio, const char *name)
34  : MythScreenType(parent, name),
35  m_generalScreen(general), m_audioScreen(audio)
36 {
37  m_popupStack = GetMythMainWindow()->GetStack("popup stack");
38 
40 }
41 
43 {
44  // Load the theme for this screen
45  bool foundtheme = LoadWindowFromXML("config-ui.xml", "videowizard", this);
46  if (!foundtheme)
47  return false;
48 
50  dynamic_cast<MythUIButtonList *> (GetChild("playbackprofiles"));
51 
52  m_testSDButton = dynamic_cast<MythUIButton *> (GetChild("testsd"));
53  m_testHDButton = dynamic_cast<MythUIButton *> (GetChild("testhd"));
54 
55  m_nextButton = dynamic_cast<MythUIButton *> (GetChild("next"));
56  m_prevButton = dynamic_cast<MythUIButton *> (GetChild("previous"));
57 
60  {
61  LOG(VB_GENERAL, LOG_ERR, "Theme is missing critical theme elements.");
62  return false;
63  }
64 
65  m_playbackProfileButtonList->SetHelpText( tr("Select from one of the "
66  "preconfigured playback profiles. When "
67  "satisfied, you can test Standard Definition "
68  "and High Definition playback with the selected "
69  "profile before moving on.") );
70  m_testSDButton->SetHelpText( tr("Test your playback settings with Standard "
71  "Definition content. (480p)") );
72  m_testHDButton->SetHelpText( tr("Test your playback settings with High "
73  "Definition content (1080p).") );
74  m_nextButton->SetHelpText( tr("Save these changes and move on to the "
75  "next configuration step.") );
76  m_prevButton->SetHelpText(tr("Return to the previous configuration step."));
77 
82 
84  loadData();
85 
86  return true;
87 }
88 
90 {
92 }
93 
95 {
96  QStringList profiles = MythVideoProfile::GetProfiles(gCoreContext->GetHostName());
97 
98  for (const auto & prof : std::as_const(profiles))
99  {
100  auto *item = new MythUIButtonListItem(m_playbackProfileButtonList, prof);
101  item->SetData(prof);
102  }
103 
105  if (!currentpbp.isEmpty())
106  {
107  MythUIButtonListItem *set =
110  }
111 }
112 
114 {
115  save();
116 
117  if (m_audioScreen)
118  {
119  m_audioScreen->Close();
120  m_audioScreen = nullptr;
121  }
122 
123  if (m_generalScreen)
124  {
126  m_generalScreen = nullptr;
127  }
128 
129  Close();
130 }
131 
133 {
134  QString desiredpbp =
137 }
138 
140 {
141  Close();
142 }
143 
144 bool VideoSetupWizard::keyPressEvent(QKeyEvent *event)
145 {
146  if (GetFocusWidget()->keyPressEvent(event))
147  return true;
148 
149  bool handled = false;
150 
152  handled = true;
153 
154  return handled;
155 }
156 
158 {
159  QString sdtestfile = StorageGroup::generate_file_url("Temp",
162  QString desiredpbp =
164  QString desc = tr("A short test of your system's playback of "
165  "Standard Definition content with the %1 profile.")
166  .arg(desiredpbp);
167  QString title = tr("Standard Definition Playback Test");
168 
169  if (!RemoteFile::Exists(sdtestfile))
170  {
173  }
174  else
175  {
176  playVideoTest(desc, title, sdtestfile);
177  }
178 }
179 
181 {
182  QString hdtestfile = StorageGroup::generate_file_url("Temp",
185  QString desiredpbp =
187  QString desc = tr("A short test of your system's playback of "
188  "High Definition content with the %1 profile.")
189  .arg(desiredpbp);
190  QString title = tr("High Definition Playback Test");
191 
192  if (!RemoteFile::Exists(hdtestfile))
193  {
196  }
197  else
198  {
199  playVideoTest(desc, title, hdtestfile);
200  }
201 }
202 
203 void VideoSetupWizard::playVideoTest(const QString& desc, const QString& title, const QString& file)
204 {
205  QString desiredpbp =
208 
210  GetMythMainWindow()->HandleMedia("Internal", file, desc, title);
212 }
213 
214 void VideoSetupWizard::DownloadSample(const QString& url, const QString& dest)
215 {
217  m_downloadFile = RemoteDownloadFile(url, "Temp", dest);
218 }
219 
221 {
222  QString message = tr("Downloading Video Sample...");
224  m_popupStack, "sampledownloadprogressdialog");
225 
226  if (m_progressDialog->Create())
227  {
229  }
230  else
231  {
232  delete m_progressDialog;
233  m_progressDialog = nullptr;
234  }
235 }
236 
238 {
239  if (e->type() == MythEvent::kMythEventMessage)
240  {
241  auto *me = dynamic_cast<MythEvent *>(e);
242  if (me == nullptr)
243  return;
244 
245  QStringList tokens = me->Message().split(" ", Qt::SkipEmptyParts);
246  if (tokens.isEmpty())
247  return;
248 
249  if (tokens[0] == "DOWNLOAD_FILE")
250  {
251  QStringList args = me->ExtraDataList();
252  if ((tokens.size() != 2) ||
253  (args[1] != m_downloadFile))
254  return;
255 
256  if (tokens[1] == "UPDATE")
257  {
258  QString message = tr("Downloading Video Sample...\n"
259  "(%1 of %2 MB)")
260  .arg(QString::number(args[2].toInt() / 1024.0 / 1024.0, 'f', 2),
261  QString::number(args[3].toInt() / 1024.0 / 1024.0, 'f', 2));
262  m_progressDialog->SetMessage(message);
263  m_progressDialog->SetTotal(args[3].toInt());
264  m_progressDialog->SetProgress(args[2].toInt());
265  }
266  else if (tokens[1] == "FINISHED")
267  {
268  int fileSize = args[2].toInt();
269  int errorCode = args[4].toInt();
270 
271  if (m_progressDialog)
273 
274  if ((m_downloadFile.startsWith("myth://")))
275  {
276  if ((errorCode == 0) &&
277  (fileSize > 0))
278  {
280  testHDVideo();
281  else if (m_testType == ttStandardDefinition)
282  testSDVideo();
283  }
284  else
285  {
286  ShowOkPopup(tr("Error downloading sample to backend."));
287  }
288  }
289  }
290  }
291  }
292 }
MythUIButton::Clicked
void Clicked()
StorageGroup::generate_file_url
static QString generate_file_url(const QString &storage_group, const QString &host, const QString &path)
Definition: storagegroup.cpp:895
VideoSetupWizard::m_generalScreen
MythScreenType * m_generalScreen
Definition: setupwizard_video.h:46
VideoSetupWizard::~VideoSetupWizard
~VideoSetupWizard() override
Definition: setupwizard_video.cpp:89
build_compdb.args
args
Definition: build_compdb.py:11
MythUIProgressDialog::Create
bool Create(void) override
Definition: mythprogressdialog.cpp:132
VIDEO_SAMPLE_HD_LOCATION
const QString VIDEO_SAMPLE_HD_LOCATION
Definition: setupwizard_video.cpp:22
build_compdb.dest
dest
Definition: build_compdb.py:9
MythUIButtonList::GetItemCurrent
MythUIButtonListItem * GetItemCurrent() const
Definition: mythuibuttonlist.cpp:1614
MythCoreContext::GetMasterHostName
QString GetMasterHostName(void)
Definition: mythcorecontext.cpp:813
VideoSetupWizard::playVideoTest
void playVideoTest(const QString &desc, const QString &title, const QString &file)
Definition: setupwizard_video.cpp:203
MythEvent::kMythEventMessage
static const Type kMythEventMessage
Definition: mythevent.h:79
VideoSetupWizard::ttHighDefinition
@ ttHighDefinition
Definition: setupwizard_video.h:39
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:384
RemoteFile::Exists
static bool Exists(const QString &url, struct stat *fileinfo)
Definition: remotefile.cpp:461
VideoSetupWizard::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: setupwizard_video.cpp:144
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:138
VideoSetupWizard::testSDVideo
void testSDVideo(void)
Definition: setupwizard_video.cpp:157
VideoSetupWizard::initProgressDialog
void initProgressDialog()
Definition: setupwizard_video.cpp:220
VIDEO_SAMPLE_HD_FILENAME
const QString VIDEO_SAMPLE_HD_FILENAME
Definition: setupwizard_video.cpp:26
VIDEO_SAMPLE_SD_FILENAME
const QString VIDEO_SAMPLE_SD_FILENAME
Definition: setupwizard_video.cpp:28
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:42
setupwizard_general.h
MythScreenStack
Definition: mythscreenstack.h:16
mythdbcon.h
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
VideoSetupWizard::save
void save(void)
Definition: setupwizard_video.cpp:132
build_compdb.file
file
Definition: build_compdb.py:55
mythdirs.h
MythUIProgressDialog::SetMessage
void SetMessage(const QString &message)
Definition: mythprogressdialog.cpp:209
setupwizard_video.h
remoteutil.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:1496
VideoSetupWizard::customEvent
void customEvent(QEvent *e) override
Definition: setupwizard_video.cpp:237
VIDEO_SAMPLE_SD_LOCATION
const QString VIDEO_SAMPLE_SD_LOCATION
Definition: setupwizard_video.cpp:24
MythUIButtonList::GetItemByData
MythUIButtonListItem * GetItemByData(const QVariant &data)
Definition: mythuibuttonlist.cpp:1708
VideoSetupWizard::ttStandardDefinition
@ ttStandardDefinition
Definition: setupwizard_video.h:40
MythScreenType::GetFocusWidget
MythUIType * GetFocusWidget(void) const
Definition: mythscreentype.cpp:111
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:875
mythlogging.h
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:203
MythUIType::SetHelpText
void SetHelpText(const QString &text)
Definition: mythuitype.h:175
VideoSetupWizard::slotPrevious
void slotPrevious(void)
Definition: setupwizard_video.cpp:139
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:204
MythUIButton
A single button widget.
Definition: mythuibutton.h:21
VideoSetupWizard::m_progressDialog
MythUIProgressDialog * m_progressDialog
Definition: setupwizard_video.h:51
storagegroup.h
VideoSetupWizard::VideoSetupWizard
VideoSetupWizard(MythScreenStack *parent, MythScreenType *general, MythScreenType *audio, const char *name=nullptr)
Definition: setupwizard_video.cpp:31
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:57
MythVideoProfile::SetDefaultProfileName
static void SetDefaultProfileName(const QString &ProfileName, const QString &HostName)
Definition: mythvideoprofile.cpp:913
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:3368
VideoSetupWizard::m_testType
TestType m_testType
Definition: setupwizard_video.h:44
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:402
mythcorecontext.h
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:701
MythUIProgressDialog::SetTotal
void SetTotal(uint total)
Definition: mythprogressdialog.cpp:197
MythVideoProfile::GetDefaultProfileName
static QString GetDefaultProfileName(const QString &HostName)
Definition: mythvideoprofile.cpp:894
VideoSetupWizard::slotNext
void slotNext(void)
Definition: setupwizard_video.cpp:113
VideoSetupWizard::testHDVideo
void testHDVideo(void)
Definition: setupwizard_video.cpp:180
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
MythUIButtonList::SetItemCurrent
void SetItemCurrent(MythUIButtonListItem *item)
Definition: mythuibuttonlist.cpp:1581
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:322
RemoteDownloadFile
QString RemoteDownloadFile(const QString &url, const QString &storageGroup, const QString &filename)
Definition: remoteutil.cpp:609
MythCoreContext::GetHostName
QString GetHostName(void)
Definition: mythcorecontext.cpp:844
VideoSetupWizard::m_testSDButton
MythUIButton * m_testSDButton
Definition: setupwizard_video.h:53
VideoSetupWizard::loadData
void loadData(void)
Definition: setupwizard_video.cpp:94
VideoSetupWizard::DownloadSample
void DownloadSample(const QString &url, const QString &dest)
Definition: setupwizard_video.cpp:214
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:52
ShowOkPopup
MythConfirmationDialog * ShowOkPopup(const QString &message, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
Definition: mythdialogbox.cpp:566
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
VideoSetupWizard::m_popupStack
MythScreenStack * m_popupStack
Definition: setupwizard_video.h:50