#include "i18n.h"
#include "setup.h"
#include "soundtest.h"
#include "viewer.h"
#include <vdr/plugin.h>
#include <getopt.h>

static const char *VERSION        = "0.0.5";
static const char *DESCRIPTION    = "Soundtest";
static const char *MAINMENUENTRY  = "Soundtest";

int doexit;

// --- cPluginSoundtest --------------------------------------------------------

cPluginSoundTest::cPluginSoundTest(void) {
//    isyslog("cPluginSoundTest::cPluginSoundTest()");
}

cPluginSoundTest::~cPluginSoundTest() {
    doexit++;
//    isyslog("cPluginSoundTest::~cPluginSoundTest()");
}

const char *cPluginSoundTest::Version(void) {
//    isyslog("cPluginSoundTest::Version()");
    return VERSION;
}

const char *cPluginSoundTest::Description(void) {
//    isyslog("cPluginSoundTest::Description()");
    return tr(DESCRIPTION);
}

const char *cPluginSoundTest::CommandLineHelp(void) {
//    isyslog("cPluginSoundTest::CommandLineHelp()");
    return
     "  -c Device, --device=device  optional path for device to use\n"
     "                                       (default: '/dev/dsp')\n";
}

bool cPluginSoundTest::ProcessArgs(int argc, char *argv[]) {
//    isyslog("cPluginSoundTest::ProcessArgs(%d,...)", argc);
    static struct option long_options[] = {
      { "device", required_argument, NULL, 'c' },
      { NULL }
    };
    int c, option_index = 0;
    while ((c = getopt_long(argc, argv, "c:", long_options, &option_index)) != -1) {
	switch (c) {
	    case 'c':	strcpy(SoundtestSetup.device, optarg);
			SoundtestSetup.commandlinedevice = true;
			break;
	    default:  
    			break;
      }
    }
    return true;
}

bool cPluginSoundTest::Start(void) {
//    isyslog("cPluginSoundTest::Start()");
    RegisterI18n(Phrases);
    return true;
}

void cPluginSoundTest::Stop(void) {
//    isyslog("cPluginSoundTest::Stop()");
    doexit++;
}

void cPluginSoundTest::Housekeeping(void) {
//    isyslog("cPluginSoundTest::Housekeeping()");
}

const char *cPluginSoundTest::MainMenuEntry(void) {
//    isyslog("cPluginSoundTest::MainMenuEntry()");
    return (SoundtestSetup.hidemenu ? NULL : MAINMENUENTRY);
}

cOsdObject *cPluginSoundTest::MainMenuAction(void) {
//    isyslog("cPluginSoundTest::MainMenuAction()");
    return new cViewerObject;
}

cMenuSetupPage *cPluginSoundTest::SetupMenu(void) {
//    isyslog("cPluginSoundTest::SetupMenu()");
    return new cSoundtestSetupPage;
}

bool cPluginSoundTest::SetupParse(const char *Name, const char *Value) {
//    isyslog("PluginSoundTest::SetupParse(%s,%s)", Name, Value);
    return SoundtestSetup.SetupParse(Name, Value);
}

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