/**
 *  beep plugin for the Video Disk Recorder 
 *
 *  beep.c  -  define base plugin class
 *
 *  (c) 2004 - 2006 Andreas Brachold <vdr04 AT deltab de>
 **/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program;                                              *
 *   if not, write to the Free Software Foundation, Inc.,                  *
 *   59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *
 *                                                                         *
 ***************************************************************************/
 
#include <vdr/plugin.h>

#include "status.h"
#include "setup.h"
#include "menu.h"
#include "i18n.h"

static const char *VERSION        = "0.0.6";
static const char *DESCRIPTION    = "Notify with a beep";

class cPluginNotifyBeep : public cPlugin {
private:
  cStatusNotifyBeep * m_pStatusNotify;
public:
  cPluginNotifyBeep(void);
  virtual ~cPluginNotifyBeep();
  virtual const char *Version(void) { return VERSION; }
  virtual const char *Description(void) { return tr(DESCRIPTION); }
  virtual const char *CommandLineHelp(void){ return NULL; }
  virtual bool ProcessArgs(int argc, char *argv[]){ return true; }
  virtual bool Initialize(void){ return true; }
  virtual void Housekeeping(void) {  }
  virtual const char *MainMenuEntry(void) { return NULL; }
  virtual cOsdObject *MainMenuAction(void){ return NULL; }

  virtual bool Start(void);
  virtual cMenuSetupPage *SetupMenu(void);
  virtual bool SetupParse(const char *Name, const char *Value);
  };

cPluginNotifyBeep::cPluginNotifyBeep(void)
: m_pStatusNotify(NULL)
{

}

cPluginNotifyBeep::~cPluginNotifyBeep()
{
   if(m_pStatusNotify)
     delete m_pStatusNotify;
   m_pStatusNotify = NULL;
}

bool cPluginNotifyBeep::Start(void)
{
  bool ret = false;

  RegisterI18n(Phrases);

  m_pStatusNotify = new cStatusNotifyBeep();
  if (m_pStatusNotify)
  {
    ret = true;
  }
  return ret;
}

cMenuSetupPage *cPluginNotifyBeep::SetupMenu(void)
{
  // Return a setup menu in case the plugin supports one.
  return new cSetupMenuNotifyBeep();
}

bool cPluginNotifyBeep::SetupParse(const char * Name, const char * Value)
{
  if     (!strcasecmp(Name, "active"))      NotifyBeepSetup.active    = atoi(Value);
  else if(!strcasecmp(Name, "freq"))        
       {
           NotifyBeepSetup.freq = atoi(Value); 
           NotifyBeepSetup.freq = max(NotifyBeepSetup.freq,NotifyBeepSetup.freq_min);
           NotifyBeepSetup.freq = min(NotifyBeepSetup.freq,NotifyBeepSetup.freq_max);
       }
  else if(!strcasecmp(Name, "duration"))
       {
           NotifyBeepSetup.duration = atoi(Value); 
           NotifyBeepSetup.duration = max(NotifyBeepSetup.duration,NotifyBeepSetup.duration_min);
           NotifyBeepSetup.duration = min(NotifyBeepSetup.duration,NotifyBeepSetup.duration_max);
       }
  else if(!strcasecmp(Name, "console"))      
  {    
         strncpy(NotifyBeepSetup.console,Value,sizeof(NotifyBeepSetup.console));
  }
  else if(!strcasecmp(Name, "onshutdown"))      NotifyBeepSetup.onshutdown= atoi(Value);
  else if(!strcasecmp(Name, "oneditprocess"))   NotifyBeepSetup.oneditprocess= atoi(Value);
  else if(!strcasecmp(Name, "onanymessage"))    NotifyBeepSetup.onanymessage= atoi(Value);
  else return false;
  return true;
}

VDRPLUGINCREATOR(cPluginNotifyBeep); // Don't touch this!
