-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrssreader.c
183 lines (160 loc) · 5.21 KB
/
rssreader.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
/*
* rssreader.c: RSS Reader plugin for the Video Disk Recorder
*
*/
#include <getopt.h>
#include <vdr/config.h>
#include <vdr/menu.h>
#include <vdr/plugin.h>
#include "config.h"
#include "common.h"
#include "log.h"
#include "menu.h"
#include "setup.h"
#if defined(APIVERSNUM) && APIVERSNUM < 20400
#error "VDR-2.4.0 API version or greater is required!"
#endif
#ifndef GITVERSION
#define GITVERSION ""
#endif
const char VERSION[] = "2.4.0" GITVERSION;
static const char DESCRIPTION[] = trNOOP("RSS Reader for OSD");
static const char MAINMENUENTRY[] = trNOOP("RSS Reader");
class cPluginRssReader : public cPlugin {
private:
// Add any member variables or functions you may need here.
public:
cPluginRssReader(void);
virtual ~cPluginRssReader();
virtual const char *Version(void) { return VERSION; }
virtual const char *Description(void) { return tr(DESCRIPTION); }
virtual const char *CommandLineHelp(void);
virtual bool ProcessArgs(int argc, char *argv[]);
virtual bool Initialize(void);
virtual bool Start(void);
virtual void Stop(void);
virtual void Housekeeping(void);
virtual void MainThreadHook(void) {}
virtual cString Active(void) { return NULL; }
virtual const char *MainMenuEntry(void) { return (RssReaderConfig.IsHideMenu() ? NULL : tr(MAINMENUENTRY)); }
virtual cOsdObject *MainMenuAction(void);
virtual cMenuSetupPage *SetupMenu(void);
virtual bool SetupParse(const char *nameP, const char *valueP);
virtual bool Service(const char *idP, void *dataP = NULL);
virtual const char **SVDRPHelpPages(void);
virtual cString SVDRPCommand(const char *commandP, const char *optionP, int &replyCodeP);
};
cPluginRssReader::cPluginRssReader(void)
{
// Initialize any member variables here.
// DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
// VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
}
cPluginRssReader::~cPluginRssReader()
{
// Clean up after yourself!
}
const char *cPluginRssReader::CommandLineHelp(void)
{
// Return a string that describes all known command line options.
return " -t <mode>, --trace=<mode> set the tracing mode\n";
}
bool cPluginRssReader::ProcessArgs(int argc, char *argv[])
{
// Implement command line argument processing here if applicable.
static const struct option long_options[] = {
{ "trace", required_argument, NULL, 't' },
{ NULL, no_argument, NULL, 0 }
};
cString server;
int c;
while ((c = getopt_long(argc, argv, "t:", long_options, NULL)) != -1) {
switch (c) {
case 't':
RssReaderConfig.SetTraceMode(strtol(optarg, NULL, 0));
break;
default:
return false;
}
}
return true;
}
bool cPluginRssReader::Initialize(void)
{
// Initialize any background activities the plugin shall perform.
RssReaderConfig.SetConfigFile(*AddDirectory(ConfigDirectory(PLUGIN_NAME_I18N), PLUGIN_NAME_I18N ".conf"));
return true;
}
bool cPluginRssReader::Start(void)
{
// Start any background activities the plugin shall perform.
if (!RssItems.Load(RssReaderConfig.GetConfigFile()))
error("Configuration file '%s' not found!", RssReaderConfig.GetConfigFile());
return true;
}
void cPluginRssReader::Stop(void)
{
// Stop any background activities the plugin shall perform.
}
void cPluginRssReader::Housekeeping(void)
{
// Perform any cleanup or other regular tasks.
}
cOsdObject *cPluginRssReader::MainMenuAction(void)
{
// Perform the action when selected from the main VDR menu.
return new cRssStreamsMenu();
}
cMenuSetupPage *cPluginRssReader::SetupMenu(void)
{
// Return a setup menu in case the plugin supports one.
return new cRssReaderSetup();
}
bool cPluginRssReader::SetupParse(const char *nameP, const char *valueP)
{
// Parse your own setup parameters and store their values.
if (!strcasecmp(nameP, "HideMenu"))
RssReaderConfig.SetHideMenu(atoi(valueP));
else if (!strcasecmp(nameP, "HideElem"))
RssReaderConfig.SetHideElem(atoi(valueP));
else if (!strcasecmp(nameP, "UseProxy"))
RssReaderConfig.SetUseProxy(atoi(valueP));
else if (!strcasecmp(nameP, "HttpProxy"))
RssReaderConfig.SetHttpProxy(valueP);
else
return false;
return true;
}
bool cPluginRssReader::Service(const char *idP, void *dataP)
{
// Handle custom service requests from other plugins
return false;
}
const char **cPluginRssReader::SVDRPHelpPages(void)
{
static const char *HelpPages[] = {
"LOAD\n"
" Load RSS feed configuration file.",
"TRAC [ <mode> ]\n"
" Gets and/or sets used tracing mode.\n",
NULL
};
return HelpPages;
}
cString cPluginRssReader::SVDRPCommand(const char *commandP, const char *optionP, int &replyCodeP)
{
if (strcasecmp(commandP, "LOAD") == 0) {
if (!RssItems.Load(RssReaderConfig.GetConfigFile())) {
replyCodeP = 550; // Requested action not taken
return cString("Configuration file not found!");
}
return cString("Configuration file loaded");
}
else if (strcasecmp(commandP, "TRAC") == 0) {
if (optionP && *optionP)
RssReaderConfig.SetTraceMode(strtol(optionP, NULL, 0));
return cString::sprintf("Tracing mode: 0x%04X\n", RssReaderConfig.GetTraceMode());
}
return NULL;
}
VDRPLUGINCREATOR(cPluginRssReader); // Don't touch this!