/*
 * amarok.c: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */

#include <vdr/plugin.h>
#include "menuAmarok.h"
#include "commands.h"
#include "menuAmarokSetup.h"
#include "amarok_i18n.h"

static const char *VERSION        = "0.0.2";
static const char *DESCRIPTION    = "A frontend for KDE's amarok";
static const char *MAINMENUENTRY  = "amaroK";

AmarokConfig g_amarokConfig;

class cPluginAmarok : public cPlugin
{
private:
    // Add any member variables or functions you may need here.
public:
    cPluginAmarok(void);
    virtual ~cPluginAmarok();
    virtual const char *Version(void)
    {
        return VERSION;
    }
    virtual const char *Description(void)
    {
        return 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 void MainThreadHook(void);
    virtual cString Active(void);
    virtual const char *MainMenuEntry(void)
    {
        return MAINMENUENTRY;
    }
    virtual cOsdObject *MainMenuAction(void);
    virtual cMenuSetupPage *SetupMenu(void);
    virtual bool SetupParse(const char *Name, const char *Value);
    virtual bool Service(const char *Id, void *Data = NULL);
    virtual const char **SVDRPHelpPages(void);
    virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode);
};

cPluginAmarok::cPluginAmarok(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!
}

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

const char *cPluginAmarok::CommandLineHelp(void)
{
    // Return a string that describes all known command line options.
    return "no command line options available";
    // @todo
    /*   return " -h server,  --host=server      setup amaroK vdr gateway (default: localhost)\n"
       " -P port,    --Port=PORT        setup port of amaroK vdr gateway (default: 8173)\n"
       " -u user,    --user=file        user login name of gateway host (default: amarok)\n"
       " -p pword,   --passwd=PASSWORD  user login password of gateway (default: secret)\n";
    */
}

bool cPluginAmarok::ProcessArgs(int argc, char *argv[])
{
    // Implement command line argument processing here if applicable.
    // @todo
    /*    static struct option long_options[] =
            {
                { "host",      required_argument, NULL, 'h'
                },
                { "Port",       required_argument, NULL, 'P' },
                { "user",       required_argument, NULL, 'u' },
                { "passwd",     required_argument, NULL, 'p' },
                { NULL }
            };
     
        int c;
        while ((c = getopt_long(argc, argv, "h:P:u:p:", long_options, NULL)) != -1)
        {
            switch (c)
            {
            case 'h':
                break;
            case 'P':
                break;
            case 'u':
                break;
            case 'p':
                break;
            default:
                return false;
            }
        }*/
    return true;
}

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

bool cPluginAmarok::Start(void)
{
    RegisterI18n(tlPhrases);
    // Start any background activities the plugin shall perform.
    g_amarokConfig.p_ConfigDir = strdup (ConfigDirectory(Name()));
    return true;
}

void cPluginAmarok::Stop(void)
{
    // Stop any background activities the plugin shall perform.
}

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

void cPluginAmarok::MainThreadHook(void)
{
    // Perform actions in the context of the main program thread.
    // WARNING: Use with great care - see PLUGINS.html!
}

cString cPluginAmarok::Active(void)
{
    // Return a message string if shutdown should be postponed
    return NULL;
}

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

cMenuSetupPage *cPluginAmarok::SetupMenu(void)
{
    return new cMenuAmarokSetup;
}

bool cPluginAmarok::SetupParse(const char *Name, const char *Value)
{
    // Parse your own setup parameters and store their values.
    return g_amarokConfig.SetupParse(Name, Value );
}

bool cPluginAmarok::Service(const char *Id, void *Data)
{
    // Handle custom service requests from other plugins
    return false;
}

const char **cPluginAmarok::SVDRPHelpPages(void)
{
    // Return help text for SVDRP commands this plugin implements
    return NULL;
}

cString cPluginAmarok::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode)
{
    // Process SVDRP commands this plugin implements
    return NULL;
}

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