示例#1
0
bool CPVREpgs::RemoveOldEntries()
{
  bool bReturn = false;
  CLog::Log(LOGINFO, "PVREpgs - %s - removing old EPG entries",
      __FUNCTION__);

  CPVRDatabase *database = g_PVRManager.GetTVDatabase();
  CDateTime now = CDateTime::GetCurrentDateTime();

  if (!database->Open())
  {
    CLog::Log(LOGERROR, "PVREpgs - %s - cannot open the database",
        __FUNCTION__);
    return bReturn;
  }

  /* call Cleanup() on all known EPG tables */
  for (unsigned int iEpgPtr = 0; iEpgPtr < size(); iEpgPtr++)
  {
    at(iEpgPtr)->Cleanup(now);
  }

  /* remove the old entries from the database */
  bReturn = database->EraseOldEpgEntries();

  if (bReturn)
    CDateTime::GetCurrentDateTime().GetAsTime(m_iLastEpgCleanup);

  return bReturn;
}
示例#2
0
void CPVREpgs::Clear(bool bClearDb /* = false */)
{
  /* remove all pointers to epg tables on timers */
  for (unsigned int iTimerPtr = 0; iTimerPtr < PVRTimers.size(); iTimerPtr++)
    PVRTimers[iTimerPtr].SetEpgInfoTag(NULL);

  /* clear all epg tables and remove pointers to epg tables on channels */
  for (unsigned int iEpgPtr = 0; iEpgPtr < size(); iEpgPtr++)
  {
    CPVREpg *epg = at(iEpgPtr);
    epg->Clear();

    CPVRChannel *channel = (CPVRChannel *) epg->Channel();
    if (channel)
      channel->m_EPG = NULL;
  }

  /* remove all EPG tables */
  clear();

  /* clear the database entries */
  if (bClearDb)
  {
    CPVRDatabase *database = g_PVRManager.GetTVDatabase();
    database->Open();
    database->EraseEpg();
    database->Close();
  }

  m_iLastEpgUpdate  = 0;
  m_bDatabaseLoaded = false;
}
示例#3
0
int CPVRChannels::LoadFromClients(bool bAddToDb /* = true */)
{
  CPVRDatabase *database = NULL;
  int iCurSize = size();

  if (bAddToDb)
  {
    database = g_PVRManager.GetTVDatabase();

    if (!database || !database->Open())
      return -1;
  }

  if (GetFromClients() == -1)
    return -1;

  SortByClientChannelNumber();
  ReNumberAndCheck();
  SearchAndSetChannelIcons();

  if (bAddToDb)
  {
    /* add all channels to the database */
    for (unsigned int ptr = 0; ptr < size(); ptr++)
      database->UpdateChannel(*at(ptr));

    database->Close();

    clear();

    return LoadFromDb(true);
  }

  return size() - iCurSize;
}
示例#4
0
int CPVRChannelGroupInternal::LoadFromDb(bool bCompress /* = false */)
{
  CPVRDatabase *database = g_PVRManager.GetTVDatabase();
  if (!database || !database->Open())
    return -1;

  int iChannelCount = size();

  if (database->GetChannels(this, m_bRadio) > 0)
  {
    if (bCompress)
      database->Compress(true);
  }
  else
  {
    CLog::Log(LOGINFO, "PVRChannelGroupInternal - %s - no channels in the database",
        __FUNCTION__);
  }

  database->Close();

  SortByChannelNumber();

  return size() - iChannelCount;
}
示例#5
0
bool CPVRChannelGroups::Load(void)
{
    CLog::Log(LOGDEBUG, "PVRChannelGroups - %s - loading all %s channel groups",
              __FUNCTION__, m_bRadio ? "radio" : "TV");

    Clear();

    /* create internal channel group */
    CPVRChannelGroupInternal *internalChannels = new CPVRChannelGroupInternal(m_bRadio);
    push_back(internalChannels);
    internalChannels->Load();

    /* load the other groups from the database */
    CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase();
    if (database->Open())
    {
        database->GetChannelGroupList(*this, m_bRadio);

        /* load group members */
        for (unsigned int iGroupPtr = 1; iGroupPtr < size(); iGroupPtr++)
            at(iGroupPtr)->Load();

        database->Close();
    }

    CLog::Log(LOGDEBUG, "PVRChannelGroups - %s - %d %s channel groups loaded",
              __FUNCTION__, size(), m_bRadio ? "radio" : "TV");

    return true;
}
示例#6
0
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;
}
示例#7
0
bool CPVRChannelGroupInternal::Persist(void)
{
  bool bReturn(true);
  CSingleLock lock(m_critSection);

  bool bHasNewChannels = HasNewChannels();
  bool bHasChangedChannels = HasChangedChannels();

  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++)
    {
      if (!at(iChannelPtr).channel->Persist())
      {
        CLog::Log(LOGERROR, "CPVRChannelGroupInternal - %s - failed to persist channel '%s'",
            __FUNCTION__, at(iChannelPtr).channel->ChannelName().c_str());
        bReturn = false;
      }
    }
  }
  else if (bHasChangedChannels)
  {
    /* open the database */
    CPVRDatabase *database = g_PVRManager.GetTVDatabase();
    if (!database || !database->Open())
    {
      CLog::Log(LOGERROR, "CPVRChannelGroupInternal - %s - failed to open the database", __FUNCTION__);
      return false;
    }

    /* queue queries */
    for (unsigned int iChannelPtr = 0; iChannelPtr < size(); iChannelPtr++)
      at(iChannelPtr).channel->Persist(true);

    /* and commit them */
    bReturn = database->CommitInsertQueries();
    if (!bReturn)
      CLog::Log(LOGERROR, "CPVRChannelGroupInternal - %s - failed to persist channels", __FUNCTION__);

    database->Close();
  }

  if (bReturn)
    bReturn = CPVRChannelGroup::Persist();

  return bReturn;
}
示例#8
0
int CPVRChannelGroup::LoadFromDb(bool bCompress /* = false */)
{
  CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase();
  if (!database || !database->Open())
    return -1;

  int iChannelCount = size();

  database->GetChannelsInGroup(this);
  database->Close();

  return size() - iChannelCount;
}
bool CPVRChannelGroupInternal::Update()
{
  bool          bReturn  = false;
  CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase();

  if (database && database->Open())
  {
    CPVRChannelGroupInternal PVRChannels_tmp(m_bRadio);

    PVRChannels_tmp.LoadFromClients(false);
    bReturn = UpdateGroupEntries(&PVRChannels_tmp);

    database->Close();
  }

  return bReturn;
}
示例#10
0
bool CPVRChannels::Update()
{
  bool         bReturn  = false;
  CPVRDatabase *database = g_PVRManager.GetTVDatabase();

  if (database && database->Open())
  {
    CPVRChannels PVRChannels_tmp(m_bRadio);

    PVRChannels_tmp.LoadFromClients(false);
    bReturn = Update(&PVRChannels_tmp);

    database->Close();
  }

  return bReturn;
}
示例#11
0
void CPVRChannels::MoveChannel(unsigned int iOldIndex, unsigned int iNewIndex)
{
  if (iNewIndex == iOldIndex || iNewIndex == 0)
    return;

  CPVRDatabase *database = g_PVRManager.GetTVDatabase();
  database->Open();

  CPVRChannels tempChannels(m_bRadio);

  /* move the channel */
  tempChannels.push_back(at(iOldIndex - 1));
  erase(begin() + iOldIndex - 1);
  if (iNewIndex < size())
    insert(begin() + iNewIndex - 1, tempChannels[0]);
  else
    push_back(tempChannels[0]);

  /* update the channel numbers */
  for (unsigned int ptr = 0; ptr < size(); ptr++)
  {
    CPVRChannel *channel = at(ptr);

    if (channel->ChannelNumber() != (int) ptr + 1)
    {
      channel->SetChannelNumber(ptr + 1, true);
    }
  }

  CLog::Log(LOGNOTICE, "%s - %s channel '%d' moved to '%d'",
      __FUNCTION__, (m_bRadio ? "radio" : "tv"), iOldIndex, iNewIndex);

  database->Close();

  /* update the timers with the new channel numbers */
  for (unsigned int ptr = 0; ptr < PVRTimers.size(); ptr++)
  {
    CPVRTimerInfoTag timer = PVRTimers[ptr];
    CPVRChannel *tag = GetByClient(timer.Number(), timer.ClientID());
    if (tag)
      timer.SetNumber(tag->ChannelNumber());
  }

  m_bIsSorted = false;
}
示例#12
0
void CPVREpgs::Process()
{
  time_t iNow          = 0;
  m_iLastPointerUpdate = 0;
  m_iLastTimerUpdate   = 0;
  m_iLastEpgCleanup    = 0;
  m_iLastEpgUpdate     = 0;

  CPVRDatabase *database = g_PVRManager.GetTVDatabase();
  if (!database->Open())
  {
    CLog::Log(LOGERROR, "PVREpgs - %s - cannot open the database",
        __FUNCTION__);
    return;
  }

  /* get the last EPG update time from the database */
  database->GetLastEpgScanTime().GetAsTime(m_iLastEpgUpdate);
  database->Close();

  LoadSettings();

  while (!m_bStop)
  {
    CDateTime::GetCurrentDateTime().GetAsTime(iNow);

    /* update the EPG */
    if (!m_bStop && (iNow > m_iLastEpgUpdate + m_iUpdateTime || !m_bDatabaseLoaded))
      UpdateEPG(!m_bDatabaseLoaded);

    /* update the "now playing" pointers every 60 seconds */
    if (!m_bStop && iNow > m_iLastPointerUpdate + 60)
      UpdateAllChannelEPGPointers();

    /* update the timers every 60 seconds */
    if (!m_bStop && iNow > m_iLastTimerUpdate + 60)
      UpdateTimers();

    /* remove old entries every 30 minutes */
    if (!m_bStop && iNow > m_iLastEpgCleanup + 1800)
      RemoveOldEntries();

    Sleep(1000);
  }
}
示例#13
0
void CPVRChannelGroup::SearchAndSetChannelIcons(bool bUpdateDb /* = false */)
{
  if (g_guiSettings.GetString("pvrmenu.iconpath") == "")
    return;

  CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase();
  database->Open();
  CSingleLock lock(m_critSection);

  for (unsigned int ptr = 0; ptr < size(); ptr++)
  {
    PVRChannelGroupMember groupMember = at(ptr);

    /* skip if an icon is already set */
    if (groupMember.channel->IconPath() != "")
      continue;

    CStdString strBasePath = g_guiSettings.GetString("pvrmenu.iconpath");
    CStdString strChannelName = groupMember.channel->ClientChannelName();

    CStdString strIconPath = strBasePath + groupMember.channel->ClientChannelName();
    CStdString strIconPathLower = strBasePath + strChannelName.ToLower();
    CStdString strIconPathUid;
    strIconPathUid.Format("%s/%08d", strBasePath, groupMember.channel->UniqueID());

    groupMember.channel->SetIconPath(strIconPath      + ".tbn", bUpdateDb) ||
    groupMember.channel->SetIconPath(strIconPath      + ".jpg", bUpdateDb) ||
    groupMember.channel->SetIconPath(strIconPath      + ".png", bUpdateDb) ||

    groupMember.channel->SetIconPath(strIconPathLower + ".tbn", bUpdateDb) ||
    groupMember.channel->SetIconPath(strIconPathLower + ".jpg", bUpdateDb) ||
    groupMember.channel->SetIconPath(strIconPathLower + ".png", bUpdateDb) ||

    groupMember.channel->SetIconPath(strIconPathUid   + ".tbn", bUpdateDb) ||
    groupMember.channel->SetIconPath(strIconPathUid   + ".jpg", bUpdateDb) ||
    groupMember.channel->SetIconPath(strIconPathUid   + ".png", bUpdateDb);

    /* TODO: start channel icon scraper here if nothing was found */
  }

  database->Close();
}
示例#14
0
int CPVRChannels::LoadFromDb(bool bCompress /* = false */)
{
  CPVRDatabase *database = g_PVRManager.GetTVDatabase();
  if (!database || !database->Open())
    return -1;

  int iChannelCount = size();

  if (database->GetChannels(*this, m_bRadio) > 0)
  {
    if (bCompress)
      database->Compress(true);

    Update();
  }

  database->Close();

  return size() - iChannelCount;
}
示例#15
0
bool CPVRChannelGroup::Persist(void)
{
  CSingleLock lock(m_critSection);
  if (!HasChanges())
    return true;

  CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase();
  if (database && database->Open())
  {
    CLog::Log(LOGDEBUG, "CPVRChannelGroup - %s - persisting channel group '%s' with %d channels",
        __FUNCTION__, GroupName().c_str(), (int) size());
    database->Persist(this);
    database->Close();

    m_bChanged = false;
    return true;
  }

  return false;
}
示例#16
0
文件: PVRChannel.cpp 项目: rdaoc/xbmc
bool CPVRChannel::Delete(void)
{
  bool bReturn = false;
  CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase();
  if (!database || !database->Open())
    return bReturn;

  /* delete the EPG table */
  if (m_EPG)
  {
    CPVRManager::GetEpg()->DeleteEpg(*m_EPG, true);
    m_EPG = NULL;
  }

  bReturn = database->Delete(*this);

  database->Close();

  return bReturn;
}
示例#17
0
文件: PVRChannel.cpp 项目: rdaoc/xbmc
bool CPVRChannel::Persist(bool bQueueWrite /* = false */)
{
  CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase();
  if (database)
  {
    if (!bQueueWrite)
    {
      database->Open();
      m_iChannelId = database->Persist(*this, false);
      database->Close();
      return m_iChannelId > 0;
    }
    else
    {
      database->Persist(*this, true);
      return true;
    }
  }

  return false;
}
示例#18
0
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();
}
示例#19
0
bool CPVRChannelGroups::DeleteGroup(const CPVRChannelGroup &group)
{
    bool bReturn = false;

    if (group.IsInternalGroup())
    {
        CLog::Log(LOG_ERROR, "CPVRChannelGroups - %s - cannot delete internal group '%s'",
                  __FUNCTION__, group.GroupName().c_str());
        return bReturn;
    }

    CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase();
    if (!database || !database->Open())
    {
        CLog::Log(LOG_ERROR, "CPVRChannelGroups - %s - unable to open the database", __FUNCTION__);
        return bReturn;
    }

    /* remove all channels from the group */
    database->RemoveChannelsFromGroup(group.GroupID());

    /* delete the group from the database */
    bReturn = database->DeleteChannelGroup(group.GroupID(), m_bRadio);

    database->Close();

    /* delete the group in this container */
    for (unsigned int iGroupPtr = 0; iGroupPtr < size(); iGroupPtr++)
    {
        if (at(iGroupPtr)->GroupID() == group.GroupID())
        {
            delete at(iGroupPtr);
            erase(begin() + iGroupPtr);
            break;
        }
    }

    return bReturn;
}
示例#20
0
bool CPVRChannelGroupInternal::Persist(void)
{
  bool bReturn = false;
  bool bRefreshChannelList = false;
  CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase();

  if (!database || !database->Open())
    return bReturn;

  CLog::Log(LOGDEBUG, "CPVRChannelGroupInternal - %s - persisting %d channels",
      __FUNCTION__, size());
  bReturn = true;
  for (unsigned int iChannelPtr = 0; iChannelPtr < size(); iChannelPtr++)
  {
    /* if this channel has an invalid ID, reload the list afterwards */
    bRefreshChannelList = at(iChannelPtr).channel->ChannelID() <= 0;

    bReturn = at(iChannelPtr).channel->Persist(true) && bReturn;
  }

  if (bReturn)
  {
    if (bRefreshChannelList)
    {
      database->CommitInsertQueries();
      CLog::Log(LOGDEBUG, "PVRChannelGroup - %s - reloading the channels list to get channel IDs", __FUNCTION__);
      Unload();
      bReturn = LoadFromDb(true) > 0;
    }

    if (bReturn)
      bReturn = CPVRChannelGroup::Persist();
  }
  database->Close();

  return bReturn;
}
示例#21
0
bool CPVRClients::LoadClients(void)
{
  if (m_bAllClientsLoaded)
    return !m_clientMap.empty();

  CAddonMgr::Get().RegisterAddonMgrCallback(ADDON_PVRDLL, this);

  /* get all PVR addons */
  VECADDONS addons;
  if (!CAddonMgr::Get().GetAddons(ADDON_PVRDLL, addons, true))
    return false;

  /* load and initialise the clients */
  CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase();
  if (!database || !database->Open())
  {
    CLog::Log(LOGERROR, "PVR - %s - cannot open the database", __FUNCTION__);
    return false;
  }

  m_bAllClientsLoaded = true;
  for (unsigned iClientPtr = 0; iClientPtr < addons.size(); iClientPtr++)
  {
    const AddonPtr clientAddon = addons.at(iClientPtr);
    if (!clientAddon->Enabled())
      continue;

    int iClientId = AddClientToDb(clientAddon->ID(), clientAddon->Name());
    if (iClientId == -1)
      continue; // don't set "m_bAllClientsLoaded = false;" here because this will enter a neverending loop

    /* check if this client isn't active already */
    if (ClientLoaded(clientAddon->ID()))
      continue;

    /* load and initialise the client libraries */
    boost::shared_ptr<CPVRClient> addon = boost::dynamic_pointer_cast<CPVRClient>(clientAddon);
    if (addon && addon->Create(iClientId, this))
    {
      /* get the client's properties */
      PVR_SERVERPROPS props;
      if (addon->GetProperties(&props) == PVR_ERROR_NO_ERROR)
      {
        m_clientMap.insert(std::make_pair(iClientId, addon));
        m_clientsProps.insert(std::make_pair(iClientId, props));
      }
      else
      {
        CLog::Log(LOGERROR, "PVR - %s - can't get client properties from addon '%s'",
            __FUNCTION__, clientAddon->Name().c_str());
        m_bAllClientsLoaded = false;
      }
    }
    else
    {
      CLog::Log(LOGERROR, "PVR - %s - can't initialise client '%s'",
          __FUNCTION__, clientAddon->Name().c_str());
      m_bAllClientsLoaded = false;
    }
  }

  database->Close();

  return !m_clientMap.empty();
}
示例#22
0
bool CPVREpgs::UpdateEPG(bool bShowProgress /* = false */)
{
  long iStartTime                         = CTimeUtils::GetTimeMS();
  int iEpgCount                           = size();
  CPVRDatabase *database                   = g_PVRManager.GetTVDatabase();
  bool bUpdateSuccess                     = true;
  CGUIDialogPVRUpdateProgressBar *scanner = NULL;

  /* set start and end time */
  time_t start;
  time_t end;
  CDateTime::GetCurrentDateTime().GetAsTime(start); // NOTE: XBMC stores the EPG times as local time
  end = start;
  start -= m_iLingerTime;

  if (!m_bDatabaseLoaded)
  {
    CLog::Log(LOGNOTICE, "PVREpgs - %s - loading initial EPG entries for %i tables from clients",
        __FUNCTION__, iEpgCount);
    end += 60 * 60 * 3; // load 3 hours
  }
  else
  {
    CLog::Log(LOGNOTICE, "PVREpgs - %s - starting EPG update for %i tables (update time = %d)",
        __FUNCTION__, iEpgCount, m_iUpdateTime);
    end += m_iDisplayTime;
  }

  /* show the progress bar */
  if (bShowProgress)
  {
    scanner = (CGUIDialogPVRUpdateProgressBar *)g_windowManager.GetWindow(WINDOW_DIALOG_EPG_SCAN);
    scanner->Show();
    scanner->SetHeader(g_localizeStrings.Get(19004));
  }

  /* open the database */
  database->Open();

  /* update all EPG tables */
  for (unsigned int iEpgPtr = 0; iEpgPtr < size(); iEpgPtr++)
  {
    /* interrupt the update on exit */
    if (m_bStop)
    {
      bUpdateSuccess = false;
      break;
    }

    CPVREpg *epg = at(iEpgPtr);

    bUpdateSuccess = epg->Update(start, end, !m_bIgnoreDbForClient) && bUpdateSuccess;

    if (bShowProgress)
    {
      /* update the progress bar */
      scanner->SetProgress(iEpgPtr, iEpgCount);
      scanner->SetTitle(epg->Channel()->ChannelName());
      scanner->UpdateState();
    }
  }

  /* update the last scan time if the update was successful and if we did a full update */
  if (bUpdateSuccess && m_bDatabaseLoaded)
  {
    database->UpdateLastEpgScanTime();
    CDateTime::GetCurrentDateTime().GetAsTime(m_iLastEpgUpdate);
  }
  database->Close();

  if (!m_bDatabaseLoaded)
  {
    UpdateAllChannelEPGPointers();
    m_bDatabaseLoaded = true;
  }

  if (bShowProgress)
    scanner->Close();

  long lUpdateTime = CTimeUtils::GetTimeMS() - iStartTime;
  CLog::Log(LOGINFO, "PVREpgs - %s - finished updating the EPG after %li.%li seconds",
      __FUNCTION__, lUpdateTime / 1000, lUpdateTime % 1000);

  return bUpdateSuccess;
}
示例#23
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;
  }
}
示例#24
0
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;
}
示例#25
0
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;
}
示例#26
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();
}
示例#27
0
bool CGUIDialogPVRChannelManager::OnMessage(CGUIMessage& message)
{
  unsigned int iControl = 0;
  unsigned int iMessage = message.GetMessage();

  switch (iMessage)
  {
    case GUI_MSG_WINDOW_DEINIT:
    {
      Clear();
    }
    break;

    case GUI_MSG_WINDOW_INIT:
    {
      CGUIWindow::OnMessage(message);
      m_iSelected = 0;
      m_bIsRadio = false;
      m_bMovingMode = false;
      m_bContainsChanges = false;
      SetProperty("IsRadio", "");
      Update();
      SetData(m_iSelected);
      return true;
    }
    break;

    case GUI_MSG_CLICKED:
    {
      iControl = message.GetSenderId();
      if (iControl == CONTROL_LIST_CHANNELS)
      {
        if (!m_bMovingMode)
        {
          int iAction = message.GetParam1();
          int iItem = m_viewControl.GetSelectedItem();

          /* Check file item is in list range and get his pointer */
          if (iItem < 0 || iItem >= (int)m_channelItems->Size()) return true;

          /* Process actions */
          if (iAction == ACTION_SELECT_ITEM || iAction == ACTION_CONTEXT_MENU || iAction == ACTION_MOUSE_RIGHT_CLICK)
          {
            /* Show Contextmenu */
            OnPopupMenu(iItem);
          }
        }
        else
        {
          CFileItemPtr pItem = m_channelItems->Get(m_iSelected);
          if (pItem)
          {
            pItem->SetProperty("Changed", true);
            pItem->Select(false);
            m_bMovingMode = false;
            m_bContainsChanges = true;
            return true;
          }
          else
            return false;
        }
      }
      else if (iControl == BUTTON_OK)
      {
        SaveList();
        Close();
        return true;
      }
      else if (iControl == BUTTON_APPLY)
      {
        SaveList();
        return true;
      }
      else if (iControl == BUTTON_CANCEL)
      {
        Close();
        return true;
      }
      else if (iControl == BUTTON_RADIO_TV)
      {
        if (m_bContainsChanges)
        {
          // prompt user for confirmation of channel record
          CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
          if (!pDialog)
            return true;

          pDialog->SetHeading(20052);
          pDialog->SetLine(0, "");
          pDialog->SetLine(1, 19212);
          pDialog->SetLine(2, 20103);
          pDialog->DoModal();

          if (pDialog->IsConfirmed())
            SaveList();
        }

        m_iSelected = 0;
        m_bMovingMode = false;
        m_bContainsChanges = false;
        m_bIsRadio = !m_bIsRadio;
        SetProperty("IsRadio", m_bIsRadio ? "true" : "");
        Update();
        SetData(m_iSelected);
        return true;
      }
      else if (iControl == RADIOBUTTON_ACTIVE)
      {
        CGUIRadioButtonControl *pRadioButton = (CGUIRadioButtonControl *)GetControl(RADIOBUTTON_ACTIVE);
        if (pRadioButton)
        {
          CFileItemPtr pItem = m_channelItems->Get(m_iSelected);
          if (pItem)
          {
            pItem->SetProperty("Changed", true);
            pItem->SetProperty("ActiveChannel", pRadioButton->IsSelected());
            m_bContainsChanges = true;
            Renumber();
          }
        }
      }
      else if (iControl == EDIT_NAME)
      {
        CGUIEditControl *pEdit = (CGUIEditControl *)GetControl(EDIT_NAME);
        if (pEdit)
        {
          CFileItemPtr pItem = m_channelItems->Get(m_iSelected);
          if (pItem)
          {
            pItem->SetProperty("Changed", true);
            pItem->SetProperty("Name", pEdit->GetLabel2());
            m_bContainsChanges = true;
          }
        }
      }
      else if (iControl == BUTTON_CHANNEL_LOGO)
      {
        CFileItemPtr pItem = m_channelItems->Get(m_iSelected);

        if (!pItem)
          return false;
        if (g_settings.GetCurrentProfile().canWriteSources() && !g_passwordManager.IsProfileLockUnlocked())
          return false;
        else if (!g_passwordManager.IsMasterLockUnlocked(true))
          return false;

        // setup our thumb list
        CFileItemList items;

        // add the current thumb, if available
        if (!pItem->GetProperty("Icon").IsEmpty())
        {
          CFileItemPtr current(new CFileItem("thumb://Current", false));
          current->SetThumbnailImage(pItem->GetPVRChannelInfoTag()->IconPath());
          current->SetLabel(g_localizeStrings.Get(20016));
          items.Add(current);
        }
        else if (pItem->HasThumbnail())
        { // already have a thumb that the share doesn't know about - must be a local one, so we mayaswell reuse it.
          CFileItemPtr current(new CFileItem("thumb://Current", false));
          current->SetThumbnailImage(pItem->GetThumbnailImage());
          current->SetLabel(g_localizeStrings.Get(20016));
          items.Add(current);
        }

        // and add a "no thumb" entry as well
        CFileItemPtr nothumb(new CFileItem("thumb://None", false));
        nothumb->SetIconImage(pItem->GetIconImage());
        nothumb->SetLabel(g_localizeStrings.Get(20018));
        items.Add(nothumb);

        CStdString strThumb;
        VECSOURCES shares;
        if (g_guiSettings.GetString("pvrmenu.iconpath") != "")
        {
          CMediaSource share1;
          share1.strPath = g_guiSettings.GetString("pvrmenu.iconpath");
          share1.strName = g_localizeStrings.Get(19018);
          shares.push_back(share1);
        }
        g_mediaManager.GetLocalDrives(shares);
        if (!CGUIDialogFileBrowser::ShowAndGetImage(items, shares, g_localizeStrings.Get(1030), strThumb))
          return false;

        if (strThumb == "thumb://Current")
          return true;

        if (strThumb == "thumb://None")
          strThumb = "";

        pItem->SetProperty("Icon", strThumb);
        pItem->SetProperty("Changed", true);
        m_bContainsChanges = true;
        return true;
      }
      else if (iControl == RADIOBUTTON_USEEPG)
      {
        CGUIRadioButtonControl *pRadioButton = (CGUIRadioButtonControl *)GetControl(RADIOBUTTON_USEEPG);
        if (pRadioButton)
        {
          CFileItemPtr pItem = m_channelItems->Get(m_iSelected);
          if (pItem)
          {
            pItem->SetProperty("Changed", true);
            pItem->SetProperty("UseEPG", pRadioButton->IsSelected());
            m_bContainsChanges = true;
          }
        }
      }
      else if (iControl == SPIN_EPGSOURCE_SELECTION)
      {
        /// TODO: Add EPG scraper support
        return true;
        CGUISpinControlEx *pSpin = (CGUISpinControlEx *)GetControl(SPIN_EPGSOURCE_SELECTION);
        if (pSpin)
        {
          CFileItemPtr pItem = m_channelItems->Get(m_iSelected);
          if (pItem)
          {
            pItem->SetProperty("EPGSource", (int)0);
            pItem->SetProperty("Changed", true);
            m_bContainsChanges = true;
            return true;
          }
        }
      }
      else if (iControl == BUTTON_GROUP_MANAGER)
      {
        /* Load group manager dialog */
        CGUIDialogPVRGroupManager* pDlgInfo = (CGUIDialogPVRGroupManager*)g_windowManager.GetWindow(WINDOW_DIALOG_PVR_GROUP_MANAGER);
        if (!pDlgInfo)
          return false;

        pDlgInfo->SetRadio(m_bIsRadio);

        /* Open dialog window */
        pDlgInfo->DoModal();

        return true;
      }
      else if (iControl == BUTTON_EDIT_CHANNEL)
      {
        CFileItemPtr pItem = m_channelItems->Get(m_iSelected);
        if (!pItem)
          return false;

        if (pItem->GetPropertyBOOL("Virtual"))
        {
          CStdString strURL = pItem->GetProperty("StreamURL");
          if (CGUIDialogKeyboard::ShowAndGetInput(strURL, g_localizeStrings.Get(19214), false))
            pItem->SetProperty("StreamURL", strURL);
          return true;
        }

        CGUIDialogOK::ShowAndGetInput(19033,19038,0,0);
        return true;
      }
      else if (iControl == BUTTON_DELETE_CHANNEL)
      {
        CFileItemPtr pItem = m_channelItems->Get(m_iSelected);
        if (!pItem)
          return false;

        // prompt user for confirmation of channel record
        CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
        if (!pDialog)
          return true;

        pDialog->SetHeading(19211);
        pDialog->SetLine(0, "");
        pDialog->SetLine(1, 750);
        pDialog->SetLine(2, "");
        pDialog->DoModal();

        if (pDialog->IsConfirmed())
        {
          if (pItem->GetPropertyBOOL("Virtual"))
          {
            CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase();
            database->Open();
            database->Delete(*pItem->GetPVRChannelInfoTag());
            database->Close();

            m_channelItems->Remove(m_iSelected);
            m_viewControl.SetItems(*m_channelItems);
            Renumber();
            return true;
          }
          CGUIDialogOK::ShowAndGetInput(19033,19038,0,0);
        }
        return true;
      }
      else if (iControl == BUTTON_NEW_CHANNEL)
      {
        std::vector<long> clients;

        CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
        if (!pDlgSelect)
          return false;

        pDlgSelect->SetHeading(19213); // Select Client
        pDlgSelect->Add(g_localizeStrings.Get(19209));
        clients.push_back(XBMC_VIRTUAL_CLIENTID);

        std::map<long, CStdString> clientMap;
        if (CPVRManager::GetClients()->GetClients(&clientMap) > 0)
        {
          std::map<long,CStdString>::iterator itr;
          for (itr = clientMap.begin() ; itr != clientMap.end(); itr++)
          {
            clients.push_back((*itr).first);
            pDlgSelect->Add(clientMap[(*itr).first]);
          }
        }
        pDlgSelect->DoModal();

        int selection = pDlgSelect->GetSelectedLabel();
        if (selection >= 0 && selection <= (int) clients.size())
        {
          int clientID = clients[selection];
          if (clientID == XBMC_VIRTUAL_CLIENTID)
          {
            CStdString strURL = "";
            if (CGUIDialogKeyboard::ShowAndGetInput(strURL, g_localizeStrings.Get(19214), false))
            {
              if (!strURL.IsEmpty())
              {
                CPVRChannel newchannel(m_bIsRadio);
                newchannel.SetChannelName(g_localizeStrings.Get(19204));
                newchannel.SetEPGEnabled(false);
                newchannel.SetVirtual(true);
                newchannel.SetStreamURL(strURL);
                newchannel.SetClientID(XBMC_VIRTUAL_CLIENTID);

                CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase();
                database->Open();
                database->Persist(newchannel);
                database->Close();
                CFileItemPtr channel(new CFileItem(newchannel));

                if (channel)
                {
                  channel->SetProperty("ActiveChannel", true);
                  channel->SetProperty("Name", g_localizeStrings.Get(19204));
                  channel->SetProperty("UseEPG", false);
                  channel->SetProperty("Icon", newchannel.IconPath());
                  channel->SetProperty("EPGSource", (int)0);
                  channel->SetProperty("ClientName", g_localizeStrings.Get(19209));

                  m_channelItems->AddFront(channel, m_iSelected);
                  m_viewControl.SetItems(*m_channelItems);
                  Renumber();
                }
              }
            }
          }
          else
          {
            CGUIDialogOK::ShowAndGetInput(19033,19038,0,0);
          }
        }
        return true;
      }
    }
    break;
  }

  return CGUIDialog::OnMessage(message);
}