From e2ee8f838c99e5d9af4b921e34b38e157e6d8581 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sun, 10 Jan 2016 19:18:00 +0000 Subject: [PATCH] Make unapplied changes counter private --- src/gui/handler.cpp | 12 ++++++------ src/gui/loot_handler.cpp | 2 +- src/gui/loot_state.cpp | 14 +++++++++++++- src/gui/loot_state.h | 8 ++++++-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/gui/handler.cpp b/src/gui/handler.cpp index db75cd8c..b185dd6b 100644 --- a/src/gui/handler.cpp +++ b/src/gui/handler.cpp @@ -160,12 +160,12 @@ namespace loot { return true; } else if (request == "cancelSort") { - --_lootState.numUnappliedChanges; + _lootState.decrementUnappliedChangeCounter(); callback->Success(""); return true; } else if (request == "editorOpened") { - ++_lootState.numUnappliedChanges; + _lootState.incrementUnappliedChangeCounter(); callback->Success(""); return true; } @@ -173,7 +173,7 @@ namespace loot { // This version of the editorClosed query has no arguments as it is // sent when editing is cancelled. Just update the unapplied changes // counter. - --_lootState.numUnappliedChanges; + _lootState.decrementUnappliedChangeCounter(); callback->Success(""); return true; } @@ -253,7 +253,7 @@ namespace loot { // One argument, which is the plugin metadata that has changed (+ its name). try { callback->Success(ApplyUserEdits(request["args"][0])); - --_lootState.numUnappliedChanges; + _lootState.decrementUnappliedChangeCounter(); } catch (loot::error &e) { BOOST_LOG_TRIVIAL(error) << "Failed to apply plugin metadata. Details: " << e.what(); @@ -297,7 +297,7 @@ namespace loot { return true; } else if (requestName == "applySort") { - --_lootState.numUnappliedChanges; + _lootState.decrementUnappliedChangeCounter(); BOOST_LOG_TRIVIAL(trace) << "User has accepted sorted load order, applying it."; try { _lootState.CurrentGame().SetLoadOrder(request["args"][0].as>()); @@ -983,7 +983,7 @@ namespace loot { node.push_back(pluginNode); } - ++_lootState.numUnappliedChanges; + _lootState.incrementUnappliedChangeCounter(); if (node.size() > 0) callback->Success(JSON::stringify(node)); diff --git a/src/gui/loot_handler.cpp b/src/gui/loot_handler.cpp index df652804..1ef3bcec 100644 --- a/src/gui/loot_handler.cpp +++ b/src/gui/loot_handler.cpp @@ -152,7 +152,7 @@ namespace loot { assert(CefCurrentlyOn(TID_UI)); // Check if unapplied changes exist. - if (_lootState.numUnappliedChanges > 0) { + if (_lootState.hasUnappliedChanges()) { browser->GetMainFrame()->ExecuteJavaScript("onQuit();", browser->GetMainFrame()->GetURL(), 0); return true; } diff --git a/src/gui/loot_state.cpp b/src/gui/loot_state.cpp index 9eb89571..9fcbd5ea 100644 --- a/src/gui/loot_state.cpp +++ b/src/gui/loot_state.cpp @@ -46,7 +46,7 @@ using boost::format; namespace fs = boost::filesystem; namespace loot { - LootState::LootState() : numUnappliedChanges(0), _currentGame(_games.end()) {} + LootState::LootState() : unappliedChangeCounter(0), _currentGame(_games.end()) {} void LootState::Init(const std::string& cmdLineGame) { // Do some preliminary locale / UTF-8 support setup here, in case the settings file reading requires it. @@ -229,6 +229,18 @@ namespace loot { return installedGames; } + bool LootState::hasUnappliedChanges() const { + return unappliedChangeCounter > 0; + } + + void LootState::incrementUnappliedChangeCounter() { + ++unappliedChangeCounter; + } + + void LootState::decrementUnappliedChangeCounter() { + --unappliedChangeCounter; + } + void LootState::SelectGame(std::string preferredGame) { if (preferredGame.empty()) { // Get preferred game from settings. diff --git a/src/gui/loot_state.h b/src/gui/loot_state.h index c6683d73..26205135 100644 --- a/src/gui/loot_state.h +++ b/src/gui/loot_state.h @@ -48,13 +48,17 @@ namespace loot { // Get the folder names of the installed games. std::vector InstalledGames(); - // Used to check if LOOT has unaccepted sorting or metadata changes on quit. - int numUnappliedChanges; + bool hasUnappliedChanges() const; + void incrementUnappliedChangeCounter(); + void decrementUnappliedChangeCounter(); private: std::list _games; std::list::iterator _currentGame; std::vector _initErrors; + // Used to check if LOOT has unaccepted sorting or metadata changes on quit. + size_t unappliedChangeCounter; + // Select initial game. void SelectGame(std::string cmdLineGame);