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.
|
|
|
|
*
|
2006-01-28 12:48:33 +01:00
|
|
|
* $Id: interface.c 1.72 2006/01/28 12:44:34 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"
|
2002-05-19 15:50:11 +02:00
|
|
|
#include "status.h"
|
2000-09-03 11:40:00 +02:00
|
|
|
|
2000-10-08 12:24:30 +02:00
|
|
|
cInterface *Interface = NULL;
|
2000-02-19 13:36:48 +01:00
|
|
|
|
2000-10-08 12:24:30 +02: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);
|
|
|
|
}
|
|
|
|
|
2000-10-08 12:24:30 +02:00
|
|
|
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
|
|
|
{
|
2003-04-27 12:36:21 +02:00
|
|
|
if (!cRemote::HasKeys())
|
2004-05-16 10:35:36 +02:00
|
|
|
Skins.Flush();
|
2001-02-18 14:18:13 +01:00
|
|
|
if (SVDRP) {
|
2002-10-20 12:49:16 +02:00
|
|
|
if (SVDRP->Process())
|
|
|
|
Wait = false;
|
2001-02-18 14:18:13 +01:00
|
|
|
}
|
2006-01-28 12:48:33 +01:00
|
|
|
return cRemote::Get(Wait ? 1000 : 100);
|
2000-09-17 09:36:50 +02:00
|
|
|
}
|
|
|
|
|
2000-04-22 13:51:48 +02:00
|
|
|
eKeys cInterface::Wait(int Seconds, bool KeepChar)
|
2000-03-11 11:22:37 +01:00
|
|
|
{
|
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();
|
2005-09-03 09:09:23 +02:00
|
|
|
if (ISRAWKEY(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;
|
2000-03-11 11:22:37 +01:00
|
|
|
}
|
|
|
|
|
2001-09-01 09:04:37 +02:00
|
|
|
bool cInterface::Confirm(const char *s, int Seconds, bool WaitForTimeout)
|
2000-03-11 11:22:37 +01:00
|
|
|
{
|
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 ");
|
2000-03-11 11:22:37 +01:00
|
|
|
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-11-01 14:27:43 +01:00
|
|
|
DisplayMenu->SetItem(tr("Phase 1: Detecting RC code type"), 2, false, false);
|
|
|
|
DisplayMenu->SetItem(tr("Press any key on the RC unit"), 4, false, false);
|
2004-05-16 10:35:36 +02:00
|
|
|
DisplayMenu->Flush();
|
2002-09-29 13:40:45 +02:00
|
|
|
if (Remote->Initialize()) {
|
2004-11-01 14:27:43 +01:00
|
|
|
DisplayMenu->SetItem(tr("RC code detected!"), 4, false, false);
|
|
|
|
DisplayMenu->SetItem(tr("Do not press any key..."), 5, false, false);
|
2004-05-16 10:35:36 +02:00
|
|
|
DisplayMenu->Flush();
|
2002-09-29 13:40:45 +02:00
|
|
|
sleep(3);
|
2004-05-16 10:35:36 +02:00
|
|
|
DisplayMenu->SetItem("", 4, false, false);
|
2004-11-01 14:27:43 +01:00
|
|
|
DisplayMenu->SetItem("", 5, false, false);
|
2002-09-29 13:40:45 +02:00
|
|
|
|
2004-11-01 14:27:43 +01:00
|
|
|
DisplayMenu->SetItem(tr("Phase 2: Learning specific key codes"), 2, false, false);
|
2002-09-29 13:40:45 +02:00
|
|
|
eKeys NewKey = kUp;
|
|
|
|
while (NewKey != kNone) {
|
|
|
|
char *Prompt;
|
2006-01-04 15:51:03 +01:00
|
|
|
char buf[32];
|
|
|
|
snprintf(buf, sizeof(buf), "Key$%s", cKey::ToString(NewKey));
|
|
|
|
asprintf(&Prompt, tr("Press key for '%s'"), tr(buf));
|
2004-11-01 14:27:43 +01:00
|
|
|
DisplayMenu->SetItem(Prompt, 4, 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) {
|
2002-10-27 16:02:27 +01:00
|
|
|
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-11-01 14:27:43 +01:00
|
|
|
case kDown: DisplayMenu->SetItem(tr("Press 'Up' to confirm"), 4, false, false);
|
|
|
|
DisplayMenu->SetItem(tr("Press 'Down' to continue"), 5, false, false);
|
2004-05-16 10:35:36 +02:00
|
|
|
DisplayMenu->SetItem("", 6, false, false);
|
|
|
|
DisplayMenu->SetItem("", 7, false, false);
|
2004-11-01 14:27:43 +01:00
|
|
|
DisplayMenu->SetItem("", 8, false, false);
|
2004-05-16 10:35:36 +02:00
|
|
|
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();
|
2003-10-05 09:51:02 +02:00
|
|
|
return true;
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
2002-09-29 13:40:45 +02:00
|
|
|
else if (Key == kDown) {
|
2004-11-01 14:27:43 +01:00
|
|
|
DisplayMenu->SetItem("", 5, 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-11-01 14:27:43 +01:00
|
|
|
DisplayMenu->SetItem(tr("(press 'Up' to go back)"), 6, false, false);
|
2002-09-29 13:40:45 +02:00
|
|
|
else
|
2004-11-01 14:27:43 +01:00
|
|
|
DisplayMenu->SetItem("", 6, false, false);
|
2002-09-29 13:40:45 +02:00
|
|
|
if (NewKey > kDown)
|
2004-11-01 14:27:43 +01:00
|
|
|
DisplayMenu->SetItem(tr("(press 'Down' to end key definition)"), 7, false, false);
|
2002-09-29 13:40:45 +02:00
|
|
|
else
|
2004-11-01 14:27:43 +01:00
|
|
|
DisplayMenu->SetItem("", 7, false, false);
|
2002-09-29 13:40:45 +02:00
|
|
|
if (NewKey > kMenu)
|
2004-11-01 14:27:43 +01:00
|
|
|
DisplayMenu->SetItem(tr("(press 'Menu' to skip this key)"), 8, false, false);
|
2002-09-29 13:40:45 +02:00
|
|
|
else
|
2004-11-01 14:27:43 +01:00
|
|
|
DisplayMenu->SetItem("", 8, false, false);
|
2002-09-29 13:40:45 +02:00
|
|
|
}
|
2003-10-05 09:51:02 +02:00
|
|
|
return true;
|
2002-09-29 13:40:45 +02:00
|
|
|
}
|
2003-10-05 09:51:02 +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)) {
|
2003-04-12 14:37:57 +02:00
|
|
|
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];
|
2004-11-01 14:27:43 +01:00
|
|
|
snprintf(Headline, sizeof(Headline), tr("Learning Remote Control Keys"));
|
2002-10-26 12:56:53 +02:00
|
|
|
cRemote::Clear();
|
2004-05-16 10:35:36 +02:00
|
|
|
DisplayMenu->SetTitle(Headline);
|
2004-11-01 14:27:43 +01:00
|
|
|
DisplayMenu->SetItem(Remote->Name(), 0, false, false);
|
2002-11-01 10:53:07 +01:00
|
|
|
cRemote::SetLearning(Remote);
|
2004-05-16 10:35:36 +02:00
|
|
|
bool rc = QueryKeys(Remote, DisplayMenu);
|
2002-11-01 10:53:07 +01:00
|
|
|
cRemote::SetLearning(NULL);
|
2004-05-16 10:35:36 +02:00
|
|
|
DisplayMenu->Clear();
|
2003-10-05 09:51:02 +02:00
|
|
|
if (!rc) {
|
2004-05-16 10:35:36 +02:00
|
|
|
delete DisplayMenu;
|
2003-10-24 15:48:09 +02:00
|
|
|
continue;
|
2003-10-05 09:51:02 +02:00
|
|
|
}
|
2004-11-01 14:27:43 +01:00
|
|
|
DisplayMenu->SetItem(Remote->Name(), 0, false, false);
|
|
|
|
DisplayMenu->SetItem(tr("Phase 3: Saving key codes"), 2, false, false);
|
|
|
|
DisplayMenu->SetItem(tr("Press 'Up' to save, 'Down' to cancel"), 4, false, false);
|
2002-09-29 13:40:45 +02:00
|
|
|
for (;;) {
|
2002-10-26 12:56:53 +02:00
|
|
|
eKeys key = GetKey();
|
|
|
|
if (key == kUp) {
|
|
|
|
Keys.Save();
|
2004-05-16 10:35:36 +02:00
|
|
|
delete DisplayMenu;
|
2002-10-26 12:56:53 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (key == kDown) {
|
|
|
|
Keys.Load();
|
2004-05-16 10:35:36 +02:00
|
|
|
delete DisplayMenu;
|
2002-10-26 12:56:53 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|