vdr  2.2.0
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 3.2 2015/02/17 13:12:26 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.2.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;
43 
44 // --- cMenuSetupHello -------------------------------------------------------
45 
47 private:
50 protected:
51  virtual void Store(void);
52 public:
53  cMenuSetupHello(void);
54  };
55 
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 
65 {
66  SetupStore("GreetingTime", GreetingTime = newGreetingTime);
67  SetupStore("UseAlternateGreeting", UseAlternateGreeting = newUseAlternateGreeting);
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 
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 
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 
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!
int newUseAlternateGreeting
Definition: hello.c:49
bool Confirm(const char *s, int Seconds=10, bool WaitForTimeout=false)
Definition: interface.c:67
const char * Name(void)
Definition: plugin.h:34
static const char * MAINMENUENTRY
Definition: hello.c:17
void SetupStore(const char *Name, const char *Value=NULL)
Definition: plugin.c:110
Definition: plugin.h:20
int UseAlternateGreeting
Definition: hello.c:42
int newGreetingTime
Definition: hello.c:48
static const char * DESCRIPTION
Definition: hello.c:16
virtual cOsdObject * MainMenuAction(void)
Definition: hello.c:126
cPluginHello(void)
Definition: hello.c:72
virtual ~cPluginHello()
Definition: hello.c:81
#define trNOOP(s)
Definition: i18n.h:88
virtual bool SetupParse(const char *Name, const char *Value)
Definition: hello.c:139
virtual const char * MainMenuEntry(void)
Definition: hello.c:33
int GreetingTime
Definition: hello.c:41
VDRPLUGINCREATOR(cPluginHello)
virtual void Store(void)
Definition: hello.c:64
virtual const char * CommandLineHelp(void)
Definition: hello.c:86
virtual const char * Description(void)
Definition: hello.c:28
virtual cMenuSetupPage * SetupMenu(void)
Definition: hello.c:133
cMenuSetupHello(void)
Definition: hello.c:56
#define tr(s)
Definition: i18n.h:85
virtual const char * Version(void)
Definition: hello.c:27
virtual bool Start(void)
Definition: hello.c:115
const char * option_a
Definition: hello.c:22
bool option_b
Definition: hello.c:23
cInterface * Interface
Definition: interface.c:20
virtual void Housekeeping(void)
Definition: hello.c:121
static const char * VERSION
Definition: hello.c:15
virtual bool ProcessArgs(int argc, char *argv[])
Definition: hello.c:93