MythTV  master
setupwizard_video.cpp
Go to the documentation of this file.
1 // qt
2 #include <QString>
3 #include <QVariant>
4 #include <QFileInfo>
5 
6 // myth
7 #include "mythcontext.h"
8 #include "mythdbcon.h"
9 #include "mythdirs.h"
10 #include "mythprogressdialog.h"
11 #include "mythcoreutil.h"
12 #include "videoutils.h"
13 #include "remotefile.h"
14 
15 #include "setupwizard_general.h"
16 #include "setupwizard_audio.h"
17 #include "setupwizard_video.h"
18 
19 const QString VIDEO_SAMPLE_HD_LOCATION =
20  QString("http://services.mythtv.org/samples/video/?sample=HD");
21 const QString VIDEO_SAMPLE_SD_LOCATION =
22  QString("http://services.mythtv.org/samples/video/?sample=SD");
23 const QString VIDEO_SAMPLE_HD_FILENAME =
24  QString("mythtv_video_test_HD_19000Kbps_H264.mkv");
25 const QString VIDEO_SAMPLE_SD_FILENAME =
26  QString("mythtv_video_test_SD_6000Kbps_H264.mkv");
27 
29  MythScreenType *general,
30  MythScreenType *audio, const char *name)
31  : MythScreenType(parent, name),
32  m_generalScreen(general), m_audioScreen(audio)
33 {
34  m_popupStack = GetMythMainWindow()->GetStack("popup stack");
35 
37 }
38 
40 {
41  // Load the theme for this screen
42  bool foundtheme = LoadWindowFromXML("config-ui.xml", "videowizard", this);
43  if (!foundtheme)
44  return false;
45 
47  dynamic_cast<MythUIButtonList *> (GetChild("playbackprofiles"));
48 
49  m_testSDButton = dynamic_cast<MythUIButton *> (GetChild("testsd"));
50  m_testHDButton = dynamic_cast<MythUIButton *> (GetChild("testhd"));
51 
52  m_nextButton = dynamic_cast<MythUIButton *> (GetChild("next"));
53  m_prevButton = dynamic_cast<MythUIButton *> (GetChild("previous"));
54 
57  {
58  LOG(VB_GENERAL, LOG_ERR, "Theme is missing critical theme elements.");
59  return false;
60  }
61 
62  m_playbackProfileButtonList->SetHelpText( tr("Select from one of the "
63  "preconfigured playback profiles. When "
64  "satisfied, you can test Standard Definition "
65  "and High Definition playback with the selected "
66  "profile before moving on.") );
67  m_testSDButton->SetHelpText( tr("Test your playback settings with Standard "
68  "Definition content. (480p)") );
69  m_testHDButton->SetHelpText( tr("Test your playback settings with High "
70  "Definition content (1080p).") );
71  m_nextButton->SetHelpText( tr("Save these changes and move on to the "
72  "next configuration step.") );
73  m_prevButton->SetHelpText(tr("Return to the previous configuration step."));
74 
75  connect(m_testSDButton, SIGNAL(Clicked()), this, SLOT(testSDVideo()));
76  connect(m_testHDButton, SIGNAL(Clicked()), this, SLOT(testHDVideo()));
77  connect(m_nextButton, SIGNAL(Clicked()), this, SLOT(slotNext()));
78  connect(m_prevButton, SIGNAL(Clicked()), this, SLOT(slotPrevious()));
79 
81  loadData();
82 
83  return true;
84 }
85 
87 {
89 }
90 
92 {
94 
95  for (QStringList::const_iterator i = profiles.begin();
96  i != profiles.end(); ++i)
97  {
99  item->SetData(*i);
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  QStringList tokens = me->Message().split(" ", QString::SkipEmptyParts);
240  if (tokens.isEmpty())
241  return;
242 
243  if (tokens[0] == "DOWNLOAD_FILE")
244  {
245  QStringList args = me->ExtraDataList();
246  if ((tokens.size() != 2) ||
247  (args[1] != m_downloadFile))
248  return;
249 
250  if (tokens[1] == "UPDATE")
251  {
252  QString message = tr("Downloading Video Sample...\n"
253  "(%1 of %2 MB)")
254  .arg(QString::number(args[2].toInt() / 1024.0 / 1024.0, 'f', 2))
255  .arg(QString::number(args[3].toInt() / 1024.0 / 1024.0, 'f', 2));
256  m_progressDialog->SetMessage(message);
257  m_progressDialog->SetTotal(args[3].toInt());
258  m_progressDialog->SetProgress(args[2].toInt());
259  }
260  else if (tokens[1] == "FINISHED")
261  {
262  int fileSize = args[2].toInt();
263  int errorCode = args[4].toInt();
264 
265  if (m_progressDialog)
267 
268  QFileInfo file(m_downloadFile);
269  if ((m_downloadFile.startsWith("myth://")))
270  {
271  if ((errorCode == 0) &&
272  (fileSize > 0))
273  {
275  testHDVideo();
276  else if (m_testType == ttStandardDefinition)
277  testSDVideo();
278  }
279  else
280  {
281  ShowOkPopup(tr("Error downloading sample to backend."));
282  }
283  }
284  }
285  }
286  }
287 }
void SetMessage(const QString &message)
VideoSetupWizard(MythScreenStack *parent, MythScreenType *general, MythScreenType *audio, const char *name=nullptr)
void SetProgress(uint count)
MythConfirmationDialog * ShowOkPopup(const QString &message, QObject *parent, const char *slot, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
bool Create(void) override
static Type MythEventMessage
Definition: mythevent.h:73
void removeListener(QObject *listener)
Remove a listener to the observable.
static void SetDefaultProfileName(const QString &ProfileName, const QString &HostName)
MythScreenStack * GetStack(const QString &stackname)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
void addListener(QObject *listener)
Add a listener to the observable.
void BuildFocusList(void)
MythUIButton * m_testSDButton
const QString VIDEO_SAMPLE_SD_FILENAME
MythUIButton * m_prevButton
~VideoSetupWizard() override
virtual void Close()
const QString VIDEO_SAMPLE_HD_LOCATION
MythUIButtonListItem * GetItemByData(const QVariant &data)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
void SetHelpText(const QString &text)
Definition: mythuitype.h:150
MythScreenType * m_generalScreen
void playVideoTest(const QString &desc, const QString &title, const QString &file)
MythScreenType * m_audioScreen
MythScreenStack * m_popupStack
void DownloadSample(const QString &url, const QString &dest)
static QString GetDefaultProfileName(const QString &HostName)
const QString VIDEO_SAMPLE_HD_FILENAME
QString GetMasterHostName(void)
MythUIButton * m_testHDButton
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
MythUIType * GetFocusWidget(void) const
const QString VIDEO_SAMPLE_SD_LOCATION
MythMainWindow * GetMythMainWindow(void)
QString GetText(const QString &name="") const
QString RemoteDownloadFile(const QString &url, const QString &storageGroup, const QString &filename)
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
static bool Exists(const QString &url, struct stat *fileinfo)
Definition: remotefile.cpp:460
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
void customEvent(QEvent *e) override
static QStringList GetProfiles(const QString &HostName)
QString generate_file_url(const QString &storage_group, const QString &host, const QString &path)
Definition: videoutils.h:65
void SetItemCurrent(MythUIButtonListItem *item)
bool Create(void) override
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="", int lenMins=120, const QString &year="1895", const QString &id="", bool useBookmarks=false)
MythUIButtonList * m_playbackProfileButtonList
Screen in which all other widgets are contained and rendered.
QString GetHostName(void)
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:130
MythUIProgressDialog * m_progressDialog
MythUIButtonListItem * GetItemCurrent() const
MythUIButton * m_nextButton