void CAddonCallbacksPVR::PVRTransferChannelGroupMember(void *addonData, const ADDON_HANDLE handle, const PVR_CHANNEL_GROUP_MEMBER *member)
{
  if (!handle)
  {
    CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
    return;
  }

  CPVRClient *client      = GetPVRClient(addonData);
  CPVRChannelGroup *group = static_cast<CPVRChannelGroup *>(handle->dataAddress);
  if (!member || !client || !group)
  {
    CLog::Log(LOGERROR, "PVR - %s - invalid handler data", __FUNCTION__);
    return;
  }

  CPVRChannelPtr channel  = g_PVRChannelGroups->GetByUniqueID(member->iChannelUniqueId, client->GetID());
  if (!channel)
  {
    CLog::Log(LOGERROR, "PVR - %s - cannot find group '%s' or channel '%d'", __FUNCTION__, member->strGroupName, member->iChannelUniqueId);
  }
  else if (group->IsRadio() == channel->IsRadio())
  {
    /* transfer this entry to the group */
    group->AddToGroup(channel, member->iChannelNumber);
  }
}
Exemple #2
0
bool CPVRChannelGroups::AddChannelToGroup(CPVRChannel *channel, int iGroupId)
{
  bool bReturn = false;
  CPVRChannelGroup *group = (CPVRChannelGroup *) GetById(iGroupId);
  if (group)
  {
    bReturn = group->AddToGroup(*channel);
  }

  return bReturn;
}
Exemple #3
0
bool CPVRChannelGroups::AddChannelToGroup(CPVRChannel *channel, int iGroupId)
{
  bool bReturn = false;
  CSingleLock lock(m_critSection);
  CPVRChannelGroup *group = (CPVRChannelGroup *) GetById(iGroupId);
  if (group)
  {
    bReturn = group->AddToGroup(*channel);
  }

  return bReturn;
}
Exemple #4
0
int CPVRDatabase::GetGroupMembers(CPVRChannelGroup &group)
{
  int iReturn = -1;

  /* invalid group id */
  if (group.GroupID() < 0)
  {
    CLog::Log(LOGERROR, "PVRDB - %s - invalid group id: %d",
        __FUNCTION__, group.GroupID());
    return -1;
  }

  CStdString strQuery = FormatSQL("SELECT idChannel, iChannelNumber FROM map_channelgroups_channels WHERE idGroup = %u ORDER BY iChannelNumber", group.GroupID());
  if (ResultQuery(strQuery))
  {
    iReturn = 0;

    try
    {
      while (!m_pDS->eof())
      {
        int iChannelId = m_pDS->fv("idChannel").get_asInt();
        int iChannelNumber = m_pDS->fv("iChannelNumber").get_asInt();
        CPVRChannel *channel = (CPVRChannel *) g_PVRChannelGroups->GetByChannelIDFromAll(iChannelId);

        if (channel && group.AddToGroup(*channel, iChannelNumber))
          ++iReturn;

        m_pDS->next();
      }
      m_pDS->close();
    }
    catch(...)
    {
      CLog::Log(LOGERROR, "PVRDB - %s - failed to get channels", __FUNCTION__);
    }
  }

  return iReturn;
}
Exemple #5
0
void CAddonCallbacksPVR::PVRTransferChannelGroupMember(void *addonData, const PVR_HANDLE handle, const PVR_CHANNEL_GROUP_MEMBER *member)
{
  CAddonCallbacks* addon = (CAddonCallbacks*) addonData;
  if (addon == NULL || handle == NULL || member == NULL || handle->dataAddress == NULL)
  {
    CLog::Log(LOGERROR, "CAddonCallbacksPVR - %s - called with a null pointer", __FUNCTION__);
    return;
  }

  CPVRClient* client      = (CPVRClient*) handle->callerAddress;
  CPVRChannelGroup *group = (CPVRChannelGroup *) handle->dataAddress;
  CPVRChannel *channel    = (CPVRChannel *) g_PVRChannelGroups->GetByUniqueID(member->iChannelUniqueId, client->GetClientID());
  if (group != NULL && channel != NULL && group->IsRadio() == channel->IsRadio())
  {
    /* transfer this entry to the group */
    group->AddToGroup(*channel, member->iChannelNumber, false);
  }
  else
  {
    CLog::Log(LOGERROR, "CAddonCallbacksPVR - %s - cannot find group '%s' or channel '%d'",
        __FUNCTION__, member->strGroupName, member->iChannelUniqueId);
  }
}
Exemple #6
0
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;
  }
}