summarylogtreecommitdiffstats
path: root/0001-fix-Fix-building-prismlauncher-7.2-on-Qt-6.6.0.patch
blob: 49a778e08477d9953dfadf2ffd623b2926f532b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
From 8e54a071009c1e4a7efc7b1e974e588e9c26646e Mon Sep 17 00:00:00 2001
From: txtsd <code@ihavea.quest>
Date: Sat, 21 Oct 2023 01:49:51 +0530
Subject: [PATCH] fix: Fix building prismlauncher 7.2 on Qt 6.6.0

Signed-off-by: txtsd <code@ihavea.quest>
---
 launcher/translations/TranslationsModel.cpp | 42 ++++++++++-----------
 launcher/translations/TranslationsModel.h   |  4 +-
 2 files changed, 22 insertions(+), 24 deletions(-)

diff --git a/launcher/translations/TranslationsModel.cpp b/launcher/translations/TranslationsModel.cpp
index 2763cca26..fe9752b9f 100644
--- a/launcher/translations/TranslationsModel.cpp
+++ b/launcher/translations/TranslationsModel.cpp
@@ -242,7 +242,7 @@ void TranslationsModel::indexReceived()
         reloadLocalFiles();
 
         auto language = d->m_system_locale;
-        if (!findLanguage(language))
+        if (!findLanguageAsOptional(language).has_value())
         {
             language = d->m_system_language;
         }
@@ -512,20 +512,17 @@ int TranslationsModel::columnCount(const QModelIndex& parent) const
     return 2;
 }
 
-Language * TranslationsModel::findLanguage(const QString& key)
+QVector<Language>::Iterator TranslationsModel::findLanguage(const QString& key)
 {
-    auto found = std::find_if(d->m_languages.begin(), d->m_languages.end(), [&](Language & lang)
-    {
-        return lang.key == key;
-    });
-    if(found == d->m_languages.end())
-    {
-        return nullptr;
-    }
-    else
-    {
-        return found;
-    }
+    return std::find_if(d->m_languages.begin(), d->m_languages.end(), [&](Language& lang) { return lang.key == key; });
+}
+
+std::optional<Language> TranslationsModel::findLanguageAsOptional(const QString& key)
+{
+    auto found = findLanguage(key);
+    if (found != d->m_languages.end())
+        return *found;
+    return {};
 }
 
 void TranslationsModel::setUseSystemLocale(bool useSystemLocale)
@@ -537,13 +534,13 @@ void TranslationsModel::setUseSystemLocale(bool useSystemLocale)
 bool TranslationsModel::selectLanguage(QString key)
 {
     QString& langCode = key;
-    auto langPtr = findLanguage(key);
+    auto langPtr = findLanguageAsOptional(key);
 
     if (langCode.isEmpty()) {
         d->no_language_set = true;
     }
 
-    if (!langPtr) {
+    if (!langPtr.has_value()) {
         qWarning() << "Selected invalid language" << key << ", defaulting to" << defaultLangCode;
         langCode = defaultLangCode;
     } else {
@@ -653,10 +650,9 @@ bool TranslationsModel::selectLanguage(QString key)
 QModelIndex TranslationsModel::selectedIndex()
 {
     auto found = findLanguage(d->m_selectedLanguage);
-    if(found)
+    if(found != d->m_languages.end())
     {
-        // QVector iterator freely converts to pointer to contained type
-        return index(found - d->m_languages.begin(), 0, QModelIndex());
+        return index(std::distance(d->m_languages.begin(), found), 0, QModelIndex());
     }
     return QModelIndex();
 }
@@ -691,8 +687,8 @@ void TranslationsModel::updateLanguage(QString key)
         qWarning() << "Cannot update builtin language" << key;
         return;
     }
-    auto found = findLanguage(key);
-    if(!found)
+    auto found = findLanguageAsOptional(key);
+    if(!found.has_value())
     {
         qWarning() << "Cannot update invalid language" << key;
         return;
@@ -710,8 +706,8 @@ void TranslationsModel::downloadTranslation(QString key)
         d->m_nextDownload = key;
         return;
     }
-    auto lang = findLanguage(key);
-    if(!lang)
+    auto lang = findLanguageAsOptional(key);
+    if(!lang.has_value())
     {
         qWarning() << "Will not download an unknown translation" << key;
         return;
diff --git a/launcher/translations/TranslationsModel.h b/launcher/translations/TranslationsModel.h
index cff23ce74..96a0e9f8b 100644
--- a/launcher/translations/TranslationsModel.h
+++ b/launcher/translations/TranslationsModel.h
@@ -17,6 +17,7 @@
 
 #include <QAbstractListModel>
 #include <memory>
+#include <optional>
 
 struct Language;
 
@@ -40,7 +41,8 @@ class TranslationsModel : public QAbstractListModel {
     void setUseSystemLocale(bool useSystemLocale);
 
    private:
-    Language* findLanguage(const QString& key);
+    QVector<Language>::Iterator findLanguage(const QString& key);
+    std::optional<Language> findLanguageAsOptional(const QString& key);
     void reloadLocalFiles();
     void downloadTranslation(QString key);
     void downloadNext();
-- 
2.42.0