Better encapsulation of record control

This commit is contained in:
Klaus Schmidinger 2000-04-30 10:22:13 +02:00
parent f13ded672b
commit 49ce70fdb3
5 changed files with 89 additions and 49 deletions

49
menu.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: menu.c 1.10 2000/04/29 14:53:27 kls Exp $
* $Id: menu.c 1.11 2000/04/30 10:10:19 kls Exp $
*/
#include "menu.h"
@ -997,6 +997,7 @@ cMenuMain::cMenuMain(void)
Add(new cOsdItem("Channels", osChannels));
Add(new cOsdItem("Timer", osTimer));
Add(new cOsdItem("Recordings", osRecordings));
Display();
}
eOSState cMenuMain::ProcessKey(eKeys Key)
@ -1013,6 +1014,48 @@ eOSState cMenuMain::ProcessKey(eKeys Key)
return state;
}
// --- cRecordControl --------------------------------------------------------
cRecordControl::cRecordControl(cTimer *Timer)
{
timer = Timer;
if (!timer) {
timer = new cTimer(true);
Timers.Add(timer);
Timers.Save();
}
timer->SetRecording(true);
cChannel::SwitchTo(timer->channel - 1);
cRecording Recording(timer);
DvbApi.StartRecord(Recording.FileName());
}
cRecordControl::~cRecordControl()
{
DvbApi.StopRecord();
timer->SetRecording(false);
if (timer->IsSingleEvent() && !timer->Matches()) {
// checking timer->Matches() to make sure we don't delete the timer
// if the program was cancelled before the timer's stop time!
isyslog(LOG_INFO, "deleting timer %d", timer->Index() + 1);
Timers.Del(timer);
Timers.Save();
}
}
eOSState cRecordControl::ProcessKey(eKeys Key)
{
if (!timer->Matches())
return osEnd;
switch (Key) {
case kNone: break;
case kMenu: return osMenu; // allow switching to menu
default: return osUnknown; // anything else is blocked while recording
}
AssertFreeDiskSpace();
return osContinue;
}
// --- cReplayControl --------------------------------------------------------
char *cReplayControl::fileName = NULL;
@ -1043,7 +1086,7 @@ void cReplayControl::Show(void)
{
if (!visible) {
Interface.Open(MenuColumns, -3);
visible = true;
needsFastResponse = visible = true;
shown = DvbApi.ShowProgress(true);
}
}
@ -1052,7 +1095,7 @@ void cReplayControl::Hide(void)
{
if (visible) {
Interface.Close();
visible = false;
needsFastResponse = visible = false;
}
}

