/*
 * daap.c: A daap client plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id: daap.c,v 1.10 2005/10/06 08:13:43 cm Exp $
 */

#include <vdr/plugin.h>
#include "daap_i18n.h"
#include "daap_menu.h"
#include "daap_client.h"
#include "daap_config.h"

cDaapConfiguration oConfig;
cDaapClient oDAAPClient;

static const char *DAAP_VERSION        = "0.0.1";
static const char *DAAP_DESCRIPTION    = "DAAP Client";
static const char *DAAP_MAINMENUENTRY  = "DAAP";

class cPluginDaap : public cPlugin {
private:
  // Add any member variables or functions you may need here.
public:
  cPluginDaap(void);
  virtual ~cPluginDaap();
  virtual const char *Version(void) { return DAAP_VERSION; }
  virtual const char *Description(void) { return tr(DAAP_DESCRIPTION); }
  virtual const char *CommandLineHelp(void);
  virtual bool ProcessArgs(int argc, char *argv[]);
  virtual bool Initialize(void);
  virtual bool Start(void);
  virtual void Stop(void);
  virtual void Housekeeping(void);
  virtual const char *MainMenuEntry(void) { return oConfig.allowMenuEntry() ? tr(DAAP_MAINMENUENTRY) : NULL; }
  virtual cOsdObject *MainMenuAction(void);
  virtual cMenuSetupPage *SetupMenu(void);
  virtual bool SetupParse(const char *Name, const char *Value);
  };

cPluginDaap::cPluginDaap(void)
{
  // Initialize any member variables here.
  // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
  // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
}

cPluginDaap::~cPluginDaap()
{
  // Clean up after yourself!
}

const char *cPluginDaap::CommandLineHelp(void)
{
  // Return a string that describes all known command line options.
  return NULL;
}

bool cPluginDaap::ProcessArgs(int argc, char *argv[])
{
  // Implement command line argument processing here if applicable.
  return true;
}

bool cPluginDaap::Initialize(void)
{
  // Initialize any background activities the plugin shall perform.
  RegisterI18n(tlPhrases);
  return true;
}

bool cPluginDaap::Start(void)
{
  // Start any background activities the plugin shall perform.
  oDAAPClient.Create();
  return true;
}

void cPluginDaap::Stop(void)
{
  // Stop any background activities the plugin shall perform.
  oDAAPClient.Destroy();
}

void cPluginDaap::Housekeeping(void)
{
  // Perform any cleanup or other regular tasks.
}

cOsdObject *cPluginDaap::MainMenuAction(void)
{
  // Perform the action when selected from the main VDR menu.
  return new cDaapMenu();
}

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

bool cPluginDaap::SetupParse(const char *Name, const char *Value)
{

  if (! strcasecmp(Name, "menuEntry"))
    oConfig.SetMenuEntry(atoi(Value));
  else if (! strcasecmp(Name, "instantPlaylistName"))
    oConfig.SetInstantPlaylistName(Value);
  else if (! strcasecmp(Name, "audioOnly"))
    oConfig.SetAudioOnly(atoi(Value));
  else if (! strcasecmp(Name, "skipBackMargin"))
    oConfig.SetSkipBackMargin(atoi(Value));
  else if (! strcasecmp(Name, "skipLength"))
    oConfig.SetSkipLength(atoi(Value));
  else
    return false;

  return true;
}

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