2 * Copyright (C) 2005-2013 Team XBMC
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)
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/>.
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())
57 if (iControl
== ID_BUTTON_EJECT
)
59 g_mediaManager
.ToggleTray();
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
;
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())
97 CGUIDialogPlayEject
* pDialog
= (CGUIDialogPlayEject
*)g_windowManager
.
98 GetWindow(WINDOW_DIALOG_PLAY_EJECT
);
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());
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);
129 pDialog
->SetAutoClose(uiAutoCloseTime
);
131 // Display the dialog
134 return pDialog
->IsConfirmed();