121 |
121 |
122 QString loc = settings.value("misc/locale", "").toString(); |
122 QString loc = settings.value("misc/locale", "").toString(); |
123 if (loc.isEmpty()) |
123 if (loc.isEmpty()) |
124 loc = QLocale::system().name(); |
124 loc = QLocale::system().name(); |
125 |
125 |
126 QFile * infoFile = HWDataManager::instance().findFileForRead(QString( |
126 QFile * infoFile = HWDataManager::instance().findFileForRead( |
127 "Locale/missions_" + loc + ".txt")); |
127 QString("Locale/missions_" + loc + ".txt")); |
128 |
128 |
129 // if file is non-existant try with language only |
129 // if file is non-existant try with language only |
130 if (!infoFile->exists()) |
130 if (!infoFile->exists()) |
131 { |
131 { |
132 delete infoFile; |
132 delete infoFile; |
133 infoFile = HWDataManager::instance().findFileForRead(QString( |
133 infoFile = HWDataManager::instance().findFileForRead(QString( |
134 "Locale/missions_" + loc.replace(QRegExp("_.*$"),"") + ".txt")); |
134 "Locale/missions_" + loc.remove(QRegExp("_.*$")) + ".txt")); |
135 } |
135 } |
136 |
136 |
137 // fallback if file for current locale is non-existant |
137 // fallback if file for current locale is non-existant |
138 if (!infoFile->exists()) |
138 if (!infoFile->exists()) |
139 { |
139 { |
140 delete infoFile; |
140 delete infoFile; |
141 infoFile = HWDataManager::instance().findFileForRead(QString( |
141 infoFile = HWDataManager::instance().findFileForRead( |
142 "Locale/missions_en.txt")); |
142 QString("Locale/missions_en.txt")); |
143 } |
143 } |
144 |
144 |
145 |
145 |
146 // preload mission info for current locale |
146 // preload mission info for current locale |
147 m_info = |
147 m_info = |
148 new QSettings(infoFile->fileName(), QSettings::IniFormat, this); |
148 new QSettings(infoFile->fileName(), QSettings::IniFormat, this); |
149 |
149 |
150 // we don't need infoFile anymore |
150 // this QFile isn't needed any further |
151 delete infoFile; |
151 delete infoFile; |
152 |
152 |
153 QStringList missionList = |
153 QStringList missionList = |
154 HWDataManager::instance().entryList(QString("Missions/Training"), |
154 HWDataManager::instance().entryList( |
155 QDir::Files, |
155 "Missions/Training", |
156 QStringList("*.lua") |
156 QDir::Files, |
157 ).replaceInStrings(QRegExp("\\.lua$"), ""); |
157 QStringList("*.lua") |
|
158 ).replaceInStrings(QRegExp("\\.lua$"), ""); |
158 |
159 |
159 // scripts to lost - TODO: model? |
160 // scripts to lost - TODO: model? |
160 foreach (const QString & mission, missionList) |
161 foreach (const QString & mission, missionList) |
161 { |
162 { |
162 QListWidgetItem * item = new QListWidgetItem(mission); |
163 QListWidgetItem * item = new QListWidgetItem(mission); |
163 |
164 |
164 // fallback name: replace underscores in mission name with spaces |
165 // fallback name: replace underscores in mission name with spaces |
165 QString name = item->text().replace("_", " "); |
166 QString name = item->text().remove("_"); |
166 |
167 |
167 // see if we can get a prettier/translated name |
168 // see if we can get a prettier/translated name |
168 name = m_info->value(mission + ".name", name).toString(); |
169 name = m_info->value(mission + ".name", name).toString(); |
169 |
170 |
170 item->setText(name); |
171 item->setText(name); |