11
menu.h
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: menu.h 1.6 2000/04/29 15:38:39 kls Exp $
* $Id: menu.h 1.7 2000/04/29 17:54:55 kls Exp $
*/
#ifndef _MENU_H
@ -18,6 +18,15 @@ public:
virtual eOSState ProcessKey(eKeys Key);
};
class cRecordControl : public cOsdBase {
private:
cTimer *timer;
public:
cRecordControl(cTimer *Timer = NULL);
virtual ~cRecordControl();
virtual eOSState ProcessKey(eKeys Key);
};
class cReplayControl : public cOsdBase {
private:
bool visible, shown;

7
osd.h
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: osd.h 1.5 2000/04/29 14:45:47 kls Exp $
* $Id: osd.h 1.6 2000/04/30 09:47:52 kls Exp $
*/
#ifndef __OSD_H
@ -46,10 +46,13 @@ public:
};
class cOsdBase {
protected:
bool needsFastResponse;
public:
cOsdBase(void) {}
cOsdBase(bool FastResponse = false) { needsFastResponse = FastResponse; }
virtual ~cOsdBase() {}
virtual eOSState ProcessKey(eKeys Key) = 0;
bool NeedsFastResponse(void) { return needsFastResponse; }
};
class cOsdMenu : public cOsdBase, public cList<cOsdItem> {

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
* $Id: recording.c 1.6 2000/04/24 09:45:13 kls Exp $
* $Id: recording.c 1.7 2000/04/30 10:22:13 kls Exp $
*/
#define _GNU_SOURCE
@ -62,7 +62,7 @@ void AssertFreeDiskSpace(void)
static time_t LastFreeDiskCheck = 0;
if (time(NULL) - LastFreeDiskCheck > DISKCHECKDELTA) {
LastFreeDiskCheck = time(NULL);
if (DvbApi.Recording() && LowDiskSpace()) {
if (LowDiskSpace()) {
// Remove the oldest file that has been "deleted":
cRecordings Recordings;
if (Recordings.Load(true)) {

67
vdr.c
View File

@ -22,7 +22,7 @@
*
* The project's page is at http://www.cadsoft.de/people/kls/vdr
*
* $Id: vdr.c 1.14 2000/04/29 15:57:42 kls Exp $
* $Id: vdr.c 1.15 2000/04/30 10:19:52 kls Exp $
*/
#include <signal.h>
@ -65,15 +65,15 @@ int main(int argc, char *argv[])
if (signal(SIGTERM, SignalHandler) == SIG_IGN) signal(SIGTERM, SIG_IGN);
cMenuMain *Menu = NULL;
cRecordControl *RecordControl = NULL;
cReplayControl *ReplayControl = NULL;
cTimer *Timer = NULL;
int dcTime = 0, dcNumber = 0;
int LastChannel = -1;
while (!Interrupted) {
// Channel display:
if (CurrentChannel != LastChannel) {
if (!Timer) {
if (!RecordControl) {
cChannel *channel = Channels.Get(CurrentChannel);
if (channel)
Interface.DisplayChannel(CurrentChannel + 1, channel->name);
@ -87,42 +87,31 @@ int main(int argc, char *argv[])
LastChannel = -1; // in case an invalid channel number was entered!
}
// Timer Processing:
else {
AssertFreeDiskSpace();
if (!Timer && (Timer = cTimer::GetMatch()) != NULL) {
else if (!RecordControl) {
cTimer *Timer = cTimer::GetMatch();
if (Timer) {
DELETENULL(Menu);
DELETENULL(ReplayControl);
// make sure the timer won't be deleted:
Timer->SetRecording(true);
// switch to channel:
cChannel::SwitchTo(Timer->channel - 1);
// start recording:
cRecording Recording(Timer);
DvbApi.StartRecord(Recording.FileName());
}
if (Timer && !Timer->Matches()) {
// stop recording:
DvbApi.StopRecord();
// release timer:
Timer->SetRecording(false);
// clear single event timer:
if (Timer->IsSingleEvent()) {
DELETENULL(Menu); // must make sure no menu uses it
isyslog(LOG_INFO, "deleting timer %d", Timer->Index() + 1);
Timers.Del(Timer);
Timers.Save();
}
Timer = NULL;
RecordControl = new cRecordControl(Timer);
}
}
// User Input:
eKeys key = Interface.GetKey(!ReplayControl || !ReplayControl->Visible());
cOsdBase **Interact = Menu ? (cOsdBase **)&Menu : (cOsdBase **)&ReplayControl;
eKeys key = Interface.GetKey(!*Interact || !(*Interact)->NeedsFastResponse());
if (RecordControl) {
switch (RecordControl->ProcessKey(key)) {
case osMenu: break;
case osEnd: DELETENULL(Menu); // must make sure no menu uses the timer
DELETENULL(RecordControl);
break;
default: if (!*Interact)
continue;
}
}
if (*Interact) {
switch ((*Interact)->ProcessKey(key)) {
case osMenu: DELETENULL(Menu);
Menu = new cMenuMain;
Menu->Display();
break;
case osReplay: DELETENULL(Menu);
DELETENULL(ReplayControl);
@ -139,7 +128,7 @@ int main(int argc, char *argv[])
// Direct Channel Select (input):
case k0: case k1: case k2: case k3: case k4: case k5: case k6: case k7: case k8: case k9:
{
if (!DvbApi.Recording()) {
if (!RecordControl) {
dcNumber = dcNumber * 10 + key - k0;
dcTime = time_ms();
Interface.DisplayChannel(dcNumber);
@ -147,19 +136,14 @@ int main(int argc, char *argv[])
}
break;
// Instant Recording:
case kRecord: if (!DvbApi.Recording()) {
cTimer *timer = new cTimer(true);
Timers.Add(timer);
Timers.Save();
}
case kRecord: if (!RecordControl)
RecordControl = new cRecordControl;
break;
// Menu Control:
case kMenu: Menu = new cMenuMain;
Menu->Display();
break;
case kMenu: Menu = new cMenuMain; break;
// Up/Down Channel Select:
case kUp:
case kDown: if (!DvbApi.Recording()) {
case kDown: if (!RecordControl) {
int n = CurrentChannel + (key == kUp ? 1 : -1);
cChannel *channel = Channels.Get(n);
if (channel)
@ -173,8 +157,9 @@ int main(int argc, char *argv[])
}
}
isyslog(LOG_INFO, "caught signal %d", Interrupted);
DvbApi.StopRecord();
DvbApi.StopReplay();
delete Menu;
delete RecordControl;
delete ReplayControl;
isyslog(LOG_INFO, "exiting");
closelog();
return 0;