vdr  1.7.27
pictures.c
Go to the documentation of this file.
00001 /*
00002  * pictures.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: pictures.c 2.5 2012/02/27 11:40:15 kls Exp $
00007  */
00008 
00009 #include <getopt.h>
00010 #include <vdr/plugin.h>
00011 #include "menu.h"
00012 #include "player.h"
00013 
00014 static const char *VERSION       = "0.1.2";
00015 static const char *DESCRIPTION   = trNOOP("A simple picture viewer");
00016 static const char *MAINMENUENTRY = trNOOP("Pictures");
00017 
00018 // --- cMenuSetupPictures ----------------------------------------------------
00019 
00020 class cMenuSetupPictures : public cMenuSetupPage {
00021 private:
00022   char newPictureDirectory[PATH_MAX];
00023   int newSlideShowDelay;
00024 protected:
00025   virtual void Store(void);
00026 public:
00027   cMenuSetupPictures(void);
00028   };
00029 
00030 cMenuSetupPictures::cMenuSetupPictures(void)
00031 {
00032   strn0cpy(newPictureDirectory, PictureDirectory, sizeof(newPictureDirectory));
00033   newSlideShowDelay = SlideShowDelay;
00034   Add(new cMenuEditStrItem(tr("Picture directory"),    newPictureDirectory, sizeof(newPictureDirectory)));
00035   Add(new cMenuEditIntItem(tr("Slide show delay (s)"), &newSlideShowDelay));
00036 }
00037 
00038 void cMenuSetupPictures::Store(void)
00039 {
00040   SetupStore("PictureDirectory", strn0cpy(PictureDirectory, newPictureDirectory, sizeof(PictureDirectory)));
00041   SetupStore("SlideShowDelay",   SlideShowDelay = newSlideShowDelay);
00042 }
00043 
00044 // --- cPluginPictures -------------------------------------------------------
00045 
00046 class cPluginPictures : public cPlugin {
00047 private:
00048   // Add any member variables or functions you may need here.
00049 public:
00050   cPluginPictures(void);
00051   virtual ~cPluginPictures();
00052   virtual const char *Version(void) { return VERSION; }
00053   virtual const char *Description(void) { return tr(DESCRIPTION); }
00054   virtual const char *CommandLineHelp(void);
00055   virtual bool ProcessArgs(int argc, char *argv[]);
00056   virtual const char *MainMenuEntry(void) { return tr(MAINMENUENTRY); }
00057   virtual cOsdObject *MainMenuAction(void);
00058   virtual cMenuSetupPage *SetupMenu(void);
00059   virtual bool SetupParse(const char *Name, const char *Value);
00060   };
00061 
00062 cPluginPictures::cPluginPictures(void)
00063 {
00064   // Initialize any member variables here.
00065   // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
00066   // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
00067 }
00068 
00069 cPluginPictures::~cPluginPictures()
00070 {
00071   // Clean up after yourself!
00072 }
00073 
00074 const char *cPluginPictures::CommandLineHelp(void)
00075 {
00076   // Return a string that describes all known command line options.
00077   return "  -d DIR,   --dir=DIR      set the picture directory to DIR\n";
00078 }
00079 
00080 bool cPluginPictures::ProcessArgs(int argc, char *argv[])
00081 {
00082   // Implement command line argument processing here if applicable.
00083   static struct option long_options[] = {
00084        { "dir",      required_argument, NULL, 'd' },
00085        { NULL,       no_argument,       NULL,  0  }
00086      };
00087 
00088   int c;
00089   while ((c = getopt_long(argc, argv, "d:", long_options, NULL)) != -1) {
00090         switch (c) {
00091           case 'd': strn0cpy(PictureDirectory, optarg, sizeof(PictureDirectory));
00092                     break;
00093           default:  return false;
00094           }
00095         }
00096   return true;
00097 }
00098 
00099 cOsdObject *cPluginPictures::MainMenuAction(void)
00100 {
00101   // Perform the action when selected from the main VDR menu.
00102   if (*PictureDirectory)
00103      return cPictureMenu::CreatePictureMenu();
00104   Skins.Message(mtWarning, tr("No picture directory has been defined!"));
00105   return NULL;
00106 }
00107 
00108 cMenuSetupPage *cPluginPictures::SetupMenu(void)
00109 {
00110   // Return a setup menu in case the plugin supports one.
00111   return new cMenuSetupPictures;
00112 }
00113 
00114 bool cPluginPictures::SetupParse(const char *Name, const char *Value)
00115 {
00116   // Parse your own setup parameters and store their values.
00117   if      (!strcasecmp(Name, "PictureDirectory")) strn0cpy(PictureDirectory, Value, sizeof(PictureDirectory));
00118   else if (!strcasecmp(Name, "SlideShowDelay"))   SlideShowDelay = atoi(Value);
00119   else
00120      return false;
00121   return true;
00122 }
00123 
00124 VDRPLUGINCREATOR(cPluginPictures); // Don't touch this!