vdr
1.7.27
|
00001 /* 00002 * hello.c: A plugin for the Video Disk Recorder 00003 * 00004 * See the README file for copyright information and how to reach the author. 00005 * 00006 * $Id: hello.c 2.3 2010/02/28 12:49:28 kls Exp $ 00007 */ 00008 00009 #include <getopt.h> 00010 #include <stdlib.h> 00011 #include <vdr/i18n.h> 00012 #include <vdr/interface.h> 00013 #include <vdr/plugin.h> 00014 00015 static const char *VERSION = "0.2.5"; 00016 static const char *DESCRIPTION = trNOOP("A friendly greeting"); 00017 static const char *MAINMENUENTRY = trNOOP("Hello"); 00018 00019 class cPluginHello : public cPlugin { 00020 private: 00021 // Add any member variables or functions you may need here. 00022 const char *option_a; 00023 bool option_b; 00024 public: 00025 cPluginHello(void); 00026 virtual ~cPluginHello(); 00027 virtual const char *Version(void) { return VERSION; } 00028 virtual const char *Description(void) { return tr(DESCRIPTION); } 00029 virtual const char *CommandLineHelp(void); 00030 virtual bool ProcessArgs(int argc, char *argv[]); 00031 virtual bool Start(void); 00032 virtual void Housekeeping(void); 00033 virtual const char *MainMenuEntry(void) { return tr(MAINMENUENTRY); } 00034 virtual cOsdObject *MainMenuAction(void); 00035 virtual cMenuSetupPage *SetupMenu(void); 00036 virtual bool SetupParse(const char *Name, const char *Value); 00037 }; 00038 00039 // Global variables that control the overall behaviour: 00040 00041 int GreetingTime = 3; 00042 int UseAlternateGreeting = false; 00043 00044 // --- cMenuSetupHello ------------------------------------------------------- 00045 00046 class cMenuSetupHello : public cMenuSetupPage { 00047 private: 00048 int newGreetingTime; 00049 int newUseAlternateGreeting; 00050 protected: 00051 virtual void Store(void); 00052 public: 00053 cMenuSetupHello(void); 00054 }; 00055 00056 cMenuSetupHello::cMenuSetupHello(void) 00057 { 00058 newGreetingTime = GreetingTime; 00059 newUseAlternateGreeting = UseAlternateGreeting; 00060 Add(new cMenuEditIntItem( tr("Greeting time (s)"), &newGreetingTime)); 00061 Add(new cMenuEditBoolItem(tr("Use alternate greeting"), &newUseAlternateGreeting)); 00062 } 00063 00064 void cMenuSetupHello::Store(void) 00065 { 00066 SetupStore("GreetingTime", GreetingTime = newGreetingTime); 00067 SetupStore("UseAlternateGreeting", UseAlternateGreeting = newUseAlternateGreeting); 00068 } 00069 00070 // --- cPluginHello ---------------------------------------------------------- 00071 00072 cPluginHello::cPluginHello(void) 00073 { 00074 // Initialize any member variables here. 00075 // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL 00076 // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT! 00077 option_a = NULL; 00078 option_b = false; 00079 } 00080 00081 cPluginHello::~cPluginHello() 00082 { 00083 // Clean up after yourself! 00084 } 00085 00086 const char *cPluginHello::CommandLineHelp(void) 00087 { 00088 // Return a string that describes all known command line options. 00089 return " -a ABC, --aaa=ABC do something nice with ABC\n" 00090 " -b, --bbb activate 'plan B'\n"; 00091 } 00092 00093 bool cPluginHello::ProcessArgs(int argc, char *argv[]) 00094 { 00095 // Implement command line argument processing here if applicable. 00096 static struct option long_options[] = { 00097 { "aaa", required_argument, NULL, 'a' }, 00098 { "bbb", no_argument, NULL, 'b' }, 00099 { NULL, no_argument, NULL, 0 } 00100 }; 00101 00102 int c; 00103 while ((c = getopt_long(argc, argv, "a:b", long_options, NULL)) != -1) { 00104 switch (c) { 00105 case 'a': option_a = optarg; 00106 break; 00107 case 'b': option_b = true; 00108 break; 00109 default: return false; 00110 } 00111 } 00112 return true; 00113 } 00114 00115 bool cPluginHello::Start(void) 00116 { 00117 // Start any background activities the plugin shall perform. 00118 return true; 00119 } 00120 00121 void cPluginHello::Housekeeping(void) 00122 { 00123 // Perform any cleanup or other regular tasks. 00124 } 00125 00126 cOsdObject *cPluginHello::MainMenuAction(void) 00127 { 00128 // Perform the action when selected from the main VDR menu. 00129 Interface->Confirm(UseAlternateGreeting ? tr("Howdy folks!") : tr("Hello world!"), GreetingTime); 00130 return NULL; 00131 } 00132 00133 cMenuSetupPage *cPluginHello::SetupMenu(void) 00134 { 00135 // Return a setup menu in case the plugin supports one. 00136 return new cMenuSetupHello; 00137 } 00138 00139 bool cPluginHello::SetupParse(const char *Name, const char *Value) 00140 { 00141 // Parse your own setup parameters and store their values. 00142 if (!strcasecmp(Name, "GreetingTime")) GreetingTime = atoi(Value); 00143 else if (!strcasecmp(Name, "UseAlternateGreeting")) UseAlternateGreeting = atoi(Value); 00144 else 00145 return false; 00146 return true; 00147 } 00148 00149 VDRPLUGINCREATOR(cPluginHello); // Don't touch this!