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
|
/*
* menuitems.c: New menu item types
*
* See the main source file 'xineliboutput.c' for copyright information and
* how to reach the author.
*
* $Id: menuitems.c,v 1.1 2006-06-03 10:01:17 phintuka Exp $
*
*/
#include <vdr/i18n.h>
#include "menuitems.h"
// --- cMenuEditTypedIntItem -------------------------------------------------
cMenuEditTypedIntItem::cMenuEditTypedIntItem(const char *Name, const char *Type, int *Value, int Min, int Max, const char *ZeroText)
:cMenuEditIntItem(Name,Value,Min,Max)
{
type = strdup(Type?Type:"");
zeroText = ZeroText ? strdup(ZeroText) : NULL;
Set();
}
cMenuEditTypedIntItem::~cMenuEditTypedIntItem()
{
free(type);
if(zeroText)
free(zeroText);
}
void cMenuEditTypedIntItem::Set(void)
{
char buf[16];
if(zeroText && *value == 0) {
SetValue(zeroText);
} else {
snprintf(buf, sizeof(buf), "%d %s", *value, type);
SetValue(buf);
}
}
// --- 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 = strdup(name);
m_IsDir = isDir;
m_HasResume = false;
m_HasSubs = false;
m_ShowFlags = false;
m_Up = m_IsDir && !strcmp(m_Name,"..");
Set();
}
cFileListItem::cFileListItem(const char *name, bool isDir, bool HasResume, bool HasSubs)
{
m_Name = strdup(name);
m_IsDir = isDir;
m_HasResume = HasResume;
m_HasSubs = HasSubs;
m_ShowFlags = true;
m_Up = m_IsDir && !strcmp(m_Name,"..");
Set();
}
cFileListItem::~cFileListItem()
{
free(m_Name);
}
void cFileListItem::Set(void)
{
char *txt = NULL,*pt;
if(m_ShowFlags) {
if(m_IsDir) {
asprintf(&txt, "\t\t[%s] ", m_Name); // text2skin requires space at end of string to display item correctly ...
} else {
asprintf(&txt, "%c\t%c\t%s", m_HasResume?' ':'*', m_HasSubs ? 'S' : ' ', m_Name);
if(NULL != (pt = strrchr(txt,'.')))
*pt = 0;
}
} else {
if(m_IsDir) {
asprintf(&txt, "[%s] ", m_Name); // text2skin requires space at end of string to display item correctly ...
} else {
asprintf(&txt, "%s", m_Name);
if(NULL != (pt = strrchr(txt,'.')))
*pt = 0;
}
}
SetText(txt, false);
}
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;
}
|