Ticket #9521: 1050-mediamon.diff

File 1050-mediamon.diff, 8.9 KB (added by Lawrence Rust <lvr@…>, 15 years ago)
  • mythtv/libs/libmyth/mythmediamonitor.cpp

    diff --git a/mythtv/libs/libmyth/mythmediamonitor.cpp b/mythtv/libs/libmyth/mythmediamonitor.cpp
    index 3dac2ff..1d3d47b 100644
    bool MediaMonitor::RemoveDevice(const QString &dev)  
    362362    {
    363363        if ((*it)->getDevicePath() == dev)
    364364        {
     365            // Ensure device gets an unmount
     366            (*it)->checkMedia();
     367
    365368            if (m_UseCount[*it] == 0)
    366369            {
    367370                (*it)->deleteLater();
    void MediaMonitor::JumpToMediaHandler(MythMediaDevice* pMedia)  
    652652
    653653
    654654    GetMythMainWindow()->JumpTo("Main Menu");
     655    QTime t; t.start();
     656    while (GetMythMainWindow()->IsExitingToMain() && t.elapsed() < 2000)
     657        qApp->processEvents(); // Ensure jump is executed before calling handler
    655658    handlers.at(selected).callback(pMedia);
    656659}
    657660
    void MediaMonitor::mediaStatusChanged(MediaStatus oldStatus,  
    672677    // This gets called from outside the main thread so we need
    673678    // to post an event back to the main thread.
    674679    // We now send events for all non-error statuses, so plugins get ejects
    675     if (m_SendEvent && stat != MEDIASTAT_ERROR && stat != MEDIASTAT_UNKNOWN)
     680    if (m_SendEvent && stat != MEDIASTAT_ERROR && stat != MEDIASTAT_UNKNOWN &&
     681        // Don't send an event for a new device that's not mounted
     682        !(oldStatus == MEDIASTAT_UNPLUGGED && stat == MEDIASTAT_NOTMOUNTED))
    676683    {
    677684        // Should we ValidateAndLock() first?
    678685        QEvent *e = new MediaEvent(stat, pMedia);
  • mythtv/libs/libmyth/mythhdd.cpp

    diff --git a/mythtv/libs/libmyth/mythhdd.cpp b/mythtv/libs/libmyth/mythhdd.cpp
    index 86f2018..0265d57 100644
    MediaStatus MythHDD::checkMedia(void)  
    4141        return setStatus(MEDIASTAT_MOUNTED);
    4242    }
    4343
     44    // Has device been removed?
     45    if (!isDeviceOpen())
     46    {
     47        if (!openDevice())
     48            return setStatus(MEDIASTAT_UNPLUGGED);
     49        closeDevice();
     50    }
     51
    4452    // device is not mounted
    45     if (m_Status == MEDIASTAT_UNPLUGGED)
     53    switch (m_Status)
    4654    {
     55    case MEDIASTAT_UNPLUGGED:
    4756        // a removable device was just plugged in try to mount it.
    4857        mount();
    4958        if (isMounted())
    MediaStatus MythHDD::checkMedia(void)  
    5160            m_Status = MEDIASTAT_NOTMOUNTED;
    5261            return setStatus(MEDIASTAT_MOUNTED);
    5362        }
    54         else
    55             return setStatus(MEDIASTAT_NOTMOUNTED);
    56     }
    57     else if (m_Status == MEDIASTAT_MOUNTED)
    58     {
     63        return setStatus(MEDIASTAT_NOTMOUNTED);
     64    case MEDIASTAT_MOUNTED:
    5965        // device was mounted and someone unmounted it.
    60         return m_Status = setStatus(MEDIASTAT_NOTMOUNTED);
    61     }
    62     else
    63     {
     66        return setStatus(MEDIASTAT_NOTMOUNTED);
     67    default:
    6468        // leave device state as is
    6569        return m_Status;
    6670    }
  • mythtv/libs/libmyth/mythcdrom-linux.cpp

    diff --git a/mythtv/libs/libmyth/mythcdrom-linux.cpp b/mythtv/libs/libmyth/mythcdrom-linux.cpp
    index 6c5b0d0..eea65d5 100644
     
    1919#define LOC_ERR QString("MythCDROMLinux, Error: ")
    2020
    2121// On a mixed-mode disc (audio+data), set this to 0 to mount the data portion:
     22#ifndef ASSUME_WANT_AUDIO
    2223#define ASSUME_WANT_AUDIO 1
     24#endif
    2325
    2426
    2527// Some features cannot be detected (reliably) using the standard
    MediaStatus MythCDROMLinux::checkMedia()  
    382384    switch (driveStatus())
    383385    {
    384386        case CDS_DISC_OK:
    385             VERBOSE(VB_MEDIA, m_DevicePath + " Disk OK, type = "
     387            VERBOSE(VB_MEDIA+VB_EXTRA, m_DevicePath + " Disk OK, type = "
    386388                              + MediaTypeString(m_MediaType) );
    387389            // further checking is required
    388390            break;
    MediaStatus MythCDROMLinux::checkMedia()  
    432434    // If we have tried to mount and failed, don't keep trying
    433435    if (m_Status == MEDIASTAT_ERROR)
    434436    {
     437        // Check if an external agent (like Gnome/KDE) mounted the disk
     438        if (isMounted())
     439        {
     440            onDeviceMounted();
     441            // pretend we're NOTMOUNTED so setStatus emits a signal
     442            m_Status = MEDIASTAT_NOTMOUNTED;
     443            return setStatus(MEDIASTAT_MOUNTED, OpenedHere);
     444        }
     445
    435446        VERBOSE(VB_MEDIA+VB_EXTRA, "Disc is unmountable?");
    436447        if (OpenedHere)
    437448            closeDevice();
    MediaStatus MythCDROMLinux::checkMedia()  
    510521            }
    511522            case CDS_AUDIO:
    512523                VERBOSE(VB_MEDIA, "found an audio disk");
     524                // pretend we're NOTMOUNTED so setStatus emits a signal
     525                m_Status = MEDIASTAT_NOTMOUNTED;
    513526                m_MediaType = MEDIATYPE_AUDIO;
    514527                return setStatus(MEDIASTAT_USEABLE, OpenedHere);
    515528                break;
    516529            case CDS_MIXED:
    517                 m_MediaType = MEDIATYPE_MIXED;
    518530                VERBOSE(VB_MEDIA, "found a mixed CD");
    519531                // Note: Mixed mode CDs require an explixit mount call
    520532                //       since we'll usually want the audio portion.
    521533                // undefine ASSUME_WANT_AUDIO to change this behavior.
    522                 #ifdef ASSUME_WANT_AUDIO
     534                #if ASSUME_WANT_AUDIO
     535                    // pretend we're NOTMOUNTED so setStatus emits a signal
     536                    m_Status = MEDIASTAT_NOTMOUNTED;
     537                    m_MediaType = MEDIATYPE_AUDIO;
    523538                    return setStatus(MEDIASTAT_USEABLE, OpenedHere);
    524539                #else
     540                    m_MediaType = MEDIATYPE_MIXED;
    525541                    mount();
    526542                    if (isMounted())
    527543                    {
  • mythtv/libs/libmyth/mediamonitor-windows.cpp

    diff --git a/mythtv/libs/libmyth/mediamonitor-windows.cpp b/mythtv/libs/libmyth/mediamonitor-windows.cpp
    index acdc8b7..3fb6230 100644
    MediaMonitorWindows::MediaMonitorWindows(QObject* par,  
    2626{
    2727    char strDrives[128];
    2828    if (!::GetLogicalDriveStrings(sizeof(strDrives), strDrives))
     29    {
     30        VERBOSE(VB_IMPORTANT,
     31            "Error. MediaMonitorWindows failed at GetLogicalDriveStrings.");
    2932        return;
     33    }
    3034
    3135    for (char *driveName = strDrives; *driveName;
    3236         driveName += strlen(driveName) + 1)
    3337    {
    34         uint type = ::GetDriveType(driveName);
    35         if (type != DRIVE_REMOVABLE && type != DRIVE_CDROM)
    36             continue;
    37 
    3838        MythMediaDevice *media = NULL;
    39 
    40         if (type == DRIVE_CDROM)
     39        UINT type = ::GetDriveType(driveName);
     40        switch (type)
     41        {
     42        case DRIVE_CDROM:
     43            VERBOSE(VB_MEDIA+VB_EXTRA,
     44                QString("MediaMonitorWindows found cdrom '%1'").arg(driveName));
    4145            media = MythCDROM::get(this, driveName, false, allowEject);
    42         else
     46            break;
     47        case DRIVE_REMOVABLE:
     48            VERBOSE(VB_MEDIA+VB_EXTRA,
     49                QString("MediaMonitorWindows found removeable '%1'")
     50                    .arg(driveName));
    4351            media = MythHDD::Get(this, driveName, false, allowEject);
    44 
    45         if (!media)
    46         {
    47             VERBOSE(VB_IMPORTANT,
    48                     "Error. Couldn't create MythMediaDevice.");
    49             return;
     52            break;
     53        case DRIVE_UNKNOWN:
     54            VERBOSE(VB_MEDIA+VB_EXTRA,
     55                QString("MediaMonitorWindows found unknown '%1'")
     56                    .arg(driveName));
     57            media = MythCDROM::get(this, driveName, false, allowEject);
     58            break;
     59        case DRIVE_NO_ROOT_DIR:
     60            VERBOSE(VB_MEDIA+VB_EXTRA,
     61                QString("MediaMonitorWindows found '%1' with no root dir")
     62                    .arg(driveName));
     63            media = MythCDROM::get(this, driveName, false, allowEject);
     64            break;
     65        default:
     66            VERBOSE(VB_MEDIA, QString("MediaMonitorWindows found '%1' type %2")
     67                .arg(driveName).arg(type));
     68        case DRIVE_FIXED:
     69        case DRIVE_REMOTE:
     70        case DRIVE_RAMDISK:
     71            continue;
    5072        }
    5173
    52         // We store the volume name to improve
    53         // user activities like ChooseAndEjectMedia().
    54         char volumeName[MAX_PATH];
    55         if (GetVolumeInformation(driveName, volumeName, MAX_PATH,
    56                                  NULL, NULL, NULL, NULL, NULL))
     74        if (media)
    5775        {
    58             media->setVolumeID(volumeName);
     76            // We store the volume name to improve
     77            // user activities like ChooseAndEjectMedia().
     78            char volumeName[MAX_PATH];
     79            if (GetVolumeInformation(driveName, volumeName, MAX_PATH,
     80                                     NULL, NULL, NULL, NULL, NULL))
     81            {
     82                media->setVolumeID(volumeName);
     83            }
     84
     85            AddDevice(media);
    5986        }
    60 
    61         AddDevice(media);
     87        else
     88            VERBOSE(VB_IMPORTANT, "Error. Couldn't create MythMediaDevice.");
    6289    }
    6390
    6491    VERBOSE(VB_MEDIA, "Initial device list: " + listDevices());