MythTV  master
mythmediamonitor.cpp
Go to the documentation of this file.
1 
2 // Standard C headers
3 #include <cstdio>
4 
5 // C++ headers
6 #include <iostream>
7 #include <typeinfo>
8 
9 // Qt headers
10 #include <QtGlobal>
11 #include <QCoreApplication>
12 #include <QFile>
13 #include <QList>
14 #include <QDir>
15 
16 // MythTV headers
17 #include "libmythbase/mythcdrom.h"
18 #include "libmythbase/mythconfig.h"
20 #include "libmythbase/mythdate.h"
26 
27 #include "mythmediamonitor.h"
28 #ifdef USING_DARWIN_DA
29 #include "mediamonitor-darwin.h"
30 #elif defined(Q_OS_WIN)
31 #include "mediamonitor-windows.h"
32 #else
33 #include "mediamonitor-unix.h"
34 #endif
35 
36 static const QString sLocation = QObject::tr("Media Monitor");
37 
39 
40 // Nice and simple, as long as our monitor is valid and active,
41 // loop and check it's devices.
43 {
44  RunProlog();
45  QMutex mtx;
46  mtx.lock();
47  while (m_monitor && m_monitor->IsActive())
48  {
49  m_monitor->CheckDevices();
50  m_monitor->m_wait.wait(&mtx, m_interval);
51  QDateTime now(QDateTime::currentDateTimeUtc());
52  // if 10 seconds have elapsed instead of 5 seconds
53  // assume the system was suspended and reconnect
54  // sockets
55  if (m_lastCheckTime.secsTo(now) > 120)
56  {
58  if (HasMythMainWindow())
59  {
60  LOG(VB_GENERAL, LOG_INFO, "Restarting LIRC handler");
62  }
63  }
64  m_lastCheckTime = now;
65  }
66  mtx.unlock();
67  RunEpilog();
68 }
69 
71 // MediaMonitor
72 
73 static constexpr unsigned long MONITOR_INTERVAL { 5000 };
74 
76 {
77  if (s_monitor)
78  return s_monitor;
79 
80 #ifdef USING_DARWIN_DA
81  s_monitor = new MediaMonitorDarwin(nullptr, MONITOR_INTERVAL, true);
82 #elif defined(Q_OS_WIN)
83  s_monitor = new MediaMonitorWindows(nullptr, MONITOR_INTERVAL, true);
84 #else
85  s_monitor = new MediaMonitorUnix(nullptr, MONITOR_INTERVAL, true);
86 #endif
87 
88  return s_monitor;
89 }
90 
91 void MediaMonitor::SetCDSpeed(const char *device, int speed)
92 {
94  if (mon)
95  {
96  MythMediaDevice *pMedia = mon->GetMedia(device);
97  if (pMedia && mon->ValidateAndLock(pMedia))
98  {
99  pMedia->setSpeed(speed);
100  mon->Unlock(pMedia);
101  return;
102  }
103  }
104 
105  MythCDROM *cd = MythCDROM::get(nullptr, device, false, false);
106  if (cd)
107  {
108  cd->setDeviceSpeed(device, speed);
109  delete cd;
110  return;
111  }
112 
113  LOG(VB_MEDIA, LOG_INFO,
114  QString("MediaMonitor::setSpeed(%1) - Cannot find/create CDROM?")
115  .arg(device));
116 }
117 
118 // When ejecting one of multiple devices, present a nice name to the user
119 static QString DevName(MythMediaDevice *d)
120 {
121  QString str = d->getVolumeID(); // First choice, the name of the media
122 
123  if (str.isEmpty())
124  {
125  str = d->getDeviceModel(); // otherwise, the drive manufacturer/model
126 
127  if (!str.isEmpty()) // and/or the device node
128  str += " (" + d->getDevicePath() + ')';
129  else
130  str = d->getDevicePath();
131  }
132  // We could add even more information here, but volume names
133  // are usually descriptively unique (i.e. usually good enough)
134  //else
135  // str += " (" + d->getDeviceModel() + ", " + d->getDevicePath() + ')';
136 
137  return str;
138 }
139 
145 QList<MythMediaDevice*> MediaMonitor::GetRemovable(bool showMounted,
146  bool showUsable)
147 {
148  QList <MythMediaDevice *> drives;
149  QList <MythMediaDevice *>::iterator it;
150  QMutexLocker locker(&m_devicesLock);
151 
152  for (it = m_devices.begin(); it != m_devices.end(); ++it)
153  {
154  // By default, we only list CD/DVD devices.
155  // Caller can also request mounted drives to be listed (e.g. USB flash)
156 
157  if (showUsable && !(*it)->isUsable())
158  continue;
159 
160  if (QString(typeid(**it).name()).contains("MythCDROM") ||
161  (showMounted && (*it)->isMounted(false)))
162  drives.append(*it);
163  }
164 
165  return drives;
166 }
167 
174  bool showMounted,
175  bool showUsable)
176 {
177  QList <MythMediaDevice *> drives = GetRemovable(showMounted,
178  showUsable);
179 
180  if (drives.count() == 0)
181  {
182  QString msg = "MediaMonitor::selectDrivePopup() - no removable devices";
183 
184  LOG(VB_MEDIA, LOG_INFO, msg);
185  return nullptr;
186  }
187 
188  if (drives.count() == 1)
189  {
190  LOG(VB_MEDIA, LOG_INFO,
191  "MediaMonitor::selectDrivePopup(" + label +
192  ") - One suitable device");
193  return drives.front();
194  }
195 
197  if (!win)
198  return nullptr;
199 
200  MythScreenStack *stack = win->GetMainStack();
201  if (!stack)
202  return nullptr;
203 
204  // Ignore MENU dialog actions
205  int btnIndex = -2;
206  while (btnIndex < -1)
207  {
208  auto *dlg = new MythDialogBox(label, stack, "select drive");
209  if (!dlg->Create())
210  {
211  delete dlg;
212  return nullptr;
213  }
214 
215  // Add button for each drive
216  for (auto *drive : std::as_const(drives))
217  dlg->AddButton(DevName(drive));
218 
219  dlg->AddButton(tr("Cancel"));
220 
221  stack->AddScreen(dlg);
222 
223  // Wait in local event loop so events are processed
224  QEventLoop block;
225  connect(dlg, &MythDialogBox::Closed,
226  &block, [&](const QString& /*resultId*/, int result) { block.exit(result); });
227 
228  // Block until dialog closes
229  btnIndex = block.exec();
230  }
231 
232  // If the user cancelled, return a special value
233  return btnIndex < 0 || btnIndex >= drives.size() ? (MythMediaDevice *)-1
234  : drives.at(btnIndex);
235 }
236 
237 
247 {
248  MythMediaDevice *selected =
249  selectDrivePopup(tr("Select removable media to eject or insert"), true);
250 
251  // If the user cancelled, no need to display or do anything more
252  if (selected == (MythMediaDevice *) -1)
253  return;
254 
255  if (!selected)
256  {
257  ShowNotification(tr("No devices to eject"), sLocation);
258  return;
259  }
260 
261  AttemptEject(selected);
262 }
263 
264 
265 void MediaMonitor::EjectMedia(const QString &path)
266 {
267  MythMediaDevice *device = GetMedia(path);
268  if (device)
269  AttemptEject(device);
270 }
271 
272 
274 {
275  QString dev = DevName(device);
276 
277  if (device->getStatus() == MEDIASTAT_OPEN)
278  {
279  LOG(VB_MEDIA, LOG_INFO,
280  QString("Disk %1's tray is OPEN. Closing tray").arg(dev));
281 
282  if (device->eject(false) != MEDIAERR_OK)
283  {
284  QString msg =
285  QObject::tr("Unable to open or close the empty drive %1");
286  QString extra =
287  QObject::tr("You may have to use the eject button under its tray");
288  ShowNotificationError(msg.arg(dev), sLocation, extra);
289  }
290  return;
291  }
292 
293  if (device->isMounted())
294  {
295  LOG(VB_MEDIA, LOG_INFO,
296  QString("Disk %1 is mounted? Unmounting").arg(dev));
297  device->unmount();
298 
299 #ifndef Q_OS_DARWIN
300  if (device->isMounted())
301  {
302  ShowNotificationError(tr("Failed to unmount %1").arg(dev),
303  sLocation);
304  return;
305  }
306 #endif
307  }
308 
309  LOG(VB_MEDIA, LOG_INFO,
310  QString("Unlocking disk %1, then ejecting").arg(dev));
311  device->unlock();
312 
313  MythMediaError err = device->eject();
314 
315  if (err == MEDIAERR_UNSUPPORTED)
316  {
317  // Physical ejection isn't possible (there is no tray or slot),
318  // but logically the device is now ejected (ignored by the OS).
319  ShowNotification(tr("You may safely remove %1").arg(dev), sLocation);
320  }
321  else if (err == MEDIAERR_FAILED)
322  {
323  ShowNotificationError(tr("Failed to eject %1").arg(dev), sLocation);
324  }
325 }
326 
333 MediaMonitor::MediaMonitor(QObject* par, unsigned long interval, bool allowEject)
334  : QObject(par),
335  m_monitorPollingInterval(interval),
336  m_allowEject(allowEject)
337 {
338  // User can specify that some devices are not monitored
339  QString ignore = gCoreContext->GetSetting("IgnoreDevices", "");
340 
341  if (!ignore.isEmpty())
342  {
343  m_ignoreList = ignore.split(',', Qt::SkipEmptyParts);
344  }
345 
346  LOG(VB_MEDIA, LOG_NOTICE, "Creating MediaMonitor");
347  LOG(VB_MEDIA, LOG_INFO, "IgnoreDevices=" + ignore);
348 
349  // If any of IgnoreDevices are symlinks, also add the real device
350  QStringList symlinked;
351  for (const auto & ignored : std::as_const(m_ignoreList))
352  {
353  if (auto fi = QFileInfo(ignored); fi.isSymLink())
354  {
355  if (auto target = getSymlinkTarget(ignored); m_ignoreList.filter(target).isEmpty())
356  {
357  symlinked += target;
358  LOG(VB_MEDIA, LOG_INFO, QString("Also ignoring %1 (symlinked from %2)")
359  .arg(target, ignored));
360  }
361  }
362  }
363 
364  m_ignoreList += symlinked;
365 }
366 
368 {
369  if (m_thread)
370  {
371  StopMonitoring();
372  delete m_thread;
373  m_thread = nullptr;
374  }
375  QObject::deleteLater();
376 }
377 
386 bool MediaMonitor::RemoveDevice(const QString &dev)
387 {
388  QMutexLocker locker(&m_devicesLock);
389 
390  QList<MythMediaDevice*>::iterator it;
391  for (it = m_devices.begin(); it != m_devices.end(); ++it)
392  {
393  if ((*it)->getDevicePath() == dev)
394  {
395  // Ensure device gets an unmount
396  (*it)->checkMedia();
397 
398  if (m_useCount[*it] == 0)
399  {
400  m_useCount.remove(*it);
401  (*it)->deleteLater();
402  m_devices.erase(it);
403  }
404  else
405  {
406  // Other threads are still using this device
407  // postpone actual delete until they finish.
408  disconnect(*it);
409  m_removedDevices.append(*it);
410  m_devices.erase(it);
411  }
412 
413  return true;
414  }
415  }
416  return false;
417 }
418 
423 {
424  /* check if new devices have been plugged in */
426 
427  QMutexLocker locker(&m_devicesLock);
428 
429  QList<MythMediaDevice*>::iterator itr = m_devices.begin();
430  while (itr != m_devices.end())
431  {
432  MythMediaDevice* pDev = *itr;
433  if (pDev)
434  pDev->checkMedia();
435  ++itr;
436  }
437 }
438 
443 {
444  // Sanity check
445  if (m_active)
446  return;
447  if (!gCoreContext->GetBoolSetting("MonitorDrives", false)) {
448  LOG(VB_MEDIA, LOG_NOTICE, "MediaMonitor disabled by user setting.");
449  return;
450  }
451 
452  if (!m_thread)
454 
455  qRegisterMetaType<MythMediaStatus>("MythMediaStatus");
456 
457  LOG(VB_MEDIA, LOG_NOTICE, "Starting MediaMonitor");
458  m_active = true;
459  m_thread->start();
460 }
461 
466 {
467  // Sanity check
468  if (!m_active)
469  return;
470 
471  LOG(VB_MEDIA, LOG_NOTICE, "Stopping MediaMonitor");
472  m_active = false;
473  m_wait.wakeAll();
474  m_thread->wait();
475  LOG(VB_MEDIA, LOG_NOTICE, "Stopped MediaMonitor");
476 }
477 
489 {
490  QMutexLocker locker(&m_devicesLock);
491 
492  if (!m_devices.contains(pMedia))
493  return false;
494 
495  m_useCount[pMedia]++;
496 
497  return true;
498 }
499 
506 {
507  QMutexLocker locker(&m_devicesLock);
508 
509  if (!m_useCount.contains(pMedia))
510  return;
511 
512  m_useCount[pMedia]--;
513 
514  if (m_useCount[pMedia] == 0 && m_removedDevices.contains(pMedia))
515  {
516  m_removedDevices.removeAll(pMedia);
517  m_useCount.remove(pMedia);
518  pMedia->deleteLater();
519  }
520 }
521 
529 {
530  QMutexLocker locker(&m_devicesLock);
531 
532  for (auto *dev : std::as_const(m_devices))
533  {
534  if (dev->isSameDevice(path) &&
535  ((dev->getStatus() == MEDIASTAT_USEABLE) ||
536  (dev->getStatus() == MEDIASTAT_MOUNTED) ||
537  (dev->getStatus() == MEDIASTAT_NOTMOUNTED)))
538  {
539  return dev;
540  }
541  }
542 
543  return nullptr;
544 }
545 
552 QString MediaMonitor::GetMountPath(const QString& devPath)
553 {
554  QString mountPath;
555 
556  if (s_monitor)
557  {
558  MythMediaDevice *pMedia = s_monitor->GetMedia(devPath);
559  if (pMedia && s_monitor->ValidateAndLock(pMedia))
560  {
561  mountPath = pMedia->getMountPath();
562  s_monitor->Unlock(pMedia);
563  }
564  // The media monitor could be inactive.
565  // Create a fake media device just to lookup mount map:
566  else
567  {
568  pMedia = MythCDROM::get(nullptr, devPath.toLatin1(), true, false);
569  if (pMedia && pMedia->findMountPath())
570  mountPath = pMedia->getMountPath();
571  else
572  LOG(VB_MEDIA, LOG_INFO,
573  "MediaMonitor::GetMountPath() - failed");
574  // need some way to delete the media device.
575  }
576  }
577 
578  return mountPath;
579 }
580 
599 QList<MythMediaDevice*> MediaMonitor::GetMedias(unsigned mediatypes)
600 {
601  QMutexLocker locker(&m_devicesLock);
602 
603  QList<MythMediaDevice*> medias;
604 
605  for (auto *dev : std::as_const(m_devices))
606  {
607  if ((dev->getMediaType() & mediatypes) &&
608  ((dev->getStatus() == MEDIASTAT_USEABLE) ||
609  (dev->getStatus() == MEDIASTAT_MOUNTED) ||
610  (dev->getStatus() == MEDIASTAT_NOTMOUNTED)))
611  {
612  medias.push_back(dev);
613  }
614  }
615 
616  return medias;
617 }
618 
638 void MediaMonitor::RegisterMediaHandler(const QString &destination,
639  const QString &description,
640  void (*callback)
641  (MythMediaDevice*),
642  int mediaType,
643  const QString &extensions)
644 {
645  if (m_handlerMap.count(destination) == 0)
646  {
647  MHData mhd = { callback, mediaType, destination, description };
648  QString msg = MythMediaDevice::MediaTypeString((MythMediaType)mediaType);
649 
650  if (!extensions.isEmpty())
651  msg += QString(", ext(%1)").arg(extensions);
652 
653  LOG(VB_MEDIA, LOG_INFO,
654  "Registering '" + destination + "' as a media handler for " +
655  msg);
656 
657  m_handlerMap[destination] = mhd;
658 
659  if (!extensions.isEmpty())
660  MythMediaDevice::RegisterMediaExtensions(mediaType, extensions);
661  }
662  else
663  {
664  LOG(VB_GENERAL, LOG_INFO,
665  destination + " is already registered as a media handler.");
666  }
667 }
668 
677 {
678  QVector<MHData> handlers;
679  QMap<QString, MHData>::Iterator itr = m_handlerMap.begin();
680 
681  while (itr != m_handlerMap.end())
682  {
683  if (((*itr).MythMediaType & (int)pMedia->getMediaType()))
684  {
685  LOG(VB_GENERAL, LOG_NOTICE,
686  QString("Found a handler for %1 - '%2'")
687  .arg(pMedia->MediaTypeString(), itr.key()));
688  handlers.append(*itr);
689  }
690  itr++;
691  }
692 
693  if (handlers.empty())
694  {
695  LOG(VB_MEDIA, LOG_INFO, "No media handler found for event type");
696  return;
697  }
698 
699 
700  // TODO - Generate a dialog, add buttons for each description,
701  // if user didn't cancel, selected = handlers.at(choice);
702  int selected = 0;
703 
704  handlers.at(selected).callback(pMedia);
705 }
706 
712  MythMediaDevice* pMedia) const
713 {
714  // If we're not active then ignore signal.
715  if (!m_active)
716  return;
717 
718  MythMediaStatus stat = pMedia->getStatus();
719  QString msg = QString(" (%1, %2 -> %3)")
720  .arg(pMedia->MediaTypeString(),
723 
724  // This gets called from outside the main thread so we need
725  // to post an event back to the main thread.
726  // We now send events for all non-error statuses, so plugins get ejects
727  if (stat != MEDIASTAT_ERROR && stat != MEDIASTAT_UNKNOWN &&
728  // Don't send an event for a new device that's not mounted
729  (oldStatus != MEDIASTAT_UNPLUGGED || stat != MEDIASTAT_NOTMOUNTED))
730  {
731  // Should we ValidateAndLock() first?
732  QEvent *e = new MythMediaEvent(stat, pMedia);
733 
734  LOG(VB_MEDIA, LOG_INFO, "Posting MediaEvent" + msg);
735 
736  // sendEvent() is needed here - it waits for the event to be used.
737  // postEvent() would result in pDevice's media type changing
738  // ... before the plugin's event chain would process it.
739  // Another way would be to send an exact copy of pDevice instead.
740  QCoreApplication::sendEvent((QObject*)GetMythMainWindow(), e);
741  delete e;
742  }
743  else
744  LOG(VB_MEDIA, LOG_INFO,
745  "Media status changed, but not sending event" + msg);
746 
747 
748  if (stat == MEDIASTAT_OPEN || stat == MEDIASTAT_NODISK
749  || stat == MEDIASTAT_UNPLUGGED)
750  {
751  pMedia->clearData();
752  }
753 }
754 
759 {
760  if (m_ignoreList.contains(device->getMountPath()) ||
761  m_ignoreList.contains(device->getRealDevice())||
762  m_ignoreList.contains(device->getDevicePath()) )
763  {
764  LOG(VB_MEDIA, LOG_INFO,
765  "Ignoring device: " + device->getDevicePath());
766  return true;
767  }
768 #if 0
769  else
770  {
771  LOG(VB_MEDIA, LOG_DEBUG,
772  "Not ignoring: " + device->getDevicePath() + " / " +
773  device->getMountPath());
774  LOG(VB_MEDIA, LOG_DEBUG,
775  "Paths not in: " + m_ignoreList.join(", "));
776  }
777 #endif
778 
779  return false;
780 }
781 
786 bool MediaMonitor::eventFilter(QObject *obj, QEvent *event)
787 {
788  if (event->type() == MythMediaEvent::kEventType)
789  {
790  auto *me = dynamic_cast<MythMediaEvent *>(event);
791  if (me == nullptr)
792  {
793  LOG(VB_GENERAL, LOG_ALERT,
794  "MediaMonitor::eventFilter() couldn't cast event");
795  return true;
796  }
797 
798  MythMediaDevice *pDev = me->getDevice();
799  if (!pDev)
800  {
801  LOG(VB_GENERAL, LOG_ALERT,
802  "MediaMonitor::eventFilter() got a bad media event?");
803  return true;
804  }
805 
806  if (pDev->isUsable())
807  JumpToMediaHandler(pDev);
808  else
809  {
810  // We don't want to jump around in the menus, but should
811  // call each plugin's callback so it can track this change.
812 
813  QMap<QString, MHData>::Iterator itr = m_handlerMap.begin();
814  while (itr != m_handlerMap.end())
815  {
816  if ((*itr).MythMediaType & (int)pDev->getMediaType() ||
817  pDev->getStatus() == MEDIASTAT_OPEN)
818  (*itr).callback(pDev);
819  itr++;
820  }
821  }
822 
823  return false; // Don't eat the event
824  }
825 
826  // standard event processing
827  return QObject::eventFilter(obj, event);
828 }
829 
830 /*
831  * These methods return the user's preferred devices for playing and burning
832  * CDs and DVDs. Traditionally we had a database setting to remember this,
833  * but that is a bit wasteful when most users only have one drive.
834  *
835  * To make it a bit more beginner friendly, if no database default exists,
836  * or if it contains "default", the code tries to find a monitored drive.
837  * If, still, nothing is suitable, a caller hard-coded default is used.
838  *
839  * Ideally, these would return a MythMediaDevice * instead of a QString
840  */
841 
842 QString MediaMonitor::defaultDevice(const QString &dbSetting,
843  const QString &label,
844  const char *hardCodedDefault)
845 {
846  QString device = gCoreContext->GetSetting(dbSetting);
847 
848  LOG(VB_MEDIA, LOG_DEBUG,
849  QString("MediaMonitor::defaultDevice(%1,..,%2) dbSetting='%3'")
850  .arg(dbSetting, hardCodedDefault, device));
851 
852  // No settings database defaults? Try to choose one:
853  if (device.isEmpty() || device == "default")
854  {
855  device = hardCodedDefault;
856 
857  if (!s_monitor)
859 
860  if (s_monitor)
861  {
862  MythMediaDevice *d = s_monitor->selectDrivePopup(label, false, true);
863 
864  if (d == (MythMediaDevice *) -1) // User cancelled
865  {
866  device.clear(); // If user has explicitly cancelled return empty string
867  d = nullptr;
868  }
869 
870  if (d && s_monitor->ValidateAndLock(d))
871  {
872  device = d->getDevicePath();
873  s_monitor->Unlock(d);
874  }
875  }
876  }
877 
878  LOG(VB_MEDIA, LOG_DEBUG,
879  "MediaMonitor::defaultDevice() returning " + device);
880  return device;
881 }
882 
887 {
888  return defaultDevice("CDDevice", tr("Select a CD drive"), DEFAULT_CD);
889 }
890 
895 {
896  return defaultDevice("VCDDeviceLocation",
897  tr("Select a VCD drive"), DEFAULT_CD);
898 }
899 
904 {
905  return defaultDevice("DVDDeviceLocation",
906  tr("Select a DVD drive"), DEFAULT_DVD);
907 }
908 
913 {
914  return defaultDevice("CDWriterDeviceLocation",
915  tr("Select a CD writer"), DEFAULT_CD);
916 }
917 
925 {
926  QString device = defaultDevice("MythArchiveDVDLocation",
927  tr("Select a DVD writer"), DEFAULT_DVD);
928 
929  return device;
930 }
931 
932 
937 {
938  QStringList list;
939 
940  for (const auto *dev : std::as_const(m_devices))
941  {
942  QString devStr;
943  QString model = dev->getDeviceModel();
944  const QString& path = dev->getDevicePath();
945  const QString& real = dev->getRealDevice();
946 
947  if (path != real)
948  devStr += path + "->";
949  devStr += real;
950 
951  if (model.isEmpty())
952  model = "unknown";
953  devStr += " (" + model + ")";
954 
955  list += devStr;
956  }
957 
958  return list.join(", ");
959 }
960 
968 {
970  if (mon)
971  mon->ChooseAndEjectMedia();
972  else
973  {
974  LOG(VB_MEDIA, LOG_INFO, "CD/DVD Monitor isn't enabled.");
975 #ifdef __linux__
976  LOG(VB_MEDIA, LOG_INFO, "Trying Linux 'eject -T' command");
977  myth_system("eject -T");
978 #elif defined(Q_OS_DARWIN)
979  QString def = DEFAULT_CD;
980  LOG(VB_MEDIA, LOG_INFO, "Trying 'diskutil eject " + def);
981  myth_system("diskutil eject " + def);
982 #endif
983  }
984 }
985 
986 /*
987  * vim:ts=4:sw=4:ai:et:si:sts=4
988  */
MythMediaDevice::isUsable
bool isUsable() const
Is this device "ready", for a plugin to access?
Definition: mythmedia.h:84
MythMediaDevice::getMountPath
const QString & getMountPath() const
Definition: mythmedia.h:58
MediaMonitor::m_devices
QList< MythMediaDevice * > m_devices
Definition: mythmediamonitor.h:119
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:318
MediaMonitor::AttemptEject
static void AttemptEject(MythMediaDevice *device)
Definition: mythmediamonitor.cpp:273
MThread::start
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
Definition: mthread.cpp:283
MediaMonitor::m_wait
QWaitCondition m_wait
Definition: mythmediamonitor.h:127
MONITOR_INTERVAL
static constexpr unsigned long MONITOR_INTERVAL
Definition: mythmediamonitor.cpp:73
MediaMonitor::ejectOpticalDisc
static void ejectOpticalDisc(void)
Eject a disk, unmount a drive, open a tray.
Definition: mythmediamonitor.cpp:967
MediaMonitor::eventFilter
bool eventFilter(QObject *obj, QEvent *event) override
Installed into the main window's event chain, so that the main thread can safely jump to plugin code.
Definition: mythmediamonitor.cpp:786
ShowNotificationError
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
Definition: mythnotificationcenter.cpp:1426
MediaMonitor::GetMedias
QList< MythMediaDevice * > GetMedias(unsigned mediatypes)
Ask for available media. Must be locked with ValidateAndLock().
Definition: mythmediamonitor.cpp:599
MediaMonitor::m_removedDevices
QList< MythMediaDevice * > m_removedDevices
Definition: mythmediamonitor.h:120
MediaMonitor::selectDrivePopup
MythMediaDevice * selectDrivePopup(const QString &label, bool showMounted=false, bool showUsable=false)
List removable drives, let the user select one.
Definition: mythmediamonitor.cpp:173
mediamonitor-windows.h
ShowNotification
void ShowNotification(const QString &msg, const QString &from, const QString &detail, const VNMask visibility, const MythNotification::Priority priority)
Definition: mythnotificationcenter.cpp:1437
MythCoreContext::ResetSockets
void ResetSockets(void)
Definition: mythcorecontext.cpp:1826
DevName
static QString DevName(MythMediaDevice *d)
Definition: mythmediamonitor.cpp:119
MediaMonitor::GetMediaMonitor
static MediaMonitor * GetMediaMonitor(void)
Definition: mythmediamonitor.cpp:75
MonitorThread::run
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
Definition: mythmediamonitor.cpp:42
MThread::wait
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:300
mythcdrom.h
MediaMonitor::GetRemovable
QList< MythMediaDevice * > GetRemovable(bool showMounted=false, bool showUsable=false)
Generate a list of removable drives.
Definition: mythmediamonitor.cpp:145
MediaMonitor::StartMonitoring
virtual void StartMonitoring(void)
Start the monitoring thread if needed.
Definition: mythmediamonitor.cpp:442
MediaMonitor::defaultDevice
static QString defaultDevice(const QString &setting, const QString &label, const char *hardCodedDefault)
Definition: mythmediamonitor.cpp:842
MediaMonitor::MediaMonitor
MediaMonitor(QObject *par, unsigned long interval, bool allowEject)
Lookup some settings, and do OS-specific stuff in sub-classes.
Definition: mythmediamonitor.cpp:333
MEDIASTAT_ERROR
@ MEDIASTAT_ERROR
Unable to mount, but could be usable.
Definition: mythmedia.h:13
mythdialogbox.h
MythScreenStack
Definition: mythscreenstack.h:16
mythmediamonitor.h
MEDIASTAT_USEABLE
@ MEDIASTAT_USEABLE
Definition: mythmedia.h:19
getSymlinkTarget
QString getSymlinkTarget(const QString &start_file, QStringList *intermediaries, unsigned maxLinks)
Definition: mythmiscutil.cpp:451
MythMediaDevice::getDevicePath
const QString & getDevicePath() const
Definition: mythmedia.h:61
MythMediaEvent::kEventType
static const Type kEventType
Definition: mythmedia.h:193
MediaMonitor::m_monitorPollingInterval
unsigned long m_monitorPollingInterval
Definition: mythmediamonitor.h:129
MythMediaDevice::getStatus
MythMediaStatus getStatus() const
Definition: mythmedia.h:70
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MThread::RunProlog
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
Definition: mthread.cpp:196
MediaMonitor::MonitorThread
friend class MonitorThread
Definition: mythmediamonitor.h:48
MythDialogBox::Closed
void Closed(QString, int)
MediaMonitor::mediaStatusChanged
void mediaStatusChanged(MythMediaStatus oldStatus, MythMediaDevice *pMedia) const
Slot which is called when the device status changes and posts a media event to the mainwindow.
Definition: mythmediamonitor.cpp:711
MediaMonitor::s_monitor
static MediaMonitor * s_monitor
Definition: mythmediamonitor.h:134
MediaMonitor::GetMedia
MythMediaDevice * GetMedia(const QString &path)
Get media device by pathname. Must be locked with ValidateAndLock().
Definition: mythmediamonitor.cpp:528
MEDIASTAT_MOUNTED
@ MEDIASTAT_MOUNTED
Definition: mythmedia.h:21
myth_system
uint myth_system(const QString &command, uint flags, std::chrono::seconds timeout)
Definition: mythsystemlegacy.cpp:506
sLocation
static const QString sLocation
Definition: mythmediamonitor.cpp:36
HasMythMainWindow
bool HasMythMainWindow(void)
Definition: mythmainwindow.cpp:109
MonitorThread::m_lastCheckTime
QDateTime m_lastCheckTime
Definition: mythmediamonitor.h:42
MediaMonitor::SetCDSpeed
static void SetCDSpeed(const char *device, int speed)
Definition: mythmediamonitor.cpp:91
MediaMonitor::CheckDevices
void CheckDevices(void)
Poll the devices in our list.
Definition: mythmediamonitor.cpp:422
MEDIASTAT_UNPLUGGED
@ MEDIASTAT_UNPLUGGED
Definition: mythmedia.h:15
mythsystemlegacy.h
MythMediaDevice::isMounted
bool isMounted(bool bVerify=true)
Tells us if m_devicePath is a mounted device.
Definition: mythmedia.cpp:356
MediaMonitor::RegisterMediaHandler
void RegisterMediaHandler(const QString &destination, const QString &description, void(*callback)(MythMediaDevice *), int mediaType, const QString &extensions)
Register a handler for media related events.
Definition: mythmediamonitor.cpp:638
mythdate.h
mythlogging.h
MythMediaDevice::setSpeed
virtual void setSpeed(int speed)
Definition: mythmedia.cpp:330
MythMediaDevice::getRealDevice
const QString & getRealDevice() const
Definition: mythmedia.h:63
MediaMonitor::StopMonitoring
void StopMonitoring(void)
Stop the monitoring thread if needed.
Definition: mythmediamonitor.cpp:465
MythDialogBox
Basic menu dialog, message and a list of options.
Definition: mythdialogbox.h:166
MythMediaDevice::clearData
void clearData()
Definition: mythmedia.cpp:507
MythMediaEvent
Definition: mythmedia.h:183
MythMediaDevice::unlock
virtual MythMediaError unlock()
Definition: mythmedia.cpp:348
MediaMonitor::CheckDeviceNotifications
virtual void CheckDeviceNotifications(void)
Definition: mythmediamonitor.h:102
MonitorThread::m_monitor
QPointer< MediaMonitor > m_monitor
Definition: mythmediamonitor.h:40
MythMediaDevice::unmount
bool unmount()
Definition: mythmedia.h:108
MediaMonitor::Unlock
void Unlock(MythMediaDevice *pMedia)
decrements the MythMediaDevices reference count
Definition: mythmediamonitor.cpp:505
MThread::RunEpilog
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
Definition: mthread.cpp:209
MythCDROM
Definition: mythcdrom.h:6
handlers
static QList< GameHandler * > * handlers
Definition: gamehandler.cpp:27
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
MediaMonitor::m_ignoreList
QStringList m_ignoreList
Definition: mythmediamonitor.h:124
MediaMonitor
Definition: mythmediamonitor.h:45
MediaMonitor::m_handlerMap
QMap< QString, MHData > m_handlerMap
Registered Media Handlers.
Definition: mythmediamonitor.h:132
MediaMonitor::listDevices
QString listDevices(void)
A string summarising the current devices, for debugging.
Definition: mythmediamonitor.cpp:936
MediaMonitor::RemoveDevice
bool RemoveDevice(const QString &dev)
Remove a device from the media monitor.
Definition: mythmediamonitor.cpp:386
MediaMonitor::shouldIgnore
bool shouldIgnore(const MythMediaDevice *device)
Check user preferences to see if this device should be monitored.
Definition: mythmediamonitor.cpp:758
MediaMonitorDarwin
Definition: mediamonitor-darwin.h:21
MediaMonitor::defaultDVDWriter
static QString defaultDVDWriter()
MythArchiveDVDLocation, user-selected drive, or /dev/dvd.
Definition: mythmediamonitor.cpp:924
MythCoreContext::GetBoolSetting
bool GetBoolSetting(const QString &key, bool defaultval=false)
Definition: mythcorecontext.cpp:906
MediaMonitor::m_thread
MonitorThread * m_thread
Definition: mythmediamonitor.h:128
MythMediaDevice::eject
virtual MythMediaError eject(bool open_close=true)
Definition: mythmedia.cpp:307
MythMediaDevice::RegisterMediaExtensions
static void RegisterMediaExtensions(uint mediatype, const QString &extensions)
Used to register media types with extensions.
Definition: mythmedia.cpp:299
MediaMonitor::m_active
bool volatile m_active
Was MonitorThread started?
Definition: mythmediamonitor.h:126
MythCDROM::get
static MythCDROM * get(QObject *par, const QString &devicePath, bool SuperMount, bool AllowEject)
Definition: mythcdrom.cpp:43
MythMediaType
MythMediaType
Definition: mythmedia.h:24
MediaMonitor::m_useCount
QMap< MythMediaDevice *, int > m_useCount
Definition: mythmediamonitor.h:121
mythmiscutil.h
MEDIASTAT_NODISK
@ MEDIASTAT_NODISK
CD/DVD tray closed but empty, device unusable.
Definition: mythmedia.h:17
mythcorecontext.h
DEFAULT_DVD
#define DEFAULT_DVD
Definition: mediamonitor-darwin.h:4
MediaMonitor::EjectMedia
void EjectMedia(const QString &path)
Definition: mythmediamonitor.cpp:265
MythMediaDevice::kMediaStatusStrings
static const std::array< const QString, 9 > kMediaStatusStrings
Definition: mythmedia.h:117
MonitorThread::m_interval
unsigned long m_interval
Definition: mythmediamonitor.h:41
MHData
Stores details of media handlers.
Definition: mythmediamonitor.h:20
MythMediaDevice::checkMedia
virtual MythMediaStatus checkMedia()=0
MythCDROM::setDeviceSpeed
void setDeviceSpeed(const char *devicePath, int speed) override
Definition: mythcdrom.cpp:140
MythMediaDevice::getMediaType
MythMediaType getMediaType() const
Definition: mythmedia.h:91
MediaMonitorWindows
Definition: mediamonitor-windows.h:9
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
MEDIASTAT_OPEN
@ MEDIASTAT_OPEN
CD/DVD tray open (meaningless for non-CDs?)
Definition: mythmedia.h:16
MediaMonitor::defaultCDWriter
static QString defaultCDWriter()
CDWriterDeviceLocation, user-selected drive, or /dev/cdrom.
Definition: mythmediamonitor.cpp:912
MediaMonitor::defaultDVDdevice
static QString defaultDVDdevice()
DVDDeviceLocation, user-selected drive, or /dev/dvd.
Definition: mythmediamonitor.cpp:903
MediaMonitor::ValidateAndLock
bool ValidateAndLock(MythMediaDevice *pMedia)
Validates the MythMediaDevice and increments its reference count.
Definition: mythmediamonitor.cpp:488
MEDIAERR_FAILED
@ MEDIAERR_FAILED
Definition: mythmedia.h:41
MythMediaError
MythMediaError
Definition: mythmedia.h:39
MythMediaDevice
Definition: mythmedia.h:48
d
static const iso6937table * d
Definition: iso6937tables.cpp:1025
mediamonitor-unix.h
MediaMonitor::deleteLater
virtual void deleteLater(void)
Definition: mythmediamonitor.cpp:367
MediaMonitor::JumpToMediaHandler
void JumpToMediaHandler(MythMediaDevice *pMedia)
Find a relevant jump point for this type of media.
Definition: mythmediamonitor.cpp:676
MEDIAERR_OK
@ MEDIAERR_OK
Definition: mythmedia.h:40
MEDIASTAT_UNKNOWN
@ MEDIASTAT_UNKNOWN
Definition: mythmedia.h:14
MEDIAERR_UNSUPPORTED
@ MEDIAERR_UNSUPPORTED
Definition: mythmedia.h:42
MythMainWindow::RestartInputHandlers
void RestartInputHandlers()
Definition: mythmainwindow.cpp:2102
mediamonitor-darwin.h
MediaMonitorUnix
Definition: mediamonitor-unix.h:16
MythMediaStatus
MythMediaStatus
Definition: mythmedia.h:12
mythmainwindow.h
DEFAULT_CD
#define DEFAULT_CD
Definition: mediamonitor-darwin.h:5
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
MediaMonitor::ChooseAndEjectMedia
void ChooseAndEjectMedia(void)
Unmounts and ejects removable media devices.
Definition: mythmediamonitor.cpp:246
MediaMonitor::defaultVCDdevice
static QString defaultVCDdevice()
VCDDeviceLocation, user-selected drive, or /dev/cdrom.
Definition: mythmediamonitor.cpp:894
MythMainWindow
Definition: mythmainwindow.h:28
MediaMonitor::m_devicesLock
QRecursiveMutex m_devicesLock
Definition: mythmediamonitor.h:118
MythMediaDevice::findMountPath
bool findMountPath()
Try to find a mount of m_devicePath in the mounts file.
Definition: mythmedia.cpp:364
MediaMonitor::defaultCDdevice
static QString defaultCDdevice()
CDDevice, user-selected drive, or /dev/cdrom.
Definition: mythmediamonitor.cpp:886
MEDIASTAT_NOTMOUNTED
@ MEDIASTAT_NOTMOUNTED
Definition: mythmedia.h:20
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:898
MediaMonitor::GetMountPath
static QString GetMountPath(const QString &devPath)
If the device is being monitored, return its mountpoint.
Definition: mythmediamonitor.cpp:552
MythMediaDevice::MediaTypeString
QString MediaTypeString()
Definition: mythmedia.cpp:514