/***************************************************************************
                          commands.h  -  description
                             -------------------
    begin                : Sa Jan 15 2005
    copyright            : (C) 2005 by Holger Brunn
    email                : holger.brunn@stud.uni-karlsruhe.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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef ROASTER_COMMANDS_H
#define ROASTER_COMMANDS_H

#include <vdr/keys.h>
#include <vdr/osdbase.h>

#include <stdio.h>

#include "tools.h"
#ifdef ROASTER_PLUGIN_BUILD
#include "threads.h"
#endif
#include "statebag.h"
#include "menu-roaster.h"

// Forward declaration eMenuRoasterTask (from menu.h)
enum eMenuRoasterTask;

class cRoasterCommand
{
  protected:
    char* Name;
    char* Pattern;
    bool Confirm;
    bool UseDestination;
    bool UseCurrentFile;
    bool UseSelectedFiles;
    bool UseNewDestination;
    bool PatternIsShellscript;
    bool Synchronous;
    bool Menu;
    bool RemoveFinished;
    cRoasterStatebag* Statebag;
    cRoasterCommand(cRoasterStatebag* Statebag);
    bool MatchesSingleFile(const char* Filename);
    eOSState State;
  public:
    virtual ~cRoasterCommand();
    virtual char* GetName();
    virtual eKeys GetHotkey();
    virtual bool UsesDestination() { return UseDestination || UseNewDestination; };
    virtual bool UsesCurrentFile() { return UseCurrentFile; };
    virtual bool UsesSelectedFiles() { return UseSelectedFiles; };
    virtual bool UsesNewDestination() { return UseNewDestination; };
    virtual bool Matches(const char* Filename);
    virtual bool MatchesDestination(const char* Filename) { return true; };
    virtual bool NeedsConfirmation() { return Confirm; };
    virtual bool IsSynchronous() { return Synchronous; };
    virtual bool ShowMenu() { return Menu; };
    virtual bool RemoveWhenFinished() { return RemoveFinished; };
    virtual bool Execute(cOsdMenu* Menu, char* DestinationFile, char* CurrentFile);
    virtual eMenuRoasterTask Task() { return taskBrowse; };
    virtual eOSState GetState() { return State; };
};

class cRoasterConfigCommand : public cRoasterCommand
{
  protected:
    char* Command;
    static char* FlagHandler(const char* OrgString, const char* CurrentPos, const cCommandParser::cHandlerParameters* Params);
  public:
    cRoasterConfigCommand(cRoasterStatebag* Statebag);
    ~cRoasterConfigCommand();
    static cRoasterConfigCommand* Parse(char* Config, cRoasterStatebag* Statebag);
    bool Execute(cOsdMenu* Menu, char* DestinationFile, char* CurrentFile);
    char* GetCommand();
};

class cRoasterDestinationNewCommand : public cRoasterCommand
{
  public:
    cRoasterDestinationNewCommand(cRoasterStatebag* Statebag);
    bool Execute(cOsdMenu* Menu, char* DestinationFile, char* CurrentFile);
    bool Matches(const char* Filename);
    virtual eMenuRoasterTask Task() { return taskSelectDestination; };
};

class cRoasterDestinationContainerCommand : public cRoasterCommand
{
  protected:
    cRoasterCommand* Command;
    char* CurrentFile;
    char* DestinationFile;
  public:
    cRoasterDestinationContainerCommand(cRoasterCommand* Command, char* CurrentFile, cRoasterStatebag* Statebag);
    ~cRoasterDestinationContainerCommand();
    bool Execute(cOsdMenu* Menu, char* DestinationFile, char* CurrentFile);
    bool Matches(const char* Filename);
};

class cRoasterDestinationAbortCommand : public cRoasterCommand
{
  public:
    cRoasterDestinationAbortCommand(cRoasterStatebag* Statebag);
    bool Execute(cOsdMenu* Menu, char* DestinationFile, char* CurrentFile);
    bool Matches(const char* Filename);
};

#ifdef ROASTER_PLUGIN_BUILD

class cRoasterCommandThreadList : public cRoasterCommand
{
  public:
    cRoasterCommandThreadList(cRoasterStatebag* Statebag);
    bool Execute(cOsdMenu* Menu, char* DestinationFile, char* SelectedFile);
    bool Matches(const char* Filename);
};

#endif

class cRoasterCommandContainer : public cListContainer<cRoasterCommand>
{
  public:
    cRoasterCommandContainer(cRoasterCommand* Object, bool DelOnFree=true) : cListContainer<cRoasterCommand>(Object, DelOnFree) {};
    cRoasterCommandContainer* Next() { return (cRoasterCommandContainer*)cListContainer<cRoasterCommand>::Next(); };
    cRoasterCommandContainer* Prev() { return (cRoasterCommandContainer*)cListContainer<cRoasterCommand>::Prev(); };
};

class cRoasterCommands : public cList<cRoasterCommandContainer> {};

#endif
