1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

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 * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * 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" #include "menu.h"
@ -997,6 +997,7 @@ cMenuMain::cMenuMain(void)
Add(new cOsdItem("Channels", osChannels)); Add(new cOsdItem("Channels", osChannels));
Add(new cOsdItem("Timer", osTimer)); Add(new cOsdItem("Timer", osTimer));
Add(new cOsdItem("Recordings", osRecordings)); Add(new cOsdItem("Recordings", osRecordings));
Display();
} }
eOSState cMenuMain::ProcessKey(eKeys Key) eOSState cMenuMain::ProcessKey(eKeys Key)
@ -1013,6 +1014,48 @@ eOSState cMenuMain::ProcessKey(eKeys Key)
return state; 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 -------------------------------------------------------- // --- cReplayControl --------------------------------------------------------
char *cReplayControl::fileName = NULL; char *cReplayControl::fileName = NULL;
@ -1043,7 +1086,7 @@ void cReplayControl::Show(void)
{ {
if (!visible) { if (!visible) {
Interface.Open(MenuColumns, -3); Interface.Open(MenuColumns, -3);
visible = true; needsFastResponse = visible = true;
shown = DvbApi.ShowProgress(true); shown = DvbApi.ShowProgress(true);
} }
} }
@ -1052,7 +1095,7 @@ void cReplayControl::Hide(void)
{ {
if (visible) { if (visible) {
Interface.Close(); 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 * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * 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 #ifndef _MENU_H
@ -18,6 +18,15 @@ public:
virtual eOSState ProcessKey(eKeys Key); 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 { class cReplayControl : public cOsdBase {
private: private:
bool visible, shown; bool visible, shown;

7
osd.h
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * 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 #ifndef __OSD_H
@ -46,10 +46,13 @@ public:
}; };
class cOsdBase { class cOsdBase {
protected:
bool needsFastResponse;
public: public:
cOsdBase(void) {} cOsdBase(bool FastResponse = false) { needsFastResponse = FastResponse; }
virtual ~cOsdBase() {} virtual ~cOsdBase() {}
virtual eOSState ProcessKey(eKeys Key) = 0; virtual eOSState ProcessKey(eKeys Key) = 0;
bool NeedsFastResponse(void) { return needsFastResponse; }
}; };
class cOsdMenu : public cOsdBase, public cList<cOsdItem> { class cOsdMenu : public cOsdBase, public cList<cOsdItem> {

View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * 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 #define _GNU_SOURCE
@ -62,7 +62,7 @@ void AssertFreeDiskSpace(void)
static time_t LastFreeDiskCheck = 0; static time_t LastFreeDiskCheck = 0;
if (time(NULL) - LastFreeDiskCheck > DISKCHECKDELTA) { if (time(NULL) - LastFreeDiskCheck > DISKCHECKDELTA) {
LastFreeDiskCheck = time(NULL); LastFreeDiskCheck = time(NULL);
if (DvbApi.Recording() && LowDiskSpace()) { if (LowDiskSpace()) {
// Remove the oldest file that has been "deleted": // Remove the oldest file that has been "deleted":
cRecordings Recordings; cRecordings Recordings;
if (Recordings.Load(true)) { 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 * 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> #include <signal.h>
@ -65,15 +65,15 @@ int main(int argc, char *argv[])
if (signal(SIGTERM, SignalHandler) == SIG_IGN) signal(SIGTERM, SIG_IGN); if (signal(SIGTERM, SignalHandler) == SIG_IGN) signal(SIGTERM, SIG_IGN);
cMenuMain *Menu = NULL; cMenuMain *Menu = NULL;
cRecordControl *RecordControl = NULL;
cReplayControl *ReplayControl = NULL; cReplayControl *ReplayControl = NULL;
cTimer *Timer = NULL;
int dcTime = 0, dcNumber = 0; int dcTime = 0, dcNumber = 0;
int LastChannel = -1; int LastChannel = -1;
while (!Interrupted) { while (!Interrupted) {
// Channel display: // Channel display:
if (CurrentChannel != LastChannel) { if (CurrentChannel != LastChannel) {
if (!Timer) { if (!RecordControl) {
cChannel *channel = Channels.Get(CurrentChannel); cChannel *channel = Channels.Get(CurrentChannel);
if (channel) if (channel)
Interface.DisplayChannel(CurrentChannel + 1, channel->name); 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! LastChannel = -1; // in case an invalid channel number was entered!
} }
// Timer Processing: // Timer Processing:
else { else if (!RecordControl) {
AssertFreeDiskSpace(); cTimer *Timer = cTimer::GetMatch();
if (!Timer && (Timer = cTimer::GetMatch()) != NULL) { if (Timer) {
DELETENULL(Menu); DELETENULL(Menu);
DELETENULL(ReplayControl); DELETENULL(ReplayControl);
// make sure the timer won't be deleted: RecordControl = new cRecordControl(Timer);
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;
} }
} }
// User Input: // User Input:
eKeys key = Interface.GetKey(!ReplayControl || !ReplayControl->Visible());
cOsdBase **Interact = Menu ? (cOsdBase **)&Menu : (cOsdBase **)&ReplayControl; 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) { if (*Interact) {
switch ((*Interact)->ProcessKey(key)) { switch ((*Interact)->ProcessKey(key)) {
case osMenu: DELETENULL(Menu); case osMenu: DELETENULL(Menu);
Menu = new cMenuMain; Menu = new cMenuMain;
Menu->Display();
break; break;
case osReplay: DELETENULL(Menu); case osReplay: DELETENULL(Menu);
DELETENULL(ReplayControl); DELETENULL(ReplayControl);
@ -139,7 +128,7 @@ int main(int argc, char *argv[])
// Direct Channel Select (input): // Direct Channel Select (input):
case k0: case k1: case k2: case k3: case k4: case k5: case k6: case k7: case k8: case k9: 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; dcNumber = dcNumber * 10 + key - k0;
dcTime = time_ms(); dcTime = time_ms();
Interface.DisplayChannel(dcNumber); Interface.DisplayChannel(dcNumber);
@ -147,19 +136,14 @@ int main(int argc, char *argv[])
} }
break; break;
// Instant Recording: // Instant Recording:
case kRecord: if (!DvbApi.Recording()) { case kRecord: if (!RecordControl)
cTimer *timer = new cTimer(true); RecordControl = new cRecordControl;
Timers.Add(timer);
Timers.Save();
}
break; break;
// Menu Control: // Menu Control:
case kMenu: Menu = new cMenuMain; case kMenu: Menu = new cMenuMain; break;
Menu->Display();
break;
// Up/Down Channel Select: // Up/Down Channel Select:
case kUp: case kUp:
case kDown: if (!DvbApi.Recording()) { case kDown: if (!RecordControl) {
int n = CurrentChannel + (key == kUp ? 1 : -1); int n = CurrentChannel + (key == kUp ? 1 : -1);
cChannel *channel = Channels.Get(n); cChannel *channel = Channels.Get(n);
if (channel) if (channel)
@ -173,8 +157,9 @@ int main(int argc, char *argv[])
} }
} }
isyslog(LOG_INFO, "caught signal %d", Interrupted); isyslog(LOG_INFO, "caught signal %d", Interrupted);
DvbApi.StopRecord(); delete Menu;
DvbApi.StopReplay(); delete RecordControl;
delete ReplayControl;
isyslog(LOG_INFO, "exiting"); isyslog(LOG_INFO, "exiting");
closelog(); closelog();
return 0; return 0;