12#if QT_VERSION >= QT_VERSION_CHECK(6,5,0)
13#include <QtSystemDetection>
17#include <QFileInfoList>
18#include <QRegularExpression>
33#define LOC QString("MythMediaDevice:")
46# define USE_MOUNT_COMMAND
53 "MEDIASTAT_UNPLUGGED",
56 "MEDIASTAT_UNFORMATTED",
58 "MEDIASTAT_NOTMOUNTED",
66 "MEDIAERR_UNSUPPORTED"
70 (QEvent::Type) QEvent::registerEventType();
81 bool SuperMount,
bool AllowEject)
82 : QObject(par), m_devicePath(std::move(DevicePath)),
83 m_allowEject(AllowEject), m_superMount(SuperMount)
126 LOG(VB_MEDIA, LOG_ERR,
"MythMediaDevice::performMountCmd(true)"
127 " - Logic Error? Device already mounted.");
137 QString MountCommand;
143 MountCommand = QString(
"%1 %2")
148 MountCommand = QString(
"%1 %2")
152 LOG(VB_MEDIA, LOG_INFO, QString(
"Executing '%1'").arg(MountCommand));
156 std::this_thread::sleep_for(300ms);
157 LOG(VB_MEDIA, LOG_INFO, QString(
"Retrying '%1'").arg(MountCommand));
169 std::this_thread::sleep_for(1s);
172 LOG(VB_MEDIA, LOG_INFO,
173 QString(
"Repeating '%1'").arg(MountCommand));
175 std::this_thread::sleep_for(500ms);
179 LOG(VB_MEDIA, LOG_ERR,
"performMountCmd() attempted to"
180 " find mounted media, but failed?");
184 LOG(VB_GENERAL, LOG_INFO,
194 LOG(VB_GENERAL, LOG_ERR, QString(
"Failed to %1 %2.")
199 LOG(VB_MEDIA, LOG_INFO,
"Disk inserted on a supermount device");
206 LOG(VB_GENERAL, LOG_INFO,
228 LOG(VB_MEDIA, LOG_NOTICE,
229 QString(
"No files with extensions found in '%1'")
234 QMap<uint, uint> media_cnts;
237 for (
auto it = ext_cnt.cbegin(); it != ext_cnt.cend(); ++it)
239 ext_to_media_t::const_iterator found =
s_ext_to_media.constFind(it.key());
242 LOG(VB_MEDIA, LOG_INFO, QString(
"DetectMediaType %1 (%2)")
244 media_cnts[*found] += *it;
248 LOG(VB_MEDIA, LOG_NOTICE, QString(
249 "DetectMediaType(this=0x%1) unknown file type %1")
250 .arg(quintptr(
this),0,16).arg(it.key()));
257 for (
auto cit = media_cnts.cbegin(); cit != media_cnts.cend(); ++cit)
279 d.setFilter(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot);
280 QFileInfoList entries =
d.entryInfoList();
281 for (
const auto& fi : std::as_const(entries))
292 const QString ext = fi.suffix();
294 cnt[ext.toLower()]++;
308 const QString &extensions)
310 QStringList exts = extensions.split(
",");
311 for (
const auto& ext : std::as_const(exts))
376 LOG(VB_MEDIA, LOG_ERR,
"findMountPath() - logic error, no device path");
380#ifdef USE_MOUNT_COMMAND
384 QFile mountFile(
"/tmp/mounts");
390 if (!mountFile.open(QIODevice::ReadOnly))
394 QTextStream stream(&mountFile);
402#ifdef USE_MOUNT_COMMAND
406 stream >> deviceName;
407 mountPoint = stream.readLine();
408 mountPoint.remove(
" on ");
409 mountPoint.remove(QRegularExpression(
" type \\w.*"));
410 mountPoint.remove(QRegularExpression(
" \\(\\w.*"));
413 stream >> deviceName >> mountPoint;
417 if (deviceName.isNull())
420 if (deviceName.isEmpty())
423 if (!deviceName.startsWith(
"/dev/"))
426 QStringList deviceNames;
432 deviceNames << deviceName.mid(5);
436 if (mountPoint.contains(
"\\040"))
437 mountPoint.replace(
"\\040",
" ");
449 debug += QString(
" %1 | %2\n")
450 .arg(deviceName, 16).arg(mountPoint);
457 debug =
LOC +
":findMountPath() - mount of '"
459 +
" Device name/type | Current mountpoint\n"
460 +
" -----------------+-------------------\n"
462 +
" =================+===================";
478 if (NewStatus != OldStatus)
480 LOG(VB_MEDIA, LOG_DEBUG,
481 QString(
"MythMediaDevice::setStatus %1 %2->%3")
535 s =
"MEDIATYPE_UNKNOWN";
537 s =
"MEDIATYPE_DATA";
539 s =
"MEDIATYPE_MIXED";
541 s =
"MEDIATYPE_AUDIO";
549 s =
"MEDIATYPE_MMUSIC";
551 s =
"MEDIATYPE_MVIDEO";
553 s =
"MEDIATYPE_MGALLERY";
@ GENERIC_EXIT_OK
Exited with no error.
static const iso6937table * d
static bool VERBOSE_LEVEL_CHECK(uint64_t mask, LogLevel_t level)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
QString getSymlinkTarget(const QString &start_file, QStringList *intermediaries, unsigned maxLinks)
@ kMSDontBlockInputDevs
avoid blocking LIRC & Joystick Menu
@ kMSRunBackground
run child in the background
uint myth_system(const QString &command, uint flags, std::chrono::seconds timeout)
VERBOSE_PREAMBLE Most debug(nodatabase, notimestamp, noextra)") VERBOSE_MAP(VB_GENERAL