#ifndef __EPGSEARCHEXT_H
#define __EPGSEARCHEXT_H

#include <vdr/menu.h>
#include <vdr/menuitems.h>
#include <vdr/status.h>
#include <vdr/plugin.h>
#include <vdr/interface.h>
#include <vdr/skins.h>

#define MAXOSDTEXTWIDTH 45
#define ERROR(T) Skins.Message(mtError, T)
#define INFO(I)  Skins.Message(mtInfo, I)


class cSearchExt : public cListObject {
  friend class cMenuEditSearchExt;
public:
  char     search[MaxFileName];
  int      options;
  int      useTime;
  int      startTime;
  int      stopTime;
  int      useChannel;
  int      useCase;
  int      mode;
  int      useTitle;
  int      useSubtitle;
  int      useDescription;
  int      useDuration;
  int      minDuration;
  int      maxDuration;
  int      useAsSearchTimer;
  int      useDayOfWeek;
  int      DayOfWeek;
  int      useEpisode;
  char     directory[MaxFileName];
  int      Priority;
  int      Lifetime;
  int      MarginStart;
  int      MarginStop;
  int      useVPS;
  int      announceOnly;
  int      useExtEPGInfo;
  char**   catvalues;
  cChannel *channelMin;
  cChannel *channelMax;
  char*    channelGroup;

  static char *buffer;
public:
  cSearchExt(void);
  virtual ~cSearchExt(void);
  cSearchExt& operator= (const cSearchExt &SearchExt);
  virtual bool operator< (const cListObject &ListObject);

  const char *Search(void) { return search; }
  int Options(void) { return options; }
  int StartTime(void) { return startTime; }
  int StopTime(void) { return stopTime; }
  int UseChannel(void) { return useChannel; }
  cChannel *ChannelMin(void) { return channelMin; }
  cChannel *ChannelMax(void) { return channelMax; }
  cEvent * GetEventBySearchExt(const cSchedule *schedules, const cEvent *Start);
  bool MatchesExtEPGInfo(const cEvent* e);
  const char *ToText(void);
  bool Parse(const char *s);
  bool ParseExtEPGValues(const char *s);
  bool ParseExtEPGEntry(const char *s);
  bool Save(FILE *f);
  char* BuildFile(const cEvent* pEvent);
  };

class cSearchExts : public cConfig<cSearchExt> {
private:
public:
  cSearchExts(void);
  };

extern cSearchExts SearchExts;

// --- cMenuEditSearchExt --------------------------------------------------------

class cMenuEditSearchExt : public cOsdMenu {
private:
  cSearchExt *searchExt;
  cSearchExt data;
  int channelMin;
  int channelMax;
  int useTime;
  bool addIfConfirmed;
  int UserDefDayOfWeek;
  int* catselection;
  int channelGroupNr;
  char* channelGroupName;
  char** menuitemsChGr;

public:
  cMenuEditSearchExt(cSearchExt *SearchExt, bool New = false);
  virtual ~cMenuEditSearchExt();
  void Set();
  void CreateMenuitemsChannelGroups();
  virtual eOSState ProcessKey(eKeys Key);
  };
 
class cMenuEPGSearchExt : public cOsdMenu {
  private:
	eOSState New(void);
	eOSState Delete(void);
  protected:
    	virtual eOSState ProcessKey(eKeys Key);
  public:
    	cMenuEPGSearchExt();
	cSearchExt* CurrentSearchExt(void);
	eOSState Search(void);
	eOSState OnOffSearchtimer(void);
};

// --- cMenuEditDaysOfWeek --------------------------------------------------------

class cMenuEditDaysOfWeek : public cOsdMenu {
private:
  int* pDaysOfWeek;
  int Days[7];
  int offset;
  bool negate;
public:
  cMenuEditDaysOfWeek(int* DaysOfWeek, int Offset=0, bool Negate = true);
  virtual eOSState ProcessKey(eKeys Key);
  };

#endif
