Merge pull request #4594 from FernetMenta/paplayer
[xbmc.git] / xbmc / dialogs / GUIDialogPlayEject.cpp
bloba7e49d157c52bd9a815f994bc3a4e6cb92c6c783
1 /*
2 * Copyright (C) 2005-2013 Team XBMC
3 * http://xbmc.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * any later version.
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "Autorun.h"
22 #include "GUIDialogPlayEject.h"
23 #include "guilib/GUIWindowManager.h"
24 #include "storage/MediaManager.h"
25 #include "utils/log.h"
26 #include "utils/URIUtils.h"
27 #include "utils/XMLUtils.h"
28 #include "video/VideoInfoTag.h"
30 #define ID_BUTTON_PLAY 11
31 #define ID_BUTTON_EJECT 10
33 CGUIDialogPlayEject::CGUIDialogPlayEject()
34 : CGUIDialogYesNo(WINDOW_DIALOG_PLAY_EJECT)
38 CGUIDialogPlayEject::~CGUIDialogPlayEject()
42 bool CGUIDialogPlayEject::OnMessage(CGUIMessage& message)
44 if (message.GetMessage() == GUI_MSG_CLICKED)
46 int iControl = message.GetSenderId();
47 if (iControl == ID_BUTTON_PLAY)
49 if (g_mediaManager.IsDiscInDrive())
51 m_bConfirmed = true;
52 Close();
55 return true;
57 if (iControl == ID_BUTTON_EJECT)
59 g_mediaManager.ToggleTray();
60 return true;
64 return CGUIDialogYesNo::OnMessage(message);
67 void CGUIDialogPlayEject::FrameMove()
69 CONTROL_ENABLE_ON_CONDITION(ID_BUTTON_PLAY, g_mediaManager.IsDiscInDrive());
71 CGUIDialogYesNo::FrameMove();
74 void CGUIDialogPlayEject::OnInitWindow()
76 if (g_mediaManager.IsDiscInDrive())
78 m_defaultControl = ID_BUTTON_PLAY;
80 else
82 CONTROL_DISABLE(ID_BUTTON_PLAY);
83 m_defaultControl = ID_BUTTON_EJECT;
86 CGUIDialogYesNo::OnInitWindow();
89 bool CGUIDialogPlayEject::ShowAndGetInput(const CFileItem & item,
90 unsigned int uiAutoCloseTime /* = 0 */)
92 // Make sure we're actually dealing with a Disc Stub
93 if (!item.IsDiscStub())
94 return false;
96 // Create the dialog
97 CGUIDialogPlayEject * pDialog = (CGUIDialogPlayEject *)g_windowManager.
98 GetWindow(WINDOW_DIALOG_PLAY_EJECT);
99 if (!pDialog)
100 return false;
102 // Figure out Lines 1 and 2 of the dialog
103 CStdString strLine1, strLine2;
104 CXBMCTinyXML discStubXML;
105 if (discStubXML.LoadFile(item.GetPath()))
107 TiXmlElement * pRootElement = discStubXML.RootElement();
108 if (!pRootElement || strcmpi(pRootElement->Value(), "discstub") != 0)
109 CLog::Log(LOGERROR, "Error loading %s, no <discstub> node", item.GetPath().c_str());
110 else
112 XMLUtils::GetString(pRootElement, "title", strLine1);
113 XMLUtils::GetString(pRootElement, "message", strLine2);
117 // Use the label for Line 1 if not defined
118 if (strLine1.empty())
119 strLine1 = item.GetLabel();
121 // Setup dialog parameters
122 pDialog->SetHeading(219);
123 pDialog->SetLine(0, 429);
124 pDialog->SetLine(1, strLine1);
125 pDialog->SetLine(2, strLine2);
126 pDialog->SetChoice(ID_BUTTON_PLAY - 10, 208);
127 pDialog->SetChoice(ID_BUTTON_EJECT - 10, 13391);
128 if (uiAutoCloseTime)
129 pDialog->SetAutoClose(uiAutoCloseTime);
131 // Display the dialog
132 pDialog->DoModal();
134 return pDialog->IsConfirmed();