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.
|
|
|
|
*
|
2012-03-13 11:27:54 +01:00
|
|
|
* $Id: menuitems.c 2.13 2012/03/13 11:21:57 kls Exp $
|
2002-05-09 16:26:56 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "menuitems.h"
|
|
|
|
#include <ctype.h>
|
2009-05-03 14:15:21 +02:00
|
|
|
#include <math.h>
|
2007-06-10 13:02:43 +02:00
|
|
|
#include <wctype.h>
|
2002-05-09 16:26:56 +02:00
|
|
|
#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
|
|
|
|
|
2007-10-21 12:32:51 +02:00
|
|
|
const char *FileNameChars = trNOOP("FileNameChars$ abcdefghijklmnopqrstuvwxyz0123456789-.,#~\\^$[]|()*+?{}/:%@&");
|
2002-08-15 11:28:26 +02:00
|
|
|
|
2002-05-09 16:26:56 +02:00
|
|
|
// --- cMenuEditItem ---------------------------------------------------------
|
|
|
|
|
|
|
|
cMenuEditItem::cMenuEditItem(const char *Name)
|
|
|
|
{
|
2006-04-14 10:00:44 +02:00
|
|
|
name = strdup(Name ? Name : "???");
|
2012-03-02 15:49:57 +01:00
|
|
|
SetHelp(NULL);
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cMenuEditItem::~cMenuEditItem()
|
|
|
|
{
|
2002-08-11 13:32:23 +02:00
|
|
|
free(name);
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditItem::SetValue(const char *Value)
|
|
|
|
{
|
2008-02-15 14:57:48 +01:00
|
|
|
cString buffer = cString::sprintf("%s:\t%s", name, Value);
|
|
|
|
SetText(buffer);
|
2004-01-25 15:43:11 +01:00
|
|
|
cStatus::MsgOsdCurrentItem(buffer);
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
|
2012-03-02 15:49:57 +01:00
|
|
|
void cMenuEditItem::SetHelp(const char *Red, const char *Green, const char *Yellow, const char *Blue)
|
|
|
|
{
|
|
|
|
// strings are NOT copied - must be constants!!!
|
|
|
|
helpRed = Red;
|
|
|
|
helpGreen = Green;
|
|
|
|
helpYellow = Yellow;
|
|
|
|
helpBlue = Blue;
|
|
|
|
helpDisplayed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cMenuEditItem::DisplayHelp(void)
|
|
|
|
{
|
|
|
|
bool HasHelp = helpRed || helpGreen || helpYellow || helpBlue;
|
|
|
|
if (HasHelp && !helpDisplayed) {
|
|
|
|
cSkinDisplay::Current()->SetButtons(helpRed, helpGreen, helpYellow, helpBlue);
|
|
|
|
cStatus::MsgOsdHelpKeys(helpRed, helpGreen, helpYellow, helpBlue);
|
|
|
|
helpDisplayed = true;
|
|
|
|
}
|
|
|
|
return HasHelp;
|
|
|
|
}
|
|
|
|
|
2002-05-09 16:26:56 +02:00
|
|
|
// --- cMenuEditIntItem ------------------------------------------------------
|
|
|
|
|
2006-04-09 12:05:05 +02:00
|
|
|
cMenuEditIntItem::cMenuEditIntItem(const char *Name, int *Value, int Min, int Max, const char *MinString, const char *MaxString)
|
2002-05-09 16:26:56 +02:00
|
|
|
:cMenuEditItem(Name)
|
|
|
|
{
|
|
|
|
value = Value;
|
|
|
|
min = Min;
|
|
|
|
max = Max;
|
2006-04-09 12:05:05 +02:00
|
|
|
minString = MinString;
|
|
|
|
maxString = MaxString;
|
2006-02-28 12:54:38 +01:00
|
|
|
if (*value < min)
|
|
|
|
*value = min;
|
|
|
|
else if (*value > max)
|
|
|
|
*value = max;
|
2002-05-09 16:26:56 +02:00
|
|
|
Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditIntItem::Set(void)
|
|
|
|
{
|
2006-04-09 12:05:05 +02:00
|
|
|
if (minString && *value == min)
|
|
|
|
SetValue(minString);
|
|
|
|
else if (maxString && *value == max)
|
|
|
|
SetValue(maxString);
|
|
|
|
else {
|
|
|
|
char buf[16];
|
|
|
|
snprintf(buf, sizeof(buf), "%d", *value);
|
|
|
|
SetValue(buf);
|
|
|
|
}
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
eOSState cMenuEditIntItem::ProcessKey(eKeys Key)
|
|
|
|
{
|
|
|
|
eOSState state = cMenuEditItem::ProcessKey(Key);
|
|
|
|
|
|
|
|
if (state == osUnknown) {
|
2003-04-12 09:24:48 +02:00
|
|
|
int newValue = *value;
|
2006-07-23 09:48:51 +02:00
|
|
|
bool IsRepeat = Key & k_Repeat;
|
2003-04-12 09:24:48 +02:00
|
|
|
Key = NORMALKEY(Key);
|
|
|
|
switch (Key) {
|
|
|
|
case kNone: break;
|
|
|
|
case k0 ... k9:
|
|
|
|
if (fresh) {
|
2006-04-25 16:04:55 +02:00
|
|
|
newValue = 0;
|
2003-04-12 09:24:48 +02:00
|
|
|
fresh = false;
|
|
|
|
}
|
2006-04-25 16:04:55 +02:00
|
|
|
newValue = newValue * 10 + (Key - k0);
|
2003-04-12 09:24:48 +02:00
|
|
|
break;
|
|
|
|
case kLeft: // TODO might want to increase the delta if repeated quickly?
|
|
|
|
newValue = *value - 1;
|
|
|
|
fresh = true;
|
2006-07-23 09:48:51 +02:00
|
|
|
if (!IsRepeat && newValue < min && max != INT_MAX)
|
|
|
|
newValue = max;
|
2003-04-12 09:24:48 +02:00
|
|
|
break;
|
|
|
|
case kRight:
|
|
|
|
newValue = *value + 1;
|
|
|
|
fresh = true;
|
2006-07-23 09:48:51 +02:00
|
|
|
if (!IsRepeat && newValue > max && min != INT_MIN)
|
|
|
|
newValue = min;
|
2003-04-12 09:24:48 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (*value < min) { *value = min; Set(); }
|
|
|
|
if (*value > max) { *value = max; Set(); }
|
|
|
|
return state;
|
|
|
|
}
|
2006-04-14 10:40:12 +02:00
|
|
|
if (newValue != *value && (!fresh || min <= newValue) && newValue <= max) {
|
2002-05-09 16:26:56 +02:00
|
|
|
*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;
|
|
|
|
}
|
|
|
|
|
2009-05-03 14:15:21 +02:00
|
|
|
// --- cMenuEditPrcItem ------------------------------------------------------
|
|
|
|
|
|
|
|
cMenuEditPrcItem::cMenuEditPrcItem(const char *Name, double *Value, double Min, double Max, int Decimals)
|
|
|
|
:cMenuEditItem(Name)
|
|
|
|
{
|
|
|
|
value = Value;
|
|
|
|
min = Min;
|
|
|
|
max = Max;
|
|
|
|
decimals = Decimals;
|
|
|
|
factor = 100;
|
|
|
|
while (Decimals-- > 0)
|
|
|
|
factor *= 10;
|
|
|
|
if (*value < min)
|
|
|
|
*value = min;
|
|
|
|
else if (*value > max)
|
|
|
|
*value = max;
|
|
|
|
Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditPrcItem::Set(void)
|
|
|
|
{
|
|
|
|
char buf[16];
|
|
|
|
snprintf(buf, sizeof(buf), "%.*f", decimals, *value * 100);
|
|
|
|
SetValue(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
eOSState cMenuEditPrcItem::ProcessKey(eKeys Key)
|
|
|
|
{
|
|
|
|
eOSState state = cMenuEditItem::ProcessKey(Key);
|
|
|
|
|
|
|
|
if (state == osUnknown) {
|
|
|
|
double newValue = round(*value * factor); // avoids precision problems
|
|
|
|
Key = NORMALKEY(Key);
|
|
|
|
switch (Key) {
|
|
|
|
case kNone: break;
|
|
|
|
case k0 ... k9:
|
|
|
|
if (fresh) {
|
|
|
|
newValue = 0;
|
|
|
|
fresh = false;
|
|
|
|
}
|
|
|
|
newValue = newValue * 10 + (Key - k0);
|
|
|
|
break;
|
|
|
|
case kLeft: // TODO might want to increase the delta if repeated quickly?
|
|
|
|
newValue--;
|
|
|
|
fresh = true;
|
|
|
|
break;
|
|
|
|
case kRight:
|
|
|
|
newValue++;
|
|
|
|
fresh = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (*value < min) { *value = min; Set(); }
|
|
|
|
if (*value > max) { *value = max; Set(); }
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
newValue /= factor;
|
2009-12-06 12:57:45 +01:00
|
|
|
if (!DoubleEqual(newValue, *value) && (!fresh || min <= newValue) && newValue <= max) {
|
2009-05-03 14:15:21 +02:00
|
|
|
*value = newValue;
|
|
|
|
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;
|
2006-04-14 10:00:44 +02:00
|
|
|
allowed = strdup(Allowed ? Allowed : "");
|
2002-05-09 16:26:56 +02:00
|
|
|
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];
|
2007-08-17 13:50:20 +02:00
|
|
|
buf[0] = *value;
|
|
|
|
buf[1] = '\0';
|
2002-05-09 16:26:56 +02:00
|
|
|
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;
|
2007-11-03 15:06:00 +01:00
|
|
|
allowed = Allowed ? Allowed : tr(FileNameChars);
|
2002-05-09 16:26:56 +02:00
|
|
|
pos = -1;
|
2007-06-10 13:02:43 +02:00
|
|
|
offset = 0;
|
2002-05-09 16:26:56 +02:00
|
|
|
insert = uppercase = false;
|
|
|
|
newchar = true;
|
2007-06-10 13:02:43 +02:00
|
|
|
lengthUtf8 = 0;
|
|
|
|
valueUtf8 = NULL;
|
|
|
|
allowedUtf8 = NULL;
|
|
|
|
charMapUtf8 = NULL;
|
|
|
|
currentCharUtf8 = NULL;
|
2006-01-06 16:57:41 +01:00
|
|
|
lastKey = kNone;
|
2002-05-09 16:26:56 +02:00
|
|
|
Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
cMenuEditStrItem::~cMenuEditStrItem()
|
|
|
|
{
|
2009-04-05 10:15:12 +02:00
|
|
|
delete[] valueUtf8;
|
|
|
|
delete[] allowedUtf8;
|
|
|
|
delete[] charMapUtf8;
|
2007-06-10 13:02:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditStrItem::EnterEditMode(void)
|
|
|
|
{
|
|
|
|
if (!valueUtf8) {
|
|
|
|
valueUtf8 = new uint[length];
|
|
|
|
lengthUtf8 = Utf8ToArray(value, valueUtf8, length);
|
|
|
|
int l = strlen(allowed) + 1;
|
|
|
|
allowedUtf8 = new uint[l];
|
|
|
|
Utf8ToArray(allowed, allowedUtf8, l);
|
2007-10-21 12:32:51 +02:00
|
|
|
const char *charMap = tr("CharMap$ 0\t-.,1#~\\^$[]|()*+?{}/:%@&\tabc2\tdef3\tghi4\tjkl5\tmno6\tpqrs7\ttuv8\twxyz9");
|
2007-06-10 13:02:43 +02:00
|
|
|
l = strlen(charMap) + 1;
|
|
|
|
charMapUtf8 = new uint[l];
|
|
|
|
Utf8ToArray(charMap, charMapUtf8, l);
|
|
|
|
currentCharUtf8 = charMapUtf8;
|
|
|
|
AdvancePos();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditStrItem::LeaveEditMode(bool SaveValue)
|
|
|
|
{
|
|
|
|
if (valueUtf8) {
|
|
|
|
if (SaveValue) {
|
|
|
|
Utf8FromArray(valueUtf8, value, length);
|
|
|
|
stripspace(value);
|
|
|
|
}
|
|
|
|
lengthUtf8 = 0;
|
2007-10-13 12:07:27 +02:00
|
|
|
delete[] valueUtf8;
|
2007-06-10 13:02:43 +02:00
|
|
|
valueUtf8 = NULL;
|
2007-10-13 12:07:27 +02:00
|
|
|
delete[] allowedUtf8;
|
2007-06-10 13:02:43 +02:00
|
|
|
allowedUtf8 = NULL;
|
2007-10-13 12:07:27 +02:00
|
|
|
delete[] charMapUtf8;
|
2007-06-10 13:02:43 +02:00
|
|
|
charMapUtf8 = NULL;
|
|
|
|
pos = -1;
|
|
|
|
offset = 0;
|
|
|
|
newchar = true;
|
|
|
|
}
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditStrItem::SetHelpKeys(void)
|
|
|
|
{
|
2006-01-03 12:50:58 +01:00
|
|
|
if (InEditMode())
|
2012-03-02 15:49:57 +01:00
|
|
|
SetHelp(tr("Button$ABC/abc"), insert ? tr("Button$Overwrite") : tr("Button$Insert"), tr("Button$Delete"));
|
2002-05-09 16:26:56 +02:00
|
|
|
else
|
2012-03-02 15:49:57 +01:00
|
|
|
SetHelp(NULL);
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
|
2007-06-10 13:02:43 +02:00
|
|
|
uint *cMenuEditStrItem::IsAllowed(uint c)
|
|
|
|
{
|
|
|
|
if (allowedUtf8) {
|
|
|
|
for (uint *a = allowedUtf8; *a; a++) {
|
|
|
|
if (c == *a)
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-01-21 12:27:14 +01:00
|
|
|
void cMenuEditStrItem::AdvancePos(void)
|
|
|
|
{
|
2007-06-10 13:02:43 +02:00
|
|
|
if (pos < length - 2 && pos < lengthUtf8) {
|
|
|
|
if (++pos >= lengthUtf8) {
|
|
|
|
if (pos >= 2 && valueUtf8[pos - 1] == ' ' && valueUtf8[pos - 2] == ' ')
|
2006-01-21 12:27:14 +01:00
|
|
|
pos--; // allow only two blanks at the end
|
|
|
|
else {
|
2007-06-10 13:02:43 +02:00
|
|
|
valueUtf8[pos] = ' ';
|
|
|
|
valueUtf8[pos + 1] = 0;
|
|
|
|
lengthUtf8++;
|
2006-01-21 12:27:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
newchar = true;
|
2007-06-10 13:02:43 +02:00
|
|
|
if (!insert && Utf8is(alpha, valueUtf8[pos]))
|
|
|
|
uppercase = Utf8is(upper, valueUtf8[pos]);
|
2006-01-21 12:27:14 +01:00
|
|
|
}
|
|
|
|
|
2002-05-09 16:26:56 +02:00
|
|
|
void cMenuEditStrItem::Set(void)
|
|
|
|
{
|
2006-01-03 12:50:58 +01:00
|
|
|
if (InEditMode()) {
|
2006-06-03 13:21:33 +02:00
|
|
|
// This is an ugly hack to make editing strings work with the 'skincurses' plugin.
|
|
|
|
const cFont *font = dynamic_cast<cSkinDisplayMenu *>(cSkinDisplay::Current())->GetTextAreaFont(false);
|
|
|
|
if (!font || font->Width("W") != 1) // all characters have with == 1 in the font used by 'skincurses'
|
|
|
|
font = cFont::GetFont(fontOsd);
|
2007-06-10 13:02:43 +02:00
|
|
|
|
2004-05-16 10:35:36 +02:00
|
|
|
int width = cSkinDisplay::Current()->EditableWidth();
|
2007-06-10 13:02:43 +02:00
|
|
|
width -= font->Width("[]");
|
|
|
|
width -= font->Width("<>"); // reserving this anyway make the whole thing simpler
|
|
|
|
|
|
|
|
if (pos < offset)
|
|
|
|
offset = pos;
|
|
|
|
int WidthFromOffset = 0;
|
|
|
|
int EndPos = lengthUtf8;
|
|
|
|
for (int i = offset; i < lengthUtf8; i++) {
|
|
|
|
WidthFromOffset += font->Width(valueUtf8[i]);
|
|
|
|
if (WidthFromOffset > width) {
|
|
|
|
if (pos >= i) {
|
|
|
|
do {
|
|
|
|
WidthFromOffset -= font->Width(valueUtf8[offset]);
|
|
|
|
offset++;
|
|
|
|
} while (WidthFromOffset > width && offset < pos);
|
|
|
|
EndPos = pos + 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
EndPos = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char buf[1000];
|
|
|
|
char *p = buf;
|
|
|
|
if (offset)
|
|
|
|
*p++ = '<';
|
|
|
|
p += Utf8FromArray(valueUtf8 + offset, p, sizeof(buf) - (p - buf), pos - offset);
|
|
|
|
*p++ = '[';
|
|
|
|
if (insert && newchar)
|
|
|
|
*p++ = ']';
|
|
|
|
p += Utf8FromArray(&valueUtf8[pos], p, sizeof(buf) - (p - buf), 1);
|
|
|
|
if (!(insert && newchar))
|
|
|
|
*p++ = ']';
|
|
|
|
p += Utf8FromArray(&valueUtf8[pos + 1], p, sizeof(buf) - (p - buf), EndPos - pos - 1);
|
|
|
|
if (EndPos != lengthUtf8)
|
|
|
|
*p++ = '>';
|
|
|
|
*p = 0;
|
|
|
|
|
|
|
|
SetValue(buf);
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
SetValue(value);
|
|
|
|
}
|
|
|
|
|
2007-06-10 13:02:43 +02:00
|
|
|
uint cMenuEditStrItem::Inc(uint c, bool Up)
|
2002-05-09 16:26:56 +02:00
|
|
|
{
|
2007-06-10 13:02:43 +02:00
|
|
|
uint *p = IsAllowed(c);
|
2002-05-09 16:26:56 +02:00
|
|
|
if (!p)
|
2007-06-10 13:02:43 +02:00
|
|
|
p = allowedUtf8;
|
2002-05-09 16:26:56 +02:00
|
|
|
if (Up) {
|
|
|
|
if (!*++p)
|
2007-06-10 13:02:43 +02:00
|
|
|
p = allowedUtf8;
|
|
|
|
}
|
|
|
|
else if (--p < allowedUtf8) {
|
|
|
|
p = allowedUtf8;
|
|
|
|
while (*p && *(p + 1))
|
|
|
|
p++;
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
return *p;
|
|
|
|
}
|
|
|
|
|
2010-06-06 10:56:11 +02:00
|
|
|
void cMenuEditStrItem::Type(uint c)
|
|
|
|
{
|
|
|
|
if (insert && lengthUtf8 < length - 1)
|
|
|
|
Insert();
|
|
|
|
valueUtf8[pos] = c;
|
|
|
|
if (pos < length - 2)
|
|
|
|
pos++;
|
|
|
|
if (pos >= lengthUtf8) {
|
|
|
|
valueUtf8[pos] = ' ';
|
|
|
|
valueUtf8[pos + 1] = 0;
|
|
|
|
lengthUtf8 = pos + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-10 13:02:43 +02:00
|
|
|
void cMenuEditStrItem::Insert(void)
|
|
|
|
{
|
|
|
|
memmove(valueUtf8 + pos + 1, valueUtf8 + pos, (lengthUtf8 - pos + 1) * sizeof(*valueUtf8));
|
|
|
|
lengthUtf8++;
|
|
|
|
valueUtf8[pos] = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditStrItem::Delete(void)
|
|
|
|
{
|
|
|
|
memmove(valueUtf8 + pos, valueUtf8 + pos + 1, (lengthUtf8 - pos) * sizeof(*valueUtf8));
|
|
|
|
lengthUtf8--;
|
|
|
|
}
|
|
|
|
|
2002-05-09 16:26:56 +02:00
|
|
|
eOSState cMenuEditStrItem::ProcessKey(eKeys Key)
|
|
|
|
{
|
2006-04-23 11:43:54 +02:00
|
|
|
bool SameKey = NORMALKEY(Key) == lastKey;
|
2006-01-06 16:57:41 +01:00
|
|
|
if (Key != kNone)
|
2006-04-23 11:43:54 +02:00
|
|
|
lastKey = NORMALKEY(Key);
|
|
|
|
else if (!newchar && k0 <= lastKey && lastKey <= k9 && autoAdvanceTimeout.TimedOut()) {
|
2006-01-21 12:27:14 +01:00
|
|
|
AdvancePos();
|
|
|
|
newchar = true;
|
2007-06-10 13:02:43 +02:00
|
|
|
currentCharUtf8 = NULL;
|
2006-01-21 12:27:14 +01:00
|
|
|
Set();
|
|
|
|
return osContinue;
|
|
|
|
}
|
2010-12-12 13:42:00 +01:00
|
|
|
switch (int(Key)) {
|
2002-05-09 16:26:56 +02:00
|
|
|
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;
|
2007-06-10 13:02:43 +02:00
|
|
|
valueUtf8[pos] = uppercase ? Utf8to(upper, valueUtf8[pos]) : Utf8to(lower, valueUtf8[pos]);
|
2005-09-17 09:42:45 +02:00
|
|
|
}
|
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:
|
2007-06-10 13:02:43 +02:00
|
|
|
case kYellow: // Remove the character at the current position; in insert mode it is the character to the right of the cursor
|
2006-01-03 12:50:58 +01:00
|
|
|
if (InEditMode()) {
|
2007-06-10 13:02:43 +02:00
|
|
|
if (lengthUtf8 > 1) {
|
|
|
|
if (!insert || pos < lengthUtf8 - 1)
|
|
|
|
Delete();
|
|
|
|
else if (insert && pos == lengthUtf8 - 1)
|
|
|
|
valueUtf8[pos] = ' '; // in insert mode, deleting the last character replaces it with a blank to keep the cursor position
|
2002-05-09 16:26:56 +02:00
|
|
|
// reduce position, if we removed the last character
|
2007-06-10 13:02:43 +02:00
|
|
|
if (pos == lengthUtf8)
|
2002-05-09 16:26:56 +02:00
|
|
|
pos--;
|
|
|
|
}
|
2007-06-10 13:02:43 +02:00
|
|
|
else if (lengthUtf8 == 1)
|
|
|
|
valueUtf8[0] = ' '; // This is the last character in the string, replace it with a blank
|
|
|
|
if (Utf8is(alpha, valueUtf8[pos]))
|
|
|
|
uppercase = Utf8is(upper, valueUtf8[pos]);
|
2002-05-09 16:26:56 +02:00
|
|
|
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
|
2007-08-17 13:50:20 +02:00
|
|
|
if (!InEditMode())
|
2005-09-17 09:42:45 +02:00
|
|
|
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;
|
2007-10-13 10:41:37 +02:00
|
|
|
if (!insert && Utf8is(alpha, valueUtf8[pos]))
|
|
|
|
uppercase = Utf8is(upper, valueUtf8[pos]);
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case kRight|k_Repeat:
|
2007-06-10 13:02:43 +02:00
|
|
|
case kRight: if (InEditMode())
|
|
|
|
AdvancePos();
|
|
|
|
else {
|
|
|
|
EnterEditMode();
|
2002-05-09 16:26:56 +02:00
|
|
|
SetHelpKeys();
|
2006-02-12 10:35:10 +01:00
|
|
|
}
|
2002-05-09 16:26:56 +02:00
|
|
|
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
|
2007-06-10 13:02:43 +02:00
|
|
|
if (lengthUtf8 < length - 1)
|
|
|
|
Insert();
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
if (uppercase)
|
2007-06-10 13:02:43 +02:00
|
|
|
valueUtf8[pos] = Utf8to(upper, Inc(Utf8to(lower, valueUtf8[pos]), NORMALKEY(Key) == kUp));
|
2002-05-09 16:26:56 +02:00
|
|
|
else
|
2007-06-10 13:02:43 +02:00
|
|
|
valueUtf8[pos] = Inc( valueUtf8[pos], NORMALKEY(Key) == kUp);
|
2006-02-04 12:50:11 +01:00
|
|
|
newchar = false;
|
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()) {
|
2010-06-06 10:56:11 +02:00
|
|
|
if (Setup.NumberKeysForChars) {
|
|
|
|
if (!SameKey) {
|
|
|
|
if (!newchar)
|
|
|
|
AdvancePos();
|
|
|
|
currentCharUtf8 = NULL;
|
|
|
|
}
|
|
|
|
if (!currentCharUtf8 || !*currentCharUtf8 || *currentCharUtf8 == '\t') {
|
|
|
|
// find the beginning of the character map entry for Key
|
|
|
|
int n = NORMALKEY(Key) - k0;
|
|
|
|
currentCharUtf8 = charMapUtf8;
|
|
|
|
while (n > 0 && *currentCharUtf8) {
|
|
|
|
if (*currentCharUtf8++ == '\t')
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
// find first allowed character
|
|
|
|
while (*currentCharUtf8 && *currentCharUtf8 != '\t' && !IsAllowed(*currentCharUtf8))
|
|
|
|
currentCharUtf8++;
|
|
|
|
}
|
|
|
|
if (*currentCharUtf8 && *currentCharUtf8 != '\t') {
|
|
|
|
if (insert && newchar) {
|
|
|
|
// create a new character in insert mode
|
|
|
|
if (lengthUtf8 < length - 1)
|
|
|
|
Insert();
|
2006-01-06 16:57:41 +01:00
|
|
|
}
|
2010-06-06 10:56:11 +02:00
|
|
|
valueUtf8[pos] = *currentCharUtf8;
|
|
|
|
if (uppercase)
|
|
|
|
valueUtf8[pos] = Utf8to(upper, valueUtf8[pos]);
|
|
|
|
// find next allowed character
|
|
|
|
do {
|
2007-06-10 13:02:43 +02:00
|
|
|
currentCharUtf8++;
|
2010-06-06 10:56:11 +02:00
|
|
|
} while (*currentCharUtf8 && *currentCharUtf8 != '\t' && !IsAllowed(*currentCharUtf8));
|
|
|
|
newchar = false;
|
|
|
|
autoAdvanceTimeout.Set(AUTO_ADVANCE_TIMEOUT);
|
2007-01-04 13:38:40 +01:00
|
|
|
}
|
2006-01-06 16:57:41 +01:00
|
|
|
}
|
2010-06-06 10:56:11 +02:00
|
|
|
else
|
|
|
|
Type('0' + NORMALKEY(Key) - k0);
|
2006-01-06 16:57:41 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return cMenuEditItem::ProcessKey(Key);
|
|
|
|
}
|
|
|
|
break;
|
2006-02-12 10:35:10 +01:00
|
|
|
case kBack:
|
2006-01-03 12:50:58 +01:00
|
|
|
case kOk: if (InEditMode()) {
|
2007-06-10 13:02:43 +02:00
|
|
|
LeaveEditMode(Key == kOk);
|
2002-05-09 16:26:56 +02:00
|
|
|
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);
|
2007-06-10 13:02:43 +02:00
|
|
|
if (c <= 0xFF) { // FIXME what about other UTF-8 characters?
|
2010-06-06 10:56:11 +02:00
|
|
|
if (IsAllowed(Utf8to(lower, c)))
|
|
|
|
Type(c);
|
2002-12-15 10:58:00 +01:00
|
|
|
else {
|
|
|
|
switch (c) {
|
|
|
|
case 0x7F: // backspace
|
|
|
|
if (pos > 0) {
|
|
|
|
pos--;
|
|
|
|
return ProcessKey(kYellow);
|
|
|
|
}
|
|
|
|
break;
|
2009-12-06 12:57:45 +01:00
|
|
|
default: ;
|
2002-12-15 10:58:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (c) {
|
|
|
|
case kfHome: pos = 0; break;
|
2007-06-10 13:02:43 +02:00
|
|
|
case kfEnd: pos = lengthUtf8 - 1; break;
|
2002-12-15 10:58:00 +01:00
|
|
|
case kfIns: return ProcessKey(kGreen);
|
|
|
|
case kfDel: return ProcessKey(kYellow);
|
2009-12-06 12:57:45 +01:00
|
|
|
default: ;
|
2002-12-15 10:58:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 -----------------------------------------------------
|
|
|
|
|
2006-04-09 12:05:05 +02:00
|
|
|
cMenuEditChanItem::cMenuEditChanItem(const char *Name, int *Value, const char *NoneString)
|
|
|
|
:cMenuEditIntItem(Name, Value, NoneString ? 0 : 1, Channels.MaxNumber())
|
2004-03-28 09:20:02 +02:00
|
|
|
{
|
2011-06-13 14:48:41 +02:00
|
|
|
channelID = NULL;
|
2006-04-09 12:05:05 +02:00
|
|
|
noneString = NoneString;
|
2011-06-13 14:48:41 +02:00
|
|
|
dummyValue = 0;
|
|
|
|
Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
cMenuEditChanItem::cMenuEditChanItem(const char *Name, cString *ChannelID, const char *NoneString)
|
|
|
|
:cMenuEditIntItem(Name, &dummyValue, NoneString ? 0 : 1, Channels.MaxNumber())
|
|
|
|
{
|
|
|
|
channelID = ChannelID;
|
|
|
|
noneString = NoneString;
|
|
|
|
cChannel *channel = Channels.GetByChannelID(tChannelID::FromString(*ChannelID));
|
|
|
|
dummyValue = channel ? channel->Number() : 0;
|
2004-03-28 09:20:02 +02:00
|
|
|
Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditChanItem::Set(void)
|
|
|
|
{
|
2006-04-09 12:05:05 +02:00
|
|
|
if (*value > 0) {
|
|
|
|
char buf[255];
|
|
|
|
cChannel *channel = Channels.GetByNumber(*value);
|
|
|
|
snprintf(buf, sizeof(buf), "%d %s", *value, channel ? channel->Name() : "");
|
|
|
|
SetValue(buf);
|
2011-08-12 13:21:42 +02:00
|
|
|
if (channelID)
|
|
|
|
*channelID = channel->GetChannelID().ToString();
|
2006-04-09 12:05:05 +02:00
|
|
|
}
|
2011-08-12 13:21:42 +02:00
|
|
|
else if (noneString) {
|
2006-04-09 12:05:05 +02:00
|
|
|
SetValue(noneString);
|
2011-08-12 13:21:42 +02:00
|
|
|
if (channelID)
|
|
|
|
*channelID = "";
|
|
|
|
}
|
2004-03-28 09:20:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
eOSState cMenuEditChanItem::ProcessKey(eKeys Key)
|
|
|
|
{
|
|
|
|
int delta = 1;
|
|
|
|
|
2010-12-12 13:42:00 +01:00
|
|
|
switch (int(Key)) {
|
2004-03-28 09:20:02 +02:00
|
|
|
case kLeft|k_Repeat:
|
|
|
|
case kLeft: delta = -1;
|
|
|
|
case kRight|k_Repeat:
|
|
|
|
case kRight:
|
|
|
|
{
|
|
|
|
cChannel *channel = Channels.GetByNumber(*value + delta, delta);
|
2006-04-09 12:05:05 +02:00
|
|
|
if (channel)
|
2004-03-28 09:20:02 +02:00
|
|
|
*value = channel->Number();
|
2006-04-09 12:05:05 +02:00
|
|
|
else if (delta < 0 && noneString)
|
|
|
|
*value = 0;
|
2011-06-13 14:48:41 +02:00
|
|
|
if (channelID)
|
|
|
|
*channelID = channel ? channel->GetChannelID().ToString() : "";
|
2006-04-09 12:05:05 +02:00
|
|
|
Set();
|
2004-03-28 09:20:02 +02:00
|
|
|
}
|
|
|
|
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)
|
2006-04-14 10:26:46 +02:00
|
|
|
:cMenuEditChanItem(Name, &number, "-")
|
2004-03-28 09:20:02 +02:00
|
|
|
{
|
|
|
|
number = 0;
|
2004-05-16 12:58:04 +02:00
|
|
|
source = Source;
|
2006-04-01 09:12:38 +02:00
|
|
|
transponder = Value;
|
2004-03-28 09:20:02 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
eOSState cMenuEditTranItem::ProcessKey(eKeys Key)
|
|
|
|
{
|
|
|
|
eOSState state = cMenuEditChanItem::ProcessKey(Key);
|
2006-04-01 09:12:38 +02:00
|
|
|
cChannel *channel = Channels.GetByNumber(number);
|
2004-05-16 12:58:04 +02:00
|
|
|
if (channel) {
|
|
|
|
*source = channel->Source();
|
2006-04-01 09:12:38 +02:00
|
|
|
*transponder = channel->Transponder();
|
2004-05-16 12:58:04 +02:00
|
|
|
}
|
2006-04-14 10:41:28 +02:00
|
|
|
else {
|
|
|
|
*source = 0;
|
|
|
|
*transponder = 0;
|
|
|
|
}
|
2004-03-28 09:20:02 +02:00
|
|
|
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;
|
2012-03-13 11:27:54 +01:00
|
|
|
oldweekdays = 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) {
|
2007-06-10 13:02:43 +02:00
|
|
|
SetValue(cTimer::PrintDay(0, *weekdays, false));
|
2005-03-19 15:38:43 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-03-08 13:51:00 +01:00
|
|
|
void cMenuEditDateItem::ToggleRepeating(void)
|
|
|
|
{
|
|
|
|
if (weekdays) {
|
|
|
|
if (*weekdays) {
|
|
|
|
*value = cTimer::SetTime(oldvalue ? oldvalue : time(NULL), 0);
|
|
|
|
oldvalue = 0;
|
2012-03-13 11:27:54 +01:00
|
|
|
oldweekdays = *weekdays;
|
2012-03-08 13:51:00 +01:00
|
|
|
*weekdays = 0;
|
|
|
|
}
|
|
|
|
else {
|
2012-03-13 11:27:54 +01:00
|
|
|
*weekdays = oldweekdays ? oldweekdays : days[cTimer::GetWDay(*value)];
|
|
|
|
oldweekdays = 0;
|
2012-03-08 13:51:00 +01:00
|
|
|
dayindex = FindDayIndex(*weekdays);
|
|
|
|
oldvalue = *value;
|
|
|
|
*value = 0;
|
|
|
|
}
|
|
|
|
Set();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-28 09:20:02 +02:00
|
|
|
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:
|
2012-03-08 13:51:00 +01:00
|
|
|
ToggleRepeating();
|
|
|
|
return osContinue; // ToggleRepeating) has already called Set()
|
2005-03-19 15:38:43 +01:00
|
|
|
}
|
|
|
|
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;
|
2009-12-06 12:57:45 +01:00
|
|
|
default: ;
|
2004-03-28 09:20:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-04-12 13:39:12 +02:00
|
|
|
// --- cMenuEditMapItem ------------------------------------------------------
|
|
|
|
|
2010-02-28 12:19:50 +01:00
|
|
|
cMenuEditMapItem::cMenuEditMapItem(const char *Name, int *Value, const tDvbParameterMap *Map, const char *ZeroString)
|
2008-04-12 13:39:12 +02:00
|
|
|
:cMenuEditItem(Name)
|
|
|
|
{
|
|
|
|
value = Value;
|
|
|
|
map = Map;
|
|
|
|
zeroString = ZeroString;
|
|
|
|
Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cMenuEditMapItem::Set(void)
|
|
|
|
{
|
|
|
|
const char *s = NULL;
|
|
|
|
int n = MapToUser(*value, map, &s);
|
2008-12-13 12:22:36 +01:00
|
|
|
if (n == 0 && zeroString)
|
2008-04-12 13:39:12 +02:00
|
|
|
SetValue(zeroString);
|
|
|
|
else if (n >= 0) {
|
|
|
|
if (s)
|
|
|
|
SetValue(s);
|
|
|
|
else {
|
|
|
|
char buf[16];
|
|
|
|
snprintf(buf, sizeof(buf), "%d", n);
|
|
|
|
SetValue(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SetValue("???");
|
|
|
|
}
|
|
|
|
|
|
|
|
eOSState cMenuEditMapItem::ProcessKey(eKeys Key)
|
|
|
|
{
|
|
|
|
eOSState state = cMenuEditItem::ProcessKey(Key);
|
|
|
|
|
|
|
|
if (state == osUnknown) {
|
|
|
|
int newValue = *value;
|
|
|
|
int n = DriverIndex(*value, map);
|
|
|
|
if (NORMALKEY(Key) == kLeft) { // TODO might want to increase the delta if repeated quickly?
|
|
|
|
if (n-- > 0)
|
|
|
|
newValue = map[n].driverValue;
|
|
|
|
}
|
|
|
|
else if (NORMALKEY(Key) == kRight) {
|
|
|
|
if (map[++n].userValue >= 0)
|
|
|
|
newValue = map[n].driverValue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return state;
|
|
|
|
if (newValue != *value) {
|
|
|
|
*value = newValue;
|
|
|
|
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
|
|
|
{
|
2007-06-10 13:02:43 +02:00
|
|
|
SetTitle(cString::sprintf("%s - %s", tr("Setup"), Section));
|
2002-05-09 16:26:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2007-06-10 13:02:43 +02:00
|
|
|
SetSection(cString::sprintf("%s '%s'", tr("Plugin"), plugin->Name()));
|
2002-05-11 13:44:58 +02:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|