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

194 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.
*
* $Id: interface.c 4.1 2015/04/28 11:16: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>
2015-01-11 13:42:26 +01:00
#ifdef SDNOTIFY
#include <systemd/sd-daemon.h>
#endif
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(void)
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
}
cInterface::~cInterface()
2000-09-19 17:48:42 +02:00
{
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 (!cRemote::IsLearning())
return cRemote::Get(Wait ? 1000 : 10);
else
return kNone;
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();
if (ISRAWKEY(Key) || time(NULL) > timeout || interrupted)
2000-10-08 09:25:20 +02:00
break;
}
if (KeepChar && ISRAWKEY(Key) || Key == k_Plugin)
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
{
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()) {
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();
cCondWait::SleepMs(3000);
2004-05-16 10:35:36 +02:00
DisplayMenu->SetItem("", 4, false, false);
DisplayMenu->SetItem("", 5, false, false);
2002-09-29 13:40:45 +02: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) {
DisplayMenu->SetItem(cString::sprintf(tr("Press key for '%s'"), cKey::ToString(NewKey, true)), 4, false, false);
2002-09-29 13:40:45 +02:00
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;
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);
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();
return true;
2000-02-19 13:36:48 +01:00
}
2002-09-29 13:40:45 +02:00
else if (Key == kDown) {
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)
DisplayMenu->SetItem(tr("(press 'Up' to go back)"), 6, false, false);
2002-09-29 13:40:45 +02:00
else
DisplayMenu->SetItem("", 6, false, false);
2002-09-29 13:40:45 +02:00
if (NewKey > kDown)
DisplayMenu->SetItem(tr("(press 'Down' to end key definition)"), 7, false, false);
2002-09-29 13:40:45 +02:00
else
DisplayMenu->SetItem("", 7, false, false);
2002-09-29 13:40:45 +02:00
if (NewKey > kMenu)
DisplayMenu->SetItem(tr("(press 'Menu' to skip this key)"), 8, false, false);
2002-09-29 13:40:45 +02:00
else
DisplayMenu->SetItem("", 8, 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) {
2015-01-11 13:42:26 +01:00
#ifdef SDNOTIFY
sd_notify(0, "READY=1\nSTATUS=Learning keys...");
#endif
2004-05-16 10:35:36 +02:00
cSkinDisplayMenu *DisplayMenu = Skins.Current()->DisplayMenu();
DisplayMenu->SetMenuCategory(mcUnknown);
2004-05-16 10:35:36 +02:00
char Headline[256];
snprintf(Headline, sizeof(Headline), tr("Learning Remote Control Keys"));
cRemote::Clear();
2004-05-16 10:35:36 +02:00
DisplayMenu->SetTitle(Headline);
DisplayMenu->SetItem(Remote->Name(), 0, false, false);
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;
}
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 (;;) {
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
}
}