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

Better encapsulation of user interaction

This commit is contained in:
Klaus Schmidinger 2000-04-29 15:57:42 +02:00
parent 20ad6d5a05
commit f13ded672b
4 changed files with 122 additions and 83 deletions

81
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.9 2000/04/29 08:52:54 kls Exp $ * $Id: menu.c 1.10 2000/04/29 14:53:27 kls Exp $
*/ */
#include "menu.h" #include "menu.h"
@ -947,9 +947,8 @@ eOSState cMenuRecordings::Play(void)
{ {
cMenuRecordingItem *ri = (cMenuRecordingItem *)Get(Current()); cMenuRecordingItem *ri = (cMenuRecordingItem *)Get(Current());
if (ri) { if (ri) {
//XXX what if this recording's file is currently in use??? cReplayControl::SetRecording(ri->recording->FileName(), ri->recording->Title());
if (DvbApi.StartReplay(ri->recording->FileName(), ri->recording->Title())) return osReplay;
return osEnd;
} }
return osContinue; return osContinue;
} }
@ -1008,41 +1007,75 @@ eOSState cMenuMain::ProcessKey(eKeys Key)
case osChannels: return AddSubMenu(new cMenuChannels); case osChannels: return AddSubMenu(new cMenuChannels);
case osTimer: return AddSubMenu(new cMenuTimers); case osTimer: return AddSubMenu(new cMenuTimers);
case osRecordings: return AddSubMenu(new cMenuRecordings); case osRecordings: return AddSubMenu(new cMenuRecordings);
default: break; default: if (Key == kMenu)
state = osEnd;
} }
return state; return state;
} }
// --- cReplayDisplay -------------------------------------------------------- // --- cReplayControl --------------------------------------------------------
cReplayDisplay::cReplayDisplay(void) char *cReplayControl::fileName = NULL;
char *cReplayControl::title = NULL;
cReplayControl::cReplayControl(void)
{ {
visible = shown = false;
if (fileName)
DvbApi.StartReplay(fileName, title);
}
cReplayControl::~cReplayControl()
{
Hide();
DvbApi.StopReplay();
}
void cReplayControl::SetRecording(const char *FileName, const char *Title)
{
delete fileName;
delete title;
fileName = FileName ? strdup(FileName) : NULL;
title = Title ? strdup(Title) : NULL;
}
void cReplayControl::Show(void)
{
if (!visible) {
Interface.Open(MenuColumns, -3); Interface.Open(MenuColumns, -3);
visible = true;
shown = DvbApi.ShowProgress(true); shown = DvbApi.ShowProgress(true);
} }
cReplayDisplay::~cReplayDisplay()
{
Interface.Close();
} }
eKeys cReplayDisplay::ProcessKey(eKeys Key) void cReplayControl::Hide(void)
{
if (visible) {
Interface.Close();
visible = false;
}
}
eOSState cReplayControl::ProcessKey(eKeys Key)
{ {
if (!DvbApi.Replaying()) if (!DvbApi.Replaying())
return kOk; // will turn off replay display return osEnd;
if (visible)
shown = DvbApi.ShowProgress(!shown) || shown; shown = DvbApi.ShowProgress(!shown) || shown;
switch (Key) { switch (Key) {
case kBegin: case kBegin: DvbApi.Skip(-INT_MAX); break;
case kPause: case kPause: DvbApi.PauseReplay(); break;
case kStop: case kStop: Hide();
case kSearchBack: DvbApi.StopReplay();
case kSearchForward: return osEnd;
case kSkipBack: case kSearchBack: DvbApi.FastRewind(); break;
case kSkipForward: break; // will be done in main loop case kSearchForward: DvbApi.FastForward(); break;
case kMenu: break; // allow direct switching to menu case kSkipBack: DvbApi.Skip(-60); break;
case kOk: break; // switches off replay display case kSkipForward: DvbApi.Skip(60); break;
default: Key = kNone; // ignore anything not explicitly known here case kMenu: Hide(); return osMenu; // allow direct switching to menu
case kOk: visible ? Hide() : Show(); break;
default: return osUnknown;
} }
return Key; return osContinue;
} }

18
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.5 2000/04/24 15:31:53 kls Exp $ * $Id: menu.h 1.6 2000/04/29 15:38:39 kls Exp $
*/ */
#ifndef _MENU_H #ifndef _MENU_H
@ -18,13 +18,19 @@ public:
virtual eOSState ProcessKey(eKeys Key); virtual eOSState ProcessKey(eKeys Key);
}; };
class cReplayDisplay { class cReplayControl : public cOsdBase {
private: private:
bool shown; bool visible, shown;
void Show(void);
void Hide(void);
static char *fileName;
static char *title;
public: public:
cReplayDisplay(void); cReplayControl(void);
~cReplayDisplay(); virtual ~cReplayControl();
eKeys ProcessKey(eKeys Key); virtual eOSState ProcessKey(eKeys Key);
bool Visible(void) { return visible; }
static void SetRecording(const char *FileName, const char *Title);
}; };
#endif //_MENU_H #endif //_MENU_H

