gui: extract methods for condition list handling

This is a preparation for list item conditions.

Change-Id: Iec731d1986a53b0362c534adf504dfe8db87d3f0
diff --git a/gui/object.cpp b/gui/object.cpp
index 7cce5db..eae56e6 100644
--- a/gui/object.cpp
+++ b/gui/object.cpp
@@ -1,25 +1,12 @@
-// checkbox.cpp - GUICheckbox object
+// object.cpp - GUIObject base class
 
-#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/reboot.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/mman.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <time.h>
-#include <unistd.h>
-#include <stdlib.h>
 
 #include <string>
 
 extern "C" {
 #include "../twcommon.h"
-#include "../minuitwrp/minui.h"
 #include "../variables.h"
 }
 
@@ -30,17 +17,16 @@
 GUIObject::GUIObject(xml_node<>* node)
 {
 	mConditionsResult = true;
+	if (node)
+		LoadConditions(node, mConditions);
+}
 
-	// Break out early, it's too hard to check if valid every step
-	if (!node)		return;
-
-	// First, get the action
+void GUIObject::LoadConditions(xml_node<>* node, std::vector<Condition>& conditions)
+{
 	xml_node<>* condition = FindNode(node, "conditions");
 	if (condition)  condition = FindNode(condition, "condition");
 	else			condition = FindNode(node, "condition");
 
-	if (!condition)	return;
-
 	while (condition)
 	{
 		Condition cond;
@@ -57,7 +43,7 @@
 		attr = condition->first_attribute("var2");
 		if (attr)   cond.mVar2 = attr->value();
 
-		mConditions.push_back(cond);
+		conditions.push_back(cond);
 
 		condition = condition->next_sibling("condition");
 	}
@@ -157,11 +143,17 @@
 
 int GUIObject::NotifyVarChange(const std::string& varName, const std::string& value)
 {
-	mConditionsResult = true;
+	mConditionsResult = UpdateConditions(mConditions, varName);
+	return 0;
+}
+
+bool GUIObject::UpdateConditions(std::vector<Condition>& conditions, const std::string& varName)
+{
+	bool result = true;
 
 	const bool varNameEmpty = varName.empty();
 	std::vector<Condition>::iterator iter;
-	for (iter = mConditions.begin(); iter != mConditions.end(); ++iter)
+	for (iter = conditions.begin(); iter != conditions.end(); ++iter)
 	{
 		if(varNameEmpty && iter->mCompareOp == "modified")
 		{
@@ -180,9 +172,9 @@
 			iter->mLastResult = isConditionTrue(&(*iter));
 
 		if(!iter->mLastResult)
-			mConditionsResult = false;
+			result = false;
 	}
-	return 0;
+	return result;
 }
 
 bool GUIObject::isMounted(string vol)
diff --git a/gui/objects.hpp b/gui/objects.hpp
index 624db07..99bf0db 100644
--- a/gui/objects.hpp
+++ b/gui/objects.hpp
@@ -151,8 +151,10 @@
 	std::vector<Condition> mConditions;
 
 protected:
-	bool isMounted(std::string vol);
-	bool isConditionTrue(Condition* condition);
+	static void LoadConditions(xml_node<>* node, std::vector<Condition>& conditions);
+	static bool isMounted(std::string vol);
+	static bool isConditionTrue(Condition* condition);
+	static bool UpdateConditions(std::vector<Condition>& conditions, const std::string& varName);
 
 	bool mConditionsResult;
 };