2 * Copyright (C) 2015-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.
11 #include "utils/Job.h"
15 class CGUIDialogProgress
;
16 class CGUIDialogProgressBarHandle
;
19 \brief Basic implementation of a CJob with a progress bar to indicate the
20 progress of the job being processed.
22 class CProgressJob
: public CJob
25 ~CProgressJob() override
;
27 // implementation of CJob
28 const char *GetType() const override
{ return "ProgressJob"; }
29 bool operator==(const CJob
* job
) const override
{ return false; }
30 bool ShouldCancel(unsigned int progress
, unsigned int total
) const override
;
33 \brief Executes the job showing a modal progress dialog.
38 \brief Sets the given progress indicators to be used during execution of
41 \details This automatically disables auto-closing the given progress
42 indicators once the job has been finished.
44 \param progressBar Progress bar handle to be used.
45 \param progressDialog Progress dialog to be used.
46 \param updateProgress (optional) Whether to show progress updates.
47 \param updateInformation (optional) Whether to show progress information.
49 void SetProgressIndicators(CGUIDialogProgressBarHandle
* progressBar
, CGUIDialogProgress
* progressDialog
, bool updateProgress
= true, bool updateInformation
= true);
51 bool HasProgressIndicator() const;
55 explicit CProgressJob(CGUIDialogProgressBarHandle
* progressBar
);
58 \brief Whether the job is being run modally or in the background.
60 bool IsModal() const { return m_modal
; }
63 \brief Returns the progress bar indicating the progress of the job.
65 CGUIDialogProgressBarHandle
* GetProgressBar() const { return m_progress
; }
68 \brief Sets the progress bar indicating the progress of the job.
70 void SetProgressBar(CGUIDialogProgressBarHandle
* progress
) { m_progress
= progress
; }
73 \brief Returns the progress dialog indicating the progress of the job.
75 CGUIDialogProgress
* GetProgressDialog() const { return m_progressDialog
; }
78 \brief Sets the progress bar indicating the progress of the job.
80 void SetProgressDialog(CGUIDialogProgress
* progressDialog
) { m_progressDialog
= progressDialog
; }
83 \brief Whether to automatically close the progress indicator in MarkFinished().
85 bool GetAutoClose() { return m_autoClose
; }
88 \brief Set whether to automatically close the progress indicator in MarkFinished().
90 void SetAutoClose(bool autoClose
) { m_autoClose
= autoClose
; }
93 \brief Whether to update the progress bar or not.
95 bool GetUpdateProgress() { return m_updateProgress
; }
98 \brief Set whether to update the progress bar or not.
100 void SetUpdateProgress(bool updateProgress
) { m_updateProgress
= updateProgress
; }
103 \brief Whether to update the progress information or not.
105 bool GetUpdateInformation() { return m_updateInformation
; }
108 \brief Set whether to update the progress information or not.
110 void SetUpdateInformation(bool updateInformation
) { m_updateInformation
= updateInformation
; }
113 \brief Makes sure that the modal dialog is being shown.
115 void ShowProgressDialog() const;
118 \brief Sets the given title as the title of the progress bar.
120 \param[in] title Title to be set
122 void SetTitle(const std::string
&title
);
125 \brief Sets the given text as the description of the progress bar.
127 \param[in] text Text to be set
129 void SetText(const std::string
&text
);
132 \brief Sets the progress of the progress bar to the given value in percentage.
134 \param[in] percentage Percentage to be set as the current progress
136 void SetProgress(float percentage
) const;
139 \brief Sets the progress of the progress bar to the given value.
141 \param[in] currentStep Current step being processed
142 \param[in] totalSteps Total steps to be processed
144 void SetProgress(int currentStep
, int totalSteps
) const;
147 \brief Marks the progress as finished by setting it to 100%.
152 \brief Checks if the progress dialog has been cancelled.
154 bool IsCancelled() const;
157 bool m_modal
= false;
158 bool m_autoClose
= true;
159 bool m_updateProgress
= true;
160 bool m_updateInformation
= true;
161 mutable CGUIDialogProgressBarHandle
* m_progress
;
162 mutable CGUIDialogProgress
* m_progressDialog
;