bool CPVRChannelGroup::AddToGroup(CPVRChannel &channel, int iChannelNumber /* = 0 */) { CSingleLock lock(m_critSection); bool bReturn(false); if (!CPVRChannelGroup::IsGroupMember(channel)) { if (iChannelNumber <= 0 || iChannelNumber > (int) m_members.size() + 1) iChannelNumber = m_members.size() + 1; CPVRChannelPtr realChannel = (IsInternalGroup()) ? GetByClient(channel.UniqueID(), channel.ClientID()) : g_PVRChannelGroups->GetGroupAll(m_bRadio)->GetByClient(channel.UniqueID(), channel.ClientID()); if (realChannel) { PVRChannelGroupMember newMember = { realChannel, (unsigned int)iChannelNumber }; m_members.push_back(newMember); m_bChanged = true; SortAndRenumber(); // TODO notify observers bReturn = true; } } return bReturn; }
bool CPVRDatabase::Persist(CPVRChannel &channel, bool bQueueWrite /* = false */) { bool bReturn(false); /* invalid channel */ if (channel.UniqueID() <= 0) { CLog::Log(LOGERROR, "PVR - %s - invalid channel uid: %d", __FUNCTION__, channel.UniqueID()); return bReturn; } CStdString strQuery; if (channel.ChannelID() <= 0) { /* new channel */ strQuery = PrepareSQL("INSERT INTO channels (" "iUniqueId, bIsRadio, bIsHidden, bIsUserSetIcon, bIsLocked, " "sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, " "iClientChannelNumber, sInputFormat, sStreamURL, iEncryptionSystem, idEpg) " "VALUES (%i, %i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i, '%s', '%s', %i, %i)", channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), (channel.IsUserSetIcon() ? 1 : 0), (channel.IsLocked() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), (channel.IsVirtual() ? 1 : 0), (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.LastWatched(), channel.ClientID(), channel.ClientChannelNumber(), channel.InputFormat().c_str(), channel.StreamURL().c_str(), channel.EncryptionSystem(), channel.EpgID()); } else { /* update channel */ strQuery = PrepareSQL("REPLACE INTO channels (" "iUniqueId, bIsRadio, bIsHidden, bIsUserSetIcon, bIsLocked, " "sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, " "iClientChannelNumber, sInputFormat, sStreamURL, iEncryptionSystem, idChannel, idEpg) " "VALUES (%i, %i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i, '%s', '%s', %i, %i, %i)", channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), (channel.IsUserSetIcon() ? 1 : 0), (channel.IsLocked() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), (channel.IsVirtual() ? 1 : 0), (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.LastWatched(), channel.ClientID(), channel.ClientChannelNumber(), channel.InputFormat().c_str(), channel.StreamURL().c_str(), channel.EncryptionSystem(), channel.ChannelID(), channel.EpgID()); } if (bQueueWrite) { QueueInsertQuery(strQuery); bReturn = true; } else if (ExecuteQuery(strQuery)) { CSingleLock lock(channel.m_critSection); if (channel.m_iChannelId <= 0) channel.m_iChannelId = (int)m_pDS->lastinsertid(); bReturn = true; } return bReturn; }
int CPVRDatabase::Persist(const CPVRChannel &channel, bool bQueueWrite /* = false */) { int iReturn = -1; /* invalid channel */ if (channel.UniqueID() <= 0) { CLog::Log(LOGERROR, "PVRDB - %s - invalid channel uid: %d", __FUNCTION__, channel.UniqueID()); return iReturn; } CStdString strQuery; if (channel.ChannelID() <= 0) { /* new channel */ strQuery = FormatSQL("INSERT INTO channels (" "iUniqueId, bIsRadio, bIsHidden, " "sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, " "iClientChannelNumber, sInputFormat, sStreamURL, iEncryptionSystem, idEpg) " "VALUES (%i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i, '%s', '%s', %i, %i);", channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), (channel.IsVirtual() ? 1 : 0), (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.LastWatched(), channel.ClientID(), channel.ClientChannelNumber(), channel.InputFormat().c_str(), channel.StreamURL().c_str(), channel.EncryptionSystem(), channel.EpgID()); } else { /* update channel */ strQuery = FormatSQL("REPLACE INTO channels (" "iUniqueId, bIsRadio, bIsHidden, " "sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, " "iClientChannelNumber, sInputFormat, sStreamURL, iEncryptionSystem, idChannel, idEpg) " "VALUES (%i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i, '%s', '%s', %i, %i, %i);", channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), (channel.IsVirtual() ? 1 : 0), (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.LastWatched(), channel.ClientID(), channel.ClientChannelNumber(), channel.InputFormat().c_str(), channel.StreamURL().c_str(), channel.EncryptionSystem(), channel.ChannelID(), channel.EpgID()); } if (bQueueWrite) { QueueInsertQuery(strQuery); iReturn = 0; } else if (ExecuteQuery(strQuery)) { iReturn = (channel.ChannelID() <= 0) ? (int) m_pDS->lastinsertid() : channel.ChannelID(); } return iReturn; }
bool CPVRDatabase::Persist(CPVRChannel &channel, bool bCommit) { bool bReturn(false); /* invalid channel */ if (channel.UniqueID() <= 0) { CLog::LogF(LOGERROR, "Invalid channel uid: %d", channel.UniqueID()); return bReturn; } CSingleLock lock(m_critSection); // Note: Do not use channel.ChannelID value to check presence of channel in channels table. It might not yet be set correctly. std::string strQuery = PrepareSQL("iUniqueId = %u AND iClientId = %u", channel.UniqueID(), channel.ClientID()); const std::string strValue = GetSingleValue("channels", "idChannel", strQuery); if (strValue.empty()) { /* new channel */ strQuery = PrepareSQL("INSERT INTO channels (" "iUniqueId, bIsRadio, bIsHidden, bIsUserSetIcon, bIsUserSetName, bIsLocked, " "sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, " "idEpg) " "VALUES (%i, %i, %i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i)", channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), (channel.IsUserSetIcon() ? 1 : 0), (channel.IsUserSetName() ? 1 : 0), (channel.IsLocked() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), 0, (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), static_cast<unsigned int>(channel.LastWatched()), channel.ClientID(), channel.EpgID()); } else { /* update channel */ strQuery = PrepareSQL("REPLACE INTO channels (" "iUniqueId, bIsRadio, bIsHidden, bIsUserSetIcon, bIsUserSetName, bIsLocked, " "sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, " "idChannel, idEpg) " "VALUES (%i, %i, %i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %s, %i)", channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), (channel.IsUserSetIcon() ? 1 : 0), (channel.IsUserSetName() ? 1 : 0), (channel.IsLocked() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), 0, (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), static_cast<unsigned int>(channel.LastWatched()), channel.ClientID(), strValue.c_str(), channel.EpgID()); } if (QueueInsertQuery(strQuery)) { bReturn = true; if (bCommit) bReturn = CommitInsertQueries(); } return bReturn; }
long CPVRDatabase::UpdateChannel(const CPVRChannel &channel, bool bQueueWrite /* = false */) { long iReturn = -1; /* invalid channel */ if (channel.UniqueID() <= 0) { CLog::Log(LOGERROR, "PVRDB - %s - invalid channel uid: %d", __FUNCTION__, channel.UniqueID()); return iReturn; } CStdString strQuery; if (channel.ChannelID() <= 0) { /* new channel */ strQuery = FormatSQL("INSERT INTO Channels (" "UniqueId, ChannelNumber, GroupId, IsRadio, IsHidden, " "IconPath, ChannelName, IsVirtual, EPGEnabled, EPGScraper, ClientId, " "ClientChannelNumber, InputFormat, StreamURL, EncryptionSystem) " "VALUES (%i, %i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %i, %i, '%s', '%s', %i)\n", channel.UniqueID(), channel.ChannelNumber(), channel.GroupID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), (channel.IsVirtual() ? 1 : 0), (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.ClientID(), channel.ClientChannelNumber(), channel.InputFormat().c_str(), channel.StreamURL().c_str(), channel.EncryptionSystem()); } else { /* update channel */ strQuery = FormatSQL("REPLACE INTO Channels (" "UniqueId, ChannelNumber, GroupId, IsRadio, IsHidden, " "IconPath, ChannelName, IsVirtual, EPGEnabled, EPGScraper, ClientId, " "ClientChannelNumber, InputFormat, StreamURL, EncryptionSystem, ChannelId) " "VALUES (%i, %i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %i, %i, '%s', '%s', %i, %i)\n", channel.UniqueID(), channel.ChannelNumber(), channel.GroupID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), (channel.IsVirtual() ? 1 : 0), (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.ClientID(), channel.ClientChannelNumber(), channel.InputFormat().c_str(), channel.StreamURL().c_str(), channel.EncryptionSystem(), channel.ChannelID()); } if (bQueueWrite) { QueueInsertQuery(strQuery); iReturn = 0; } else if (ExecuteQuery(strQuery)) { iReturn = (channel.ChannelID() <= 0) ? (long) m_pDS->lastinsertid() : channel.ChannelID(); } return iReturn; }
bool CPVRDatabase::Persist(CPVRChannel &channel) { bool bReturn(false); /* invalid channel */ if (channel.UniqueID() <= 0) { CLog::Log(LOGERROR, "PVR - %s - invalid channel uid: %d", __FUNCTION__, channel.UniqueID()); return bReturn; } std::string strQuery; if (channel.ChannelID() <= 0) { /* new channel */ strQuery = PrepareSQL("INSERT INTO channels (" "iUniqueId, bIsRadio, bIsHidden, bIsUserSetIcon, bIsUserSetName, bIsLocked, " "sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, " "idEpg) " "VALUES (%i, %i, %i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i)", channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), (channel.IsUserSetIcon() ? 1 : 0), (channel.IsUserSetName() ? 1 : 0), (channel.IsLocked() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), 0, (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.LastWatched(), channel.ClientID(), channel.EpgID()); } else { /* update channel */ strQuery = PrepareSQL("REPLACE INTO channels (" "iUniqueId, bIsRadio, bIsHidden, bIsUserSetIcon, bIsUserSetName, bIsLocked, " "sIconPath, sChannelName, bIsVirtual, bEPGEnabled, sEPGScraper, iLastWatched, iClientId, " "idChannel, idEpg) " "VALUES (%i, %i, %i, %i, %i, %i, '%s', '%s', %i, %i, '%s', %u, %i, %i, %i)", channel.UniqueID(), (channel.IsRadio() ? 1 :0), (channel.IsHidden() ? 1 : 0), (channel.IsUserSetIcon() ? 1 : 0), (channel.IsUserSetName() ? 1 : 0), (channel.IsLocked() ? 1 : 0), channel.IconPath().c_str(), channel.ChannelName().c_str(), 0, (channel.EPGEnabled() ? 1 : 0), channel.EPGScraper().c_str(), channel.LastWatched(), channel.ClientID(), channel.ChannelID(), channel.EpgID()); } if (QueueInsertQuery(strQuery)) { /* update the channel ID for new channels */ if (channel.ChannelID() <= 0) channel.SetChannelID((int)m_pDS->lastinsertid()); bReturn = true; } return bReturn; }
bool CPVRChannelGroupInternal::UpdateChannel(const CPVRChannel &channel) { CPVRChannel *updateChannel = (CPVRChannel *) GetByUniqueID(channel.UniqueID()); if (!updateChannel) { updateChannel = new CPVRChannel(channel.IsRadio()); PVRChannelGroupMember newMember = { updateChannel, 0 }; push_back(newMember); updateChannel->SetUniqueID(channel.UniqueID()); } updateChannel->UpdateFromClient(channel); return updateChannel->Persist(!m_bLoaded); }
bool CPVRChannelGroupInternal::UpdateChannel(const CPVRChannel &channel) { CSingleLock lock(m_critSection); CPVRChannelPtr updateChannel = GetByUniqueID(channel.UniqueID()); if (!updateChannel) { updateChannel = CPVRChannelPtr(new CPVRChannel(channel.IsRadio())); PVRChannelGroupMember newMember = { updateChannel, 0 }; m_members.push_back(newMember); updateChannel->SetUniqueID(channel.UniqueID()); } updateChannel->UpdateFromClient(channel); return updateChannel->Persist(!m_bLoaded); }
CPVRTimerInfoTag *CPVRTimerInfoTag::CreateFromEpg(const CEpgInfoTag &tag) { /* create a new timer */ CPVRTimerInfoTag *newTag = new CPVRTimerInfoTag(); if (!newTag) { CLog::Log(LOGERROR, "%s - couldn't create new timer", __FUNCTION__); return NULL; } /* check if a valid channel is set */ CPVRChannel *channel = (CPVRChannel *) tag.ChannelTag(); if (channel == NULL) { CLog::Log(LOGERROR, "%s - no channel set", __FUNCTION__); return NULL; } /* check if the epg end date is in the future */ if (tag.EndAsLocalTime() < CDateTime::GetCurrentDateTime()) { CLog::Log(LOGERROR, "%s - end time is in the past", __FUNCTION__); return NULL; } /* set the timer data */ CDateTime newStart = tag.StartAsUTC(); CDateTime newEnd = tag.EndAsUTC(); newTag->m_iClientIndex = -1; newTag->m_strTitle = tag.Title().IsEmpty() ? channel->ChannelName() : tag.Title(); newTag->m_iChannelNumber = channel->ChannelNumber(); newTag->m_iClientChannelUid = channel->UniqueID(); newTag->m_iClientId = channel->ClientID(); newTag->m_bIsRadio = channel->IsRadio(); newTag->SetStartFromUTC(newStart); newTag->SetEndFromUTC(newEnd); if (tag.Plot().IsEmpty()) { newTag->m_strSummary.Format("%s %s %s %s %s", newTag->StartAsLocalTime().GetAsLocalizedDate(), g_localizeStrings.Get(19159), newTag->StartAsLocalTime().GetAsLocalizedTime("", false), g_localizeStrings.Get(19160), newTag->EndAsLocalTime().GetAsLocalizedTime("", false)); } else { newTag->m_strSummary = tag.Plot(); } /* we might have a copy of the tag here, so get the real one from the pvrmanager */ const CEpg *epgTable = channel->GetEPG(); newTag->m_epgInfo = epgTable ? epgTable->GetTag(tag.UniqueBroadcastID(), tag.StartAsUTC()) : NULL; /* unused only for reference */ newTag->m_strFileNameAndPath = "pvr://timers/new"; return newTag; }
void CPVRChannelGroup::RemoveInvalidChannels(void) { for (unsigned int ptr = 0; ptr < size(); ptr--) { CPVRChannel *channel = at(ptr).channel; if (channel->IsVirtual()) continue; if (at(ptr).channel->ClientChannelNumber() <= 0) { CLog::Log(LOGERROR, "PVRChannelGroup - %s - removing invalid channel '%s' from client '%i': no valid client channel number", __FUNCTION__, channel->ChannelName().c_str(), channel->ClientID()); erase(begin() + ptr); ptr--; m_bChanged = true; continue; } if (channel->UniqueID() <= 0) { CLog::Log(LOGERROR, "PVRChannelGroup - %s - removing invalid channel '%s' from client '%i': no valid unique ID", __FUNCTION__, channel->ChannelName().c_str(), channel->ClientID()); erase(begin() + ptr); ptr--; m_bChanged = true; continue; } } }
bool CPVRClient::SwitchChannel(const CPVRChannel &channel) { bool bSwitched(false); if (IsPlayingLiveStream() && CanPlayChannel(channel)) { PVR_CHANNEL tag; WriteClientChannelInfo(channel, tag); try { bSwitched = m_pStruct->SwitchChannel(tag); if (bSwitched) { m_bCanPauseStream = m_pStruct->CanPauseStream(); m_bCanSeekStream = m_pStruct->CanSeekStream(); } } catch (exception &e) { LogException(e, __FUNCTION__); } } if (bSwitched) { CPVRChannelPtr currentChannel = g_PVRChannelGroups->GetByUniqueID(channel.UniqueID(), channel.ClientID()); CSingleLock lock(m_critSection); ResetQualityData(m_qualityInfo); m_playingChannel = currentChannel; } return bSwitched; }
bool CPVRChannelGroup::RemoveDeletedChannels(const CPVRChannelGroup &channels) { bool bReturn(false); CSingleLock lock(m_critSection); /* check for deleted channels */ for (int iChannelPtr = size() - 1; iChannelPtr >= 0; iChannelPtr--) { CPVRChannel *channel = at(iChannelPtr).channel; if (!channel) continue; if (channels.GetByClient(channel->UniqueID(), channel->ClientID()) == NULL) { /* channel was not found */ CLog::Log(LOGINFO,"PVRChannelGroup - %s - deleted %s channel '%s' from group '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str(), GroupName().c_str()); /* remove this channel from all non-system groups if this is the internal group */ if (IsInternalGroup()) { g_PVRChannelGroups->Get(m_bRadio)->RemoveFromAllGroups(channel); /* since it was not found in the internal group, it was deleted from the backend */ channel->Delete(); } erase(begin() + iChannelPtr); m_bChanged = true; bReturn = true; } } return bReturn; }
CPVRChannel *CPVRChannels::GetByUniqueID(int iUniqueID) { for (unsigned int ptr = 0; ptr < size(); ptr++) { CPVRChannel *channel = at(ptr); if (channel->UniqueID() == iUniqueID) return channel; } return NULL; }
bool CPVRChannelGroupInternal::UpdateFromClient(const CPVRChannel &channel) { CSingleLock lock(m_critSection); CPVRChannel *realChannel = (CPVRChannel *) GetByClient(channel.UniqueID(), channel.ClientID()); if (realChannel != NULL) realChannel->UpdateFromClient(channel); else realChannel = new CPVRChannel(channel); return CPVRChannelGroup::AddToGroup(realChannel, 0, false); }
bool CPVRClient::OpenStream(const CPVRChannel &channel, bool bIsSwitchingChannel) { bool bReturn(false); CloseStream(); if(!CanPlayChannel(channel)) { CLog::Log(LOGDEBUG, "add-on '%s' can not play channel '%s'", GetFriendlyName().c_str(), channel.ChannelName().c_str()); } else if (!channel.StreamURL().IsEmpty()) { CLog::Log(LOGDEBUG, "opening live stream on url '%s'", channel.StreamURL().c_str()); bReturn = true; // the Njoy N7 sometimes doesn't switch channels, but opens a stream to the previous channel // when not waiting for a short period. // added in 1.1.0 AddonVersion checkVersion("1.1.0"); if (m_apiVersion >= checkVersion) { unsigned int iWaitTimeMs = m_pStruct->GetChannelSwitchDelay(); if (iWaitTimeMs > 0) XbmcThreads::ThreadSleep(iWaitTimeMs); } } else { CLog::Log(LOGDEBUG, "opening live stream for channel '%s'", channel.ChannelName().c_str()); PVR_CHANNEL tag; WriteClientChannelInfo(channel, tag); try { bReturn = m_pStruct->OpenLiveStream(tag); if (bReturn) { m_bCanPauseStream = m_pStruct->CanPauseStream(); m_bCanSeekStream = m_pStruct->CanSeekStream(); } } catch (exception &e) { LogException(e, __FUNCTION__); } } if (bReturn) { CPVRChannelPtr currentChannel = g_PVRChannelGroups->GetByUniqueID(channel.UniqueID(), channel.ClientID()); CSingleLock lock(m_critSection); m_playingChannel = currentChannel; m_bIsPlayingTV = true; m_bIsPlayingRecording = false; } return bReturn; }
/*! * @brief Copy over channel info from xbmcChannel to addonClient. * @param xbmcChannel The channel on XBMC's side. * @param addonChannel The channel on the addon's side. */ inline void PVRWriteClientChannelInfo(const CPVRChannel &xbmcChannel, PVR_CHANNEL &addonChannel) { addonChannel.iUniqueId = xbmcChannel.UniqueID(); addonChannel.iChannelNumber = xbmcChannel.ClientChannelNumber(); addonChannel.strChannelName = xbmcChannel.ClientChannelName().c_str(); addonChannel.strIconPath = xbmcChannel.IconPath().c_str(); addonChannel.iEncryptionSystem = xbmcChannel.EncryptionSystem(); addonChannel.bIsRadio = xbmcChannel.IsRadio(); addonChannel.bIsHidden = xbmcChannel.IsHidden(); addonChannel.strInputFormat = xbmcChannel.InputFormat().c_str(); addonChannel.strStreamURL = xbmcChannel.StreamURL().c_str(); }
/*! * @brief Copy over channel info from xbmcChannel to addonClient. * @param xbmcChannel The channel on XBMC's side. * @param addonChannel The channel on the addon's side. */ void CPVRClient::WriteClientChannelInfo(const CPVRChannel &xbmcChannel, PVR_CHANNEL &addonChannel) { memset(&addonChannel, 0, sizeof(addonChannel)); addonChannel.iUniqueId = xbmcChannel.UniqueID(); addonChannel.iChannelNumber = xbmcChannel.ClientChannelNumber(); strncpy(addonChannel.strChannelName, xbmcChannel.ClientChannelName().c_str(), sizeof(addonChannel.strChannelName) - 1); strncpy(addonChannel.strIconPath, xbmcChannel.IconPath().c_str(), sizeof(addonChannel.strIconPath) - 1); addonChannel.iEncryptionSystem = xbmcChannel.EncryptionSystem(); addonChannel.bIsRadio = xbmcChannel.IsRadio(); addonChannel.bIsHidden = xbmcChannel.IsHidden(); strncpy(addonChannel.strInputFormat, xbmcChannel.InputFormat().c_str(), sizeof(addonChannel.strInputFormat) - 1); strncpy(addonChannel.strStreamURL, xbmcChannel.StreamURL().c_str(), sizeof(addonChannel.strStreamURL) - 1); }
void CPVRChannelGroupInternal::UpdateFromClient(const CPVRChannel &channel, unsigned int iChannelNumber /* = 0 */) { CSingleLock lock(m_critSection); CPVRChannelPtr realChannel = GetByClient(channel.UniqueID(), channel.ClientID()); if (realChannel) realChannel->UpdateFromClient(channel); else { PVRChannelGroupMember newMember = { CPVRChannelPtr(new CPVRChannel(channel)), iChannelNumber > 0l ? iChannelNumber : (int)m_members.size() + 1 }; m_members.push_back(newMember); m_bChanged = true; SortAndRenumber(); } }
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; if (!newTimer) { newTimer = new CPVRTimerInfoTag; /* set the timer data */ newTimer->m_iClientIndex = -1; newTimer->m_strTitle = channel.ChannelName(); newTimer->m_strSummary = g_localizeStrings.Get(19056); newTimer->m_iChannelNumber = channel.ChannelNumber(); newTimer->m_iClientChannelUid = channel.UniqueID(); newTimer->m_iClientId = channel.ClientID(); newTimer->m_bIsRadio = channel.IsRadio(); /* generate summary string */ newTimer->m_strSummary.Format("%s %s %s %s %s", newTimer->StartAsLocalTime().GetAsLocalizedDate(), g_localizeStrings.Get(19159), newTimer->StartAsLocalTime().GetAsLocalizedTime(StringUtils::EmptyString, false), g_localizeStrings.Get(19160), newTimer->EndAsLocalTime().GetAsLocalizedTime(StringUtils::EmptyString, false)); } CDateTime startTime(0); newTimer->SetStartFromUTC(startTime); newTimer->m_iMarginStart = 0; /* set the start margin to 0 for instant timers */ int iDuration = g_guiSettings.GetInt("pvrrecord.instantrecordtime"); CDateTime endTime = CDateTime::GetUTCDateTime() + CDateTimeSpan(0, 0, iDuration ? iDuration : 120, 0); newTimer->SetEndFromUTC(endTime); /* unused only for reference */ newTimer->m_strFileNameAndPath = "pvr://timers/new"; bool bReturn = newTimer->AddToClient(); if (!bReturn) CLog::Log(LOGERROR, "PVRTimers - %s - unable to add an instant timer on the client", __FUNCTION__); delete newTimer; return bReturn; }
bool CPVRTimers::IsRecordingOnChannel(const CPVRChannel &channel) const { CSingleLock lock(m_critSection); for (MapTags::const_iterator it = m_tags.begin(); it != m_tags.end(); ++it) { for (VecTimerInfoTag::const_iterator timerIt = it->second->begin(); timerIt != it->second->end(); ++timerIt) { if ((*timerIt)->IsRecording() && (*timerIt)->m_iClientChannelUid == channel.UniqueID() && (*timerIt)->m_iClientId == channel.ClientID()) return true; } } return false; }
bool CPVRTimers::IsRecordingOnChannel(const CPVRChannel &channel) const { CSingleLock lock(m_critSection); for (map<CDateTime, vector<CPVRTimerInfoTag *>* >::const_iterator it = m_tags.begin(); it != m_tags.end(); it++) { for (unsigned int iTimerPtr = 0; iTimerPtr < it->second->size(); iTimerPtr++) { CPVRTimerInfoTag *timer = it->second->at(iTimerPtr); if (timer->IsRecording() && timer->m_iClientChannelUid == channel.UniqueID() && timer->m_iClientId == channel.ClientID()) return true; } } return false; }
bool CPVRTimers::IsRecordingOnChannel(const CPVRChannel &channel) const { bool bReturn(false); CSingleLock lock(m_critSection); for (unsigned int ptr = 0; ptr < size(); ptr++) { CPVRTimerInfoTag *timer = at(ptr); if (timer->IsRecording() && timer->m_iClientChannelUid == channel.UniqueID() && timer->m_iClientId == channel.ClientID()) { bReturn = true; break; } } return bReturn; }
void CPVRChannelGroup::RemoveInvalidChannels(void) { bool bDelete(false); CSingleLock lock(m_critSection); for (unsigned int ptr = 0; ptr < m_members.size(); ptr--) { bDelete = false; CPVRChannel *channel = m_members.at(ptr).channel; if (channel->IsVirtual()) continue; if (m_members.at(ptr).channel->ClientChannelNumber() <= 0) { CLog::Log(LOGERROR, "PVRChannelGroup - %s - removing invalid channel '%s' from client '%i': no valid client channel number", __FUNCTION__, channel->ChannelName().c_str(), channel->ClientID()); bDelete = true; } if (!bDelete && channel->UniqueID() <= 0) { CLog::Log(LOGERROR, "PVRChannelGroup - %s - removing invalid channel '%s' from client '%i': no valid unique ID", __FUNCTION__, channel->ChannelName().c_str(), channel->ClientID()); bDelete = true; } /* remove this channel from all non-system groups if this is the internal group */ if (bDelete) { if (IsInternalGroup()) { g_PVRChannelGroups->Get(m_bRadio)->RemoveFromAllGroups(channel); channel->Delete(); } else { m_members.erase(m_members.begin() + ptr); } m_bChanged = true; } } }
void CPVRChannels::SearchAndSetChannelIcons(bool bUpdateDb /* = false */) { if (g_guiSettings.GetString("pvrmenu.iconpath") == "") return; CPVRDatabase *database = g_PVRManager.GetTVDatabase(); database->Open(); for (unsigned int ptr = 0; ptr < size(); ptr++) { CPVRChannel *channel = at(ptr); /* skip if an icon is already set */ if (channel->IconPath() != "") continue; CStdString strBasePath = g_guiSettings.GetString("pvrmenu.iconpath"); CStdString strIconPath = strBasePath + channel->ClientChannelName(); CStdString strIconPathLower = strBasePath + channel->ClientChannelName().ToLower(); CStdString strIconPathUid; strIconPathUid.Format("%s/%08d", strBasePath, channel->UniqueID()); channel->SetIconPath(strIconPath + ".tbn", bUpdateDb) || channel->SetIconPath(strIconPath + ".jpg", bUpdateDb) || channel->SetIconPath(strIconPath + ".png", bUpdateDb) || channel->SetIconPath(strIconPathLower + ".tbn", bUpdateDb) || channel->SetIconPath(strIconPathLower + ".jpg", bUpdateDb) || channel->SetIconPath(strIconPathLower + ".png", bUpdateDb) || channel->SetIconPath(strIconPathUid + ".tbn", bUpdateDb) || channel->SetIconPath(strIconPathUid + ".jpg", bUpdateDb) || channel->SetIconPath(strIconPathUid + ".png", bUpdateDb); /* TODO: start channel icon scraper here if nothing was found */ } database->Close(); }
bool CPVRChannelGroup::AddToGroup(CPVRChannel &channel, int iChannelNumber /* = 0 */, bool bSortAndRenumber /* = true */) { CSingleLock lock(m_critSection); bool bReturn(false); if (!CPVRChannelGroup::IsGroupMember(channel)) { if (iChannelNumber <= 0 || iChannelNumber > (int) size() + 1) iChannelNumber = size() + 1; CPVRChannel *realChannel = (IsInternalGroup()) ? &channel : (CPVRChannel *) g_PVRChannelGroups->GetGroupAll(m_bRadio)->GetByClient(channel.UniqueID(), channel.ClientID()); if (realChannel) { PVRChannelGroupMember newMember = { realChannel, iChannelNumber }; push_back(newMember); m_bChanged = true; if (bSortAndRenumber) { if (m_bUsingBackendChannelOrder) SortByClientChannelNumber(); else SortByChannelNumber(); Renumber(); } // TODO notify observers bReturn = true; } } return bReturn; }
bool CPVRChannels::Update(CPVRChannels *channels) { /* the database has already been opened */ CPVRDatabase *database = g_PVRManager.GetTVDatabase(); int iSize = size(); for (int ptr = 0; ptr < iSize; ptr++) { CPVRChannel *channel = at(ptr); /* ignore virtual channels */ if (channel->IsVirtual()) continue; /* check if this channel is still present */ CPVRChannel *existingChannel = channels->GetByUniqueID(channel->UniqueID()); if (existingChannel) { /* if it's present, update the current tag */ if (channel->UpdateFromClient(*existingChannel)) { channel->Persist(true); CLog::Log(LOGINFO,"%s - updated %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); } /* remove this tag from the temporary channel list */ channels->RemoveByUniqueID(channel->UniqueID()); } else { /* channel is no longer present */ CLog::Log(LOGINFO,"%s - removing %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); database->RemoveChannel(*channel); erase(begin() + ptr); ptr--; iSize--; } } /* the temporary channel list only contains new channels now */ for (unsigned int ptr = 0; ptr < channels->size(); ptr++) { CPVRChannel *channel = channels->at(ptr); channel->Persist(true); push_back(channel); CLog::Log(LOGINFO,"%s - added %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); } /* post the queries generated by the update */ database->CommitInsertQueries(); /* recount hidden channels */ m_iHiddenChannels = 0; for (unsigned int i = 0; i < size(); i++) { if (at(i)->IsHidden()) m_iHiddenChannels++; } m_bIsSorted = false; return true; }
bool CPVRChannelGroup::UpdateGroupEntries(const CPVRChannelGroup &channels) { bool bChanged(false); CSingleLock lock(m_critSection); int iCurSize = size(); CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase(); if (!database || !database->Open()) return false; /* go through the channel list and check for updated or new channels */ for (unsigned int iChannelPtr = 0; iChannelPtr < channels.size(); iChannelPtr++) { CPVRChannel *channel = channels.at(iChannelPtr).channel; int iChannelNumber = channels.at(iChannelPtr).iChannelNumber; if (!channel) continue; CPVRChannel *realChannel = (CPVRChannel *) CPVRManager::GetChannelGroups()->GetGroupAll(m_bRadio)->GetByClient(channel->UniqueID(), channel->ClientID()); if (!realChannel) continue; if (!IsGroupMember(realChannel)) { AddToGroup(realChannel, iChannelNumber, false); bChanged = true; m_bChanged = true; CLog::Log(LOGINFO,"PVRChannelGroup - %s - added %s channel '%s' at position %d in group '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", realChannel->ChannelName().c_str(), iChannelNumber, GroupName().c_str()); } } /* check for deleted channels */ unsigned int iSize = size(); for (unsigned int iChannelPtr = 0; iChannelPtr < iSize; iChannelPtr++) { CPVRChannel *channel = (CPVRChannel *) GetByIndex(iChannelPtr); if (!channel) continue; if (channels.GetByClient(channel->UniqueID(), channel->ClientID()) == NULL) { /* channel was not found */ CLog::Log(LOGINFO,"PVRChannelGroup - %s - deleted %s channel '%s' from group '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str(), GroupName().c_str()); /* remove this channel from all non-system groups */ RemoveFromGroup(channel); m_bChanged = true; bChanged = true; iChannelPtr--; iSize--; } } if (bChanged) { /* sort by client channel number if this is the first time */ if (iCurSize == 0) SortByClientChannelNumber(); /* renumber to make sure all channels have a channel number. new channels were added at the back, so they'll get the highest numbers */ Renumber(); return Persist(); } return true; }
bool CPVRChannelGroupInternal::UpdateGroupEntries(CPVRChannelGroup *channels) { CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase(); if(!database && !database->Open()) return false; int iSize = size(); for (int ptr = 0; ptr < iSize; ptr++) { CPVRChannel *channel = at(ptr).channel; /* ignore virtual channels */ if (channel->IsVirtual()) continue; /* check if this channel is still present */ const CPVRChannel *existingChannel = channels->GetByUniqueID(channel->UniqueID()); if (existingChannel) { /* if it's present, update the current tag */ if (channel->UpdateFromClient(*existingChannel)) { channel->Persist(true); CLog::Log(LOGINFO,"PVRChannelGroupInternal - %s - updated %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); } /* remove this tag from the temporary channel list */ channels->RemoveByUniqueID(channel->UniqueID()); } else { /* channel is no longer present */ CLog::Log(LOGINFO,"PVRChannelGroupInternal - %s - removing %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); channel->Delete(); erase(begin() + ptr); ptr--; iSize--; } } /* the temporary channel list only contains new channels now */ for (unsigned int ptr = 0; ptr < channels->size(); ptr++) { CPVRChannel *channel = channels->at(ptr).channel; channel->Persist(true); PVRChannelGroupMember member = { channel, size() }; push_back(member); CLog::Log(LOGINFO,"PVRChannelGroupInternal - %s - added %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); } /* post the queries generated by the update */ database->CommitInsertQueries(); database->Close(); Renumber(); return true; }
bool CPVRChannelGroupInternal::UpdateGroupEntries(const CPVRChannelGroup &channels) { bool bChanged = false; int iCurSize = size(); CPVRChannelGroup *newChannels = new CPVRChannelGroup(m_bRadio); CPVRDatabase *database = g_PVRManager.GetTVDatabase(); if (!database || !database->Open()) return bChanged; /* go through the channel list and check for updated or new channels */ for (unsigned int iChannelPtr = 0; iChannelPtr < channels.size(); iChannelPtr++) { const CPVRChannel *channel = channels.at(iChannelPtr).channel; /* check if this channel is present in this container */ CPVRChannel *existingChannel = (CPVRChannel *) GetByClient(channel->UniqueID(), channel->ClientID()); if (existingChannel) { /* if it's present, update the current tag */ if (existingChannel->UpdateFromClient(*channel)) { bChanged = true; CLog::Log(LOGINFO,"PVRChannelGroupInternal - %s - updated %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); } } else { /* new channel */ CPVRChannel *newChannel = new CPVRChannel(m_bRadio); newChannel->SetUniqueID(channel->UniqueID(), false); newChannel->UpdateFromClient(*channel); newChannels->AddToGroup(newChannel); int iChannelNumber = iCurSize == 0 ? channel->ClientChannelNumber() : 0; InsertInGroup(newChannel, iChannelNumber, false); bChanged = true; CLog::Log(LOGINFO,"PVRChannelGroupInternal - %s - added %s channel '%s' at position %d", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str(), iChannelNumber); } } /* persist changes */ for (unsigned int iChannelPtr = 0; iChannelPtr < newChannels->size(); iChannelPtr++) ((CPVRChannel *) newChannels->GetByIndex(iChannelPtr))->Persist(false); /* write immediately to get a db id */ delete newChannels; /* check for deleted channels */ unsigned int iSize = size(); for (unsigned int iChannelPtr = 0; iChannelPtr < iSize; iChannelPtr++) { CPVRChannel *channel = (CPVRChannel *) GetByIndex(iChannelPtr); if (!channel) continue; if (channels.GetByClient(channel->UniqueID(), channel->ClientID()) == NULL) { /* channel was not found */ CLog::Log(LOGINFO,"PVRChannelGroupInternal - %s - deleted %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); /* remove this channel from all non-system groups */ ((CPVRChannelGroups *) g_PVRChannelGroups->Get(m_bRadio))->RemoveFromAllGroups(channel); delete at(iChannelPtr).channel; erase(begin() + iChannelPtr); iChannelPtr--; iSize--; bChanged = true; } } database->Close(); /* try to find channel icons */ SearchAndSetChannelIcons(); CacheIcons(); if (bChanged || HasChanges()) { /* remove invalid channels */ RemoveInvalidChannels(); /* sort by client channel number if this is the first time */ if (iCurSize == 0) SortByClientChannelNumber(); /* renumber to make sure all channels have a channel number. new channels were added at the back, so they'll get the highest numbers */ Renumber(); return Persist(); } else { return true; } }