Merge pull request #26350 from jjd-uk/estuary_media_align
[xbmc.git] / xbmc / dialogs / GUIDialogPlayEject.cpp
blob14ee2bc0d35185434783aab79acd8c87c8be5129
1 /*
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.
7 */
9 #include "GUIDialogPlayEject.h"
11 #include "ServiceBroker.h"
12 #include "guilib/GUIComponent.h"
13 #include "guilib/GUIWindowManager.h"
14 #include "storage/MediaManager.h"
15 #include "utils/Variant.h"
17 #include <utility>
19 #define ID_BUTTON_PLAY 11
20 #define ID_BUTTON_EJECT 10
22 CGUIDialogPlayEject::CGUIDialogPlayEject()
23 : CGUIDialogYesNo(WINDOW_DIALOG_PLAY_EJECT)
27 CGUIDialogPlayEject::~CGUIDialogPlayEject() = default;
29 bool CGUIDialogPlayEject::OnMessage(CGUIMessage& message)
31 if (message.GetMessage() == GUI_MSG_CLICKED)
33 int iControl = message.GetSenderId();
34 if (iControl == ID_BUTTON_PLAY)
36 if (CServiceBroker::GetMediaManager().IsDiscInDrive())
38 m_bConfirmed = true;
39 Close();
42 return true;
44 if (iControl == ID_BUTTON_EJECT)
46 CServiceBroker::GetMediaManager().ToggleTray();
47 return true;
51 return CGUIDialogYesNo::OnMessage(message);
54 void CGUIDialogPlayEject::FrameMove()
56 CONTROL_ENABLE_ON_CONDITION(ID_BUTTON_PLAY, CServiceBroker::GetMediaManager().IsDiscInDrive());
58 CGUIDialogYesNo::FrameMove();
61 void CGUIDialogPlayEject::OnInitWindow()
63 if (CServiceBroker::GetMediaManager().IsDiscInDrive())
65 m_defaultControl = ID_BUTTON_PLAY;
67 else
69 CONTROL_DISABLE(ID_BUTTON_PLAY);
70 m_defaultControl = ID_BUTTON_EJECT;
73 CGUIDialogYesNo::OnInitWindow();
76 bool CGUIDialogPlayEject::ShowAndGetInput(const std::string& strLine1,
77 const std::string& strLine2,
78 unsigned int uiAutoCloseTime /* = 0 */)
81 // Create the dialog
82 CGUIDialogPlayEject * pDialog = (CGUIDialogPlayEject *)CServiceBroker::GetGUI()->GetWindowManager().
83 GetWindow(WINDOW_DIALOG_PLAY_EJECT);
84 if (!pDialog)
85 return false;
87 // Setup dialog parameters
88 pDialog->SetHeading(CVariant{219});
89 pDialog->SetLine(0, CVariant{429});
90 pDialog->SetLine(1, CVariant{strLine1});
91 pDialog->SetLine(2, CVariant{strLine2});
92 pDialog->SetChoice(ID_BUTTON_PLAY - 10, 208);
93 pDialog->SetChoice(ID_BUTTON_EJECT - 10, 13391);
94 if (uiAutoCloseTime)
95 pDialog->SetAutoClose(uiAutoCloseTime);
97 // Display the dialog
98 pDialog->Open();
100 return pDialog->IsConfirmed();