vdr-plugin-streamdev/server/menuHTTP.h

214 lines
6.1 KiB
C
Raw Normal View History

2008-03-28 16:13:11 +01:00
#ifndef VDR_STREAMDEV_SERVERS_MENUHTTP_H
#define VDR_STREAMDEV_SERVERS_MENUHTTP_H
#include <string>
#include "../common.h"
#include <vdr/recording.h>
2008-03-28 16:13:11 +01:00
class cChannel;
2013-02-03 11:02:25 +01:00
// ******************** cItemIterator ******************
class cItemIterator
{
public:
virtual bool Next() = 0;
virtual bool IsGroup() const = 0;
virtual const cString ItemId() const = 0;
virtual const char* ItemTitle() const = 0;
virtual const cString ItemRessource() const = 0;
virtual const char* Alang(int i) const = 0;
virtual const char* Dlang(int i) const = 0;
2013-10-20 17:40:22 +02:00
virtual ~cItemIterator() {};
2013-02-03 11:02:25 +01:00
};
class cRecordingsIterator: public cItemIterator
{
private:
const cRecording *first;
const cRecording *current;
cThreadLock RecordingsLock;
public:
virtual bool Next();
virtual bool IsGroup() const { return false; }
virtual const cString ItemId() const { return current ? itoa(current->Index() + 1) : "0"; }
virtual const char* ItemTitle() const { return current ? current->Title() : ""; }
virtual const cString ItemRessource() const;
virtual const char* Alang(int i) const { return NULL; }
virtual const char* Dlang(int i) const { return NULL; }
cRecordingsIterator();
virtual ~cRecordingsIterator() {};
};
2013-02-03 11:02:25 +01:00
class cChannelIterator: public cItemIterator
2008-03-28 16:13:11 +01:00
{
private:
2013-02-03 11:02:25 +01:00
const cChannel *first;
const cChannel *current;
2008-03-28 16:13:11 +01:00
protected:
virtual const cChannel* NextChannel(const cChannel *Channel) = 0;
2010-12-02 09:57:17 +01:00
static inline const cChannel* SkipFakeGroups(const cChannel *Channel);
2013-02-03 11:02:25 +01:00
// Helper which returns the group by its index
static const cChannel* GetGroup(const char* GroupId);
2008-03-28 16:13:11 +01:00
public:
2013-02-03 11:02:25 +01:00
virtual bool Next();
virtual bool IsGroup() const { return current && current->GroupSep(); }
virtual const cString ItemId() const;
virtual const char* ItemTitle() const { return current ? current->Name() : ""; }
virtual const cString ItemRessource() const { return (current ? current->GetChannelID() : tChannelID::InvalidID).ToString(); }
virtual const char* Alang(int i) const { return current && current->Apid(i) ? current->Alang(i) : NULL; }
virtual const char* Dlang(int i) const { return current && current->Dpid(i) ? current->Dlang(i) : NULL; }
2010-12-02 09:57:17 +01:00
cChannelIterator(const cChannel *First);
2008-03-28 16:13:11 +01:00
virtual ~cChannelIterator() {};
};
class cListAll: public cChannelIterator
{
protected:
virtual const cChannel* NextChannel(const cChannel *Channel);
public:
cListAll();
virtual ~cListAll() {};
};
class cListChannels: public cChannelIterator
{
protected:
virtual const cChannel* NextChannel(const cChannel *Channel);
public:
cListChannels();
virtual ~cListChannels() {};
};
class cListGroups: public cChannelIterator
{
protected:
virtual const cChannel* NextChannel(const cChannel *Channel);
public:
cListGroups();
virtual ~cListGroups() {};
};
class cListGroup: public cChannelIterator
{
2010-12-02 09:57:17 +01:00
private:
static const cChannel* GetNextChannelInGroup(const cChannel *Channel);
2008-03-28 16:13:11 +01:00
protected:
virtual const cChannel* NextChannel(const cChannel *Channel);
public:
2013-02-03 11:02:25 +01:00
cListGroup(const char *GroupId);
2008-03-28 16:13:11 +01:00
virtual ~cListGroup() {};
};
class cListTree: public cChannelIterator
{
private:
const cChannel* selectedGroup;
const cChannel* currentGroup;
protected:
virtual const cChannel* NextChannel(const cChannel *Channel);
public:
2013-02-03 11:02:25 +01:00
cListTree(const char *SelectedGroupId);
2008-03-28 16:13:11 +01:00
virtual ~cListTree() {};
};
2013-02-03 11:02:25 +01:00
// ******************** cMenuList ******************
class cMenuList
2008-03-28 16:13:11 +01:00
{
private:
2013-02-03 11:02:25 +01:00
cItemIterator *iterator;
2008-03-28 16:13:11 +01:00
protected:
2013-02-03 11:02:25 +01:00
bool NextItem() { return iterator->Next(); }
bool IsGroup() { return iterator->IsGroup(); }
const cString ItemId() { return iterator->ItemId(); }
const char* ItemTitle() { return iterator->ItemTitle(); }
const cString ItemRessource() { return iterator->ItemRessource(); }
const char* Alang(int i) { return iterator->Alang(i); }
const char* Dlang(int i) { return iterator->Dlang(i); }
2008-03-28 16:13:11 +01:00
public:
virtual std::string HttpHeader() { return "HTTP/1.0 200 OK\r\n"; };
virtual bool HasNext() = 0;
virtual std::string Next() = 0;
2013-02-03 11:02:25 +01:00
cMenuList(cItemIterator *Iterator);
virtual ~cMenuList();
2008-03-28 16:13:11 +01:00
};
2013-02-03 11:02:25 +01:00
class cHtmlMenuList: public cMenuList
2008-03-28 16:13:11 +01:00
{
private:
static const char* menu;
static const char* css;
static const char* js;
enum eHtmlState {
hsRoot, hsHtmlHead, hsCss, hsJs, hsPageTop, hsPageBottom,
hsGroupTop, hsGroupBottom,
hsPlainTop, hsPlainItem, hsPlainBottom,
hsItemsTop, hsItem, hsItemsBottom
};
eHtmlState htmlState;
2013-02-03 11:02:25 +01:00
bool onItem;
2008-03-28 16:13:11 +01:00
eStreamType streamType;
const char* self;
2013-02-02 23:28:55 +01:00
const char* rss;
2008-03-28 16:13:11 +01:00
const char* groupTarget;
std::string StreamTypeMenu();
std::string HtmlHead();
std::string PageTop();
std::string GroupTitle();
std::string ItemText();
std::string PageBottom();
public:
virtual std::string HttpHeader() {
2013-02-03 11:02:25 +01:00
return cMenuList::HttpHeader()
+ "Content-type: text/html; charset="
+ (cCharSetConv::SystemCharacterTable() ? cCharSetConv::SystemCharacterTable() : "UTF-8")
+ "\r\n";
}
2008-03-28 16:13:11 +01:00
virtual bool HasNext();
virtual std::string Next();
2013-02-03 11:02:25 +01:00
cHtmlMenuList(cItemIterator *Iterator, eStreamType StreamType, const char *Self, const char *Rss, const char *GroupTarget);
virtual ~cHtmlMenuList();
2008-03-28 16:13:11 +01:00
};
2013-02-03 11:02:25 +01:00
class cM3uMenuList: public cMenuList
2008-03-28 16:13:11 +01:00
{
private:
char *base;
enum eM3uState { msFirst, msContinue, msLast };
eM3uState m3uState;
cCharSetConv m_IConv;
public:
2013-02-03 11:02:25 +01:00
virtual std::string HttpHeader() { return cMenuList::HttpHeader() + "Content-type: audio/x-mpegurl; charset=UTF-8\r\n"; };
2008-03-28 16:13:11 +01:00
virtual bool HasNext();
virtual std::string Next();
2013-02-03 11:02:25 +01:00
cM3uMenuList(cItemIterator *Iterator, const char* Base);
virtual ~cM3uMenuList();
2008-03-28 16:13:11 +01:00
};
2013-02-03 11:02:25 +01:00
class cRssMenuList: public cMenuList
2013-02-02 23:28:55 +01:00
{
private:
char *base;
char *html;
enum eRssState { msFirst, msContinue, msLast };
eRssState rssState;
cCharSetConv m_IConv;
public:
2013-02-03 11:02:25 +01:00
virtual std::string HttpHeader() { return cMenuList::HttpHeader() + "Content-type: application/rss+xml\r\n"; };
2013-02-02 23:28:55 +01:00
virtual bool HasNext();
virtual std::string Next();
2013-02-03 11:02:25 +01:00
cRssMenuList(cItemIterator *Iterator, const char *Base, const char *Html);
virtual ~cRssMenuList();
2013-02-02 23:28:55 +01:00
};
2010-12-02 09:57:17 +01:00
inline const cChannel* cChannelIterator::SkipFakeGroups(const cChannel* Group)
{
while (Group && Group->GroupSep() && !*Group->Name())
Group = Channels.Next(Group);
return Group;
}
2008-03-28 16:13:11 +01:00
#endif