/*
 * pin.c: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * Date: 11.04.05 - 27.12.05, horchi
 */

#ifndef VDR_PIN_LOCKS_H
#define VDR_PIN_LOCKS_H

//***************************************************************************
// Includes
//***************************************************************************

#include <vdr/tools.h>
#include <vdr/config.h>

#include "def.h"

//***************************************************************************
// Locked Broadcast
//***************************************************************************

class cLockedBroadcast : public cListObject
{     
   public:

      enum SearchMode
      {
         smUnknown = na,

         smRegexp,
         smInclude,
         smExact,

         smCount
      };

      cLockedBroadcast();
      cLockedBroadcast(const char* aName);
      virtual ~cLockedBroadcast();

      // interface

      bool Parse(char* line);
      bool Save(FILE* file);

      // tests

      int Locked();
      bool HasName(const char* aName);
      bool MatchPattern(const char* aPattern);
      
      // gettings

      int GetActive()                  { return active; }
      const char* GetName()            { return name; }
      const char* GetPattern()         { return pattern; }
      int SearchMode()                 { return searchMode; }

      // settings

      void SetActive(int aActive)      { active = aActive; }
      void SetSearchMode(int aMode)    { searchMode = aMode; }
      void SetName(const char* aName);
      void SetPattern(const char* aPattern);

      static const char* searchModes[smCount+1];

   private:
   
      char* name;
      char* pattern;
      int active;
      int searchMode;
};


//***************************************************************************
// Locked Broadcasts
//***************************************************************************

class cLockedBroadcasts : public cConfig<cLockedBroadcast>
{
   public:
   
      int Locked(const char* aPattern);
};

//***************************************************************************
// Locked Channel
//***************************************************************************

class cLockItem : public cListObject
{     
   public:
   
      cLockItem();
      cLockItem(const char* aName, int aActive = yes);
      virtual ~cLockItem();
      
      // interface

      bool Parse(char* line);
      bool Save(FILE* file);

      // tests

      int Locked(long startTime = 0);
      bool HasName(const char* aName);
      
      // gettings

      int GetActive()           { return active; }
      const char* GetName()     { return name; }
      long GetStart()           { return start; }
      long GetEnd()             { return end; }
      char* GetStart(char* ct)  { return DT::int2Hhmm(start, ct); }
      char* GetEnd(char* ct)    { return DT::int2Hhmm(end, ct); }

      // settings

      void SetActive(int aActive)      { active = aActive; }
      void SetName(const char* aName);
      void SetStart(const char* ct)    { start = DT::hhmm2Int(ct); }
      void SetEnd(const char* ct)      { end = DT::hhmm2Int(ct); }
      void SetStart(long lt)           { start = lt; }
      void SetEnd(long lt)             { end = lt; }

   private:
   
      char* name;
      long start;         // in seconds
      long end;           // in seconds
      int active;
};

//***************************************************************************
// Locked Channels
//***************************************************************************

class cLockItems : public cConfig<cLockItem>
{
   public:
   
      int Locked(const char* aName, long startTime = 0);
      cLockItem* FindByName(const char* aName);
};

//***************************************************************************
#endif // VDR_PIN_LOCKS_H
