2 * Copyright (C) 2005-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.
9 #include "GUIDialogSeekBar.h"
11 #include "GUIInfoManager.h"
12 #include "SeekHandler.h"
13 #include "application/ApplicationComponents.h"
14 #include "application/ApplicationPlayer.h"
15 #include "guilib/GUIComponent.h"
16 #include "guilib/GUIMessage.h"
17 #include "guilib/guiinfo/GUIInfoLabels.h"
21 #define POPUP_SEEK_PROGRESS 401
22 #define POPUP_SEEK_EPG_EVENT_PROGRESS 402
23 #define POPUP_SEEK_TIMESHIFT_PROGRESS 403
25 CGUIDialogSeekBar::CGUIDialogSeekBar(void)
26 : CGUIDialog(WINDOW_DIALOG_SEEK_BAR
, "DialogSeekBar.xml", DialogModalityType::MODELESS
)
28 m_loadType
= LOAD_ON_GUI_INIT
; // the application class handles our resources
31 CGUIDialogSeekBar::~CGUIDialogSeekBar(void) = default;
33 bool CGUIDialogSeekBar::OnMessage(CGUIMessage
& message
)
35 switch (message
.GetMessage())
37 case GUI_MSG_WINDOW_INIT
:
38 case GUI_MSG_WINDOW_DEINIT
:
39 return CGUIDialog::OnMessage(message
);
40 case GUI_MSG_ITEM_SELECT
:
41 if (message
.GetSenderId() == GetID() &&
42 (message
.GetControlId() == POPUP_SEEK_PROGRESS
||
43 message
.GetControlId() == POPUP_SEEK_EPG_EVENT_PROGRESS
||
44 message
.GetControlId() == POPUP_SEEK_TIMESHIFT_PROGRESS
))
45 return CGUIDialog::OnMessage(message
);
47 case GUI_MSG_REFRESH_TIMER
:
48 return CGUIDialog::OnMessage(message
);
50 return false; // don't process anything other than what we need!
53 void CGUIDialogSeekBar::FrameMove()
55 const auto& components
= CServiceBroker::GetAppComponents();
56 const auto appPlayer
= components
.GetComponent
<CApplicationPlayer
>();
57 if (!appPlayer
->HasPlayer())
63 int progress
= GetProgress();
64 if (progress
!= m_lastProgress
)
65 CONTROL_SELECT_ITEM(POPUP_SEEK_PROGRESS
, m_lastProgress
= progress
);
67 int epgEventProgress
= GetEpgEventProgress();
68 if (epgEventProgress
!= m_lastEpgEventProgress
)
69 CONTROL_SELECT_ITEM(POPUP_SEEK_EPG_EVENT_PROGRESS
, m_lastEpgEventProgress
= epgEventProgress
);
71 int timeshiftProgress
= GetTimeshiftProgress();
72 if (timeshiftProgress
!= m_lastTimeshiftProgress
)
73 CONTROL_SELECT_ITEM(POPUP_SEEK_TIMESHIFT_PROGRESS
, m_lastTimeshiftProgress
= timeshiftProgress
);
75 CGUIDialog::FrameMove();
78 int CGUIDialogSeekBar::GetProgress() const
80 const CGUIInfoManager
& infoMgr
= CServiceBroker::GetGUI()->GetInfoManager();
84 const auto& components
= CServiceBroker::GetAppComponents();
85 const auto appPlayer
= components
.GetComponent
<CApplicationPlayer
>();
86 if (appPlayer
->GetSeekHandler().GetSeekSize() != 0)
87 infoMgr
.GetInt(progress
, PLAYER_SEEKBAR
, INFO::DEFAULT_CONTEXT
);
89 infoMgr
.GetInt(progress
, PLAYER_PROGRESS
, INFO::DEFAULT_CONTEXT
);
94 int CGUIDialogSeekBar::GetEpgEventProgress() const
96 CGUIInfoManager
& infoMgr
= CServiceBroker::GetGUI()->GetInfoManager();
99 infoMgr
.GetInt(progress
, PVR_EPG_EVENT_PROGRESS
, INFO::DEFAULT_CONTEXT
);
101 const auto& components
= CServiceBroker::GetAppComponents();
102 const auto appPlayer
= components
.GetComponent
<CApplicationPlayer
>();
103 int seekSize
= appPlayer
->GetSeekHandler().GetSeekSize();
107 infoMgr
.GetInt(total
, PVR_EPG_EVENT_DURATION
, INFO::DEFAULT_CONTEXT
);
109 float totalTime
= static_cast<float>(total
);
110 if (totalTime
== 0.0f
)
113 float percentPerSecond
= 100.0f
/ totalTime
;
114 float percent
= progress
+ percentPerSecond
* seekSize
;
115 percent
= std::max(0.0f
, std::min(percent
, 100.0f
));
116 return std::lrintf(percent
);
122 int CGUIDialogSeekBar::GetTimeshiftProgress() const
124 const CGUIInfoManager
& infoMgr
= CServiceBroker::GetGUI()->GetInfoManager();
127 infoMgr
.GetInt(progress
, PVR_TIMESHIFT_SEEKBAR
, INFO::DEFAULT_CONTEXT
);