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

Jack Porter jack at porter.net.au
Fri Jan 14 10:58:21 EST 2005


Hi,

I wrote this patch because I found it annoying to have to go back to the 
watch recordings menu, find the active recording, delete it and then go 
back to the live tv menu, when I just want to watch a bit of live tv and 
I know myth is recording some program I don't really care too much about.

If myth can't find a free recorder, it looks up the status of all 
current recorders and adds a button for each of the titles currently 
being recorded.  You can choose one to stop recording, and it will then 
take you to live tv, or you can press the cancel button and go back to 
the TV menu as before.

Note: I only have a single backend/frontend box with a single tuner 
card, but I can't see any reason why this wouldn't work for those of you 
with multiple recorders and backends, but if there's some problem, 
please let me know.

Cheers
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 15:47:14 -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,104 @@
     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
+                break;  // found a valid recorder, fall out of the loop.
         }
-
+        
         activerecorder = recorder = testrec;
         lastRecorderNum = recorder->GetRecorderNumber();
         nextState = kState_WatchingLiveTV;
@@ -4217,4 +4295,3 @@
         cout << "No sleep timer?";
     }
 }
-


More information about the mythtv-dev mailing list