2 * Copyright (C) 2017-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
9 #include "PVRGUIProgressHandler.h"
11 #include "ServiceBroker.h"
12 #include "dialogs/GUIDialogExtendedProgressBar.h"
13 #include "guilib/GUIComponent.h"
14 #include "guilib/GUIWindowManager.h"
15 #include "guilib/WindowIDs.h"
22 using namespace std::chrono_literals
;
27 CPVRGUIProgressHandler::CPVRGUIProgressHandler(const std::string
& strTitle
)
28 : CThread("PVRGUIProgressHandler"), m_strTitle(strTitle
)
32 void CPVRGUIProgressHandler::UpdateProgress(const std::string
& strText
, float fProgress
)
34 std::unique_lock
<CCriticalSection
> lock(m_critSection
);
37 m_fProgress
= fProgress
;
46 void CPVRGUIProgressHandler::UpdateProgress(const std::string
& strText
, int iCurrent
, int iMax
)
48 float fPercentage
= (iCurrent
* 100.0f
) / iMax
;
49 if (!std::isnan(fPercentage
))
50 fPercentage
= std::min(100.0f
, fPercentage
);
52 UpdateProgress(strText
, fPercentage
);
55 void CPVRGUIProgressHandler::Process()
57 CGUIDialogExtendedProgressBar
* progressBar
=
58 CServiceBroker::GetGUI()->GetWindowManager().GetWindow
<CGUIDialogExtendedProgressBar
>(
59 WINDOW_DIALOG_EXT_PROGRESS
);
60 if (m_bStop
|| !progressBar
)
63 CGUIDialogProgressBarHandle
* progressHandle
= progressBar
->GetHandle(m_strTitle
);
69 float fProgress
= 0.0;
74 std::unique_lock
<CCriticalSection
> lock(m_critSection
);
78 fProgress
= m_fProgress
;
86 progressHandle
->SetPercentage(fProgress
);
87 progressHandle
->SetText(strText
);
90 // Intentionally ignore some changes that come in too fast. Humans cannot read as fast as Mr. Data ;-)
91 CThread::Sleep(100ms
);
94 progressHandle
->MarkFinished();