/*
 * statusandquestion: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id: messages.h 0.1 2004/07/11 14:12:20 hflor Exp $
 */

#ifndef __MESSAGES_H
#define __MESSAGES_H

#include <vdr/keys.h>

enum eMessageTyp {
  MessageTyp_min        = 0,
  MessageTyp_Status     = 0,  // same value in skins.h for choise color
  MessageTyp_Info       = 1,  // same value in skins.h for choise color
  MessageTyp_Warning    = 2,  // same value in skins.h for choise color
  MessageTyp_Error      = 3,  // same value in skins.h for choise color
  MessageTyp_Text       = 4,  // test with <= MessageTyp_Text
  MessageTyp_VDRStatus  = 5,
  MessageTyp_Param      = 6,
  MessageTyp_SetTime    = 7,
  MessageTyp_none       = 8 };

enum eMenuTyp {
     MenuTyp_Title = 0,
     MenuTyp_Red,
     MenuTyp_Green,
     MenuTyp_Yellow,
     MenuTyp_Blue };

const char *MessageTypName(eMessageTyp MessageTyp);
const char *MessageTypNameShort(eMessageTyp MessageTyp);

class cMessageData {
private:
  eMessageTyp messagetyp;
  char   *text;
  char   *textorg;
  char   *menu[5];
  int    timeout;
  int    usecount;
  int    id;
  eKeys  key;
  time_t receivetime;
  time_t responsetime;
public:
  cMessageData(eMessageTyp MessageTyp);
  virtual ~cMessageData(void);
  eMessageTyp MessageTyp(void) { return messagetyp; }
  char *Text(void) { return text; }
  char *Textorg(void) { return textorg; }
  const char *Menu(eMenuTyp Choise) { return Choise < MenuTyp_Title || Choise > MenuTyp_Blue ? NULL : menu[Choise]; }
  int Timeout(void) { return timeout; }
  int ID(void) { return id; }
  eKeys Key(void) { return key; }
  const time_t ReceiveTime(void) { return receivetime; }
  const time_t ResponseTime(void) { return responsetime; }
  void SetTimeout(int Timeout);
  void SetText(const char *Text);
  void SetMenu(eMenuTyp Choise, const char *Text);
  void SetKey(eKeys Key);
  void IncUseCount(void) { usecount++; }
  bool DecUseCount(void) { return --usecount == 0; }
  };

class cMessage : public cListObject {
private:
  cMessageData *messagedata;
public:
  cMessage(cMessageData *MessageData);
  virtual ~cMessage(void);
// methods from cMessageData
  cMessageData *MessageData(void)                  { return messagedata; }
  eMessageTyp MessageTyp(void)                     { return messagedata->MessageTyp(); }
  char *Text(void)                                 { return messagedata->Text(); }
  char *Textorg(void)                              { return messagedata->Textorg(); }
  const char *Menu(eMenuTyp Choise)                { return messagedata->Menu(Choise); }
  int Timeout(void)                                { return messagedata->Timeout(); }
  int ID(void)                                     { return messagedata->ID(); }
  eKeys Key(void)                                  { return messagedata->Key(); }
  const time_t ReceiveTime(void)                   { return messagedata->ReceiveTime(); }
  const time_t ResponseTime(void)                  { return messagedata->ResponseTime(); }
  };

class cMessages : public cList<cMessage> {
private:
  int lock;
public:
  bool GetLock(void) { return lock != 0; }
  bool SetLock(bool Lock, bool Wait = false);
  cMessage *SearchMessage(cMessageData *MessageData);
  };

extern cMessages Messages;
extern cMessages Responses;
extern cMessages History;

#endif //__MESSAGES_H
