12#include <QCoreApplication>
19#include "libmythbase/mythconfig.h"
30#elif defined(Q_OS_WIN)
36static const QString
sLocation = QObject::tr(
"Media Monitor");
51 QDateTime now(QDateTime::currentDateTimeUtc());
60 LOG(VB_GENERAL, LOG_INFO,
"Restarting LIRC handler");
82#elif defined(Q_OS_WIN)
113 LOG(VB_MEDIA, LOG_INFO,
114 QString(
"MediaMonitor::setSpeed(%1) - Cannot find/create CDROM?")
121 QString str =
d->getVolumeID();
125 str =
d->getDeviceModel();
128 str +=
" (" +
d->getDevicePath() +
')';
130 str =
d->getDevicePath();
148 QList <MythMediaDevice *> drives;
156 if (showUsable && !dev->isUsable())
159 if (QString(
typeid(*dev).name()).contains(
"MythCDROM") ||
160 (showMounted && dev->isMounted(
false)))
178 QList <MythMediaDevice *> drives =
GetRemovable(showMounted,
181 if (drives.count() == 0)
183 QString msg =
"MediaMonitor::selectDrivePopup() - no removable devices";
185 LOG(VB_MEDIA, LOG_INFO, msg);
189 if (drives.count() == 1)
191 LOG(VB_MEDIA, LOG_INFO,
192 "MediaMonitor::selectDrivePopup(" + label +
193 ") - One suitable device");
194 return drives.front();
207 while (btnIndex < -1)
217 for (
auto *drive : std::as_const(drives))
218 dlg->AddButton(
DevName(drive));
220 dlg->AddButton(tr(
"Cancel"));
227 &block, [&](
const QString& ,
int result) { block.exit(result); });
230 btnIndex = block.exec();
234 if (btnIndex < 0 || btnIndex >= drives.size())
239 return drives.at(btnIndex);
253 bool canceled {
false };
255 selectDrivePopup(tr(
"Select removable media to eject or insert"), canceled,
true);
285 LOG(VB_MEDIA, LOG_INFO,
286 QString(
"Disk %1's tray is OPEN. Closing tray").arg(dev));
291 QObject::tr(
"Unable to open or close the empty drive %1");
293 QObject::tr(
"You may have to use the eject button under its tray");
301 LOG(VB_MEDIA, LOG_INFO,
302 QString(
"Disk %1 is mounted? Unmounting").arg(dev));
315 LOG(VB_MEDIA, LOG_INFO,
316 QString(
"Unlocking disk %1, then ejecting").arg(dev));
341 m_monitorPollingInterval(interval),
342 m_allowEject(allowEject)
347 if (!ignore.isEmpty())
352 LOG(VB_MEDIA, LOG_NOTICE,
"Creating MediaMonitor");
353 LOG(VB_MEDIA, LOG_INFO,
"IgnoreDevices=" + ignore);
356 QStringList symlinked;
357 for (
const auto & ignored : std::as_const(
m_ignoreList))
359 if (
auto fi = QFileInfo(ignored); fi.isSymLink())
364 LOG(VB_MEDIA, LOG_INFO, QString(
"Also ignoring %1 (symlinked from %2)")
365 .arg(target, ignored));
381 QObject::deleteLater();
396 QList<MythMediaDevice*>::iterator it;
399 if ((*it)->getDevicePath() == dev)
407 (*it)->deleteLater();
435 QList<MythMediaDevice*>::iterator itr =
m_devices.begin();
454 LOG(VB_MEDIA, LOG_NOTICE,
"MediaMonitor disabled by user setting.");
461 qRegisterMetaType<MythMediaStatus>(
"MythMediaStatus");
463 LOG(VB_MEDIA, LOG_NOTICE,
"Starting MediaMonitor");
477 LOG(VB_MEDIA, LOG_NOTICE,
"Stopping MediaMonitor");
481 LOG(VB_MEDIA, LOG_NOTICE,
"Stopped MediaMonitor");
524 pMedia->deleteLater();
538 for (
auto *dev : std::as_const(
m_devices))
540 if (dev->isSameDevice(path) &&
574 pMedia =
MythCDROM::get(
nullptr, devPath.toLatin1(),
true,
false);
578 LOG(VB_MEDIA, LOG_INFO,
579 "MediaMonitor::GetMountPath() - failed");
609 QList<MythMediaDevice*> medias;
611 for (
auto *dev : std::as_const(
m_devices))
613 if ((dev->getMediaType() & mediatypes) &&
618 medias.push_back(dev);
645 const QString &description,
648 const QString &extensions)
652 MHData mhd = { callback, mediaType, destination, description };
655 if (!extensions.isEmpty())
656 msg += QString(
", ext(%1)").arg(extensions);
658 LOG(VB_MEDIA, LOG_INFO,
659 "Registering '" + destination +
"' as a media handler for " +
664 if (!extensions.isEmpty())
669 LOG(VB_GENERAL, LOG_INFO,
670 destination +
" is already registered as a media handler.");
684 QMap<QString, MHData>::Iterator itr =
m_handlerMap.begin();
688 if (((*itr).MythMediaType & (
int)pMedia->
getMediaType()))
690 LOG(VB_GENERAL, LOG_NOTICE,
691 QString(
"Found a handler for %1 - '%2'")
700 LOG(VB_MEDIA, LOG_INFO,
"No media handler found for event type");
709 handlers.at(selected).callback(pMedia, forcePlayback);
724 QString msg = QString(
" (%1, %2 -> %3)")
739 LOG(VB_MEDIA, LOG_INFO,
"Posting MediaEvent" + msg);
750 LOG(VB_MEDIA, LOG_INFO,
751 "Media status changed, but not sending event" + msg);
771 LOG(VB_MEDIA, LOG_INFO,
778 LOG(VB_MEDIA, LOG_DEBUG,
781 LOG(VB_MEDIA, LOG_DEBUG,
800 LOG(VB_GENERAL, LOG_ALERT,
801 "MediaMonitor::eventFilter() couldn't cast event");
808 LOG(VB_GENERAL, LOG_ALERT,
809 "MediaMonitor::eventFilter() got a bad media event?");
820 QMap<QString, MHData>::Iterator itr =
m_handlerMap.begin();
825 (*itr).callback(pDev,
false);
834 return QObject::eventFilter(obj, event);
850 const QString &label,
851 const char *hardCodedDefault)
855 LOG(VB_MEDIA, LOG_DEBUG,
856 QString(
"MediaMonitor::defaultDevice(%1,..,%2) dbSetting='%3'")
857 .arg(dbSetting, hardCodedDefault, device));
860 if (device.isEmpty() || device ==
"default")
862 device = hardCodedDefault;
869 bool canceled {
false };
880 device =
d->getDevicePath();
886 LOG(VB_MEDIA, LOG_DEBUG,
887 "MediaMonitor::defaultDevice() returning " + device);
948 for (
const auto *dev : std::as_const(
m_devices))
951 QString model = dev->getDeviceModel();
952 const QString& path = dev->getDevicePath();
953 const QString& real = dev->getRealDevice();
956 devStr += path +
"->";
961 devStr +=
" (" + model +
")";
966 return list.join(
", ");
982 LOG(VB_MEDIA, LOG_INFO,
"CD/DVD Monitor isn't enabled.");
984 LOG(VB_MEDIA, LOG_INFO,
"Trying Linux 'eject -T' command");
986#elif defined(Q_OS_DARWIN)
988 LOG(VB_MEDIA, LOG_INFO,
"Trying 'diskutil eject " + def);
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
QDateTime m_lastCheckTime
QPointer< MediaMonitor > m_monitor
static MythCDROM * get(QObject *par, const QString &devicePath, bool SuperMount, bool AllowEject)
void setDeviceSpeed(const char *devicePath, int speed) override
QString GetSetting(const QString &key, const QString &defaultval="")
bool GetBoolSetting(const QString &key, bool defaultval=false)
Basic menu dialog, message and a list of options.
void Closed(QString, int)
MythScreenStack * GetMainStack()
void RestartInputHandlers()
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
static QList< GameHandler * > * handlers
static const iso6937table * d
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
bool HasMythMainWindow(void)
MythMainWindow * GetMythMainWindow(void)
QString getSymlinkTarget(const QString &start_file, QStringList *intermediaries, unsigned maxLinks)
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)
uint myth_system(const QString &command, uint flags, std::chrono::seconds timeout)
Stores details of media handlers.