vdr 2.6.1
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 4.1 2018/04/10 13:00:22 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
15static const char *VERSION = "2.4.0";
16static const char *DESCRIPTION = trNOOP("A friendly greeting");
17static const char *MAINMENUENTRY = trNOOP("Hello");
18
19class cPluginHello : public cPlugin {
20private:
21 // Add any member variables or functions you may need here.
22 const char *option_a;
24public:
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
43
44// --- cMenuSetupHello -------------------------------------------------------
45
47private:
50protected:
51 virtual void Store(void);
52public:
53 cMenuSetupHello(void);
54 };
55
57{
60 Add(new cMenuEditIntItem( tr("Greeting time (s)"), &newGreetingTime));
61 Add(new cMenuEditBoolItem(tr("Use alternate greeting"), &newUseAlternateGreeting));
62}
63
65{
66 SetupStore("GreetingTime", GreetingTime = newGreetingTime);
68}
69
70// --- cPluginHello ----------------------------------------------------------
71
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
82{
83 // Clean up after yourself!
84}
85
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
93bool 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
116{
117 // Start any background activities the plugin shall perform.
118 return true;
119}
120
122{
123 // Perform any cleanup or other regular tasks.
124}
125
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
134{
135 // Return a setup menu in case the plugin supports one.
136 return new cMenuSetupHello;
137}
138
139bool 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
149VDRPLUGINCREATOR(cPluginHello); // Don't touch this!
bool Confirm(const char *s, int Seconds=10, bool WaitForTimeout=false)
Definition: interface.c:59
int newGreetingTime
Definition: hello.c:48
int newUseAlternateGreeting
Definition: hello.c:49
cMenuSetupHello(void)
Definition: hello.c:56
virtual void Store(void)
Definition: hello.c:64
void SetupStore(const char *Name, const char *Value=NULL)
Definition: menuitems.c:1267
void Add(cOsdItem *Item, bool Current=false, cOsdItem *After=NULL)
Definition: osdbase.c:213
virtual const char * MainMenuEntry(void)
Definition: hello.c:33
virtual const char * Description(void)
Definition: hello.c:28
virtual ~cPluginHello()
Definition: hello.c:81
cPluginHello(void)
Definition: hello.c:72
virtual bool ProcessArgs(int argc, char *argv[])
Definition: hello.c:93
virtual void Housekeeping(void)
Definition: hello.c:121
virtual bool Start(void)
Definition: hello.c:115
virtual const char * CommandLineHelp(void)
Definition: hello.c:86
virtual cOsdObject * MainMenuAction(void)
Definition: hello.c:126
virtual bool SetupParse(const char *Name, const char *Value)
Definition: hello.c:139
bool option_b
Definition: hello.c:23
virtual cMenuSetupPage * SetupMenu(void)
Definition: hello.c:133
const char * option_a
Definition: hello.c:22
virtual const char * Version(void)
Definition: hello.c:27
const char * Name(void)
static const char * VERSION
Definition: hello.c:15
static const char * DESCRIPTION
Definition: hello.c:16
int GreetingTime
Definition: hello.c:41
int UseAlternateGreeting
Definition: hello.c:42
VDRPLUGINCREATOR(cPluginHello)
static const char * MAINMENUENTRY
Definition: hello.c:17
#define tr(s)
Definition: i18n.h:85
#define trNOOP(s)
Definition: i18n.h:88
cInterface * Interface
Definition: interface.c:20