1818#include " debug.hpp"
1919
2020TombRaiderLinuxLauncher::TombRaiderLinuxLauncher (QWidget *parent)
21- :QMainWindow(parent),
22- ui( new Ui::TombRaiderLinuxLauncher) {
21+ : QMainWindow(parent) {
22+ ui = new Ui::TombRaiderLinuxLauncher;
2323 ui->setupUi (this );
2424
2525 // Button signal connections
@@ -105,10 +105,11 @@ TombRaiderLinuxLauncher::TombRaiderLinuxLauncher(QWidget *parent)
105105
106106 // Read settings
107107 QString value = m_settings.value (" setup" ).toString ();
108- if (value != " yes" )
108+ if (value != " yes" ) {
109109 setup ();
110- else
110+ } else {
111111 readSavedSettings ();
112+ }
112113}
113114
114115void TombRaiderLinuxLauncher::generateList (const QList<int >& availableGames) {
@@ -189,7 +190,7 @@ void TombRaiderLinuxLauncher::sortItems(
189190 QList<QListWidgetItem*> items;
190191
191192 // Step 1: Extract items from the QListWidget
192- if (ui->checkBoxOriginalFirst ->isChecked ()) {
193+ if (ui->checkBoxOriginalFirst ->isChecked () == true ) {
193194 for (int i = 0 ; i < ui->listWidgetModds ->count (); ++i) {
194195 QListWidgetItem* item = ui->listWidgetModds ->item (i);
195196 // Append the item only if it's not in originalGamesSet_m
@@ -207,92 +208,108 @@ void TombRaiderLinuxLauncher::sortItems(
207208 std::sort (items.begin (), items.end (), compare);
208209
209210 // Step 3: Adjust the position of each item without clearing the list
210- qint64 s =
211+ qint64 originalGamesSize =
211212 ui->checkBoxOriginalFirst ->isChecked () ? originalGamesList_m.size () : 0 ;
212213
213- for (int i = 0 ; i < s + items.size (); ++i) {
214+ qint64 size = originalGamesSize + items.size ();
215+ for (qint64 i = 0 ; i < size; ++i) {
214216 QListWidgetItem* item;
215- if (i < s ) {
217+ if (i < originalGamesSize ) {
216218 // Handle originalGamesList_m items
217219 item = ui->listWidgetModds ->takeItem (
218220 ui->listWidgetModds ->row (originalGamesList_m[i]));
219221 ui->listWidgetModds ->insertItem (i, item);
220222 } else {
221223 // Handle items list
222224 item = ui->listWidgetModds ->takeItem (
223- ui->listWidgetModds ->row (items[i - s ]));
225+ ui->listWidgetModds ->row (items[i - originalGamesSize ]));
224226 ui->listWidgetModds ->insertItem (i, item);
225227 }
226228 }
227229}
228230
231+ bool compareTitles (QListWidgetItem* a, QListWidgetItem* b) {
232+ const QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
233+ const QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
234+
235+ return aData.value (" title" ).toString ().toLower ()
236+ < bData.value (" title" ).toString ().toLower ();
237+ }
238+
239+ bool compareAuthors (QListWidgetItem* a, QListWidgetItem* b) {
240+ const QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
241+ const QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
242+ return aData.value (" author" ).toString ().toLower ()
243+ < bData.value (" author" ).toString ().toLower ();
244+ }
245+
246+ bool compareDifficulties (QListWidgetItem* a, QListWidgetItem* b) {
247+ const QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
248+ const QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
249+ return aData.value (" difficulty" ).toInt ()
250+ > bData.value (" difficulty" ).toInt ();
251+ }
252+
253+ bool compareDurations (QListWidgetItem* a, QListWidgetItem* b) {
254+ const QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
255+ const QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
256+ return aData.value (" duration" ).toInt ()
257+ > bData.value (" duration" ).toInt ();
258+ }
259+
260+ bool compareClasses (QListWidgetItem* a, QListWidgetItem* b) {
261+ const QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
262+ const QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
263+ return aData.value (" class_" ).toInt ()
264+ > bData.value (" class_" ).toInt ();
265+ }
266+
267+ bool compareTypes (QListWidgetItem* a, QListWidgetItem* b) {
268+ const QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
269+ const QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
270+ return aData.value (" type" ).toInt ()
271+ > bData.value (" type" ).toInt ();
272+ }
273+
274+ bool compareReleaseDates (QListWidgetItem* a, QListWidgetItem* b) {
275+ const QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
276+ const QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
277+
278+ const QDate dateA = QDate::fromString (
279+ aData.value (" releaseDate" ).toString (), " dd-MMM-yyyy" );
280+ const QDate dateB = QDate::fromString (
281+ bData.value (" releaseDate" ).toString (), " dd-MMM-yyyy" );
282+
283+ return dateA > dateB; // descending order
284+ }
285+
286+
229287void TombRaiderLinuxLauncher::sortByTitle () {
230- sortItems ([](QListWidgetItem* a, QListWidgetItem* b) {
231- QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
232- QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
233- return aData[" title" ].toString ().toLower () <
234- bData[" title" ].toString ().toLower ();
235- });
288+ sortItems (compareTitles);
236289}
237290
238291void TombRaiderLinuxLauncher::sortByAuthor () {
239- sortItems ([](QListWidgetItem* a, QListWidgetItem* b) {
240- QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
241- QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
242- return aData[" author" ].toString ().toLower () <
243- bData[" author" ].toString ().toLower ();
244- });
292+ sortItems (compareAuthors);
245293}
246294
247295void TombRaiderLinuxLauncher::sortByDifficulty () {
248- sortItems ([](QListWidgetItem* a, QListWidgetItem* b) {
249- QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
250- QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
251- return aData[" difficulty" ].toInt () >
252- bData[" difficulty" ].toInt ();
253- });
296+ sortItems (compareDifficulties);
254297}
255298
256299void TombRaiderLinuxLauncher::sortByDuration () {
257- sortItems ([](QListWidgetItem* a, QListWidgetItem* b) {
258- QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
259- QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
260- return aData[" duration" ].toInt () >
261- bData[" duration" ].toInt ();
262- });
300+ sortItems (compareDurations);
263301}
264302
265303void TombRaiderLinuxLauncher::sortByClass () {
266- sortItems ([](QListWidgetItem* a, QListWidgetItem* b) {
267- QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
268- QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
269- return aData[" class_" ].toInt () >
270- bData[" class_" ].toInt ();
271- });
304+ sortItems (compareClasses);
272305}
273306
274307void TombRaiderLinuxLauncher::sortByType () {
275- sortItems ([](QListWidgetItem* a, QListWidgetItem* b) {
276- QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
277- QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
278- return aData[" type" ].toInt () >
279- bData[" type" ].toInt ();
280- });
308+ sortItems (compareTypes);
281309}
282310
283311void TombRaiderLinuxLauncher::sortByReleaseDate () {
284- sortItems ([](QListWidgetItem* a, QListWidgetItem* b) {
285- QVariantMap aData = a->data (Qt::UserRole + 1 ).toMap ();
286- QVariantMap bData = b->data (Qt::UserRole + 1 ).toMap ();
287-
288- // Parse dates using QDate::fromString
289- QDate dateA = QDate::fromString (
290- aData[" releaseDate" ].toString (), " dd-MMM-yyyy" );
291- QDate dateB = QDate::fromString (
292- bData[" releaseDate" ].toString (), " dd-MMM-yyyy" );
293-
294- return dateA > dateB; // descending order
295- });
312+ sortItems (compareReleaseDates);
296313}
297314
298315void TombRaiderLinuxLauncher::readSavedSettings () {
@@ -324,7 +341,7 @@ void TombRaiderLinuxLauncher::setup() {
324341}
325342
326343void TombRaiderLinuxLauncher::originalSelected (QListWidgetItem *selectedItem) {
327- if (selectedItem) {
344+ if (selectedItem != nullptr ) {
328345 int id = selectedItem->data (Qt::UserRole).toInt ();
329346 bool linkedGameDir = selectedItem->data (Qt::UserRole + 1 ).toBool ();
330347 // the game dirr was a symbolic link and it has a level dir
@@ -340,7 +357,7 @@ void TombRaiderLinuxLauncher::originalSelected(QListWidgetItem *selectedItem) {
340357}
341358
342359void TombRaiderLinuxLauncher::levelDirSelected (QListWidgetItem *selectedItem) {
343- if (selectedItem) {
360+ if (selectedItem != nullptr ) {
344361 int id = selectedItem->data (Qt::UserRole).toInt ();
345362 int state = controller.getItemState (id);
346363 // Activate or deactivate pushbuttons based on the selected item
@@ -372,7 +389,7 @@ void TombRaiderLinuxLauncher::levelDirSelected(QListWidgetItem *selectedItem) {
372389
373390void TombRaiderLinuxLauncher::onListItemSelected () {
374391 QListWidgetItem *selectedItem = ui->listWidgetModds ->currentItem ();
375- if (selectedItem) {
392+ if (selectedItem != nullptr ) {
376393 int id = selectedItem->data (Qt::UserRole).toInt ();
377394 if (id < 0 ) { // its the original game
378395 originalSelected (selectedItem);
@@ -408,7 +425,7 @@ void TombRaiderLinuxLauncher::linkClicked() {
408425 bool status = false ;
409426 QListWidgetItem *selectedItem = ui->listWidgetModds ->currentItem ();
410427 int id = selectedItem->data (Qt::UserRole).toInt ();
411- if (id) {
428+ if (id != 0 ) {
412429 status = controller.link (id);
413430 } else {
414431 qDebug () << " id error" ;
@@ -442,7 +459,7 @@ void TombRaiderLinuxLauncher::downloadClicked() {
442459void TombRaiderLinuxLauncher::infoClicked () {
443460 QListWidgetItem *selectedItem = ui->listWidgetModds ->currentItem ();
444461 int id = selectedItem->data (Qt::UserRole).toInt ();
445- if (id) {
462+ if (id != 0 ) {
446463 InfoData info = controller.getInfo (id);
447464 ui->infoWebEngineView ->setHtml (info.m_body );
448465 ui->infoListWidget ->setViewMode (QListView::IconMode);
@@ -472,7 +489,7 @@ void TombRaiderLinuxLauncher::infoClicked() {
472489void TombRaiderLinuxLauncher::walkthroughClicked () {
473490 QListWidgetItem *selectedItem = ui->listWidgetModds ->currentItem ();
474491 int id = selectedItem->data (Qt::UserRole).toInt ();
475- if (id) {
492+ if (id != 0 ) {
476493 ui->walkthroughWebEngineView ->setHtml (controller.getWalkthrough (id));
477494 ui->walkthroughWebEngineView ->show ();
478495 ui->stackedWidget ->setCurrentWidget (
0 commit comments