/*
    Copyright 2004-2005 Chris Tallon

    This file is part of VOMP.

    VOMP 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.

    VOMP 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 VOMP; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef REMOTE_H
#define REMOTE_H

#include <stdio.h>
#include <map>

#include "defines.h"
#include "abstractoption.h"


using namespace std;
typedef map<ULLONG,UCHAR> RemoteTranslationList;

class Remote: public AbstractOption
{
  public:
    Remote();
    virtual ~Remote();
    static Remote* getInstance();

    bool addOptionPagesToWTB(WTabBar *wtb);
    bool loadOptionsfromServer(VDR* vdr);
    bool saveOptionstoServer();

    void setRemoteType(UCHAR type);
    void setHWCtoCommand(ULLONG hcw,UCHAR command);
    void unsetHWC(ULLONG hcw);
    void LoadKeysConfig(VDR *vdr,const char*keynum);
    void SaveKeysConfig();
    void EnterLearningMode(UCHAR command);

    virtual int init(char *devName)=0;
    virtual int shutdown()=0;
    virtual UCHAR getButtonPress(int how)=0;
    virtual void clearBuffer()=0;

    virtual bool mayHaveFewButtons() {return false;};

    virtual bool handlesVolume() {return false;};
    virtual void volumeUp() {};
    virtual void volumeDown() {};
    virtual void volumeMute() {};

    virtual void InitHWCListwithDefaults();
    virtual char* HCWDesc(ULLONG hcw);
    const char *CommandDesc(UCHAR number);
    char *CommandTranslateStr(UCHAR command);
    virtual const char*HardcodedTranslateStr(UCHAR command);
    void EnterLearnMode(UCHAR command);
    void ResetToDefault();

    virtual void changePowerState(bool poweron) {}; //informs the remote control, that about vomp's power state, this is important e.g. for cec

    const static ULONG NOLEARNMODE = 256;
    // Not buttons
    const static UCHAR NA_LEARN    = 101;
    const static UCHAR NA_NONE     = 98;
    const static UCHAR NA_UNKNOWN  = 99;
    const static UCHAR NA_SIGNAL   = 100;
    const static UCHAR DF_UP       = 94;
    const static UCHAR DF_DOWN     = 95;
    const static UCHAR DF_LEFT     = 96;
    const static UCHAR DF_RIGHT    = 97;

    // Problem common buttons
    const static UCHAR VOLUMEUP    = 16;
    const static UCHAR VOLUMEDOWN  = 17;
    const static UCHAR CHANNELUP   = 32;
    const static UCHAR CHANNELDOWN = 33;

    // Common buttons
    const static UCHAR ZERO        = 0;
    const static UCHAR ONE         = 1;
    const static UCHAR TWO         = 2;
    const static UCHAR THREE       = 3;
    const static UCHAR FOUR        = 4;
    const static UCHAR FIVE        = 5;
    const static UCHAR SIX         = 6;
    const static UCHAR SEVEN       = 7;
    const static UCHAR EIGHT       = 8;
    const static UCHAR NINE        = 9;
    const static UCHAR POWER       = 61;
    const static UCHAR GO          = 59;
    const static UCHAR BACK        = 31;
    const static UCHAR MENU        = 13;
    const static UCHAR RED         = 11;
    const static UCHAR GREEN       = 46;
    const static UCHAR YELLOW      = 56;
    const static UCHAR BLUE        = 41;
    const static UCHAR MUTE        = 15;
    const static UCHAR RADIO       = 12; // The unlabelled button on old
    const static UCHAR REVERSE     = 50;
    const static UCHAR PLAY        = 53;
    const static UCHAR FORWARD     = 52;
    const static UCHAR RECORD      = 55;
    const static UCHAR STOP        = 54;
    const static UCHAR PAUSE       = 48;
    const static UCHAR SKIPBACK    = 36;
    const static UCHAR SKIPFORWARD = 30;
    const static UCHAR OK          = 37;

    // Old remote only
    const static UCHAR FULL        = 60;

    // New remote only
    const static UCHAR TV          = 28;
    const static UCHAR VIDEOS      = 24;
    const static UCHAR MUSIC       = 25;
    const static UCHAR PICTURES    = 26;
    const static UCHAR GUIDE       = 27;
    const static UCHAR UP          = 20;
    const static UCHAR DOWN        = 21;
    const static UCHAR LEFT        = 22;
    const static UCHAR RIGHT       = 23;
    const static UCHAR PREVCHANNEL = 18;
    const static UCHAR STAR        = 10;
    const static UCHAR HASH        = 14;

    // Android only
    const static UCHAR PLAYPAUSE       = 201;
    // cec only
    const static UCHAR POWERON       = 202;
    const static UCHAR POWEROFF       = 203;


    // Remote types
    const static UCHAR OLDREMOTE   = 1;
    const static UCHAR NEWREMOTE   = 2;

  protected:
    virtual UCHAR TranslateHWCFixed(ULLONG code);
    UCHAR TranslateHWCList(ULLONG code);
    UCHAR TranslateHWC(ULLONG code);
    

    ULONG learnmode;
    static Remote* instance;
    UCHAR remoteType;
    RemoteTranslationList translist;
};

#endif
