Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

settings: implement input validation for edit controls

  • Loading branch information...
commit c53b46d8dcfe38aea964a49c6e75f184f747f0a8 1 parent c1baf21
@Montellese Montellese authored
View
16 xbmc/settings/windows/GUIControlSettings.cpp
@@ -570,6 +570,10 @@ CGUIControlEditSetting::CGUIControlEditSetting(CGUIEditControl *pEdit, int id, C
m_pEdit->SetInputType(inputType, heading);
Update();
+
+ // this will automatically trigger validation so it must be executed after
+ // having set the value of the control based on the value of the setting
+ m_pEdit->SetInputValidation(InputValidation, this);
}
CGUIControlEditSetting::~CGUIControlEditSetting()
@@ -594,6 +598,18 @@ void CGUIControlEditSetting::Update()
m_pEdit->SetLabel2(m_pSetting->ToString());
}
+bool CGUIControlEditSetting::InputValidation(const std::string &input, void *data)
+{
+ if (data == NULL)
+ return true;
+
+ CGUIControlEditSetting *editControl = reinterpret_cast<CGUIControlEditSetting*>(data);
+ if (editControl == NULL || editControl->GetSetting() == NULL)
+ return true;
+
+ return editControl->GetSetting()->FromString(input);
+}
+
CGUIControlSeparatorSetting::CGUIControlSeparatorSetting(CGUIImage *pImage, int id)
: CGUIControlBaseSetting(id, NULL)
{
View
2  xbmc/settings/windows/GUIControlSettings.h
@@ -157,6 +157,8 @@ class CGUIControlEditSetting : public CGUIControlBaseSetting
virtual void Update();
virtual void Clear() { m_pEdit = NULL; }
private:
+ static bool InputValidation(const std::string &input, void *data);
+
CGUIEditControl *m_pEdit;
};
Please sign in to comment.
Something went wrong with that request. Please try again.