Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

CGUIDialogNumeric: handle GUI_MSG_SET_TEXT and add new SetMode() meth…

…od which takes the initial value as a CStdString instead of a void*
  • Loading branch information...
commit 9740905c034ab6da94d29bd3d088547418338f6c 1 parent 1c9f832
@Montellese authored
View
55 xbmc/dialogs/GUIDialogNumeric.cpp
@@ -139,6 +139,14 @@ bool CGUIDialogNumeric::OnMessage(CGUIMessage& message)
}
}
break;
+
+ case GUI_MSG_SET_TEXT:
+ SetMode(m_mode, message.GetLabel());
+
+ // close the dialog if requested
+ if (message.GetParam1() > 0)
+ OnOK();
+ break;
}
return CGUIDialog::OnMessage(message);
}
@@ -462,7 +470,7 @@ void CGUIDialogNumeric::SetMode(INPUT_MODE mode, void *initial)
m_datetime = *(SYSTEMTIME *)initial;
m_lastblock = (m_mode == INPUT_DATE) ? 2 : 1;
}
- if (m_mode == INPUT_IP_ADDRESS)
+ else if (m_mode == INPUT_IP_ADDRESS)
{
m_lastblock = 3;
m_ip[0] = m_ip[1] = m_ip[2] = m_ip[3] = 0;
@@ -484,10 +492,51 @@ void CGUIDialogNumeric::SetMode(INPUT_MODE mode, void *initial)
}
}
}
- if (m_mode == INPUT_NUMBER || m_mode == INPUT_PASSWORD)
- {
+ else if (m_mode == INPUT_NUMBER || m_mode == INPUT_PASSWORD)
m_number = *(CStdString *)initial;
+}
+
+void CGUIDialogNumeric::SetMode(INPUT_MODE mode, const CStdString &initial)
+{
+ m_mode = mode;
+ m_block = 0;
+ m_lastblock = 0;
+ if (m_mode == INPUT_TIME || m_mode == INPUT_TIME_SECONDS || m_mode == INPUT_DATE)
+ {
+ CDateTime dateTime;
+ if (m_mode == INPUT_TIME || m_mode == INPUT_TIME_SECONDS)
+ {
+ // check if we have a pure number
+ if (initial.find_first_not_of("0123456789") == std::string::npos)
+ {
+ long seconds = strtol(initial.c_str(), NULL, 10);
+ dateTime = seconds;
+ }
+ else
+ {
+ CStdString tmp = initial;
+ // if we are handling seconds and if the string only contains
+ // "mm:ss" we need to add dummy "hh:" to get "hh:mm:ss"
+ if (m_mode == INPUT_TIME_SECONDS && tmp.size() <= 5)
+ tmp = "00:" + tmp;
+ dateTime.SetFromDBTime(tmp);
+ }

You could probably use dateTime = StringUtils::TimeStringToSeconds(initial); perhaps?

@Montellese Owner

I looked at StringUtils::TimeStringToSeconds() but the problem is that in case of INPUT_TIME we look for HH:MM whereas TimeStringToSeconds assumes that if the string is XX:YY that it's MM:SS and only handles hours if the string is HH:MM:SS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
+ else if (m_mode == INPUT_DATE)
+ {
+ CStdString tmp = initial;
+ tmp.Replace("/", ".");
+ dateTime.SetFromDBDate(tmp);
+ }
+
+ if (!dateTime.IsValid())
+ return;
+
+ dateTime.GetAsSystemTime(m_datetime);
+ m_lastblock = (m_mode == INPUT_DATE) ? 2 : 1;
}
+ else
+ SetMode(mode, (void*)&initial);
}
void CGUIDialogNumeric::GetOutput(void *output)
View
1  xbmc/dialogs/GUIDialogNumeric.h
@@ -44,6 +44,7 @@ class CGUIDialogNumeric :
void SetHeading(const CStdString &strHeading);
void SetMode(INPUT_MODE mode, void *initial);
+ void SetMode(INPUT_MODE mode, const CStdString &initial);
void GetOutput(void *output);
static bool ShowAndGetTime(SYSTEMTIME &time, const CStdString &heading);
@jmarshallnz

You could probably use dateTime = StringUtils::TimeStringToSeconds(initial); perhaps?

@Montellese

I looked at StringUtils::TimeStringToSeconds() but the problem is that in case of INPUT_TIME we look for HH:MM whereas TimeStringToSeconds assumes that if the string is XX:YY that it's MM:SS and only handles hours if the string is HH:MM:SS.

Please sign in to comment.
Something went wrong with that request. Please try again.