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