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 <QCoreApplication>
11 #include <QFile>
12 #include <QList>
13 #include <QDir>
14 
15 // MythTV headers
16 #include "mythmediamonitor.h"
17 #include "mythcdrom.h"
18 #include "mythcorecontext.h"
19 #include "mythconfig.h"
20 #include "mythdialogbox.h"
21 #include "mythdate.h"
22 #include "mythlogging.h"
23 #include "mythmainwindow.h"
24 #include "mythsystemlegacy.h"
25 #include "mythmiscutil.h"
26 
27 #ifdef USING_DARWIN_DA
28 #include "mediamonitor-darwin.h"
29 #elif CONFIG_CYGWIN || defined(_WIN32)
30 #include "mediamonitor-windows.h"
31 #else
32 #include "mediamonitor-unix.h"
33 #endif
34 
35 static const QString sLocation = QObject::tr("Media Monitor");
36 
38 
39 // MonitorThread
40 MonitorThread::MonitorThread(MediaMonitor* pMon, unsigned long interval) :
41  MThread("Monitor")
42 {
43  m_monitor = pMon;
44  m_interval = interval;
45  m_lastCheckTime = QDateTime::currentDateTimeUtc();
46 }
47 
48 // Nice and simple, as long as our monitor is valid and active,
49 // loop and check it's devices.
51 {
52  RunProlog();
53  QMutex mtx;
54  mtx.lock();
55  while (m_monitor && m_monitor->IsActive())
56  {
57  m_monitor->CheckDevices();
58  m_monitor->m_wait.wait(&mtx, m_interval);
59  QDateTime now(QDateTime::currentDateTimeUtc());
60  // if 10 seconds have elapsed instead of 5 seconds
61  // assume the system was suspended and reconnect
62  // sockets
63  if (m_lastCheckTime.secsTo(now) > 120)
64  {
66  if (HasMythMainWindow())
67  {
68  LOG(VB_GENERAL, LOG_INFO, "Restarting LIRC handler");
70  }
71  }
72  m_lastCheckTime = now;
73  }
74  mtx.unlock();
75  RunEpilog();
76 }
77 
79 // MediaMonitor
80 
81 #define MONITOR_INTERVAL 5000
82 
84 {
85  if (s_monitor)
86  return s_monitor;
87 
88 #ifdef USING_DARWIN_DA
89  s_monitor = new MediaMonitorDarwin(nullptr, MONITOR_INTERVAL, true);
90 #else
91  #if CONFIG_CYGWIN || defined(_WIN32)
92  s_monitor = new MediaMonitorWindows(nullptr, MONITOR_INTERVAL, true);
93  #else
94  s_monitor = new MediaMonitorUnix(nullptr, MONITOR_INTERVAL, true);
95  #endif
96 #endif
97 
98  return s_monitor;
99 }
100 
101 void MediaMonitor::SetCDSpeed(const char *device, int speed)
102 {
103  MediaMonitor *mon = GetMediaMonitor();
104  if (mon)
105  {
106  MythMediaDevice *pMedia = mon->GetMedia(device);
107  if (pMedia && mon->ValidateAndLock(pMedia))
108  {
109  pMedia->setSpeed(speed);
110  mon->Unlock(pMedia);
111  return;
112  }
113  }
114 
115  MythCDROM *cd = MythCDROM::get(nullptr, device, false, false);
116  if (cd)
117  {
118  cd->setDeviceSpeed(device, speed);
119  delete cd;
120  return;
121  }
122 
123  LOG(VB_MEDIA, LOG_INFO,
124  QString("MediaMonitor::setSpeed(%1) - Cannot find/create CDROM?")
125  .arg(device));
126 }
127 
128 // When ejecting one of multiple devices, present a nice name to the user
129 static QString DevName(MythMediaDevice *d)
130 {
131  QString str = d->getVolumeID(); // First choice, the name of the media
132 
133  if (str.isEmpty())
134  {
135  str = d->getDeviceModel(); // otherwise, the drive manufacturer/model
136 
137  if (!str.isEmpty()) // and/or the device node
138  str += " (" + d->getDevicePath() + ')';
139  else
140  str = d->getDevicePath();
141  }
142  // We could add even more information here, but volume names
143  // are usually descriptively unique (i.e. usually good enough)
144  //else
145  // str += " (" + d->getDeviceModel() + ", " + d->getDevicePath() + ')';
146 
147  return str;
148 }
149 
155 QList<MythMediaDevice*> MediaMonitor::GetRemovable(bool showMounted,
156  bool showUsable)
157 {
158  QList <MythMediaDevice *> drives;
159  QList <MythMediaDevice *>::iterator it;
160  QMutexLocker locker(&m_devicesLock);
161 
162  for (it = m_devices.begin(); it != m_devices.end(); ++it)
163  {
164  // By default, we only list CD/DVD devices.
165  // Caller can also request mounted drives to be listed (e.g. USB flash)
166 
167  if (showUsable && !(*it)->isUsable())
168  continue;
169 
170  if (QString(typeid(**it).name()).contains("MythCDROM") ||
171  (showMounted && (*it)->isMounted(false)))
172  drives.append(*it);
173  }
174 
175  return drives;
176 }
177 
184  bool showMounted,
185  bool showUsable)
186 {
187  QList <MythMediaDevice *> drives = GetRemovable(showMounted,
188  showUsable);
189 
190  if (drives.count() == 0)
191  {
192  QString msg = "MediaMonitor::selectDrivePopup() - no removable devices";
193 
194  LOG(VB_MEDIA, LOG_INFO, msg);
195  return nullptr;
196  }
197 
198  if (drives.count() == 1)
199  {
200  LOG(VB_MEDIA, LOG_INFO,
201  "MediaMonitor::selectDrivePopup(" + label +
202  ") - One suitable device");
203  return drives.front();
204  }
205 
207  if (!win)
208  return nullptr;
209 
210  MythScreenStack *stack = win->GetMainStack();
211  if (!stack)
212  return nullptr;
213 
214  // Ignore MENU dialog actions
215  int btnIndex = -2;
216  while (btnIndex < -1)
217  {
218  auto *dlg = new MythDialogBox(label, stack, "select drive");
219  if (!dlg->Create())
220  {
221  delete dlg;
222  return nullptr;
223  }
224 
225  // Add button for each drive
226  for (auto *drive : drives)
227  dlg->AddButton(DevName(drive));
228 
229  dlg->AddButton(tr("Cancel"));
230 
231  stack->AddScreen(dlg);
232 
233  // Wait in local event loop so events are processed
234  QEventLoop block;
235  connect(dlg, &MythDialogBox::Closed,
236  &block, [&](const QString& /*resultId*/, int result) { block.exit(result); });
237 
238  // Block until dialog closes
239  btnIndex = block.exec();
240  }
241 
242  // If the user cancelled, return a special value
243  return btnIndex < 0 || btnIndex >= drives.size() ? (MythMediaDevice *)-1
244  : drives.at(btnIndex);
245 }
246 
247 
257 {
258  MythMediaDevice *selected =
259  selectDrivePopup(tr("Select removable media to eject or insert"), true);
260 
261  // If the user cancelled, no need to display or do anything more
262  if (selected == (MythMediaDevice *) -1)
263  return;
264 
265  if (!selected)
266  {
267  ShowNotification(tr("No devices to eject"), sLocation);
268  return;
269  }
270 
271  AttemptEject(selected);
272 }
273 
274 
275 void MediaMonitor::EjectMedia(const QString &path)
276 {
277  MythMediaDevice *device = GetMedia(path);
278  if (device)
279  AttemptEject(device);
280 }
281 
282 
284 {
285  QString dev = DevName(device);
286 
287  if (device->getStatus() == MEDIASTAT_OPEN)
288  {
289  LOG(VB_MEDIA, LOG_INFO,
290  QString("Disk %1's tray is OPEN. Closing tray").arg(dev));
291 
292  if (device->eject(false) != MEDIAERR_OK)
293  {
294  QString msg =
295  QObject::tr("Unable to open or close the empty drive %1");
296  QString extra =
297  QObject::tr("You may have to use the eject button under its tray");
298  ShowNotificationError(msg.arg(dev), sLocation, extra);
299  }
300  return;
301  }
302 
303  if (device->isMounted())
304  {
305  LOG(VB_MEDIA, LOG_INFO,
306  QString("Disk %1 is mounted? Unmounting").arg(dev));
307  device->unmount();
308 
309 #if !CONFIG_DARWIN
310  if (device->isMounted())
311  {
312  ShowNotificationError(tr("Failed to unmount %1").arg(dev),
313  sLocation);
314  return;
315  }
316 #endif
317  }
318 
319  LOG(VB_MEDIA, LOG_INFO,
320  QString("Unlocking disk %1, then ejecting").arg(dev));
321  device->unlock();
322 
323  MythMediaError err = device->eject();
324 
325  if (err == MEDIAERR_UNSUPPORTED)
326  {
327  // Physical ejection isn't possible (there is no tray or slot),
328  // but logically the device is now ejected (ignored by the OS).
329  ShowNotification(tr("You may safely remove %1").arg(dev), sLocation);
330  }
331  else if (err == MEDIAERR_FAILED)
332  {
333  ShowNotificationError(tr("Failed to eject %1").arg(dev), sLocation);
334  }
335 }
336 
343 MediaMonitor::MediaMonitor(QObject* par, unsigned long interval, bool allowEject)
344  : QObject(par),
345  m_monitorPollingInterval(interval),
346  m_allowEject(allowEject)
347 {
348  // User can specify that some devices are not monitored
349  QString ignore = gCoreContext->GetSetting("IgnoreDevices", "");
350 
351  if (!ignore.isEmpty())
352  {
353 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
354  m_ignoreList = ignore.split(',', QString::SkipEmptyParts);
355 #else
356  m_ignoreList = ignore.split(',', Qt::SkipEmptyParts);
357 #endif
358  }
359 
360  LOG(VB_MEDIA, LOG_NOTICE, "Creating MediaMonitor");
361  LOG(VB_MEDIA, LOG_INFO, "IgnoreDevices=" + ignore);
362 
363  // If any of IgnoreDevices are symlinks, also add the real device
364  QStringList symlinked;
365  for (const auto & ignored : qAsConst(m_ignoreList))
366  {
367  if (auto fi = QFileInfo(ignored); fi.isSymLink())
368  {
369  if (auto target = getSymlinkTarget(ignored); m_ignoreList.filter(target).isEmpty())
370  {
371  symlinked += target;
372  LOG(VB_MEDIA, LOG_INFO, QString("Also ignoring %1 (symlinked from %2)")
373  .arg(target, ignored));
374  }
375  }
376  }
377 
378  m_ignoreList += symlinked;
379 }
380 
382 {
383  if (m_thread)
384  {
385  StopMonitoring();
386  delete m_thread;
387  m_thread = nullptr;
388  }
389  QObject::deleteLater();
390 }
391 
400 bool MediaMonitor::RemoveDevice(const QString &dev)
401 {
402  QMutexLocker locker(&m_devicesLock);
403 
404  QList<MythMediaDevice*>::iterator it;
405  for (it = m_devices.begin(); it != m_devices.end(); ++it)
406  {
407  if ((*it)->getDevicePath() == dev)
408  {
409  // Ensure device gets an unmount
410  (*it)->checkMedia();
411 
412  if (m_useCount[*it] == 0)
413  {
414  m_useCount.remove(*it);
415  (*it)->deleteLater();
416  m_devices.erase(it);
417  }
418  else
419  {
420  // Other threads are still using this device
421  // postpone actual delete until they finish.
422  disconnect(*it);
423  m_removedDevices.append(*it);
424  m_devices.erase(it);
425  }
426 
427  return true;
428  }
429  }
430  return false;
431 }
432 
437 {
438  /* check if new devices have been plugged in */
440 
441  QMutexLocker locker(&m_devicesLock);
442 
443  QList<MythMediaDevice*>::iterator itr = m_devices.begin();
444  while (itr != m_devices.end())
445  {
446  MythMediaDevice* pDev = *itr;
447  if (pDev)
448  pDev->checkMedia();
449  ++itr;
450  }
451 }
452 
457 {
458  // Sanity check
459  if (m_active)
460  return;
461  if (!gCoreContext->GetBoolSetting("MonitorDrives", false)) {
462  LOG(VB_MEDIA, LOG_NOTICE, "MediaMonitor disabled by user setting.");
463  return;
464  }
465 
466  if (!m_thread)
468 
469  qRegisterMetaType<MythMediaStatus>("MythMediaStatus");
470 
471  LOG(VB_MEDIA, LOG_NOTICE, "Starting MediaMonitor");
472  m_active = true;
473  m_thread->start();
474 }
475 
480 {
481  // Sanity check
482  if (!m_active)
483  return;
484 
485  LOG(VB_MEDIA, LOG_NOTICE, "Stopping MediaMonitor");
486  m_active = false;
487  m_wait.wakeAll();
488  m_thread->wait();
489  LOG(VB_MEDIA, LOG_NOTICE, "Stopped MediaMonitor");
490 }
491 
503 {
504  QMutexLocker locker(&m_devicesLock);
505 
506  if (!m_devices.contains(pMedia))
507  return false;
508 
509  m_useCount[pMedia]++;
510 
511  return true;
512 }
513 
520 {
521  QMutexLocker locker(&m_devicesLock);
522 
523  if (!m_useCount.contains(pMedia))
524  return;
525 
526  m_useCount[pMedia]--;
527 
528  if (m_useCount[pMedia] == 0 && m_removedDevices.contains(pMedia))
529  {
530  m_removedDevices.removeAll(pMedia);
531  m_useCount.remove(pMedia);
532  pMedia->deleteLater();
533  }
534 }
535 
543 {
544  QMutexLocker locker(&m_devicesLock);
545 
546  for (auto *dev : qAsConst(m_devices))
547  {
548  if (dev->isSameDevice(path) &&
549  ((dev->getStatus() == MEDIASTAT_USEABLE) ||
550  (dev->getStatus() == MEDIASTAT_MOUNTED) ||
551  (dev->getStatus() == MEDIASTAT_NOTMOUNTED)))
552  {
553  return dev;
554  }
555  }
556 
557  return nullptr;
558 }
559 
566 QString MediaMonitor::GetMountPath(const QString& devPath)
567 {
568  QString mountPath;
569 
570  if (s_monitor)
571  {
572  MythMediaDevice *pMedia = s_monitor->GetMedia(devPath);
573  if (pMedia && s_monitor->ValidateAndLock(pMedia))
574  {
575  mountPath = pMedia->getMountPath();
576  s_monitor->Unlock(pMedia);
577  }
578  // The media monitor could be inactive.
579  // Create a fake media device just to lookup mount map:
580  else
581  {
582  pMedia = MythCDROM::get(nullptr, devPath.toLatin1(), true, false);
583  if (pMedia && pMedia->findMountPath())
584  mountPath = pMedia->getMountPath();
585  else
586  LOG(VB_MEDIA, LOG_INFO,
587  "MediaMonitor::GetMountPath() - failed");
588  // need some way to delete the media device.
589  }
590  }
591 
592  return mountPath;
593 }
594 
613 QList<MythMediaDevice*> MediaMonitor::GetMedias(unsigned mediatypes)
614 {
615  QMutexLocker locker(&m_devicesLock);
616 
617  QList<MythMediaDevice*> medias;
618 
619  for (auto *dev : qAsConst(m_devices))
620  {
621  if ((dev->getMediaType() & mediatypes) &&
622  ((dev->getStatus() == MEDIASTAT_USEABLE) ||
623  (dev->getStatus() == MEDIASTAT_MOUNTED) ||
624  (dev->getStatus() == MEDIASTAT_NOTMOUNTED)))
625  {
626  medias.push_back(dev);
627  }
628  }
629 
630  return medias;
631 }
632 
652 void MediaMonitor::RegisterMediaHandler(const QString &destination,
653  const QString &description,
654  void (*callback)
655  (MythMediaDevice*),
656  int mediaType,
657  const QString &extensions)
658 {
659  if (m_handlerMap.count(destination) == 0)
660  {
661  MHData mhd = { callback, mediaType, destination, description };
662  QString msg = MythMediaDevice::MediaTypeString((MythMediaType)mediaType);
663 
664  if (!extensions.isEmpty())
665  msg += QString(", ext(%1)").arg(extensions);
666 
667  LOG(VB_MEDIA, LOG_INFO,
668  "Registering '" + destination + "' as a media handler for " +
669  msg);
670 
671  m_handlerMap[destination] = mhd;
672 
673  if (!extensions.isEmpty())
674  MythMediaDevice::RegisterMediaExtensions(mediaType, extensions);
675  }
676  else
677  {
678  LOG(VB_GENERAL, LOG_INFO,
679  destination + " is already registered as a media handler.");
680  }
681 }
682 
691 {
692  QVector<MHData> handlers;
693  QMap<QString, MHData>::Iterator itr = m_handlerMap.begin();
694 
695  while (itr != m_handlerMap.end())
696  {
697  if (((*itr).MythMediaType & (int)pMedia->getMediaType()))
698  {
699  LOG(VB_GENERAL, LOG_NOTICE,
700  QString("Found a handler for %1 - '%2'")
701  .arg(pMedia->MediaTypeString(), itr.key()));
702  handlers.append(*itr);
703  }
704  itr++;
705  }
706 
707  if (handlers.empty())
708  {
709  LOG(VB_MEDIA, LOG_INFO, "No media handler found for event type");
710  return;
711  }
712 
713 
714  // TODO - Generate a dialog, add buttons for each description,
715  // if user didn't cancel, selected = handlers.at(choice);
716  int selected = 0;
717 
718  handlers.at(selected).callback(pMedia);
719 }
720 
726  MythMediaDevice* pMedia) const
727 {
728  // If we're not active then ignore signal.
729  if (!m_active)
730  return;
731 
732  MythMediaStatus stat = pMedia->getStatus();
733  QString msg = QString(" (%1, %2 -> %3)")
734  .arg(pMedia->MediaTypeString(),
737 
738  // This gets called from outside the main thread so we need
739  // to post an event back to the main thread.
740  // We now send events for all non-error statuses, so plugins get ejects
741  if (stat != MEDIASTAT_ERROR && stat != MEDIASTAT_UNKNOWN &&
742  // Don't send an event for a new device that's not mounted
743  !(oldStatus == MEDIASTAT_UNPLUGGED && stat == MEDIASTAT_NOTMOUNTED))
744  {
745  // Should we ValidateAndLock() first?
746  QEvent *e = new MythMediaEvent(stat, pMedia);
747 
748  LOG(VB_MEDIA, LOG_INFO, "Posting MediaEvent" + msg);
749 
750  // sendEvent() is needed here - it waits for the event to be used.
751  // postEvent() would result in pDevice's media type changing
752  // ... before the plugin's event chain would process it.
753  // Another way would be to send an exact copy of pDevice instead.
754  QCoreApplication::sendEvent((QObject*)GetMythMainWindow(), e);
755  delete e;
756  }
757  else
758  LOG(VB_MEDIA, LOG_INFO,
759  "Media status changed, but not sending event" + msg);
760 
761 
762  if (stat == MEDIASTAT_OPEN || stat == MEDIASTAT_NODISK
763  || stat == MEDIASTAT_UNPLUGGED)
764  {
765  pMedia->clearData();
766  }
767 }
768 
773 {
774  if (m_ignoreList.contains(device->getMountPath()) ||
775  m_ignoreList.contains(device->getRealDevice())||
776  m_ignoreList.contains(device->getDevicePath()) )
777  {
778  LOG(VB_MEDIA, LOG_INFO,
779  "Ignoring device: " + device->getDevicePath());
780  return true;
781  }
782 #if 0
783  else
784  {
785  LOG(VB_MEDIA, LOG_DEBUG,
786  "Not ignoring: " + device->getDevicePath() + " / " +
787  device->getMountPath());
788  LOG(VB_MEDIA, LOG_DEBUG,
789  "Paths not in: " + m_ignoreList.join(", "));
790  }
791 #endif
792 
793  return false;
794 }
795 
800 bool MediaMonitor::eventFilter(QObject *obj, QEvent *event)
801 {
802  if (event->type() == MythMediaEvent::kEventType)
803  {
804  auto *me = dynamic_cast<MythMediaEvent *>(event);
805  if (me == nullptr)
806  {
807  LOG(VB_GENERAL, LOG_ALERT,
808  "MediaMonitor::eventFilter() couldn't cast event");
809  return true;
810  }
811 
812  MythMediaDevice *pDev = me->getDevice();
813  if (!pDev)
814  {
815  LOG(VB_GENERAL, LOG_ALERT,
816  "MediaMonitor::eventFilter() got a bad media event?");
817  return true;
818  }
819 
820  if (pDev->isUsable())
821  JumpToMediaHandler(pDev);
822  else
823  {
824  // We don't want to jump around in the menus, but should
825  // call each plugin's callback so it can track this change.
826 
827  QMap<QString, MHData>::Iterator itr = m_handlerMap.begin();
828  while (itr != m_handlerMap.end())
829  {
830  if ((*itr).MythMediaType & (int)pDev->getMediaType() ||
831  pDev->getStatus() == MEDIASTAT_OPEN)
832  (*itr).callback(pDev);
833  itr++;
834  }
835  }
836 
837  return false; // Don't eat the event
838  }
839 
840  // standard event processing
841  return QObject::eventFilter(obj, event);
842 }
843 
844 /*
845  * These methods return the user's preferred devices for playing and burning
846  * CDs and DVDs. Traditionally we had a database setting to remember this,
847  * but that is a bit wasteful when most users only have one drive.
848  *
849  * To make it a bit more beginner friendly, if no database default exists,
850  * or if it contains "default", the code tries to find a monitored drive.
851  * If, still, nothing is suitable, a caller hard-coded default is used.
852  *
853  * Ideally, these would return a MythMediaDevice * instead of a QString
854  */
855 
856 QString MediaMonitor::defaultDevice(const QString &dbSetting,
857  const QString &label,
858  const char *hardCodedDefault)
859 {
860  QString device = gCoreContext->GetSetting(dbSetting);
861 
862  LOG(VB_MEDIA, LOG_DEBUG,
863  QString("MediaMonitor::defaultDevice(%1,..,%2) dbSetting='%3'")
864  .arg(dbSetting, hardCodedDefault, device));
865 
866  // No settings database defaults? Try to choose one:
867  if (device.isEmpty() || device == "default")
868  {
869  device = hardCodedDefault;
870 
871  if (!s_monitor)
873 
874  if (s_monitor)
875  {
876  MythMediaDevice *d = s_monitor->selectDrivePopup(label, false, true);
877 
878  if (d == (MythMediaDevice *) -1) // User cancelled
879  {
880  device.clear(); // If user has explicitly cancelled return empty string
881  d = nullptr;
882  }
883 
884  if (d && s_monitor->ValidateAndLock(d))
885  {
886  device = d->getDevicePath();
887  s_monitor->Unlock(d);
888  }
889  }
890  }
891 
892  LOG(VB_MEDIA, LOG_DEBUG,
893  "MediaMonitor::defaultDevice() returning " + device);
894  return device;
895 }
896 
901 {
902  return defaultDevice("CDDevice", tr("Select a CD drive"), DEFAULT_CD);
903 }
904 
909 {
910  return defaultDevice("VCDDeviceLocation",
911  tr("Select a VCD drive"), DEFAULT_CD);
912 }
913 
918 {
919  return defaultDevice("DVDDeviceLocation",
920  tr("Select a DVD drive"), DEFAULT_DVD);
921 }
922 
927 {
928  return defaultDevice("CDWriterDeviceLocation",
929  tr("Select a CD writer"), DEFAULT_CD);
930 }
931 
939 {
940  QString device = defaultDevice("MythArchiveDVDLocation",
941  tr("Select a DVD writer"), DEFAULT_DVD);
942 
943  return device;
944 }
945 
946 
951 {
952  QStringList list;
953 
954  for (const auto *dev : qAsConst(m_devices))
955  {
956  QString devStr;
957  QString model = dev->getDeviceModel();
958  const QString& path = dev->getDevicePath();
959  const QString& real = dev->getRealDevice();
960 
961  if (path != real)
962  devStr += path + "->";
963  devStr += real;
964 
965  if (model.isEmpty())
966  model = "unknown";
967  devStr += " (" + model + ")";
968 
969  list += devStr;
970  }
971 
972  return list.join(", ");
973 }
974 
982 {
984  if (mon)
985  mon->ChooseAndEjectMedia();
986  else
987  {
988  LOG(VB_MEDIA, LOG_INFO, "CD/DVD Monitor isn't enabled.");
989 #ifdef __linux__
990  LOG(VB_MEDIA, LOG_INFO, "Trying Linux 'eject -T' command");
991  myth_system("eject -T");
992 #elif CONFIG_DARWIN
993  QString def = DEFAULT_CD;
994  LOG(VB_MEDIA, LOG_INFO, "Trying 'diskutil eject " + def);
995  myth_system("diskutil eject " + def);
996 #endif
997  }
998 }
999 
1000 /*
1001  * vim:ts=4:sw=4:ai:et:si:sts=4
1002  */
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:125
MonitorThread::MonitorThread
MonitorThread(MediaMonitor *pMon, unsigned long interval)
Definition: mythmediamonitor.cpp:40
MythMainWindow::GetMainStack
MythScreenStack * GetMainStack()
Definition: mythmainwindow.cpp:314
MediaMonitor::AttemptEject
static void AttemptEject(MythMediaDevice *device)
Definition: mythmediamonitor.cpp:283
MThread::start
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
Definition: mthread.cpp:286
MediaMonitor::m_wait
QWaitCondition m_wait
Definition: mythmediamonitor.h:133
MediaMonitor::ejectOpticalDisc
static void ejectOpticalDisc(void)
Eject a disk, unmount a drive, open a tray.
Definition: mythmediamonitor.cpp:981
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:800
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:1428
MediaMonitor::GetMedias
QList< MythMediaDevice * > GetMedias(unsigned mediatypes)
Ask for available media. Must be locked with ValidateAndLock().
Definition: mythmediamonitor.cpp:613
MediaMonitor::m_removedDevices
QList< MythMediaDevice * > m_removedDevices
Definition: mythmediamonitor.h:126
MediaMonitor::selectDrivePopup
MythMediaDevice * selectDrivePopup(const QString &label, bool showMounted=false, bool showUsable=false)
List removable drives, let the user select one.
Definition: mythmediamonitor.cpp:183
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:1439
MythCoreContext::ResetSockets
void ResetSockets(void)
Definition: mythcorecontext.cpp:1822
DevName
static QString DevName(MythMediaDevice *d)
Definition: mythmediamonitor.cpp:129
MediaMonitor::GetMediaMonitor
static MediaMonitor * GetMediaMonitor(void)
Definition: mythmediamonitor.cpp:83
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:50
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:303
mythcdrom.h
MediaMonitor::GetRemovable
QList< MythMediaDevice * > GetRemovable(bool showMounted=false, bool showUsable=false)
Generate a list of removable drives.
Definition: mythmediamonitor.cpp:155
MediaMonitor::StartMonitoring
virtual void StartMonitoring(void)
Start the monitoring thread if needed.
Definition: mythmediamonitor.cpp:456
MediaMonitor::defaultDevice
static QString defaultDevice(const QString &setting, const QString &label, const char *hardCodedDefault)
Definition: mythmediamonitor.cpp:856
MediaMonitor::MediaMonitor
MediaMonitor(QObject *par, unsigned long interval, bool allowEject)
Lookup some settings, and do OS-specific stuff in sub-classes.
Definition: mythmediamonitor.cpp:343
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:502
MythMediaDevice::getDevicePath
const QString & getDevicePath() const
Definition: mythmedia.h:61
MediaMonitor::m_monitorPollingInterval
unsigned long m_monitorPollingInterval
Definition: mythmediamonitor.h:135
MythMediaDevice::getStatus
MythMediaStatus getStatus() const
Definition: mythmedia.h:70
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
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:50
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:725
MediaMonitor::s_monitor
static MediaMonitor * s_monitor
Definition: mythmediamonitor.h:140
MediaMonitor::GetMedia
MythMediaDevice * GetMedia(const QString &path)
Get media device by pathname. Must be locked with ValidateAndLock().
Definition: mythmediamonitor.cpp:542
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:505
sLocation
static const QString sLocation
Definition: mythmediamonitor.cpp:35
HasMythMainWindow
bool HasMythMainWindow(void)
Definition: mythmainwindow.cpp:106
MonitorThread::m_lastCheckTime
QDateTime m_lastCheckTime
Definition: mythmediamonitor.h:44
MediaMonitor::SetCDSpeed
static void SetCDSpeed(const char *device, int speed)
Definition: mythmediamonitor.cpp:101
MythMediaEvent::kEventType
static Type kEventType
Definition: mythmedia.h:193
MediaMonitor::CheckDevices
void CheckDevices(void)
Poll the devices in our list.
Definition: mythmediamonitor.cpp:436
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:357
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:652
mythdate.h
mythlogging.h
MythMediaDevice::setSpeed
virtual void setSpeed(int speed)
Definition: mythmedia.cpp:331
MythMediaDevice::getRealDevice
const QString & getRealDevice() const
Definition: mythmedia.h:63
MediaMonitor::StopMonitoring
void StopMonitoring(void)
Stop the monitoring thread if needed.
Definition: mythmediamonitor.cpp:479
MythDialogBox
Basic menu dialog, message and a list of options.
Definition: mythdialogbox.h:166
MythMediaDevice::clearData
void clearData()
Definition: mythmedia.cpp:508
MythMediaEvent
Definition: mythmedia.h:183
MythMediaDevice::unlock
virtual MythMediaError unlock()
Definition: mythmedia.cpp:349
MediaMonitor::CheckDeviceNotifications
virtual void CheckDeviceNotifications(void)
Definition: mythmediamonitor.h:104
MonitorThread::m_monitor
QPointer< MediaMonitor > m_monitor
Definition: mythmediamonitor.h:42
MythMediaDevice::unmount
bool unmount()
Definition: mythmedia.h:108
MediaMonitor::Unlock
void Unlock(MythMediaDevice *pMedia)
decrements the MythMediaDevices reference count
Definition: mythmediamonitor.cpp:519
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:23
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:60
MediaMonitor::m_ignoreList
QStringList m_ignoreList
Definition: mythmediamonitor.h:130
MediaMonitor
Definition: mythmediamonitor.h:47
MediaMonitor::m_handlerMap
QMap< QString, MHData > m_handlerMap
Registered Media Handlers.
Definition: mythmediamonitor.h:138
MediaMonitor::listDevices
QString listDevices(void)
A string summarising the current devices, for debugging.
Definition: mythmediamonitor.cpp:950
MediaMonitor::RemoveDevice
bool RemoveDevice(const QString &dev)
Remove a device from the media monitor.
Definition: mythmediamonitor.cpp:400
MediaMonitor::shouldIgnore
bool shouldIgnore(const MythMediaDevice *device)
Check user preferences to see if this device should be monitored.
Definition: mythmediamonitor.cpp:772
MediaMonitorDarwin
Definition: mediamonitor-darwin.h:21
MediaMonitor::defaultDVDWriter
static QString defaultDVDWriter()
MythArchiveDVDLocation, user-selected drive, or /dev/dvd.
Definition: mythmediamonitor.cpp:938
MythCoreContext::GetBoolSetting
bool GetBoolSetting(const QString &key, bool defaultval=false)
Definition: mythcorecontext.cpp:930
MediaMonitor::m_thread
MonitorThread * m_thread
Definition: mythmediamonitor.h:134
MythMediaDevice::eject
virtual MythMediaError eject(bool open_close=true)
Definition: mythmedia.cpp:306
MythMediaDevice::RegisterMediaExtensions
static void RegisterMediaExtensions(uint mediatype, const QString &extensions)
Used to register media types with extensions.
Definition: mythmedia.cpp:298
MediaMonitor::m_active
bool volatile m_active
Was MonitorThread started?
Definition: mythmediamonitor.h:132
MythCDROM::get
static MythCDROM * get(QObject *par, const QString &devicePath, bool SuperMount, bool AllowEject)
Definition: mythcdrom.cpp:42
MythMediaType
MythMediaType
Definition: mythmedia.h:24
MediaMonitor::m_useCount
QMap< MythMediaDevice *, int > m_useCount
Definition: mythmediamonitor.h:127
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
MONITOR_INTERVAL
#define MONITOR_INTERVAL
Definition: mythmediamonitor.cpp:81
MediaMonitor::EjectMedia
void EjectMedia(const QString &path)
Definition: mythmediamonitor.cpp:275
MythMediaDevice::kMediaStatusStrings
static const std::array< const QString, 9 > kMediaStatusStrings
Definition: mythmedia.h:117
MonitorThread::m_interval
unsigned long m_interval
Definition: mythmediamonitor.h:43
MHData
Stores details of media handlers.
Definition: mythmediamonitor.h:24
MThread
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:48
MythMediaDevice::checkMedia
virtual MythMediaStatus checkMedia()=0
MythCDROM::setDeviceSpeed
void setDeviceSpeed(const char *devicePath, int speed) override
Definition: mythcdrom.cpp:139
MythMediaDevice::getMediaType
MythMediaType getMediaType() const
Definition: mythmedia.h:91
MediaMonitorWindows
Definition: mediamonitor-windows.h:9
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:101
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:926
MediaMonitor::defaultDVDdevice
static QString defaultDVDdevice()
DVDDeviceLocation, user-selected drive, or /dev/dvd.
Definition: mythmediamonitor.cpp:917
MediaMonitor::ValidateAndLock
bool ValidateAndLock(MythMediaDevice *pMedia)
Validates the MythMediaDevice and increments its reference count.
Definition: mythmediamonitor.cpp:502
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:381
MediaMonitor::JumpToMediaHandler
void JumpToMediaHandler(MythMediaDevice *pMedia)
Find a relevant jump point for this type of media.
Definition: mythmediamonitor.cpp:690
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:2061
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:50
MediaMonitor::ChooseAndEjectMedia
void ChooseAndEjectMedia(void)
Unmounts and ejects removable media devices.
Definition: mythmediamonitor.cpp:256
MediaMonitor::defaultVCDdevice
static QString defaultVCDdevice()
VCDDeviceLocation, user-selected drive, or /dev/cdrom.
Definition: mythmediamonitor.cpp:908
MythMainWindow
Definition: mythmainwindow.h:35
MediaMonitor::m_devicesLock
QRecursiveMutex m_devicesLock
Definition: mythmediamonitor.h:123
MythMediaDevice::findMountPath
bool findMountPath()
Try to find a mount of m_devicePath in the mounts file.
Definition: mythmedia.cpp:365
MediaMonitor::defaultCDdevice
static QString defaultCDdevice()
CDDevice, user-selected drive, or /dev/cdrom.
Definition: mythmediamonitor.cpp:900
MEDIASTAT_NOTMOUNTED
@ MEDIASTAT_NOTMOUNTED
Definition: mythmedia.h:20
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:922
MediaMonitor::GetMountPath
static QString GetMountPath(const QString &devPath)
If the device is being monitored, return its mountpoint.
Definition: mythmediamonitor.cpp:566
MythMediaDevice::MediaTypeString
QString MediaTypeString()
Definition: mythmedia.cpp:515