Blob Blame History Raw
Index: vdr-plugin-epg2vdr-1.2.9/handler.h
===================================================================
--- vdr-plugin-epg2vdr-1.2.9.orig/handler.h	2022-12-22 09:02:41.104757343 +0100
+++ vdr-plugin-epg2vdr-1.2.9/handler.h	2022-12-24 11:45:58.543278919 +0100
@@ -409,6 +409,7 @@
 
       virtual bool HandledExternally(const cChannel* Channel)
       {
+         handledByUs = false;
          static int reportFirst = yes;
 
          LogDuration l("HandledExternally", 5);
@@ -430,8 +431,10 @@
 
          // dbConnected() here okay -> if not connected we return false an the vdr will handle the event?!?
 
-         if (dbConnected() && getExternalIdOfChannel(&channelId) != "")
+         if (dbConnected() && getExternalIdOfChannel(&channelId) != "") {
+            handledByUs = true;
             return true;
+         }
 
          return false;
       }
@@ -453,6 +456,53 @@
       }
 
       //***************************************************************************
+      // SetEventID
+      //***************************************************************************
+
+      virtual bool SetEventID(cEvent *Event, tEventID EventID) {
+// do we handle this channel?
+        if (!handledByUs) return false;
+        return true;
+// our use IDs don't change
+/*
+
+        eventsDb->clear();
+        eventsDb->setValue("CHANNELID", channelId.ToString());
+        eventsDb->setBigintValue("EVENTID", (long)EventID);
+
+        if (eventsDb->find()) {
+          tEventID useID = eventsDb->getIntValue("USEID");
+          Event->SetEventID(useID);
+          return true;
+        }
+        return false;
+*/
+      }
+
+      //***************************************************************************
+      // Get event
+      //***************************************************************************
+
+      virtual bool GetEvent(cEvent **event, const cChannel *channel, const cSchedule *schedule, const SI::EIT::Event *siEitEvent, uchar tableID) {
+// do we handle this channel?
+        if (!handledByUs) return false;
+        *event = NULL;
+
+        if (tableID == 0x4E || (tableID & 0xF0) == 0x50) {
+           eventsDb->clear();
+           eventsDb->setValue("CHANNELID", channelId.ToString());
+           eventsDb->setBigintValue("EVENTID", (long)siEitEvent->getEventId());
+
+           if (eventsDb->find()) {
+             tEventID useID = eventsDb->getIntValue("USEID");
+             *event = const_cast<cEvent *>(schedule->GetEventById(useID));
+           }
+        } else
+           *event = const_cast<cEvent *>(schedule->GetEventByTime(siEitEvent->getStartTime() ));
+        return true;
+      }
+
+      //***************************************************************************
       // Is Update
       //***************************************************************************
 
@@ -746,7 +796,7 @@
 
          selectEventByStarttime->freeResult();
 
-         return true;
+         return false; // so other plugins can still get the event
       }
 
       //***************************************************************************
@@ -876,6 +926,7 @@
       std::map<std::string,MemMap> evtMemList;
       std::map<std::string,std::string> externIdMap;
       tChannelID channelId;
+      bool handledByUs; // == EpgHandlers.HandledExternally(Channel);
 
       int initialized;
       cDbConnection* connection;
@@ -980,6 +1031,18 @@
          return false;
       }
 
+      virtual bool SetEventID(cEvent *Event, tEventID EventID)
+      {
+         cEpgHandlerInstance* h = getHandler();
+         return h->SetEventID(Event, EventID);
+      }
+
+      virtual bool GetEvent(cEvent **event, const cChannel *channel, const cSchedule *schedule, const SI::EIT::Event *siEitEvent, uchar tableID)
+      {
+         cEpgHandlerInstance* h = getHandler();
+         return h->GetEvent(event, channel, schedule, siEitEvent, tableID);
+      }
+
       virtual bool IsUpdate(tEventID EventID, time_t StartTime, uchar TableID, uchar Version)
       {
 
Index: vdr-plugin-epg2vdr-1.2.9/update.c
===================================================================
--- vdr-plugin-epg2vdr-1.2.9.orig/update.c	2022-12-22 07:32:05.000000000 +0100
+++ vdr-plugin-epg2vdr-1.2.9/update.c	2022-12-22 09:51:26.419974590 +0100
@@ -1431,6 +1431,18 @@
 }
 
 //***************************************************************************
+// Return true if any timer is in VPS margin
+//***************************************************************************
+
+bool timerInVpsMargin()
+{
+   LOCK_TIMERS_WRITE;
+   for (cTimer* timer = Timers->First(); timer; timer = Timers->Next(timer))
+      if (timer->InVpsMargin() ) return true;
+   return false;
+}
+
+//***************************************************************************
 // Clear Epg
 //***************************************************************************
 
@@ -1520,6 +1532,10 @@
    if (fullreload)
    {
       tell(1, "Removing all events from epg");
+      if (timerInVpsMargin() ) {
+         tell(1, "Abort, as there is a timer in VPS margin");
+         return fail;
+      }
 
       clearEpg();
 
@@ -1665,8 +1681,10 @@
                   }
                }
 
-               if (timer)
+               if (timer) {
+                  if (timer->InVpsMargin() ) continue; // ignore events in vps margin, especially don't set the timer to no event.
                   timer->SetEvent(0);
+               }
 
                s->DelEvent((cEvent*)event);
             }