Kodi Development  20.0
for Binary and Script based Add-Ons
Progress.h
1 /*
2  * Copyright (C) 2005-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 "../../AddonBase.h"
12 #include "../../c-api/gui/dialogs/progress.h"
13 
14 #ifdef __cplusplus
15 
16 namespace kodi
17 {
18 namespace gui
19 {
20 namespace dialogs
21 {
22 
23 //==============================================================================
52 class ATTRIBUTE_HIDDEN CProgress
53 {
54 public:
55  //============================================================================
60  {
61  using namespace ::kodi::addon;
62  m_DialogHandle = CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->new_dialog(
63  CAddonBase::m_interface->toKodi->kodiBase);
64  if (!m_DialogHandle)
66  "kodi::gui::dialogs::CProgress can't create window class from Kodi !!!");
67  }
68  //----------------------------------------------------------------------------
69 
70  //============================================================================
75  {
76  using namespace ::kodi::addon;
77  if (m_DialogHandle)
78  CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->delete_dialog(
79  CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle);
80  }
81  //----------------------------------------------------------------------------
82 
83  //============================================================================
87  void Open()
88  {
89  using namespace ::kodi::addon;
90  CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->open(
91  CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle);
92  }
93  //----------------------------------------------------------------------------
94 
95  //============================================================================
101  void SetHeading(const std::string& heading)
102  {
103  using namespace ::kodi::addon;
104  CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->set_heading(
105  CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, heading.c_str());
106  }
107  //----------------------------------------------------------------------------
108 
109  //============================================================================
116  void SetLine(unsigned int iLine, const std::string& line)
117  {
118  using namespace ::kodi::addon;
119  CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->set_line(
120  CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, iLine, line.c_str());
121  }
122  //----------------------------------------------------------------------------
123 
124  //============================================================================
130  void SetCanCancel(bool canCancel)
131  {
132  using namespace ::kodi::addon;
133  CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->set_can_cancel(
134  CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, canCancel);
135  }
136  //----------------------------------------------------------------------------
137 
138  //============================================================================
144  bool IsCanceled() const
145  {
146  using namespace ::kodi::addon;
147  return CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->is_canceled(
148  CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle);
149  }
150  //----------------------------------------------------------------------------
151 
152  //============================================================================
158  void SetPercentage(int percentage)
159  {
160  using namespace ::kodi::addon;
161  CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->set_percentage(
162  CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, percentage);
163  }
164  //----------------------------------------------------------------------------
165 
166  //============================================================================
172  int GetPercentage() const
173  {
174  using namespace ::kodi::addon;
175  return CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->get_percentage(
176  CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle);
177  }
178  //----------------------------------------------------------------------------
179 
180  //============================================================================
186  void ShowProgressBar(bool onOff)
187  {
188  using namespace ::kodi::addon;
189  CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->show_progress_bar(
190  CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, onOff);
191  }
192  //----------------------------------------------------------------------------
193 
194  //============================================================================
200  void SetProgressMax(int max)
201  {
202  using namespace ::kodi::addon;
203  CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->set_progress_max(
204  CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, max);
205  }
206  //----------------------------------------------------------------------------
207 
208  //============================================================================
214  void SetProgressAdvance(int steps = 1)
215  {
216  using namespace ::kodi::addon;
217  CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->set_progress_advance(
218  CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle, steps);
219  }
220  //----------------------------------------------------------------------------
221 
222  //============================================================================
228  bool Abort()
229  {
230  using namespace ::kodi::addon;
231  return CAddonBase::m_interface->toKodi->kodi_gui->dialogProgress->abort(
232  CAddonBase::m_interface->toKodi->kodiBase, m_DialogHandle);
233  }
234  //----------------------------------------------------------------------------
235 
236 private:
237  KODI_GUI_HANDLE m_DialogHandle;
238 };
239 
240 } /* namespace dialogs */
241 } /* namespace gui */
242 } /* namespace kodi */
243 
244 #endif /* __cplusplus */
Definition: Progress.h:53
@ ADDON_LOG_FATAL
4 : To notify fatal unrecoverable errors, which can may also indicate upcoming crashes.
Definition: addon_base.h:187
void SetPercentage(int percentage)
Get the current progress position as percent.
Definition: Progress.h:158
void SetCanCancel(bool canCancel)
To enable and show cancel button on dialog.
Definition: Progress.h:130
void ShowProgressBar(bool onOff)
To show or hide progress bar dialog.
Definition: Progress.h:186
void Open()
To open the dialog.
Definition: Progress.h:87
bool Abort()
To check progress was canceled on work.
Definition: Progress.h:228
void SetLine(unsigned int iLine, const std::string &line)
To set the line text field on dialog from 0 - 2.
Definition: Progress.h:116
int GetPercentage() const
To set the current progress position as percent.
Definition: Progress.h:172
void SetProgressMax(int max)
Set the maximum position of progress, needed if SetProgressAdvance(...) is used.
Definition: Progress.h:200
~CProgress()
Destructor.
Definition: Progress.h:74
bool IsCanceled() const
To check dialog for clicked cancel button.
Definition: Progress.h:144
void SetProgressAdvance(int steps=1)
To increase progress bar by defined step size until reach of maximum position.
Definition: Progress.h:214
CProgress()
Construct a new dialog.
Definition: Progress.h:59
void SetHeading(const std::string &heading)
Set the heading title of dialog.
Definition: Progress.h:101
void ATTRIBUTE_HIDDEN Log(const AddonLog loglevel, const char *format,...)
Add a message to Kodi's log.
Definition: AddonBase.h:749