Go to the documentation of this file.
11 #include <QCoreApplication>
18 #include "libmythbase/mythconfig.h"
28 #ifdef USING_DARWIN_DA
30 #elif defined(Q_OS_WIN)
36 static const QString
sLocation = QObject::tr(
"Media Monitor");
60 QDateTime now(QDateTime::currentDateTimeUtc());
69 LOG(VB_GENERAL, LOG_INFO,
"Restarting LIRC handler");
82 #define MONITOR_INTERVAL 5000
89 #ifdef USING_DARWIN_DA
91 #elif defined(Q_OS_WIN)
122 LOG(VB_MEDIA, LOG_INFO,
123 QString(
"MediaMonitor::setSpeed(%1) - Cannot find/create CDROM?")
130 QString str =
d->getVolumeID();
134 str =
d->getDeviceModel();
137 str +=
" (" +
d->getDevicePath() +
')';
139 str =
d->getDevicePath();
157 QList <MythMediaDevice *> drives;
158 QList <MythMediaDevice *>::iterator it;
166 if (showUsable && !(*it)->isUsable())
169 if (QString(
typeid(**it).name()).contains(
"MythCDROM") ||
170 (showMounted && (*it)->isMounted(
false)))
186 QList <MythMediaDevice *> drives =
GetRemovable(showMounted,
189 if (drives.count() == 0)
191 QString msg =
"MediaMonitor::selectDrivePopup() - no removable devices";
193 LOG(VB_MEDIA, LOG_INFO, msg);
197 if (drives.count() == 1)
199 LOG(VB_MEDIA, LOG_INFO,
200 "MediaMonitor::selectDrivePopup(" + label +
201 ") - One suitable device");
202 return drives.front();
215 while (btnIndex < -1)
225 for (
auto *drive : drives)
226 dlg->AddButton(
DevName(drive));
228 dlg->AddButton(tr(
"Cancel"));
235 &block, [&](
const QString& ,
int result) { block.exit(result); });
238 btnIndex = block.exec();
242 return btnIndex < 0 || btnIndex >= drives.size() ? (
MythMediaDevice *)-1
243 : drives.at(btnIndex);
288 LOG(VB_MEDIA, LOG_INFO,
289 QString(
"Disk %1's tray is OPEN. Closing tray").arg(dev));
294 QObject::tr(
"Unable to open or close the empty drive %1");
296 QObject::tr(
"You may have to use the eject button under its tray");
304 LOG(VB_MEDIA, LOG_INFO,
305 QString(
"Disk %1 is mounted? Unmounting").arg(dev));
318 LOG(VB_MEDIA, LOG_INFO,
319 QString(
"Unlocking disk %1, then ejecting").arg(dev));
344 m_monitorPollingInterval(interval),
345 m_allowEject(allowEject)
350 if (!ignore.isEmpty())
352 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
353 m_ignoreList = ignore.split(
',', QString::SkipEmptyParts);
359 LOG(VB_MEDIA, LOG_NOTICE,
"Creating MediaMonitor");
360 LOG(VB_MEDIA, LOG_INFO,
"IgnoreDevices=" + ignore);
363 QStringList symlinked;
366 if (
auto fi = QFileInfo(ignored); fi.isSymLink())
371 LOG(VB_MEDIA, LOG_INFO, QString(
"Also ignoring %1 (symlinked from %2)")
372 .arg(target, ignored));
388 QObject::deleteLater();
403 QList<MythMediaDevice*>::iterator it;
406 if ((*it)->getDevicePath() == dev)
414 (*it)->deleteLater();
442 QList<MythMediaDevice*>::iterator itr =
m_devices.begin();
461 LOG(VB_MEDIA, LOG_NOTICE,
"MediaMonitor disabled by user setting.");
468 qRegisterMetaType<MythMediaStatus>(
"MythMediaStatus");
470 LOG(VB_MEDIA, LOG_NOTICE,
"Starting MediaMonitor");
484 LOG(VB_MEDIA, LOG_NOTICE,
"Stopping MediaMonitor");
488 LOG(VB_MEDIA, LOG_NOTICE,
"Stopped MediaMonitor");
531 pMedia->deleteLater();
547 if (dev->isSameDevice(path) &&
581 pMedia =
MythCDROM::get(
nullptr, devPath.toLatin1(),
true,
false);
585 LOG(VB_MEDIA, LOG_INFO,
586 "MediaMonitor::GetMountPath() - failed");
616 QList<MythMediaDevice*> medias;
620 if ((dev->getMediaType() & mediatypes) &&
625 medias.push_back(dev);
652 const QString &description,
656 const QString &extensions)
660 MHData mhd = { callback, mediaType, destination, description };
663 if (!extensions.isEmpty())
664 msg += QString(
", ext(%1)").arg(extensions);
666 LOG(VB_MEDIA, LOG_INFO,
667 "Registering '" + destination +
"' as a media handler for " +
672 if (!extensions.isEmpty())
677 LOG(VB_GENERAL, LOG_INFO,
678 destination +
" is already registered as a media handler.");
692 QMap<QString, MHData>::Iterator itr =
m_handlerMap.begin();
696 if (((*itr).MythMediaType & (
int)pMedia->
getMediaType()))
698 LOG(VB_GENERAL, LOG_NOTICE,
699 QString(
"Found a handler for %1 - '%2'")
708 LOG(VB_MEDIA, LOG_INFO,
"No media handler found for event type");
717 handlers.at(selected).callback(pMedia);
732 QString msg = QString(
" (%1, %2 -> %3)")
747 LOG(VB_MEDIA, LOG_INFO,
"Posting MediaEvent" + msg);
757 LOG(VB_MEDIA, LOG_INFO,
758 "Media status changed, but not sending event" + msg);
777 LOG(VB_MEDIA, LOG_INFO,
784 LOG(VB_MEDIA, LOG_DEBUG,
787 LOG(VB_MEDIA, LOG_DEBUG,
806 LOG(VB_GENERAL, LOG_ALERT,
807 "MediaMonitor::eventFilter() couldn't cast event");
814 LOG(VB_GENERAL, LOG_ALERT,
815 "MediaMonitor::eventFilter() got a bad media event?");
826 QMap<QString, MHData>::Iterator itr =
m_handlerMap.begin();
831 (*itr).callback(pDev);
840 return QObject::eventFilter(obj, event);
856 const QString &label,
857 const char *hardCodedDefault)
861 LOG(VB_MEDIA, LOG_DEBUG,
862 QString(
"MediaMonitor::defaultDevice(%1,..,%2) dbSetting='%3'")
863 .arg(dbSetting, hardCodedDefault, device));
866 if (device.isEmpty() || device ==
"default")
868 device = hardCodedDefault;
885 device =
d->getDevicePath();
891 LOG(VB_MEDIA, LOG_DEBUG,
892 "MediaMonitor::defaultDevice() returning " + device);
953 for (
const auto *dev : qAsConst(
m_devices))
956 QString model = dev->getDeviceModel();
957 const QString& path = dev->getDevicePath();
958 const QString& real = dev->getRealDevice();
961 devStr += path +
"->";
966 devStr +=
" (" + model +
")";
971 return list.join(
", ");
987 LOG(VB_MEDIA, LOG_INFO,
"CD/DVD Monitor isn't enabled.");
989 LOG(VB_MEDIA, LOG_INFO,
"Trying Linux 'eject -T' command");
991 #elif defined(Q_OS_DARWIN)
993 LOG(VB_MEDIA, LOG_INFO,
"Trying 'diskutil eject " + def);
MonitorThread(MediaMonitor *pMon, unsigned long interval)
MythScreenStack * GetMainStack()
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
void ShowNotificationError(const QString &msg, const QString &from, const QString &detail, const VNMask visibility, const MythNotification::Priority priority)
convenience utility to display error message as notification
void ShowNotification(const QString &msg, const QString &from, const QString &detail, const VNMask visibility, const MythNotification::Priority priority)
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
QString getSymlinkTarget(const QString &start_file, QStringList *intermediaries, unsigned maxLinks)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
void Closed(QString, int)
uint myth_system(const QString &command, uint flags, std::chrono::seconds timeout)
bool HasMythMainWindow(void)
QDateTime m_lastCheckTime
Basic menu dialog, message and a list of options.
QPointer< MediaMonitor > m_monitor
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
static QList< GameHandler * > * handlers
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
bool GetBoolSetting(const QString &key, bool defaultval=false)
static MythCDROM * get(QObject *par, const QString &devicePath, bool SuperMount, bool AllowEject)
Stores details of media handlers.
This is a wrapper around QThread that does several additional things.
void setDeviceSpeed(const char *devicePath, int speed) override
MythMainWindow * GetMythMainWindow(void)
static const iso6937table * d
void RestartInputHandlers()
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
QString GetSetting(const QString &key, const QString &defaultval="")