summaryrefslogtreecommitdiffstats
path: root/xbmc/dialogs/GUIDialogProgress.h
blob: ba8426901355bfc993624a5a8271d713bb1a526e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
 *  Copyright (C) 2005-2018 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#pragma once

#include "GUIDialogBoxBase.h"
#include "IProgressCallback.h"

#include <array>

class CGUIDialogProgress :
      public CGUIDialogBoxBase, public IProgressCallback
{
public:
  CGUIDialogProgress(void);
  ~CGUIDialogProgress(void) override;

  void Reset();
  void Open(const std::string &param = "");
  bool OnMessage(CGUIMessage& message) override;
  bool OnBack(int actionID) override;
  void OnWindowLoaded() override;
  void Progress();
  bool IsCanceled() const { return m_iChoice == CHOICE_CANCELED; }
  void SetPercentage(int iPercentage);
  int GetPercentage() const { return m_percentage; }
  void ShowProgressBar(bool bOnOff);

  void ShowChoice(int iChoice, const CVariant& label);

  static constexpr int CHOICE_NONE = -2;
  static constexpr int CHOICE_CANCELED = -1;
  int GetChoice() const;

  /*! \brief Wait for the progress dialog to be closed or canceled, while regularly
   rendering to allow for pointer movement or progress to be shown. Used when showing
   the progress of a process that is taking place on a separate thread and may be
   reporting progress infrequently.
   \param progresstime the time in ms to wait between rendering the dialog (defaults to 10ms)
   \return true if the dialog is closed, false if the user cancels early.
   */
  bool Wait(int progresstime = 10);

  /*! \brief Wait on an event or for the progress dialog to be canceled, while
  regularly rendering to allow for pointer movement or progress to be shown.
  \param event the CEvent to wait on.
  \return true if the event completed, false if cancelled.
  */
  bool WaitOnEvent(CEvent& event);

  // Implements IProgressCallback
  void SetProgressMax(int iMax) override;
  void SetProgressAdvance(int nSteps=1) override;
  bool Abort() override;

  void SetCanCancel(bool bCanCancel);

protected:
  void OnInitWindow() override;
  int GetDefaultLabelID(int controlId) const override;
  void Process(unsigned int currentTime, CDirtyRegionList &dirtyregions) override;

  bool m_bCanCancel;

  int  m_iCurrent;
  int  m_iMax;
  int m_percentage;
  bool m_showProgress;

  std::array<bool, DIALOG_MAX_CHOICES> m_supportedChoices = {};
  int m_iChoice = CHOICE_NONE;

private:
  void UpdateControls();
};