[mythtv] Re: [fixed PATCH] Cancel a recording when no free recorder for live tv

Jack Porter jack at porter.net.au
Fri Jan 14 11:13:17 EST 2005


Sorry!! That patch is missing an "else return 0;" for the case where 
showDialogs is false, possibly causing an infinite loop.

Please use this one instead.

Thanks
Jack

-- 
Jack Porter                       Programmer
jack at porter.net.au                Softmax
jack at softmax.co.kr                South Korea
-------------- next part --------------
Index: tv_play.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/tv_play.cpp,v
retrieving revision 1.233
diff -u -r1.233 tv_play.cpp
--- tv_play.cpp	24 Dec 2004 23:24:07 -0000	1.233
+++ tv_play.cpp	14 Jan 2005 16:06:13 -0000
@@ -37,6 +37,17 @@
     float rew_repos;
 };
 
+struct CurrentEncRecordingInfo
+{
+    RemoteEncoder* enc;
+    QString chanid;
+    
+    CurrentEncRecordingInfo(RemoteEncoder* inenc, QString inchanid)
+    :   enc(inenc)
+    ,   chanid(inchanid)
+    {}
+};
+
 #define MAX_REPO_LEVEL 3
 SeekSpeedInfo seek_speed_array[MAX_REPO_LEVEL][7] =
 {
@@ -405,37 +416,106 @@
     return internalState;
 }
 
+   
 int TV::LiveTV(bool showDialogs)
 {
     if (internalState == kState_None)
     {
-        RemoteEncoder *testrec = RemoteRequestNextFreeRecorder(lastRecorderNum);
-
-        if (!testrec)
-            return 0;
-
-        if (!testrec->IsValidRecorder())
+        RemoteEncoder* testrec;
+        for (;;)
         {
-            if (showDialogs)
-            {
-                QString title = tr("MythTV is already using all available "
-                                   "inputs for recording.  If you want to "
-                                   "watch an in-progress recording, select one "
-                                   "from the playback menu.  If you want to "
-                                   "watch live TV, cancel one of the "
-                                   "in-progress recordings from the delete "
-                                   "menu.");
-    
-                DialogBox diag(gContext->GetMainWindow(), title);
-                diag.AddButton(tr("Cancel and go back to the TV menu"));
-                diag.exec();
-            }        
+            testrec = RemoteRequestNextFreeRecorder(lastRecorderNum);
 
-            delete testrec;
- 
-            return 0;
+            if (!testrec)
+                return 0;
+           
+            if (!testrec->IsValidRecorder())
+            {
+                delete testrec;
+                
+                if (showDialogs)
+                {
+                    QString title = tr("MythTV is already using all available "
+                                       "inputs for recording.  If you want to "
+                                       "watch an in-progress recording, select one "
+                                       "from the playback menu.  If you want to "
+                                       "watch live TV, cancel one of the "
+                                       "in-progress recordings from the delete "
+                                       "menu.");
+        
+                    DialogBox diag(gContext->GetMainWindow(), title);
+                    diag.AddButton(tr("Cancel and go back to the TV menu"));
+    
+                    vector<CurrentEncRecordingInfo> encoderinfos;
+    
+                    int countRecording = RemoteIsRecording();
+                    for (int i = 1; i <= countRecording; i++)
+                    {
+                        RemoteEncoder* enc = RemoteGetExistingRecorder(i);
+                        if (enc)
+                        {
+                            if (enc->IsValidRecorder())
+                            {
+                                enc->Setup();
+                                QString title, subtitle,
+                                          desc, category,
+                                          starttime, endtime,
+                                          callsign, iconpath,
+                                          channelname, chanid,
+                                          seriesid, programid,
+                                          outputFilters, repeat, 
+                                          airdate, stars;
+                    
+                                enc->GetChannelInfo(title, subtitle,
+                                                  desc, category,
+                                                  starttime, endtime,
+                                                  callsign, iconpath,
+                                                  channelname, chanid,
+                                                  seriesid, programid,
+                                                  outputFilters, repeat, 
+                                                  airdate, stars);
+                                if (title != "")
+                                {
+                                    diag.AddButton(tr("Cancel Recording: ")+title);
+                                    encoderinfos.push_back(CurrentEncRecordingInfo(enc, chanid));
+                                }
+                                else
+                                    delete enc;
+                            }
+                            else
+                                delete enc;
+                        }
+                    }
+                
+                    int result = diag.exec();
+                    int c = 2;
+                    for (vector<CurrentEncRecordingInfo>::iterator i = encoderinfos.begin();
+                        i != encoderinfos.end();
+                        ++i)
+                    {
+                        RemoteEncoder* enc = (*i).enc;
+                        if (result == c)
+                        {
+                            QDateTime now = QDateTime::currentDateTime();
+                            ProgramInfo* currentprog = ProgramInfo::GetProgramAtDateTime(QSqlDatabase::database(), (*i).chanid, now);
+                            cout << "stopping recording " << currentprog->title.local8Bit() << endl;
+                            RemoteStopRecording(currentprog);
+                            delete currentprog;
+                        }
+                        delete enc;
+                        c++;
+                    }
+                    
+                    if (result == 1)    // Cancel and go back to TV menu.
+                        return 0;
+                }
+                else
+                    return 0;
+            }
+            else
+                break;  // found a valid recorder, fall out of the loop.
         }
-
+        
         activerecorder = recorder = testrec;
         lastRecorderNum = recorder->GetRecorderNumber();
         nextState = kState_WatchingLiveTV;
@@ -4217,4 +4297,3 @@
         cout << "No sleep timer?";
     }
 }
-


More information about the mythtv-dev mailing list