00001 #include <cstdlib>
00002
00003 #include <qapplication.h>
00004
00005 #include <mythtv/xmlparse.h>
00006 #include <mythtv/mythcontext.h>
00007
00008 #include "globals.h"
00009 #include "videodlg.h"
00010 #include "metadata.h"
00011 #include "videofilter.h"
00012 #include "videolist.h"
00013 #include "videoutils.h"
00014 #include "parentalcontrols.h"
00015 #include "videoui-common.h"
00016
00017 bool VideoDialog::IsValidDialogType(int num)
00018 {
00019 for (int i = 1; i <= dtLast - 1; i <<= 1)
00020 if (num == i) return true;
00021 return false;
00022 }
00023
00024 VideoDialog::VideoDialog(DialogType ltype, MythMainWindow *lparent,
00025 const QString &lwinName, const QString &lname,
00026 VideoList *video_list) :
00027 MythDialog(lparent, lname), curitem(NULL),
00028 popup(NULL), m_type(ltype), m_video_list(video_list), m_exit_type(0)
00029 {
00030
00031
00032
00033
00034 theme.reset(new XMLParse());
00035 theme->SetWMult(wmult);
00036 theme->SetHMult(hmult);
00037 if (!theme->LoadTheme(xmldata, lwinName, "video-"))
00038 {
00039 VERBOSE(VB_IMPORTANT,
00040 QString("VideoDialog: Couldn't find your theme. I'm outta here"
00041 " (%1-video-ui)").arg(lwinName));
00042 exit(0);
00043 }
00044
00045 expectingPopup = false;
00046 fullRect = QRect(0, 0, size().width(), size().height());
00047 allowPaint = true;
00048 currentParentalLevel.reset(new ParentalLevel(
00049 gContext->GetNumSetting("VideoDefaultParentalLevel", 1)));
00050
00051
00052
00053 if (!checkParentPassword(currentParentalLevel->GetLevel()))
00054 {
00055 *currentParentalLevel = ParentalLevel::plLowest;
00056 }
00057
00058 VideoFilterSettings video_filter(true, lwinName);
00059 m_video_list->setCurrentVideoFilter(video_filter);
00060
00061 isFileBrowser = false;
00062 isFlatList = false;
00063 video_tree_root = NULL;
00064 }
00065
00066 VideoDialog::~VideoDialog()
00067 {
00068 }
00069
00070 void VideoDialog::slotVideoBrowser()
00071 {
00072 jumpTo(JUMP_VIDEO_BROWSER);
00073 }
00074
00075 void VideoDialog::slotVideoGallery()
00076 {
00077 jumpTo(JUMP_VIDEO_GALLERY);
00078 }
00079
00080 void VideoDialog::slotVideoTree()
00081 {
00082 jumpTo(JUMP_VIDEO_TREE);
00083 }
00084
00085 void VideoDialog::slotDoCancel(void)
00086 {
00087 if (!expectingPopup)
00088 return;
00089
00090 cancelPopup();
00091 }
00092
00093 void VideoDialog::cancelPopup(void)
00094 {
00095 allowPaint = true;
00096 expectingPopup = false;
00097
00098 if (popup)
00099 {
00100 popup->deleteLater();
00101 popup = NULL;
00102
00103 update(fullRect);
00104 qApp->processEvents();
00105 setActiveWindow();
00106 }
00107 }
00108
00109 QButton *VideoDialog::AddPopupViews()
00110 {
00111 if (!popup)
00112 return NULL;
00113
00114 std::vector<QButton *> buttons;
00115
00116 if (!(m_type & DLG_BROWSER))
00117 buttons.push_back(popup->addButton(tr("Switch to Browse View"), this,
00118 SLOT(slotVideoBrowser())));
00119
00120 if (!(m_type & DLG_GALLERY))
00121 buttons.push_back(popup->addButton(tr("Switch to Gallery View"), this,
00122 SLOT(slotVideoGallery())));
00123
00124 if (!(m_type & DLG_TREE))
00125 buttons.push_back(popup->addButton(tr("Switch to List View"), this,
00126 SLOT(slotVideoTree())));
00127
00128 return buttons.size() ? buttons[0] : NULL;
00129 }
00130
00131 bool VideoDialog::createPopup()
00132 {
00133 if (!popup)
00134 {
00135 allowPaint = false;
00136 popup = new MythPopupBox(gContext->GetMainWindow(), "video popup");
00137
00138 expectingPopup = true;
00139
00140 popup->addLabel(tr("Select action"));
00141 popup->addLabel("");
00142 }
00143
00144 return (popup != NULL);
00145 }
00146
00147
00148 void VideoDialog::slotViewPlot()
00149 {
00150 cancelPopup();
00151
00152 if (curitem)
00153 {
00154 allowPaint = false;
00155 MythPopupBox * plotbox = new MythPopupBox(gContext->GetMainWindow());
00156
00157 QLabel *plotLabel = plotbox->addLabel(curitem->Plot(),
00158 MythPopupBox::Small,true);
00159 plotLabel->setAlignment(Qt::AlignJustify | Qt::WordBreak);
00160
00161 QButton *okButton = plotbox->addButton(
00162 tr("OK"), plotbox, SLOT(accept()));
00163 okButton->setFocus();
00164
00165 plotbox->ExecPopup();
00166 plotbox->deleteLater();
00167 allowPaint = true;
00168 }
00169 else
00170 {
00171 VERBOSE(VB_IMPORTANT, QString("no Item to view"));
00172 }
00173 }
00174
00175 void VideoDialog::slotViewCast()
00176 {
00177 cancelPopup();
00178
00179 if (curitem)
00180 {
00181 allowPaint = false;
00182 ShowCastDialog(gContext->GetMainWindow(), *curitem);
00183 allowPaint = true;
00184 }
00185 else
00186 {
00187 VERBOSE(VB_IMPORTANT, QString("no item to view"));
00188 }
00189 }
00190
00191 void VideoDialog::slotWatchVideo()
00192 {
00193 cancelPopup();
00194
00195 if (curitem)
00196 playVideo(curitem);
00197 else
00198 VERBOSE(VB_IMPORTANT, QString("no Item to watch"));
00199 }
00200
00201 void VideoDialog::playVideo(Metadata *someItem)
00202 {
00203
00204 LayerSet *container = theme->GetSet("playwait");
00205 if (container)
00206 {
00207 checkedSetText(container, "title", someItem->Title());
00208 }
00209 update(fullRect);
00210 allowPaint = false;
00211
00212 PlayVideo(someItem->Filename(), m_video_list->getListCache());
00213
00214 gContext->GetMainWindow()->raise();
00215 gContext->GetMainWindow()->setActiveWindow();
00216 if (gContext->GetMainWindow()->currentWidget())
00217 gContext->GetMainWindow()->currentWidget()->setFocus();
00218
00219 allowPaint = true;
00220
00221 update(fullRect);
00222 }
00223
00224 void VideoDialog::setParentalLevel(const ParentalLevel &which_level)
00225 {
00226 ParentalLevel::Level new_level = which_level.GetLevel();
00227 if (new_level == ParentalLevel::plNone)
00228 new_level = ParentalLevel::plLowest;
00229
00230 if (checkParentPassword(new_level, currentParentalLevel->GetLevel()) &&
00231 *currentParentalLevel != new_level)
00232 {
00233 *currentParentalLevel = new_level;
00234 fetchVideos();
00235 slotParentalLevelChanged();
00236 }
00237 }
00238
00239 void VideoDialog::shiftParental(int amount)
00240 {
00241 setParentalLevel(ParentalLevel(*currentParentalLevel) += amount);
00242 }
00243
00244 GenericTree *VideoDialog::getVideoTreeRoot(void)
00245 {
00246 return video_tree_root;
00247 }
00248
00249 void VideoDialog::fetchVideos()
00250 {
00251 video_tree_root = m_video_list->buildVideoList(isFileBrowser, isFlatList,
00252 *currentParentalLevel, true);
00253 }
00254
00255 void VideoDialog::slotDoFilter()
00256 {
00257 cancelPopup();
00258 BasicFilterSettingsProxy<VideoList> sp(*m_video_list);
00259 VideoFilterDialog *vfd = new VideoFilterDialog(&sp,
00260 gContext->GetMainWindow(),
00261 "filter", "video-",
00262 *m_video_list,
00263 "Video Filter Dialog");
00264 vfd->exec();
00265 delete vfd;
00266
00267 fetchVideos();
00268 }
00269
00270 void VideoDialog::exitWin()
00271 {
00272 emit accept();
00273 }
00274
00275 void VideoDialog::slotParentalLevelChanged()
00276 {
00277 }
00278
00279 void VideoDialog::loadWindow(QDomElement &element)
00280 {
00281 for (QDomNode lchild = element.firstChild(); !lchild.isNull();
00282 lchild = lchild.nextSibling())
00283 {
00284 QDomElement e = lchild.toElement();
00285
00286 if (!e.isNull())
00287 {
00288 if (e.tagName() == "font")
00289 {
00290 theme->parseFont(e);
00291 }
00292 else if (e.tagName() == "container")
00293 {
00294 this->parseContainer(e);
00295 }
00296 else
00297 {
00298 MythPopupBox::showOkPopup(gContext->GetMainWindow(), "",
00299 tr(QString("There is a problem with your video-ui.xml "
00300 "file... Unknown element: %1").
00301 arg(e.tagName())));
00302
00303 VERBOSE(VB_IMPORTANT, QString("Unknown element: %1")
00304 .arg(e.tagName()));
00305 }
00306 }
00307 }
00308 }
00309
00310 void VideoDialog::updateBackground(void)
00311 {
00312 QPixmap bground(size());
00313 bground.fill(this, 0, 0);
00314
00315 QPainter tmp(&bground);
00316
00317 LayerSet *container = theme->GetSet("background");
00318 if (container)
00319 container->Draw(&tmp, 0, 0);
00320
00321 tmp.end();
00322 myBackground = bground;
00323
00324 setPaletteBackgroundPixmap(myBackground);
00325 }
00326
00327 void VideoDialog::jumpTo(const QString &location)
00328 {
00329 cancelPopup();
00330 setExitType(SCREEN_EXIT_VIA_JUMP);
00331 gContext->GetMainWindow()->JumpTo(location);
00332 }