PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/dialogs/GUIDialogOK.cpp

http://github.com/xbmc/xbmc
C++ | 96 lines | 75 code | 12 blank | 9 comment | 12 complexity | 9350039493a1a79c79de14f0210a95f7 MD5 | raw file
 1/*
 2 *  Copyright (C) 2005-2018 Team Kodi
 3 *  This file is part of Kodi - https://kodi.tv
 4 *
 5 *  SPDX-License-Identifier: GPL-2.0-or-later
 6 *  See LICENSES/README.md for more information.
 7 */
 8
 9#include "GUIDialogOK.h"
10
11#include "ServiceBroker.h"
12#include "guilib/GUIComponent.h"
13#include "guilib/GUIMessage.h"
14#include "guilib/GUIWindowManager.h"
15#include "utils/Variant.h"
16
17CGUIDialogOK::CGUIDialogOK(void)
18    : CGUIDialogBoxBase(WINDOW_DIALOG_OK, "DialogConfirm.xml")
19{
20}
21
22CGUIDialogOK::~CGUIDialogOK(void) = default;
23
24bool CGUIDialogOK::OnMessage(CGUIMessage& message)
25{
26  if (message.GetMessage() == GUI_MSG_CLICKED)
27  {
28    int iControl = message.GetSenderId();
29    if (iControl == CONTROL_YES_BUTTON)
30    {
31      m_bConfirmed = true;
32      Close();
33      return true;
34    }
35  }
36  return CGUIDialogBoxBase::OnMessage(message);
37}
38
39// \brief Show CGUIDialogOK dialog, then wait for user to dismiss it.
40bool CGUIDialogOK::ShowAndGetInput(CVariant heading, CVariant text)
41{
42  CGUIDialogOK *dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogOK>(WINDOW_DIALOG_OK);
43  if (!dialog)
44    return false;
45  dialog->SetHeading(heading);
46  dialog->SetText(text);
47  dialog->Open();
48  return dialog->IsConfirmed();
49}
50
51// \brief Show CGUIDialogOK dialog, then wait for user to dismiss it.
52bool CGUIDialogOK::ShowAndGetInput(CVariant heading, CVariant line0, CVariant line1, CVariant line2)
53{
54  CGUIDialogOK *dialog = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogOK>(WINDOW_DIALOG_OK);
55  if (!dialog)
56    return false;
57  dialog->SetHeading(heading);
58  dialog->SetLine(0, line0);
59  dialog->SetLine(1, line1);
60  dialog->SetLine(2, line2);
61  dialog->Open();
62  return dialog->IsConfirmed();
63}
64
65bool CGUIDialogOK::ShowAndGetInput(const HELPERS::DialogOKMessage & options)
66{
67  if (!options.heading.isNull())
68    SetHeading(options.heading);
69  if (!options.text.isNull())
70    SetText(options.text);
71
72  for (size_t i = 0; i < 3; ++i)
73  {
74    if (!options.lines[i].isNull())
75      SetLine(i, options.lines[i]);
76  }
77  Open();
78  return IsConfirmed();
79}
80
81void CGUIDialogOK::OnInitWindow()
82{
83  SET_CONTROL_HIDDEN(CONTROL_NO_BUTTON);
84  SET_CONTROL_HIDDEN(CONTROL_CUSTOM_BUTTON);
85  SET_CONTROL_HIDDEN(CONTROL_PROGRESS_BAR);
86  SET_CONTROL_FOCUS(CONTROL_YES_BUTTON, 0);
87
88  CGUIDialogBoxBase::OnInitWindow();
89}
90
91int CGUIDialogOK::GetDefaultLabelID(int controlId) const
92{
93  if (controlId == CONTROL_YES_BUTTON)
94    return 186;
95  return CGUIDialogBoxBase::GetDefaultLabelID(controlId);
96}