void CPVRClients::SaveCurrentChannelSettings(void) { CPVRChannel channel; { CSingleLock lock(m_critSection); if (!GetPlayingChannel(channel) || !m_bIsValidChannelSettings) return; } CPVRDatabase *database = GetPVRDatabase(); if (!database) return; if (g_settings.m_currentVideoSettings != g_settings.m_defaultVideoSettings) { CLog::Log(LOGDEBUG, "PVR - %s - persisting custom channel settings for channel '%s'", __FUNCTION__, channel.ChannelName().c_str()); database->PersistChannelSettings(channel, g_settings.m_currentVideoSettings); } else { CLog::Log(LOGDEBUG, "PVR - %s - no custom channel settings for channel '%s'", __FUNCTION__, channel.ChannelName().c_str()); database->DeleteChannelSettings(channel); } }
bool CGUIWindowPVRChannels::OnContextButtonUpdateEpg(CFileItem *item, CONTEXT_BUTTON button) { bool bReturn = false; if (button == CONTEXT_BUTTON_UPDATE_EPG) { CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO); if (!pDialog) return bReturn; CPVRChannel *channel = item->GetPVRChannelInfoTag(); pDialog->SetHeading(19251); pDialog->SetLine(0, g_localizeStrings.Get(19252)); pDialog->SetLine(1, channel->ChannelName()); pDialog->SetLine(2, ""); pDialog->DoModal(); if (!pDialog->IsConfirmed()) return bReturn; bReturn = UpdateEpgForChannel(item); CStdString strMessage; strMessage.Format("%s: '%s'", g_localizeStrings.Get(bReturn ? 19253 : 19254), channel->ChannelName()); CGUIDialogKaiToast::QueueNotification(bReturn ? CGUIDialogKaiToast::Info : CGUIDialogKaiToast::Error, g_localizeStrings.Get(19166), strMessage); } return bReturn; }
void CPVRManager::SaveCurrentChannelSettings(void) { CSingleLock lock(m_critSection); CPVRChannel channel; if (!m_addons->GetPlayingChannel(&channel)) return; if (!m_database->Open()) { CLog::Log(LOGERROR, "PVR - %s - could not open the database", __FUNCTION__); return; } if (g_settings.m_currentVideoSettings != g_settings.m_defaultVideoSettings) { CLog::Log(LOGDEBUG, "PVR - %s - persisting custom channel settings for channel '%s'", __FUNCTION__, channel.ChannelName().c_str()); m_database->PersistChannelSettings(channel, g_settings.m_currentVideoSettings); } else { CLog::Log(LOGDEBUG, "PVR - %s - no custom channel settings for channel '%s'", __FUNCTION__, channel.ChannelName().c_str()); m_database->DeleteChannelSettings(channel); } m_database->Close(); }
bool CPVRManager::PerformChannelSwitch(const CPVRChannel &channel, bool bPreview) { bool bSwitched(false); CSingleLock lock(m_critSection); if (m_bIsSwitchingChannels) { CLog::Log(LOGDEBUG, "PVRManager - %s - can't switch to channel '%s'. waiting for the previous switch to complete", __FUNCTION__, channel.ChannelName().c_str()); return bSwitched; } m_bIsSwitchingChannels = true; CLog::Log(LOGDEBUG, "PVRManager - %s - switching to channel '%s'", __FUNCTION__, channel.ChannelName().c_str()); /* make sure that channel settings are persisted */ if (!bPreview) SaveCurrentChannelSettings(); if (m_currentFile) { delete m_currentFile; m_currentFile = NULL; } lock.Leave(); if (!bPreview && (channel.ClientID() < 0 || !m_addons->SwitchChannel(channel))) { lock.Enter(); m_bIsSwitchingChannels = false; lock.Leave(); CLog::Log(LOGERROR, "PVRManager - %s - failed to switch to channel '%s'", __FUNCTION__, channel.ChannelName().c_str()); } else { bSwitched = true; lock.Enter(); m_currentFile = new CFileItem(channel); if (!bPreview) CLog::Log(LOGNOTICE, "PVRManager - %s - switched to channel '%s'", __FUNCTION__, channel.ChannelName().c_str()); m_bIsSwitchingChannels = false; } if (!bSwitched) { CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, g_localizeStrings.Get(19166), g_localizeStrings.Get(19035)); } return bSwitched; }
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 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; }
int CPVREpgContainer::GetEPGNext(CFileItemList* results, bool bRadio) { CPVRChannelGroup *channels = (CPVRChannelGroup *) CPVRManager::GetChannelGroups()->GetGroupAll(bRadio); CSingleLock lock(m_critSection); int iInitialSize = results->Size(); for (unsigned int iChannelPtr = 0; iChannelPtr < channels->Size(); iChannelPtr++) { CPVRChannel *channel = (CPVRChannel *) channels->GetByIndex(iChannelPtr); CPVREpg *epg = channel->GetEPG(); if (!epg->HasValidEntries()) continue; const CPVREpgInfoTag *epgNext = (CPVREpgInfoTag *) epg->InfoTagNext(); if (!epgNext) continue; CFileItemPtr entry(new CFileItem(*epgNext)); entry->SetLabel2(epgNext->Start().GetAsLocalizedTime("", false)); entry->m_strPath = channel->ChannelName(); entry->SetThumbnailImage(channel->IconPath()); results->Add(entry); } return results->Size() - iInitialSize; }
bool CGUIWindowPVRCommon::ActionDeleteChannel(CFileItem *item) { CPVRChannel *channel = item->GetPVRChannelInfoTag(); /* check if the channel tag is valid */ if (!channel || channel->ChannelNumber() <= 0) return false; /* show a confirmation dialog */ CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*) g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO); if (pDialog) return false; pDialog->SetHeading(19039); pDialog->SetLine(0, ""); pDialog->SetLine(1, channel->ChannelName()); pDialog->SetLine(2, ""); pDialog->DoModal(); /* prompt for the user's confirmation */ if (!pDialog->IsConfirmed()) return false; g_PVRChannelGroups->GetGroupAll(channel->IsRadio())->RemoveFromGroup(*channel); UpdateData(); return true; }
bool CPVRDatabase::GetChannelSettings(const CPVRChannel &channel, CVideoSettings &settings) { bool bReturn = false; /* invalid channel */ if (channel.ChannelID() <= 0) { CLog::Log(LOGERROR, "PVRDB - %s - invalid channel id: %i", __FUNCTION__, channel.ChannelID()); return bReturn; } CStdString strQuery = FormatSQL("SELECT * FROM channelsettings WHERE idChannel = %u;", channel.ChannelID()); if (ResultQuery(strQuery)) { try { if (m_pDS->num_rows() > 0) { settings.m_AudioDelay = m_pDS->fv("fAudioDelay").get_asFloat(); settings.m_AudioStream = m_pDS->fv("iAudioStream").get_asInt(); settings.m_Brightness = m_pDS->fv("fBrightness").get_asFloat(); settings.m_Contrast = m_pDS->fv("fContrast").get_asFloat(); settings.m_CustomPixelRatio = m_pDS->fv("fPixelRatio").get_asFloat(); settings.m_CustomNonLinStretch = m_pDS->fv("bCustomNonLinStretch").get_asBool(); settings.m_NoiseReduction = m_pDS->fv("fNoiseReduction").get_asFloat(); settings.m_PostProcess = m_pDS->fv("bPostProcess").get_asBool(); settings.m_Sharpness = m_pDS->fv("fSharpness").get_asFloat(); settings.m_CustomZoomAmount = m_pDS->fv("fCustomZoomAmount").get_asFloat(); settings.m_CustomVerticalShift = m_pDS->fv("fCustomVerticalShift").get_asFloat(); settings.m_Gamma = m_pDS->fv("fGamma").get_asFloat(); settings.m_SubtitleDelay = m_pDS->fv("fSubtitleDelay").get_asFloat(); settings.m_SubtitleOn = m_pDS->fv("bSubtitles").get_asBool(); settings.m_SubtitleStream = m_pDS->fv("iSubtitleStream").get_asInt(); settings.m_ViewMode = m_pDS->fv("iViewMode").get_asInt(); settings.m_Crop = m_pDS->fv("bCrop").get_asBool(); settings.m_CropLeft = m_pDS->fv("iCropLeft").get_asInt(); settings.m_CropRight = m_pDS->fv("iCropRight").get_asInt(); settings.m_CropTop = m_pDS->fv("iCropTop").get_asInt(); settings.m_CropBottom = m_pDS->fv("iCropBottom").get_asInt(); settings.m_InterlaceMethod = (EINTERLACEMETHOD)m_pDS->fv("iInterlaceMethod").get_asInt(); settings.m_VolumeAmplification = m_pDS->fv("fVolumeAmplification").get_asFloat(); settings.m_OutputToAllSpeakers = m_pDS->fv("bOutputToAllSpeakers").get_asBool(); settings.m_ScalingMethod = (ESCALINGMETHOD)m_pDS->fv("iScalingMethod").get_asInt(); bReturn = true; } m_pDS->close(); } catch(...) { CLog::Log(LOGERROR, "PVRDB - %s - failed to get channel settings for channel '%s'", __FUNCTION__, channel.ChannelName().c_str()); } } return bReturn; }
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; }
bool CPVRChannelGroup::AddAndUpdateChannels(const CPVRChannelGroup &channels, bool bUseBackendChannelNumbers) { bool bReturn(false); CSingleLock lock(m_critSection); /* go through the channel list and check for new channels. channels will only by updated in CPVRChannelGroupInternal to prevent dupe updates */ for (unsigned int iChannelPtr = 0; iChannelPtr < channels.size(); iChannelPtr++) { PVRChannelGroupMember member = channels.at(iChannelPtr); if (!member.channel) continue; /* check whether this channel is known in the internal group */ CPVRChannel *existingChannel = (CPVRChannel *) g_PVRChannelGroups->GetGroupAll(m_bRadio)->GetByClient(member.channel->UniqueID(), member.channel->ClientID()); if (!existingChannel) continue; /* if it's found, add the channel to this group */ if (!IsGroupMember(*existingChannel)) { int iChannelNumber = bUseBackendChannelNumbers ? member.channel->ClientChannelNumber() : 0; AddToGroup(*existingChannel, iChannelNumber, false); bReturn = true; CLog::Log(LOGINFO,"PVRChannelGroup - %s - added %s channel '%s' at position %d in group '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", existingChannel->ChannelName().c_str(), iChannelNumber, GroupName().c_str()); } } return bReturn; }
int CPVRChannelGroup::GetEPGNext(CFileItemList &results) { int iInitialSize = results.Size(); CSingleLock lock(m_critSection); for (unsigned int iChannelPtr = 0; iChannelPtr < size(); iChannelPtr++) { CPVRChannel *channel = at(iChannelPtr).channel; CEpg *epg = channel->GetEPG(); if (!epg || !epg->HasValidEntries() || at(iChannelPtr).channel->IsHidden()) continue; CEpgInfoTag epgNow; if (!epg->InfoTagNext(epgNow)) continue; CFileItemPtr entry(new CFileItem(epgNow)); entry->SetLabel2(epgNow.StartAsLocalTime().GetAsLocalizedTime(StringUtils::EmptyString, false)); entry->SetPath(channel->ChannelName()); entry->SetThumbnailImage(channel->IconPath()); results.Add(entry); } return results.Size() - iInitialSize; }
int CPVREpgs::GetEPGNext(CFileItemList* results, bool bRadio) { CPVRChannels *channels = bRadio ? &PVRChannelsRadio : &PVRChannelsTV; int iInitialSize = results->Size(); for (unsigned int iChannelPtr = 0; iChannelPtr < channels->size(); iChannelPtr++) { CPVRChannel *channel = channels->GetByIndex(iChannelPtr); CPVREpg *epg = channel->GetEPG(); if (!epg->HasValidEntries() || epg->IsUpdateRunning()) continue; const CPVREpgInfoTag *epgNext = epg->InfoTagNext(); if (!epgNext) { continue; } CFileItemPtr entry(new CFileItem(*epgNext)); entry->SetLabel2(epgNext->Start().GetAsLocalizedTime("", false)); entry->m_strPath = channel->ChannelName(); entry->SetThumbnailImage(channel->IconPath()); results->Add(entry); } return results->Size() - iInitialSize; }
bool CGUIWindowPVRChannels::OnContextButtonHide(CFileItem *item, CONTEXT_BUTTON button) { bool bReturn = false; if (button == CONTEXT_BUTTON_HIDE) { CPVRChannel *channel = item->GetPVRChannelInfoTag(); if (!channel || channel->IsRadio() != m_bRadio) return bReturn; CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO); if (!pDialog) return bReturn; pDialog->SetHeading(19039); pDialog->SetLine(0, ""); pDialog->SetLine(1, channel->ChannelName()); pDialog->SetLine(2, ""); pDialog->DoModal(); if (!pDialog->IsConfirmed()) return bReturn; g_PVRManager.GetPlayingGroup(m_bRadio)->RemoveFromGroup(*channel); UpdateData(); bReturn = true; } return bReturn; }
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; }
bool CGUIWindowPVRCommon::PlayFile(CFileItem *item, bool bPlayMinimized /* = false */) { if (item->m_bIsFolder) { return false; } if (item->GetPath() == g_application.CurrentFile()) { CGUIMessage msg(GUI_MSG_FULLSCREEN, 0, m_parent->GetID()); g_windowManager.SendMessage(msg); return true; } CMediaSettings::Get().SetVideoStartWindowed(bPlayMinimized); if (item->HasPVRRecordingInfoTag()) { return PlayRecording(item, bPlayMinimized); } else { bool bSwitchSuccessful(false); CPVRChannel *channel = item->HasPVRChannelInfoTag() ? item->GetPVRChannelInfoTag() : NULL; if (channel && g_PVRManager.CheckParentalLock(*channel)) { /* try a fast switch */ if (channel && (g_PVRManager.IsPlayingTV() || g_PVRManager.IsPlayingRadio()) && (channel->IsRadio() == g_PVRManager.IsPlayingRadio()) && g_application.m_pPlayer) { if (channel->StreamURL().IsEmpty()) bSwitchSuccessful = g_application.m_pPlayer->SwitchChannel(*channel); } if (!bSwitchSuccessful) { CApplicationMessenger::Get().PlayFile(*item, false); return true; } } if (!bSwitchSuccessful) { CStdString msg; CStdString channelName = g_localizeStrings.Get(19029); // Channel if (channel) channelName = channel->ChannelName(); msg.Format(g_localizeStrings.Get(19035).c_str(), channelName.c_str()); // CHANNELNAME could not be played. Check the log for details. CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, g_localizeStrings.Get(19166), // PVR information msg); return false; } } return true; }
void CGUIDialogPVRChannelsOSD::GotoChannel(int item) { /* Check file item is in list range and get his pointer */ if (item < 0 || item >= (int)m_vecItems->Size()) return; CFileItemPtr pItem = m_vecItems->Get(item); if (pItem->GetPath() == g_application.CurrentFile()) { CloseOrSelect(item); return; } if (g_PVRManager.IsPlaying() && pItem->HasPVRChannelInfoTag() && g_application.m_pPlayer->HasPlayer()) { CPVRChannel *channel = pItem->GetPVRChannelInfoTag(); if (!g_PVRManager.CheckParentalLock(*channel) || !g_application.m_pPlayer->SwitchChannel(*channel)) { CStdString msg; msg.Format(g_localizeStrings.Get(19035).c_str(), channel->ChannelName().c_str()); // CHANNELNAME could not be played. Check the log for details. CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, g_localizeStrings.Get(19166), // PVR information msg); return; } } else CApplicationMessenger::Get().PlayFile(*pItem); m_group = GetPlayingGroup(); CloseOrSelect(item); }
CStdString CPVRTimerInfoTag::ChannelName() const { CPVRChannel *channeltag = CPVRChannels::GetByClientFromAll(m_iClientNumber, m_iClientID); if (channeltag) return channeltag->ChannelName(); else return ""; }
bool CPVREpgs::LoadFromDb(bool bShowProgress /* = false */) { if (m_bDatabaseLoaded) return m_bDatabaseLoaded; CPVRDatabase *database = g_PVRManager.GetTVDatabase(); /* show the progress bar */ CGUIDialogPVRUpdateProgressBar *scanner = NULL; if (bShowProgress) { scanner = (CGUIDialogPVRUpdateProgressBar *)g_windowManager.GetWindow(WINDOW_DIALOG_EPG_SCAN); scanner->Show(); scanner->SetHeader(g_localizeStrings.Get(19004)); } /* open the database */ database->Open(); /* load all EPG tables */ bool bLoaded = false; unsigned int iSize = size(); for (unsigned int iEpgPtr = 0; iEpgPtr < iSize; iEpgPtr++) { CPVREpg *epg = at(iEpgPtr); CPVRChannel *channel = epg->Channel(); if (epg->LoadFromDb()) { if (channel) channel->UpdateEPGPointers(); bLoaded = true; } if (bShowProgress) { /* update the progress bar */ if (channel) scanner->SetTitle(channel->ChannelName()); scanner->SetProgress(iEpgPtr, iSize); scanner->UpdateState(); } } /* close the database */ database->Close(); if (bShowProgress) scanner->Close(); m_bDatabaseLoaded = bLoaded; return bLoaded; }
bool CPVRChannelGroupInternal::Persist(void) { bool bReturn(true); CSingleLock lock(m_critSection); bool bHasNewChannels = HasNewChannels(); bool bHasChangedChannels = HasChangedChannels(); /* open the database */ CPVRDatabase *database = OpenPVRDatabase(); if (!database) return false; if (bHasNewChannels || bHasChangedChannels) CLog::Log(LOGDEBUG, "CPVRChannelGroupInternal - %s - persisting %d channels", __FUNCTION__, (int) size()); if (bHasNewChannels) { CLog::Log(LOGDEBUG, "CPVRChannelGroupInternal - %s - group '%s' has new channels. writing changes directly", __FUNCTION__, GroupName().c_str()); /* write directly to get channel ids */ for (unsigned int iChannelPtr = 0; iChannelPtr < size(); iChannelPtr++) { CPVRChannel *channel = at(iChannelPtr).channel; if (!channel->Persist()) { CLog::Log(LOGERROR, "CPVRChannelGroupInternal - %s - failed to persist channel '%s'", __FUNCTION__, channel->ChannelName().c_str()); bReturn = false; } } lock.Leave(); } else if (bHasChangedChannels) { /* queue queries */ for (unsigned int iChannelPtr = 0; iChannelPtr < size(); iChannelPtr++) at(iChannelPtr).channel->Persist(true); lock.Leave(); /* and commit them */ bReturn = database->CommitInsertQueries(); if (!bReturn) CLog::Log(LOGERROR, "CPVRChannelGroupInternal - %s - failed to persist channels", __FUNCTION__); } if (bReturn) bReturn = CPVRChannelGroup::Persist(); database->Close(); return bReturn; }
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; }
void SSortFileItem::ByChannel(CFileItemPtr &item) { if (!item) return; if (item->IsEPG() || item->IsPVRChannel()) { CPVRChannel *channel = item->GetPVRChannelInfoTag(); if (channel) item->SetSortLabel(channel->ChannelName()); } }
int CPVRChannels::GetChannels(CFileItemList* results, int iGroupID /* = -1 */, bool bHidden /* = false */) { int iAmount = 0; SortByChannelNumber(); for (unsigned int ptr = 0; ptr < size(); ptr++) { CPVRChannel *channel = at(ptr); if (channel->IsHidden() != bHidden) continue; if (iGroupID != -1 && channel->GroupID() != iGroupID) continue; CFileItemPtr channelFile(new CFileItem(*channel)); if (channel->IsRadio()) { CMusicInfoTag* musictag = channelFile->GetMusicInfoTag(); if (musictag) { const CPVREpgInfoTag *epgNow = channel->GetEPGNow(); musictag->SetURL(channel->Path()); musictag->SetTitle(epgNow->Title()); musictag->SetArtist(channel->ChannelName()); musictag->SetAlbumArtist(channel->ChannelName()); musictag->SetGenre(epgNow->Genre()); musictag->SetDuration(epgNow->GetDuration()); musictag->SetLoaded(true); musictag->SetComment(""); musictag->SetLyrics(""); } } results->Add(channelFile); iAmount++; } return iAmount; }
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 CGUIWindowPVRGuide::UpdateViewChannel(void) { CPVRChannel CurrentChannel; bool bGotCurrentChannel = g_PVRManager.GetCurrentChannel(&CurrentChannel); m_parent->m_guideGrid = NULL; m_parent->m_viewControl.SetCurrentView(CONTROL_LIST_GUIDE_CHANNEL); m_parent->SetLabel(m_iControlButton, g_localizeStrings.Get(19222) + ": " + g_localizeStrings.Get(19029)); if (bGotCurrentChannel) m_parent->SetLabel(CONTROL_LABELGROUP, CurrentChannel.ChannelName().c_str()); if (!bGotCurrentChannel || g_PVRManager.GetCurrentEpg(m_parent->m_vecItems) == 0) { CFileItemPtr item; item.reset(new CFileItem("pvr://guide/" + CurrentChannel.ChannelName() + "/empty.epg", false)); item->SetLabel(g_localizeStrings.Get(19028)); item->SetLabelPreformated(true); m_parent->m_vecItems->Add(item); } m_parent->m_viewControl.SetItems(*m_parent->m_vecItems); }
bool CPVRDatabase::Delete(const CPVRChannel &channel) { /* invalid channel */ if (channel.ChannelID() <= 0) return false; CLog::LogFC(LOGDEBUG, LOGPVR, "Deleting channel '%s' from the database", channel.ChannelName().c_str()); Filter filter; filter.AppendWhere(PrepareSQL("idChannel = %u", channel.ChannelID())); CSingleLock lock(m_critSection); return DeleteValues("channels", filter); }