xbmc
ProgressJob.h
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 
15 class CGUIDialogProgress;
17 
22 class CProgressJob : public CJob
23 {
24 public:
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 
35  bool DoModal();
36 
49  void SetProgressIndicators(CGUIDialogProgressBarHandle* progressBar, CGUIDialogProgress* progressDialog, bool updateProgress = true, bool updateInformation = true);
50 
51  bool HasProgressIndicator() const;
52 
53 protected:
54  CProgressJob();
55  explicit CProgressJob(CGUIDialogProgressBarHandle* progressBar);
56 
60  bool IsModal() const { return m_modal; }
61 
65  CGUIDialogProgressBarHandle* GetProgressBar() const { return m_progress; }
66 
70  void SetProgressBar(CGUIDialogProgressBarHandle* progress) { m_progress = progress; }
71 
75  CGUIDialogProgress* GetProgressDialog() const { return m_progressDialog; }
76 
80  void SetProgressDialog(CGUIDialogProgress* progressDialog) { m_progressDialog = progressDialog; }
81 
85  bool GetAutoClose() { return m_autoClose; }
86 
90  void SetAutoClose(bool autoClose) { m_autoClose = autoClose; }
91 
95  bool GetUpdateProgress() { return m_updateProgress; }
96 
100  void SetUpdateProgress(bool updateProgress) { m_updateProgress = updateProgress; }
101 
105  bool GetUpdateInformation() { return m_updateInformation; }
106 
110  void SetUpdateInformation(bool updateInformation) { m_updateInformation = updateInformation; }
111 
115  void ShowProgressDialog() const;
116 
122  void SetTitle(const std::string &title);
123 
129  void SetText(const std::string &text);
130 
136  void SetProgress(float percentage) const;
137 
144  void SetProgress(int currentStep, int totalSteps) const;
145 
149  void MarkFinished();
150 
154  bool IsCancelled() const;
155 
156 private:
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 };
bool GetUpdateInformation()
Whether to update the progress information or not.
Definition: ProgressJob.h:105
CGUIDialogProgressBarHandle * GetProgressBar() const
Returns the progress bar indicating the progress of the job.
Definition: ProgressJob.h:65
Base class for jobs that are executed asynchronously.
Definition: Job.h:109
bool IsModal() const
Whether the job is being run modally or in the background.
Definition: ProgressJob.h:60
bool GetUpdateProgress()
Whether to update the progress bar or not.
Definition: ProgressJob.h:95
void SetUpdateProgress(bool updateProgress)
Set whether to update the progress bar or not.
Definition: ProgressJob.h:100
bool DoModal()
Executes the job showing a modal progress dialog.
Definition: ProgressJob.cpp:48
bool IsCancelled() const
Checks if the progress dialog has been cancelled.
Definition: ProgressJob.cpp:174
void SetAutoClose(bool autoClose)
Set whether to automatically close the progress indicator in MarkFinished().
Definition: ProgressJob.h:90
bool GetAutoClose()
Whether to automatically close the progress indicator in MarkFinished().
Definition: ProgressJob.h:85
CGUIDialogProgress * GetProgressDialog() const
Returns the progress dialog indicating the progress of the job.
Definition: ProgressJob.h:75
void SetUpdateInformation(bool updateInformation)
Set whether to update the progress information or not.
Definition: ProgressJob.h:110
void SetProgressIndicators(CGUIDialogProgressBarHandle *progressBar, CGUIDialogProgress *progressDialog, bool updateProgress=true, bool updateInformation=true)
Sets the given progress indicators to be used during execution of the job.
Definition: ProgressJob.cpp:73
bool ShouldCancel(unsigned int progress, unsigned int total) const override
Function for longer jobs to report progress and check whether they have been cancelled.
Definition: ProgressJob.cpp:38
void SetTitle(const std::string &title)
Sets the given title as the title of the progress bar.
Definition: ProgressJob.cpp:95
void SetText(const std::string &text)
Sets the given text as the description of the progress bar.
Definition: ProgressJob.cpp:110
Definition: GUIDialogExtendedProgressBar.h:16
void SetProgressBar(CGUIDialogProgressBarHandle *progress)
Sets the progress bar indicating the progress of the job.
Definition: ProgressJob.h:70
Definition: GUIDialogProgress.h:16
void SetProgress(float percentage) const
Sets the progress of the progress bar to the given value in percentage.
Definition: ProgressJob.cpp:125
void SetProgressDialog(CGUIDialogProgress *progressDialog)
Sets the progress bar indicating the progress of the job.
Definition: ProgressJob.h:80
void MarkFinished()
Marks the progress as finished by setting it to 100%.
Definition: ProgressJob.cpp:158
const char * GetType() const override
Function that returns the type of job.
Definition: ProgressJob.h:28
void ShowProgressDialog() const
Makes sure that the modal dialog is being shown.
Definition: ProgressJob.cpp:84
Basic implementation of a CJob with a progress bar to indicate the progress of the job being processe...
Definition: ProgressJob.h:22