287
290
return retdatetime;
293
/// Download preview & get timestamp if newer than cachefile's
294
/// last modified time, otherwise just get the timestamp
295
QDateTime RemoteGetPreviewIfModified(
296
const ProgramInfo &pginfo, const QString &cachefile)
298
QString loc_err("RemoteGetPreviewIfModified, Error: ");
300
QDateTime cacheLastModified;
301
QFileInfo cachefileinfo(cachefile);
302
if (cachefileinfo.exists())
303
cacheLastModified = cachefileinfo.lastModified();
305
QStringList strlist("QUERY_PIXMAP_GET_IF_MODIFIED");
306
strlist << ((cacheLastModified.isValid()) ? // unix secs, UTC
307
QString::number(cacheLastModified.toTime_t()) : QString("-1"));
308
strlist << QString::number(200 * 1024); // max size of preview file
309
pginfo.ToStringList(strlist);
311
if (!gContext->SendReceiveStringList(strlist) ||
312
strlist.empty() || strlist[0] == "ERROR")
314
VERBOSE(VB_IMPORTANT, loc_err +
315
QString("Remote error") +
316
((strlist.size() >= 2) ?
317
(QString(":\n\t\t\t") + strlist[1]) : QString("")));
322
if (strlist[0] == "WARNING")
324
VERBOSE(VB_NETWORK, QString("RemoteGetPreviewIfModified, Warning: ") +
325
QString("Remote warning") +
326
((strlist.size() >= 2) ?
327
(QString(":\n\t\t\t") + strlist[1]) : QString("")));
332
QDateTime retdatetime;
333
qlonglong timet = strlist[0].toLongLong();
335
retdatetime.setTime_t(timet);
337
if (strlist.size() < 4)
342
size_t length = strlist[1].toLongLong();
343
quint16 checksum16 = strlist[2].toUInt();
344
QByteArray data = QByteArray::fromBase64(strlist[3].toAscii());
345
if ((size_t) data.size() < length)
346
{ // (note data.size() may be up to 3 bytes longer after decoding
347
VERBOSE(VB_IMPORTANT, loc_err +
348
QString("Preview size check failed %1 < %2")
349
.arg(data.size()).arg(length));
353
if (checksum16 != qChecksum(data.constData(), data.size()))
355
VERBOSE(VB_IMPORTANT, loc_err + "Preview checksum failed");
359
QString pdir(cachefile.section("/", 0, -2));
361
if (!cfd.exists() && !cfd.mkdir(pdir))
363
VERBOSE(VB_IMPORTANT, loc_err +
364
QString("Unable to create remote cache directory '%1'")
370
QFile file(cachefile);
371
if (!file.open(QIODevice::WriteOnly|QIODevice::Truncate))
373
VERBOSE(VB_IMPORTANT, loc_err +
374
QString("Unable to open cached "
375
"preview file for writing '%1'")
382
size_t remaining = length;
383
uint failure_cnt = 0;
384
while ((remaining > 0) && (failure_cnt < 5))
386
ssize_t written = file.write(data.data() + offset, remaining);
396
remaining -= written;
401
VERBOSE(VB_IMPORTANT, loc_err +
402
QString("Failed to write cached preview file '%1'")
405
file.resize(0); // in case unlink fails..
406
file.remove(); // closes fd
290
415
void RemoteFillProginfo(ProgramInfo *pginfo, const QString &playbackhostname)
292
417
QStringList strlist( "FILL_PROGRAM_INFO" );
371
496
return strlist[0].toInt();
499
static QMutex sgroupMapLock;
500
static QHash <QString, QString>sgroupMap;
502
void RemoteClearSGMap(void)
504
QMutexLocker locker(&sgroupMapLock);
508
QString GetHostSGToUse(QString host, QString sgroup)
510
QString tmpGroup = sgroup;
511
QString groupKey = QString("%1:%2").arg(sgroup, host);
513
QMutexLocker locker(&sgroupMapLock);
515
if (sgroupMap.contains(groupKey))
517
tmpGroup = sgroupMap[groupKey];
521
if (StorageGroup::FindDirs(sgroup, host))
523
sgroupMap[groupKey] = sgroup;
527
VERBOSE(VB_FILE+VB_EXTRA, QString("GetHostSGToUse(): "
528
"falling back to Videos Storage Group for host %1 "
529
"since it does not have a %2 Storage Group.")
530
.arg(host).arg(sgroup));
533
sgroupMap[groupKey] = tmpGroup;
540
bool RemoteGetFileList(QString host, QString path, QStringList* list,
541
QString sgroup, bool fileNamesOnly)
544
// Make sure the list is empty when we get started
547
if (sgroup.isEmpty())
550
*list << "QUERY_SG_GETFILELIST";
552
*list << GetHostSGToUse(host, sgroup);
554
*list << QString::number(fileNamesOnly);
556
bool ok = gContext->SendReceiveStringList(*list);
558
// Should the SLAVE UNREACH test be here ?
562
QString RemoteGenFileURL(QString sgroup, QString host, QString path)
564
return QString("myth://%1@").arg(GetHostSGToUse(host, sgroup)) +
565
gContext->GetSettingOnHost("BackendServerIP", host) + ":" +
566
gContext->GetSettingOnHost("BackendServerPort", host) + "/" +
375
572
* Get recorder for a programme.