Skip to content

Commit

Permalink
Cleanup CPVRGUIProgressHandler: Get rid of some unneeded narrowing ca…
Browse files Browse the repository at this point in the history
…sts.
  • Loading branch information
ksooo committed Dec 18, 2024
1 parent a1da2d0 commit f93f5ea
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
12 changes: 5 additions & 7 deletions xbmc/pvr/addons/PVRClients.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,11 @@ void CPVRClients::UpdateClients(
auto progressHandler = std::make_unique<CPVRGUIProgressHandler>(
g_localizeStrings.Get(19239)); // Creating PVR clients

unsigned int i = 0;
size_t i = 0;
for (const auto& client : clientsToCreate)
{
progressHandler->UpdateProgress(
client->Name(), i++,
static_cast<unsigned int>(clientsToCreate.size() + clientsToReCreate.size()));
progressHandler->UpdateProgress(client->Name(), i++,
clientsToCreate.size() + clientsToReCreate.size());

const ADDON_STATUS status = client->Create();

Expand All @@ -192,9 +191,8 @@ void CPVRClients::UpdateClients(

for (const auto& clientInfo : clientsToReCreate)
{
progressHandler->UpdateProgress(
clientInfo.second, i++,
static_cast<unsigned int>(clientsToCreate.size() + clientsToReCreate.size()));
progressHandler->UpdateProgress(clientInfo.second, i++,
clientsToCreate.size() + clientsToReCreate.size());

// stop and recreate client
StopClient(clientInfo.first, true /* restart */);
Expand Down
6 changes: 3 additions & 3 deletions xbmc/pvr/epg/EpgContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,6 @@ bool CPVREpgContainer::UpdateEPG(bool bOnlyPending /* = false */)

std::vector<std::shared_ptr<CPVREpg>> invalidTables;

unsigned int iCounter = 0;
const std::shared_ptr<CPVREpgDatabase> database = GetEpgDatabase();

m_critSection.lock();
Expand All @@ -745,6 +744,7 @@ bool CPVREpgContainer::UpdateEPG(bool bOnlyPending /* = false */)
progressHandler = std::make_unique<CPVRGUIProgressHandler>(
g_localizeStrings.Get(19004)); // Loading programme guide

size_t counter = 0;
for (const auto& epgEntry : epgsToUpdate)
{
if (InterruptUpdate())
Expand All @@ -758,8 +758,8 @@ bool CPVREpgContainer::UpdateEPG(bool bOnlyPending /* = false */)
continue;

if (progressHandler)
progressHandler->UpdateProgress(epg->GetChannelData()->ChannelName(), ++iCounter,
static_cast<unsigned int>(epgsToUpdate.size()));
progressHandler->UpdateProgress(epg->GetChannelData()->ChannelName(), ++counter,
epgsToUpdate.size());

if ((!bOnlyPending || epg->UpdatePending()) &&
epg->Update(start,
Expand Down
5 changes: 2 additions & 3 deletions xbmc/pvr/guilib/PVRGUIChannelIconUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,12 @@ void CPVRGUIChannelIconUpdater::SearchAndUpdateMissingChannelIcons() const
for (const auto& group : m_groups)
{
const std::vector<std::shared_ptr<CPVRChannelGroupMember>> members = group->GetMembers();
int channelIndex = 0;
size_t channelIndex = 0;
for (const auto& member : members)
{
const std::shared_ptr<CPVRChannel> channel = member->Channel();

progressHandler->UpdateProgress(channel->ChannelName(), channelIndex++,
static_cast<unsigned int>(members.size()));
progressHandler->UpdateProgress(channel->ChannelName(), channelIndex++, members.size());

// skip if an icon is already set and exists
if (CFileUtils::Exists(channel->IconPath()))
Expand Down
14 changes: 7 additions & 7 deletions xbmc/pvr/guilib/PVRGUIProgressHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ void CPVRGUIProgressHandler::UpdateProgress(const std::string& strText, float fP
}
}

void CPVRGUIProgressHandler::UpdateProgress(const std::string& strText,
unsigned int iCurrent,
unsigned int iMax)
void CPVRGUIProgressHandler::UpdateProgress(const std::string& text,
size_t currentValue,
size_t maxValue)
{
float fPercentage = (iCurrent * 100.0f) / iMax;
if (!std::isnan(fPercentage))
fPercentage = std::min(100.0f, fPercentage);
float percentage = (currentValue * 100.0f) / maxValue;
if (!std::isnan(percentage))
percentage = std::min(100.0f, percentage);

UpdateProgress(strText, fPercentage);
UpdateProgress(text, percentage);
}

void CPVRGUIProgressHandler::Process()
Expand Down
8 changes: 4 additions & 4 deletions xbmc/pvr/guilib/PVRGUIProgressHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ namespace PVR

/*!
* @brief Update the progress dialogs's content.
* @param strText The new progress text.
* @param iCurrent The new current progress value, must be less or equal iMax.
* @param iMax The new maximum progress value, must be greater or equal iCurrent.
* @param text The new progress text.
* @param currentValue The new current progress value, must be less or equal iMax.
* @param maxValue The new maximum progress value, must be greater or equal iCurrent.
*/
void UpdateProgress(const std::string& strText, unsigned int iCurrent, unsigned int iMax);
void UpdateProgress(const std::string& text, size_t currentValue, size_t maxValue);

protected:
// CThread implementation
Expand Down

0 comments on commit f93f5ea

Please sign in to comment.