summaryrefslogtreecommitdiff
path: root/src/vdr-plugin/history.c
blob: fe444ca4c72d1845fbbe90448d9872d06beef7ac (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
/*
 * history.c: Web video plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */

#include <string.h>
#include "history.h"
#include "menu.h"

// --- cHistoryObject -----------------------------------------------------

cHistoryObject::cHistoryObject(const char *xml, const char *ref, int ID) {
  osdxml = strdup(xml);
  reference = strdup(ref);
  id = ID;
  selected = 0;
}

cHistoryObject::~cHistoryObject() {
  if (osdxml)
    free(osdxml);
  if (reference)
    free(reference);

  for (int i=0; i < editData.Size(); i++)
    delete editData[i];
}

cQueryData *cHistoryObject::GetEditItem(const char *controlName) {
  for (int i=0; i < editData.Size(); i++) {
    if (strcmp(editData[i]->GetName(), controlName) == 0) {
      return editData[i];
    }
  }

  return NULL;
}

int cHistoryObject::QuerySize() const {
  return editData.Size();
}

char *cHistoryObject::GetQueryFragment(int i, const char *encoding) const {
  if (i < 0 && i >= editData.Size())
    return NULL;
  else
    return editData[i]->GetQueryFragment(encoding);
}

cTextFieldData *cHistoryObject::GetTextFieldData(const char *controlName) {
  cQueryData *edititem = GetEditItem(controlName);
  cTextFieldData *tfdata = dynamic_cast<cTextFieldData *>(edititem);

  if (!tfdata) {
    tfdata = new cTextFieldData(controlName, 256);
    editData.Append(tfdata);
  }

  return tfdata;
}

cItemListData *cHistoryObject::GetItemListData(const char *controlName,
                                               cStringList &items,
                                               cStringList &values) {
  int n;
  char **itemtable, **itemvaluetable;
  cQueryData *edititem = GetEditItem(controlName);
  cItemListData *ildata = dynamic_cast<cItemListData *>(edititem);

  if (!ildata) {
    n = min(items.Size(), values.Size());
    itemtable = (char **)malloc(n*sizeof(char *));
    itemvaluetable = (char **)malloc(n*sizeof(char *));

    for (int i=0; i<n; i++) {
      itemtable[i] = strdup(csc.Convert(items[i]));
      itemvaluetable[i] = strdup(values[i]);
    }
    
    ildata = new cItemListData(controlName,
                               itemtable,
                               itemvaluetable,
                               n);

    editData.Append(ildata);
  }

  return ildata;
}

// --- cHistory ------------------------------------------------------------

cHistory::cHistory() {
  current = NULL;
}

void cHistory::Clear() {
  current = NULL;
  cList<cHistoryObject>::Clear();
}

void cHistory::TruncateAndAdd(cHistoryObject *page) {
  cHistoryObject *last = Last();
  while ((last) && (last != current)) {
    Del(last);
    last = Last();
  }

  Add(page);
  current = Last();
}

void cHistory::Reset() {
  current = NULL;
}

cHistoryObject *cHistory::Current() {
  return current;
}

cHistoryObject *cHistory::Home() {
  current = First();
  return current;
}

cHistoryObject *cHistory::Back() {
  if (current)
    current = Prev(current);
  return current;
}

cHistoryObject *cHistory::Forward() {
  cHistoryObject *next;
  if (current) {
    next = Next(current);
    if (next)
      current = next;
  } else {
    current = First();
  }
  return current;
}