Example #1
0
bool CPVRChannelGroup::UpdateChannel(const CFileItem &item, bool bHidden, bool bVirtual, bool bEPGEnabled, bool bParentalLocked, int iEPGSource, int iChannelNumber, const CStdString &strChannelName, const CStdString &strIconPath, const CStdString &strStreamURL)
{
  if (!item.HasPVRChannelInfoTag())
    return false;

  CSingleLock lock(m_critSection);

  /* get the real channel from the group */
  CPVRChannel *channel = GetByUniqueID(item.GetPVRChannelInfoTag()->UniqueID());
  if (!channel)
    return false;

  channel->SetChannelName(strChannelName);
  channel->SetHidden(bHidden);
  channel->SetLocked(bParentalLocked);
  channel->SetIconPath(strIconPath);

  if (bVirtual)
    channel->SetStreamURL(strStreamURL);
  if (iEPGSource == 0)
    channel->SetEPGScraper("client");

  // TODO add other scrapers
  channel->SetEPGEnabled(bEPGEnabled);

  /* set new values in the channel tag */
  if (bHidden)
  {
    SortByChannelNumber(); // or previous changes will be overwritten
    RemoveFromGroup(*channel);
  }
  else
  {
    SetChannelNumber(*channel, iChannelNumber);
  }

  return true;
}
Example #2
0
void CGUIDialogPVRChannelManager::SaveList() // XXX investigate: renumbering doesn't work
{
  if (!m_bContainsChanges)
   return;

  CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase();
  if (!database || !database->Open())
    return;

  CGUIDialogProgress* pDlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
  pDlgProgress->SetHeading(190);
  pDlgProgress->SetLine(0, "");
  pDlgProgress->SetLine(1, 328);
  pDlgProgress->SetLine(2, "");
  pDlgProgress->StartModal();
  pDlgProgress->Progress();
  pDlgProgress->SetPercentage(0);

  int iActiveChannels = 0;
  for (int iListPtr = 0; iListPtr < m_channelItems->Size(); iListPtr++)
  {
    if (m_channelItems->Get(iListPtr)->GetPropertyBOOL("ActiveChannel"))
      ++iActiveChannels;
  }

//  int iNextChannelNumber = 1;
//  int iNextHiddenChannelNumber = iActiveChannels + 1;
  bool bHasChangedItems = false;

  for (int iListPtr = 0; iListPtr < m_channelItems->Size(); iListPtr++)
  {
    bool bChanged = false;
    CFileItemPtr pItem = m_channelItems->Get(iListPtr);
    if (!pItem)
      continue;
    CPVRChannel *channel = pItem->GetPVRChannelInfoTag();

    if (!channel)
    {
      //TODO add new channel
      continue;
    }

    /* get values from the form */
    bool bHidden              = !pItem->GetPropertyBOOL("ActiveChannel");
    bool bVirtual             = pItem->GetPropertyBOOL("Virtual");
    bool bEPGEnabled          = pItem->GetPropertyBOOL("UseEPG");
    int iEPGSource            = pItem->GetPropertyInt("EPGSource");
    CStdString strChannelName = pItem->GetProperty("Name");
    CStdString strIconPath    = pItem->GetProperty("Icon");
    CStdString strStreamURL   = pItem->GetProperty("StreamURL");

    /* set new values in the channel tag */
// TODO
//    if (bHidden)
//      bChanged = channel->SetChannelNumber(iNextHiddenChannelNumber++) || bChanged;
//    else
//      bChanged = channel->SetChannelNumber(iNextChannelNumber++) || bChanged;
    bChanged = channel->SetChannelName(strChannelName) || bChanged;
    bChanged = channel->SetHidden(bHidden) || bChanged;
    bChanged = channel->SetIconPath(strIconPath) || bChanged;
    if (bVirtual)
      bChanged = channel->SetStreamURL(strStreamURL) || bChanged;

    if (iEPGSource == 0)
      bChanged = channel->SetEPGScraper("client") || bChanged;
    // TODO add other scrapers
    bChanged = channel->SetEPGEnabled(bEPGEnabled) || bChanged;

    if (bChanged)
    {
      bHasChangedItems = true;
      channel->Persist(true);
    }

    pItem->SetProperty("Changed", false);
    pDlgProgress->SetPercentage(iListPtr * 100 / m_channelItems->Size());
  }

  if (bHasChangedItems)
  {
    database->CommitInsertQueries();
    CPVRManager::Get()->Start(); // XXX not a nice way to refresh the channels, but works for now
  }

  database->Close();

  m_bContainsChanges = false;
  pDlgProgress->Close();
}