summaryrefslogtreecommitdiff
path: root/menuitems.c
blob: c11032af785368c9b90145c11805c90682561c4e (plain)
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
/*
 * 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.4 2006-11-05 16:37:10 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 *ZeroString,
					     const char *MinString, const char *MaxString)
:cMenuEditIntItem(Name,Value,Min,Max,MinString,MaxString)
{
  type = strdup(Type?Type:"");
  zeroString = ZeroString ? strdup(ZeroString) : NULL;
  Set();
}

cMenuEditTypedIntItem::~cMenuEditTypedIntItem()
{
  free(type);
  if(zeroString)
    free(zeroString);
}

void cMenuEditTypedIntItem::Set(void)
{
  char buf[64];
  if(zeroString && *value == 0) 
    SetValue(zeroString);
  else if (minString && *value == min)
    SetValue(minString);
  else if (maxString && *value == max)
    SetValue(maxString);
  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_IsDvd = false;
  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,
			     bool IsDvd)
{
  m_Name = strdup(name);
  m_IsDir = IsDir;
  m_IsDvd = IsDvd;
  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) {
      if(m_IsDvd) 
	asprintf(&txt, "\tD\t[%s] ", m_Name); // text2skin requires space at end of string to display item correctly ...
      else
	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_IsDvd ? 'D' : ' ', 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;
}