00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <qapplication.h>
00015 #include <qstringlist.h>
00016 #include <qpixmap.h>
00017
00018 #include <unistd.h>
00019 #include <cstdlib>
00020
00021 #include <mythtv/mythcontext.h>
00022 #include <mythtv/xmlparse.h>
00023
00024 #include "videoselected.h"
00025
00026 #include "metadata.h"
00027 #include "videolist.h"
00028 #include "videoutils.h"
00029 #include "imagecache.h"
00030
00031 VideoSelected::VideoSelected(const VideoList *video_list,
00032 MythMainWindow *lparent, const QString &lname,
00033 int index) :
00034 MythDialog(lparent, lname), noUpdate(false), m_state(0),
00035 allowselect(false), m_video_list(video_list)
00036 {
00037 m_item = m_video_list->getVideoListMetadata(index);
00038
00039 fullRect = QRect(0, 0, size().width(), size().height());
00040
00041 theme.reset(new XMLParse());
00042 theme->SetWMult(wmult);
00043 theme->SetHMult(hmult);
00044 theme->LoadTheme(xmldata, "selected", "video-");
00045 LoadWindow(xmldata);
00046
00047 bgTransBackup.reset(gContext->LoadScalePixmap("trans-backup.png"));
00048 if (!bgTransBackup.get())
00049 bgTransBackup.reset(new QPixmap());
00050
00051 updateBackground();
00052
00053 setNoErase();
00054 }
00055
00056 VideoSelected::~VideoSelected()
00057 {
00058 }
00059
00060 void VideoSelected::processEvents()
00061 {
00062 qApp->processEvents();
00063 }
00064
00065 void VideoSelected::keyPressEvent(QKeyEvent *e)
00066 {
00067 bool handled = false;
00068 QStringList actions;
00069 gContext->GetMainWindow()->TranslateKeyPress("Video", e, actions);
00070
00071 for (unsigned int i = 0; i < actions.size() && !handled; i++)
00072 {
00073 QString action = actions[i];
00074
00075
00076 if (action == "SELECT" && allowselect)
00077 {
00078 handled = true;
00079 startPlayItem();
00080 return;
00081
00082 }
00083 }
00084
00085 if (!handled)
00086 {
00087 gContext->GetMainWindow()->TranslateKeyPress("TV Frontend", e, actions);
00088
00089 for (unsigned int i = 0; i < actions.size() && !handled; i++)
00090 {
00091 if (actions[i] == "PLAYBACK")
00092 {
00093 handled = true;
00094 startPlayItem();
00095 }
00096 }
00097 }
00098
00099 if (!handled)
00100 MythDialog::keyPressEvent(e);
00101 }
00102
00103 void VideoSelected::updateBackground(void)
00104 {
00105 QPixmap bground(size());
00106 bground.fill(this, 0, 0);
00107
00108 QPainter tmp(&bground);
00109
00110 LayerSet *container = theme->GetSet("background");
00111 if (container)
00112 container->Draw(&tmp, 0, 0);
00113
00114 tmp.end();
00115 myBackground = bground;
00116
00117 setPaletteBackgroundPixmap(myBackground);
00118 }
00119
00120 void VideoSelected::paintEvent(QPaintEvent *e)
00121 {
00122 QRect r = e->rect();
00123 QPainter p(this);
00124
00125 if (m_state == 0)
00126 {
00127 if (r.intersects(infoRect) && noUpdate == false)
00128 {
00129 updateInfo(&p);
00130 }
00131 }
00132 else if (m_state > 0)
00133 {
00134 noUpdate = true;
00135 updatePlayWait(&p);
00136 }
00137 }
00138
00139 namespace
00140 {
00141 const int kMythVideoStartPlayEventType = 301976;
00142 }
00143
00144 void VideoSelected::customEvent(QCustomEvent *e)
00145 {
00146 if (e->type() == kMythVideoStartPlayEventType)
00147 {
00148 if (m_item)
00149 PlayVideo(m_item->Filename(), m_video_list->getListCache());
00150 ++m_state;
00151 update(fullRect);
00152 }
00153 }
00154
00155 void VideoSelected::updatePlayWait(QPainter *p)
00156 {
00157 if (m_state < 4)
00158 {
00159
00160 LayerSet *container = theme->GetSet("playwait");
00161 if (container)
00162 {
00163 QRect area = container->GetAreaRect();
00164 if (area.isValid())
00165 {
00166 QPixmap pix(area.size());
00167 pix.fill(this, area.topLeft());
00168 QPainter tmp(&pix);
00169
00170 for (int i = 0; i < 4; ++i)
00171 container->Draw(&tmp, i, 0);
00172
00173 tmp.end();
00174
00175 p->drawPixmap(area.topLeft(), pix);
00176 }
00177 else
00178 {
00179 VERBOSE(VB_IMPORTANT,
00180 QObject::tr("Theme Error: selected/playwait "
00181 "has an invalid area."));
00182 }
00183 }
00184
00185 m_state++;
00186 update(fullRect);
00187 }
00188 else if (m_state == 4)
00189 {
00190 update(fullRect);
00191
00192 ++m_state;
00193 QApplication::postEvent(this,
00194 new QCustomEvent(kMythVideoStartPlayEventType));
00195 }
00196 else if (m_state == 5)
00197 {
00198
00199 }
00200 else if (m_state == 6)
00201 {
00202 noUpdate = false;
00203
00204 gContext->GetMainWindow()->raise();
00205 gContext->GetMainWindow()->setActiveWindow();
00206 if (gContext->GetMainWindow()->currentWidget())
00207 gContext->GetMainWindow()->currentWidget()->setFocus();
00208
00209 m_state = 0;
00210 update(fullRect);
00211 }
00212 }
00213
00214 void VideoSelected::updateInfo(QPainter *p)
00215 {
00216 QRect pr = infoRect;
00217 QPixmap pix(pr.size());
00218 pix.fill(this, pr.topLeft());
00219 QPainter tmp(&pix);
00220
00221 if (m_item)
00222 {
00223 LayerSet *container = theme->GetSet("info");
00224 if (container)
00225 {
00226 checkedSetText(container, "title", m_item->Title());
00227 checkedSetText(container, "filename", m_item->Filename());
00228
00229 QString coverfile = m_item->CoverFile();
00230 UIImageType *itype = (UIImageType *)container->GetType("coverart");
00231 if (itype)
00232 {
00233 if (isDefaultCoverFile(coverfile))
00234 {
00235 if (itype->isShown())
00236 itype->hide();
00237 }
00238 else
00239 {
00240 QSize img_size = itype->GetSize(true);
00241 const QPixmap *img =
00242 ImageCache::getImageCache().load(coverfile,
00243 img_size.width(),
00244 img_size.height(),
00245 QImage::ScaleFree);
00246
00247 if (img)
00248 {
00249 if (itype->GetImage().serialNumber() !=
00250 img->serialNumber())
00251 {
00252 itype->SetImage(*img);
00253 }
00254 if (itype->isHidden())
00255 itype->show();
00256 }
00257 else
00258 {
00259 if (itype->isShown())
00260 itype->hide();
00261 }
00262 }
00263 }
00264
00265 checkedSetText(container, "video_player",
00266 Metadata::getPlayer(m_item));
00267 checkedSetText(container, "director", m_item->Director());
00268 checkedSetText(container, "plot", m_item->Plot());
00269 checkedSetText(container, "cast", GetCast(*m_item));
00270 checkedSetText(container, "rating",
00271 getDisplayRating(m_item->Rating()));
00272 checkedSetText(container, "inetref", m_item->InetRef());
00273 checkedSetText(container, "year", getDisplayYear(m_item->Year()));
00274 checkedSetText(container, "userrating",
00275 getDisplayUserRating(m_item->UserRating()));
00276 checkedSetText(container, "length",
00277 getDisplayLength(m_item->Length()));
00278 checkedSetText(container, "coverfile", m_item->CoverFile());
00279 checkedSetText(container, "child_id",
00280 QString::number(m_item->ChildID()));
00281 checkedSetText(container, "browseable",
00282 getDisplayBrowse(m_item->Browse()));
00283 checkedSetText(container, "category", m_item->Category());
00284 checkedSetText(container, "level",
00285 QString::number(m_item->ShowLevel()));
00286
00287 for (int i = 1; i < 9; ++i)
00288 container->Draw(&tmp, i, 0);
00289 }
00290
00291 allowselect = true;
00292 }
00293 else
00294 {
00295
00296 LayerSet *norec = theme->GetSet("novideos_info");
00297 if (norec)
00298 {
00299 for (int i = 4; i < 9; ++i)
00300 norec->Draw(&tmp, i, 0);
00301 }
00302
00303 allowselect = false;
00304 }
00305 tmp.end();
00306 p->drawPixmap(pr.topLeft(), pix);
00307 }
00308
00309 void VideoSelected::LoadWindow(QDomElement &element)
00310 {
00311
00312 for (QDomNode lchild = element.firstChild(); !lchild.isNull();
00313 lchild = lchild.nextSibling())
00314 {
00315 QDomElement e = lchild.toElement();
00316 if (!e.isNull())
00317 {
00318 if (e.tagName() == "font")
00319 {
00320 theme->parseFont(e);
00321 }
00322 else if (e.tagName() == "container")
00323 {
00324 parseContainer(e);
00325 }
00326 else
00327 {
00328 VERBOSE(VB_IMPORTANT,
00329 QString("Unknown element: ").arg(e.tagName()));
00330 exit(0);
00331 }
00332 }
00333 }
00334 }
00335
00336 void VideoSelected::parseContainer(QDomElement &element)
00337 {
00338 QRect area;
00339 QString container_name;
00340 int context;
00341 theme->parseContainer(element, container_name, context, area);
00342
00343 if (container_name.lower() == "info")
00344 infoRect = area;
00345 }
00346
00347 void VideoSelected::exitWin()
00348 {
00349 emit accept();
00350 }
00351
00352 void VideoSelected::startPlayItem()
00353 {
00354 LayerSet *container = theme->GetSet("playwait");
00355 if (container)
00356 {
00357 checkedSetText(container, "title", m_item->Title());
00358 }
00359 m_state = 1;
00360 update(fullRect);
00361 }