[mythtv] [PATCH] Allow recording of shows that have already started

Jim Radford mythtv-dev@snowman.net
Wed, 16 Oct 2002 02:29:34 -0700


Hi Isaac,

I like being able to record shows that have already started.
Sometimes I remember just a little too late and I can't see how it
hurts.  Plus is makes it easier to test the scheduler.  :-)

Also I consolidated some repeated code from the frontend main loop.

-Jim

Index: main.cpp
===================================================================
RCS file: /var/lib/cvs/MC/programs/mythfrontend/main.cpp,v
retrieving revision 1.37
diff -u -r1.37 main.cpp
--- main.cpp	15 Oct 2002 16:24:42 -0000	1.37
+++ main.cpp	16 Oct 2002 09:16:16 -0000
@@ -117,114 +117,70 @@
 
     Scheduler *sched = new Scheduler(db);
 
-    sched->FillRecordLists();
-
-    int secsleft = -1;
-    int asksecs = -1;
     bool asked = false;
-
     TV *nexttv = NULL;
-
-    ProgramInfo *nextRecording = sched->GetNextRecording();
+    ProgramInfo *nextRecording = NULL;
     QDateTime nextrectime;
-    if (nextRecording)
-    {
-        nextrectime = nextRecording->startts;
-        asked = false;
-        if (tvList.find(nextRecording->cardid) == tvList.end())
-        {
-            cerr << "cardid: " << nextRecording->cardid 
-                 << " isn't in the databae of capture cards.\n";
-            exit(0);
-        }
-        nexttv = tvList[nextRecording->cardid];
-    }
-    QDateTime curtime = QDateTime::currentDateTime();
-
-    QDateTime lastupdate = curtime;
+    QDateTime lastupdate = QDateTime::currentDateTime().addDays(-1);
 
     while (1)
     {
         sleep(1);
 
-        if (sched->CheckForChanges() ||
-            (lastupdate.date().day() != curtime.date().day()))
+        QDateTime curtime = QDateTime::currentDateTime();
+
+        if(sched->CheckForChanges() || (lastupdate.date().day() != curtime.date().day())) {
+            sched->FillRecordLists();
+            cout << "Found changes in the todo list." << endl;
+            nextRecording = NULL;
+        }
+
+        if(!nextRecording) 
         {
             lastupdate = curtime;
-            sched->FillRecordLists();
             nextRecording = sched->GetNextRecording();
             if (nextRecording)
             {
                 nextrectime = nextRecording->startts;
+                cout << "Will record " << nextRecording->title 
+                     << " in " << curtime.secsTo(nextrectime) << " secs." << endl;
                 asked = false;
                 if (tvList.find(nextRecording->cardid) == tvList.end())
-                {
+                  {
                     cerr << "invalid cardid " << nextRecording->cardid << endl;
                     exit(0);
-                }
+                  }
                 nexttv = tvList[nextRecording->cardid];
-            }
+            } 
         }
 
-        curtime = QDateTime::currentDateTime();
         if (nextRecording)
         {
-            secsleft = curtime.secsTo(nextrectime);
-            asksecs = secsleft - 30;
-
-            if (nexttv->GetState() == kState_WatchingLiveTV && asksecs <= 0)
+            int secsleft = curtime.secsTo(nextrectime);
+            // cout << "secs left "  << secsleft << " until " << nextRecording->title << endl;
+            if (nexttv->GetState() == kState_WatchingLiveTV && secsleft <= 30 && !asked)
             {
-                if (!asked)
+                asked = true;
+                int result = askRecording(nexttv, nextRecording, secsleft);
+                
+                if (result == 3)
                 {
-                    asked = true;
-                    int result = askRecording(nexttv, nextRecording, secsleft);
-
-                    if (result == 3)
-                    {
-                        sched->RemoveFirstRecording();
-                        nextRecording = sched->GetNextRecording();
-                    }
- 
-                    if (nextRecording)
-                    {
-                        nextrectime = nextRecording->startts;
-                        curtime = QDateTime::currentDateTime();
-                        secsleft = curtime.secsTo(nextrectime);
-                        if (tvList.find(nextRecording->cardid) == tvList.end())
-                        {
-                            cerr << "invalid cardid " << nextRecording->cardid 
-                                 << endl;
-                            exit(0);
-                        }
-                        nexttv = tvList[nextRecording->cardid];
-                    }
+                    cout << "Skipping " << nextRecording->title << endl;
+                    sched->RemoveFirstRecording();
+                    nextRecording = NULL;
+                    continue;
                 }
             }
             if (secsleft <= -2)
             {
-                // don't record stuff that's already started..
-                if (secsleft > -30)
-                    startRecording(nexttv, nextRecording);
-
+                // FIXME: How can we test to see if this is already recording?  
+                //        Say nextRecording got set back to the same thing after CheckForChanges.
+                startRecording(nexttv, nextRecording);
+                cout << "Started recording " << nextRecording->title << endl;
                 sched->RemoveFirstRecording();
-                nextRecording = sched->GetNextRecording();
-
-                if (nextRecording)
-                {
-                    nextrectime = nextRecording->startts;
-                    curtime = QDateTime::currentDateTime();
-                    secsleft = curtime.secsTo(nextrectime);
-                    if (tvList.find(nextRecording->cardid) == tvList.end())
-                    {
-                        cerr << "invalid cardid " << nextRecording->cardid 
-                             << endl;
-                        exit(0);
-                    }
-                    nexttv = tvList[nextRecording->cardid];
-                }
+                nextRecording = NULL;
+                continue;
             }
-//            else 
-//                cout << secsleft << " secs left until " << nextRecording->title << endl;
         }
     }
     
Index: scheduler.cpp
===================================================================
RCS file: /var/lib/cvs/MC/programs/mythfrontend/scheduler.cpp,v
retrieving revision 1.27
diff -u -r1.27 scheduler.cpp
--- scheduler.cpp	12 Oct 2002 16:15:16 -0000	1.27
+++ scheduler.cpp	16 Oct 2002 09:16:16 -0000
@@ -194,7 +194,7 @@
             if (proginfo->description == QString::null)
                 proginfo->description = "";
 
-            if (proginfo->startts < curDateTime)
+            if (proginfo->endts < curDateTime)
                 delete proginfo;
             else 
                 recordingList.push_back(proginfo);