diff options
author | Dieter Hametner <dh (plus) vdr (at) gekrumbel (dot) de> | 2008-11-23 16:02:50 +0100 |
---|---|---|
committer | Dieter Hametner <dh (plus) vdr (at) gekrumbel (dot) de> | 2008-11-23 16:02:50 +0100 |
commit | a50450088499f585170712385e758b08ceb67abd (patch) | |
tree | 595ad47b2ade06b4ea207f1f6040a309533bd148 | |
parent | 11b2c7792efd10b513469bf8144c874f8e419cb1 (diff) | |
download | vdr-plugin-live-a50450088499f585170712385e758b08ceb67abd.tar.gz vdr-plugin-live-a50450088499f585170712385e758b08ceb67abd.tar.bz2 |
Exchanged EpgEvents class by a namespace, as the class had only static
methods.
-rw-r--r-- | epg_events.cpp | 211 | ||||
-rw-r--r-- | epg_events.h | 109 | ||||
-rw-r--r-- | pages/timers.ecpp | 1 | ||||
-rw-r--r-- | pages/whats_on.ecpp | 1 |
4 files changed, 169 insertions, 153 deletions
diff --git a/epg_events.cpp b/epg_events.cpp index b8ba70d..b95443d 100644 --- a/epg_events.cpp +++ b/epg_events.cpp @@ -51,6 +51,11 @@ namespace vdrlive return EpgEvents::ElapsedTime(GetStartTime(), GetEndTime()); } + int EpgInfo::Duration() const + { + return EpgEvents::Duration(GetStartTime(), GetEndTime()); + } + /* * ------------------------------------------------------------------------- * EpgEvent @@ -201,9 +206,9 @@ namespace vdrlive * ------------------------------------------------------------------------- */ - EmptyEvent::EmptyEvent(std::string const &id, tChannelID const &channelID, const char* channelName) : - EpgInfo(id, channelName), - m_channelID(channelID) + EmptyEvent::EmptyEvent(std::string const &id, tChannelID const &channelID, const char* channelName) : + EpgInfo(id, channelName), + m_channelID(channelID) { } @@ -216,128 +221,122 @@ namespace vdrlive * EpgEvents * ------------------------------------------------------------------------- */ + namespace EpgEvents { + string EncodeDomId(tChannelID const &chanId, tEventID const &eId) + { + string channelId(chanId.ToString()); + string eventId("event_"); - EpgEvents::EpgEvents() - { - } - - EpgEvents::~EpgEvents() - { - } - - string EpgEvents::EncodeDomId(tChannelID const &chanId, tEventID const &eId) - { - string channelId(chanId.ToString()); - string eventId("event_"); - - channelId = vdrlive::EncodeDomId(channelId, ".-", "pm"); - // replace(channelId.begin(), channelId.end(), '.', 'p'); - // replace(channelId.begin(), channelId.end(), '-', 'm'); + channelId = vdrlive::EncodeDomId(channelId, ".-", "pm"); - eventId += channelId; - eventId += '_'; - eventId += lexical_cast<std::string>(eId); - return eventId; - } + eventId += channelId; + eventId += '_'; + eventId += lexical_cast<std::string>(eId); + return eventId; + } - void EpgEvents::DecodeDomId(string const &epgid, tChannelID& channelId, tEventID& eventId) - { - string const eventStr("event_"); + void DecodeDomId(string const &epgid, tChannelID& channelId, tEventID& eventId) + { + string const eventStr("event_"); - size_t delimPos = epgid.find_last_of('_'); - string cIdStr = epgid.substr(eventStr.length(), delimPos - eventStr.length()); + size_t delimPos = epgid.find_last_of('_'); + string cIdStr = epgid.substr(eventStr.length(), delimPos - eventStr.length()); - cIdStr = vdrlive::DecodeDomId(cIdStr, "mp", "-."); - // replace(cIdStr.begin(), cIdStr.end(), 'm', '-'); - // replace(cIdStr.begin(), cIdStr.end(), 'p', '.'); + cIdStr = vdrlive::DecodeDomId(cIdStr, "mp", "-."); - string const eIdStr = epgid.substr(delimPos+1); + string const eIdStr = epgid.substr(delimPos+1); - channelId = tChannelID::FromString(cIdStr.c_str()); - eventId = lexical_cast<tEventID>(eIdStr); - } + channelId = tChannelID::FromString(cIdStr.c_str()); + eventId = lexical_cast<tEventID>(eIdStr); + } - EpgInfoPtr EpgEvents::CreateEpgInfo(string const &epgid, cSchedules const *schedules) - { - string const errorInfo(tr("Epg error")); - cSchedulesLock schedulesLock; + EpgInfoPtr CreateEpgInfo(string const &epgid, cSchedules const *schedules) + { + string const errorInfo(tr("Epg error")); + cSchedulesLock schedulesLock; - tEventID eventId = tEventID(); - tChannelID channelId = tChannelID(); + tEventID eventId = tEventID(); + tChannelID channelId = tChannelID(); - DecodeDomId(epgid, channelId, eventId); - cChannel const *channel = Channels.GetByChannelID(channelId); - if (!channel) { - return CreateEpgInfo(epgid, errorInfo, tr("Wrong channel id")); - } - cSchedule const *schedule = schedules->GetSchedule(channel); - if (!schedule) { - return CreateEpgInfo(epgid, errorInfo, tr("Channel has no schedule")); - } - cEvent const *event = schedule->GetEvent(eventId); - if (!event) { - return CreateEpgInfo(epgid, errorInfo, tr("Wrong event id")); + DecodeDomId(epgid, channelId, eventId); + cChannel const *channel = Channels.GetByChannelID(channelId); + if (!channel) { + return CreateEpgInfo(epgid, errorInfo, tr("Wrong channel id")); + } + cSchedule const *schedule = schedules->GetSchedule(channel); + if (!schedule) { + return CreateEpgInfo(epgid, errorInfo, tr("Channel has no schedule")); + } + cEvent const *event = schedule->GetEvent(eventId); + if (!event) { + return CreateEpgInfo(epgid, errorInfo, tr("Wrong event id")); + } + return CreateEpgInfo(channel, event, epgid.c_str()); } - return CreateEpgInfo(channel, event, epgid.c_str()); - } - EpgInfoPtr EpgEvents::CreateEpgInfo(cChannel const *chan, cEvent const *event, char const *idOverride) - { - if (event) - { - string domId(idOverride ? idOverride : EncodeDomId(chan->GetChannelID(), event->EventID())); - return EpgInfoPtr(new EpgEvent(domId, event, chan->Name())); - } - else if (LiveSetup().GetShowChannelsWithoutEPG()) - { - string domId(idOverride ? idOverride : EncodeDomId(chan->GetChannelID(), 0)); - return EpgInfoPtr(new EmptyEvent(domId, chan->GetChannelID(), chan->Name())); - } - } - - EpgInfoPtr EpgEvents::CreateEpgInfo(string const &recid, cRecording const *recording, char const *caption) - { - return EpgInfoPtr(new EpgRecording(recid, recording, caption)); - } - - EpgInfoPtr EpgEvents::CreateEpgInfo(string const &id, string const &caption, string const &info) - { - return EpgInfoPtr(new EpgString(id, caption, info)); - } + EpgInfoPtr CreateEpgInfo(cChannel const *chan, cEvent const *event, char const *idOverride) + { + if (event) { + string domId(idOverride ? idOverride : EncodeDomId(chan->GetChannelID(), event->EventID())); + return EpgInfoPtr(new EpgEvent(domId, event, chan->Name())); + } + else if (LiveSetup().GetShowChannelsWithoutEPG()) { + string domId(idOverride ? idOverride : EncodeDomId(chan->GetChannelID(), 0)); + return EpgInfoPtr(new EmptyEvent(domId, chan->GetChannelID(), chan->Name())); + } + } - list<string> EpgEvents::EpgImages(string const &epgid) - { - list<string> images; + EpgInfoPtr CreateEpgInfo(string const &recid, cRecording const *recording, char const *caption) + { + return EpgInfoPtr(new EpgRecording(recid, recording, caption)); + } - size_t delimPos = epgid.find_last_of('_'); - string imageId = epgid.substr(delimPos+1); - imageId = imageId.substr(0, imageId.size()-1); // tvm2vdr seems always to use one digit less + EpgInfoPtr CreateEpgInfo(string const &id, string const &caption, string const &info) + { + return EpgInfoPtr(new EpgString(id, caption, info)); + } - const string filemask(LiveSetup().GetEpgImageDir() + "/" + imageId + "*.*"); - glob_t globbuf; - globbuf.gl_offs = 0; - if (!LiveSetup().GetEpgImageDir().empty() && glob(filemask.c_str(), GLOB_DOOFFS, NULL, &globbuf) == 0) + list<string> EpgImages(string const &epgid) { - for(int i=0; i<(int)globbuf.gl_pathc; i++) - { - const string imagefile(globbuf.gl_pathv[i]); - size_t delimPos = imagefile.find_last_of('/'); - images.push_back(imagefile.substr(delimPos+1)); + list<string> images; + + size_t delimPos = epgid.find_last_of('_'); + string imageId = epgid.substr(delimPos+1); + imageId = imageId.substr(0, imageId.size()-1); // tvm2vdr seems always to use one digit less + + const string filemask(LiveSetup().GetEpgImageDir() + "/" + imageId + "*.*"); + glob_t globbuf; + globbuf.gl_offs = 0; + if (!LiveSetup().GetEpgImageDir().empty() && glob(filemask.c_str(), GLOB_DOOFFS, NULL, &globbuf) == 0) { + for(int i=0; i<(int)globbuf.gl_pathc; i++) { + const string imagefile(globbuf.gl_pathv[i]); + size_t delimPos = imagefile.find_last_of('/'); + images.push_back(imagefile.substr(delimPos+1)); + } + globfree(&globbuf); } - globfree(&globbuf); + return images; } - return images; - } - int EpgEvents::ElapsedTime(time_t const startTime, time_t const endTime) - { - if (startTime == 0 && endTime == 0) return 0; - if (endTime > startTime) { - time_t now = time(0); - if ((startTime <= now) && (now <= endTime)) { - return 100 * (now - startTime) / (endTime - startTime); + int ElapsedTime(time_t const startTime, time_t const endTime) + { + // Elapsed time is only meaningful when there is a non zero + // duration (e.g. startTime != endTime and endTime > startTime) + int duration = Duration(startTime, endTime); + if (duration > 0) { + time_t now = time(0); + if ((startTime <= now) && (now <= endTime)) { + return 100 * (now - startTime) / duration; + } } + return -1; } - return -1; - } + + int Duration(time_t const startTime, time_t const endTime) + { + return endTime - startTime; + } + + } // namespace EpgEvents + }; // namespace vdrlive diff --git a/epg_events.h b/epg_events.h index da3c473..7d05b45 100644 --- a/epg_events.h +++ b/epg_events.h @@ -16,6 +16,64 @@ namespace vdrlive { + class EpgInfo; + + typedef std::tr1::shared_ptr<EpgInfo> EpgInfoPtr; + + // ------------------------------------------------------------------------- + + namespace EpgEvents { + + std::string EncodeDomId(tChannelID const &chanId, tEventID const &eventId); + void DecodeDomId(std::string const &epgid, tChannelID &chanId, tEventID &eventId); + + /** + * Allocate and initalize an epgEvent instance with the + * passed channel and event information. + */ + EpgInfoPtr CreateEpgInfo(cChannel const *chan, cEvent const *event, char const *idOverride = 0); + + /** + * This is the inverse creator for epgInfos to the creator above. + */ + EpgInfoPtr CreateEpgInfo(std::string const &epgid, cSchedules const *schedules); + + /** + * Allocate and initalize an epgEvent instance with the + * passed recording information. + */ + EpgInfoPtr CreateEpgInfo(std::string const &recid, cRecording const *recording, char const *caption = 0); + + /** + * Allocate and initalize an epgEvent instance with the + * passed string informations + */ + EpgInfoPtr CreateEpgInfo(std::string const &id, std::string const &caption, std::string const &info); + + /** + * Return a list of EpgImage paths for a given epgid. + */ + std::list<std::string> EpgImages(std::string const &epgid); + + /** + * Calculate the duration. A duration can be zero or + * negative. Negative durations are considered invalid by + * LIVE. + */ + int Duration(time_t const startTime, time_t const endTime); + + /** + * Calculate the elapsed time of a positive duration. This + * takes into account the startTime and the current time. If + * the current time is not in the interval startTime <= + * currTime <= endTime the return value is -1. + */ + int ElapsedTime(time_t const startTime, time_t const endTime); + + } // namespace EpgEvents + + // ------------------------------------------------------------------------- + class EpgInfo { protected: @@ -45,6 +103,8 @@ namespace vdrlive virtual std::string const CurrentTime(const char* format) const; + virtual int Duration() const; + virtual int Elapsed() const; // virtual const cTimer* GetTimer() const = 0; @@ -58,13 +118,11 @@ namespace vdrlive std::string m_caption; }; - typedef std::tr1::shared_ptr<EpgInfo> EpgInfoPtr; - // ------------------------------------------------------------------------- class EpgString : public EpgInfo { - friend class EpgEvents; + friend EpgInfoPtr EpgEvents::CreateEpgInfo(std::string const &, std::string const &, std::string const &); protected: EpgString(std::string const &id, @@ -92,7 +150,7 @@ namespace vdrlive class EpgEvent : public EpgInfo { - friend class EpgEvents; + friend EpgInfoPtr EpgEvents::CreateEpgInfo(cChannel const *, cEvent const *, char const *); protected: EpgEvent(std::string const &id, @@ -122,7 +180,7 @@ namespace vdrlive class EmptyEvent : public EpgInfo { - friend class EpgEvents; + friend EpgInfoPtr EpgEvents::CreateEpgInfo(cChannel const *, cEvent const *, char const *); protected: EmptyEvent(std::string const &id, tChannelID const &channelID, const char* channelName); @@ -150,7 +208,7 @@ namespace vdrlive class EpgRecording : public EpgInfo { - friend class EpgEvents; + friend EpgInfoPtr EpgEvents::CreateEpgInfo(std::string const &, cRecording const *, char const *); protected: EpgRecording(std::string const &recid, @@ -183,45 +241,6 @@ namespace vdrlive mutable std::string m_archived; }; - // ------------------------------------------------------------------------- - - class EpgEvents { - public: - EpgEvents(); - virtual ~EpgEvents(); - - static std::string EncodeDomId(tChannelID const &chanId, tEventID const &eventId); - static void DecodeDomId(std::string const &epgid, tChannelID &chanId, tEventID &eventId); - - /** - * Allocate and initalize an epgEvent instance with the - * passed channel and event information. - */ - static EpgInfoPtr CreateEpgInfo(cChannel const *chan, cEvent const *event, char const *idOverride = 0); - - /** - * This is the inverse creator for epgInfos to the creator above. - */ - static EpgInfoPtr CreateEpgInfo(std::string const &epgid, cSchedules const *schedules); - - /** - * Allocate and initalize an epgEvent instance with the - * passed recording information. - */ - static EpgInfoPtr CreateEpgInfo(std::string const &recid, cRecording const *recording, char const *caption = 0); - - /** - * Allocate and initalize an epgEvent instance with the - * passed string informations - */ - static EpgInfoPtr CreateEpgInfo(std::string const &id, std::string const &caption, std::string const &info); - - static std::list<std::string> EpgImages(std::string const &epgid); - - static int ElapsedTime(time_t const startTime, time_t const endTime); - - private: - }; }; // namespace vdrlive #endif // VDR_LIVE_WHATS_ON_H diff --git a/pages/timers.ecpp b/pages/timers.ecpp index edea2a9..8ed41c0 100644 --- a/pages/timers.ecpp +++ b/pages/timers.ecpp @@ -71,7 +71,6 @@ static const size_t maximumDescriptionLength = 300; % } else { <table class="listing" cellspacing="0" cellpadding="0"> <%cpp> - EpgEvents epgEvents; // output of the timer list: for (SortedTimers::iterator timer = timers.begin(); timer != timers.end(); ++timer) { EpgInfoPtr epgEvent; diff --git a/pages/whats_on.ecpp b/pages/whats_on.ecpp index e188fee..ea5d222 100644 --- a/pages/whats_on.ecpp +++ b/pages/whats_on.ecpp @@ -109,7 +109,6 @@ if (type == "now") { </tr> % } <%cpp> - EpgEvents epgEvents; std::list<EpgInfoPtr> eventList; // collect the broadcasts |