Skip to content

Commit

Permalink
make 'ok', 'yesno' & 'progress' dialogs use the same xml file
Browse files Browse the repository at this point in the history
  • Loading branch information
ronie committed Jan 18, 2016
1 parent 34ae127 commit 92fe219
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 22 deletions.
6 changes: 5 additions & 1 deletion xbmc/dialogs/GUIDialogBoxBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#define CONTROL_HEADING 1
#define CONTROL_LINES_START 2
#define CONTROL_TEXTBOX 9
#define CONTROL_CHOICES_START 10

CGUIDialogBoxBase::CGUIDialogBoxBase(int id, const std::string &xmlFile)
: CGUIDialog(id, xmlFile)
Expand Down Expand Up @@ -145,6 +144,11 @@ void CGUIDialogBoxBase::Process(unsigned int currentTime, CDirtyRegionList &dirt

void CGUIDialogBoxBase::OnInitWindow()
{
// hide all controls
for (int i = 0; i < DIALOG_MAX_CHOICES; ++i)
SET_CONTROL_HIDDEN(CONTROL_CHOICES_START + i);
SET_CONTROL_HIDDEN(CONTROL_PROGRESS_BAR);

// set focus to default
m_lastControlID = m_defaultControl;

Expand Down
8 changes: 7 additions & 1 deletion xbmc/dialogs/GUIDialogBoxBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@
#include "guilib/GUIDialog.h"
#include "threads/CriticalSection.h"

#define CONTROL_CHOICES_START 10
#define CONTROL_NO_BUTTON CONTROL_CHOICES_START
#define CONTROL_YES_BUTTON CONTROL_CHOICES_START + 1
#define CONTROL_CUSTOM_BUTTON CONTROL_CHOICES_START + 2
#define CONTROL_PROGRESS_BAR 20

#define DIALOG_MAX_LINES 3
#define DIALOG_MAX_CHOICES 2
#define DIALOG_MAX_CHOICES 3

class CVariant;

Expand Down
4 changes: 1 addition & 3 deletions xbmc/dialogs/GUIDialogGamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <utility>

CGUIDialogGamepad::CGUIDialogGamepad(void)
: CGUIDialogBoxBase(WINDOW_DIALOG_GAMEPAD, "DialogOK.xml")
: CGUIDialogBoxBase(WINDOW_DIALOG_GAMEPAD, "DialogConfirm.xml")
{
m_bCanceled = false;
m_iRetries = 0;
Expand All @@ -45,8 +45,6 @@ CGUIDialogGamepad::~CGUIDialogGamepad(void)

void CGUIDialogGamepad::OnInitWindow()
{
// hide ok button from DialogOK
SET_CONTROL_HIDDEN(10);

CGUIDialogBoxBase::OnInitWindow();
}
Expand Down
16 changes: 11 additions & 5 deletions xbmc/dialogs/GUIDialogOK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@
#include "guilib/GUIMessage.h"
#include "utils/Variant.h"

#define ID_BUTTON_OK 10

CGUIDialogOK::CGUIDialogOK(void)
: CGUIDialogBoxBase(WINDOW_DIALOG_OK, "DialogOK.xml")
: CGUIDialogBoxBase(WINDOW_DIALOG_OK, "DialogConfirm.xml")
{
}

Expand All @@ -38,7 +36,7 @@ bool CGUIDialogOK::OnMessage(CGUIMessage& message)
if (message.GetMessage() == GUI_MSG_CLICKED)
{
int iControl = message.GetSenderId();
if (iControl == ID_BUTTON_OK)
if (iControl == CONTROL_YES_BUTTON)
{
m_bConfirmed = true;
Close();
Expand Down Expand Up @@ -72,9 +70,17 @@ void CGUIDialogOK::ShowAndGetInput(CVariant heading, CVariant line0, CVariant li
dialog->Open();
}

void CGUIDialogOK::OnInitWindow()
{
CGUIDialogBoxBase::OnInitWindow();

SET_CONTROL_VISIBLE(CONTROL_YES_BUTTON);
SET_CONTROL_FOCUS(CONTROL_YES_BUTTON, 0);
}

int CGUIDialogOK::GetDefaultLabelID(int controlId) const
{
if (controlId == ID_BUTTON_OK)
if (controlId == CONTROL_YES_BUTTON)
return 186;
return CGUIDialogBoxBase::GetDefaultLabelID(controlId);
}
1 change: 1 addition & 0 deletions xbmc/dialogs/GUIDialogOK.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ class CGUIDialogOK :
static void ShowAndGetInput(CVariant heading, CVariant text);
static void ShowAndGetInput(CVariant heading, CVariant line0, CVariant line1, CVariant line2);
protected:
virtual void OnInitWindow();
virtual int GetDefaultLabelID(int controlId) const;
};
22 changes: 14 additions & 8 deletions xbmc/dialogs/GUIDialogProgress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@
#include "utils/log.h"
#include "utils/Variant.h"

#define CONTROL_CANCEL_BUTTON 10
#define CONTROL_PROGRESS_BAR 20

CGUIDialogProgress::CGUIDialogProgress(void)
: CGUIDialogBoxBase(WINDOW_DIALOG_PROGRESS, "DialogProgress.xml")
: CGUIDialogBoxBase(WINDOW_DIALOG_PROGRESS, "DialogConfirm.xml")
{
Reset();
}
Expand Down Expand Up @@ -112,7 +109,7 @@ bool CGUIDialogProgress::OnMessage(CGUIMessage& message)
case GUI_MSG_CLICKED:
{
int iControl = message.GetSenderId();
if (iControl == CONTROL_CANCEL_BUTTON && m_bCanCancel && !m_bCanceled)
if (iControl == CONTROL_NO_BUTTON && m_bCanCancel && !m_bCanceled)
{
std::string strHeading = m_strHeading;
strHeading.append(" : ");
Expand Down Expand Up @@ -201,16 +198,25 @@ void CGUIDialogProgress::Process(unsigned int currentTime, CDirtyRegionList &dir
else
SET_CONTROL_HIDDEN(CONTROL_PROGRESS_BAR);
if (showCancel)
SET_CONTROL_VISIBLE(CONTROL_CANCEL_BUTTON);
SET_CONTROL_VISIBLE(CONTROL_NO_BUTTON);
else
SET_CONTROL_HIDDEN(CONTROL_CANCEL_BUTTON);
SET_CONTROL_HIDDEN(CONTROL_NO_BUTTON);
}
CGUIDialogBoxBase::Process(currentTime, dirtyregions);
}

void CGUIDialogProgress::OnInitWindow()
{
CGUIDialogBoxBase::OnInitWindow();

SET_CONTROL_VISIBLE(CONTROL_NO_BUTTON);
SET_CONTROL_VISIBLE(CONTROL_PROGRESS_BAR);
SET_CONTROL_FOCUS(CONTROL_NO_BUTTON, 0);
}

int CGUIDialogProgress::GetDefaultLabelID(int controlId) const
{
if (controlId == CONTROL_CANCEL_BUTTON)
if (controlId == CONTROL_NO_BUTTON)
return 222;
return CGUIDialogBoxBase::GetDefaultLabelID(controlId);
}
1 change: 1 addition & 0 deletions xbmc/dialogs/GUIDialogProgress.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class CGUIDialogProgress :
void SetCanCancel(bool bCanCancel);

protected:
virtual void OnInitWindow();
virtual int GetDefaultLabelID(int controlId) const;
virtual void Process(unsigned int currentTime, CDirtyRegionList &dirtyregions);

Expand Down
14 changes: 10 additions & 4 deletions xbmc/dialogs/GUIDialogYesNo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@
#include "input/Key.h"
#include "messaging/helpers/DialogHelper.h"

#define CONTROL_NO_BUTTON 10
#define CONTROL_YES_BUTTON 11

CGUIDialogYesNo::CGUIDialogYesNo(int overrideId /* = -1 */)
: CGUIDialogBoxBase(overrideId == -1 ? WINDOW_DIALOG_YES_NO : overrideId, "DialogYesNo.xml")
: CGUIDialogBoxBase(overrideId == -1 ? WINDOW_DIALOG_YES_NO : overrideId, "DialogConfirm.xml")
{
m_bConfirmed = false;
m_bCanceled = false;
Expand Down Expand Up @@ -73,6 +70,15 @@ bool CGUIDialogYesNo::OnBack(int actionID)
return CGUIDialogBoxBase::OnBack(actionID);
}

void CGUIDialogYesNo::OnInitWindow()
{
CGUIDialogBoxBase::OnInitWindow();

SET_CONTROL_VISIBLE(CONTROL_YES_BUTTON);
SET_CONTROL_VISIBLE(CONTROL_NO_BUTTON);
SET_CONTROL_FOCUS(CONTROL_NO_BUTTON, 0);
}

bool CGUIDialogYesNo::ShowAndGetInput(CVariant heading, CVariant line0, CVariant line1, CVariant line2, bool &bCanceled)
{
return ShowAndGetInput(heading, line0, line1, line2, bCanceled, "", "", NO_TIMEOUT);
Expand Down
1 change: 1 addition & 0 deletions xbmc/dialogs/GUIDialogYesNo.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class CGUIDialogYesNo :
int ShowAndGetInput(const KODI::MESSAGING::HELPERS::DialogYesNoMessage& options);

protected:
virtual void OnInitWindow();
virtual int GetDefaultLabelID(int controlId) const;

bool m_bCanceled;
Expand Down

0 comments on commit 92fe219

Please sign in to comment.