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

200 lines
6.8 KiB
C
Raw Permalink Normal View History

2000-02-19 13:36:48 +01:00
/*
* interface.c: Abstract user interface layer
*
2000-04-24 09:46:05 +02:00
* See the main source file 'vdr.c' for copyright information and
2000-02-19 13:36:48 +01:00
* how to reach the author.
*
2004-05-16 10:35:36 +02:00
* $Id: interface.c 1.67 2004/05/02 10:57:06 kls Exp $
2000-02-19 13:36:48 +01:00
*/
#include "interface.h"
2000-11-01 11:45:05 +01:00
#include <ctype.h>
2002-08-11 10:47:11 +02:00
#include <stdlib.h>
2000-02-19 13:36:48 +01:00
#include <unistd.h>
2000-11-11 10:39:27 +01:00
#include "i18n.h"
#include "status.h"
cInterface *Interface = NULL;
2000-02-19 13:36:48 +01:00
cInterface::cInterface(int SVDRPport)
2000-02-19 13:36:48 +01:00
{
2001-09-01 09:04:37 +02:00
interrupted = false;
2000-09-19 17:48:42 +02:00
SVDRP = NULL;
if (SVDRPport)
SVDRP = new cSVDRP(SVDRPport);
}
cInterface::~cInterface()
2000-09-19 17:48:42 +02:00
{
delete SVDRP;
2000-02-19 13:36:48 +01:00
}
2000-04-23 15:38:16 +02:00
eKeys cInterface::GetKey(bool Wait)
2000-02-19 13:36:48 +01:00
{
if (!cRemote::HasKeys())
2004-05-16 10:35:36 +02:00
Skins.Flush();
if (SVDRP) {
2002-10-20 12:49:16 +02:00
if (SVDRP->Process())
Wait = false;
2004-05-16 10:35:36 +02:00
if (!Skins.IsOpen()) {
char *message = SVDRP->GetMessage();
if (message) {
2004-05-16 10:35:36 +02:00
Skins.Message(mtInfo, message);
free(message);
}
}
}
2002-09-29 13:40:45 +02:00
return cRemote::Get(Wait ? 1000 : 10);
2000-09-17 09:36:50 +02:00
}
2000-04-22 13:51:48 +02:00
eKeys cInterface::Wait(int Seconds, bool KeepChar)
{
2001-09-01 15:23:27 +02:00
if (Seconds == 0)
Seconds = Setup.OSDMessageTime;
2004-05-16 10:35:36 +02:00
Skins.Flush();
2000-10-08 09:25:20 +02:00
eKeys Key = kNone;
time_t timeout = time(NULL) + Seconds;
for (;;) {
Key = GetKey();
2001-09-01 09:04:37 +02:00
if ((Key != kNone && (RAWKEY(Key) != kOk || RAWKEY(Key) == Key)) || time(NULL) > timeout || interrupted)
2000-10-08 09:25:20 +02:00
break;
}
2000-10-08 16:34:17 +02:00
if (KeepChar && ISRAWKEY(Key))
2002-09-29 13:40:45 +02:00
cRemote::Put(Key);
2001-09-01 09:04:37 +02:00
interrupted = false;
2000-04-22 13:51:48 +02:00
return Key;
}
2001-09-01 09:04:37 +02:00
bool cInterface::Confirm(const char *s, int Seconds, bool WaitForTimeout)
{
2002-05-13 16:35:49 +02:00
isyslog("confirm: %s", s);
2004-05-16 10:35:36 +02:00
eKeys k = Skins.Message(mtWarning, s, Seconds);
2001-09-01 09:04:37 +02:00
bool result = WaitForTimeout ? k == kNone : k == kOk;
2002-05-13 16:35:49 +02:00
isyslog("%sconfirmed", result ? "" : "not ");
return result;
}
2004-05-16 10:35:36 +02:00
bool cInterface::QueryKeys(cRemote *Remote, cSkinDisplayMenu *DisplayMenu)
2000-02-19 13:36:48 +01:00
{
2004-05-16 10:35:36 +02:00
DisplayMenu->SetItem(tr("Phase 1: Detecting RC code type"), 1, false, false);
DisplayMenu->SetItem(tr("Press any key on the RC unit"), 3, false, false);
DisplayMenu->Flush();
2002-09-29 13:40:45 +02:00
if (Remote->Initialize()) {
2004-05-16 10:35:36 +02:00
DisplayMenu->SetItem(tr("RC code detected!"), 3, false, false);
DisplayMenu->SetItem(tr("Do not press any key..."), 4, false, false);
DisplayMenu->Flush();
2002-09-29 13:40:45 +02:00
sleep(3);
2004-05-16 10:35:36 +02:00
DisplayMenu->SetItem("", 3, false, false);
DisplayMenu->SetItem("", 4, false, false);
2002-09-29 13:40:45 +02:00
2004-05-16 10:35:36 +02:00
DisplayMenu->SetItem(tr("Phase 2: Learning specific key codes"), 1, false, false);
2002-09-29 13:40:45 +02:00
eKeys NewKey = kUp;
while (NewKey != kNone) {
char *Prompt;
asprintf(&Prompt, tr("Press key for '%s'"), tr(cKey::ToString(NewKey)));
2004-05-16 10:35:36 +02:00
DisplayMenu->SetItem(Prompt, 3, false, false);
2002-09-29 13:40:45 +02:00
free(Prompt);
cRemote::Clear();
2004-05-16 10:35:36 +02:00
DisplayMenu->Flush();
2002-09-29 13:40:45 +02:00
for (eKeys k = NewKey; k == NewKey; ) {
char *NewCode = NULL;
eKeys Key = cRemote::Get(100, &NewCode);
switch (Key) {
case kUp: if (NewKey > kUp) {
NewKey = eKeys(NewKey - 1);
cKey *last = Keys.Last();
if (last && last->Key() == NewKey)
Keys.Del(last);
}
2002-09-29 13:40:45 +02:00
break;
2004-05-16 10:35:36 +02:00
case kDown: DisplayMenu->SetItem(tr("Press 'Up' to confirm"), 3, false, false);
DisplayMenu->SetItem(tr("Press 'Down' to continue"), 4, false, false);
DisplayMenu->SetItem("", 5, false, false);
DisplayMenu->SetItem("", 6, false, false);
DisplayMenu->SetItem("", 7, false, false);
DisplayMenu->Flush();
2002-09-29 13:40:45 +02:00
for (;;) {
Key = cRemote::Get(100);
if (Key == kUp) {
2004-05-16 10:35:36 +02:00
DisplayMenu->Clear();
return true;
2000-02-19 13:36:48 +01:00
}
2002-09-29 13:40:45 +02:00
else if (Key == kDown) {
2004-05-16 10:35:36 +02:00
DisplayMenu->SetItem("", 4, false, false);
2002-09-29 13:40:45 +02:00
k = kNone; // breaks the outer for() loop
break;
}
}
break;
case kMenu: NewKey = eKeys(NewKey + 1);
break;
case kNone: if (NewCode) {
dsyslog("new %s code: %s = %s", Remote->Name(), NewCode, cKey::ToString(NewKey));
Keys.Add(new cKey(Remote->Name(), NewCode, NewKey));
NewKey = eKeys(NewKey + 1);
free(NewCode);
2000-02-19 13:36:48 +01:00
}
break;
default: break;
}
}
2002-09-29 13:40:45 +02:00
if (NewKey > kUp)
2004-05-16 10:35:36 +02:00
DisplayMenu->SetItem(tr("(press 'Up' to go back)"), 5, false, false);
2002-09-29 13:40:45 +02:00
else
2004-05-16 10:35:36 +02:00
DisplayMenu->SetItem("", 5, false, false);
2002-09-29 13:40:45 +02:00
if (NewKey > kDown)
2004-05-16 10:35:36 +02:00
DisplayMenu->SetItem(tr("(press 'Down' to end key definition)"), 6, false, false);
2002-09-29 13:40:45 +02:00
else
2004-05-16 10:35:36 +02:00
DisplayMenu->SetItem("", 6, false, false);
2002-09-29 13:40:45 +02:00
if (NewKey > kMenu)
2004-05-16 10:35:36 +02:00
DisplayMenu->SetItem(tr("(press 'Menu' to skip this key)"), 7, false, false);
2002-09-29 13:40:45 +02:00
else
2004-05-16 10:35:36 +02:00
DisplayMenu->SetItem("", 7, false, false);
2002-09-29 13:40:45 +02:00
}
return true;
2002-09-29 13:40:45 +02:00
}
return false;
2000-02-19 13:36:48 +01:00
}
void cInterface::LearnKeys(void)
{
2002-09-29 13:40:45 +02:00
for (cRemote *Remote = Remotes.First(); Remote; Remote = Remotes.Next(Remote)) {
if (!Remote->Ready()) {
esyslog("ERROR: remote control %s not ready!", Remote->Name());
continue;
}
2002-09-29 13:40:45 +02:00
bool known = Keys.KnowsRemote(Remote->Name());
dsyslog("remote control %s - %s", Remote->Name(), known ? "keys known" : "learning keys");
if (!known) {
2004-05-16 10:35:36 +02:00
cSkinDisplayMenu *DisplayMenu = Skins.Current()->DisplayMenu();
char Headline[256];
snprintf(Headline, sizeof(Headline), tr("Learning Remote Control Keys (%s)"), Remote->Name());
cRemote::Clear();
2004-05-16 10:35:36 +02:00
DisplayMenu->SetTitle(Headline);
cRemote::SetLearning(Remote);
2004-05-16 10:35:36 +02:00
bool rc = QueryKeys(Remote, DisplayMenu);
cRemote::SetLearning(NULL);
2004-05-16 10:35:36 +02:00
DisplayMenu->Clear();
if (!rc) {
2004-05-16 10:35:36 +02:00
delete DisplayMenu;
continue;
}
2004-05-16 10:35:36 +02:00
DisplayMenu->SetItem(tr("Phase 3: Saving key codes"), 1, false, false);
DisplayMenu->SetItem(tr("Press 'Up' to save, 'Down' to cancel"), 3, false, false);
2002-09-29 13:40:45 +02:00
for (;;) {
eKeys key = GetKey();
if (key == kUp) {
Keys.Save();
2004-05-16 10:35:36 +02:00
delete DisplayMenu;
break;
}
else if (key == kDown) {
Keys.Load();
2004-05-16 10:35:36 +02:00
delete DisplayMenu;
break;
}
2000-02-19 13:36:48 +01:00
}
2002-09-29 13:40:45 +02:00
}
2000-02-19 13:36:48 +01:00
}
}