vdr
2.0.4
Main Page
Namespaces
Classes
Files
File List
File Members
PLUGINS
src
hello
hello.c
Go to the documentation of this file.
1
/*
2
* hello.c: A plugin for the Video Disk Recorder
3
*
4
* See the README file for copyright information and how to reach the author.
5
*
6
* $Id: hello.c 2.6 2013/03/31 09:30:18 kls Exp $
7
*/
8
9
#include <getopt.h>
10
#include <stdlib.h>
11
#include <vdr/i18n.h>
12
#include <vdr/interface.h>
13
#include <vdr/plugin.h>
14
15
static
const
char
*
VERSION
=
"2.0.0"
;
16
static
const
char
*
DESCRIPTION
=
trNOOP
(
"A friendly greeting"
);
17
static
const
char
*
MAINMENUENTRY
=
trNOOP
(
"Hello"
);
18
19
class
cPluginHello
:
public
cPlugin
{
20
private
:
21
// Add any member variables or functions you may need here.
22
const
char
*
option_a
;
23
bool
option_b
;
24
public
:
25
cPluginHello
(
void
);
26
virtual
~cPluginHello
();
27
virtual
const
char
*
Version
(
void
) {
return
VERSION
; }
28
virtual
const
char
*
Description
(
void
) {
return
tr
(
DESCRIPTION
); }
29
virtual
const
char
*
CommandLineHelp
(
void
);
30
virtual
bool
ProcessArgs
(
int
argc,
char
*argv[]);
31
virtual
bool
Start
(
void
);
32
virtual
void
Housekeeping
(
void
);
33
virtual
const
char
*
MainMenuEntry
(
void
) {
return
tr
(
MAINMENUENTRY
); }
34
virtual
cOsdObject
*
MainMenuAction
(
void
);
35
virtual
cMenuSetupPage
*
SetupMenu
(
void
);
36
virtual
bool
SetupParse
(
const
char
*
Name
,
const
char
*Value);
37
};
38
39
// Global variables that control the overall behaviour:
40
41
int
GreetingTime
= 3;
42
int
UseAlternateGreeting
=
false
;
43
44
// --- cMenuSetupHello -------------------------------------------------------
45
46
class
cMenuSetupHello
:
public
cMenuSetupPage
{
47
private
:
48
int
newGreetingTime
;
49
int
newUseAlternateGreeting
;
50
protected
:
51
virtual
void
Store
(
void
);
52
public
:
53
cMenuSetupHello
(
void
);
54
};
55
56
cMenuSetupHello::cMenuSetupHello
(
void
)
57
{
58
newGreetingTime
=
GreetingTime
;
59
newUseAlternateGreeting
=
UseAlternateGreeting
;
60
Add
(
new
cMenuEditIntItem
(
tr
(
"Greeting time (s)"
), &
newGreetingTime
));
61
Add
(
new
cMenuEditBoolItem
(
tr
(
"Use alternate greeting"
), &
newUseAlternateGreeting
));
62
}
63
64
void
cMenuSetupHello::Store
(
void
)
65
{
66
SetupStore
(
"GreetingTime"
,
GreetingTime
=
newGreetingTime
);
67
SetupStore
(
"UseAlternateGreeting"
,
UseAlternateGreeting
=
newUseAlternateGreeting
);
68
}
69
70
// --- cPluginHello ----------------------------------------------------------
71
72
cPluginHello::cPluginHello
(
void
)
73
{
74
// Initialize any member variables here.
75
// DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
76
// VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
77
option_a
= NULL;
78
option_b
=
false
;
79
}
80
81
cPluginHello::~cPluginHello
()
82
{
83
// Clean up after yourself!
84
}
85
86
const
char
*
cPluginHello::CommandLineHelp
(
void
)
87
{
88
// Return a string that describes all known command line options.
89
return
" -a ABC, --aaa=ABC do something nice with ABC\n"
90
" -b, --bbb activate 'plan B'\n"
;
91
}
92
93
bool
cPluginHello::ProcessArgs
(
int
argc,
char
*argv[])
94
{
95
// Implement command line argument processing here if applicable.
96
static
struct
option long_options[] = {
97
{
"aaa"
, required_argument, NULL,
'a'
},
98
{
"bbb"
, no_argument, NULL,
'b'
},
99
{ NULL, no_argument, NULL, 0 }
100
};
101
102
int
c;
103
while
((c = getopt_long(argc, argv,
"a:b"
, long_options, NULL)) != -1) {
104
switch
(c) {
105
case
'a'
:
option_a
= optarg;
106
break
;
107
case
'b'
:
option_b
=
true
;
108
break
;
109
default
:
return
false
;
110
}
111
}
112
return
true
;
113
}
114
115
bool
cPluginHello::Start
(
void
)
116
{
117
// Start any background activities the plugin shall perform.
118
return
true
;
119
}
120
121
void
cPluginHello::Housekeeping
(
void
)
122
{
123
// Perform any cleanup or other regular tasks.
124
}
125
126
cOsdObject
*
cPluginHello::MainMenuAction
(
void
)
127
{
128
// Perform the action when selected from the main VDR menu.
129
Interface
->
Confirm
(
UseAlternateGreeting
?
tr
(
"Howdy folks!"
) :
tr
(
"Hello world!"
),
GreetingTime
);
130
return
NULL;
131
}
132
133
cMenuSetupPage
*
cPluginHello::SetupMenu
(
void
)
134
{
135
// Return a setup menu in case the plugin supports one.
136
return
new
cMenuSetupHello
;
137
}
138
139
bool
cPluginHello::SetupParse
(
const
char
*Name,
const
char
*Value)
140
{
141
// Parse your own setup parameters and store their values.
142
if
(!strcasecmp(Name,
"GreetingTime"
))
GreetingTime
= atoi(Value);
143
else
if
(!strcasecmp(Name,
"UseAlternateGreeting"
))
UseAlternateGreeting
= atoi(Value);
144
else
145
return
false
;
146
return
true
;
147
}
148
149
VDRPLUGINCREATOR
(
cPluginHello
);
// Don't touch this!
150
Generated by
1.8.3.1