Skip to content

Commit 829c4e9

Browse files
committed
Refactor unapplied change counter
1 parent d4fed7b commit 829c4e9

File tree

13 files changed

+183
-174
lines changed

13 files changed

+183
-174
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ set(LOOT_SRC_GUI_H_FILES
409409
"${CMAKE_SOURCE_DIR}/src/gui/query/types/get_overlapping_plugins_query.h"
410410
"${CMAKE_SOURCE_DIR}/src/gui/query/types/get_game_data_query.h"
411411
"${CMAKE_SOURCE_DIR}/src/gui/query/types/sort_plugins_query.h"
412+
"${CMAKE_SOURCE_DIR}/src/gui/state/change_count.h"
412413
"${CMAKE_SOURCE_DIR}/src/gui/state/game/detection/common.h"
413414
"${CMAKE_SOURCE_DIR}/src/gui/state/game/detection/detail.h"
414415
"${CMAKE_SOURCE_DIR}/src/gui/state/game/detection/epic_games_store.h"
@@ -430,7 +431,6 @@ set(LOOT_SRC_GUI_H_FILES
430431
"${CMAKE_SOURCE_DIR}/src/gui/state/loot_paths.h"
431432
"${CMAKE_SOURCE_DIR}/src/gui/state/loot_settings.h"
432433
"${CMAKE_SOURCE_DIR}/src/gui/state/loot_state.h"
433-
"${CMAKE_SOURCE_DIR}/src/gui/state/unapplied_change_counter.h"
434434
"${CMAKE_SOURCE_DIR}/src/gui/resource.h"
435435
"${CMAKE_SOURCE_DIR}/src/gui/version.h")
436436

cmake/tests.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ set(LOOT_SRC_TESTS_GUI_CPP_FILES
2929
"${CMAKE_SOURCE_DIR}/src/tests/gui/qt/tasks/non_blocking_test_task.cpp")
3030

3131
set(LOOT_SRC_TESTS_GUI_H_FILES
32+
"${CMAKE_SOURCE_DIR}/src/tests/gui/state/change_count_test.h"
3233
"${CMAKE_SOURCE_DIR}/src/tests/gui/state/game/detection/common_test.h"
3334
"${CMAKE_SOURCE_DIR}/src/tests/gui/state/game/detection/detail_test.h"
3435
"${CMAKE_SOURCE_DIR}/src/tests/gui/state/game/detection/epic_games_store_test.h"
@@ -46,7 +47,6 @@ set(LOOT_SRC_TESTS_GUI_H_FILES
4647
"${CMAKE_SOURCE_DIR}/src/tests/gui/state/game/helpers_test.h"
4748
"${CMAKE_SOURCE_DIR}/src/tests/gui/state/loot_paths_test.h"
4849
"${CMAKE_SOURCE_DIR}/src/tests/gui/state/loot_settings_test.h"
49-
"${CMAKE_SOURCE_DIR}/src/tests/gui/state/unapplied_change_counter_test.h"
5050
"${CMAKE_SOURCE_DIR}/src/tests/gui/qt/helpers_test.h"
5151
"${CMAKE_SOURCE_DIR}/src/tests/gui/qt/tasks/non_blocking_test_task.h"
5252
"${CMAKE_SOURCE_DIR}/src/tests/gui/qt/tasks/tasks_test.h"
@@ -100,6 +100,7 @@ set(LOOT_GUI_TESTS_ALL_SOURCES
100100
"${CMAKE_SOURCE_DIR}/src/gui/sourced_message.h"
101101
"${CMAKE_SOURCE_DIR}/src/gui/qt/helpers.h"
102102
"${CMAKE_SOURCE_DIR}/src/gui/qt/tasks/tasks.h"
103+
"${CMAKE_SOURCE_DIR}/src/gui/state/change_count.h"
103104
"${CMAKE_SOURCE_DIR}/src/gui/state/game/detection/common.h"
104105
"${CMAKE_SOURCE_DIR}/src/gui/state/game/detection/detail.h"
105106
"${CMAKE_SOURCE_DIR}/src/gui/state/game/detection/epic_games_store.h"
@@ -120,8 +121,7 @@ set(LOOT_GUI_TESTS_ALL_SOURCES
120121
"${CMAKE_SOURCE_DIR}/src/gui/state/game/validation.h"
121122
"${CMAKE_SOURCE_DIR}/src/gui/state/loot_paths.h"
122123
"${CMAKE_SOURCE_DIR}/src/gui/state/loot_settings.h"
123-
"${CMAKE_SOURCE_DIR}/src/gui/state/loot_state.h"
124-
"${CMAKE_SOURCE_DIR}/src/gui/state/unapplied_change_counter.h")
124+
"${CMAKE_SOURCE_DIR}/src/gui/state/loot_state.h")
125125

126126
##############################
127127
# Define Targets

resources/l10n/template.pot

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: LOOT 0.25.2\n"
1010
"Report-Msgid-Bugs-To: https://github.com/loot/loot/issues\n"
11-
"POT-Creation-Date: 2025-04-03 20:52+0100\n"
11+
"POT-Creation-Date: 2025-04-03 21:42+0100\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -431,7 +431,7 @@ msgid "F&ilters"
431431
msgstr ""
432432

433433
#: src/gui/qt/main_window.cpp:1075 src/gui/qt/main_window.cpp:1528
434-
#: src/gui/qt/main_window.cpp:2152
434+
#: src/gui/qt/main_window.cpp:2154
435435
msgid "Updating and parsing masterlist…"
436436
msgstr ""
437437

@@ -632,41 +632,41 @@ msgstr ""
632632
msgid "About LOOT"
633633
msgstr ""
634634

635-
#: src/gui/qt/main_window.cpp:2362
635+
#: src/gui/qt/main_window.cpp:2364
636636
msgid "Identifying overlapping plugins…"
637637
msgstr ""
638638

639-
#: src/gui/qt/main_window.cpp:2510
639+
#: src/gui/qt/main_window.cpp:2512
640640
msgid ""
641641
"Auto-sort has been cancelled as there is at least one error message "
642642
"displayed."
643643
msgstr ""
644644

645-
#: src/gui/qt/main_window.cpp:2569
645+
#: src/gui/qt/main_window.cpp:2571
646646
msgid "No masterlist update was necessary."
647647
msgstr ""
648648

649-
#: src/gui/qt/main_window.cpp:2589
649+
#: src/gui/qt/main_window.cpp:2591
650650
#, c++-format
651651
msgid "Masterlist updated to revision {0}."
652652
msgstr ""
653653

654-
#: src/gui/qt/main_window.cpp:2653
654+
#: src/gui/qt/main_window.cpp:2655
655655
msgid "No masterlist updates were necessary."
656656
msgstr ""
657657

658-
#: src/gui/qt/main_window.cpp:2676
658+
#: src/gui/qt/main_window.cpp:2678
659659
msgid ""
660660
"Masterlists updated for the following games:\n"
661661
"\n"
662662
msgstr ""
663663

664-
#: src/gui/qt/main_window.cpp:2738
664+
#: src/gui/qt/main_window.cpp:2740
665665
#, c++-format
666666
msgid "A [new release]({0}) of LOOT is available."
667667
msgstr ""
668668

669-
#: src/gui/qt/main_window.cpp:2755
669+
#: src/gui/qt/main_window.cpp:2757
670670
msgid ""
671671
"Failed to check for LOOT updates! You can check your LOOTDebugLog.txt (you "
672672
"can get to it through the main menu) for more information."
@@ -1083,7 +1083,7 @@ msgstr ""
10831083
msgid "Add new game…"
10841084
msgstr ""
10851085

1086-
#: src/gui/query/types/apply_sort_query.h:76
1086+
#: src/gui/query/types/apply_sort_query.h:75
10871087
msgid ""
10881088
"Oh no, something went wrong! This is usually because \"{0}\" is set to be "
10891089
"read-only. If it is, unset it and try again. If it isn't, you can check your "
@@ -1118,49 +1118,49 @@ msgstr ""
11181118
msgid "Error: Game-specific settings could not be initialised. {0}"
11191119
msgstr ""
11201120

1121-
#: src/gui/state/loot_state.cpp:197
1121+
#: src/gui/state/loot_state.cpp:201
11221122
#, c++-format
11231123
msgid "Error: Could not create LOOT data directory. {0}"
11241124
msgstr ""
11251125

11261126
#. translators: This error is displayed when LOOT is unable to
11271127
#. load its own settings file. The placeholder is for additional
11281128
#. detail about what went wrong.
1129-
#: src/gui/state/loot_state.cpp:211 src/gui/state/loot_state.cpp:265
1129+
#: src/gui/state/loot_state.cpp:215 src/gui/state/loot_state.cpp:269
11301130
#, c++-format
11311131
msgid "Error: Settings parsing failed. {0}"
11321132
msgstr ""
11331133

11341134
#. translators: --auto-sort and --game are command-line arguments and
11351135
#. shouldn't be translated.
1136-
#: src/gui/state/loot_state.cpp:220
1136+
#: src/gui/state/loot_state.cpp:224
11371137
msgid "Error: --auto-sort was passed but no --game parameter was provided."
11381138
msgstr ""
11391139

1140-
#: src/gui/state/loot_state.cpp:306
1140+
#: src/gui/state/loot_state.cpp:310
11411141
#, c++-format
11421142
msgid "Error: Could not create LOOT prelude directory. {0}"
11431143
msgstr ""
11441144

11451145
#. translators: --game and --game-path are command-line arguments and
11461146
#. shouldn't be translated.
1147-
#: src/gui/state/loot_state.cpp:323
1147+
#: src/gui/state/loot_state.cpp:327
11481148
msgid "Error: --game-path was passed but no --game parameter was provided."
11491149
msgstr ""
11501150

1151-
#: src/gui/state/loot_state.cpp:336
1151+
#: src/gui/state/loot_state.cpp:340
11521152
#, c++-format
11531153
msgid "Error: failed to override game path, the game {0} was not recognised."
11541154
msgstr ""
11551155

1156-
#: src/gui/state/loot_state.cpp:370
1156+
#: src/gui/state/loot_state.cpp:374
11571157
msgid ""
11581158
"No supported games were detected. Try running the launcher(s) for the "
11591159
"supported game(s) that you have installed (e.g. press \"Play\" in Steam or "
11601160
"GOG Galaxy), then restarting LOOT."
11611161
msgstr ""
11621162

1163-
#: src/gui/state/loot_state.cpp:389
1163+
#: src/gui/state/loot_state.cpp:393
11641164
#, c++-format
11651165
msgid ""
11661166
"The initial game with folder name \"{0}\" could not be set. If it is "
@@ -1177,7 +1177,17 @@ msgstr ""
11771177
msgid "The group \"{0}\" does not exist."
11781178
msgstr ""
11791179

1180-
#: src/gui/state/game/game.cpp:570
1180+
#: src/gui/state/game/game.cpp:831
1181+
msgid ""
1182+
"Sorting failed because there is at least one installed plugin that depends "
1183+
"on at least one plugin that is not installed."
1184+
msgstr ""
1185+
1186+
#: src/gui/state/game/game.cpp:862
1187+
msgid "You have not sorted your load order this session."
1188+
msgstr ""
1189+
1190+
#: src/gui/state/game/game.cpp:940
11811191
#, c++-format
11821192
msgid ""
11831193
"An error occurred while parsing the metadata list(s): {0}.\n"
@@ -1196,17 +1206,7 @@ msgid ""
11961206
"[LOOT's website]({1})."
11971207
msgstr ""
11981208

1199-
#: src/gui/state/game/game.cpp:970
1200-
msgid ""
1201-
"Sorting failed because there is at least one installed plugin that depends "
1202-
"on at least one plugin that is not installed."
1203-
msgstr ""
1204-
1205-
#: src/gui/state/game/game.cpp:1007
1206-
msgid "You have not sorted your load order this session."
1207-
msgstr ""
1208-
1209-
#: src/gui/state/game/game.cpp:1127
1209+
#: src/gui/state/game/game.cpp:1115
12101210
msgid ""
12111211
"Failed to load the current load order, information displayed may be "
12121212
"incorrect."

src/gui/qt/main_window.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,7 @@ void MainWindow::sortPlugins(bool isAutoSort) {
10971097

10981098
std::unique_ptr<Query> sortPluginsQuery =
10991099
std::make_unique<SortPluginsQuery>(state.GetCurrentGame(),
1100-
state,
1100+
state.GetUnappliedChangeCount(),
11011101
state.getSettings().getLanguage(),
11021102
sendProgressUpdate);
11031103

@@ -1247,7 +1247,7 @@ PluginItem MainWindow::getSelectedPlugin() const {
12471247
}
12481248

12491249
void MainWindow::closeEvent(QCloseEvent* event) {
1250-
if (state.HasUnappliedChanges()) {
1250+
if (state.GetUnappliedChangeCount().IsNonZero()) {
12511251
auto changeType = pluginEditorWidget->isVisible()
12521252
? boost::locale::translate("metadata edits")
12531253
: boost::locale::translate("sorted load order");
@@ -1418,7 +1418,7 @@ bool MainWindow::handlePluginsSorted(QueryResult result) {
14181418
if (loadOrderHasChanged) {
14191419
enterSortingState();
14201420
} else {
1421-
state.DecrementUnappliedChangeCounter();
1421+
state.GetUnappliedChangeCount().Decrement();
14221422

14231423
const auto message =
14241424
translate("Sorting made no changes to the load order.");
@@ -1789,7 +1789,7 @@ void MainWindow::on_actionEditMetadata_triggered() {
17891789

17901790
pluginEditorWidget->show();
17911791

1792-
state.IncrementUnappliedChangeCounter();
1792+
state.GetUnappliedChangeCount().Increment();
17931793

17941794
// Refresh the sidebar items so that all their groups are displayed.
17951795
pluginItemModel->setEditorPluginName(selectedPluginName);
@@ -2086,8 +2086,9 @@ void MainWindow::on_actionApplySort_triggered() {
20862086
try {
20872087
auto sortedPluginNames = pluginItemModel->getPluginNames();
20882088

2089-
auto query =
2090-
ApplySortQuery<>(state.GetCurrentGame(), state, sortedPluginNames);
2089+
auto query = ApplySortQuery(state.GetCurrentGame(),
2090+
state.GetUnappliedChangeCount(),
2091+
sortedPluginNames);
20912092

20922093
try {
20932094
query.executeLogic();
@@ -2109,7 +2110,8 @@ void MainWindow::on_actionApplySort_triggered() {
21092110

21102111
void MainWindow::on_actionDiscardSort_triggered() {
21112112
try {
2112-
auto query = CancelSortQuery(state.GetCurrentGame(), state);
2113+
auto query = CancelSortQuery(state.GetCurrentGame(),
2114+
state.GetUnappliedChangeCount());
21132115

21142116
auto result = query.executeLogic();
21152117

@@ -2326,7 +2328,7 @@ void MainWindow::on_pluginEditorWidget_accepted(PluginMetadata userMetadata) {
23262328

23272329
refreshPluginRawData(pluginName);
23282330

2329-
state.DecrementUnappliedChangeCounter();
2331+
state.GetUnappliedChangeCount().Decrement();
23302332

23312333
exitEditingState();
23322334
} catch (const std::exception& e) {
@@ -2335,7 +2337,7 @@ void MainWindow::on_pluginEditorWidget_accepted(PluginMetadata userMetadata) {
23352337
}
23362338

23372339
void MainWindow::on_pluginEditorWidget_rejected() {
2338-
state.DecrementUnappliedChangeCounter();
2340+
state.GetUnappliedChangeCount().Decrement();
23392341

23402342
pluginItemModel->setEditorPluginName(std::nullopt);
23412343

src/gui/query/types/apply_sort_query.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,21 @@ along with LOOT. If not, see
3232
#include "gui/query/query.h"
3333

3434
namespace loot {
35-
template<typename G = gui::Game>
3635
class ApplySortQuery : public Query {
3736
public:
38-
ApplySortQuery(G& game,
39-
UnappliedChangeCounter& counter,
37+
ApplySortQuery(gui::Game& game,
38+
ChangeCount& counter,
4039
const std::vector<std::string>& plugins) :
41-
game_(game), counter_(counter), plugins_(plugins) {}
40+
game_(&game), counter_(&counter), plugins_(plugins) {}
4241

4342
QueryResult executeLogic() override {
4443
auto logger = getLogger();
4544
if (logger) {
4645
logger->trace("User has accepted sorted load order, applying it.");
4746
}
4847
try {
49-
game_.SetLoadOrder(plugins_);
50-
counter_.DecrementUnappliedChangeCounter();
48+
game_->SetLoadOrder(plugins_);
49+
counter_->Decrement();
5150
} catch (...) {
5251
useSortingErrorMessage = true;
5352
throw;
@@ -58,19 +57,19 @@ class ApplySortQuery : public Query {
5857

5958
std::string getErrorMessage() const override {
6059
if (useSortingErrorMessage) {
61-
return getSortingErrorMessage(game_);
60+
return getSortingErrorMessage(*game_);
6261
}
6362

6463
return Query::getErrorMessage();
6564
}
6665

6766
private:
68-
G& game_;
69-
UnappliedChangeCounter& counter_;
67+
gui::Game* game_;
68+
ChangeCount* counter_;
7069
const std::vector<std::string> plugins_;
7170
bool useSortingErrorMessage{false};
7271

73-
std::string getSortingErrorMessage(const G& game) const {
72+
std::string getSortingErrorMessage(const gui::Game& game) const {
7473
return fmt::format(
7574
boost::locale::translate(
7675
"Oh no, something went wrong! This is usually because \"{0}\" "

src/gui/query/types/cancel_sort_query.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ along with LOOT. If not, see
3434
namespace loot {
3535
class CancelSortQuery : public Query {
3636
public:
37-
CancelSortQuery(gui::Game& game, UnappliedChangeCounter& counter) :
38-
game_(game), counter_(counter) {}
37+
CancelSortQuery(gui::Game& game, ChangeCount& counter) :
38+
game_(&game), counter_(&counter) {}
3939

4040
QueryResult executeLogic() override {
4141
auto logger = getLogger();
4242
if (logger) {
4343
logger->trace("User has rejected sorted load order, discarding it.");
4444
}
4545

46-
counter_.DecrementUnappliedChangeCounter();
47-
game_.DecrementLoadOrderSortCount();
46+
counter_->Decrement();
47+
game_->DecrementLoadOrderSortCount();
4848

4949
const std::function<std::pair<std::string, std::optional<short>>(
5050
const PluginInterface* const, std::optional<short>, bool)>
@@ -54,12 +54,12 @@ class CancelSortQuery : public Query {
5454
return std::make_pair(plugin->GetName(), loadOrderIndex);
5555
};
5656

57-
return MapFromLoadOrderData(game_, game_.GetLoadOrder(), mapper);
57+
return MapFromLoadOrderData(*game_, game_->GetLoadOrder(), mapper);
5858
}
5959

6060
private:
61-
gui::Game& game_;
62-
UnappliedChangeCounter& counter_;
61+
gui::Game* game_;
62+
ChangeCount* counter_;
6363
};
6464
}
6565

0 commit comments

Comments
 (0)