00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00013
00014 #include <qapplication.h>
00015 #include <qdir.h>
00016
00017 #include <mythtv/mythcontext.h>
00018 #include <mythtv/lcddevice.h>
00019 #include <mythtv/libmythui/myththemedmenu.h>
00020 #include <mythtv/mythpluginapi.h>
00021 #include <mythtv/mythmediamonitor.h>
00022 #include <mythtv/util.h>
00023
00024 #include "videomanager.h"
00025 #include "videobrowser.h"
00026 #include "videotree.h"
00027 #include "videogallery.h"
00028 #include "globalsettings.h"
00029 #include "fileassoc.h"
00030 #include "dbcheck.h"
00031 #include "videoscan.h"
00032 #include "cleanup.h"
00033 #include "globals.h"
00034 #include "videolist.h"
00035 #include "videoutils.h"
00036 #include "dvdripbox.h"
00037 #include "parentalcontrols.h"
00038
00039 #if defined(AEW_VG)
00040 #include <valgrind/memcheck.h>
00041 #endif
00042
00043 namespace
00044 {
00045 template <typename T>
00046 class screen_inst
00047 {
00048 public:
00049 screen_inst(T *inst, const QString &loc_name) : m_inst(inst),
00050 m_location_name(loc_name)
00051 {
00052 }
00053
00054 int run()
00055 {
00056 gContext->addCurrentLocation(m_location_name);
00057 qApp->unlock();
00058 m_inst->exec();
00059 qApp->lock();
00060 gContext->removeCurrentLocation();
00061 return m_inst->videoExitType();
00062 }
00063
00064 ~screen_inst()
00065 {
00066 delete m_inst;
00067 }
00068
00069 private:
00070 T *m_inst;
00071 const QString &m_location_name;
00072 };
00073
00074 template <typename T>
00075 class q_screen_inst
00076 {
00077 public:
00078 q_screen_inst(T *inst, const QString &loc_name) : m_inst(inst),
00079 m_location_name(loc_name)
00080 {
00081 }
00082
00083 int run()
00084 {
00085 gContext->addCurrentLocation(m_location_name);
00086 qApp->unlock();
00087 m_inst->exec();
00088 qApp->lock();
00089 gContext->removeCurrentLocation();
00090 return m_inst->videoExitType();
00091 }
00092
00093 ~q_screen_inst()
00094 {
00095 m_inst->deleteLater();
00096 m_inst = NULL;
00097 }
00098
00099 private:
00100 T *m_inst;
00101 const QString &m_location_name;
00102 };
00103
00104 template <typename T>
00105 int exec_screen(T *inst, const QString &loc_name)
00106 {
00107 screen_inst<T> si(inst, loc_name);
00108 return si.run();
00109 }
00110
00111 template <typename T>
00112 int q_exec_screen(T *inst, const QString &loc_name)
00113 {
00114 q_screen_inst<T> si(inst, loc_name);
00115 return si.run();
00116 }
00117
00118 class screens
00119 {
00120 private:
00121 static int runVideoManager(VideoList *video_list)
00122 {
00123 if (checkParentPassword(ParentalLevel::plHigh))
00124 {
00125 VideoScanner scanner;
00126 scanner.doScan(GetVideoDirs());
00127
00128 return q_exec_screen(
00129 new VideoManager(gContext->GetMainWindow(), video_list),
00130 "videomanager");
00131 }
00132 return 0;
00133 }
00134
00135 static int runVideoBrowser(VideoList *video_list)
00136 {
00137 return exec_screen(new VideoBrowser(gContext->GetMainWindow(),
00138 "video browser", video_list),
00139 "videobrowser");
00140 }
00141
00142 static int runVideoTree(VideoList *video_list)
00143 {
00144 return exec_screen(new VideoTree(gContext->GetMainWindow(),
00145 "videotree", "video-",
00146 "video tree", video_list),
00147 "videolistings");
00148 }
00149
00150 static int runVideoGallery(VideoList *video_list)
00151 {
00152 return q_exec_screen(new VideoGallery(gContext->GetMainWindow(),
00153 "video gallery", video_list),
00154 "videogallery");
00155 }
00156
00157 public:
00158
00159
00160
00161 enum screen_type
00162 {
00163 stVideoBrowser = VideoDialog::DLG_BROWSER,
00164 stVideoGallery = VideoDialog::DLG_GALLERY,
00165 stVideoTree = VideoDialog::DLG_TREE,
00166 stVideoManager,
00167 stDefaultView
00168 };
00169
00170 static void runScreen(screen_type st)
00171 {
00172 static VideoList *video_list = 0;
00173
00174 if (st == stDefaultView)
00175 {
00176 st = static_cast<screen_type>(
00177 gContext->GetNumSetting("Default MythVideo View",
00178 stVideoGallery));
00179 if (!VideoDialog::IsValidDialogType(st))
00180 st = stVideoGallery;
00181 }
00182
00183 if (!video_list)
00184 {
00185 video_list = new VideoList;
00186 }
00187
00188 int sret = 0;
00189 switch (st)
00190 {
00191 case stVideoManager:
00192 {
00193 sret = runVideoManager(video_list);
00194 break;
00195 }
00196 case stVideoBrowser:
00197 {
00198 sret = runVideoBrowser(video_list);
00199 break;
00200 }
00201 case stVideoTree:
00202 {
00203 sret = runVideoTree(video_list);
00204 break;
00205 }
00206 case stVideoGallery:
00207 {
00208 sret = runVideoGallery(video_list);
00209 break;
00210 }
00211 case stDefaultView:
00212 default:
00213 {
00214 sret = runVideoGallery(video_list);
00215 break;
00216 }
00217 }
00218
00219 if (sret != SCREEN_EXIT_VIA_JUMP)
00220 {
00221
00222
00223
00224
00225 CleanupHooks::getInstance()->cleanup();
00226 delete video_list;
00227 video_list = 0;
00228 }
00229 }
00230 };
00231
00232 void screenVideoManager() { screens::runScreen(screens::stVideoManager); }
00233 void screenVideoBrowser() { screens::runScreen(screens::stVideoBrowser); }
00234 void screenVideoTree() { screens::runScreen(screens::stVideoTree); }
00235 void screenVideoGallery() { screens::runScreen(screens::stVideoGallery); }
00236 void screenVideoDefault() { screens::runScreen(screens::stDefaultView); }
00237
00239
00241
00242
00243 QString gDVDdevice;
00244
00245 void startDVDRipper()
00246 {
00247
00248
00249 QString ripDir = gContext->GetSetting("DVDRipLocation");
00250 if (ripDir.length() && !QDir(ripDir).exists())
00251 MythPopupBox::showOkPopup(
00252 gContext->GetMainWindow(), "",
00253 QObject::tr("No directory %1 - DVD importing will fail")
00254 .arg(ripDir));
00255
00256 QString dvd_device = gDVDdevice;
00257
00258 if (dvd_device.isNull())
00259 dvd_device = MediaMonitor::defaultDVDdevice();
00260
00261 #ifdef Q_OS_MAC
00262
00263 dvd_device.prepend("/dev/r");
00264 #endif
00265 DVDRipBox *drb = new DVDRipBox(gContext->GetMainWindow(),
00266 "dvd_rip", dvd_device, "dvd-");
00267 gContext->addCurrentLocation("ripdvd");
00268 qApp->unlock();
00269 drb->exec();
00270 qApp->lock();
00271 gContext->removeCurrentLocation();
00272
00273 qApp->processEvents();
00274
00275 delete drb;
00276 }
00277
00278 void playVCD()
00279 {
00280
00281
00282
00283 QString command_string = gContext->GetSetting("VCDPlayerCommand");
00284
00285 gContext->addCurrentLocation("playvcd");
00286
00287 if(command_string.length() < 1)
00288 {
00289
00290
00291
00292 DialogBox *no_player_dialog =
00293 new DialogBox(gContext->GetMainWindow(),
00294 QObject::tr("\n\nYou have no VCD Player command defined."));
00295 no_player_dialog->AddButton(QObject::tr("OK, I'll go run Setup"));
00296 no_player_dialog->exec();
00297
00298 no_player_dialog->deleteLater();
00299 gContext->removeCurrentLocation();
00300 return;
00301 }
00302 else
00303 {
00304 if(command_string.contains("%d"))
00305 {
00306
00307
00308
00309 command_string
00310 = command_string.replace(QRegExp("%d"),
00311 MediaMonitor::defaultVCDdevice());
00312 }
00313 gContext->sendPlaybackStart();
00314 myth_system(command_string);
00315 gContext->sendPlaybackEnd();
00316 gContext->GetMainWindow()->raise();
00317 gContext->GetMainWindow()->setActiveWindow();
00318 if (gContext->GetMainWindow()->currentWidget())
00319 gContext->GetMainWindow()->currentWidget()->setFocus();
00320 }
00321 gContext->removeCurrentLocation();
00322 }
00323
00324 void playDVD()
00325 {
00326
00327
00328
00329
00330 QString command_string =
00331 gContext->GetSetting("mythdvd.DVDPlayerCommand");
00332
00333 QString dvd_device = gDVDdevice;
00334
00335 if (dvd_device.isNull())
00336 dvd_device = MediaMonitor::defaultDVDdevice();
00337
00338 gContext->addCurrentLocation("playdvd");
00339
00340 if ((command_string.find("internal", 0, false) > -1) ||
00341 (command_string.length() < 1))
00342 {
00343 #ifdef Q_OS_MAC
00344
00345 QString filename = "dvd://dev/r";
00346 #elif MINGW
00347 QString filename = "dvd:";
00348 #else
00349 QString filename = "dvd:/";
00350 #endif
00351 filename += dvd_device;
00352
00353 command_string = "Internal";
00354 gContext->GetMainWindow()->HandleMedia(command_string, filename);
00355 gContext->removeCurrentLocation();
00356
00357 return;
00358 }
00359 else
00360 {
00361 if (command_string.contains("%d"))
00362 {
00363
00364
00365
00366 command_string =
00367 command_string.replace(QRegExp("%d"), dvd_device);
00368 }
00369 gContext->sendPlaybackStart();
00370 myth_system(command_string);
00371 gContext->sendPlaybackEnd();
00372 if (gContext->GetMainWindow())
00373 {
00374 gContext->GetMainWindow()->raise();
00375 gContext->GetMainWindow()->setActiveWindow();
00376 if (gContext->GetMainWindow()->currentWidget())
00377 gContext->GetMainWindow()->currentWidget()->setFocus();
00378 }
00379 }
00380 gContext->removeCurrentLocation();
00381 }
00382
00386 void handleDVDMedia(MythMediaDevice *dvd)
00387 {
00388 if (!dvd)
00389 return;
00390
00391 QString newDevice = dvd->getDevicePath();
00392
00393
00394 if (dvd->isUsable())
00395 if (gDVDdevice.length() && gDVDdevice != newDevice)
00396 {
00397
00398
00399
00400 VERBOSE(VB_MEDIA, "MythVideo: Multiple DVD drives? Forgetting "
00401 + gDVDdevice);
00402 gDVDdevice = QString::null;
00403 }
00404 else
00405 {
00406 gDVDdevice = newDevice;
00407 VERBOSE(VB_MEDIA,
00408 "MythVideo: Storing DVD device " + gDVDdevice);
00409 }
00410 else
00411 {
00412
00413
00414 if (gDVDdevice.length() && gDVDdevice == newDevice)
00415 {
00416 VERBOSE(VB_MEDIA,
00417 "MythVideo: Forgetting existing DVD " + gDVDdevice);
00418 gDVDdevice = QString::null;
00419
00420
00421 }
00422
00423 return;
00424 }
00425
00426 switch (gContext->GetNumSetting("DVDOnInsertDVD", 1))
00427 {
00428 case 0 :
00429 break;
00430 case 1 :
00431 mythplugin_run();
00432 break;
00433 case 2 :
00434 playDVD();
00435 break;
00436 case 3 :
00437 startDVDRipper();
00438 break;
00439 default:
00440 cerr << "mythdvd main.o: handleMedia() does not know what to do"
00441 << endl;
00442 }
00443 }
00444
00445 void handleVCDMedia(MythMediaDevice *vcd)
00446 {
00447 if (!vcd || !vcd->isUsable())
00448 return;
00449
00450 switch (gContext->GetNumSetting("DVDOnInsertDVD", 1))
00451 {
00452 case 0 :
00453 break;
00454 case 1 :
00455 mythplugin_run();
00456 break;
00457 case 2 :
00458 playVCD();
00459 break;
00460 case 3 :
00461 break;
00462 }
00463 }
00464
00466
00468
00469 void setupKeys()
00470 {
00471 REG_JUMP(JUMP_VIDEO_DEFAULT, "The MythVideo default view", "",
00472 screenVideoDefault);
00473
00474 REG_JUMP(JUMP_VIDEO_MANAGER, "The MythVideo video manager", "",
00475 screenVideoManager);
00476 REG_JUMP(JUMP_VIDEO_BROWSER, "The MythVideo video browser", "",
00477 screenVideoBrowser);
00478 REG_JUMP(JUMP_VIDEO_TREE, "The MythVideo video listings", "",
00479 screenVideoTree);
00480 REG_JUMP(JUMP_VIDEO_GALLERY, "The MythVideo video gallery", "",
00481 screenVideoGallery);
00482
00483 REG_KEY("Video","FILTER","Open video filter dialog","F");
00484
00485 REG_KEY("Video","DELETE","Delete video","D");
00486 REG_KEY("Video","BROWSE","Change browsable in video manager","B");
00487 REG_KEY("Video","INCPARENT","Increase Parental Level","],},F11");
00488 REG_KEY("Video","DECPARENT","Decrease Parental Level","[,{,F10");
00489
00490 REG_KEY("Video","HOME","Go to the first video","Home");
00491 REG_KEY("Video","END","Go to the last video","End");
00492
00493
00494 REG_JUMP("Play DVD", "Play a DVD", "", playDVD);
00495 REG_MEDIA_HANDLER("MythDVD DVD Media Handler", "", "", handleDVDMedia,
00496 MEDIATYPE_DVD, QString::null);
00497
00498 REG_JUMP("Play VCD", "Play a VCD", "", playVCD);
00499 REG_MEDIA_HANDLER("MythDVD VCD Media Handler", "", "", handleVCDMedia,
00500 MEDIATYPE_VCD, QString::null);
00501
00502 REG_JUMP("Rip DVD", "Import a DVD into your MythVideo database", "",
00503 startDVDRipper);
00504 }
00505
00506 void VideoCallback(void *data, QString &selection)
00507 {
00508 (void)data;
00509
00510 QString sel = selection.lower();
00511
00512 if (sel == "manager")
00513 screenVideoManager();
00514 else if (sel == "browser")
00515 screenVideoBrowser();
00516 else if (sel == "listing")
00517 screenVideoTree();
00518 else if (sel == "gallery")
00519 screenVideoGallery();
00520 else if (sel == "settings_general")
00521 {
00522
00523
00524
00525
00526
00527
00528
00529 if (gContext->GetNumSetting("VideoAggressivePC", 0))
00530 {
00531 if (checkParentPassword(ParentalLevel::plHigh))
00532 {
00533 VideoGeneralSettings settings;
00534 settings.exec();
00535 }
00536 }
00537 else
00538 {
00539 VideoGeneralSettings settings;
00540 settings.exec();
00541 }
00542 }
00543 else if (sel == "settings_player")
00544 {
00545 VideoPlayerSettings settings;
00546 settings.exec();
00547 }
00548 else if (sel == "settings_associations")
00549 {
00550 FileAssocDialog fa(gContext->GetMainWindow(),
00551 "file_associations",
00552 "video-",
00553 "fa dialog");
00554
00555 fa.exec();
00556 }
00557 else if (sel == "dvd_play")
00558 {
00559 playDVD();
00560 }
00561 else if (sel == "vcd_play")
00562 {
00563 playVCD();
00564 }
00565 else if (sel == "dvd_rip")
00566 {
00567 startDVDRipper();
00568 }
00569 else if (sel == "dvd_settings_rip")
00570 {
00571 DVDRipperSettings settings;
00572 settings.exec();
00573 }
00574 }
00575
00576 void runMenu(const QString &menuname)
00577 {
00578 QString themedir = gContext->GetThemeDir();
00579
00580 MythThemedMenu *diag =
00581 new MythThemedMenu(themedir.ascii(), menuname,
00582 GetMythMainWindow()->GetMainStack(),
00583 "video menu");
00584
00585 diag->setCallback(VideoCallback, NULL);
00586 diag->setKillable();
00587
00588 if (diag->foundTheme())
00589 {
00590 if (LCD *lcd = LCD::Get())
00591 {
00592 lcd->switchToTime();
00593 }
00594 GetMythMainWindow()->GetMainStack()->AddScreen(diag);
00595 }
00596 else
00597 {
00598 VERBOSE(VB_IMPORTANT,
00599 QString("Couldn't find theme %1").arg(themedir));
00600 delete diag;
00601 }
00602 }
00603 }
00604
00605 int mythplugin_init(const char *libversion)
00606 {
00607 if (!gContext->TestPopupVersion("mythvideo", libversion,
00608 MYTH_BINARY_VERSION))
00609 return -1;
00610
00611 gContext->ActivateSettingsCache(false);
00612 UpgradeVideoDatabaseSchema();
00613 gContext->ActivateSettingsCache(true);
00614
00615 VideoGeneralSettings general;
00616 general.load();
00617 general.save();
00618
00619 VideoPlayerSettings settings;
00620 settings.load();
00621 settings.save();
00622
00623 DVDRipperSettings rsettings;
00624 rsettings.load();
00625 rsettings.save();
00626
00627 setupKeys();
00628
00629 return 0;
00630 }
00631
00632 int mythplugin_run()
00633 {
00634 runMenu("videomenu.xml");
00635 return 0;
00636 }
00637
00638 int mythplugin_config()
00639 {
00640 runMenu("video_settings.xml");
00641
00642 return 0;
00643 }
00644
00645 void mythplugin_destroy()
00646 {
00647 CleanupHooks::getInstance()->cleanup();
00648 #if defined(AEW_VG)
00649
00650
00651
00652 VALGRIND_DO_LEAK_CHECK;
00653 #endif
00654 }