-
Notifications
You must be signed in to change notification settings - Fork 1
/
menu.c
273 lines (243 loc) · 7.42 KB
/
menu.c
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/*
* menu.c: RSS Reader plugin for the Video Disk Recorder
*
* See the README file for copyright information and how to reach the author.
*
*/
#include <vdr/plugin.h>
#include <vdr/status.h>
#include "parser.h"
#include "config.h"
#include "log.h"
#include "menu.h"
#include "tools.h"
#include "common.h"
// --- Globals ----------------------------------------------------------------
cRssItems RssItems;
// --- cRssItem(s) ------------------------------------------------------------
cRssItem::cRssItem()
: titleM(NULL),
urlM(NULL)
{
}
cRssItem::~cRssItem()
{
FREE_POINTER(titleM);
FREE_POINTER(urlM);
}
bool cRssItem::Parse(const char *strP)
{
const char *p = strchr(strP, ':');
if (p) {
long l = p - strP;
if (l > 0) {
titleM = MALLOC(char, l + 1);
stripspace(strn0cpy(titleM, strP, l + 1));
if (!isempty(titleM)) {
urlM = stripspace(strdup(skipspace(p + 1)));
return true;
}
}
}
return false;
}
cRssItems::cRssItems()
: updatedM(false)
{
}
bool cRssItems::Load(const char *fileNameP)
{
if (cConfig<cRssItem>::Load(fileNameP, true)) {
updatedM = true;
return true;
}
return false;
}
bool cRssItems::Updated()
{
bool result = updatedM;
updatedM = false;
return result;
}
// --- cRssMenuItem -----------------------------------------------------------
cRssMenuItem::cRssMenuItem(const char *streamP, const char *dateP, const char *titleP, const char *linkP, const char *descriptionP)
: cOsdMenu(*cString::sprintf("%s - %s", tr("RSS item"), streamP)),
linkM(linkP)
{
textM = cString::sprintf("\n%s%s%s%s%s%s%s",
*dateP ? strdup(dateP) : RssReaderConfig.IsHideElem() ? "" : tr("<no date available>"), (*dateP || !RssReaderConfig.IsHideElem()) ? "\n\n" : "",
*titleP ? strdup(titleP) : RssReaderConfig.IsHideElem() ? "" : tr("<no title available>"), (*titleP || !RssReaderConfig.IsHideElem()) ? "\n\n" : "",
*descriptionP ? strdup(descriptionP) : RssReaderConfig.IsHideElem() ? "" : tr("<no description available>"), (*descriptionP || !RssReaderConfig.IsHideElem()) ? "\n\n" : "",
*linkP ? strdup(linkP) : RssReaderConfig.IsHideElem() ? "" : tr("<no link available>")
);
if (isimage(*linkM))
typeM = TYPE_IMAGE;
else if (ismusic(*linkM))
typeM = TYPE_MUSIC;
else if (isvideo(*linkM))
typeM = TYPE_VIDEO;
else
typeM = TYPE_NONE;
SetHelp(NULL, "<<", (typeM != TYPE_NONE) ? ">>" : NULL, NULL);
}
cRssMenuItem::~cRssMenuItem()
{
}
void cRssMenuItem::Display(void)
{
cOsdMenu::Display();
debug1("%s textM='%s'", __PRETTY_FUNCTION__, *textM);
DisplayMenu()->SetText(textM, false);
cStatus::MsgOsdTextItem(textM);
}
eOSState cRssMenuItem::ProcessKey(eKeys keyP)
{
switch (int(keyP)) {
case kUp|k_Repeat:
case kUp:
case kDown|k_Repeat:
case kDown:
case kLeft|k_Repeat:
case kLeft:
case kRight|k_Repeat:
case kRight:
DisplayMenu()->Scroll(NORMALKEY(keyP) == kUp || NORMALKEY(keyP) == kLeft, NORMALKEY(keyP) == kLeft || NORMALKEY(keyP) == kRight);
cStatus::MsgOsdTextItem(NULL, NORMALKEY(keyP) == kUp);
return osContinue;
default:
break;
}
eOSState state = cOsdMenu::ProcessKey(keyP);
if (state == osUnknown) {
switch (keyP) {
case kGreen:
case kOk:
return osBack;
case kYellow:
switch (typeM) {
case TYPE_IMAGE:
cPluginManager::CallFirstService("ImagePlayer-1.0", (void *)*linkM);
break;
case TYPE_MUSIC:
cPluginManager::CallFirstService("MusicPlayer-1.0", (void *)*linkM);
break;
case TYPE_VIDEO:
cPluginManager::CallFirstService("MediaPlayer-1.0", (void *)*linkM);
break;
case TYPE_NONE:
default:
break;
}
default:
state = osContinue;
}
state = osContinue;
}
return state;
}
// --- cRssItemsMenu ----------------------------------------------------------
cRssItemsMenu::cRssItemsMenu(const char *streamP)
: cOsdMenu(*cString::sprintf("%s - %s", tr("Select RSS item"), streamP)),
streamM(streamP)
{
for (cRssParserItem *rssItem = RssParser.Items()->First(); rssItem; rssItem = RssParser.Items()->Next(rssItem))
Add(new cOsdItem(rssItem->GetTitle()));
SetHelp(NULL, "<<", ">>", NULL);
Display();
}
eOSState cRssItemsMenu::ProcessKey(eKeys keyP)
{
eOSState state = cOsdMenu::ProcessKey(keyP);
if (state == osUnknown) {
switch (keyP) {
case kGreen:
return osBack;
case kYellow:
case kOk:
return ShowDetails();
default:
break;
}
state = osContinue;
}
return state;
}
eOSState cRssItemsMenu::ShowDetails(void)
{
cRssParserItem *rssItem = reinterpret_cast<cRssParserItem *>(RssParser.Items()->Get(Current()));
if (rssItem) {
return AddSubMenu(new cRssMenuItem(*streamM, rssItem->GetDate(), rssItem->GetTitle(), rssItem->GetLink(), rssItem->GetDescription()));
}
return osContinue;
}
// --- cRssStreamsMenu --------------------------------------------------------
cRssStreamsMenu::cRssStreamsMenu()
:cOsdMenu(tr("Select RSS stream"))
{
Setup();
SetHelp(tr("Button$Load"), "<<", ">>", NULL);
}
void cRssStreamsMenu::Setup(void)
{
int current = Current();
Clear();
for (cRssItem *rssItem = RssItems.First(); rssItem; rssItem = RssItems.Next(rssItem)) {
cOsdItem *osdItem = new cOsdItem;
if (!*rssItem->Url())
osdItem->SetSelectable(false);
osdItem->SetText(rssItem->Title());
debug1("%s title='%s' url='%s'", __PRETTY_FUNCTION__, rssItem->Title(), rssItem->Url());
Add(osdItem);
}
SetCurrent(Get(current));
Display();
}
eOSState cRssStreamsMenu::Select(void)
{
cRssItem *rssItem = reinterpret_cast<cRssItem *>(RssItems.Get(Current()));
if (rssItem) {
debug1("%s title='%s'", __PRETTY_FUNCTION__, rssItem->Title());
// the following message generates an annoying slowdown
//Skins.Message(mtInfo, tr("Loading RSS stream..."));
switch (RssParser.DownloadAndParse(rssItem->Url())) {
case (cRssParser::RSS_PARSING_OK):
return AddSubMenu(new cRssItemsMenu(rssItem->Title()));
case (cRssParser::RSS_PARSING_ERROR):
Skins.Message(mtError, tr("Can't parse RSS stream!"));
return osContinue;
case (cRssParser::RSS_DOWNLOAD_ERROR):
Skins.Message(mtError, tr("Can't download RSS stream!"));
return osContinue;
case (cRssParser::RSS_UNKNOWN_ERROR):
default:
Skins.Message(mtError, tr("Unknown error!"));
return osContinue;
}
}
return osEnd;
}
eOSState cRssStreamsMenu::ProcessKey(eKeys keyP)
{
eOSState state = cOsdMenu::ProcessKey(keyP);
if (RssItems.Updated())
Setup();
if (state == osUnknown) {
switch (keyP) {
case kRed:
Skins.Message(mtInfo, tr("Loading configuration file..."));
RssItems.Load(RssReaderConfig.GetConfigFile());
Setup();
Skins.Message(mtInfo, NULL);
break;
case kGreen:
return osBack;
case kYellow:
case kOk:
return Select();
default:
break;
}
state = osContinue;
}
return state;
}