diff options
author | Dieter Hametner <dh (plus) vdr (at) gekrumbel (dot) de> | 2007-07-12 19:10:34 +0000 |
---|---|---|
committer | Dieter Hametner <dh (plus) vdr (at) gekrumbel (dot) de> | 2007-07-12 19:10:34 +0000 |
commit | 7b003f8aaafc2d95dcf7c9dfc5cbc6288b37915c (patch) | |
tree | 35ba447699c1fd1c1f41dd672fcc1e127d6ea3cc /epg_events.cpp | |
parent | 9f65a960ca7d4cc3819e1434de05b9428acc23ad (diff) | |
download | vdr-plugin-live-7b003f8aaafc2d95dcf7c9dfc5cbc6288b37915c.tar.gz vdr-plugin-live-7b003f8aaafc2d95dcf7c9dfc5cbc6288b37915c.tar.bz2 |
- Update to the mootools framework.
- New more XHTML compliant tips.
- Optional AJAX enabled infoboxes for epg information.
- Major speed enhancement for the single pages, due to less data to
transfer to the browser.
- See doc/ChangeLog for more detailed changes description.
- See doc/dev-conventions.txt for how we benefit from mootools package
on the ECMAScript side of live.
Diffstat (limited to 'epg_events.cpp')
-rw-r--r-- | epg_events.cpp | 293 |
1 files changed, 231 insertions, 62 deletions
diff --git a/epg_events.cpp b/epg_events.cpp index 2d5237c..e9524b3 100644 --- a/epg_events.cpp +++ b/epg_events.cpp @@ -5,54 +5,67 @@ #include "epg_events.h" +using namespace std; + namespace vdrlive { - EpgEvent::EpgEvent(const std::string& id, - const std::string& caption, - const std::string& title, - const std::string& short_descr, - const std::string& long_descr, - time_t start_time, - time_t end_time) : + + /* + * ------------------------------------------------------------------------- + * EpgInfo + * ------------------------------------------------------------------------- + */ + + EpgInfo::EpgInfo(const std::string& id, const std::string& caption) : m_eventId(id), - m_caption(caption), - m_title(title), - m_short_descr(short_descr), - m_long_descr(long_descr), - m_archived(), - m_start_time(start_time), - m_end_time(end_time) + m_caption(caption) + { + } + + EpgInfo::~EpgInfo() + { + } + + const std::string EpgInfo::CurrentTime(const char* format) const + { + return FormatDateTime(format, time(0)); + } + + const string EpgInfo::StartTime(const char* format) const { + time_t start = GetStartTime(); + return start ? FormatDateTime(format, start) : ""; } + const string EpgInfo::EndTime(const char* format) const + { + time_t end = GetEndTime(); + return end ? FormatDateTime(format, end) : ""; + } + + int EpgInfo::Elapsed() const + { + time_t end_time = GetEndTime(); + time_t start_time = GetStartTime(); + + if (end_time > start_time) { + time_t now = time(0); + if ((start_time <= now) && (now <= end_time)) { + return 100 * (now - start_time) / (end_time - start_time); + } + } + return -1; + } + + /* + * ------------------------------------------------------------------------- + * EpgEvent + * ------------------------------------------------------------------------- + */ + EpgEvent::EpgEvent(const std::string& id, const cEvent* event, const char* channelName) : - m_eventId(id), - m_caption(channelName), - m_title(event->Title() ? event->Title() : ""), - m_short_descr(event->ShortText() ? event->ShortText() : ""), - m_long_descr(event->Description() ? event->Description() : ""), - m_archived(), - m_start_time(event->StartTime()), - m_end_time(event->EndTime()) - { - } - - EpgEvent::EpgEvent(const std::string& id, - const std::string& caption, - const std::string& title, - const std::string& short_descr, - const std::string& long_descr, - const std::string& archived, - time_t start_time, - time_t end_time) : - m_eventId(id), - m_caption(caption), - m_title(title), - m_short_descr(short_descr), - m_long_descr(long_descr), - m_archived(archived), - m_start_time(start_time), - m_end_time(end_time) + EpgInfo(id, channelName), + m_event(event) { } @@ -60,50 +73,206 @@ namespace vdrlive { } - const std::string EpgEvent::StartTime(const char* format) const + /* + * ------------------------------------------------------------------------- + * EpgString + * ------------------------------------------------------------------------- + */ + + EpgString::EpgString(const string& id, const string& caption, const string& info) : + EpgInfo(id, caption), + m_info(info) { - return FormatDateTime(format, m_start_time); } - const std::string EpgEvent::EndTime(const char* format) const + EpgString::~EpgString() { - return FormatDateTime(format, m_end_time); } - const std::string EpgEvent::CurrentTime(const char* format) const + const string EpgString::Title() const { - return FormatDateTime(format, time(0)); + return m_info; } - int EpgEvent::Elapsed() const + const string EpgString::ShortDescr() const { - if (m_end_time > m_start_time) { - time_t now = time(0); - if ((m_start_time <= now) && (now <= m_end_time)) { - return 100 * (now - m_start_time) / (m_end_time - m_start_time); + return ""; + } + + const string EpgString::LongDescr() const + { + return ""; + } + + // virtual const std::string Archived() const { return std::string(); } + + time_t EpgString::GetStartTime() const + { + return time(0); + } + + time_t EpgString::GetEndTime() const + { + return time(0); + } + + /* + * ------------------------------------------------------------------------- + * EpgRecording + * ------------------------------------------------------------------------- + */ + + EpgRecording::EpgRecording(const string& recid, const cRecording* recording, const char* caption) : + EpgInfo(recid, (caption != 0) ? caption : ""), + m_recording(recording), + m_ownCaption(caption != 0), + m_checkedArchived(false), + m_archived() + { + } + + EpgRecording::~EpgRecording() + { + m_recording = 0; + } + + const string EpgRecording::Caption() const + { + if (!m_ownCaption) { + return EpgInfo::Caption(); + } + if (!m_recording) { + return ""; + } + + return Name(); + } + + const string EpgRecording::Title() const + { + if (!m_recording) { + return ""; + } + + const cRecordingInfo* info = m_recording->Info(); + return (info && info->Title()) ? info->Title() : Name(); + } + + const string EpgRecording::ShortDescr() const + { + const cRecordingInfo* info = m_recording ? m_recording->Info() : 0; + return (info && info->ShortText()) ? info->ShortText() : ""; + } + + const string EpgRecording::LongDescr() const + { + const cRecordingInfo* info = m_recording ? m_recording->Info() : 0; + return (info && info->Description()) ? info->Description() : ""; + } + + const string EpgRecording::Archived() const + { + if (!m_checkedArchived) { + if (m_recording) { + m_archived = RecordingsManager::GetArchiveDescr(m_recording); + m_checkedArchived = true; } } - return -1; + return m_archived; + } + + time_t EpgRecording::GetStartTime() const + { + return m_recording ? m_recording->start : 0; } - const cTimer* EpgEvent::GetTimer() const + time_t EpgRecording::GetEndTime() const { - return NULL; + return m_recording ? m_recording->start : 0; } - EpgEvents::EpgEvents() : - std::vector<EpgEventPtr>() + const string EpgRecording::Name() const + { + string name(m_recording->Name()); + size_t index = name.find_last_of('~'); + if (index != string::npos) { + name = name.substr(index, name.length()); + } + return name; + } + + /* + * ------------------------------------------------------------------------- + * EpgEvents + * ------------------------------------------------------------------------- + */ + + EpgEvents::EpgEvents() { } EpgEvents::~EpgEvents() { } -#ifdef never - EpgEventsPtr EpgEvents::dim(size_t count) + + string EpgEvents::GetDomId(const tChannelID& chanId, const tEventID& eId) + { + string channelId(chanId.ToString()); + string eventId("event_"); + + replace(channelId.begin(), channelId.end(), '.', 'p'); + replace(channelId.begin(), channelId.end(), '-', 'm'); + + eventId += channelId; + eventId += '_'; + eventId += lexical_cast<std::string>(eId); + return eventId; + } + + EpgInfoPtr EpgEvents::CreateEpgInfo(const std::string& epgid, const cSchedules* schedules) + { + const string eventStr("event_"); + + size_t delimPos = epgid.find_last_of('_'); + string cIdStr = epgid.substr(eventStr.length(), delimPos - eventStr.length()); + + replace(cIdStr.begin(), cIdStr.end(), 'm', '-'); + replace(cIdStr.begin(), cIdStr.end(), 'p', '.'); + + const string eIdStr = epgid.substr(delimPos+1); + const string errorInfo(tr("Epg error")); + + + tEventID eventId = lexical_cast<tEventID>(eIdStr); + tChannelID channelId = tChannelID::FromString(cIdStr.c_str()); + const cChannel* channel = Channels.GetByChannelID(channelId); + if (!channel) { + return CreateEpgInfo(epgid, errorInfo, tr("Wrong channel id")); + } + const cSchedule* schedule = schedules->GetSchedule(channel); + if (!schedule) { + return CreateEpgInfo(epgid, errorInfo, tr("Channel has no schedule")); + } + const cEvent* event = schedule->GetEvent(eventId); + if (!event) { + return CreateEpgInfo(epgid, errorInfo, tr("wrong event id")); + } + return CreateEpgInfo(channel, event, epgid.c_str()); + } + + EpgInfoPtr EpgEvents::CreateEpgInfo(const cChannel* chan, const cEvent* event, const char* idOverride) + { + string domId(idOverride ? idOverride : GetDomId(chan->GetChannelID(), event->EventID())); + return EpgInfoPtr(new EpgEvent(domId, event, chan->Name())); + } + + EpgInfoPtr EpgEvents::CreateEpgInfo(const string& recid, const cRecording* recording, const char* caption) + { + return EpgInfoPtr(new EpgRecording(recid, recording, caption)); + } + + EpgInfoPtr EpgEvents::CreateEpgInfo(const std::string& id, const std::string& caption, const std::string& info) { - EpgEventsPtr ePtr(new EpgEvents(count)); - return ePtr; + return EpgInfoPtr(new EpgString(id, caption, info)); } -#endif }; // namespace vdrlive |