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 "GUIDialogVolumeBar.h"
11 #include "IGUIVolumeBarCallback.h"
12 #include "application/ApplicationComponents.h"
13 #include "application/ApplicationVolumeHandling.h"
14 #include "guilib/GUIMessage.h"
15 #include "input/actions/Action.h"
16 #include "input/actions/ActionIDs.h"
20 #define VOLUME_BAR_DISPLAY_TIME 1000L
22 CGUIDialogVolumeBar::CGUIDialogVolumeBar(void)
23 : CGUIDialog(WINDOW_DIALOG_VOLUME_BAR
, "DialogVolumeBar.xml", DialogModalityType::MODELESS
)
25 m_loadType
= LOAD_ON_GUI_INIT
;
28 CGUIDialogVolumeBar::~CGUIDialogVolumeBar(void) = default;
30 bool CGUIDialogVolumeBar::OnAction(const CAction
&action
)
32 if (action
.GetID() == ACTION_VOLUME_UP
|| action
.GetID() == ACTION_VOLUME_DOWN
|| action
.GetID() == ACTION_VOLUME_SET
|| action
.GetID() == ACTION_MUTE
)
34 const auto& components
= CServiceBroker::GetAppComponents();
35 const auto appVolume
= components
.GetComponent
<CApplicationVolumeHandling
>();
36 if (appVolume
->IsMuted() ||
37 appVolume
->GetVolumeRatio() <= CApplicationVolumeHandling::VOLUME_MINIMUM
)
38 { // cancel the timer, dialog needs to stay visible
42 { // reset the timer, as we've changed the volume level
43 SetAutoClose(VOLUME_BAR_DISPLAY_TIME
);
48 return CGUIDialog::OnAction(action
);
51 bool CGUIDialogVolumeBar::OnMessage(CGUIMessage
& message
)
53 switch (message
.GetMessage())
55 case GUI_MSG_WINDOW_INIT
:
56 case GUI_MSG_WINDOW_DEINIT
:
57 return CGUIDialog::OnMessage(message
);
59 return false; // don't process anything other than what we need!
62 void CGUIDialogVolumeBar::RegisterCallback(IGUIVolumeBarCallback
*callback
)
64 std::unique_lock
<CCriticalSection
> lock(m_callbackMutex
);
66 m_callbacks
.insert(callback
);
69 void CGUIDialogVolumeBar::UnregisterCallback(IGUIVolumeBarCallback
*callback
)
71 std::unique_lock
<CCriticalSection
> lock(m_callbackMutex
);
73 m_callbacks
.erase(callback
);
76 bool CGUIDialogVolumeBar::IsVolumeBarEnabled() const
78 std::unique_lock
<CCriticalSection
> lock(m_callbackMutex
);
80 // Hide volume bar if any callbacks are shown
81 for (const auto &callback
: m_callbacks
)
83 if (callback
->IsShown())