Skip to content

Commit

Permalink
Merge pull request #4675 from jmarshallnz/seconds_to_hours
Browse files Browse the repository at this point in the history
Seconds to hours
  • Loading branch information
jmarshallnz committed May 12, 2014
2 parents b212b04 + 454f09f commit 6a8e3b5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 19 deletions.
53 changes: 42 additions & 11 deletions xbmc/dialogs/GUIDialogNumeric.cpp
Expand Up @@ -235,10 +235,20 @@ void CGUIDialogNumeric::OnBackSpace()
}
else if (m_mode == INPUT_TIME_SECONDS)
{
if (m_block == 0) // minutes
m_datetime.wMinute /= 10;
if (m_block == 0)
m_datetime.wHour /= 10;
else if (m_block == 1)
{
if (m_datetime.wMinute)
m_datetime.wMinute /= 10;
else
{
m_block = 0;
m_dirty = false;
}
}
else if (m_datetime.wSecond)
m_datetime.wSecond /= 10;
m_datetime.wMinute /= 10;
else
{
m_block = 0;
Expand Down Expand Up @@ -310,7 +320,7 @@ void CGUIDialogNumeric::FrameMove()
}
else if (m_mode == INPUT_TIME_SECONDS)
{ // format up the time
strLabel = StringUtils::Format("%2d:%02d", m_datetime.wMinute, m_datetime.wSecond);
strLabel = StringUtils::Format("%2d:%02d:%02d", m_datetime.wHour, m_datetime.wMinute, m_datetime.wSecond);
start = m_block * 3;
end = m_block * 3 + 2;
}
Expand Down Expand Up @@ -397,19 +407,40 @@ void CGUIDialogNumeric::OnNumber(unsigned int num)
}
else if (m_mode == INPUT_TIME_SECONDS)
{
if (m_block == 0) // minute
if (m_block == 0) // hour
{
if (m_dirty) // have input the first digit
{
m_datetime.wHour *= 10;
m_datetime.wHour += num;
m_block = 1; // move to minutes - allows up to 99 hours
m_dirty = false;
}
else // this is the first digit
{
m_datetime.wHour = num;
m_dirty = true;
}
}
else if (m_block == 1) // minute
{
if (m_dirty) // have input the first digit
{
m_datetime.wMinute *= 10;
m_datetime.wMinute += num;
m_block = 1; // move to seconds - allows up to 99 minutes
m_block = 2; // move to seconds - allows up to 99 minutes
m_dirty = false;
}
else // this is the first digit
{
m_datetime.wMinute = num;
m_dirty = true;
if (num > 5)
{
m_block = 2; // move to seconds
m_dirty = false;
}
else
m_dirty = true;
}
}
else // seconds
Expand All @@ -418,15 +449,15 @@ void CGUIDialogNumeric::OnNumber(unsigned int num)
{
m_datetime.wSecond *= 10;
m_datetime.wSecond += num;
m_block = 0; // move to minutes
m_block = 0; // move to hours
m_dirty = false;
}
else // this is the first digit
{
m_datetime.wSecond = num;
if (num > 5)
{
m_block = 0; // move to minutes
m_block = 0; // move to hours
m_dirty = false;
}
else
Expand Down Expand Up @@ -518,7 +549,7 @@ void CGUIDialogNumeric::SetMode(INPUT_MODE mode, void *initial)
if (m_mode == INPUT_TIME || m_mode == INPUT_TIME_SECONDS || m_mode == INPUT_DATE)
{
m_datetime = *(SYSTEMTIME *)initial;
m_lastblock = (m_mode == INPUT_DATE) ? 2 : 1;
m_lastblock = (m_mode != INPUT_TIME) ? 2 : 1;
}
else if (m_mode == INPUT_IP_ADDRESS)
{
Expand Down Expand Up @@ -608,7 +639,7 @@ CStdString CGUIDialogNumeric::GetOutput() const
else if (m_mode == INPUT_TIME)
output = StringUtils::Format("%i:%02i", m_datetime.wHour, m_datetime.wMinute);
else if (m_mode == INPUT_TIME_SECONDS)
output = StringUtils::Format("%i:%02i", m_datetime.wMinute, m_datetime.wSecond);
output = StringUtils::Format("%i:%02i:%02i", m_datetime.wHour, m_datetime.wMinute, m_datetime.wSecond);
else
GetOutput(&output);
return output;
Expand Down
18 changes: 10 additions & 8 deletions xbmc/utils/StringValidation.cpp
Expand Up @@ -46,14 +46,16 @@ bool StringValidation::IsTime(const std::string &input, void *data)
}
else
{
size_t pos = strTime.find(":");
// if there's no ":", the value must be in seconds only
if (pos == std::string::npos)
return IsPositiveInteger(strTime, NULL);

std::string strMin = StringUtils::Left(strTime, pos);
std::string strSec = StringUtils::Mid(strTime, pos + 1);
return IsPositiveInteger(strMin, NULL) && IsPositiveInteger(strSec, NULL);
// support [[HH:]MM:]SS
std::vector<std::string> bits = StringUtils::Split(input, ":");
if (bits.size() > 3)
return false;

for (std::vector<std::string>::const_iterator i = bits.begin(); i != bits.end(); ++i)
if (!IsPositiveInteger(*i, NULL))
return false;

return true;
}
return false;
}

0 comments on commit 6a8e3b5

Please sign in to comment.