00001
00002 #include <QString>
00003 #include <QVariant>
00004 #include <QFileInfo>
00005
00006
00007 #include "mythcontext.h"
00008 #include "mythdbcon.h"
00009 #include "mythdirs.h"
00010 #include "mythprogressdialog.h"
00011 #include "mythcoreutil.h"
00012 #include "videoutils.h"
00013 #include "remotefile.h"
00014
00015 #include "setupwizard_general.h"
00016 #include "setupwizard_audio.h"
00017 #include "setupwizard_video.h"
00018
00019 const QString VIDEO_SAMPLE_HD_LOCATION =
00020 QString("http://services.mythtv.org/samples/video/?sample=HD");
00021 const QString VIDEO_SAMPLE_SD_LOCATION =
00022 QString("http://services.mythtv.org/samples/video/?sample=SD");
00023 const QString VIDEO_SAMPLE_HD_FILENAME =
00024 QString("mythtv_video_test_HD_19000Kbps_H264.mkv");
00025 const QString VIDEO_SAMPLE_SD_FILENAME =
00026 QString("mythtv_video_test_SD_6000Kbps_H264.mkv");
00027
00028 VideoSetupWizard::VideoSetupWizard(MythScreenStack *parent,
00029 MythScreenType *general,
00030 MythScreenType *audio, const char *name)
00031 : MythScreenType(parent, name), m_downloadFile(QString()),
00032 m_testType(ttNone),
00033 m_generalScreen(general), m_audioScreen(audio),
00034 m_playbackProfileButtonList(NULL), m_testSDButton(NULL),
00035 m_testHDButton(NULL), m_nextButton(NULL),
00036 m_prevButton(NULL)
00037 {
00038 m_popupStack = GetMythMainWindow()->GetStack("popup stack");
00039 m_vdp = new VideoDisplayProfile();
00040
00041 gCoreContext->addListener(this);
00042 }
00043
00044 bool VideoSetupWizard::Create()
00045 {
00046 bool foundtheme = false;
00047
00048
00049 foundtheme = LoadWindowFromXML("config-ui.xml", "videowizard", this);
00050
00051 if (!foundtheme)
00052 return false;
00053
00054 m_playbackProfileButtonList =
00055 dynamic_cast<MythUIButtonList *> (GetChild("playbackprofiles"));
00056
00057 m_testSDButton = dynamic_cast<MythUIButton *> (GetChild("testsd"));
00058 m_testHDButton = dynamic_cast<MythUIButton *> (GetChild("testhd"));
00059
00060 m_nextButton = dynamic_cast<MythUIButton *> (GetChild("next"));
00061 m_prevButton = dynamic_cast<MythUIButton *> (GetChild("previous"));
00062
00063 if (!m_playbackProfileButtonList || !m_testSDButton ||
00064 !m_testHDButton ||!m_nextButton || !m_prevButton)
00065 {
00066 LOG(VB_GENERAL, LOG_ERR, "Theme is missing critical theme elements.");
00067 return false;
00068 }
00069
00070 m_playbackProfileButtonList->SetHelpText( tr("Select from one of the "
00071 "preconfigured playback profiles. When "
00072 "satisfied, you can test Standard Definition "
00073 "and High Definition playback with the selected "
00074 "profile before moving on.") );
00075 m_testSDButton->SetHelpText( tr("Test your playback settings with Standard "
00076 "Definition content. (480p)") );
00077 m_testHDButton->SetHelpText( tr("Test your playback settings with High "
00078 "Definition content (1080p).") );
00079 m_nextButton->SetHelpText( tr("Save these changes and move on to the "
00080 "next configuration step.") );
00081 m_prevButton->SetHelpText(tr("Return to the previous configuration step."));
00082
00083 connect(m_testSDButton, SIGNAL(Clicked()), this, SLOT(testSDVideo()));
00084 connect(m_testHDButton, SIGNAL(Clicked()), this, SLOT(testHDVideo()));
00085 connect(m_nextButton, SIGNAL(Clicked()), this, SLOT(slotNext()));
00086 connect(m_prevButton, SIGNAL(Clicked()), this, SLOT(slotPrevious()));
00087
00088 BuildFocusList();
00089 loadData();
00090
00091 return true;
00092 }
00093
00094 VideoSetupWizard::~VideoSetupWizard()
00095 {
00096 if (m_vdp)
00097 delete m_vdp;
00098
00099 gCoreContext->removeListener(this);
00100 }
00101
00102 void VideoSetupWizard::loadData(void)
00103 {
00104 QStringList profiles = m_vdp->GetProfiles(gCoreContext->GetHostName());
00105
00106 for (QStringList::const_iterator i = profiles.begin();
00107 i != profiles.end(); ++i)
00108 {
00109 MythUIButtonListItem *item =
00110 new MythUIButtonListItem(m_playbackProfileButtonList, *i);
00111 item->SetData(*i);
00112 }
00113
00114 QString currentpbp = m_vdp->GetDefaultProfileName(gCoreContext->GetHostName());
00115 if (!currentpbp.isEmpty())
00116 {
00117 MythUIButtonListItem *set =
00118 m_playbackProfileButtonList->GetItemByData(currentpbp);
00119 m_playbackProfileButtonList->SetItemCurrent(set);
00120 }
00121 }
00122
00123 void VideoSetupWizard::slotNext(void)
00124 {
00125 save();
00126
00127 if (m_audioScreen)
00128 {
00129 m_audioScreen->Close();
00130 m_audioScreen = NULL;
00131 }
00132
00133 if (m_generalScreen)
00134 {
00135 m_generalScreen->Close();
00136 m_generalScreen = NULL;
00137 }
00138
00139 Close();
00140 }
00141
00142 void VideoSetupWizard::save(void)
00143 {
00144 QString desiredpbp =
00145 m_playbackProfileButtonList->GetItemCurrent()->GetText();
00146 m_vdp->SetDefaultProfileName(desiredpbp, gCoreContext->GetHostName());
00147 }
00148
00149 void VideoSetupWizard::slotPrevious(void)
00150 {
00151 Close();
00152 }
00153
00154 bool VideoSetupWizard::keyPressEvent(QKeyEvent *event)
00155 {
00156 if (GetFocusWidget()->keyPressEvent(event))
00157 return true;
00158
00159 bool handled = false;
00160
00161 if (!handled && MythScreenType::keyPressEvent(event))
00162 handled = true;
00163
00164 return handled;
00165 }
00166
00167 void VideoSetupWizard::testSDVideo(void)
00168 {
00169 QString sdtestfile = generate_file_url("Temp",
00170 gCoreContext->GetMasterHostName(),
00171 VIDEO_SAMPLE_SD_FILENAME);
00172 QString desiredpbp =
00173 m_playbackProfileButtonList->GetItemCurrent()->GetText();
00174 QString desc = tr("A short test of your system's playback of "
00175 "Standard Definition content with the %1 profile.")
00176 .arg(desiredpbp);
00177 QString title = tr("Standard Definition Playback Test");
00178
00179 if (!RemoteFile::Exists(sdtestfile))
00180 {
00181 m_testType = ttStandardDefinition;
00182 DownloadSample(VIDEO_SAMPLE_SD_LOCATION, VIDEO_SAMPLE_SD_FILENAME);
00183 }
00184 else
00185 playVideoTest(desc, title, sdtestfile);
00186 }
00187
00188 void VideoSetupWizard::testHDVideo(void)
00189 {
00190 QString hdtestfile = generate_file_url("Temp",
00191 gCoreContext->GetMasterHostName(),
00192 VIDEO_SAMPLE_HD_FILENAME);
00193 QString desiredpbp =
00194 m_playbackProfileButtonList->GetItemCurrent()->GetText();
00195 QString desc = tr("A short test of your system's playback of "
00196 "High Definition content with the %1 profile.")
00197 .arg(desiredpbp);
00198 QString title = tr("High Definition Playback Test");
00199
00200 if (!RemoteFile::Exists(hdtestfile))
00201 {
00202 m_testType = ttHighDefinition;
00203 DownloadSample(VIDEO_SAMPLE_HD_LOCATION, VIDEO_SAMPLE_HD_FILENAME);
00204 }
00205 else
00206 playVideoTest(desc, title, hdtestfile);
00207 }
00208
00209 void VideoSetupWizard::playVideoTest(QString desc, QString title, QString file)
00210 {
00211 QString desiredpbp =
00212 m_playbackProfileButtonList->GetItemCurrent()->GetText();
00213 QString currentpbp = m_vdp->GetDefaultProfileName(gCoreContext->GetHostName());
00214
00215 m_vdp->SetDefaultProfileName(desiredpbp, gCoreContext->GetHostName());
00216 GetMythMainWindow()->HandleMedia("Internal", file, desc, title);
00217 m_vdp->SetDefaultProfileName(currentpbp, gCoreContext->GetHostName());
00218 }
00219
00220 void VideoSetupWizard::DownloadSample(QString url, QString dest)
00221 {
00222 initProgressDialog();
00223 m_downloadFile = RemoteDownloadFile(url, "Temp", dest);
00224 }
00225
00226 void VideoSetupWizard::initProgressDialog()
00227 {
00228 QString message = tr("Downloading Video Sample...");
00229 m_progressDialog = new MythUIProgressDialog(message,
00230 m_popupStack, "sampledownloadprogressdialog");
00231
00232 if (m_progressDialog->Create())
00233 {
00234 m_popupStack->AddScreen(m_progressDialog, false);
00235 }
00236 else
00237 {
00238 delete m_progressDialog;
00239 m_progressDialog = NULL;
00240 }
00241 }
00242
00243 void VideoSetupWizard::customEvent(QEvent *e)
00244 {
00245 if ((MythEvent::Type)(e->type()) == MythEvent::MythEventMessage)
00246 {
00247 MythEvent *me = (MythEvent *)e;
00248 QStringList tokens = me->Message().split(" ", QString::SkipEmptyParts);
00249
00250 if (tokens.isEmpty())
00251 return;
00252
00253 if (tokens[0] == "DOWNLOAD_FILE")
00254 {
00255 QStringList args = me->ExtraDataList();
00256 if ((tokens.size() != 2) ||
00257 (args[1] != m_downloadFile))
00258 return;
00259
00260 if (tokens[1] == "UPDATE")
00261 {
00262 QString message = tr("Downloading Video Sample...\n"
00263 "(%1 of %2 MB)")
00264 .arg(QString::number(args[2].toInt() / 1024.0 / 1024.0, 'f', 2))
00265 .arg(QString::number(args[3].toInt() / 1024.0 / 1024.0, 'f', 2));
00266 m_progressDialog->SetMessage(message);
00267 m_progressDialog->SetTotal(args[3].toInt());
00268 m_progressDialog->SetProgress(args[2].toInt());
00269 }
00270 else if (tokens[1] == "FINISHED")
00271 {
00272 int fileSize = args[2].toInt();
00273 int errorCode = args[4].toInt();
00274
00275 if (m_progressDialog)
00276 m_progressDialog->Close();
00277
00278 QFileInfo file(m_downloadFile);
00279 if ((m_downloadFile.startsWith("myth://")))
00280 {
00281 if ((errorCode == 0) &&
00282 (fileSize > 0))
00283 {
00284 if (m_testType == ttHighDefinition)
00285 testHDVideo();
00286 else if (m_testType == ttStandardDefinition)
00287 testSDVideo();
00288 }
00289 else
00290 {
00291 ShowOkPopup(tr("Error downloading sample to backend."));
00292 }
00293 }
00294 }
00295 }
00296 }
00297 }