DvbSharedEpgEntry DvbEpgModel::findExistingEntry(DvbEpgEntry &newEntry)
{
DvbSharedEpgEntry existingEntry;
existingEntry = eventIds.value(QPair<DvbSharedChannel, int>(newEntry.channel, newEntry.eventid));
if(existingEntry.isValid()) return existingEntry;
DvbEpgEntry fakeEntry(newEntry.channel);
int newDurSecs = QTime(0,0).secsTo(newEntry.duration);
int allowedDiff = 0;
int durSecs = 0;
QDateTime endTime;
QDateTime newEndTime = newEntry.begin.addSecs(newDurSecs);
for (ConstIdIterator it = entryIds.lowerBound(DvbEpgEntryId(&fakeEntry));
it != entryIds.constEnd(); ++it) {
const DvbSharedEpgEntry &exEntry = *it;
if (!exEntry.isValid() || newEntry.channel != exEntry->channel ) {
continue;
}
durSecs = QTime(0,0).secsTo(exEntry->duration);
endTime = exEntry->begin.addSecs(durSecs);
allowedDiff = (10*60 > (durSecs/2)) ? (durSecs / 2): 10*60;
if(newEntry.begin.toMSecsSinceEpoch() > exEntry->begin.toMSecsSinceEpoch() && endTime.toMSecsSinceEpoch() <= newEntry.begin.toMSecsSinceEpoch()) continue;
if(exEntry->begin.toMSecsSinceEpoch() > newEntry.begin.toMSecsSinceEpoch() && newEndTime.toMSecsSinceEpoch() <= exEntry->begin.toMSecsSinceEpoch()) continue;
Log("DATA -> : ") << newEntry.begin.toMSecsSinceEpoch() << " " << exEntry->begin.toMSecsSinceEpoch() << " " << (abs(newEntry.begin.toMSecsSinceEpoch() - exEntry->begin.toMSecsSinceEpoch()) / 1000 ) << " " << allowedDiff << " " << durSecs;
if((abs(newEntry.begin.toMSecsSinceEpoch() - exEntry->begin.toMSecsSinceEpoch()) / 1000) > allowedDiff ||
abs(newDurSecs - durSecs) > allowedDiff) continue;
return exEntry;
}
return DvbSharedEpgEntry();
}