diff options
author | Kai Sommerfeld <kai.sommerfeld@gmx.com> | 2014-11-02 10:17:12 +0100 |
---|---|---|
committer | ksooo <kai.sommerfeld@gmx.com> | 2015-01-13 14:03:03 +0100 |
commit | 2117497c0902db2456c58cd122e84bf38a7e13bf (patch) | |
tree | 3714d6a2384379205419fb76a8e3da6e7c8d9f58 | |
parent | f185a3a6bd573f4888d7cc916730249a6b12a565 (diff) |
Optimize CEpgInfoTag. No more copies, just shared pointers.
30 files changed, 438 insertions, 450 deletions
diff --git a/xbmc/FileItem.cpp b/xbmc/FileItem.cpp index eff5c0da46..f307ead31c 100644 --- a/xbmc/FileItem.cpp +++ b/xbmc/FileItem.cpp @@ -110,22 +110,24 @@ CFileItem::CFileItem(const CVideoInfoTag& movie) SetFromVideoInfoTag(movie); } -CFileItem::CFileItem(const CEpgInfoTag& tag) +CFileItem::CFileItem(const CEpgInfoTagPtr& tag) { Initialize(); - m_strPath = tag.Path(); m_bIsFolder = false; - *GetEPGInfoTag() = tag; - SetLabel(tag.Title()); - m_strLabel2 = tag.Plot(); - m_dateTime = tag.StartAsLocalTime(); - - if (!tag.Icon().empty()) - SetIconImage(tag.Icon()); - else if (tag.HasPVRChannel() && !tag.ChannelTag()->IconPath().empty()) - SetIconImage(tag.ChannelTag()->IconPath()); + m_epgInfoTag = tag; + if (tag) + { + m_strPath = tag->Path(); + SetLabel(tag->Title()); + m_strLabel2 = tag->Plot(); + m_dateTime = tag->StartAsLocalTime(); + if (!tag->Icon().empty()) + SetIconImage(tag->Icon()); + else if (tag->HasPVRChannel() && !tag->ChannelTag()->IconPath().empty()) + SetIconImage(tag->ChannelTag()->IconPath()); + } FillInMimeType(false); } @@ -133,14 +135,13 @@ CFileItem::CFileItem(const CPVRChannel& channel) { Initialize(); - CEpgInfoTag epgNow; - bool bHasEpgNow = channel.GetEPGNow(epgNow); + CEpgInfoTagPtr epgNow(channel.GetEPGNow()); m_strPath = channel.Path(); m_bIsFolder = false; *GetPVRChannelInfoTag() = channel; SetLabel(channel.ChannelName()); - m_strLabel2 = bHasEpgNow ? epgNow.Title() : + m_strLabel2 = epgNow ? epgNow->Title() : CSettings::Get().GetBool("epg.hidenoinfoavailable") ? "" : g_localizeStrings.Get(19055); // no information available @@ -153,9 +154,9 @@ CFileItem::CFileItem(const CPVRChannel& channel) musictag->SetTitle(m_strLabel2); musictag->SetArtist(channel.ChannelName()); musictag->SetAlbumArtist(channel.ChannelName()); - if (bHasEpgNow) - musictag->SetGenre(epgNow.Genre()); - musictag->SetDuration(bHasEpgNow ? epgNow.GetDuration() : 3600); + if (epgNow) + musictag->SetGenre(epgNow->Genre()); + musictag->SetDuration(epgNow ? epgNow->GetDuration() : 3600); musictag->SetLoaded(true); musictag->SetComment(""); musictag->SetLyrics(""); @@ -228,7 +229,6 @@ CFileItem::CFileItem(const CFileItem& item): CGUIListItem() { m_musicInfoTag = NULL; m_videoInfoTag = NULL; - m_epgInfoTag = NULL; m_pvrChannelInfoTag = NULL; m_pvrRecordingInfoTag = NULL; m_pvrTimerInfoTag = NULL; @@ -258,6 +258,12 @@ CFileItem::CFileItem(const std::string& strLabel) SetLabel(strLabel); } +CFileItem::CFileItem(const char* strLabel) +{ + Initialize(); + SetLabel(std::string(strLabel)); +} + CFileItem::CFileItem(const CURL& path, bool bIsFolder) { Initialize(); @@ -308,7 +314,6 @@ CFileItem::~CFileItem(void) { delete m_musicInfoTag; delete m_videoInfoTag; - delete m_epgInfoTag; delete m_pvrChannelInfoTag; delete m_pvrRecordingInfoTag; delete m_pvrTimerInfoTag; @@ -316,7 +321,6 @@ CFileItem::~CFileItem(void) m_musicInfoTag = NULL; m_videoInfoTag = NULL; - m_epgInfoTag = NULL; m_pvrChannelInfoTag = NULL; m_pvrRecordingInfoTag = NULL; m_pvrTimerInfoTag = NULL; @@ -360,18 +364,9 @@ const CFileItem& CFileItem::operator=(const CFileItem& item) } if (item.HasEPGInfoTag()) - { - m_epgInfoTag = GetEPGInfoTag(); - if (m_epgInfoTag) - *m_epgInfoTag = *item.m_epgInfoTag; - } + m_epgInfoTag = item.m_epgInfoTag; else - { - if (m_epgInfoTag) - delete m_epgInfoTag; - - m_epgInfoTag = NULL; - } + m_epgInfoTag.reset(); if (item.HasPVRChannelInfoTag()) { @@ -450,7 +445,6 @@ void CFileItem::Initialize() { m_musicInfoTag = NULL; m_videoInfoTag = NULL; - m_epgInfoTag = NULL; m_pvrChannelInfoTag = NULL; m_pvrRecordingInfoTag = NULL; m_pvrTimerInfoTag = NULL; @@ -493,8 +487,7 @@ void CFileItem::Reset() m_musicInfoTag=NULL; delete m_videoInfoTag; m_videoInfoTag=NULL; - delete m_epgInfoTag; - m_epgInfoTag=NULL; + m_epgInfoTag.reset(); delete m_pvrChannelInfoTag; m_pvrChannelInfoTag=NULL; delete m_pvrRecordingInfoTag; @@ -3112,14 +3105,6 @@ CVideoInfoTag* CFileItem::GetVideoInfoTag() return m_videoInfoTag; } -CEpgInfoTag* CFileItem::GetEPGInfoTag() -{ - if (!m_epgInfoTag) - m_epgInfoTag = new CEpgInfoTag; - - return m_epgInfoTag; -} - CPVRChannel* CFileItem::GetPVRChannelInfoTag() { if (!m_pvrChannelInfoTag) diff --git a/xbmc/FileItem.h b/xbmc/FileItem.h index 27d8472434..45366aad1b 100644 --- a/xbmc/FileItem.h +++ b/xbmc/FileItem.h @@ -44,6 +44,7 @@ class CVideoInfoTag; namespace EPG { class CEpgInfoTag; + typedef boost::shared_ptr<EPG::CEpgInfoTag> CEpgInfoTagPtr; } namespace PVR { @@ -90,6 +91,7 @@ public: CFileItem(const CFileItem& item); CFileItem(const CGUIListItem& item); explicit CFileItem(const std::string& strLabel); + explicit CFileItem(const char* strLabel); CFileItem(const CURL& path, bool bIsFolder); CFileItem(const std::string& strPath, bool bIsFolder); CFileItem(const CSong& song); @@ -99,7 +101,7 @@ public: CFileItem(const CGenre& genre); CFileItem(const MUSIC_INFO::CMusicInfoTag& music); CFileItem(const CVideoInfoTag& movie); - CFileItem(const EPG::CEpgInfoTag& tag); + CFileItem(const EPG::CEpgInfoTagPtr& tag); CFileItem(const PVR::CPVRChannel& channel); CFileItem(const PVR::CPVRRecording& record); CFileItem(const PVR::CPVRTimerInfoTag& timer); @@ -257,16 +259,19 @@ public: inline bool HasEPGInfoTag() const { - return m_epgInfoTag != NULL; + return m_epgInfoTag.get() != NULL; } - EPG::CEpgInfoTag* GetEPGInfoTag(); - - inline const EPG::CEpgInfoTag* GetEPGInfoTag() const + inline const EPG::CEpgInfoTagPtr GetEPGInfoTag() const { return m_epgInfoTag; } + inline void SetEPGInfoTag(const EPG::CEpgInfoTagPtr& tag) + { + m_epgInfoTag = tag; + } + inline bool HasPVRChannelInfoTag() const { return m_pvrChannelInfoTag != NULL; @@ -478,7 +483,7 @@ private: std::string m_extrainfo; MUSIC_INFO::CMusicInfoTag* m_musicInfoTag; CVideoInfoTag* m_videoInfoTag; - EPG::CEpgInfoTag* m_epgInfoTag; + EPG::CEpgInfoTagPtr m_epgInfoTag; PVR::CPVRChannel* m_pvrChannelInfoTag; PVR::CPVRRecording* m_pvrRecordingInfoTag; PVR::CPVRTimerInfoTag * m_pvrTimerInfoTag; diff --git a/xbmc/GUIInfoManager.cpp b/xbmc/GUIInfoManager.cpp index 2b7e0b8012..d23e9eb643 100644 --- a/xbmc/GUIInfoManager.cpp +++ b/xbmc/GUIInfoManager.cpp @@ -1528,9 +1528,9 @@ std::string CGUIInfoManager::GetLabel(int info, int contextWindow, std::string * { if (m_currentFile->HasPVRChannelInfoTag()) { - CEpgInfoTag tag; - return m_currentFile->GetPVRChannelInfoTag()->GetEPGNow(tag) ? - tag.Title() : + CEpgInfoTagPtr tag(m_currentFile->GetPVRChannelInfoTag()->GetEPGNow()); + return tag ? + tag->Title() : CSettings::Get().GetBool("epg.hidenoinfoavailable") ? "" : g_localizeStrings.Get(19055); // no information available } @@ -2643,10 +2643,7 @@ bool CGUIInfoManager::GetBool(int condition1, int contextWindow, const CGUIListI break; case VIDEOPLAYER_HAS_EPG: if (m_currentFile->HasPVRChannelInfoTag()) - { - CEpgInfoTag epgTag; - bReturn = m_currentFile->GetPVRChannelInfoTag()->GetEPGNow(epgTag); - } + bReturn = (m_currentFile->GetPVRChannelInfoTag()->GetEPGNow().get() != NULL); break; case VIDEOPLAYER_IS_STEREOSCOPIC: if(g_application.m_pPlayer->IsPlaying()) @@ -3181,9 +3178,9 @@ std::string CGUIInfoManager::GetMultiInfoLabel(const GUIInfo &info, int contextW else if (info.m_info == PLAYER_FINISH_TIME) { CDateTime time; - CEpgInfoTag currentTag; - if (GetEpgInfoTag(currentTag)) - time = currentTag.EndAsLocalTime(); + CEpgInfoTagPtr currentTag(GetEpgInfoTag()); + if (currentTag) + time = currentTag->EndAsLocalTime(); else { time = CDateTime::GetCurrentDateTime(); @@ -3194,9 +3191,9 @@ std::string CGUIInfoManager::GetMultiInfoLabel(const GUIInfo &info, int contextW else if (info.m_info == PLAYER_START_TIME) { CDateTime time; - CEpgInfoTag currentTag; - if (GetEpgInfoTag(currentTag)) - time = currentTag.StartAsLocalTime(); + CEpgInfoTagPtr currentTag(GetEpgInfoTag()); + if (currentTag) + time = currentTag->StartAsLocalTime(); else { time = CDateTime::GetCurrentDateTime(); @@ -3768,56 +3765,70 @@ std::string CGUIInfoManager::GetVideoLabel(int item) else if (m_currentFile->HasPVRChannelInfoTag()) { CPVRChannel* tag = m_currentFile->GetPVRChannelInfoTag(); - CEpgInfoTag epgTag; + CEpgInfoTagPtr epgTag; switch (item) { /* Now playing infos */ case VIDEOPLAYER_ORIGINALTITLE: - return tag->GetEPGNow(epgTag) ? - epgTag.Title() : + epgTag = tag->GetEPGNow(); + return epgTag ? + epgTag->Title() : CSettings::Get().GetBool("epg.hidenoinfoavailable") ? "" : g_localizeStrings.Get(19055); // no information available case VIDEOPLAYER_GENRE: - return tag->GetEPGNow(epgTag) ? StringUtils::Join(epgTag.Genre(), g_advancedSettings.m_videoItemSeparator) : ""; + epgTag = tag->GetEPGNow(); + return epgTag ? StringUtils::Join(epgTag->Genre(), g_advancedSettings.m_videoItemSeparator) : ""; case VIDEOPLAYER_PLOT: - return tag->GetEPGNow(epgTag) ? epgTag.Plot() : ""; + epgTag = tag->GetEPGNow(); + return epgTag ? epgTag->Plot() : ""; case VIDEOPLAYER_PLOT_OUTLINE: - return tag->GetEPGNow(epgTag) ? epgTag.PlotOutline() : ""; + epgTag = tag->GetEPGNow(); + return epgTag ? epgTag->PlotOutline() : ""; case VIDEOPLAYER_STARTTIME: - return tag->GetEPGNow(epgTag) ? epgTag.StartAsLocalTime().GetAsLocalizedTime("", false) : CDateTime::GetCurrentDateTime().GetAsLocalizedTime("", false); + epgTag = tag->GetEPGNow(); + return epgTag ? epgTag->StartAsLocalTime().GetAsLocalizedTime("", false) : CDateTime::GetCurrentDateTime().GetAsLocalizedTime("", false); case VIDEOPLAYER_ENDTIME: - return tag->GetEPGNow(epgTag) ? epgTag.EndAsLocalTime().GetAsLocalizedTime("", false) : CDateTime::GetCurrentDateTime().GetAsLocalizedTime("", false); + epgTag = tag->GetEPGNow(); + return epgTag ? epgTag->EndAsLocalTime().GetAsLocalizedTime("", false) : CDateTime::GetCurrentDateTime().GetAsLocalizedTime("", false); /* Next playing infos */ case VIDEOPLAYER_NEXT_TITLE: - return tag->GetEPGNext(epgTag) ? - epgTag.Title() : + epgTag = tag->GetEPGNext(); + return epgTag ? + epgTag->Title() : CSettings::Get().GetBool("epg.hidenoinfoavailable") ? "" : g_localizeStrings.Get(19055); // no information available case VIDEOPLAYER_NEXT_GENRE: - return tag->GetEPGNext(epgTag) ? StringUtils::Join(epgTag.Genre(), g_advancedSettings.m_videoItemSeparator) : ""; + epgTag = tag->GetEPGNext(); + return epgTag ? StringUtils::Join(epgTag->Genre(), g_advancedSettings.m_videoItemSeparator) : ""; case VIDEOPLAYER_NEXT_PLOT: - return tag->GetEPGNext(epgTag) ? epgTag.Plot() : ""; + epgTag = tag->GetEPGNext(); + return epgTag ? epgTag->Plot() : ""; case VIDEOPLAYER_NEXT_PLOT_OUTLINE: - return tag->GetEPGNext(epgTag) ? epgTag.PlotOutline() : ""; + epgTag = tag->GetEPGNext(); + return epgTag ? epgTag->PlotOutline() : ""; case VIDEOPLAYER_NEXT_STARTTIME: - return tag->GetEPGNext(epgTag) ? epgTag.StartAsLocalTime().GetAsLocalizedTime("", false) : CDateTime::GetCurrentDateTime().GetAsLocalizedTime("", false); + epgTag = tag->GetEPGNext(); + return epgTag ? epgTag->StartAsLocalTime().GetAsLocalizedTime("", false) : CDateTime::GetCurrentDateTime().GetAsLocalizedTime("", false); case VIDEOPLAYER_NEXT_ENDTIME: - return tag->GetEPGNext(epgTag) ? epgTag.EndAsLocalTime().GetAsLocalizedTime("", false) : CDateTime::GetCurrentDateTime().GetAsLocalizedTime("", false); + epgTag = tag->GetEPGNext(); + return epgTag ? epgTag->EndAsLocalTime().GetAsLocalizedTime("", false) : CDateTime::GetCurrentDateTime().GetAsLocalizedTime("", false); case VIDEOPLAYER_NEXT_DURATION: { std::string duration; - if (tag->GetEPGNext(epgTag) && epgTag.GetDuration() > 0) - duration = StringUtils::SecondsToTimeString(epgTag.GetDuration()); + epgTag = tag->GetEPGNext(); + if (epgTag && epgTag->GetDuration() > 0) + duration = StringUtils::SecondsToTimeString(epgTag->GetDuration()); return duration; } case VIDEOPLAYER_PARENTAL_RATING: { std::string rating; - if (tag->GetEPGNow(epgTag) && epgTag.ParentalRating() > 0) - rating = StringUtils::Format("%i", epgTag.ParentalRating()); + epgTag = tag->GetEPGNow(); + if (epgTag && epgTag->ParentalRating() > 0) + rating = StringUtils::Format("%i", epgTag->ParentalRating()); return rating; } break; @@ -4040,12 +4051,12 @@ void CGUIInfoManager::SetCurrentItem(CFileItem &item) SetCurrentMovie(item); if (item.HasEPGInfoTag()) - *m_currentFile->GetEPGInfoTag() = *item.GetEPGInfoTag(); + m_currentFile->SetEPGInfoTag(item.GetEPGInfoTag()); else if (item.HasPVRChannelInfoTag()) { - CEpgInfoTag tag; - if (item.GetPVRChannelInfoTag()->GetEPGNow(tag)) - *m_currentFile->GetEPGInfoTag() = tag; + CEpgInfoTagPtr tag(item.GetPVRChannelInfoTag()->GetEPGNow()); + if (tag) + m_currentFile->SetEPGInfoTag(tag); } SetChanged(); @@ -4396,9 +4407,9 @@ bool CGUIInfoManager::GetItemInt(int &value, const CGUIListItem *item, int info) const CFileItem *pItem = (const CFileItem *)item; if (pItem && pItem->HasPVRChannelInfoTag()) { - CEpgInfoTag epgNow; - if (pItem->GetPVRChannelInfoTag()->GetEPGNow(epgNow)) - value = (int) epgNow.ProgressPercentage(); + CEpgInfoTagPtr epgNow(pItem->GetPVRChannelInfoTag()->GetEPGNow()); + if (epgNow) + value = (int) epgNow->ProgressPercentage(); } else if (pItem && pItem->HasEPGInfoTag()) { @@ -4454,9 +4465,9 @@ std::string CGUIInfoManager::GetItemLabel(const CFileItem *item, int info, std:: case LISTITEM_TITLE: if (item->HasPVRChannelInfoTag()) { - CEpgInfoTag epgTag; - return item->GetPVRChannelInfoTag()->GetEPGNow(epgTag) ? - epgTag.Title() : + CEpgInfoTagPtr epgTag(item->GetPVRChannelInfoTag()->GetEPGNow()); + return epgTag ? + epgTag->Title() : CSettings::Get().GetBool("epg.hidenoinfoavailable") ? "" : g_localizeStrings.Get(19055); // no information available } @@ -4564,8 +4575,8 @@ std::string CGUIInfoManager::GetItemLabel(const CFileItem *item, int info, std:: return StringUtils::Join(item->GetMusicInfoTag()->GetGenre(), g_advancedSettings.m_musicItemSeparator); if (item->HasPVRChannelInfoTag()) { - CEpgInfoTag epgTag; - return item->GetPVRChannelInfoTag()->GetEPGNow(epgTag) ? StringUtils::Join(epgTag.Genre(), g_advancedSettings.m_videoItemSeparator) : ""; + CEpgInfoTagPtr epgTag(item->GetPVRChannelInfoTag()->GetEPGNow()); + return epgTag ? StringUtils::Join(epgTag->Genre(), g_advancedSettings.m_videoItemSeparator) : ""; } if (item->HasPVRRecordingInfoTag()) return StringUtils::Join(item->GetPVRRecordingInfoTag()->m_genre, g_advancedSettings.m_videoItemSeparator); @@ -4596,8 +4607,8 @@ std::string CGUIInfoManager::GetItemLabel(const CFileItem *item, int info, std:: return item->GetEPGInfoTag()->StartAsLocalTime().GetAsLocalizedDateTime(false, false); if (item->HasPVRChannelInfoTag()) { - CEpgInfoTag epgTag; - return item->GetPVRChannelInfoTag()->GetEPGNow(epgTag) ? epgTag.StartAsLocalTime().GetAsLocalizedDateTime(false, false) : CDateTime::GetCurrentDateTime().GetAsLocalizedDateTime(false, false); + CEpgInfoTagPtr epgTag(item->GetPVRChannelInfoTag()->GetEPGNow()); + return epgTag ? epgTag->StartAsLocalTime().GetAsLocalizedDateTime(false, false) : CDateTime::GetCurrentDateTime().GetAsLocalizedDateTime(false, false); } if (item->HasPVRRecordingInfoTag()) return item->GetPVRRecordingInfoTag()->RecordingTimeAsLocalTime().GetAsLocalizedDateTime(false, false); @@ -4652,9 +4663,12 @@ std::string CGUIInfoManager::GetItemLabel(const CFileItem *item, int info, std:: if (item->HasPVRChannelInfoTag()) { const CPVRChannel *channel = item->HasPVRChannelInfoTag() ? item->GetPVRChannelInfoTag() : NULL; - CEpgInfoTag tag; - if (channel && channel->GetEPGNow(tag)) - return StringUtils::SecondsToTimeString(tag.GetDuration()); + if (channel) + { + CEpgInfoTagPtr tag(channel->GetEPGNow()); + if (tag) + return StringUtils::SecondsToTimeString(tag->GetDuration()); + } return ""; } else if (item->HasPVRRecordingInfoTag()) @@ -4683,9 +4697,12 @@ std::string CGUIInfoManager::GetItemLabel(const CFileItem *item, int info, std:: if (item->HasPVRChannelInfoTag()) { const CPVRChannel *channel = item->HasPVRChannelInfoTag() ? item->GetPVRChannelInfoTag() : NULL; - CEpgInfoTag tag; - if (channel && channel->GetEPGNow(tag)) - return tag.Plot(); + if (channel) + { + CEpgInfoTagPtr tag(channel->GetEPGNow()); + if (tag) + return tag->Plot(); + } return ""; } if (item->HasEPGInfoTag()) @@ -4705,9 +4722,12 @@ std::string CGUIInfoManager::GetItemLabel(const CFileItem *item, int info, std:: if (item->HasPVRChannelInfoTag()) { const CPVRChannel *channel = item->HasPVRChannelInfoTag() ? item->GetPVRChannelInfoTag() : NULL; - CEpgInfoTag tag; - if (channel && channel->GetEPGNow(tag)) - return tag.PlotOutline(); + if (channel) + { + CEpgInfoTagPtr tag(channel->GetEPGNow()); + if (tag) + return tag->PlotOutline(); + } return ""; } if (item->HasEPGInfoTag()) @@ -4890,9 +4910,12 @@ std::string CGUIInfoManager::GetItemLabel(const CFileItem *item, int info, std:: if (item->HasPVRChannelInfoTag()) { const CPVRChannel *channel = item->HasPVRChannelInfoTag() ? item->GetPVRChannelInfoTag() : NULL; - CEpgInfoTag tag; - if (channel && channel->GetEPGNow(tag)) - return tag.StartAsLocalTime().GetAsLocalizedTime("", false); + if (channel) + { + CEpgInfoTagPtr tag(channel->GetEPGNow()); + if (tag) + return tag->StartAsLocalTime().GetAsLocalizedTime("", false); + } return CDateTime::GetCurrentDateTime().GetAsLocalizedTime("", false); } if (item->HasEPGInfoTag()) @@ -4908,9 +4931,12 @@ std::string CGUIInfoManager::GetItemLabel(const CFileItem *item, int info, std:: if (item->HasPVRChannelInfoTag()) { const CPVRChannel *channel = item->HasPVRChannelInfoTag() ? item->GetPVRChannelInfoTag() : NULL; - CEpgInfoTag tag; - if (channel && channel->GetEPGNow(tag)) - return tag.EndAsLocalTime().GetAsLocalizedTime("", false); + if (channel) + { + CEpgInfoTagPtr tag(channel->GetEPGNow()); + if (tag) + return tag->EndAsLocalTime().GetAsLocalizedTime("", false); + } return CDateTime::GetCurrentDateTime().GetAsLocalizedTime("", false); } if (item->HasEPGInfoTag()) @@ -4922,9 +4948,12 @@ std::string CGUIInfoManager::GetItemLabel(const CFileItem *item, int info, std:: if (item->HasPVRChannelInfoTag()) { const CPVRChannel *channel = item->HasPVRChannelInfoTag() ? item->GetPVRChannelInfoTag() : NULL; - CEpgInfoTag tag; - if (channel && channel->GetEPGNow(tag)) - return tag.StartAsLocalTime().GetAsLocalizedDate(true); + if (channel) + { + CEpgInfoTagPtr tag(channel->GetEPGNow()); + if (tag) + return tag->StartAsLocalTime().GetAsLocalizedDate(true); + } return CDateTime::GetCurrentDateTime().GetAsLocalizedDate(true); } if (item->HasEPGInfoTag()) @@ -4940,9 +4969,12 @@ std::string CGUIInfoManager::GetItemLabel(const CFileItem *item, int info, std:: if (item->HasPVRChannelInfoTag()) { const CPVRChannel *channel = item->HasPVRChannelInfoTag() ? item->GetPVRChannelInfoTag() : NULL; - CEpgInfoTag tag; - if (channel && channel->GetEPGNow(tag)) - return tag.EndAsLocalTime().GetAsLocalizedDate(true); + if (channel) + { + CEpgInfoTagPtr tag(channel->GetEPGNow()); + if (tag) + return tag->EndAsLocalTime().GetAsLocalizedDate(true); + } return CDateTime::GetCurrentDateTime().GetAsLocalizedDate(true); } if (item->HasEPGInfoTag()) @@ -5004,73 +5036,100 @@ std::string CGUIInfoManager::GetItemLabel(const CFileItem *item, int info, std:: case LISTITEM_NEXT_STARTTIME: { const CPVRChannel *channel = item->HasPVRChannelInfoTag() ? item->GetPVRChannelInfoTag() : NULL; - CEpgInfoTag tag; - if (channel && channel->GetEPGNext(tag)) - return tag.StartAsLocalTime().GetAsLocalizedTime("", false); + if (channel) + { + CEpgInfoTagPtr tag(channel->GetEPGNext()); + if (tag) + return tag->StartAsLocalTime().GetAsLocalizedTime("", false); + } } return CDateTime::GetCurrentDateTime().GetAsLocalizedTime("", false); case LISTITEM_NEXT_ENDTIME: { const CPVRChannel *channel = item->HasPVRChannelInfoTag() ? item->GetPVRChannelInfoTag() : NULL; - CEpgInfoTag tag; - if (channel && channel->GetEPGNext(tag)) - return tag.EndAsLocalTime().GetAsLocalizedTime("", false); + if (channel) + { + CEpgInfoTagPtr tag(channel->GetEPGNext()); + if (tag) + return tag->EndAsLocalTime().GetAsLocalizedTime("", false); + } } return CDateTime::GetCurrentDateTime().GetAsLocalizedTime("", false); case LISTITEM_NEXT_STARTDATE: { const CPVRChannel *channel = item->HasPVRChannelInfoTag() ? item->GetPVRChannelInfoTag() : NULL; - CEpgInfoTag tag; - if (channel && channel->GetEPGNext(tag)) - return tag.StartAsLocalTime().GetAsLocalizedDate(true); + if (channel) + { + CEpgInfoTagPtr tag(channel->GetEPGNext()); + if (tag) + return tag->StartAsLocalTime().GetAsLocalizedDate(true); + } } return CDateTime::GetCurrentDateTime().GetAsLocalizedDate(true); case LISTITEM_NEXT_ENDDATE: { const CPVRChannel *channel = item->HasPVRChannelInfoTag() ? item->GetPVRChannelInfoTag() : NULL; - CEpgInfoTag tag; - if (channel && channel->GetEPGNext(tag)) - return tag.EndAsLocalTime().GetAsLocalizedDate(true); + if (channel) + { + CEpgInfoTagPtr tag(channel->GetEPGNext()); + if (tag) + return tag->EndAsLocalTime().GetAsLocalizedDate(true); + } } return CDateTime::GetCurrentDateTime().GetAsLocalizedDate(true); case LISTITEM_NEXT_PLOT: { const CPVRChannel *channel = item->HasPVRChannelInfoTag() ? item->GetPVRChannelInfoTag() : NULL; - CEpgInfoTag tag; - if (channel && channel->GetEPGNext(tag)) - return tag.Plot(); + if (channel) + { + CEpgInfoTagPtr tag(channel->GetEPGNext()); + if (tag) + return tag->Plot(); + } } return ""; case LISTITEM_NEXT_PLOT_OUTLINE: { const CPVRChannel *channel = item->HasPVRChannelInfoTag() ? item->GetPVRChannelInfoTag() : NULL; - CEpgInfoTag tag; - if (channel && channel->GetEPGNext(tag)) - return tag.PlotOutline(); + if (channel) + { + CEpgInfoTagPtr tag(channel->GetEPGNext()); + if (tag) + return tag->PlotOutline(); + } } return ""; case LISTITEM_NEXT_DURATION: { const CPVRChannel *channel = item->HasPVRChannelInfoTag() ? item->GetPVRChannelInfoTag() : NULL; - CEpgInfoTag tag; - if (channel && channel->GetEPGNext(tag)) - return StringUtils::SecondsToTimeString(tag.GetDuration()); + if (channel) + { + CEpgInfoTagPtr tag(channel->GetEPGNext()); + if (tag) + return StringUtils::SecondsToTimeString(tag->GetDuration()); + } } return ""; case LISTITEM_NEXT_GENRE: { const CPVRChannel *channel = item->HasPVRChannelInfoTag() ? item->GetPVRChannelInfoTag() : NULL; - CEpgInfoTag tag; - if (channel && channel->GetEPGNext(tag)) - return StringUtils::Join(tag.Genre(), g_advancedSettings.m_videoItemSeparator); + if (channel) + { + CEpgInfoTagPtr tag(channel->GetEPGNext()); + if (tag) + return StringUtils::Join(tag->Genre(), g_advancedSettings.m_videoItemSeparator); + } } return ""; case LISTITEM_NEXT_TITLE: { const CPVRChannel *channel = item->HasPVRChannelInfoTag() ? item->GetPVRChannelInfoTag() : NULL; - CEpgInfoTag tag; - if (channel && channel->GetEPGNext(tag)) - return tag.Title(); + if (channel) + { + CEpgInfoTagPtr tag(channel->GetEPGNext()); + if (tag) + return tag->Title(); + } } return ""; case LISTITEM_PARENTALRATING: @@ -5239,8 +5298,7 @@ bool CGUIInfoManager::GetItemBool(const CGUIListItem *item, int condition) const { if (pItem->HasPVRChannelInfoTag()) { - CEpgInfoTag epgTag; - return pItem->GetPVRChannelInfoTag()->GetEPGNow(epgTag); + return (pItem->GetPVRChannelInfoTag()->GetEPGNow().get() != NULL); } else { @@ -5608,18 +5666,14 @@ bool CGUIInfoManager::ConditionsChangedValues(const std::map<INFO::InfoPtr, bool return false; } -bool CGUIInfoManager::GetEpgInfoTag(CEpgInfoTag& tag) const +CEpgInfoTagPtr CGUIInfoManager::GetEpgInfoTag() const { + CEpgInfoTagPtr currentTag; if (m_currentFile->HasEPGInfoTag()) { - CEpgInfoTag* currentTag = m_currentFile->GetEPGInfoTag(); + currentTag = m_currentFile->GetEPGInfoTag(); while (currentTag && !currentTag->IsActive()) - currentTag = currentTag->GetNextEvent().get(); - if (currentTag) - { - tag = *currentTag; - return true; - } + currentTag = currentTag->GetNextEvent(); } - return false; + return currentTag; } diff --git a/xbmc/GUIInfoManager.h b/xbmc/GUIInfoManager.h index 7cefda1adc..f0e0cf9925 100644 --- a/xbmc/GUIInfoManager.h +++ b/xbmc/GUIInfoManager.h @@ -672,7 +672,11 @@ namespace INFO // forward class CGUIWindow; -namespace EPG { class CEpgInfoTag; } +namespace EPG +{ + class CEpgInfoTag; + typedef boost::shared_ptr<EPG::CEpgInfoTag> CEpgInfoTagPtr; +} // Info Flags // Stored in the top 8 bits of GUIInfo::m_data1 @@ -899,10 +903,9 @@ protected: /*! * @brief Get the EPG tag that is currently active - * @param tag The active tag - * @return True if an EPG tag is active and 'tag' was updated, false otherwise + * @return the currently active tag or NULL if no active tag was found */ - bool GetEpgInfoTag(EPG::CEpgInfoTag& tag) const; + EPG::CEpgInfoTagPtr GetEpgInfoTag() const; // Conditional string parameters are stored here std::vector<std::string> m_stringParameters; diff --git a/xbmc/epg/Epg.cpp b/xbmc/epg/Epg.cpp index 2c34bc84b9..0b9580dbe0 100644 --- a/xbmc/epg/Epg.cpp +++ b/xbmc/epg/Epg.cpp @@ -48,8 +48,6 @@ CEpg::CEpg(int iEpgID, const std::string &strName /* = "" */, const std::string m_strScraperName(strScraperName), m_bUpdateLastScanTime(false) { - CPVRChannelPtr empty; - m_pvrChannel = empty; } CEpg::CEpg(CPVRChannelPtr channel, bool bLoadedFromDb /* = false */) : @@ -73,8 +71,6 @@ CEpg::CEpg(void) : m_iEpgID(0), m_bUpdateLastScanTime(false) { - CPVRChannelPtr empty; - m_pvrChannel = empty; } CEpg::~CEpg(void) @@ -96,10 +92,7 @@ CEpg &CEpg::operator =(const CEpg &right) m_pvrChannel = right.m_pvrChannel; for (map<CDateTime, CEpgInfoTagPtr>::const_iterator it = right.m_tags.begin(); it != right.m_tags.end(); ++it) - { - CEpgInfoTagPtr EITPtr (new CEpgInfoTag(*it->second)); - m_tags.insert(make_pair(it->first, EITPtr)); - } + m_tags.insert(make_pair(it->first, it->second)); return *this; } @@ -183,17 +176,14 @@ void CEpg::Cleanup(const CDateTime &Time) } } -bool CEpg::InfoTagNow(CEpgInfoTag &tag, bool bUpdateIfNeeded /* = true */) +CEpgInfoTagPtr CEpg::GetTagNow(bool bUpdateIfNeeded /* = true */) const { CSingleLock lock(m_critSection); if (m_nowActiveStart.IsValid()) { map<CDateTime, CEpgInfoTagPtr>::const_iterator it = m_tags.find(m_nowActiveStart); if (it != m_tags.end() && it->second->IsActive()) - { - tag = *it->second; - return true; - } + return it->second; } if (bUpdateIfNeeded) @@ -206,8 +196,7 @@ bool CEpg::InfoTagNow(CEpgInfoTag &tag, bool bUpdateIfNeeded /* = true */) if (it->second->IsActive()) { m_nowActiveStart = it->first; - tag = *it->second; - return true; + return it->second; } else if (it->second->WasActive()) lastActiveTag = it->second; @@ -216,27 +205,21 @@ bool CEpg::InfoTagNow(CEpgInfoTag &tag, bool bUpdateIfNeeded /* = true */) /* there might be a gap between the last and next event. return the last if found and it ended not more than 5 minutes ago */ if (lastActiveTag && lastActiveTag->EndAsUTC() + CDateTimeSpan(0, 0, 5, 0) >= CDateTime::GetUTCDateTime()) - { - tag = *lastActiveTag; - return true; - } + return lastActiveTag; } - return false; + return CEpgInfoTagPtr(); } -bool CEpg::InfoTagNext(CEpgInfoTag &tag) +CEpgInfoTagPtr CEpg::GetTagNext() const { - CEpgInfoTag nowTag; - if (InfoTagNow(nowTag)) + CEpgInfoTagPtr nowTag(GetTagNow()); + if (nowTag) { CSingleLock lock(m_critSection); - map<CDateTime, CEpgInfoTagPtr>::const_iterator it = m_tags.find(nowTag.StartAsUTC()); + map<CDateTime, CEpgInfoTagPtr>::const_iterator it = m_tags.find(nowTag->StartAsUTC()); if (it != m_tags.end() && ++it != m_tags.end()) - { - tag = *it->second; - return true; - } + return it->second; } else if (Size() > 0) { @@ -244,32 +227,26 @@ bool CEpg::InfoTagNext(CEpgInfoTag &tag) for (map<CDateTime, CEpgInfoTagPtr>::const_iterator it = m_tags.begin(); it != m_tags.end(); ++it) { if (it->second->InTheFuture()) - { - tag = *it->second; - return true; - } + return it->second; } } - return false; + return CEpgInfoTagPtr(); } bool CEpg::CheckPlayingEvent(void) { - bool bReturn(false); - CEpgInfoTag previousTag, newTag; - bool bGotPreviousTag = InfoTagNow(previousTag, false); - bool bGotCurrentTag = InfoTagNow(newTag); + CEpgInfoTagPtr previousTag(GetTagNow(false)); + CEpgInfoTagPtr newTag(GetTagNow(true)); - bool bTagChanged = bGotCurrentTag && (!bGotPreviousTag || previousTag != newTag); - bool bTagRemoved = !bGotCurrentTag && bGotPreviousTag; + bool bTagChanged = newTag && (!previousTag || *previousTag != *newTag); + bool bTagRemoved = !newTag && previousTag; if (bTagChanged || bTagRemoved) { NotifyObservers(ObservableMessageEpgActiveItem); - bReturn = true; + return true; } - - return bReturn; + return false; } CEpgInfoTagPtr CEpg::GetTag(const CDateTime &StartTime) const @@ -281,8 +258,7 @@ CEpgInfoTagPtr CEpg::GetTag(const CDateTime &StartTime) const return it->second; } - CEpgInfoTagPtr empty; - return empty; + return CEpgInfoTagPtr(); } CEpgInfoTagPtr CEpg::GetTagBetween(const CDateTime &beginTime, const CDateTime &endTime) const @@ -294,8 +270,7 @@ CEpgInfoTagPtr CEpg::GetTagBetween(const CDateTime &beginTime, const CDateTime & return it->second; } - CEpgInfoTagPtr retVal; - return retVal; + return CEpgInfoTagPtr(); } CEpgInfoTagPtr CEpg::GetTagAround(const CDateTime &time) const @@ -307,8 +282,7 @@ CEpgInfoTagPtr CEpg::GetTagAround(const CDateTime &time) const return it->second; } - CEpgInfoTagPtr retVal; - return retVal; + return CEpgInfoTagPtr(); } void CEpg::AddEntry(const CEpgInfoTag &tag) @@ -320,7 +294,7 @@ void CEpg::AddEntry(const CEpgInfoTag &tag) newTag = itr->second; else { - newTag = CEpgInfoTagPtr(new CEpgInfoTag(this, m_pvrChannel, m_strName, m_pvrChannel ? m_pvrChannel->IconPath() : "")); + newTag.reset(new CEpgInfoTag(this, m_pvrChannel, m_strName, m_pvrChannel ? m_pvrChannel->IconPath() : "")); m_tags.insert(make_pair(tag.StartAsUTC(), newTag)); } @@ -347,7 +321,7 @@ bool CEpg::UpdateEntry(const CEpgInfoTag &tag, bool bUpdateDatabase /* = false * else { /* create a new tag if no tag with this ID exists */ - infoTag = CEpgInfoTagPtr(new CEpgInfoTag(this, m_pvrChannel, m_strName, m_pvrChannel ? m_pvrChannel->IconPath() : "")); + infoTag.reset(new CEpgInfoTag(this, m_pvrChannel, m_strName, m_pvrChannel ? m_pvrChannel->IconPath() : "")); infoTag->SetUniqueBroadcastID(tag.UniqueBroadcastID()); m_tags.insert(make_pair(tag.StartAsUTC(), infoTag)); bNewTag = true; @@ -355,7 +329,7 @@ bool CEpg::UpdateEntry(const CEpgInfoTag &tag, bool bUpdateDatabase /* = false * infoTag->Update(tag, bNewTag); infoTag->m_epg = this; - infoTag->m_pvrChannel = m_pvrChannel; + infoTag->SetPVRChannel(m_pvrChannel); UpdateRecording(infoTag); if (bUpdateDatabase) @@ -364,7 +338,7 @@ bool CEpg::UpdateEntry(const CEpgInfoTag &tag, bool bUpdateDatabase /* = false * return true; } -void CEpg::UpdateRecording(CEpgInfoTagPtr tag) +void CEpg::UpdateRecording(CEpgInfoTagPtr &tag) { if (!tag) return; @@ -528,7 +502,7 @@ int CEpg::Get(CFileItemList &results) const CSingleLock lock(m_critSection); for (map<CDateTime, CEpgInfoTagPtr>::const_iterator it = m_tags.begin(); it != m_tags.end(); ++it) - results.Add(CFileItemPtr(new CFileItem(*it->second))); + results.Add(CFileItemPtr(new CFileItem(it->second))); return results.Size() - iInitialSize; } @@ -545,7 +519,7 @@ int CEpg::Get(CFileItemList &results, const EpgSearchFilter &filter) const for (map<CDateTime, CEpgInfoTagPtr>::const_iterator it = m_tags.begin(); it != m_tags.end(); ++it) { if (filter.FilterEntry(*it->second)) - results.Add(CFileItemPtr(new CFileItem(*it->second))); + results.Add(CFileItemPtr(new CFileItem(it->second))); } return results.Size() - iInitialSize; @@ -766,8 +740,8 @@ bool CEpg::UpdateEntry(const EPG_TAG *data, bool bUpdateDatabase /* = false */) if (!data) return false; - CEpgInfoTag tag(*data); - return UpdateEntry(tag, bUpdateDatabase); + CEpgInfoTagPtr tag(new CEpgInfoTag(*data)); + return UpdateEntry(*tag, bUpdateDatabase); } bool CEpg::IsRadio(void) const diff --git a/xbmc/epg/Epg.h b/xbmc/epg/Epg.h index 4a5c66eb44..da5ad15c94 100644 --- a/xbmc/epg/Epg.h +++ b/xbmc/epg/Epg.h @@ -165,16 +165,16 @@ namespace EPG void Clear(void); /*! - * @brief Get the event that is occurring now. - * @return The current event. + * @brief Get the event that is occurring now + * @return The current event or NULL if it wasn't found. */ - bool InfoTagNow(CEpgInfoTag &tag, bool bUpdateIfNeeded = true); + CEpgInfoTagPtr GetTagNow(bool bUpdateIfNeeded = true) const; /*! - * @brief Get the event that will occur next. - * @return The next event. + * @brief Get the event that will occur next + * @return The next event or NULL if it wasn't found. */ - bool InfoTagNext(CEpgInfoTag &tag); + CEpgInfoTagPtr GetTagNext() const; /*! * @brief Get the event that occurs at the given time. @@ -340,7 +340,7 @@ namespace EPG bool IsRemovableTag(const EPG::CEpgInfoTag &tag) const; - void UpdateRecording(CEpgInfoTagPtr tag); + void UpdateRecording(CEpgInfoTagPtr &tag); std::map<CDateTime, CEpgInfoTagPtr> m_tags; std::map<int, CEpgInfoTagPtr> m_changedTags; @@ -352,7 +352,7 @@ namespace EPG int m_iEpgID; /*!< the database ID of this table */ std::string m_strName; /*!< the name of this table */ std::string m_strScraperName; /*!< the name of the scraper to use */ - CDateTime m_nowActiveStart; /*!< the start time of the tag that is currently active */ + mutable CDateTime m_nowActiveStart; /*!< the start time of the tag that is currently active */ CDateTime m_lastScanTime; /*!< the last time the EPG has been updated */ diff --git a/xbmc/epg/EpgDatabase.cpp b/xbmc/epg/EpgDatabase.cpp index 3f827b1b0a..8e21e5033b 100644 --- a/xbmc/epg/EpgDatabase.cpp +++ b/xbmc/epg/EpgDatabase.cpp @@ -200,40 +200,40 @@ int CEpgDatabase::Get(CEpg &epg) { while (!m_pDS->eof()) { - CEpgInfoTag newTag; + CEpgInfoTagPtr newTag(new CEpgInfoTag()); time_t iStartTime, iEndTime, iFirstAired; iStartTime = (time_t) m_pDS->fv("iStartTime").get_asInt(); CDateTime startTime(iStartTime); - newTag.m_startTime = startTime; + newTag->m_startTime = startTime; iEndTime = (time_t) m_pDS->fv("iEndTime").get_asInt(); CDateTime endTime(iEndTime); - newTag.m_endTime = endTime; + newTag->m_endTime = endTime; iFirstAired = (time_t) m_pDS->fv("iFirstAired").get_asInt(); CDateTime firstAired(iFirstAired); - newTag.m_firstAired = firstAired; - - newTag.m_iUniqueBroadcastID = m_pDS->fv("iBroadcastUid").get_asInt(); - newTag.m_iBroadcastId = m_pDS->fv("idBroadcast").get_asInt(); - newTag.m_strTitle = m_pDS->fv("sTitle").get_asString().c_str(); - newTag.m_strPlotOutline = m_pDS->fv("sPlotOutline").get_asString().c_str(); - newTag.m_strPlot = m_pDS->fv("sPlot").get_asString().c_str(); - newTag.m_iGenreType = m_pDS->fv("iGenreType").get_asInt(); - newTag.m_iGenreSubType = m_pDS->fv("iGenreSubType").get_asInt(); - newTag.m_genre = StringUtils::Split(m_pDS->fv("sGenre").get_asString().c_str(), g_advancedSettings.m_videoItemSeparator); - newTag.m_iParentalRating = m_pDS->fv("iParentalRating").get_asInt(); - newTag.m_iStarRating = m_pDS->fv("iStarRating").get_asInt(); - newTag.m_bNotify = m_pDS->fv("bNotify").get_asBool(); - newTag.m_iEpisodeNumber = m_pDS->fv("iEpisodeId").get_asInt(); - newTag.m_iEpisodePart = m_pDS->fv("iEpisodePart").get_asInt(); - newTag.m_strEpisodeName = m_pDS->fv("sEpisodeName").get_asString().c_str(); - newTag.m_iSeriesNumber = m_pDS->fv("iSeriesId").get_asInt(); - newTag.m_strRecordingId = m_pDS->fv("sRecordingId").get_asString().c_str(); - newTag.m_strIconPath = m_pDS->fv("sIconPath").get_asString().c_str(); - - epg.AddEntry(newTag); + newTag->m_firstAired = firstAired; + + newTag->m_iUniqueBroadcastID = m_pDS->fv("iBroadcastUid").get_asInt(); + newTag->m_iBroadcastId = m_pDS->fv("idBroadcast").get_asInt(); + newTag->m_strTitle = m_pDS->fv("sTitle").get_asString().c_str(); + newTag->m_strPlotOutline = m_pDS->fv("sPlotOutline").get_asString().c_str(); + newTag->m_strPlot = m_pDS->fv("sPlot").get_asString().c_str(); + newTag->m_iGenreType = m_pDS->fv("iGenreType").get_asInt(); + newTag->m_iGenreSubType = m_pDS->fv("iGenreSubType").get_asInt(); + newTag->m_genre = StringUtils::Split(m_pDS->fv("sGenre").get_asString().c_str(), g_advancedSettings.m_videoItemSeparator); + newTag->m_iParentalRating = m_pDS->fv("iParentalRating").get_asInt(); + newTag->m_iStarRating = m_pDS->fv("iStarRating").get_asInt(); + newTag->m_bNotify = m_pDS->fv("bNotify").get_asBool(); + newTag->m_iEpisodeNumber = m_pDS->fv("iEpisodeId").get_asInt(); + newTag->m_iEpisodePart = m_pDS->fv("iEpisodePart").get_asInt(); + newTag->m_strEpisodeName = m_pDS->fv("sEpisodeName").get_asString().c_str(); + newTag->m_iSeriesNumber = m_pDS->fv("iSeriesId").get_asInt(); + newTag->m_strRecordingId = m_pDS->fv("sRecordingId").get_asString().c_str(); + newTag->m_strIconPath = m_pDS->fv("sIconPath").get_asString().c_str(); + + epg.AddEntry(*newTag); ++iReturn; m_pDS->next(); diff --git a/xbmc/epg/EpgInfoTag.cpp b/xbmc/epg/EpgInfoTag.cpp index 76dcd594a1..6a4dbd5c30 100644 --- a/xbmc/epg/EpgInfoTag.cpp +++ b/xbmc/epg/EpgInfoTag.cpp @@ -38,6 +38,11 @@ using namespace std; using namespace EPG; using namespace PVR; +CEpgInfoTagPtr CEpgInfoTag::CreateDefaultTag() +{ + return CEpgInfoTagPtr(new CEpgInfoTag()); +} + CEpgInfoTag::CEpgInfoTag(void) : m_bNotify(false), m_bChanged(false), @@ -52,11 +57,6 @@ CEpgInfoTag::CEpgInfoTag(void) : m_iUniqueBroadcastID(-1), m_epg(NULL) { - CPVRChannelPtr emptyChannel; - m_pvrChannel = emptyChannel; - - CPVRTimerInfoTagPtr emptyTimer; - m_timer = emptyTimer; } CEpgInfoTag::CEpgInfoTag(CEpg *epg, PVR::CPVRChannelPtr pvrChannel, const std::string &strTableName /* = "" */, const std::string &strIconPath /* = "" */) : @@ -75,8 +75,6 @@ CEpgInfoTag::CEpgInfoTag(CEpg *epg, PVR::CPVRChannelPtr pvrChannel, const std::s m_epg(epg), m_pvrChannel(pvrChannel) { - CPVRTimerInfoTagPtr emptyTimer; - m_timer = emptyTimer; } CEpgInfoTag::CEpgInfoTag(const EPG_TAG &data) : @@ -93,12 +91,6 @@ CEpgInfoTag::CEpgInfoTag(const EPG_TAG &data) : m_iUniqueBroadcastID(-1), m_epg(NULL) { - CPVRChannelPtr emptyChannel; - m_pvrChannel = emptyChannel; - - CPVRTimerInfoTagPtr emptyTimer; - m_timer = emptyTimer; - SetStartFromUTC(data.startTime + g_advancedSettings.m_iPVRTimeCorrection); SetEndFromUTC(data.endTime + g_advancedSettings.m_iPVRTimeCorrection); SetGenre(data.iGenreType, data.iGenreSubType, data.strGenreDescription); @@ -125,36 +117,6 @@ CEpgInfoTag::CEpgInfoTag(const EPG_TAG &data) : SetRecordingId(data.strRecordingId); } -CEpgInfoTag::CEpgInfoTag(const CEpgInfoTag &tag) : - m_bNotify(tag.m_bNotify), - m_bChanged(tag.m_bChanged), - m_iBroadcastId(tag.m_iBroadcastId), - m_iGenreType(tag.m_iGenreType), - m_iGenreSubType(tag.m_iGenreSubType), - m_iParentalRating(tag.m_iParentalRating), - m_iStarRating(tag.m_iStarRating), - m_iSeriesNumber(tag.m_iSeriesNumber), - m_iEpisodeNumber(tag.m_iEpisodeNumber), - m_iEpisodePart(tag.m_iEpisodePart), - m_iUniqueBroadcastID(tag.m_iUniqueBroadcastID), - m_strTitle(tag.m_strTitle), - m_strPlotOutline(tag.m_strPlotOutline), - m_strPlot(tag.m_strPlot), - m_genre(tag.m_genre), - m_strEpisodeName(tag.m_strEpisodeName), - m_strIconPath(tag.m_strIconPath), - m_strFileNameAndPath(tag.m_strFileNameAndPath), - m_startTime(tag.m_startTime), - m_endTime(tag.m_endTime), - m_firstAired(tag.m_firstAired), - m_strRecordingId(tag.m_strRecordingId), - m_timer(tag.m_timer), - m_recording(tag.m_recording), - m_epg(tag.m_epg), - m_pvrChannel(tag.m_pvrChannel) -{ -} - CEpgInfoTag::~CEpgInfoTag() { ClearTimer(); @@ -198,40 +160,6 @@ bool CEpgInfoTag::operator !=(const CEpgInfoTag& right) const return !(*this == right); } -CEpgInfoTag &CEpgInfoTag::operator =(const CEpgInfoTag &other) -{ - CSingleLock lock(other.m_critSection); - - m_bNotify = other.m_bNotify; - m_bChanged = other.m_bChanged; - m_iBroadcastId = other.m_iBroadcastId; - m_iGenreType = other.m_iGenreType; - m_iGenreSubType = other.m_iGenreSubType; - m_iParentalRating = other.m_iParentalRating; - m_iStarRating = other.m_iStarRating; - m_iSeriesNumber = other.m_iSeriesNumber; - m_iEpisodeNumber = other.m_iEpisodeNumber; - m_iEpisodePart = other.m_iEpisodePart; - m_iUniqueBroadcastID = other.m_iUniqueBroadcastID; - m_strTitle = other.m_strTitle; - m_strPlotOutline = other.m_strPlotOutline; - m_strPlot = other.m_strPlot; - m_genre = other.m_genre; - m_strEpisodeName = other.m_strEpisodeName; - m_strIconPath = other.m_strIconPath; - m_strFileNameAndPath = other.m_strFileNameAndPath; - m_startTime = other.m_startTime; - m_endTime = other.m_endTime; - m_firstAired = other.m_firstAired; - m_timer = other.m_timer; - m_strRecordingId = other.m_strRecordingId; - m_recording = other.m_recording; - m_epg = other.m_epg; - m_pvrChannel = other.m_pvrChannel; - - return *this; -} - void CEpgInfoTag::Serialize(CVariant &value) const { value["broadcastid"] = m_iUniqueBroadcastID; diff --git a/xbmc/epg/EpgInfoTag.h b/xbmc/epg/EpgInfoTag.h index ff1e4a0945..de0162fb05 100644 --- a/xbmc/epg/EpgInfoTag.h +++ b/xbmc/epg/EpgInfoTag.h @@ -44,9 +44,17 @@ namespace EPG { friend class CEpg; friend class CEpgDatabase; - friend class PVR::CPVRTimerInfoTag; public: + /*! + * @brief Create a new empty event . + */ + static CEpgInfoTagPtr CreateDefaultTag(); + + private: + /*! + * @brief Create a new empty event. + */ CEpgInfoTag(void); /*! @@ -60,16 +68,23 @@ namespace EPG */ CEpgInfoTag(const EPG_TAG &data); - /*! - * @brief Create a new EPG infotag with 'tag' as content. - * @param tag The tag's content. - */ + // Prevent copy construction, even for CEpgInfoTag instances and friends. + // Note: Only declared, but intentionally not implemented + // to prevent compiler generated copy ctor and to force + // a linker error in case somebody tries to call it. CEpgInfoTag(const CEpgInfoTag &tag); + + // Prevent copy by assignment, even for CEpgInfoTag instances and friends. + // Note: Only declared, but intentionally not implemented + // to prevent compiler generated assignment operator and to force + // a linker error in case somebody tries to call it. + CEpgInfoTag &operator =(const CEpgInfoTag &other); + + public: virtual ~CEpgInfoTag(); bool operator ==(const CEpgInfoTag& right) const; bool operator !=(const CEpgInfoTag& right) const; - CEpgInfoTag &operator =(const CEpgInfoTag &other); virtual void Serialize(CVariant &value) const; @@ -464,7 +479,8 @@ namespace EPG * @return True if something changed, false otherwise. */ bool Update(const CEpgInfoTag &tag, bool bUpdateBroadcastId = true); - protected: + + private: /*! * @brief Hook that is called when the start date changed. */ diff --git a/xbmc/epg/EpgSearchFilter.cpp b/xbmc/epg/EpgSearchFilter.cpp index 8b3e9e8d64..39e328d0a2 100644 --- a/xbmc/epg/EpgSearchFilter.cpp +++ b/xbmc/epg/EpgSearchFilter.cpp @@ -133,13 +133,19 @@ int EpgSearchFilter::RemoveDuplicates(CFileItemList &results) for (unsigned int iResultPtr = 0; iResultPtr < iSize; iResultPtr++) { - const CEpgInfoTag *epgentry_1 = results.Get(iResultPtr)->GetEPGInfoTag(); + const CEpgInfoTagPtr epgentry_1(results.Get(iResultPtr)->GetEPGInfoTag()); + if (!epgentry_1) + continue; + for (unsigned int iTagPtr = 0; iTagPtr < iSize; iTagPtr++) { - const CEpgInfoTag *epgentry_2 = results.Get(iTagPtr)->GetEPGInfoTag(); if (iResultPtr == iTagPtr) continue; + const CEpgInfoTagPtr epgentry_2(results.Get(iTagPtr)->GetEPGInfoTag()); + if (!epgentry_2) + continue; + if (epgentry_1->Title() != epgentry_2->Title() || epgentry_1->Plot() != epgentry_2->Plot() || epgentry_1->PlotOutline() != epgentry_2->PlotOutline()) @@ -207,7 +213,7 @@ int EpgSearchFilter::FilterRecordings(CFileItemList &results) for (int iResultPtr = 0; iResultPtr < results.Size(); iResultPtr++) { - const CEpgInfoTag *epgentry = results.Get(iResultPtr)->GetEPGInfoTag(); + const CEpgInfoTagPtr epgentry(results.Get(iResultPtr)->GetEPGInfoTag()); /* no match */ if (!epgentry || @@ -244,7 +250,7 @@ int EpgSearchFilter::FilterTimers(CFileItemList &results) for (int iResultPtr = 0; iResultPtr < results.Size(); iResultPtr++) { - const CEpgInfoTag *epgentry = results.Get(iResultPtr)->GetEPGInfoTag(); + const CEpgInfoTagPtr epgentry(results.Get(iResultPtr)->GetEPGInfoTag()); if (!epgentry || *epgentry->ChannelTag() != *timer->ChannelTag() || epgentry->StartAsUTC() < timer->StartAsUTC() || diff --git a/xbmc/epg/GUIEPGGridContainer.cpp b/xbmc/epg/GUIEPGGridContainer.cpp index bc947ea46d..2c3d624b20 100644 --- a/xbmc/epg/GUIEPGGridContainer.cpp +++ b/xbmc/epg/GUIEPGGridContainer.cpp @@ -753,7 +753,10 @@ bool CGUIEPGGridContainer::OnMessage(CGUIMessage& message) itemsPointer.start = 0; for (unsigned int i = 0; i < m_programmeItems.size(); ++i) { - const CEpgInfoTag* tag = ((CFileItem*)m_programmeItems[i].get())->GetEPGInfoTag(); + const CEpgInfoTagPtr tag(((CFileItem*)m_programmeItems[i].get())->GetEPGInfoTag()); + if (!tag) + continue; + CPVRChannelPtr channel = tag->ChannelTag(); if (!channel) continue; @@ -855,10 +858,11 @@ void CGUIEPGGridContainer::UpdateItems() for (unsigned int row = 0; row < m_epgItemsPtr.size(); ++row) { - CDateTime gridCursor = m_gridStart; //reset cursor for new channel - unsigned long progIdx = m_epgItemsPtr[row].start; - unsigned long lastIdx = m_epgItemsPtr[row].stop; - int iEpgId = ((CFileItem *)m_programmeItems[progIdx].get())->GetEPGInfoTag()->EpgID(); + CDateTime gridCursor = m_gridStart; //reset cursor for new channel + unsigned long progIdx = m_epgItemsPtr[row].start; + unsigned long lastIdx = m_epgItemsPtr[row].stop; + const CEpgInfoTagPtr info = ((CFileItem *)m_programmeItems[progIdx].get())->GetEPGInfoTag(); + int iEpgId = info ? info->EpgID() : -1; /** FOR EACH BLOCK **********************************************************************/ @@ -867,8 +871,8 @@ void CGUIEPGGridContainer::UpdateItems() while (progIdx <= lastIdx) { CGUIListItemPtr item = m_programmeItems[progIdx]; - const CEpgInfoTag* tag = ((CFileItem *)item.get())->GetEPGInfoTag(); - if (tag == NULL) + const CEpgInfoTagPtr tag(((CFileItem *)item.get())->GetEPGInfoTag()); + if (!tag) { progIdx++; continue; @@ -901,7 +905,7 @@ void CGUIEPGGridContainer::UpdateItems() { if (!item) { - CEpgInfoTag gapTag; + CEpgInfoTagPtr gapTag(CEpgInfoTag::CreateDefaultTag()); CFileItemPtr gapItem(new CFileItem(gapTag)); for (int i = block ; i > block - itemSize; i--) { @@ -910,8 +914,9 @@ void CGUIEPGGridContainer::UpdateItems() } else { - const CEpgInfoTag* tag = ((CFileItem *)item.get())->GetEPGInfoTag(); - m_gridIndex[row][savedBlock].item->SetProperty("GenreType", tag->GenreType()); + const CEpgInfoTagPtr tag(((CFileItem *)item.get())->GetEPGInfoTag()); + if (tag) + m_gridIndex[row][savedBlock].item->SetProperty("GenreType", tag->GenreType()); } m_gridIndex[row][savedBlock].originWidth = itemSize*m_blockSize; diff --git a/xbmc/interfaces/json-rpc/FileItemHandler.cpp b/xbmc/interfaces/json-rpc/FileItemHandler.cpp index 60fe6256ac..3066bf00e3 100644 --- a/xbmc/interfaces/json-rpc/FileItemHandler.cpp +++ b/xbmc/interfaces/json-rpc/FileItemHandler.cpp @@ -357,7 +357,7 @@ void CFileItemHandler::HandleFileItem(const char *ID, bool allowFile, const char if (item->HasPVRChannelInfoTag()) FillDetails(item->GetPVRChannelInfoTag(), item, fields, object, thumbLoader); if (item->HasEPGInfoTag()) - FillDetails(item->GetEPGInfoTag(), item, fields, object, thumbLoader); + FillDetails(item->GetEPGInfoTag().get(), item, fields, object, thumbLoader); if (item->HasPVRRecordingInfoTag()) FillDetails(item->GetPVRRecordingInfoTag(), item, fields, object, thumbLoader); if (item->HasPVRTimerInfoTag()) diff --git a/xbmc/interfaces/json-rpc/PlayerOperations.cpp b/xbmc/interfaces/json-rpc/PlayerOperations.cpp index 4cbdc24bc6..dc84202b4d 100644 --- a/xbmc/interfaces/json-rpc/PlayerOperations.cpp +++ b/xbmc/interfaces/json-rpc/PlayerOperations.cpp @@ -1203,9 +1203,9 @@ JSONRPC_STATUS CPlayerOperations::GetPropertyValue(PlayerType player, const std: ms = (int)(g_application.GetTime() * 1000.0); else { - EPG::CEpgInfoTag epg; - if (GetCurrentEpg(epg)) - ms = epg.Progress() * 1000; + EPG::CEpgInfoTagPtr epg(GetCurrentEpg()); + if (epg) + ms = epg->Progress() * 1000; } MillisecondsToTimeObject(ms, result); @@ -1232,9 +1232,9 @@ JSONRPC_STATUS CPlayerOperations::GetPropertyValue(PlayerType player, const std: result = g_application.GetPercentage(); else { - EPG::CEpgInfoTag epg; - if (GetCurrentEpg(epg)) - result = epg.ProgressPercentage(); + EPG::CEpgInfoTagPtr epg(GetCurrentEpg()); + if (epg) + result = epg->ProgressPercentage(); else result = 0; } @@ -1265,9 +1265,9 @@ JSONRPC_STATUS CPlayerOperations::GetPropertyValue(PlayerType player, const std: ms = (int)(g_application.GetTotalTime() * 1000.0); else { - EPG::CEpgInfoTag epg; - if (GetCurrentEpg(epg)) - ms = epg.GetDuration() * 1000; + EPG::CEpgInfoTagPtr epg(GetCurrentEpg()); + if (epg) + ms = epg->GetDuration() * 1000; } MillisecondsToTimeObject(ms, result); @@ -1661,17 +1661,14 @@ bool CPlayerOperations::IsPVRChannel() return g_PVRManager.IsPlayingTV() || g_PVRManager.IsPlayingRadio(); } -bool CPlayerOperations::GetCurrentEpg(EPG::CEpgInfoTag &epg) +EPG::CEpgInfoTagPtr CPlayerOperations::GetCurrentEpg() { if (!g_PVRManager.IsPlayingTV() && !g_PVRManager.IsPlayingRadio()) - return false; + return EPG::CEpgInfoTagPtr(); CPVRChannelPtr currentChannel; if (!g_PVRManager.GetCurrentChannel(currentChannel)) - return false; + return EPG::CEpgInfoTagPtr(); - if (!currentChannel->GetEPGNow(epg)) - return false; - - return true; + return currentChannel->GetEPGNow(); } diff --git a/xbmc/interfaces/json-rpc/PlayerOperations.h b/xbmc/interfaces/json-rpc/PlayerOperations.h index fc804e8d66..b2c9274287 100644 --- a/xbmc/interfaces/json-rpc/PlayerOperations.h +++ b/xbmc/interfaces/json-rpc/PlayerOperations.h @@ -25,6 +25,7 @@ namespace EPG { class CEpgInfoTag; + typedef boost::shared_ptr<EPG::CEpgInfoTag> CEpgInfoTagPtr; } namespace JSONRPC @@ -76,6 +77,6 @@ namespace JSONRPC static int ParseRepeatState(const CVariant &repeat); static double ParseTimeInSeconds(const CVariant &time); static bool IsPVRChannel(); - static bool GetCurrentEpg(EPG::CEpgInfoTag &epg); + static EPG::CEpgInfoTagPtr GetCurrentEpg(); }; } diff --git a/xbmc/pvr/PVRGUIInfo.cpp b/xbmc/pvr/PVRGUIInfo.cpp index 7cdde17441..b178ec3a6b 100644 --- a/xbmc/pvr/PVRGUIInfo.cpp +++ b/xbmc/pvr/PVRGUIInfo.cpp @@ -39,8 +39,7 @@ using namespace PVR; using namespace EPG; CPVRGUIInfo::CPVRGUIInfo(void) : - CThread("PVRGUIInfo"), - m_playingEpgTag(NULL) + CThread("PVRGUIInfo") { ResetProperties(); } @@ -860,22 +859,14 @@ int CPVRGUIInfo::GetStartTime(void) const void CPVRGUIInfo::ResetPlayingTag(void) { CSingleLock lock(m_critSection); - SAFE_DELETE(m_playingEpgTag); + m_playingEpgTag.reset(); m_iDuration = 0; } -bool CPVRGUIInfo::GetPlayingTag(CEpgInfoTag &tag) const +CEpgInfoTagPtr CPVRGUIInfo::GetPlayingTag() const { - bool bReturn(false); - CSingleLock lock(m_critSection); - if (m_playingEpgTag) - { - tag = *m_playingEpgTag; - bReturn = true; - } - - return bReturn; + return m_playingEpgTag; } void CPVRGUIInfo::UpdatePlayingTag(void) @@ -884,22 +875,21 @@ void CPVRGUIInfo::UpdatePlayingTag(void) CPVRRecording recording; if (g_PVRManager.GetCurrentChannel(currentChannel)) { - CEpgInfoTag epgTag; - bool bHasEpgTag = GetPlayingTag(epgTag); + CEpgInfoTagPtr epgTag(GetPlayingTag()); CPVRChannelPtr channel; - if (bHasEpgTag) - channel = epgTag.ChannelTag(); + if (epgTag) + channel = epgTag->ChannelTag(); - if (!bHasEpgTag || !epgTag.IsActive() || + if (!epgTag || !epgTag->IsActive() || !channel || *channel != *currentChannel) { - CEpgInfoTag newTag; { CSingleLock lock(m_critSection); ResetPlayingTag(); - if (currentChannel->GetEPGNow(newTag)) + CEpgInfoTagPtr newTag(currentChannel->GetEPGNow()); + if (newTag) { - m_playingEpgTag = new CEpgInfoTag(newTag); + m_playingEpgTag = newTag; m_iDuration = m_playingEpgTag->GetDuration() * 1000; } } diff --git a/xbmc/pvr/PVRGUIInfo.h b/xbmc/pvr/PVRGUIInfo.h index f1cfb2192a..9e66e6d62e 100644 --- a/xbmc/pvr/PVRGUIInfo.h +++ b/xbmc/pvr/PVRGUIInfo.h @@ -28,6 +28,7 @@ namespace EPG { class CEpgInfoTag; + typedef boost::shared_ptr<EPG::CEpgInfoTag> CEpgInfoTagPtr; } namespace PVR @@ -75,11 +76,16 @@ namespace PVR */ void ResetPlayingTag(void); - bool GetPlayingTag(EPG::CEpgInfoTag &tag) const; + /*! + * @brief Get the currently playing EPG tag. + * @return The currently playing EPG tag or NULL if no EPG tag is playing. + */ + EPG::CEpgInfoTagPtr GetPlayingTag() const; /*! - * @brief Get playing TV group. - */ + * @brief Get playing TV group. + * @return The currently playing TV group or NULL if no TV group is playing. + */ std::string GetPlayingTVGroup(); private: @@ -176,7 +182,7 @@ namespace PVR unsigned int m_iTimerInfoToggleStart; unsigned int m_iTimerInfoToggleCurrent; XbmcThreads::EndTime m_ToggleShowInfo; - EPG::CEpgInfoTag * m_playingEpgTag; + EPG::CEpgInfoTagPtr m_playingEpgTag; CCriticalSection m_critSection; }; diff --git a/xbmc/pvr/PVRManager.cpp b/xbmc/pvr/PVRManager.cpp index a80bc81a6f..91596fbb24 100644 --- a/xbmc/pvr/PVRManager.cpp +++ b/xbmc/pvr/PVRManager.cpp @@ -1145,22 +1145,21 @@ bool CPVRManager::UpdateItem(CFileItem& item) g_infoManager.SetCurrentItem(*m_currentFile); CPVRChannel* channelTag = item.GetPVRChannelInfoTag(); - CEpgInfoTag epgTagNow; - bool bHasTagNow = channelTag->GetEPGNow(epgTagNow); + CEpgInfoTagPtr epgTagNow(channelTag->GetEPGNow()); if (channelTag->IsRadio()) { CMusicInfoTag* musictag = item.GetMusicInfoTag(); if (musictag) { - musictag->SetTitle(bHasTagNow ? - epgTagNow.Title() : + musictag->SetTitle(epgTagNow ? + epgTagNow->Title() : CSettings::Get().GetBool("epg.hidenoinfoavailable") ? "" : g_localizeStrings.Get(19055)); // no information available - if (bHasTagNow) - musictag->SetGenre(epgTagNow.Genre()); - musictag->SetDuration(bHasTagNow ? epgTagNow.GetDuration() : 3600); + if (epgTagNow) + musictag->SetGenre(epgTagNow->Genre()); + musictag->SetDuration(epgTagNow ? epgTagNow->GetDuration() : 3600); musictag->SetURL(channelTag->Path()); musictag->SetArtist(channelTag->ChannelName()); musictag->SetAlbumArtist(channelTag->ChannelName()); @@ -1174,18 +1173,18 @@ bool CPVRManager::UpdateItem(CFileItem& item) CVideoInfoTag *videotag = item.GetVideoInfoTag(); if (videotag) { - videotag->m_strTitle = bHasTagNow ? - epgTagNow.Title() : + videotag->m_strTitle = epgTagNow ? + epgTagNow->Title() : CSettings::Get().GetBool("epg.hidenoinfoavailable") ? "" : g_localizeStrings.Get(19055); // no information available - if (bHasTagNow) - videotag->m_genre = epgTagNow.Genre(); + if (epgTagNow) + videotag->m_genre = epgTagNow->Genre(); videotag->m_strPath = channelTag->Path(); videotag->m_strFileNameAndPath = channelTag->Path(); - videotag->m_strPlot = bHasTagNow ? epgTagNow.Plot() : ""; - videotag->m_strPlotOutline = bHasTagNow ? epgTagNow.PlotOutline() : ""; - videotag->m_iEpisode = bHasTagNow ? epgTagNow.EpisodeNum() : 0; + videotag->m_strPlot = epgTagNow ? epgTagNow->Plot() : ""; + videotag->m_strPlotOutline = epgTagNow ? epgTagNow->PlotOutline() : ""; + videotag->m_iEpisode = epgTagNow ? epgTagNow->EpisodeNum() : 0; } } diff --git a/xbmc/pvr/channels/PVRChannel.cpp b/xbmc/pvr/channels/PVRChannel.cpp index 3416304c91..ba3565c64a 100644 --- a/xbmc/pvr/channels/PVRChannel.cpp +++ b/xbmc/pvr/channels/PVRChannel.cpp @@ -161,17 +161,18 @@ void CPVRChannel::Serialize(CVariant& value) const value["channelnumber"] = m_iCachedChannelNumber; value["subchannelnumber"] = m_iCachedSubChannelNumber; - CEpgInfoTag epg; - if (GetEPGNow(epg)) + CEpgInfoTagPtr epg(GetEPGNow()); + if (epg) { // add the properties of the current EPG item to the main object - epg.Serialize(value); + epg->Serialize(value); // and add an extra sub-object with only the current EPG details - epg.Serialize(value["broadcastnow"]); + epg->Serialize(value["broadcastnow"]); } - if (GetEPGNext(epg)) - epg.Serialize(value["broadcastnext"]); + epg = GetEPGNext(); + if (epg) + epg->Serialize(value["broadcastnext"]); } /********** XBMC related channel methods **********/ @@ -616,16 +617,24 @@ bool CPVRChannel::ClearEPG() const return true; } -bool CPVRChannel::GetEPGNow(CEpgInfoTag &tag) const +CEpgInfoTagPtr CPVRChannel::GetEPGNow() const { CEpg *epg = GetEPG(); - return epg ? epg->InfoTagNow(tag) : false; + if (epg) + return epg->GetTagNow(); + + CEpgInfoTagPtr empty; + return empty; } -bool CPVRChannel::GetEPGNext(CEpgInfoTag &tag) const +CEpgInfoTagPtr CPVRChannel::GetEPGNext() const { CEpg *epg = GetEPG(); - return epg ? epg->InfoTagNext(tag) : false; + if (epg) + return epg->GetTagNext(); + + CEpgInfoTagPtr empty; + return empty; } bool CPVRChannel::SetEPGEnabled(bool bEPGEnabled) diff --git a/xbmc/pvr/channels/PVRChannel.h b/xbmc/pvr/channels/PVRChannel.h index 63a16a1177..abbe577313 100644 --- a/xbmc/pvr/channels/PVRChannel.h +++ b/xbmc/pvr/channels/PVRChannel.h @@ -32,6 +32,9 @@ namespace EPG { class CEpg; + class CEpgInfoTag; + typedef boost::shared_ptr<CEpgInfoTag> CEpgInfoTagPtr; + } namespace PVR @@ -411,7 +414,7 @@ namespace PVR * * @return The EPG tag that is active on this channel now. */ - bool GetEPGNow(EPG::CEpgInfoTag &tag) const; + EPG::CEpgInfoTagPtr GetEPGNow() const; /*! * @brief Get the EPG tag that is active on this channel next. @@ -421,7 +424,7 @@ namespace PVR * * @return The EPG tag that is active on this channel next. */ - bool GetEPGNext(EPG::CEpgInfoTag &tag) const; + EPG::CEpgInfoTagPtr GetEPGNext() const; /*! * @return Don't use an EPG for this channel if set to false. diff --git a/xbmc/pvr/channels/PVRChannelGroup.cpp b/xbmc/pvr/channels/PVRChannelGroup.cpp index ef27a04a2a..08731124d6 100644 --- a/xbmc/pvr/channels/PVRChannelGroup.cpp +++ b/xbmc/pvr/channels/PVRChannelGroup.cpp @@ -1096,12 +1096,12 @@ int CPVRChannelGroup::GetEPGNow(CFileItemList &results) if (!epg || !epg->HasValidEntries() || m_members.at(iChannelPtr).channel->IsHidden()) continue; - CEpgInfoTag epgNow; - if (!epg->InfoTagNow(epgNow)) + CEpgInfoTagPtr epgNow(epg->GetTagNow()); + if (!epgNow) continue; CFileItemPtr entry(new CFileItem(epgNow)); - entry->SetLabel2(epgNow.StartAsLocalTime().GetAsLocalizedTime("", false)); + entry->SetLabel2(epgNow->StartAsLocalTime().GetAsLocalizedTime("", false)); entry->SetPath(channel->Path()); entry->SetArt("thumb", channel->IconPath()); results.Add(entry); @@ -1122,12 +1122,12 @@ int CPVRChannelGroup::GetEPGNext(CFileItemList &results) if (!epg || !epg->HasValidEntries() || m_members.at(iChannelPtr).channel->IsHidden()) continue; - CEpgInfoTag epgNow; - if (!epg->InfoTagNext(epgNow)) + CEpgInfoTagPtr epgNext(epg->GetTagNext()); + if (!epgNext) continue; - CFileItemPtr entry(new CFileItem(epgNow)); - entry->SetLabel2(epgNow.StartAsLocalTime().GetAsLocalizedTime("", false)); + CFileItemPtr entry(new CFileItem(epgNext)); + entry->SetLabel2(epgNext->StartAsLocalTime().GetAsLocalizedTime("", false)); entry->SetPath(channel->Path()); entry->SetArt("thumb", channel->IconPath()); results.Add(entry); diff --git a/xbmc/pvr/dialogs/GUIDialogPVRChannelsOSD.cpp b/xbmc/pvr/dialogs/GUIDialogPVRChannelsOSD.cpp index 5fb5c7917e..0d66c4b041 100644 --- a/xbmc/pvr/dialogs/GUIDialogPVRChannelsOSD.cpp +++ b/xbmc/pvr/dialogs/GUIDialogPVRChannelsOSD.cpp @@ -286,8 +286,8 @@ void CGUIDialogPVRChannelsOSD::ShowInfo(int item) return; /* Get the current running show on this channel from the EPG storage */ - CEpgInfoTag epgnow; - if (!channel->GetEPGNow(epgnow)) + CEpgInfoTagPtr epgnow(channel->GetEPGNow()); + if (!epgnow) return; /* Load programme info dialog */ diff --git a/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.cpp b/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.cpp index 79ee8da924..bce27265a4 100644 --- a/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.cpp +++ b/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.cpp @@ -51,7 +51,7 @@ CGUIDialogPVRGuideInfo::~CGUIDialogPVRGuideInfo(void) { } -bool CGUIDialogPVRGuideInfo::ActionStartTimer(const CEpgInfoTag *tag) +bool CGUIDialogPVRGuideInfo::ActionStartTimer(const CEpgInfoTagPtr &tag) { bool bReturn = false; @@ -142,7 +142,7 @@ bool CGUIDialogPVRGuideInfo::OnClickButtonRecord(CGUIMessage &message) { bReturn = true; - const CEpgInfoTag *tag = m_progItem->GetEPGInfoTag(); + const CEpgInfoTagPtr tag(m_progItem->GetEPGInfoTag()); if (!tag || !tag->HasPVRChannel()) { /* invalid channel */ @@ -171,7 +171,7 @@ bool CGUIDialogPVRGuideInfo::OnClickButtonSwitch(CGUIMessage &message) { Close(); PlayBackRet ret = PLAYBACK_CANCELED; - CEpgInfoTag *epgTag = m_progItem->GetEPGInfoTag(); + CEpgInfoTagPtr epgTag(m_progItem->GetEPGInfoTag()); if (epgTag) { @@ -203,7 +203,7 @@ bool CGUIDialogPVRGuideInfo::OnClickButtonFind(CGUIMessage &message) if (message.GetSenderId() == CONTROL_BTN_FIND) { - const CEpgInfoTag *tag = m_progItem->GetEPGInfoTag(); + const CEpgInfoTagPtr tag(m_progItem->GetEPGInfoTag()); if (tag && tag->HasPVRChannel()) { int windowSearchId = tag->ChannelTag()->IsRadio() ? WINDOW_RADIO_SEARCH : WINDOW_TV_SEARCH; @@ -248,7 +248,7 @@ void CGUIDialogPVRGuideInfo::OnInitWindow() { CGUIDialog::OnInitWindow(); - const CEpgInfoTag *tag = m_progItem->GetEPGInfoTag(); + const CEpgInfoTagPtr tag(m_progItem->GetEPGInfoTag()); if (!tag) { /* no epg event selected */ diff --git a/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.h b/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.h index 243573300b..cf10a8dc2d 100644 --- a/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.h +++ b/xbmc/pvr/dialogs/GUIDialogPVRGuideInfo.h @@ -20,10 +20,12 @@ */ #include "guilib/GUIDialog.h" +#include <boost/shared_ptr.hpp> namespace EPG { class CEpgInfoTag; + typedef boost::shared_ptr<EPG::CEpgInfoTag> CEpgInfoTagPtr; } namespace PVR @@ -44,7 +46,7 @@ namespace PVR protected: virtual void OnInitWindow(); - bool ActionStartTimer(const EPG::CEpgInfoTag *tag); + bool ActionStartTimer(const EPG::CEpgInfoTagPtr &tag); bool ActionCancelTimer(CFileItemPtr timer); bool OnClickButtonOK(CGUIMessage &message); diff --git a/xbmc/pvr/dialogs/GUIDialogPVRGuideOSD.cpp b/xbmc/pvr/dialogs/GUIDialogPVRGuideOSD.cpp index cf7e5d2d25..8003da7564 100644 --- a/xbmc/pvr/dialogs/GUIDialogPVRGuideOSD.cpp +++ b/xbmc/pvr/dialogs/GUIDialogPVRGuideOSD.cpp @@ -98,7 +98,7 @@ void CGUIDialogPVRGuideOSD::OnInitWindow() for (int iEpgPtr = 0; iEpgPtr < m_vecItems->Size(); iEpgPtr++) { CFileItemPtr entry = m_vecItems->Get(iEpgPtr); - if (entry->GetEPGInfoTag()->IsActive()) + if (entry->HasEPGInfoTag() && entry->GetEPGInfoTag()->IsActive()) { iSelectedItem = iEpgPtr; break; diff --git a/xbmc/pvr/timers/PVRTimerInfoTag.cpp b/xbmc/pvr/timers/PVRTimerInfoTag.cpp index 9cb9f3af54..e97e6bd3f6 100644 --- a/xbmc/pvr/timers/PVRTimerInfoTag.cpp +++ b/xbmc/pvr/timers/PVRTimerInfoTag.cpp @@ -439,10 +439,10 @@ void CPVRTimerInfoTag::DisplayError(PVR_ERROR err) const CGUIDialogOK::ShowAndGetInput(19033,19147,19110,0); /* print info dialog "Unknown error!" */ } -void CPVRTimerInfoTag::SetEpgInfoTag(CEpgInfoTagPtr tag) +void CPVRTimerInfoTag::SetEpgInfoTag(CEpgInfoTagPtr &tag) { CSingleLock lock(m_critSection); - if (tag && m_epgTag != tag) + if (tag && *m_epgTag != *tag) CLog::Log(LOGINFO, "cPVRTimerInfoTag: timer %s set to epg event %s", m_strTitle.c_str(), tag->Title().c_str()); else if (!tag && m_epgTag) CLog::Log(LOGINFO, "cPVRTimerInfoTag: timer %s set to no epg event", m_strTitle.c_str()); diff --git a/xbmc/pvr/timers/PVRTimerInfoTag.h b/xbmc/pvr/timers/PVRTimerInfoTag.h index a2c9e9621e..51c6c5d0b1 100644 --- a/xbmc/pvr/timers/PVRTimerInfoTag.h +++ b/xbmc/pvr/timers/PVRTimerInfoTag.h @@ -157,7 +157,7 @@ namespace PVR bool RenameOnClient(const std::string &strNewName); bool UpdateOnClient(); - void SetEpgInfoTag(EPG::CEpgInfoTagPtr tag); + void SetEpgInfoTag(EPG::CEpgInfoTagPtr &tag); void ClearEpgTag(void); void UpdateChannel(void); diff --git a/xbmc/pvr/timers/PVRTimers.cpp b/xbmc/pvr/timers/PVRTimers.cpp index ddf028818a..4084402c88 100644 --- a/xbmc/pvr/timers/PVRTimers.cpp +++ b/xbmc/pvr/timers/PVRTimers.cpp @@ -469,9 +469,8 @@ bool CPVRTimers::InstantTimer(const CPVRChannel &channel) if (!g_PVRManager.CheckParentalLock(channel)) return false; - CEpgInfoTag epgTag; - bool bHasEpgNow = channel.GetEPGNow(epgTag); - CPVRTimerInfoTag *newTimer = bHasEpgNow ? CPVRTimerInfoTag::CreateFromEpg(epgTag) : NULL; + CEpgInfoTagPtr epgTag(channel.GetEPGNow()); + CPVRTimerInfoTag *newTimer = epgTag ? CPVRTimerInfoTag::CreateFromEpg(*epgTag) : NULL; if (!newTimer) { newTimer = new CPVRTimerInfoTag; @@ -624,8 +623,8 @@ CFileItemPtr CPVRTimers::GetTimerForEpgTag(const CFileItem *item) const { if (item && item->HasEPGInfoTag() && item->GetEPGInfoTag()->ChannelTag()) { - const CEpgInfoTag *epgTag = item->GetEPGInfoTag(); - const CPVRChannelPtr channel = epgTag->ChannelTag(); + const CEpgInfoTagPtr epgTag(item->GetEPGInfoTag()); + const CPVRChannelPtr channel(epgTag->ChannelTag()); CSingleLock lock(m_critSection); for (MapTags::const_iterator it = m_tags.begin(); it != m_tags.end(); ++it) diff --git a/xbmc/pvr/windows/GUIWindowPVRBase.cpp b/xbmc/pvr/windows/GUIWindowPVRBase.cpp index 2519e8b1f4..95d8603daa 100644 --- a/xbmc/pvr/windows/GUIWindowPVRBase.cpp +++ b/xbmc/pvr/windows/GUIWindowPVRBase.cpp @@ -330,8 +330,7 @@ bool CGUIWindowPVRBase::StartRecordFile(const CFileItem &item) if (!item.HasEPGInfoTag()) return false; - // tag has been checked for NULL in HasEPGInfoTag() - const CEpgInfoTag *tag = item.GetEPGInfoTag(); + const CEpgInfoTagPtr tag = item.GetEPGInfoTag(); CPVRChannelPtr channel = tag->ChannelTag(); if (!channel || !g_PVRManager.CheckParentalLock(*channel)) @@ -372,7 +371,7 @@ bool CGUIWindowPVRBase::StopRecordFile(const CFileItem &item) if (!item.HasEPGInfoTag()) return false; - const CEpgInfoTag *tag = item.GetEPGInfoTag(); + const CEpgInfoTagPtr tag(item.GetEPGInfoTag()); if (!tag || !tag->HasPVRChannel()) return false; @@ -472,10 +471,10 @@ void CGUIWindowPVRBase::ShowEPGInfo(CFileItem *item) } else if (item->IsPVRChannel()) { - CEpgInfoTag epgnow; + CEpgInfoTagPtr epgnow(item->GetPVRChannelInfoTag()->GetEPGNow()); channel = *item->GetPVRChannelInfoTag(); bHasChannel = true; - if (!item->GetPVRChannelInfoTag()->GetEPGNow(epgnow)) + if (!epgnow) { CGUIDialogOK::ShowAndGetInput(19033,0,19055,0); return; @@ -513,7 +512,10 @@ bool CGUIWindowPVRBase::ActionInputChannelNumber(int input) m_viewControl.GetCurrentControl() == GUIDE_VIEW_TIMELINE) { CGUIEPGGridContainer* epgGridContainer = (CGUIEPGGridContainer*) GetControl(m_viewControl.GetCurrentControl()); - epgGridContainer->SetChannel((*(*it)->GetEPGInfoTag()->ChannelTag())); + if ((*it)->HasEPGInfoTag() && (*it)->GetEPGInfoTag()->HasPVRChannel()) + epgGridContainer->SetChannel(*(*it)->GetEPGInfoTag()->ChannelTag()); + else + epgGridContainer->SetChannel(*(*it)->GetPVRChannelInfoTag()); } else m_viewControl.SetSelectedItem(itemIndex); @@ -552,8 +554,8 @@ bool CGUIWindowPVRBase::ActionPlayEpg(CFileItem *item) return false; CPVRChannelPtr channel; - CEpgInfoTag *epgTag = item->GetEPGInfoTag(); - if (epgTag->HasPVRChannel()) + CEpgInfoTagPtr epgTag(item->GetEPGInfoTag()); + if (epgTag && epgTag->HasPVRChannel()) channel = epgTag->ChannelTag(); if (!channel || !g_PVRManager.CheckParentalLock(*channel)) @@ -609,7 +611,7 @@ bool CGUIWindowPVRBase::ActionRecord(CFileItem *item) { bool bReturn = false; - CEpgInfoTag *epgTag = item->GetEPGInfoTag(); + CEpgInfoTagPtr epgTag(item->GetEPGInfoTag()); if (!epgTag) return bReturn; diff --git a/xbmc/pvr/windows/GUIWindowPVRGuide.cpp b/xbmc/pvr/windows/GUIWindowPVRGuide.cpp index b854f86387..b2ec1f6c68 100644 --- a/xbmc/pvr/windows/GUIWindowPVRGuide.cpp +++ b/xbmc/pvr/windows/GUIWindowPVRGuide.cpp @@ -78,7 +78,7 @@ void CGUIWindowPVRGuide::GetContextButtons(int itemNumber, CContextButtons &butt else buttons.Add(CONTEXT_BUTTON_STOP_RECORD, 19060); /* delete timer */ } - else if (pItem->GetEPGInfoTag()->EndAsLocalTime() > CDateTime::GetCurrentDateTime()) + else if (pItem->HasEPGInfoTag() && pItem->GetEPGInfoTag()->EndAsLocalTime() > CDateTime::GetCurrentDateTime()) { if (pItem->GetEPGInfoTag()->StartAsLocalTime() < CDateTime::GetCurrentDateTime()) buttons.Add(CONTEXT_BUTTON_START_RECORD, 264); /* record */ @@ -96,7 +96,8 @@ void CGUIWindowPVRGuide::GetContextButtons(int itemNumber, CContextButtons &butt buttons.Add(CONTEXT_BUTTON_END, 19064); /* go to end */ } - if (pItem->GetEPGInfoTag()->HasPVRChannel() && + if (pItem->HasEPGInfoTag() && + pItem->GetEPGInfoTag()->HasPVRChannel() && g_PVRClients->HasMenuHooks(pItem->GetEPGInfoTag()->ChannelTag()->ClientID(), PVR_MENUHOOK_EPG)) buttons.Add(CONTEXT_BUTTON_MENU_HOOKS, 19195); /* PVR client specific action */ diff --git a/xbmc/pvr/windows/GUIWindowPVRSearch.cpp b/xbmc/pvr/windows/GUIWindowPVRSearch.cpp index 3a5b82e7f8..bfbbaf134e 100644 --- a/xbmc/pvr/windows/GUIWindowPVRSearch.cpp +++ b/xbmc/pvr/windows/GUIWindowPVRSearch.cpp @@ -106,13 +106,16 @@ bool CGUIWindowPVRSearch::OnContextButton(const CFileItem &item, CONTEXT_BUTTON case CONTEXT_BUTTON_FIND: { m_searchfilter.Reset(); - CEpgInfoTag tag; // construct the search term if (item.IsEPG()) m_searchfilter.m_strSearchTerm = "\"" + item.GetEPGInfoTag()->Title() + "\""; - else if (item.IsPVRChannel() && item.GetPVRChannelInfoTag()->GetEPGNow(tag)) - m_searchfilter.m_strSearchTerm = "\"" + tag.Title() + "\""; + else if (item.IsPVRChannel()) + { + CEpgInfoTagPtr tag(item.GetPVRChannelInfoTag()->GetEPGNow()); + if (tag) + m_searchfilter.m_strSearchTerm = "\"" + tag->Title() + "\""; + } else if (item.IsPVRRecording()) m_searchfilter.m_strSearchTerm = "\"" + item.GetPVRRecordingInfoTag()->m_strTitle + "\""; else if (item.IsPVRTimer()) |