Go to the documentation of this file.
12 #include <QCoreApplication>
19 #include "libmythbase/mythconfig.h"
28 #ifdef USING_DARWIN_DA
30 #elif defined(Q_OS_WIN)
36 static const QString
sLocation = QObject::tr(
"Media Monitor");
51 QDateTime now(QDateTime::currentDateTimeUtc());
60 LOG(VB_GENERAL, LOG_INFO,
"Restarting LIRC handler");
80 #ifdef USING_DARWIN_DA
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;
149 QList <MythMediaDevice *>::iterator it;
157 if (showUsable && !dev->isUsable())
160 if (QString(
typeid(*dev).name()).contains(
"MythCDROM") ||
161 (showMounted && dev->isMounted(
false)))
177 QList <MythMediaDevice *> drives =
GetRemovable(showMounted,
180 if (drives.count() == 0)
182 QString msg =
"MediaMonitor::selectDrivePopup() - no removable devices";
184 LOG(VB_MEDIA, LOG_INFO, msg);
188 if (drives.count() == 1)
190 LOG(VB_MEDIA, LOG_INFO,
191 "MediaMonitor::selectDrivePopup(" + label +
192 ") - One suitable device");
193 return drives.front();
206 while (btnIndex < -1)
216 for (
auto *drive : std::as_const(drives))
217 dlg->AddButton(
DevName(drive));
219 dlg->AddButton(tr(
"Cancel"));
226 &block, [&](
const QString& ,
int result) { block.exit(result); });
229 btnIndex = block.exec();
233 return btnIndex < 0 || btnIndex >= drives.size() ? (
MythMediaDevice *)-1
234 : drives.at(btnIndex);
279 LOG(VB_MEDIA, LOG_INFO,
280 QString(
"Disk %1's tray is OPEN. Closing tray").arg(dev));
285 QObject::tr(
"Unable to open or close the empty drive %1");
287 QObject::tr(
"You may have to use the eject button under its tray");
295 LOG(VB_MEDIA, LOG_INFO,
296 QString(
"Disk %1 is mounted? Unmounting").arg(dev));
309 LOG(VB_MEDIA, LOG_INFO,
310 QString(
"Unlocking disk %1, then ejecting").arg(dev));
335 m_monitorPollingInterval(interval),
336 m_allowEject(allowEject)
341 if (!ignore.isEmpty())
346 LOG(VB_MEDIA, LOG_NOTICE,
"Creating MediaMonitor");
347 LOG(VB_MEDIA, LOG_INFO,
"IgnoreDevices=" + ignore);
350 QStringList symlinked;
351 for (
const auto & ignored : std::as_const(
m_ignoreList))
353 if (
auto fi = QFileInfo(ignored); fi.isSymLink())
358 LOG(VB_MEDIA, LOG_INFO, QString(
"Also ignoring %1 (symlinked from %2)")
359 .arg(target, ignored));
375 QObject::deleteLater();
390 QList<MythMediaDevice*>::iterator it;
393 if ((*it)->getDevicePath() == dev)
401 (*it)->deleteLater();
429 QList<MythMediaDevice*>::iterator itr =
m_devices.begin();
448 LOG(VB_MEDIA, LOG_NOTICE,
"MediaMonitor disabled by user setting.");
455 qRegisterMetaType<MythMediaStatus>(
"MythMediaStatus");
457 LOG(VB_MEDIA, LOG_NOTICE,
"Starting MediaMonitor");
471 LOG(VB_MEDIA, LOG_NOTICE,
"Stopping MediaMonitor");
475 LOG(VB_MEDIA, LOG_NOTICE,
"Stopped MediaMonitor");
518 pMedia->deleteLater();
532 for (
auto *dev : std::as_const(
m_devices))
534 if (dev->isSameDevice(path) &&
568 pMedia =
MythCDROM::get(
nullptr, devPath.toLatin1(),
true,
false);
572 LOG(VB_MEDIA, LOG_INFO,
573 "MediaMonitor::GetMountPath() - failed");
603 QList<MythMediaDevice*> medias;
605 for (
auto *dev : std::as_const(
m_devices))
607 if ((dev->getMediaType() & mediatypes) &&
612 medias.push_back(dev);
639 const QString &description,
643 const QString &extensions)
647 MHData mhd = { callback, mediaType, destination, description };
650 if (!extensions.isEmpty())
651 msg += QString(
", ext(%1)").arg(extensions);
653 LOG(VB_MEDIA, LOG_INFO,
654 "Registering '" + destination +
"' as a media handler for " +
659 if (!extensions.isEmpty())
664 LOG(VB_GENERAL, LOG_INFO,
665 destination +
" is already registered as a media handler.");
679 QMap<QString, MHData>::Iterator itr =
m_handlerMap.begin();
683 if (((*itr).MythMediaType & (
int)pMedia->
getMediaType()))
685 LOG(VB_GENERAL, LOG_NOTICE,
686 QString(
"Found a handler for %1 - '%2'")
695 LOG(VB_MEDIA, LOG_INFO,
"No media handler found for event type");
704 handlers.at(selected).callback(pMedia);
719 QString msg = QString(
" (%1, %2 -> %3)")
734 LOG(VB_MEDIA, LOG_INFO,
"Posting MediaEvent" + msg);
745 LOG(VB_MEDIA, LOG_INFO,
746 "Media status changed, but not sending event" + msg);
766 LOG(VB_MEDIA, LOG_INFO,
773 LOG(VB_MEDIA, LOG_DEBUG,
776 LOG(VB_MEDIA, LOG_DEBUG,
795 LOG(VB_GENERAL, LOG_ALERT,
796 "MediaMonitor::eventFilter() couldn't cast event");
803 LOG(VB_GENERAL, LOG_ALERT,
804 "MediaMonitor::eventFilter() got a bad media event?");
815 QMap<QString, MHData>::Iterator itr =
m_handlerMap.begin();
820 (*itr).callback(pDev);
829 return QObject::eventFilter(obj, event);
845 const QString &label,
846 const char *hardCodedDefault)
850 LOG(VB_MEDIA, LOG_DEBUG,
851 QString(
"MediaMonitor::defaultDevice(%1,..,%2) dbSetting='%3'")
852 .arg(dbSetting, hardCodedDefault, device));
855 if (device.isEmpty() || device ==
"default")
857 device = hardCodedDefault;
874 device =
d->getDevicePath();
880 LOG(VB_MEDIA, LOG_DEBUG,
881 "MediaMonitor::defaultDevice() returning " + device);
942 for (
const auto *dev : std::as_const(
m_devices))
945 QString model = dev->getDeviceModel();
946 const QString& path = dev->getDevicePath();
947 const QString& real = dev->getRealDevice();
950 devStr += path +
"->";
955 devStr +=
" (" + model +
")";
960 return list.join(
", ");
976 LOG(VB_MEDIA, LOG_INFO,
"CD/DVD Monitor isn't enabled.");
978 LOG(VB_MEDIA, LOG_INFO,
"Trying Linux 'eject -T' command");
980 #elif defined(Q_OS_DARWIN)
982 LOG(VB_MEDIA, LOG_INFO,
"Trying 'diskutil eject " + def);
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.
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="")