From 20fb95d0a77da2a28e30648bd91e3fa29ce5bc6b Mon Sep 17 00:00:00 2001 From: that Date: Sat, 12 Sep 2015 11:27:47 +0200 Subject: gui: extract methods for condition list handling This is a preparation for list item conditions. Change-Id: Iec731d1986a53b0362c534adf504dfe8db87d3f0 --- gui/object.cpp | 42 +++++++++++++++++------------------------- gui/objects.hpp | 6 ++++-- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/gui/object.cpp b/gui/object.cpp index 7cce5db8b..eae56e644 100644 --- a/gui/object.cpp +++ b/gui/object.cpp @@ -1,25 +1,12 @@ -// checkbox.cpp - GUICheckbox object +// object.cpp - GUIObject base class -#include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include extern "C" { #include "../twcommon.h" -#include "../minuitwrp/minui.h" #include "../variables.h" } @@ -30,17 +17,16 @@ extern "C" { 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& 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 @@ GUIObject::GUIObject(xml_node<>* node) 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 @@ bool GUIObject::isConditionValid() int GUIObject::NotifyVarChange(const std::string& varName, const std::string& value) { - mConditionsResult = true; + mConditionsResult = UpdateConditions(mConditions, varName); + return 0; +} + +bool GUIObject::UpdateConditions(std::vector& conditions, const std::string& varName) +{ + bool result = true; const bool varNameEmpty = varName.empty(); std::vector::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 @@ int GUIObject::NotifyVarChange(const std::string& varName, const std::string& va 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 624db07f9..99bf0dbfa 100644 --- a/gui/objects.hpp +++ b/gui/objects.hpp @@ -151,8 +151,10 @@ protected: std::vector mConditions; protected: - bool isMounted(std::string vol); - bool isConditionTrue(Condition* condition); + static void LoadConditions(xml_node<>* node, std::vector& conditions); + static bool isMounted(std::string vol); + static bool isConditionTrue(Condition* condition); + static bool UpdateConditions(std::vector& conditions, const std::string& varName); bool mConditionsResult; }; -- cgit v1.2.3