Ticket #5602: mediamon.patch
File mediamon.patch, 13.8 KB (added by , 16 years ago) |
---|
-
mythtv/libs/libmythui/mythmainwindow.cpp
93 93 QString localAction; 94 94 }; 95 95 96 struct MHData97 {98 void (*callback)(MythMediaDevice *mediadevice);99 int MediaType;100 QString destination;101 QString description;102 };103 104 96 struct MPData { 105 97 QString description; 106 98 MediaPlayCallback playFn; … … 144 136 QHash<QString, KeyContext *> keyContexts; 145 137 QMap<int, JumpData*> jumpMap; 146 138 QMap<QString, JumpData> destinationMap; 147 QMap<QString, MHData> mediaHandlerMap;148 139 QMap<QString, MPData> mediaPluginMap; 149 140 150 141 void (*exitmenucallback)(void); … … 1221 1212 return (d->destinationMap.count(destination) > 0) ? true : false; 1222 1213 } 1223 1214 1224 void MythMainWindow::RegisterMediaHandler(const QString &destination,1225 const QString &description,1226 const QString &/*key*/,1227 void (*callback)(MythMediaDevice*),1228 int mediaType,1229 const QString &extensions)1230 {1231 #ifndef _WIN321232 #if 01233 if (d->mediaHandlerMap.count(destination) == 0)1234 {1235 MHData mhd = { callback, mediaType, destination, description };1236 QString msg = MythMediaDevice::MediaTypeString((MediaType)mediaType);1237 if (!extensions.isEmpty())1238 msg += QString(", ext(%1)").arg(extensions);1239 1240 VERBOSE(VB_MEDIA, "Registering " + destination +1241 " as a media handler for " + msg);1242 1243 d->mediaHandlerMap[destination] = mhd;1244 1245 MediaMonitor *mon = MediaMonitor::GetMediaMonitor();1246 if (mon && !extensions.isEmpty())1247 mon->MonitorRegisterExtensions(mediaType, extensions);1248 }1249 else1250 {1251 VERBOSE(VB_GENERAL, QString("%1 is already registered as a media "1252 "handler.").arg(destination));1253 }1254 #endif1255 #endif // !_WIN321256 }1257 1258 1215 void MythMainWindow::RegisterMediaPlugin(const QString &name, 1259 1216 const QString &desc, 1260 1217 MediaPlayCallback fn) … … 1284 1241 // Let's see if we have a plugin that matches the handler name... 1285 1242 if (d->mediaPluginMap.count(handler)) 1286 1243 { 1287 d->mediaPluginMap[handler].playFn(mrl, plot, title, director, lenMins, year); 1244 d->mediaPluginMap[handler].playFn(mrl, plot, title, 1245 director, lenMins, year); 1288 1246 return true; 1289 1247 } 1290 1248 … … 1492 1450 else 1493 1451 QApplication::sendEvent(key_target, &key); 1494 1452 } 1495 #ifndef _WIN321496 #if 01497 else if (ce->type() == kMediaEventType)1498 {1499 MediaEvent *media_event = (MediaEvent*)ce;1500 // Let's see which of our jump points are configured to handle this1501 // type of media... If there's more than one we'll want to show some1502 // UI to allow the user to select which jump point to use. But for1503 // now we're going to just use the first one.1504 QMap<QString, MHData>::Iterator itr = d->mediaHandlerMap.begin();1505 MythMediaDevice *pDev = media_event->getDevice();1506 1507 if (pDev)1508 {1509 if (!pDev->isUsable())1510 {1511 // We don't want to jump to the main window, but should1512 // call each plugin's callback so it can track this change.1513 // Should also do MediaMonitor::ValidateAndLock(pDev) first1514 1515 while (itr != d->mediaHandlerMap.end())1516 {1517 if (itr.data().MediaType & (int)pDev->getMediaType())1518 itr.data().callback(pDev);1519 1520 itr++;1521 }1522 1523 return;1524 }1525 1526 /* FIXME, this needs rewritten */1527 QWidget * activewidget = qApp->focusWidget();1528 MythDialog * activedialog = NULL;1529 bool iscatched = false;1530 while (activewidget && !activedialog)1531 {1532 activedialog = dynamic_cast<MythDialog*>(activewidget);1533 if (!activedialog)1534 activewidget = activewidget->parentWidget();1535 }1536 if (activedialog)1537 iscatched = activedialog->onMediaEvent(pDev);1538 1539 MediaMonitor *mon = MediaMonitor::GetMediaMonitor();1540 if (iscatched || !mon->ValidateAndLock(pDev))1541 mon = NULL;1542 1543 while (mon && (itr != d->mediaHandlerMap.end()))1544 {1545 if ((itr.data().MediaType & (int)pDev->getMediaType()))1546 {1547 VERBOSE(VB_IMPORTANT, "Found a handler");1548 d->exitingtomain = true;1549 d->exitmenumediadevicecallback = itr.data().callback;1550 d->mediadeviceforcallback = pDev;1551 QApplication::postEvent(this, new ExitToMainMenuEvent());1552 break;1553 }1554 itr++;1555 }1556 if (mon)1557 mon->Unlock(pDev);1558 }1559 }1560 #endif1561 #endif // !_WIN321562 1563 1453 #if defined(USE_LIRC) || defined(USING_APPLEREMOTE) 1564 1454 else if (ce->type() == kLircKeycodeEventType && !d->ignore_lirc_keys) 1565 1455 { -
mythtv/libs/libmythui/mythmainwindow.h
17 17 #define REG_JUMP(a, b, c, d) GetMythMainWindow()->RegisterJump(a, b, c, d) 18 18 #define REG_JUMPLOC(a, b, c, d, e) GetMythMainWindow()->RegisterJump(a, b, c, d, true, e) 19 19 #define REG_JUMPEX(a, b, c, d, e) GetMythMainWindow()->RegisterJump(a, b, c, d, e) 20 #define REG_MEDIA_HANDLER(a, b, c, d, e, f) GetMythMainWindow()->RegisterMediaHandler(a, b, c, d, e, f)21 20 #define REG_MEDIAPLAYER(a,b,c) GetMythMainWindow()->RegisterMediaPlugin(a, b, c) 22 21 23 22 typedef int (*MediaPlayCallback)(const QString &, const QString &, const QString &, const QString &, int, const QString &); … … 57 56 void RegisterJump(const QString &destination, const QString &description, 58 57 const QString &key, void (*callback)(void), 59 58 bool exittomain = true, QString localAction = ""); 60 void RegisterMediaHandler(const QString &destination,61 const QString &description, const QString &key,62 void (*callback)(MythMediaDevice* mediadevice),63 int mediaType, const QString &extensions);64 59 65 60 void RegisterMediaPlugin(const QString &name, const QString &desc, 66 61 MediaPlayCallback fn); -
mythtv/libs/libmyth/mythmediamonitor.h
13 13 14 14 const int kMediaEventType = 30042; 15 15 16 struct MHData 17 { 18 void (*callback)(MythMediaDevice *mediadevice); 19 int MediaType; 20 QString destination; 21 QString description; 22 }; 23 16 24 class MPUBLIC MediaEvent : public QEvent 17 25 { 18 26 public: … … 70 78 // first validate the pointer with ValidateAndLock(), if true is returned 71 79 // it is safe to dereference the pointer. When finished call Unlock() 72 80 QList<MythMediaDevice*> GetMedias(MediaType mediatype); 73 MythMediaDevice* GetMedia(const QString &path);81 MythMediaDevice* GetMedia(const QString &path); 74 82 75 83 void MonitorRegisterExtensions(uint mediaType, const QString &extensions); 84 void RegisterMediaHandler(const QString &destination, 85 const QString &description, 86 const QString &/*key*/, 87 void (*callback) 88 (MythMediaDevice*), 89 int mediaType, 90 const QString &extensions); 91 void JumpToMediaHandler(MythMediaDevice* pMedia); 76 92 77 93 // Plugins should use these if they need to access optical disks: 78 94 static QString defaultCDdevice(); … … 116 132 unsigned long m_MonitorPollingInterval; 117 133 bool m_AllowEject; 118 134 135 QMap<QString, MHData> m_handlerMap; 136 119 137 static MediaMonitor *c_monitor; 120 138 }; 121 139 140 #define REG_MEDIA_HANDLER(a, b, c, d, e, f) \ 141 MediaMonitor::GetMediaMonitor()->RegisterMediaHandler(a, b, c, d, e, f) 142 122 143 #endif // MYTH_MEDIA_MONITOR_H -
mythtv/libs/libmyth/mythmediamonitor.cpp
550 554 } 551 555 } 552 556 557 void MediaMonitor::RegisterMediaHandler(const QString &destination, 558 const QString &description, 559 const QString &/*key*/, 560 void (*callback) 561 (MythMediaDevice*), 562 int mediaType, 563 const QString &extensions) 564 { 565 if (m_handlerMap.count(destination) == 0) 566 { 567 MHData mhd = { callback, mediaType, destination, description }; 568 QString msg = MythMediaDevice::MediaTypeString((MediaType)mediaType); 569 570 if (extensions.length()) 571 msg += QString(", ext(%1)").arg(extensions); 572 573 VERBOSE(VB_MEDIA, "Registering '" + destination + 574 "'\n as a media handler for " + msg); 575 576 m_handlerMap[destination] = mhd; 577 578 if (extensions.length()) 579 MonitorRegisterExtensions(mediaType, extensions); 580 } 581 else 582 { 583 VERBOSE(VB_GENERAL, 584 destination + " is already registered as a media handler."); 585 } 586 } 587 588 // Let's see which of our jump points are configured to handle this 589 // type of media... If there's more than one we'll want to show some 590 // UI to allow the user to select which jump point to use. But for 591 // now we're going to just use the first one. 592 void MediaMonitor::JumpToMediaHandler(MythMediaDevice* pMedia) 593 { 594 #if 0 595 /* FIXME, this needs rewritten */ 596 QWidget * activewidget = qApp->focusWidget(); 597 MythDialog * activedialog = NULL; 598 bool iscatched = false; 599 while (activewidget && !activedialog) 600 { 601 activedialog = dynamic_cast<MythDialog*>(activewidget); 602 if (!activedialog) 603 activewidget = activewidget->parentWidget(); 604 } 605 if (activedialog) 606 iscatched = activedialog->onMediaEvent(pDev); 607 #endif 608 609 QMap<QString, MHData>::Iterator itr = m_handlerMap.begin(); 610 while (itr != m_handlerMap.end()) 611 { 612 if ((itr.data().MediaType & (int)pMedia->getMediaType())) 613 { 614 VERBOSE(VB_IMPORTANT, "Found a handler - " 615 + itr.data().description); 616 QApplication::postEvent(this, new ExitToMainMenuEvent()); 617 itr.data().callback(pMedia); // This should do a JumpTo? 618 break; 619 } 620 itr++; 621 } 622 VERBOSE(VB_MEDIA, "No media handler found for event type"); 623 } 624 553 625 // Signal handler. 554 626 void MediaMonitor::mediaStatusChanged(MediaStatus oldStatus, 555 627 MythMediaDevice* pMedia) … … 564 636 .arg(MythMediaDevice::MediaStatusStrings[oldStatus]) 565 637 .arg(MythMediaDevice::MediaStatusStrings[stat]); 566 638 567 // This gets called from outside the main thread so we need 568 // to post an event back to the main thread. 569 // We now send events for all non-error statuses, so plugins get ejects 639 // We process changes for all non-error statuses, so plugins get ejects: 570 640 if (m_SendEvent && stat != MEDIASTAT_ERROR && stat != MEDIASTAT_UNKNOWN) 571 641 { 572 VERBOSE(VB_MEDIA, "Posting MediaEvent" + msg); 642 VERBOSE(VB_MEDIA, "Processing MediaEvent" + msg); 643 // Should we ValidateAndLock() first? 573 644 574 // sendEvent() is needed here - it waits for the event to be used. 575 // postEvent() would result in pDevice's media type changing 576 // ... before the plugin's event chain would process it. 577 // Another way would be to send an exact copy of pDevice instead. 578 QApplication::sendEvent((QObject*)gContext->GetMainWindow(), 579 new MediaEvent(stat, pMedia)); 645 646 if (pMedia->isUsable()) 647 JumpToMediaHandler(pMedia); 648 else 649 { 650 // We don't want to jump to the plugin, but should call 651 // each plugin's callback so it can track this change. 652 653 QMap<QString, MHData>::Iterator itr = m_handlerMap.begin(); 654 while (itr != m_handlerMap.end()) 655 { 656 if (itr.data().MediaType & (int)pMedia->getMediaType()) 657 itr.data().callback(pMedia); 658 itr++; 659 } 660 } 580 661 } 581 662 else 582 663 VERBOSE(VB_MEDIA, "Media status changed, but not sending event" + msg); -
mythplugins/mythgallery/mythgallery/main.cpp
11 11 #include <mythtv/mythdialogs.h> 12 12 #include <mythtv/mythplugin.h> 13 13 #include <mythtv/dialogbox.h> 14 #include <mythtv/mythmedia .h>14 #include <mythtv/mythmediamonitor.h> 15 15 #include <mythtv/mythpluginapi.h> 16 16 17 17 // mythgallery