2002-05-09 16:26:56 +02:00
|
|
|
/*
|
|
|
|
* menuitems.c: General purpose menu items
|
|
|
|
*
|
|
|
|
* See the main source file 'vdr.c' for copyright information and
|
|
|
|
* how to reach the author.
|
|
|
|
*
|
2006-01-21 12:27:14 +01:00
|
|
|
* $Id: menuitems.c 1.30 2006/01/21 12:27:14 kls Exp $
|
2002-05-09 16:26:56 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "menuitems.h"
|
|
|
|
#include <ctype.h>
|
|
|
|
#include "i18n.h"
|
2002-05-11 13:44:58 +02:00
|
|
|
#include "plugin.h"
|
2004-05-16 10:35:36 +02:00
|
|
|
#include "remote.h"
|
|
|
|
#include "skins.h"
|
2002-05-19 15:50:11 +02:00
|
|
|
#include "status.h"
|
2002-05-09 16:26:56 +02:00
|
|
|
|
2006-01-21 12:27:14 +01:00
|
|
|
#define AUTO_ADVANCE_TIMEOUT 1500 // ms before auto advance when entering characters via numeric keys
|
|
|
|
|
2006-01-06 16:57:41 +01:00
|
|
|
const char *FileNameChars = " abcdefghijklmnopqrstuvwxyz0123456789-.#~,/_@";
|
2002-08-15 11:28:26 +02:00
|
|
|
|
2002-05-09 16:26:56 +02:00
|
|
|
// --- cMenuEditItem ---------------------------------------------------------
|
|
|
|
|
|
|
|
cMenuEditItem::cMenuEditItem(const char *Name)
|
|
|
|
{
|
|
|
|
name = strdup(Name);
|
|
|
|
value = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cMenuEditItem::~cMenuEditItem()
|
|
|
|
{
|
2002-08-11 13:32:23 +02:00
|
|
|
free(name);
|
|
|
|
free(value);
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditItem::SetValue(const char *Value)
|
|
|
|
{
|
2002-08-11 13:32:23 +02:00
|
|
|
free(value);
|
2002-05-09 16:26:56 +02:00
|
|
|
value = strdup(Value);
|
|
|
|
char *buffer = NULL;
|
|
|
|
asprintf(&buffer, "%s:\t%s", name, value);
|
|
|
|
SetText(buffer, false);
|
2004-01-25 15:43:11 +01:00
|
|
|
cStatus::MsgOsdCurrentItem(buffer);
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// --- cMenuEditIntItem ------------------------------------------------------
|
|
|
|
|
|
|
|
cMenuEditIntItem::cMenuEditIntItem(const char *Name, int *Value, int Min, int Max)
|
|
|
|
:cMenuEditItem(Name)
|
|
|
|
{
|
|
|
|
value = Value;
|
|
|
|
min = Min;
|
|
|
|
max = Max;
|
|
|
|
Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditIntItem::Set(void)
|
|
|
|
{
|
|
|
|
char buf[16];
|
|
|
|
snprintf(buf, sizeof(buf), "%d", *value);
|
|
|
|
SetValue(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
eOSState cMenuEditIntItem::ProcessKey(eKeys Key)
|
|
|
|
{
|
|
|
|
eOSState state = cMenuEditItem::ProcessKey(Key);
|
|
|
|
|
|
|
|
if (state == osUnknown) {
|
2003-04-12 09:24:48 +02:00
|
|
|
int newValue = *value;
|
|
|
|
Key = NORMALKEY(Key);
|
|
|
|
switch (Key) {
|
|
|
|
case kNone: break;
|
|
|
|
case k0 ... k9:
|
|
|
|
if (fresh) {
|
|
|
|
*value = 0;
|
|
|
|
fresh = false;
|
|
|
|
}
|
|
|
|
newValue = *value * 10 + (Key - k0);
|
|
|
|
break;
|
|
|
|
case kLeft: // TODO might want to increase the delta if repeated quickly?
|
|
|
|
newValue = *value - 1;
|
|
|
|
fresh = true;
|
|
|
|
break;
|
|
|
|
case kRight:
|
|
|
|
newValue = *value + 1;
|
|
|
|
fresh = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (*value < min) { *value = min; Set(); }
|
|
|
|
if (*value > max) { *value = max; Set(); }
|
|
|
|
return state;
|
|
|
|
}
|
2002-05-09 16:26:56 +02:00
|
|
|
if ((!fresh || min <= newValue) && newValue <= max) {
|
|
|
|
*value = newValue;
|
|
|
|
Set();
|
|
|
|
}
|
|
|
|
state = osContinue;
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- cMenuEditBoolItem -----------------------------------------------------
|
|
|
|
|
|
|
|
cMenuEditBoolItem::cMenuEditBoolItem(const char *Name, int *Value, const char *FalseString, const char *TrueString)
|
|
|
|
:cMenuEditIntItem(Name, Value, 0, 1)
|
|
|
|
{
|
|
|
|
falseString = FalseString ? FalseString : tr("no");
|
|
|
|
trueString = TrueString ? TrueString : tr("yes");
|
|
|
|
Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditBoolItem::Set(void)
|
|
|
|
{
|
|
|
|
char buf[16];
|
|
|
|
snprintf(buf, sizeof(buf), "%s", *value ? trueString : falseString);
|
|
|
|
SetValue(buf);
|
|
|
|
}
|
|
|
|
|
2004-02-29 14:21:22 +01:00
|
|
|
// --- cMenuEditBitItem ------------------------------------------------------
|
|
|
|
|
2006-01-06 14:31:57 +01:00
|
|
|
cMenuEditBitItem::cMenuEditBitItem(const char *Name, uint *Value, uint Mask, const char *FalseString, const char *TrueString)
|
2004-02-29 14:21:22 +01:00
|
|
|
:cMenuEditBoolItem(Name, &bit, FalseString, TrueString)
|
|
|
|
{
|
|
|
|
value = Value;
|
|
|
|
bit = (*value & Mask) != 0;
|
|
|
|
mask = Mask;
|
|
|
|
Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditBitItem::Set(void)
|
|
|
|
{
|
|
|
|
*value = bit ? *value | mask : *value & ~mask;
|
|
|
|
cMenuEditBoolItem::Set();
|
|
|
|
}
|
|
|
|
|
2003-01-19 14:59:46 +01:00
|
|
|
// --- cMenuEditNumItem ------------------------------------------------------
|
|
|
|
|
|
|
|
cMenuEditNumItem::cMenuEditNumItem(const char *Name, char *Value, int Length, bool Blind)
|
|
|
|
:cMenuEditItem(Name)
|
|
|
|
{
|
|
|
|
value = Value;
|
|
|
|
length = Length;
|
|
|
|
blind = Blind;
|
|
|
|
Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditNumItem::Set(void)
|
|
|
|
{
|
|
|
|
if (blind) {
|
|
|
|
char buf[length + 1];
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < length && value[i]; i++)
|
|
|
|
buf[i] = '*';
|
|
|
|
buf[i] = 0;
|
|
|
|
SetValue(buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SetValue(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
eOSState cMenuEditNumItem::ProcessKey(eKeys Key)
|
|
|
|
{
|
|
|
|
eOSState state = cMenuEditItem::ProcessKey(Key);
|
|
|
|
|
|
|
|
if (state == osUnknown) {
|
|
|
|
Key = NORMALKEY(Key);
|
|
|
|
switch (Key) {
|
|
|
|
case kLeft: {
|
|
|
|
int l = strlen(value);
|
|
|
|
if (l > 0)
|
|
|
|
value[l - 1] = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case k0 ... k9: {
|
|
|
|
int l = strlen(value);
|
|
|
|
if (l < length) {
|
|
|
|
value[l] = Key - k0 + '0';
|
|
|
|
value[l + 1] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: return state;
|
|
|
|
}
|
|
|
|
Set();
|
|
|
|
state = osContinue;
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2002-05-09 16:26:56 +02:00
|
|
|
// --- cMenuEditChrItem ------------------------------------------------------
|
|
|
|
|
|
|
|
cMenuEditChrItem::cMenuEditChrItem(const char *Name, char *Value, const char *Allowed)
|
|
|
|
:cMenuEditItem(Name)
|
|
|
|
{
|
|
|
|
value = Value;
|
|
|
|
allowed = strdup(Allowed);
|
|
|
|
current = strchr(allowed, *Value);
|
|
|
|
if (!current)
|
|
|
|
current = allowed;
|
|
|
|
Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
cMenuEditChrItem::~cMenuEditChrItem()
|
|
|
|
{
|
2002-08-11 13:32:23 +02:00
|
|
|
free(allowed);
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditChrItem::Set(void)
|
|
|
|
{
|
|
|
|
char buf[2];
|
|
|
|
snprintf(buf, sizeof(buf), "%c", *value);
|
|
|
|
SetValue(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
eOSState cMenuEditChrItem::ProcessKey(eKeys Key)
|
|
|
|
{
|
|
|
|
eOSState state = cMenuEditItem::ProcessKey(Key);
|
|
|
|
|
|
|
|
if (state == osUnknown) {
|
|
|
|
if (NORMALKEY(Key) == kLeft) {
|
|
|
|
if (current > allowed)
|
|
|
|
current--;
|
|
|
|
}
|
|
|
|
else if (NORMALKEY(Key) == kRight) {
|
|
|
|
if (*(current + 1))
|
|
|
|
current++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return state;
|
|
|
|
*value = *current;
|
|
|
|
Set();
|
|
|
|
state = osContinue;
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- cMenuEditStrItem ------------------------------------------------------
|
|
|
|
|
|
|
|
cMenuEditStrItem::cMenuEditStrItem(const char *Name, char *Value, int Length, const char *Allowed)
|
|
|
|
:cMenuEditItem(Name)
|
|
|
|
{
|
|
|
|
value = Value;
|
|
|
|
length = Length;
|
|
|
|
allowed = strdup(Allowed);
|
|
|
|
pos = -1;
|
|
|
|
insert = uppercase = false;
|
|
|
|
newchar = true;
|
2006-01-06 16:57:41 +01:00
|
|
|
charMap = tr(" 0\t-.#~,/_@1\tabc2\tdef3\tghi4\tjkl5\tmno6\tpqrs7\ttuv8\twxyz9");
|
|
|
|
currentChar = NULL;
|
|
|
|
lastKey = kNone;
|
2002-05-09 16:26:56 +02:00
|
|
|
Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
cMenuEditStrItem::~cMenuEditStrItem()
|
|
|
|
{
|
2002-08-11 13:32:23 +02:00
|
|
|
free(allowed);
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditStrItem::SetHelpKeys(void)
|
|
|
|
{
|
2006-01-03 12:50:58 +01:00
|
|
|
if (InEditMode())
|
2006-01-07 15:54:10 +01:00
|
|
|
cSkinDisplay::Current()->SetButtons(tr("Button$ABC/abc"), tr(insert ? "Button$Overwrite" : "Button$Insert"), tr("Button$Delete"));
|
2002-05-09 16:26:56 +02:00
|
|
|
else
|
2004-05-16 10:35:36 +02:00
|
|
|
cSkinDisplay::Current()->SetButtons(NULL);
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
|
2006-01-21 12:27:14 +01:00
|
|
|
void cMenuEditStrItem::AdvancePos(void)
|
|
|
|
{
|
|
|
|
if (pos < length - 2 && pos < int(strlen(value)) ) {
|
|
|
|
if (++pos >= int(strlen(value))) {
|
|
|
|
if (pos >= 2 && value[pos - 1] == ' ' && value[pos - 2] == ' ')
|
|
|
|
pos--; // allow only two blanks at the end
|
|
|
|
else {
|
|
|
|
value[pos] = ' ';
|
|
|
|
value[pos + 1] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newchar = true;
|
|
|
|
if (!insert && isalpha(value[pos]))
|
|
|
|
uppercase = isupper(value[pos]);
|
|
|
|
}
|
|
|
|
|
2002-05-09 16:26:56 +02:00
|
|
|
void cMenuEditStrItem::Set(void)
|
|
|
|
{
|
|
|
|
char buf[1000];
|
|
|
|
const char *fmt = insert && newchar ? "[]%c%s" : "[%c]%s";
|
|
|
|
|
2006-01-03 12:50:58 +01:00
|
|
|
if (InEditMode()) {
|
2004-05-16 10:35:36 +02:00
|
|
|
const cFont *font = cFont::GetFont(fontOsd);
|
2002-05-09 16:26:56 +02:00
|
|
|
strncpy(buf, value, pos);
|
|
|
|
snprintf(buf + pos, sizeof(buf) - pos - 2, fmt, *(value + pos), value + pos + 1);
|
2004-05-16 10:35:36 +02:00
|
|
|
int width = cSkinDisplay::Current()->EditableWidth();
|
|
|
|
if (font->Width(buf) <= width) {
|
2002-05-09 16:26:56 +02:00
|
|
|
// the whole buffer fits on the screen
|
|
|
|
SetValue(buf);
|
|
|
|
return;
|
|
|
|
}
|
2004-05-16 10:35:36 +02:00
|
|
|
width -= font->Width('>'); // assuming '<' and '>' have the same with
|
2002-05-09 16:26:56 +02:00
|
|
|
int w = 0;
|
|
|
|
int i = 0;
|
|
|
|
int l = strlen(buf);
|
|
|
|
while (i < l && w <= width)
|
2004-05-16 10:35:36 +02:00
|
|
|
w += font->Width(buf[i++]);
|
2002-05-09 16:26:56 +02:00
|
|
|
if (i >= pos + 4) {
|
|
|
|
// the cursor fits on the screen
|
|
|
|
buf[i - 1] = '>';
|
|
|
|
buf[i] = 0;
|
|
|
|
SetValue(buf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// the cursor doesn't fit on the screen
|
|
|
|
w = 0;
|
|
|
|
if (buf[i = pos + 3]) {
|
|
|
|
buf[i] = '>';
|
|
|
|
buf[i + 1] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
i--;
|
|
|
|
while (i >= 0 && w <= width)
|
2004-05-16 10:35:36 +02:00
|
|
|
w += font->Width(buf[i--]);
|
2002-05-09 16:26:56 +02:00
|
|
|
buf[++i] = '<';
|
|
|
|
SetValue(buf + i);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SetValue(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
char cMenuEditStrItem::Inc(char c, bool Up)
|
|
|
|
{
|
|
|
|
const char *p = strchr(allowed, c);
|
|
|
|
if (!p)
|
|
|
|
p = allowed;
|
|
|
|
if (Up) {
|
|
|
|
if (!*++p)
|
|
|
|
p = allowed;
|
|
|
|
}
|
|
|
|
else if (--p < allowed)
|
|
|
|
p = allowed + strlen(allowed) - 1;
|
|
|
|
return *p;
|
|
|
|
}
|
|
|
|
|
|
|
|
eOSState cMenuEditStrItem::ProcessKey(eKeys Key)
|
|
|
|
{
|
2006-01-06 16:57:41 +01:00
|
|
|
bool SameKey = Key == lastKey;
|
|
|
|
if (Key != kNone)
|
|
|
|
lastKey = Key;
|
2006-01-21 12:27:14 +01:00
|
|
|
else if (!newchar && autoAdvanceTimeout.TimedOut()) {
|
|
|
|
AdvancePos();
|
|
|
|
newchar = true;
|
|
|
|
currentChar = NULL;
|
|
|
|
Set();
|
|
|
|
return osContinue;
|
|
|
|
}
|
2002-05-09 16:26:56 +02:00
|
|
|
switch (Key) {
|
|
|
|
case kRed: // Switch between upper- and lowercase characters
|
2006-01-03 12:50:58 +01:00
|
|
|
if (InEditMode()) {
|
2005-09-17 09:42:45 +02:00
|
|
|
if (!insert || !newchar) {
|
|
|
|
uppercase = !uppercase;
|
|
|
|
value[pos] = uppercase ? toupper(value[pos]) : tolower(value[pos]);
|
|
|
|
}
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
2005-09-17 09:42:45 +02:00
|
|
|
else
|
|
|
|
return osUnknown;
|
2002-05-09 16:26:56 +02:00
|
|
|
break;
|
|
|
|
case kGreen: // Toggle insert/overwrite modes
|
2006-01-03 12:50:58 +01:00
|
|
|
if (InEditMode()) {
|
2002-05-09 16:26:56 +02:00
|
|
|
insert = !insert;
|
|
|
|
newchar = true;
|
2004-06-19 09:52:55 +02:00
|
|
|
SetHelpKeys();
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
2005-09-17 09:42:45 +02:00
|
|
|
else
|
|
|
|
return osUnknown;
|
2002-05-09 16:26:56 +02:00
|
|
|
break;
|
|
|
|
case kYellow|k_Repeat:
|
|
|
|
case kYellow: // Remove the character at current position; in insert mode it is the character to the right of cursor
|
2006-01-03 12:50:58 +01:00
|
|
|
if (InEditMode()) {
|
2002-05-09 16:26:56 +02:00
|
|
|
if (strlen(value) > 1) {
|
2002-12-15 11:05:19 +01:00
|
|
|
if (!insert || pos < int(strlen(value)) - 1)
|
|
|
|
memmove(value + pos, value + pos + 1, strlen(value) - pos);
|
2002-05-09 16:26:56 +02:00
|
|
|
// reduce position, if we removed the last character
|
|
|
|
if (pos == int(strlen(value)))
|
|
|
|
pos--;
|
|
|
|
}
|
|
|
|
else if (strlen(value) == 1)
|
|
|
|
value[0] = ' '; // This is the last character in the string, replace it with a blank
|
|
|
|
if (isalpha(value[pos]))
|
|
|
|
uppercase = isupper(value[pos]);
|
|
|
|
newchar = true;
|
|
|
|
}
|
2005-09-17 09:42:45 +02:00
|
|
|
else
|
|
|
|
return osUnknown;
|
|
|
|
break;
|
|
|
|
case kBlue|k_Repeat:
|
|
|
|
case kBlue: // consume the key only if in edit-mode
|
2006-01-03 12:50:58 +01:00
|
|
|
if (InEditMode())
|
2005-09-17 09:42:45 +02:00
|
|
|
;
|
|
|
|
else
|
|
|
|
return osUnknown;
|
2002-05-09 16:26:56 +02:00
|
|
|
break;
|
|
|
|
case kLeft|k_Repeat:
|
|
|
|
case kLeft: if (pos > 0) {
|
|
|
|
if (!insert || newchar)
|
|
|
|
pos--;
|
|
|
|
newchar = true;
|
|
|
|
}
|
|
|
|
if (!insert && isalpha(value[pos]))
|
|
|
|
uppercase = isupper(value[pos]);
|
|
|
|
break;
|
|
|
|
case kRight|k_Repeat:
|
2006-01-21 12:27:14 +01:00
|
|
|
case kRight: AdvancePos();
|
2002-05-09 16:26:56 +02:00
|
|
|
if (pos == 0)
|
|
|
|
SetHelpKeys();
|
|
|
|
break;
|
|
|
|
case kUp|k_Repeat:
|
|
|
|
case kUp:
|
|
|
|
case kDown|k_Repeat:
|
2006-01-03 12:50:58 +01:00
|
|
|
case kDown: if (InEditMode()) {
|
2002-05-09 16:26:56 +02:00
|
|
|
if (insert && newchar) {
|
|
|
|
// create a new character in insert mode
|
2002-12-15 10:58:00 +01:00
|
|
|
if (int(strlen(value)) < length - 1) {
|
2002-05-09 16:26:56 +02:00
|
|
|
memmove(value + pos + 1, value + pos, strlen(value) - pos + 1);
|
|
|
|
value[pos] = ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (uppercase)
|
|
|
|
value[pos] = toupper(Inc(tolower(value[pos]), NORMALKEY(Key) == kUp));
|
|
|
|
else
|
|
|
|
value[pos] = Inc( value[pos], NORMALKEY(Key) == kUp);
|
2006-01-21 12:27:14 +01:00
|
|
|
newchar = true;
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return cMenuEditItem::ProcessKey(Key);
|
|
|
|
break;
|
2006-01-21 12:27:14 +01:00
|
|
|
case k0|k_Repeat ... k9|k_Repeat:
|
2006-01-06 16:57:41 +01:00
|
|
|
case k0 ... k9: {
|
|
|
|
if (InEditMode()) {
|
2006-01-21 12:27:14 +01:00
|
|
|
if (!SameKey) {
|
|
|
|
if (!newchar)
|
|
|
|
AdvancePos();
|
|
|
|
currentChar = NULL;
|
|
|
|
}
|
2006-01-06 16:57:41 +01:00
|
|
|
if (insert && newchar) {
|
|
|
|
// create a new character in insert mode
|
|
|
|
if (int(strlen(value)) < length - 1) {
|
|
|
|
memmove(value + pos + 1, value + pos, strlen(value) - pos + 1);
|
|
|
|
value[pos] = ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!currentChar || !*currentChar || *currentChar == '\t') {
|
|
|
|
// find the beginning of the character map entry for Key
|
|
|
|
int n = Key - k0;
|
|
|
|
currentChar = charMap;
|
|
|
|
while (n > 0 && *currentChar) {
|
|
|
|
if (*currentChar++ == '\t')
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (*currentChar && *currentChar != '\t') {
|
|
|
|
value[pos] = *currentChar;
|
|
|
|
if (uppercase)
|
|
|
|
value[pos] = toupper(value[pos]);
|
|
|
|
currentChar++;
|
|
|
|
}
|
|
|
|
newchar = false;
|
2006-01-21 12:27:14 +01:00
|
|
|
autoAdvanceTimeout.Set(AUTO_ADVANCE_TIMEOUT);
|
2006-01-06 16:57:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return cMenuEditItem::ProcessKey(Key);
|
|
|
|
}
|
|
|
|
break;
|
2006-01-03 12:50:58 +01:00
|
|
|
case kOk: if (InEditMode()) {
|
2002-05-09 16:26:56 +02:00
|
|
|
pos = -1;
|
|
|
|
newchar = true;
|
|
|
|
stripspace(value);
|
|
|
|
SetHelpKeys();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// run into default
|
2006-01-03 12:50:58 +01:00
|
|
|
default: if (InEditMode() && BASICKEY(Key) == kKbd) {
|
2002-12-15 10:58:00 +01:00
|
|
|
int c = KEYKBD(Key);
|
|
|
|
if (c <= 0xFF) {
|
|
|
|
const char *p = strchr(allowed, tolower(c));
|
|
|
|
if (p) {
|
|
|
|
int l = strlen(value);
|
|
|
|
if (insert && l < length - 1)
|
|
|
|
memmove(value + pos + 1, value + pos, l - pos + 1);
|
|
|
|
value[pos] = c;
|
|
|
|
if (pos < length - 2)
|
|
|
|
pos++;
|
|
|
|
if (pos >= l) {
|
|
|
|
value[pos] = ' ';
|
|
|
|
value[pos + 1] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (c) {
|
|
|
|
case 0x7F: // backspace
|
|
|
|
if (pos > 0) {
|
|
|
|
pos--;
|
|
|
|
return ProcessKey(kYellow);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (c) {
|
|
|
|
case kfHome: pos = 0; break;
|
|
|
|
case kfEnd: pos = strlen(value) - 1; break;
|
|
|
|
case kfIns: return ProcessKey(kGreen);
|
|
|
|
case kfDel: return ProcessKey(kYellow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return cMenuEditItem::ProcessKey(Key);
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
Set();
|
|
|
|
return osContinue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- cMenuEditStraItem -----------------------------------------------------
|
|
|
|
|
|
|
|
cMenuEditStraItem::cMenuEditStraItem(const char *Name, int *Value, int NumStrings, const char * const *Strings)
|
|
|
|
:cMenuEditIntItem(Name, Value, 0, NumStrings - 1)
|
|
|
|
{
|
|
|
|
strings = Strings;
|
|
|
|
Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditStraItem::Set(void)
|
|
|
|
{
|
|
|
|
SetValue(strings[*value]);
|
|
|
|
}
|
|
|
|
|
2004-03-28 09:20:02 +02:00
|
|
|
// --- cMenuEditChanItem -----------------------------------------------------
|
|
|
|
|
|
|
|
cMenuEditChanItem::cMenuEditChanItem(const char *Name, int *Value)
|
|
|
|
:cMenuEditIntItem(Name, Value, 1, Channels.MaxNumber())
|
|
|
|
{
|
|
|
|
Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditChanItem::Set(void)
|
|
|
|
{
|
|
|
|
char buf[255];
|
|
|
|
cChannel *channel = Channels.GetByNumber(*value);
|
|
|
|
snprintf(buf, sizeof(buf), "%d %s", *value, channel ? channel->Name() : "");
|
|
|
|
SetValue(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
eOSState cMenuEditChanItem::ProcessKey(eKeys Key)
|
|
|
|
{
|
|
|
|
int delta = 1;
|
|
|
|
|
|
|
|
switch (Key) {
|
|
|
|
case kLeft|k_Repeat:
|
|
|
|
case kLeft: delta = -1;
|
|
|
|
case kRight|k_Repeat:
|
|
|
|
case kRight:
|
|
|
|
{
|
|
|
|
cChannel *channel = Channels.GetByNumber(*value + delta, delta);
|
|
|
|
if (channel) {
|
|
|
|
*value = channel->Number();
|
|
|
|
Set();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2004-11-14 16:27:27 +01:00
|
|
|
default: return cMenuEditIntItem::ProcessKey(Key);
|
2004-03-28 09:20:02 +02:00
|
|
|
}
|
|
|
|
return osContinue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- cMenuEditTranItem -----------------------------------------------------
|
|
|
|
|
2004-05-16 12:58:04 +02:00
|
|
|
cMenuEditTranItem::cMenuEditTranItem(const char *Name, int *Value, int *Source)
|
2004-03-28 09:20:02 +02:00
|
|
|
:cMenuEditChanItem(Name, Value)
|
|
|
|
{
|
|
|
|
number = 0;
|
2004-05-16 12:58:04 +02:00
|
|
|
source = Source;
|
2004-03-28 09:20:02 +02:00
|
|
|
transponder = *Value;
|
|
|
|
cChannel *channel = Channels.First();
|
|
|
|
while (channel) {
|
2004-05-16 12:58:04 +02:00
|
|
|
if (!channel->GroupSep() && *source == channel->Source() && ISTRANSPONDER(channel->Transponder(), *Value)) {
|
2004-03-28 09:20:02 +02:00
|
|
|
number = channel->Number();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
channel = (cChannel *)channel->Next();
|
|
|
|
}
|
|
|
|
*Value = number;
|
|
|
|
Set();
|
|
|
|
*Value = transponder;
|
|
|
|
}
|
|
|
|
|
|
|
|
eOSState cMenuEditTranItem::ProcessKey(eKeys Key)
|
|
|
|
{
|
|
|
|
*value = number;
|
|
|
|
eOSState state = cMenuEditChanItem::ProcessKey(Key);
|
|
|
|
number = *value;
|
|
|
|
cChannel *channel = Channels.GetByNumber(*value);
|
2004-05-16 12:58:04 +02:00
|
|
|
if (channel) {
|
|
|
|
*source = channel->Source();
|
|
|
|
transponder = channel->Transponder();
|
|
|
|
}
|
2004-03-28 09:20:02 +02:00
|
|
|
*value = transponder;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2005-03-19 15:38:43 +01:00
|
|
|
// --- cMenuEditDateItem -----------------------------------------------------
|
2004-03-28 09:20:02 +02:00
|
|
|
|
2005-03-19 15:38:43 +01:00
|
|
|
static int ParseWeekDays(const char *s)
|
2004-03-28 09:20:02 +02:00
|
|
|
{
|
2005-03-19 15:38:43 +01:00
|
|
|
time_t day;
|
|
|
|
int weekdays;
|
|
|
|
return cTimer::ParseDay(s, day, weekdays) ? weekdays : 0;
|
2004-03-28 09:20:02 +02:00
|
|
|
}
|
|
|
|
|
2005-03-19 15:38:43 +01:00
|
|
|
int cMenuEditDateItem::days[] = { ParseWeekDays("M------"),
|
|
|
|
ParseWeekDays("-T-----"),
|
|
|
|
ParseWeekDays("--W----"),
|
|
|
|
ParseWeekDays("---T---"),
|
|
|
|
ParseWeekDays("----F--"),
|
|
|
|
ParseWeekDays("-----S-"),
|
|
|
|
ParseWeekDays("------S"),
|
|
|
|
ParseWeekDays("MTWTF--"),
|
|
|
|
ParseWeekDays("MTWTFS-"),
|
|
|
|
ParseWeekDays("MTWTFSS"),
|
|
|
|
ParseWeekDays("-----SS"),
|
|
|
|
0 };
|
2004-03-28 09:20:02 +02:00
|
|
|
|
2005-03-19 15:38:43 +01:00
|
|
|
cMenuEditDateItem::cMenuEditDateItem(const char *Name, time_t *Value, int *WeekDays)
|
2004-03-28 09:20:02 +02:00
|
|
|
:cMenuEditItem(Name)
|
|
|
|
{
|
|
|
|
value = Value;
|
2005-03-19 15:38:43 +01:00
|
|
|
weekdays = WeekDays;
|
|
|
|
oldvalue = 0;
|
2005-11-11 13:31:02 +01:00
|
|
|
dayindex = weekdays ? FindDayIndex(*weekdays) : 0;
|
2004-03-28 09:20:02 +02:00
|
|
|
Set();
|
|
|
|
}
|
|
|
|
|
2005-11-11 13:31:02 +01:00
|
|
|
int cMenuEditDateItem::FindDayIndex(int WeekDays)
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < sizeof(days) / sizeof(int); i++)
|
|
|
|
if (WeekDays == days[i])
|
|
|
|
return i;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-03-28 09:20:02 +02:00
|
|
|
void cMenuEditDateItem::Set(void)
|
|
|
|
{
|
|
|
|
#define DATEBUFFERSIZE 32
|
|
|
|
char buf[DATEBUFFERSIZE];
|
2005-03-19 15:38:43 +01:00
|
|
|
if (weekdays && *weekdays) {
|
|
|
|
SetValue(cTimer::PrintDay(0, *weekdays));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (*value) {
|
2004-03-28 09:20:02 +02:00
|
|
|
struct tm tm_r;
|
|
|
|
localtime_r(value, &tm_r);
|
|
|
|
strftime(buf, DATEBUFFERSIZE, "%Y-%m-%d ", &tm_r);
|
|
|
|
strcat(buf, WeekDayName(tm_r.tm_wday));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*buf = 0;
|
|
|
|
SetValue(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
eOSState cMenuEditDateItem::ProcessKey(eKeys Key)
|
|
|
|
{
|
|
|
|
eOSState state = cMenuEditItem::ProcessKey(Key);
|
|
|
|
|
|
|
|
if (state == osUnknown) {
|
2005-03-19 15:38:43 +01:00
|
|
|
time_t now = time(NULL);
|
2004-03-28 09:20:02 +02:00
|
|
|
if (NORMALKEY(Key) == kLeft) { // TODO might want to increase the delta if repeated quickly?
|
2005-03-19 15:38:43 +01:00
|
|
|
if (!weekdays || !*weekdays) {
|
|
|
|
// Decrement single day:
|
|
|
|
time_t v = *value;
|
|
|
|
v -= SECSINDAY;
|
|
|
|
if (v < now) {
|
|
|
|
if (now <= v + SECSINDAY) { // switched from tomorrow to today
|
|
|
|
if (!weekdays)
|
|
|
|
v = 0;
|
|
|
|
}
|
|
|
|
else if (weekdays) { // switched from today to yesterday, so enter weekdays mode
|
|
|
|
v = 0;
|
|
|
|
dayindex = sizeof(days) / sizeof(int) - 2;
|
|
|
|
*weekdays = days[dayindex];
|
|
|
|
}
|
|
|
|
else // don't go before today
|
|
|
|
v = *value;
|
|
|
|
}
|
|
|
|
*value = v;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Decrement weekday index:
|
|
|
|
if (dayindex > 0)
|
|
|
|
*weekdays = days[--dayindex];
|
|
|
|
}
|
2004-03-28 09:20:02 +02:00
|
|
|
}
|
|
|
|
else if (NORMALKEY(Key) == kRight) {
|
2005-03-19 15:38:43 +01:00
|
|
|
if (!weekdays || !*weekdays) {
|
|
|
|
// Increment single day:
|
|
|
|
if (!*value)
|
|
|
|
*value = cTimer::SetTime(now, 0);
|
|
|
|
*value += SECSINDAY;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Increment weekday index:
|
|
|
|
*weekdays = days[++dayindex];
|
|
|
|
if (!*weekdays) { // was last weekday entry, so switch to today
|
|
|
|
*value = cTimer::SetTime(now, 0);
|
|
|
|
dayindex = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (weekdays) {
|
|
|
|
if (Key == k0) {
|
|
|
|
// Toggle between weekdays and single day:
|
|
|
|
if (*weekdays) {
|
|
|
|
*value = cTimer::SetTime(oldvalue ? oldvalue : now, 0);
|
|
|
|
oldvalue = 0;
|
|
|
|
*weekdays = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*weekdays = days[cTimer::GetWDay(*value)];
|
2006-01-07 11:24:08 +01:00
|
|
|
dayindex = FindDayIndex(*weekdays);
|
2005-03-19 15:38:43 +01:00
|
|
|
oldvalue = *value;
|
|
|
|
*value = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (k1 <= Key && Key <= k7) {
|
|
|
|
// Toggle individual weekdays:
|
|
|
|
if (*weekdays) {
|
|
|
|
int v = *weekdays ^ (1 << (Key - k1));
|
|
|
|
if (v != 0)
|
|
|
|
*weekdays = v; // can't let this become all 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return state;
|
2004-03-28 09:20:02 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return state;
|
|
|
|
Set();
|
|
|
|
state = osContinue;
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- cMenuEditTimeItem -----------------------------------------------------
|
|
|
|
|
|
|
|
cMenuEditTimeItem::cMenuEditTimeItem(const char *Name, int *Value)
|
|
|
|
:cMenuEditItem(Name)
|
|
|
|
{
|
|
|
|
value = Value;
|
|
|
|
hh = *value / 100;
|
|
|
|
mm = *value % 100;
|
|
|
|
pos = 0;
|
|
|
|
Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditTimeItem::Set(void)
|
|
|
|
{
|
|
|
|
char buf[10];
|
|
|
|
switch (pos) {
|
|
|
|
case 1: snprintf(buf, sizeof(buf), "%01d-:--", hh / 10); break;
|
|
|
|
case 2: snprintf(buf, sizeof(buf), "%02d:--", hh); break;
|
|
|
|
case 3: snprintf(buf, sizeof(buf), "%02d:%01d-", hh, mm / 10); break;
|
|
|
|
default: snprintf(buf, sizeof(buf), "%02d:%02d", hh, mm);
|
|
|
|
}
|
|
|
|
SetValue(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
eOSState cMenuEditTimeItem::ProcessKey(eKeys Key)
|
|
|
|
{
|
|
|
|
eOSState state = cMenuEditItem::ProcessKey(Key);
|
|
|
|
|
|
|
|
if (state == osUnknown) {
|
|
|
|
if (k0 <= Key && Key <= k9) {
|
|
|
|
if (fresh || pos > 3) {
|
|
|
|
pos = 0;
|
|
|
|
fresh = false;
|
|
|
|
}
|
|
|
|
int n = Key - k0;
|
|
|
|
switch (pos) {
|
|
|
|
case 0: if (n <= 2) {
|
|
|
|
hh = n * 10;
|
|
|
|
mm = 0;
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1: if (hh + n <= 23) {
|
|
|
|
hh += n;
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2: if (n <= 5) {
|
|
|
|
mm += n * 10;
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3: if (mm + n <= 59) {
|
|
|
|
mm += n;
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (NORMALKEY(Key) == kLeft) { // TODO might want to increase the delta if repeated quickly?
|
|
|
|
if (--mm < 0) {
|
|
|
|
mm = 59;
|
|
|
|
if (--hh < 0)
|
|
|
|
hh = 23;
|
|
|
|
}
|
|
|
|
fresh = true;
|
|
|
|
}
|
|
|
|
else if (NORMALKEY(Key) == kRight) {
|
|
|
|
if (++mm > 59) {
|
|
|
|
mm = 0;
|
|
|
|
if (++hh > 23)
|
|
|
|
hh = 0;
|
|
|
|
}
|
|
|
|
fresh = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return state;
|
|
|
|
*value = hh * 100 + mm;
|
|
|
|
Set();
|
|
|
|
state = osContinue;
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2002-05-09 16:26:56 +02:00
|
|
|
// --- cMenuSetupPage --------------------------------------------------------
|
|
|
|
|
|
|
|
cMenuSetupPage::cMenuSetupPage(void)
|
|
|
|
:cOsdMenu("", 33)
|
|
|
|
{
|
2002-05-11 13:44:58 +02:00
|
|
|
plugin = NULL;
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
|
2002-05-11 13:44:58 +02:00
|
|
|
void cMenuSetupPage::SetSection(const char *Section)
|
2002-05-09 16:26:56 +02:00
|
|
|
{
|
2002-05-11 13:44:58 +02:00
|
|
|
char buf[40];
|
|
|
|
snprintf(buf, sizeof(buf), "%s - %s", tr("Setup"), Section);
|
2002-05-09 16:26:56 +02:00
|
|
|
SetTitle(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
eOSState cMenuSetupPage::ProcessKey(eKeys Key)
|
|
|
|
{
|
|
|
|
eOSState state = cOsdMenu::ProcessKey(Key);
|
|
|
|
|
|
|
|
if (state == osUnknown) {
|
|
|
|
switch (Key) {
|
2002-05-11 13:44:58 +02:00
|
|
|
case kOk: Store();
|
|
|
|
state = osBack;
|
2002-05-09 16:26:56 +02:00
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
2002-05-11 13:44:58 +02:00
|
|
|
|
|
|
|
void cMenuSetupPage::SetPlugin(cPlugin *Plugin)
|
|
|
|
{
|
|
|
|
plugin = Plugin;
|
|
|
|
char buf[40];
|
|
|
|
snprintf(buf, sizeof(buf), "%s '%s'", tr("Plugin"), plugin->Name());
|
|
|
|
SetSection(buf);
|
|
|
|
}
|
|
|
|
|
2002-05-18 08:57:42 +02:00
|
|
|
void cMenuSetupPage::SetupStore(const char *Name, const char *Value)
|
2002-05-11 13:44:58 +02:00
|
|
|
{
|
|
|
|
if (plugin)
|
|
|
|
plugin->SetupStore(Name, Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuSetupPage::SetupStore(const char *Name, int Value)
|
|
|
|
{
|
|
|
|
if (plugin)
|
|
|
|
plugin->SetupStore(Name, Value);
|
|
|
|
}
|