From fafb0c541bb4b24515c57251a44d87825eec90fb Mon Sep 17 00:00:00 2001 From: Vojtech Bocek Date: Thu, 25 Jul 2013 22:53:02 +0200 Subject: Unify indentation and little clean-up in TWRP files Signed-off-by: Vojtech Bocek --- gui/action.cpp | 498 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 249 insertions(+), 249 deletions(-) (limited to 'gui/action.cpp') diff --git a/gui/action.cpp b/gui/action.cpp index 3e1f793df..ee3373154 100644 --- a/gui/action.cpp +++ b/gui/action.cpp @@ -64,72 +64,72 @@ extern blanktimer blankTimer; void curtainClose(void); GUIAction::GUIAction(xml_node<>* node) - : Conditional(node) + : Conditional(node) { - xml_node<>* child; - xml_node<>* actions; - xml_attribute<>* attr; - - mKey = 0; - - if (!node) return; - - // First, get the action - actions = node->first_node("actions"); - if (actions) child = actions->first_node("action"); - else child = node->first_node("action"); - - if (!child) return; - - while (child) - { - Action action; - - attr = child->first_attribute("function"); - if (!attr) return; - - action.mFunction = attr->value(); - action.mArg = child->value(); - mActions.push_back(action); - - child = child->next_sibling("action"); - } - - // Now, let's get either the key or region - child = node->first_node("touch"); - if (child) - { - attr = child->first_attribute("key"); - if (attr) - { - std::string key = attr->value(); - - mKey = getKeyByName(key); - } - else - { - attr = child->first_attribute("x"); - if (!attr) return; - mActionX = atol(attr->value()); - attr = child->first_attribute("y"); - if (!attr) return; - mActionY = atol(attr->value()); - attr = child->first_attribute("w"); - if (!attr) return; - mActionW = atol(attr->value()); - attr = child->first_attribute("h"); - if (!attr) return; - mActionH = atol(attr->value()); - } - } + xml_node<>* child; + xml_node<>* actions; + xml_attribute<>* attr; + + mKey = 0; + + if (!node) return; + + // First, get the action + actions = node->first_node("actions"); + if (actions) child = actions->first_node("action"); + else child = node->first_node("action"); + + if (!child) return; + + while (child) + { + Action action; + + attr = child->first_attribute("function"); + if (!attr) return; + + action.mFunction = attr->value(); + action.mArg = child->value(); + mActions.push_back(action); + + child = child->next_sibling("action"); + } + + // Now, let's get either the key or region + child = node->first_node("touch"); + if (child) + { + attr = child->first_attribute("key"); + if (attr) + { + std::string key = attr->value(); + + mKey = getKeyByName(key); + } + else + { + attr = child->first_attribute("x"); + if (!attr) return; + mActionX = atol(attr->value()); + attr = child->first_attribute("y"); + if (!attr) return; + mActionY = atol(attr->value()); + attr = child->first_attribute("w"); + if (!attr) return; + mActionW = atol(attr->value()); + attr = child->first_attribute("h"); + if (!attr) return; + mActionH = atol(attr->value()); + } + } } int GUIAction::NotifyTouch(TOUCH_STATE state, int x, int y) { - if (state == TOUCH_RELEASE) - doActions(); + if (state == TOUCH_RELEASE) + doActions(); - return 0; + return 0; } int GUIAction::NotifyKey(int key) @@ -143,17 +143,17 @@ int GUIAction::NotifyKey(int key) int GUIAction::NotifyVarChange(std::string varName, std::string value) { - if (varName.empty() && !isConditionValid() && !mKey && !mActionW) - doActions(); + if (varName.empty() && !isConditionValid() && !mKey && !mActionW) + doActions(); - // This handles notifying the condition system of page start - if (varName.empty() && isConditionValid()) - NotifyPageSet(); + // This handles notifying the condition system of page start + if (varName.empty() && isConditionValid()) + NotifyPageSet(); - if ((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue()) - doActions(); + if ((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue()) + doActions(); - return 0; + return 0; } void GUIAction::simulate_progress_bar(void) @@ -168,54 +168,54 @@ void GUIAction::simulate_progress_bar(void) int GUIAction::flash_zip(std::string filename, std::string pageName, const int simulate, int* wipe_cache) { - int ret_val = 0; + int ret_val = 0; DataManager::SetValue("ui_progress", 0); - if (filename.empty()) - { - LOGERR("No file specified.\n"); - return -1; - } + if (filename.empty()) + { + LOGERR("No file specified.\n"); + return -1; + } - // We're going to jump to this page first, like a loading page - gui_changePage(pageName); + // We're going to jump to this page first, like a loading page + gui_changePage(pageName); - int fd = -1; - ZipArchive zip; + int fd = -1; + ZipArchive zip; - if (!PartitionManager.Mount_By_Path(filename, true)) + if (!PartitionManager.Mount_By_Path(filename, true)) return -1; if (mzOpenZipArchive(filename.c_str(), &zip)) - { - LOGERR("Unable to open zip file.\n"); - return -1; - } + { + LOGERR("Unable to open zip file.\n"); + return -1; + } - // Check the zip to see if it has a custom installer theme + // Check the zip to see if it has a custom installer theme const ZipEntry* twrp = mzFindZipEntry(&zip, "META-INF/teamwin/twrp.zip"); - if (twrp != NULL) - { - unlink("/tmp/twrp.zip"); - fd = creat("/tmp/twrp.zip", 0666); - } - if (fd >= 0 && twrp != NULL && - mzExtractZipEntryToFile(&zip, twrp, fd) && - !PageManager::LoadPackage("install", "/tmp/twrp.zip", "main")) - { - mzCloseZipArchive(&zip); + if (twrp != NULL) + { + unlink("/tmp/twrp.zip"); + fd = creat("/tmp/twrp.zip", 0666); + } + if (fd >= 0 && twrp != NULL && + mzExtractZipEntryToFile(&zip, twrp, fd) && + !PageManager::LoadPackage("install", "/tmp/twrp.zip", "main")) + { + mzCloseZipArchive(&zip); PageManager::SelectPackage("install"); - gui_changePage("main"); - } - else - { - // In this case, we just use the default page - mzCloseZipArchive(&zip); + gui_changePage("main"); + } + else + { + // In this case, we just use the default page + mzCloseZipArchive(&zip); gui_changePage(pageName); - } - if (fd >= 0) - close(fd); + } + if (fd >= 0) + close(fd); if (simulate) { simulate_progress_bar(); @@ -237,20 +237,20 @@ int GUIAction::flash_zip(std::string filename, std::string pageName, const int s } } - // Done - DataManager::SetValue("ui_progress", 100); - DataManager::SetValue("ui_progress", 0); - return ret_val; + // Done + DataManager::SetValue("ui_progress", 100); + DataManager::SetValue("ui_progress", 0); + return ret_val; } int GUIAction::doActions() { - if (mActions.size() < 1) return -1; - if (mActions.size() == 1) + if (mActions.size() < 1) return -1; + if (mActions.size() == 1) return doAction(mActions.at(0), 0); - // For multi-action, we always use a thread - pthread_t t; + // For multi-action, we always use a thread + pthread_t t; pthread_attr_t tattr; if (pthread_attr_init(&tattr)) { @@ -271,7 +271,7 @@ int GUIAction::doActions() } */ int ret = pthread_create(&t, &tattr, thread_start, this); - if (ret) { + if (ret) { LOGERR("Unable to create more threads for actions... continuing in same thread! %i\n", ret); thread_start(this); } else { @@ -284,30 +284,30 @@ int GUIAction::doActions() return -1; } - return 0; + return 0; } void* GUIAction::thread_start(void *cookie) { - GUIAction* ourThis = (GUIAction*) cookie; + GUIAction* ourThis = (GUIAction*) cookie; DataManager::SetValue(TW_ACTION_BUSY, 1); - if (ourThis->mActions.size() > 1) - { - std::vector::iterator iter; - for (iter = ourThis->mActions.begin(); iter != ourThis->mActions.end(); iter++) - ourThis->doAction(*iter, 1); - } - else - { - ourThis->doAction(ourThis->mActions.at(0), 1); - } + if (ourThis->mActions.size() > 1) + { + std::vector::iterator iter; + for (iter = ourThis->mActions.begin(); iter != ourThis->mActions.end(); iter++) + ourThis->doAction(*iter, 1); + } + else + { + ourThis->doAction(ourThis->mActions.at(0), 1); + } int check = 0; DataManager::GetValue("tw_background_thread_running", check); if (check == 0) DataManager::SetValue(TW_ACTION_BUSY, 0); - return NULL; + return NULL; } void GUIAction::operation_start(const string operation_name) @@ -357,7 +357,7 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) if (function == "reboot") { - //curtainClose(); this sometimes causes a crash + //curtainClose(); this sometimes causes a crash sync(); DataManager::SetValue("tw_gui_done", 1); @@ -365,25 +365,25 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) return 0; } - if (function == "home") - { - PageManager::SelectPackage("TWRP"); - gui_changePage("main"); - return 0; - } - - if (function == "key") - { - PageManager::NotifyKey(getKeyByName(arg)); - return 0; - } - - if (function == "page") { + if (function == "home") + { + PageManager::SelectPackage("TWRP"); + gui_changePage("main"); + return 0; + } + + if (function == "key") + { + PageManager::NotifyKey(getKeyByName(arg)); + return 0; + } + + if (function == "page") { std::string page_name = gui_parse_text(arg); - return gui_changePage(page_name); + return gui_changePage(page_name); } - if (function == "reload") { + if (function == "reload") { int check = 0, ret_val = 0; std::string theme_path; @@ -405,85 +405,85 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) ret_val = 1; } } - operation_end(ret_val, simulate); + operation_end(ret_val, simulate); return 0; } - if (function == "readBackup") - { + if (function == "readBackup") + { string Restore_Name; DataManager::GetValue("tw_restore", Restore_Name); PartitionManager.Set_Restore_Files(Restore_Name); - return 0; - } - - if (function == "set") - { - if (arg.find('=') != string::npos) - { - string varName = arg.substr(0, arg.find('=')); - string value = arg.substr(arg.find('=') + 1, string::npos); - - DataManager::GetValue(value, value); - DataManager::SetValue(varName, value); - } - else - DataManager::SetValue(arg, "1"); - return 0; - } - if (function == "clear") - { - DataManager::SetValue(arg, "0"); - return 0; - } - - if (function == "mount") - { - if (arg == "usb") - { - DataManager::SetValue(TW_ACTION_BUSY, 1); + return 0; + } + + if (function == "set") + { + if (arg.find('=') != string::npos) + { + string varName = arg.substr(0, arg.find('=')); + string value = arg.substr(arg.find('=') + 1, string::npos); + + DataManager::GetValue(value, value); + DataManager::SetValue(varName, value); + } + else + DataManager::SetValue(arg, "1"); + return 0; + } + if (function == "clear") + { + DataManager::SetValue(arg, "0"); + return 0; + } + + if (function == "mount") + { + if (arg == "usb") + { + DataManager::SetValue(TW_ACTION_BUSY, 1); if (!simulate) PartitionManager.usb_storage_enable(); else gui_print("Simulating actions...\n"); - } - else if (!simulate) - { - string cmd; + } + else if (!simulate) + { + string cmd; if (arg == "EXTERNAL") PartitionManager.Mount_By_Path(DataManager::GetStrValue(TW_EXTERNAL_MOUNT), true); else if (arg == "INTERNAL") PartitionManager.Mount_By_Path(DataManager::GetStrValue(TW_INTERNAL_MOUNT), true); else PartitionManager.Mount_By_Path(arg, true); - } else + } else gui_print("Simulating actions...\n"); - return 0; - } - - if (function == "umount" || function == "unmount") - { - if (arg == "usb") - { - if (!simulate) + return 0; + } + + if (function == "umount" || function == "unmount") + { + if (arg == "usb") + { + if (!simulate) PartitionManager.usb_storage_disable(); else gui_print("Simulating actions...\n"); DataManager::SetValue(TW_ACTION_BUSY, 0); - } - else if (!simulate) - { - string cmd; + } + else if (!simulate) + { + string cmd; if (arg == "EXTERNAL") PartitionManager.UnMount_By_Path(DataManager::GetStrValue(TW_EXTERNAL_MOUNT), true); else if (arg == "INTERNAL") PartitionManager.UnMount_By_Path(DataManager::GetStrValue(TW_INTERNAL_MOUNT), true); else PartitionManager.UnMount_By_Path(arg, true); - } else + } else gui_print("Simulating actions...\n"); - return 0; - } + return 0; + } if (function == "restoredefaultsettings") { @@ -519,20 +519,20 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) if (function == "compute" || function == "addsubtract") { if (arg.find("+") != string::npos) - { - string varName = arg.substr(0, arg.find('+')); - string string_to_add = arg.substr(arg.find('+') + 1, string::npos); + { + string varName = arg.substr(0, arg.find('+')); + string string_to_add = arg.substr(arg.find('+') + 1, string::npos); int amount_to_add = atoi(string_to_add.c_str()); int value; DataManager::GetValue(varName, value); - DataManager::SetValue(varName, value + amount_to_add); + DataManager::SetValue(varName, value + amount_to_add); return 0; - } + } if (arg.find("-") != string::npos) - { - string varName = arg.substr(0, arg.find('-')); - string string_to_subtract = arg.substr(arg.find('-') + 1, string::npos); + { + string varName = arg.substr(0, arg.find('-')); + string string_to_subtract = arg.substr(arg.find('-') + 1, string::npos); int amount_to_subtract = atoi(string_to_subtract.c_str()); int value; @@ -540,9 +540,9 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) value -= amount_to_subtract; if (value <= 0) value = 0; - DataManager::SetValue(varName, value); + DataManager::SetValue(varName, value); return 0; - } + } if (arg.find("*") != string::npos) { string varName = arg.substr(0, arg.find('*')); @@ -653,11 +653,11 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) } if (function == "overlay") - return gui_changeOverlay(arg); + return gui_changeOverlay(arg); if (function == "queuezip") - { - if (zip_queue_index >= 10) { + { + if (zip_queue_index >= 10) { gui_print("Maximum zip queue reached!\n"); return 0; } @@ -670,8 +670,8 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) } if (function == "cancelzip") - { - if (zip_queue_index <= 0) { + { + if (zip_queue_index <= 0) { gui_print("Minimum zip queue reached!\n"); return 0; } else { @@ -696,9 +696,9 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) return 0; } - if (isThreaded) - { - if (function == "fileexists") + if (isThreaded) + { + if (function == "fileexists") { struct stat st; string newpath = arg + "/."; @@ -712,13 +712,13 @@ int GUIAction::doAction(Action action, int isThreaded /* = 0 */) } if (function == "flash") - { + { int i, ret_val = 0, wipe_cache = 0; for (i=0; i