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  {
98  MythUIButtonListItem *item =
100  item->SetData(*i);
101  }
102 
104  if (!currentpbp.isEmpty())
105  {
106  MythUIButtonListItem *set =
109  }
110 }
111 
113 {
114  save();
115 
116  if (m_audioScreen)
117  {
118  m_audioScreen->Close();
119  m_audioScreen = nullptr;
120  }
121 
122  if (m_generalScreen)
123  {
125  m_generalScreen = nullptr;
126  }
127 
128  Close();
129 }
130 
132 {
133  QString desiredpbp =
136 }
137 
139 {
140  Close();
141 }
142 
143 bool VideoSetupWizard::keyPressEvent(QKeyEvent *event)
144 {
145  if (GetFocusWidget()->keyPressEvent(event))
146  return true;
147 
148  bool handled = false;
149 
151  handled = true;
152 
153  return handled;
154 }
155 
157 {
158  QString sdtestfile = generate_file_url("Temp",
161  QString desiredpbp =
163  QString desc = tr("A short test of your system's playback of "
164  "Standard Definition content with the %1 profile.")
165  .arg(desiredpbp);
166  QString title = tr("Standard Definition Playback Test");
167 
168  if (!RemoteFile::Exists(sdtestfile))
169  {
172  }
173  else
174  playVideoTest(desc, title, sdtestfile);
175 }
176 
178 {
179  QString hdtestfile = generate_file_url("Temp",
182  QString desiredpbp =
184  QString desc = tr("A short test of your system's playback of "
185  "High Definition content with the %1 profile.")
186  .arg(desiredpbp);
187  QString title = tr("High Definition Playback Test");
188 
189  if (!RemoteFile::Exists(hdtestfile))
190  {
193  }
194  else
195  playVideoTest(desc, title, hdtestfile);
196 }
197 
198 void VideoSetupWizard::playVideoTest(const QString& desc, const QString& title, const QString& file)
199 {
200  QString desiredpbp =
203 
205  GetMythMainWindow()->HandleMedia("Internal", file, desc, title);
207 }
208 
209 void VideoSetupWizard::DownloadSample(const QString& url, const QString& dest)
210 {
212  m_downloadFile = RemoteDownloadFile(url, "Temp", dest);
213 }
214 
216 {
217  QString message = tr("Downloading Video Sample...");
219  m_popupStack, "sampledownloadprogressdialog");
220 
221  if (m_progressDialog->Create())
222  {
224  }
225  else
226  {
227  delete m_progressDialog;
228  m_progressDialog = nullptr;
229  }
230 }
231 
233 {
234  if (e->type() == MythEvent::MythEventMessage)
235  {
236  MythEvent *me = static_cast<MythEvent *>(e);
237  QStringList tokens = me->Message().split(" ", QString::SkipEmptyParts);
238 
239  if (tokens.isEmpty())
240  return;
241 
242  if (tokens[0] == "DOWNLOAD_FILE")
243  {
244  QStringList args = me->ExtraDataList();
245  if ((tokens.size() != 2) ||
246  (args[1] != m_downloadFile))
247  return;
248 
249  if (tokens[1] == "UPDATE")
250  {
251  QString message = tr("Downloading Video Sample...\n"
252  "(%1 of %2 MB)")
253  .arg(QString::number(args[2].toInt() / 1024.0 / 1024.0, 'f', 2))
254  .arg(QString::number(args[3].toInt() / 1024.0 / 1024.0, 'f', 2));
255  m_progressDialog->SetMessage(message);
256  m_progressDialog->SetTotal(args[3].toInt());
257  m_progressDialog->SetProgress(args[2].toInt());
258  }
259  else if (tokens[1] == "FINISHED")
260  {
261  int fileSize = args[2].toInt();
262  int errorCode = args[4].toInt();
263 
264  if (m_progressDialog)
266 
267  QFileInfo file(m_downloadFile);
268  if ((m_downloadFile.startsWith("myth://")))
269  {
270  if ((errorCode == 0) &&
271  (fileSize > 0))
272  {
274  testHDVideo();
275  else if (m_testType == ttStandardDefinition)
276  testSDVideo();
277  }
278  else
279  {
280  ShowOkPopup(tr("Error downloading sample to backend."));
281  }
282  }
283  }
284  }
285  }
286 }
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
void SetData(QVariant data)
static Type MythEventMessage
Definition: mythevent.h:66
static void SetDefaultProfileName(const QString &profilename, const QString &hostname)
void removeListener(QObject *listener)
Remove a listener to the observable.
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
virtual void Close()
const QString VIDEO_SAMPLE_HD_LOCATION
MythUIButtonListItem * GetItemByData(const QVariant &data)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
bool keyPressEvent(QKeyEvent *) override
Key event handler.
This class is used as a container for messages.
Definition: mythevent.h:16
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)
const QString VIDEO_SAMPLE_HD_FILENAME
static QString GetDefaultProfileName(const QString &hostname)
QString GetMasterHostName(void)
MythUIButton * m_testHDButton
const char * name
Definition: ParseText.cpp:328
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)
static bool Exists(const QString &url, struct stat *fileinfo)
Definition: remotefile.cpp:461
bool keyPressEvent(QKeyEvent *) override
Key event handler.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
void customEvent(QEvent *e) override
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
static QStringList GetProfiles(const QString &hostname)
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.
const QString & Message() const
Definition: mythevent.h:58
QString GetHostName(void)
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:132
const QStringList & ExtraDataList() const
Definition: mythevent.h:60
MythUIProgressDialog * m_progressDialog
MythUIButtonListItem * GetItemCurrent() const
MythUIButton * m_nextButton