1 /*
2  *  Copyright (C) 2017-2018 Team Kodi
3  *  This file is part of Kodi - https://kodi.tv
4  *
5  *  SPDX-License-Identifier: GPL-2.0-or-later
6  *  See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "threads/CriticalSection.h"
12 #include "threads/Thread.h"
13 
14 #include <string>
15 
16 namespace PVR
17 {
18   class CPVRGUIProgressHandler : private CThread
19   {
20   public:
21     CPVRGUIProgressHandler() = delete;
22 
23     /*!
24      * @brief Creates and asynchronously shows a progress dialog with the given title.
25      * @param strTitle The title for the progress dialog.
26      */
27     explicit CPVRGUIProgressHandler(const std::string& strTitle);
28 
29     /*!
30      * @brief Update the progress dialogs's content.
31      * @param strText The new progress text.
32      * @param fProgress The new progress value, in a range from 0.0 to 100.0.
33      */
34     void UpdateProgress(const std::string& strText, float fProgress);
35 
36     /*!
37      * @brief Update the progress dialogs's content.
38      * @param strText The new progress text.
39      * @param iCurrent The new current progress value, must be less or equal iMax.
40      * @param iMax The new maximum progress value, must be greater or equal iCurrent.
41      */
42     void UpdateProgress(const std::string& strText, int iCurrent, int iMax);
43 
44     /*!
45      * @brief Destroy the progress dialog. This happens asynchrounous, instance must not be touched anymore after calling this method.
46      */
47     void DestroyProgress();
48 
49     // CThread implementation
50     void Process() override;
51 
52   private:
53     ~CPVRGUIProgressHandler() override = default; // prevent creation of stack instances
54 
55     CCriticalSection m_critSection;
56     const std::string m_strTitle;
57     std::string m_strText;
58     float m_fProgress;
59     bool m_bChanged;
60   };
61 
62 } // namespace PVR
63