Ticket #5602: mediamon.patch

File mediamon.patch, 13.8 KB (added by Nigel, 16 years ago)
  • mythtv/libs/libmythui/mythmainwindow.cpp

     
    9393    QString localAction;
    9494};
    9595
    96 struct MHData
    97 {
    98     void (*callback)(MythMediaDevice *mediadevice);
    99     int MediaType;
    100     QString destination;
    101     QString description;
    102 };
    103 
    10496struct MPData {
    10597    QString description;
    10698    MediaPlayCallback playFn;
     
    144136    QHash<QString, KeyContext *> keyContexts;
    145137    QMap<int, JumpData*> jumpMap;
    146138    QMap<QString, JumpData> destinationMap;
    147     QMap<QString, MHData> mediaHandlerMap;
    148139    QMap<QString, MPData> mediaPluginMap;
    149140
    150141    void (*exitmenucallback)(void);
     
    12211212    return (d->destinationMap.count(destination) > 0) ? true : false;
    12221213}
    12231214
    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 _WIN32
    1232 #if 0
    1233     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     else
    1250     {
    1251        VERBOSE(VB_GENERAL, QString("%1 is already registered as a media "
    1252                                    "handler.").arg(destination));
    1253     }
    1254 #endif
    1255 #endif // !_WIN32
    1256 }
    1257 
    12581215void MythMainWindow::RegisterMediaPlugin(const QString &name,
    12591216                                         const QString &desc,
    12601217                                         MediaPlayCallback fn)
     
    12841241    // Let's see if we have a plugin that matches the handler name...
    12851242    if (d->mediaPluginMap.count(handler))
    12861243    {
    1287         d->mediaPluginMap[handler].playFn(mrl, plot, title, director, lenMins, year);
     1244        d->mediaPluginMap[handler].playFn(mrl, plot, title,
     1245                                          director, lenMins, year);
    12881246        return true;
    12891247    }
    12901248
     
    14921450        else
    14931451            QApplication::sendEvent(key_target, &key);
    14941452    }
    1495 #ifndef _WIN32
    1496 #if 0
    1497     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 this
    1501         // type of media...  If there's more than one we'll want to show some
    1502         // UI to allow the user to select which jump point to use. But for
    1503         // 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 should
    1512                 // call each plugin's callback so it can track this change.
    1513                 // Should also do MediaMonitor::ValidateAndLock(pDev) first
    1514 
    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 #endif
    1561 #endif // !_WIN32
    1562 
    15631453#if defined(USE_LIRC) || defined(USING_APPLEREMOTE)
    15641454    else if (ce->type() == kLircKeycodeEventType && !d->ignore_lirc_keys)
    15651455    {
  • mythtv/libs/libmythui/mythmainwindow.h

     
    1717#define REG_JUMP(a, b, c, d) GetMythMainWindow()->RegisterJump(a, b, c, d)
    1818#define REG_JUMPLOC(a, b, c, d, e) GetMythMainWindow()->RegisterJump(a, b, c, d, true, e)
    1919#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)
    2120#define REG_MEDIAPLAYER(a,b,c) GetMythMainWindow()->RegisterMediaPlugin(a, b, c)
    2221
    2322typedef int (*MediaPlayCallback)(const QString &, const QString &, const QString &, const QString &, int, const QString &);
     
    5756    void RegisterJump(const QString &destination, const QString &description,
    5857                      const QString &key, void (*callback)(void),
    5958                      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);
    6459
    6560    void RegisterMediaPlugin(const QString &name, const QString &desc,
    6661                             MediaPlayCallback fn);
  • mythtv/libs/libmyth/mythmediamonitor.h

     
    1313
    1414const int kMediaEventType = 30042;
    1515
     16struct MHData
     17{
     18    void (*callback)(MythMediaDevice *mediadevice);
     19    int MediaType;
     20    QString destination;
     21    QString description;
     22};
     23
    1624class MPUBLIC MediaEvent : public QEvent
    1725{
    1826  public:
     
    7078    // first validate the pointer with ValidateAndLock(), if true is returned
    7179    // it is safe to dereference the pointer. When finished call Unlock()
    7280    QList<MythMediaDevice*> GetMedias(MediaType mediatype);
    73     MythMediaDevice* GetMedia(const QString &path);
     81    MythMediaDevice*        GetMedia(const QString &path);
    7482
    7583    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);
    7692
    7793    // Plugins should use these if they need to access optical disks:
    7894    static QString defaultCDdevice();
     
    116132    unsigned long                m_MonitorPollingInterval;
    117133    bool                         m_AllowEject;
    118134
     135    QMap<QString, MHData>        m_handlerMap;
     136
    119137    static MediaMonitor         *c_monitor;
    120138};
    121139
     140#define REG_MEDIA_HANDLER(a, b, c, d, e, f) \
     141        MediaMonitor::GetMediaMonitor()->RegisterMediaHandler(a, b, c, d, e, f)
     142
    122143#endif // MYTH_MEDIA_MONITOR_H
  • mythtv/libs/libmyth/mythmediamonitor.cpp

     
    550554    }
    551555}
    552556
     557void 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.
     592void 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
    553625// Signal handler.
    554626void MediaMonitor::mediaStatusChanged(MediaStatus oldStatus,
    555627                                      MythMediaDevice* pMedia)
     
    564636                        .arg(MythMediaDevice::MediaStatusStrings[oldStatus])
    565637                        .arg(MythMediaDevice::MediaStatusStrings[stat]);
    566638
    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:
    570640    if (m_SendEvent && stat != MEDIASTAT_ERROR && stat != MEDIASTAT_UNKNOWN)
    571641    {
    572         VERBOSE(VB_MEDIA, "Posting MediaEvent" + msg);
     642        VERBOSE(VB_MEDIA, "Processing MediaEvent" + msg);
     643        // Should we ValidateAndLock() first?
    573644
    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        }
    580661    }
    581662    else
    582663        VERBOSE(VB_MEDIA, "Media status changed, but not sending event" + msg);
  • mythplugins/mythgallery/mythgallery/main.cpp

     
    1111#include <mythtv/mythdialogs.h>
    1212#include <mythtv/mythplugin.h>
    1313#include <mythtv/dialogbox.h>
    14 #include <mythtv/mythmedia.h>
     14#include <mythtv/mythmediamonitor.h>
    1515#include <mythtv/mythpluginapi.h>
    1616
    1717// mythgallery