14
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.4 2000/04/24 09:44:32 kls Exp $ * $Id: osd.h 1.5 2000/04/29 14:45:47 kls Exp $
*/ */
#ifndef __OSD_H #ifndef __OSD_H
@ -17,11 +17,12 @@
#define MAXOSDITEMS 9 #define MAXOSDITEMS 9
enum eOSState { osUnknown, enum eOSState { osUnknown,
osMenu,
osContinue, osContinue,
osProcessed,
osChannels, osChannels,
osTimer, osTimer,
osRecordings, osRecordings,
osReplay,
osBack, osBack,
osEnd, osEnd,
}; };
@ -44,7 +45,14 @@ public:
virtual eOSState ProcessKey(eKeys Key); virtual eOSState ProcessKey(eKeys Key);
}; };
class cOsdMenu : public cList<cOsdItem> { class cOsdBase {
public:
cOsdBase(void) {}
virtual ~cOsdBase() {}
virtual eOSState ProcessKey(eKeys Key) = 0;
};
class cOsdMenu : public cOsdBase, public cList<cOsdItem> {
private: private:
char *title; char *title;
int cols[cInterface::MaxCols]; int cols[cInterface::MaxCols];

62
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.13 2000/04/29 13:13:42 kls Exp $ * $Id: vdr.c 1.14 2000/04/29 15:57:42 kls Exp $
*/ */
#include <signal.h> #include <signal.h>
@ -65,7 +65,7 @@ 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;
cReplayDisplay *ReplayDisplay = NULL; cReplayControl *ReplayControl = NULL;
cTimer *Timer = NULL; cTimer *Timer = NULL;
int dcTime = 0, dcNumber = 0; int dcTime = 0, dcNumber = 0;
int LastChannel = -1; int LastChannel = -1;
@ -73,7 +73,7 @@ int main(int argc, char *argv[])
while (!Interrupted) { while (!Interrupted) {
// Channel display: // Channel display:
if (CurrentChannel != LastChannel) { if (CurrentChannel != LastChannel) {
if (!Timer && !Menu && !ReplayDisplay) { if (!Timer) {
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);
@ -81,20 +81,17 @@ int main(int argc, char *argv[])
LastChannel = CurrentChannel; LastChannel = CurrentChannel;
} }
// Direct Channel Select (action): // Direct Channel Select (action):
if (dcNumber) { if (dcNumber && time_ms() - dcTime > DIRECTCHANNELTIMEOUT) {
Interface.DisplayChannel(dcNumber);
if (time_ms() - dcTime > DIRECTCHANNELTIMEOUT) {
cChannel::SwitchTo(dcNumber - 1); cChannel::SwitchTo(dcNumber - 1);
dcNumber = 0; dcNumber = 0;
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 {
AssertFreeDiskSpace(); AssertFreeDiskSpace();
if (!Timer && (Timer = cTimer::GetMatch()) != NULL) { if (!Timer && (Timer = cTimer::GetMatch()) != NULL) {
DELETENULL(Menu); DELETENULL(Menu);
DELETENULL(ReplayDisplay); DELETENULL(ReplayControl);
// make sure the timer won't be deleted: // make sure the timer won't be deleted:
Timer->SetRecording(true); Timer->SetRecording(true);
// switch to channel: // switch to channel:
@ -119,50 +116,50 @@ int main(int argc, char *argv[])
} }
} }
// User Input: // User Input:
eKeys key = Interface.GetKey(!ReplayDisplay); eKeys key = Interface.GetKey(!ReplayControl || !ReplayControl->Visible());
if (Menu) { cOsdBase **Interact = Menu ? (cOsdBase **)&Menu : (cOsdBase **)&ReplayControl;
switch (Menu->ProcessKey(key)) { if (*Interact) {
default: if (key != kMenu) switch ((*Interact)->ProcessKey(key)) {
case osMenu: DELETENULL(Menu);
Menu = new cMenuMain;
Menu->Display();
break;
case osReplay: DELETENULL(Menu);
DELETENULL(ReplayControl);
ReplayControl = new cReplayControl;
break; break;
case osBack: case osBack:
case osEnd: DELETENULL(Menu); case osEnd: DELETENULL(*Interact);
break; break;
default: ;
} }
} }
else if (!ReplayDisplay || (key = ReplayDisplay->ProcessKey(key)) != kNone) { else {
switch (key) { switch (key) {
// 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() || DvbApi.Replaying())) { if (!DvbApi.Recording()) {
dcNumber = dcNumber * 10 + key - k0; dcNumber = dcNumber * 10 + key - k0;
dcTime = time_ms(); dcTime = time_ms();
Interface.DisplayChannel(dcNumber);
} }
} }
// Record/Replay Control: break;
case kBegin: DvbApi.Skip(-INT_MAX); break; // Instant Recording:
case kRecord: if (!(DvbApi.Recording() || DvbApi.Replaying())) { case kRecord: if (!DvbApi.Recording()) {
cTimer *timer = new cTimer(true); cTimer *timer = new cTimer(true);
Timers.Add(timer); Timers.Add(timer);
Timers.Save(); Timers.Save();
} }
break; break;
case kPause: DvbApi.PauseReplay(); break;
case kStop: DELETENULL(ReplayDisplay);
DvbApi.StopReplay();
break;
case kSearchBack: DvbApi.FastRewind(); break;
case kSearchForward: DvbApi.FastForward(); break;
case kSkipBack: DvbApi.Skip(-60); break;
case kSkipForward: DvbApi.Skip(60); break;
// Menu Control: // Menu Control:
case kMenu: DELETENULL(ReplayDisplay); case kMenu: Menu = new cMenuMain;
Menu = new cMenuMain;
Menu->Display(); Menu->Display();
break; break;
// Up/Down Channel Select: // Up/Down Channel Select:
case kUp: case kUp:
case kDown: if (!(DvbApi.Recording() || DvbApi.Replaying())) { case kDown: if (!DvbApi.Recording()) {
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)
@ -170,12 +167,7 @@ int main(int argc, char *argv[])
} }
break; break;
// Viewing Control: // Viewing Control:
case kOk: if (ReplayDisplay) case kOk: LastChannel = -1; break; // forces channel display
DELETENULL(ReplayDisplay);
else if (DvbApi.Replaying())
ReplayDisplay = new cReplayDisplay;
else
LastChannel = -1; break; // forces channel display
default: break; default: break;
} }
} }