summaryrefslogtreecommitdiffstats
path: root/xbmc/utils/ProgressJob.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
committermanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
commitbe933ef2241d79558f91796cc5b3a161f72ebf9c (patch)
treefe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/utils/ProgressJob.h
parent5f8335c1e49ce108ef3481863833c98efa00411b (diff)
downloadkodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip
sync with upstream
Diffstat (limited to 'xbmc/utils/ProgressJob.h')
-rw-r--r--xbmc/utils/ProgressJob.h163
1 files changed, 163 insertions, 0 deletions
diff --git a/xbmc/utils/ProgressJob.h b/xbmc/utils/ProgressJob.h
new file mode 100644
index 0000000..f1117aa
--- /dev/null
+++ b/xbmc/utils/ProgressJob.h
@@ -0,0 +1,163 @@
1/*
2 * Copyright (C) 2015-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 "utils/Job.h"
12
13#include <string>
14
15class CGUIDialogProgress;
16class CGUIDialogProgressBarHandle;
17
18/*!
19 \brief Basic implementation of a CJob with a progress bar to indicate the
20 progress of the job being processed.
21 */
22class CProgressJob : public CJob
23{
24public:
25 ~CProgressJob() override;
26
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;
31
32 /*!
33 \brief Executes the job showing a modal progress dialog.
34 */
35 bool DoModal();
36
37 /*!
38 \brief Sets the given progress indicators to be used during execution of
39 the job.
40
41 \details This automatically disables auto-closing the given progress
42 indicators once the job has been finished.
43
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.
48 */
49 void SetProgressIndicators(CGUIDialogProgressBarHandle* progressBar, CGUIDialogProgress* progressDialog, bool updateProgress = true, bool updateInformation = true);
50
51 bool HasProgressIndicator() const;
52
53protected:
54 CProgressJob();
55 explicit CProgressJob(CGUIDialogProgressBarHandle* progressBar);
56
57 /*!
58 \brief Whether the job is being run modally or in the background.
59 */
60 bool IsModal() const { return m_modal; }
61
62 /*!
63 \brief Returns the progress bar indicating the progress of the job.
64 */
65 CGUIDialogProgressBarHandle* GetProgressBar() const { return m_progress; }
66
67 /*!
68 \brief Sets the progress bar indicating the progress of the job.
69 */
70 void SetProgressBar(CGUIDialogProgressBarHandle* progress) { m_progress = progress; }
71
72 /*!
73 \brief Returns the progress dialog indicating the progress of the job.
74 */
75 CGUIDialogProgress* GetProgressDialog() const { return m_progressDialog; }
76
77 /*!
78 \brief Sets the progress bar indicating the progress of the job.
79 */
80 void SetProgressDialog(CGUIDialogProgress* progressDialog) { m_progressDialog = progressDialog; }
81
82 /*!
83 \brief Whether to automatically close the progress indicator in MarkFinished().
84 */
85 bool GetAutoClose() { return m_autoClose; }
86
87 /*!
88 \brief Set whether to automatically close the progress indicator in MarkFinished().
89 */
90 void SetAutoClose(bool autoClose) { m_autoClose = autoClose; }
91
92 /*!
93 \brief Whether to update the progress bar or not.
94 */
95 bool GetUpdateProgress() { return m_updateProgress; }
96
97 /*!
98 \brief Set whether to update the progress bar or not.
99 */
100 void SetUpdateProgress(bool updateProgress) { m_updateProgress = updateProgress; }
101
102 /*!
103 \brief Whether to update the progress information or not.
104 */
105 bool GetUpdateInformation() { return m_updateInformation; }
106
107 /*!
108 \brief Set whether to update the progress information or not.
109 */
110 void SetUpdateInformation(bool updateInformation) { m_updateInformation = updateInformation; }
111
112 /*!
113 \brief Makes sure that the modal dialog is being shown.
114 */
115 void ShowProgressDialog() const;
116
117 /*!
118 \brief Sets the given title as the title of the progress bar.
119
120 \param[in] title Title to be set
121 */
122 void SetTitle(const std::string &title);
123
124 /*!
125 \brief Sets the given text as the description of the progress bar.
126
127 \param[in] text Text to be set
128 */
129 void SetText(const std::string &text);
130
131 /*!
132 \brief Sets the progress of the progress bar to the given value in percentage.
133
134 \param[in] percentage Percentage to be set as the current progress
135 */
136 void SetProgress(float percentage) const;
137
138 /*!
139 \brief Sets the progress of the progress bar to the given value.
140
141 \param[in] currentStep Current step being processed
142 \param[in] totalSteps Total steps to be processed
143 */
144 void SetProgress(int currentStep, int totalSteps) const;
145
146 /*!
147 \brief Marks the progress as finished by setting it to 100%.
148 */
149 void MarkFinished();
150
151 /*!
152 \brief Checks if the progress dialog has been cancelled.
153 */
154 bool IsCancelled() const;
155
156private:
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;
163};