void CGUIDialogPVRChannelManager::SaveList(void)
{
  if (!m_bContainsChanges)
   return;

  /* display the progress dialog */
  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);

  /* persist all channels */
  unsigned int iNextChannelNumber(0);
  CPVRChannelGroupPtr group = g_PVRChannelGroups->GetGroupAll(m_bIsRadio);
  if (!group)
    return;
  for (int iListPtr = 0; iListPtr < m_channelItems->Size(); iListPtr++)
  {
    CFileItemPtr pItem = m_channelItems->Get(iListPtr);
    PersistChannel(pItem, group, &iNextChannelNumber);

    pDlgProgress->SetPercentage(iListPtr * 100 / m_channelItems->Size());
  }

  group->SortAndRenumber();
  group->Persist();
  m_bContainsChanges = false;
  SetItemsUnchanged();
  pDlgProgress->Close();
}
Example #2
0
bool CPVRChannelGroups::Update(const CPVRChannelGroup &group, bool bUpdateFromClient /* = false */)
{
  if (group.GroupName().empty() && group.GroupID() <= 0)
    return true;

  CPVRChannelGroupPtr updateGroup;
  {
    CSingleLock lock(m_critSection);

    // There can be only one internal group! Make sure we never push a new one!
    if (group.IsInternalGroup())
      updateGroup = GetGroupAll();

    // try to find the group by id
    if (!updateGroup && group.GroupID() > 0)
      updateGroup = GetById(group.GroupID());

    // try to find the group by name if we didn't find it yet
    if (!updateGroup)
      updateGroup = GetByName(group.GroupName());

    if (!updateGroup)
    {
      // create a new group if none was found. Copy the properties immediately 
      // so the group doesn't get flagged as "changed" further down.
      updateGroup = CPVRChannelGroupPtr(new CPVRChannelGroup(group.IsRadio(), group.GroupID(), group.GroupName()));
      m_groups.push_back(updateGroup);
    }

    updateGroup->SetRadio(group.IsRadio());
    updateGroup->SetGroupID(group.GroupID());
    updateGroup->SetGroupName(group.GroupName());
    updateGroup->SetGroupType(group.GroupType());
    updateGroup->SetPosition(group.GetPosition());

    // don't override properties we only store locally in our PVR database
    if (!bUpdateFromClient)
    {
      updateGroup->SetLastWatched(group.LastWatched());
      updateGroup->SetHidden(group.IsHidden());
    }
  }

  // sort groups
  SortGroups();

  // persist changes
  if (bUpdateFromClient)
    return updateGroup->Persist();

  return true;
}
Example #3
0
bool CPVRManager::OpenLiveStream(const CFileItem &channel)
{
  bool bReturn(false);
  if (!channel.HasPVRChannelInfoTag())
    return bReturn;

  CLog::Log(LOGDEBUG,"PVRManager - %s - opening live stream on channel '%s'",
      __FUNCTION__, channel.GetPVRChannelInfoTag()->ChannelName().c_str());

  // check if we're allowed to play this file
  if (IsParentalLocked(*channel.GetPVRChannelInfoTag()))
    return bReturn;

  CPVRChannelPtr playingChannel;
  CPVRChannelGroupPtr group;
  bool bPersistChanges(false);
  if ((bReturn = m_addons->OpenStream(*channel.GetPVRChannelInfoTag(), false)) != false)
  {
    CSingleLock lock(m_critSection);
    if(m_currentFile)
      delete m_currentFile;
    m_currentFile = new CFileItem(channel);

    if (m_addons->GetPlayingChannel(playingChannel))
    {
      time_t tNow;
      CDateTime::GetCurrentDateTime().GetAsTime(tNow);

      /* update last watched timestamp for channel */
      playingChannel->SetLastWatched(tNow);

      /* update last watched timestamp for group */
      group = g_PVRManager.GetPlayingGroup(playingChannel->IsRadio());
      group->SetLastWatched(tNow);

      /* update last played group */
      m_channelGroups->SetLastPlayedGroup(group);

      bPersistChanges = true;
    }
  }

  if (bPersistChanges)
  {
    playingChannel->Persist();
    group->Persist();
  }

  return bReturn;
}
Example #4
0
void CPVRManager::UpdateLastWatched(CPVRChannel &channel)
{
  time_t tNow;
  CDateTime::GetCurrentDateTime().GetAsTime(tNow);

  // update last watched timestamp for channel
  // NOTE: method could be called with a fileitem copy as argument so we need to obtain the right channel instance
  CPVRChannelPtr channelPtr = m_channelGroups->GetChannelById(channel.ChannelID());
  channelPtr->SetLastWatched(tNow);
  channelPtr->Persist();

  // update last watched timestamp for group
  CPVRChannelGroupPtr group = GetPlayingGroup(channel.IsRadio());
  group->SetLastWatched(tNow);
  group->Persist();

  /* update last played group */
  m_channelGroups->SetLastPlayedGroup(group);
}
void CGUIDialogPVRChannelManager::SaveList(void)
{
    if (!m_bContainsChanges)
        return;

    /* display the progress dialog */
    CGUIDialogProgress* pDlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
    pDlgProgress->SetHeading(CVariant{190});
    pDlgProgress->SetLine(0, CVariant{""});
    pDlgProgress->SetLine(1, CVariant{328});
    pDlgProgress->SetLine(2, CVariant{""});
    pDlgProgress->StartModal();
    pDlgProgress->Progress();
    pDlgProgress->SetPercentage(0);

    /* persist all channels */
    unsigned int iNextChannelNumber(0);
    CPVRChannelGroupPtr group = g_PVRChannelGroups->GetGroupAll(m_bIsRadio);
    if (!group)
        return;

    for (int iListPtr = 0; iListPtr < m_channelItems->Size(); iListPtr++)
    {
        CFileItemPtr pItem = m_channelItems->Get(iListPtr);

        if (!pItem->HasPVRChannelInfoTag())
            continue;

        if (pItem->GetProperty("SupportsSettings").asBoolean())
            RenameChannel(pItem);

        PersistChannel(pItem, group, &iNextChannelNumber);

        pDlgProgress->SetPercentage(iListPtr * 100 / m_channelItems->Size());
    }

    group->SortAndRenumber();
    group->Persist();
    m_bContainsChanges = false;
    SetItemsUnchanged();
    pDlgProgress->Close();
}
Example #6
0
void CPVRManager::CloseStream(void)
{
  CPVRChannelPtr channel;
  CPVRChannelGroupPtr group;
  bool bPersistChanges(false);

  {
    CSingleLock lock(m_critSection);

    if (m_addons->GetPlayingChannel(channel))
    {
      time_t tNow;
      CDateTime::GetCurrentDateTime().GetAsTime(tNow);

      /* update last watched timestamp for channel */
      channel->SetLastWatched(tNow);

      /* update last watched timestamp for group */
      group = g_PVRManager.GetPlayingGroup(channel->IsRadio());
      group->SetLastWatched(tNow);

      /* update last played group */
      m_channelGroups->SetLastPlayedGroup(group);

      bPersistChanges = true;
      
      // store channel settings
      g_application.SaveFileState();
    }

    m_addons->CloseStream();
    SAFE_DELETE(m_currentFile);
  }

  if (bPersistChanges)
  {
    channel->Persist();
    group->Persist();
  }
}
Example #7
0
bool CPVRChannelGroups::AddGroup(const CStdString &strName)
{
  bool bPersist(false);
  CPVRChannelGroupPtr group;

  {
    CSingleLock lock(m_critSection);

    // check if there's no group with the same name yet
    group = GetByName(strName);
    if (!group)
    {
      // create a new group
      group = CPVRChannelGroupPtr(new CPVRChannelGroup(m_bRadio, -1, strName));
      m_groups.push_back(group);
      bPersist = true;
    }
  }

  // persist in the db if a new group was added
  return bPersist ? group->Persist() : true;
}
bool CPVRChannelGroups::Update(const CPVRChannelGroup &group, bool bSaveInDb)
{
  if (group.GroupName().empty() && group.GroupID() <= 0)
    return true;

  CPVRChannelGroupPtr updateGroup;
  {
    CSingleLock lock(m_critSection);
    // try to find the group by id
    if (group.GroupID() > 0)
      updateGroup = GetById(group.GroupID());

    // try to find the group by name if we didn't find it yet
    if (!updateGroup)
      updateGroup = GetByName(group.GroupName());

    if (!updateGroup)
    {
      // create a new group if none was found
      updateGroup = CPVRChannelGroupPtr(new CPVRChannelGroup(m_bRadio, group.GroupID(), group.GroupName()));
      updateGroup->SetGroupType(group.GroupType());
      updateGroup->SetLastWatched(group.LastWatched());
      m_groups.push_back(updateGroup);
    }
    else
    {
      // update existing group
      updateGroup->SetGroupID(group.GroupID());
      updateGroup->SetGroupName(group.GroupName());
      updateGroup->SetGroupType(group.GroupType());
    }
  }

  // persist changes
  if (bSaveInDb && updateGroup)
    return updateGroup->Persist();

  return true;
}
Example #9
0
bool CPVRChannelGroups::AddGroup(const std::string &strName)
{
  bool bPersist(false);
  CPVRChannelGroupPtr group;

  {
    CSingleLock lock(m_critSection);

    // check if there's no group with the same name yet
    group = GetByName(strName);
    if (!group)
    {
      // create a new group
      group.reset(new CPVRChannelGroup(m_bRadio, CPVRChannelGroup::INVALID_GROUP_ID, strName, GetGroupAll()));

      m_groups.push_back(group);
      bPersist = true;
    }
  }

  // persist in the db if a new group was added
  return bPersist ? group->Persist() : true;
}