4 #include <QCoreApplication>
24 #define LOC QString("PlaybackBoxHelper: ")
25 #define LOC_WARN QString("PlaybackBoxHelper Warning: ")
26 #define LOC_ERR QString("PlaybackBoxHelper Error: ")
32 m_pbh(pbh), m_freeSpaceTimerId(0), m_checkAvailabilityTimerId(0)
36 virtual bool event(QEvent*);
37 void UpdateFreeSpaceEvent(
void);
51 QTime tm = QTime::currentTime();
53 QStringList::const_iterator it = slist.begin();
55 QSet<CheckAvailabilityType> cats;
56 for (; it != slist.end(); ++it)
60 QMutexLocker locker(&m_pbh.m_lock);
61 QHash<QString, QStringList>::iterator it =
62 m_checkAvailability.find(evinfo.MakeUniqueKey());
63 if (it != m_checkAvailability.end())
64 m_checkAvailability.erase(it);
65 if (m_checkAvailability.empty() && m_checkAvailabilityTimerId)
67 killTimer(m_checkAvailabilityTimerId);
68 m_checkAvailabilityTimerId = 0;
76 if (!evinfo.HasPathname() && !evinfo.GetChanID())
82 if (!evinfo.IsFileReadable())
84 LOG(VB_GENERAL, LOG_ERR,
LOC +
85 QString(
"CHECK_AVAILABILITY '%1' file not found")
86 .arg(evinfo.GetPathname()));
89 else if (!evinfo.GetFilesize())
91 evinfo.SetFilesize(evinfo.QueryFilesize());
92 if (!evinfo.GetFilesize())
102 list.push_back(evinfo.MakeUniqueKey());
103 list.push_back(evinfo.GetPathname());
105 QCoreApplication::postEvent(m_pbh.m_listener, e0);
108 list.push_back(evinfo.MakeUniqueKey());
109 list.push_back(QString::number((
int)*cats.begin()));
110 list.push_back(QString::number((
int)availableStatus));
111 list.push_back(QString::number(evinfo.GetFilesize()));
112 list.push_back(QString::number(tm.hour()));
113 list.push_back(QString::number(tm.minute()));
114 list.push_back(QString::number(tm.second()));
115 list.push_back(QString::number(tm.msec()));
117 QSet<CheckAvailabilityType>::iterator cit = cats.begin();
118 for (; cit != cats.end(); ++cit)
122 list[1] = QString::number((
int)*cit);
124 QCoreApplication::postEvent(m_pbh.m_listener, e);
127 return availableStatus;
132 if (e->type() == QEvent::Timer)
134 QTimerEvent *te = (QTimerEvent*)e;
135 const int timer_id = te->timerId();
136 if (timer_id == m_freeSpaceTimerId)
137 UpdateFreeSpaceEvent();
138 if (timer_id == m_checkAvailabilityTimerId)
142 QMutexLocker locker(&m_pbh.m_lock);
143 QHash<QString, QStringList>::iterator it =
144 m_checkAvailability.begin();
145 if (it != m_checkAvailability.end())
149 if (slist.size() >= 1 + NUMPROGRAMLINES)
150 CheckAvailability(slist);
157 if (me->
Message() ==
"UPDATE_FREE_SPACE")
159 UpdateFreeSpaceEvent();
162 else if (me->
Message() ==
"STOP_RECORDING")
165 if (pginfo.GetChanID())
169 else if (me->
Message() ==
"DELETE_RECORDINGS")
171 QStringList successes;
172 QStringList failures;
174 while (list.size() >= 4)
176 uint chanid = list[0].toUInt();
178 bool forceDelete = list[2].toUInt();
179 bool forgetHistory = list[3].toUInt();
182 chanid, recstartts, forceDelete, forgetHistory);
184 QStringList &res = (ok) ? successes : failures;
185 for (
uint i = 0; i < 4; i++)
187 res.push_back(list.front());
191 if (!successes.empty())
194 QCoreApplication::postEvent(m_pbh.m_listener, e);
196 if (!failures.empty())
199 QCoreApplication::postEvent(m_pbh.m_listener, e);
204 else if (me->
Message() ==
"UNDELETE_RECORDINGS")
206 QStringList successes;
207 QStringList failures;
209 while (list.size() >= 2)
211 uint chanid = list[0].toUInt();
216 QStringList &res = (ok) ? successes : failures;
217 for (
uint i = 0; i < 2; i++)
219 res.push_back(list.front());
223 if (!successes.empty())
226 QCoreApplication::postEvent(m_pbh.m_listener, e);
228 if (!failures.empty())
231 QCoreApplication::postEvent(m_pbh.m_listener, e);
236 else if (me->
Message() ==
"GET_PREVIEW")
241 QStringList::const_iterator it = list.begin()+2;
243 if (!evinfo.HasPathname())
247 evinfo.ToStringList(list);
249 if (check_avail && (
asAvailable != CheckAvailability(list)))
251 else if (
asAvailable != evinfo.GetAvailableStatus())
259 else if (me->
Message() ==
"CHECK_AVAILABILITY")
263 if (m_checkAvailabilityTimerId)
264 killTimer(m_checkAvailabilityTimerId);
265 m_checkAvailabilityTimerId = startTimer(0);
267 else if (!m_checkAvailabilityTimerId)
268 m_checkAvailabilityTimerId = startTimer(50);
270 else if (me->
Message() ==
"LOCATE_ARTWORK")
277 const QString cacheKey = QString(
"%1:%2:%3")
278 .arg((
int)type).arg(inetref).arg(season);
286 if (!info.
url.isEmpty())
288 foundFile = info.
url;
289 QMutexLocker locker(&m_pbh.m_lock);
290 m_pbh.m_artworkCache[cacheKey] = foundFile;
293 if (!foundFile.isEmpty())
296 list.push_back(foundFile);
298 QCoreApplication::postEvent(m_pbh.m_listener, e);
305 return QObject::event(e);
310 if (m_freeSpaceTimerId)
311 killTimer(m_freeSpaceTimerId);
312 m_pbh.UpdateFreeSpace();
313 m_freeSpaceTimerId = startTimer(kUpdateFreeSpaceInterval);
322 m_freeSpaceTotalMB(0ULL), m_freeSpaceUsedMB(0ULL)
342 QCoreApplication::postEvent(
355 uint chanid,
const QDateTime &recstartts,
bool forceDelete,
359 list.push_back(QString::number(chanid));
361 list.push_back((forceDelete) ?
"1" :
"0");
362 list.push_back((forgetHistory) ?
"1" :
"0");
373 uint chanid,
const QDateTime &recstartts)
376 list.push_back(QString::number(chanid));
386 QMutexLocker locker(&
m_lock);
387 for (
int i = 0; i < fsInfos.size(); i++)
389 if (fsInfos[i].getPath() ==
"TotalDiskSpace")
401 QMutexLocker locker(&
m_lock);
407 QMutexLocker locker(&
m_lock);
414 QString catstr = QString::number((
int)cat);
415 QMutexLocker locker(&
m_lock);
416 QHash<QString, QStringList>::iterator it =
427 (*it).push_back(catstr);
434 const QString &inetref,
uint season,
437 const QString &groupname)
439 QString cacheKey = QString(
"%1:%2:%3")
440 .arg((
int)type).arg(inetref).arg(season);
442 QMutexLocker locker(&
m_lock);
444 QHash<QString,QString>::const_iterator it =
450 QStringList list(inetref);
451 list.push_back(QString::number(season));
452 list.push_back(QString::number(type));
454 list.push_back(groupname);
462 const ProgramInfo &pginfo,
bool check_availability)
470 QString token = QString(
"%1:%2")
473 QStringList extra(token);
474 extra.push_back(check_availability?
"1":
"0");