1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
|
/*
* menuitems.c: New menu item types
*
* See the main source file 'xineliboutput.c' for copyright information and
* how to reach the author.
*
* $Id$
*
*/
#include <vdr/i18n.h>
#include "menuitems.h"
// --- cMenuEditTypedIntItem -------------------------------------------------
cMenuEditTypedIntItem::cMenuEditTypedIntItem(const char *Name, const char *Type, int *Value,
int Min, int Max, const char *ZeroString,
const char *MinString, const char *MaxString)
:cMenuEditIntItem(Name,Value,Min,Max,MinString,MaxString)
{
type = Type ? Type : "";
zeroString = ZeroString ? ZeroString : NULL;
Set();
}
void cMenuEditTypedIntItem::Set(void)
{
if(*value == 0 && *zeroString)
SetValue(zeroString);
else if (minString && *value == min)
SetValue(minString);
else if (maxString && *value == max)
SetValue(maxString);
else
SetValue(cString::sprintf("%d %s", *value, *type));
}
// --- cMenuEditOddIntItem ------------------------------------------------------
cMenuEditOddIntItem::cMenuEditOddIntItem(const char *Name, int *Value, int Min, int Max, const char *MinString, const char *MaxString)
:cMenuEditIntItem(Name,Value,Min,Max,MinString,MaxString)
{
value = Value;
min = Min;
max = Max;
minString = MinString;
maxString = MaxString;
if (*value < min)
*value = min;
else if (*value > max)
*value = max;
Set();
}
eOSState cMenuEditOddIntItem::ProcessKey(eKeys Key)
{
eOSState state = cMenuEditItem::ProcessKey(Key);
if (state == osUnknown) {
int newValue = *value;
bool IsRepeat = Key & k_Repeat;
Key = NORMALKEY(Key);
switch (Key) {
case kNone: break;
case kLeft:
newValue = *value - 2;
fresh = true;
if (!IsRepeat && newValue < min && max != INT_MAX)
newValue = max;
break;
case kRight:
newValue = *value + 2;
fresh = true;
if (!IsRepeat && newValue > max && min != INT_MIN)
newValue = min;
break;
default:
if (*value < min) { *value = min; Set(); }
if (*value > max) { *value = max; Set(); }
return state;
}
if (newValue != *value && (!fresh || min <= newValue) && newValue <= max) {
*value = newValue;
Set();
}
state = osContinue;
}
return state;
}
// --- cMenuEditFpIntItem ----------------------------------------------------
cMenuEditFpIntItem::cMenuEditFpIntItem(const char *Name, int *Value, int Min, int Max,
int Decimals, const char *ZeroString,
const char *MinString, const char *MaxString)
:cMenuEditIntItem(Name,Value,Min,Max,MinString,MaxString)
{
decimals = Decimals;
zeroString = ZeroString ? ZeroString : NULL;
Set();
}
static int my_exp10(int x)
{
int r = 1;
for (; x > 0; x--, r *= 10) ;
return r;
}
void cMenuEditFpIntItem::Set(void)
{
if(*value == 0 && *zeroString)
SetValue(zeroString);
else if (minString && *value == min)
SetValue(minString);
else if (maxString && *value == max)
SetValue(maxString);
else
SetValue(cString::sprintf("%1.1f", ((float)(*value)) / (float)my_exp10(decimals)));
}
// --- cMenuEditStraI18nItem -------------------------------------------------
cMenuEditStraI18nItem::cMenuEditStraI18nItem(const char *Name, int *Value, int NumStrings, const char * const *Strings)
:cMenuEditIntItem(Name, Value, 0, NumStrings - 1)
{
strings = Strings;
Set();
}
void cMenuEditStraI18nItem::Set(void)
{
SetValue(tr(strings[*value]));
}
// --- cFileListItem -------------------------------------------------
cFileListItem::cFileListItem(const char *name, bool isDir)
{
m_Name = name;
m_IsDir = isDir;
m_IsDvd = false;
m_IsBluRay = false;
m_HasResume = false;
m_SubFile = NULL;
m_ShowFlags = false;
m_Up = m_IsDir && !strcmp(m_Name, "..");
Set();
}
cFileListItem::cFileListItem(const char *name, bool IsDir,
bool HasResume, const char *subfile,
bool IsDvd, bool IsBluRay)
{
m_Name = name;
m_IsDir = IsDir;
m_IsDvd = IsDvd;
m_IsBluRay = IsBluRay;
m_HasResume = HasResume;
m_SubFile = subfile;
m_ShowFlags = true;
m_Up = m_IsDir && !strcmp(m_Name, "..");
Set();
}
void cFileListItem::Set(void)
{
cString txt;
const char *pt;
if(m_ShowFlags) {
if(m_IsDir) {
if(m_IsDvd)
txt = cString::sprintf("\tD\t[%s] ", *m_Name); // text2skin requires space at end of string to display item correctly ...
else if (m_IsBluRay)
txt = cString::sprintf("\tB\t[%s] ", *m_Name);
else
txt = cString::sprintf("\t\t[%s] ", *m_Name); // text2skin requires space at end of string to display item correctly ...
} else {
txt = cString::sprintf("%c\t%c\t%s", m_HasResume ? ' ' : '*', *m_SubFile ? 'S' : m_IsDvd ? 'D' : m_IsBluRay ? 'B' : ' ', *m_Name);
if(NULL != (pt = strrchr(txt,'.')))
txt.Truncate(pt - txt);
}
} else {
if(m_IsDir) {
txt = cString::sprintf("[%s] ", *m_Name); // text2skin requires space at end of string to display item correctly ...
} else {
txt = m_Name;
if(NULL != (pt = strrchr(txt,'.')))
txt.Truncate(pt - txt);
}
}
SetText(txt);
}
int cFileListItem::Compare(const cListObject &ListObject) const
{
cFileListItem *other = (cFileListItem *)&ListObject;
if(m_IsDir && !other->m_IsDir)
return -1;
if(!m_IsDir && other->m_IsDir)
return 1;
if(m_Up && !other->m_Up)
return -1;
if(!m_Up && other->m_Up)
return 1;
return strcmp(m_Name, other->m_Name);
}
bool cFileListItem::operator< (const cListObject &ListObject)
{
cFileListItem *other = (cFileListItem *)&ListObject;
if(m_IsDir && !other->m_IsDir)
return true;
if(!m_IsDir && other->m_IsDir)
return false;
if(m_Up && !other->m_Up)
return true;
if(!m_Up && other->m_Up)
return false;
return strcmp(m_Name, other->m_Name) < 0;
}
|