From d00d2a85a7d2a9cffe57ceadae9d8476b50e9e22 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Sun, 15 Jul 2012 12:31:05 +0100 Subject: [PATCH] Only prompt the user to select from 'usable' media If a user has multiple optical drives but only one or two contain discs then there is no need to show all in the drive selection popup. In cases where only one drive contains media this avoids showing the popup at all. --- mythtv/libs/libmyth/mythmediamonitor.cpp | 16 +++++++++++----- mythtv/libs/libmyth/mythmediamonitor.h | 7 +++++-- mythtv/libs/libmythbase/mythcdrom-linux.cpp | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/mythtv/libs/libmyth/mythmediamonitor.cpp b/mythtv/libs/libmyth/mythmediamonitor.cpp index 5e41ddb55ae..943972d7b8c 100644 --- a/mythtv/libs/libmyth/mythmediamonitor.cpp +++ b/mythtv/libs/libmyth/mythmediamonitor.cpp @@ -134,7 +134,8 @@ static const QString DevName(MythMediaDevice *d) * * Has to iterate through all devices to check if any are suitable. */ -QList MediaMonitor::GetRemovable(bool showMounted) +QList MediaMonitor::GetRemovable(bool showMounted, + bool showUsable) { QList drives; QList ::iterator it; @@ -145,6 +146,9 @@ QList MediaMonitor::GetRemovable(bool showMounted) // By default, we only list CD/DVD devices. // Caller can also request mounted drives to be listed (e.g. USB flash) + if (showUsable && !(*it)->isUsable()) + continue; + if (QString(typeid(**it).name()).contains("MythCDROM") || (showMounted && (*it)->isMounted(false))) drives.append(*it); @@ -159,9 +163,11 @@ QList MediaMonitor::GetRemovable(bool showMounted) * prevent drawing a list if there is only one drive, et cetera */ MythMediaDevice * MediaMonitor::selectDrivePopup(const QString label, - bool showMounted) + bool showMounted, + bool showUsable) { - QList drives = GetRemovable(showMounted); + QList drives = GetRemovable(showMounted, + showUsable); if (drives.count() == 0) { @@ -183,8 +189,8 @@ MythMediaDevice * MediaMonitor::selectDrivePopup(const QString label, return drives.front(); } - QStringList buttonmsgs; QList ::iterator it; + QStringList buttonmsgs; for (it = drives.begin(); it != drives.end(); ++it) buttonmsgs += DevName(*it); buttonmsgs += tr("Cancel"); @@ -824,7 +830,7 @@ QString MediaMonitor::defaultDevice(QString dbSetting, if (c_monitor) { - MythMediaDevice *d = c_monitor->selectDrivePopup(label); + MythMediaDevice *d = c_monitor->selectDrivePopup(label, false, true); if (d == (MythMediaDevice *) -1) // User cancelled d = NULL; diff --git a/mythtv/libs/libmyth/mythmediamonitor.h b/mythtv/libs/libmyth/mythmediamonitor.h index b723bbcea4c..35beeb802a8 100644 --- a/mythtv/libs/libmyth/mythmediamonitor.h +++ b/mythtv/libs/libmyth/mythmediamonitor.h @@ -57,7 +57,8 @@ class MPUBLIC MediaMonitor : public QObject // To safely dereference the pointers returned by this function // first validate the pointer with ValidateAndLock(), if true is returned // it is safe to dereference the pointer. When finished call Unlock() - QList GetRemovable(bool mounted=false); + QList GetRemovable(bool showMounted = false, + bool showUsable = false); QList GetMedias(MythMediaType mediatype); MythMediaDevice* GetMedia(const QString &path); @@ -101,7 +102,9 @@ class MPUBLIC MediaMonitor : public QObject static QString defaultDevice(const QString setting, const QString label, const char *hardCodedDefault); - MythMediaDevice *selectDrivePopup(const QString label, bool mounted=false); + MythMediaDevice *selectDrivePopup(const QString label, + bool showMounted = false, + bool showUsable = false); protected: QMutex m_DevicesLock; diff --git a/mythtv/libs/libmythbase/mythcdrom-linux.cpp b/mythtv/libs/libmythbase/mythcdrom-linux.cpp index 0fb094615db..6270fc34967 100644 --- a/mythtv/libs/libmythbase/mythcdrom-linux.cpp +++ b/mythtv/libs/libmythbase/mythcdrom-linux.cpp @@ -529,7 +529,7 @@ MythMediaStatus MythCDROMLinux::checkMedia() if (isMounted()) onDeviceMounted(); else if (!mount()) // onDeviceMounted() called as side-effect - return setStatus(MEDIASTAT_ERROR, OpenedHere); + return setStatus(MEDIASTAT_NOTMOUNTED, OpenedHere); if (isMounted()) {