vdr  1.7.31
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.3 2010/02/28 12:49:28 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 = "0.2.5";
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 {
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!