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

#ifndef __WEBVIDEO_MENU_H
#define __WEBVIDEO_MENU_H

#include <time.h>
#include <vdr/osdbase.h>
#include <vdr/menuitems.h>
#include <vdr/menu.h>
#include <libxml/parser.h>
#include "download.h"
#include "menudata.h"

extern cCharSetConv csc;

// --- cFormItemList ---------------------------------------------

class cFormItem;
class cFormItemList {
private:
  cList<cFormItem> inputItems;
  cFormItem *FindByName(const char *name);
  cFormItem *FormItemFactory(const char *type, const char *name, const char *mainLabel);
public:
  void AddInputItem(const char *name, const char *type, const char *mainLabel,
                    const char *value, const char *valueLabel);
  void CreateAndAppendOsdItems(cList<cOsdItem> *destination, const char *uriTemplate);
};

// --- cXMLMenu --------------------------------------------------

class cXMLMenu : public cOsdMenu {
protected:
  virtual bool Deserialize(const char *xml);
  virtual bool ParseRootChild(xmlDocPtr doc, xmlNodePtr node) = 0;
public:
  cXMLMenu(const char *Title, int c0 = 0, int c1 = 0, 
           int c2 = 0, int c3 = 0, int c4 = 0);

  int Load(const char *xmlstr);
};

// --- cNavigationMenu -----------------------------------------------------

enum eLinkType { LT_REGULAR, LT_MEDIA, LT_STREAMINGMEDIA };

class cHistory;
class cHistoryObject;
class cStatusScreen;

class cNavigationMenu : public cXMLMenu {
private:
  // links[i] is the navigation link of the i:th item
  cVector<cLinkBase *> links;
  // streams[i] is the media stream link of the i:th item
  cVector<cLinkBase *> streams;
  cFormItemList formItems;
  cProgressVector& summaries;
  iAsyncFileDownloaderManager *dlmanager;
  char *title;
  char *reference;
  int shortcutMode;

protected:
  cHistory *history;

  virtual bool ParseRootChild(xmlDocPtr doc, xmlNodePtr node);
  void ParseForm(xmlDocPtr doc, xmlNodePtr node);
  void ParseFormItem(cFormItemList& formItems, xmlDocPtr doc, xmlNodePtr node);
  void ParseUL(xmlDocPtr doc, xmlNodePtr node);
  void CreateLinkElement(xmlDocPtr doc, xmlNodePtr node);
  void CreateAndAddOSDLink(const char *title, const char *href, bool isStream);
  void AddLinkItem(cOsdItem *item, cLinkBase *ref, cLinkBase *streamref);
  void NewTitle(xmlDocPtr doc, xmlNodePtr node);
  void UpdateHelp();

public:
  cNavigationMenu(cHistory *History, cProgressVector& dlsummaries);
  virtual ~cNavigationMenu();

  virtual eOSState ProcessKey(eKeys Key);
  virtual eOSState Select(cLinkBase *link, eLinkType type);
  virtual void Clear(void);
  eOSState HistoryBack();
  eOSState HistoryForward();

  const char *Reference() const { return reference; }
  void Populate(const cHistoryObject *page, const char *statusmsg=NULL);
};

// --- cMenuLink -------------------------------------------------

class cMenuLink {
public:
  virtual const char *GetURL() = 0;
  virtual bool HasStream() = 0;
};

// --- cStatusScreen -------------------------------------------------------

class cStatusScreen : public cOsdMenu {
public:
  const static time_t updateInterval = 5; // seconds
private:
  cProgressVector& summaries;
  time_t lastupdate;

protected:
  void UpdateHelp();

public:
  cStatusScreen(cProgressVector& dlsummaries);
  ~cStatusScreen();

  void Update();
  bool NeedsUpdate();

  virtual eOSState ProcessKey(eKeys Key);
};

// --- MenuPointers --------------------------------------------------------

struct MenuPointers {
  cNavigationMenu *navigationMenu;
  cStatusScreen *statusScreen;

  MenuPointers() : navigationMenu(NULL), statusScreen(NULL) {};
};

extern struct MenuPointers menuPointers;

#endif // __WEBVIDEO_MENU_H