--- a/QTfrontend/ui/page/pagetraining.cpp Thu Oct 20 05:52:11 2011 +0200
+++ b/QTfrontend/ui/page/pagetraining.cpp Thu Oct 20 13:10:24 2011 +0200
@@ -27,8 +27,11 @@
#include <QLocale>
#include <QSettings>
+#include "hwconsts.h"
+
+#include "HWDataManager.h"
+
#include "pagetraining.h"
-#include "hwconsts.h"
QLayout * PageTraining::bodyLayoutDefinition()
{
@@ -120,41 +123,40 @@
if (loc.isEmpty())
loc = QLocale::system().name();
- QString infoFile =
- datadir->absolutePath() + "/Locale/missions_" + loc + ".txt";
+ QFile * infoFile = HWDataManager::instance().findFileForRead(QString(
+ "Locale/missions_" + loc + ".txt"));
// if file is non-existant try with language only
- if (!QFile::exists(infoFile))
- infoFile = datadir->absolutePath() + "/Locale/missions_" +
- loc.replace(QRegExp("_.*$"),"") + ".txt";
+ if (!infoFile->exists())
+ {
+ delete infoFile;
+ infoFile = HWDataManager::instance().findFileForRead(QString(
+ "Locale/missions_" + loc.replace(QRegExp("_.*$"),"") + ".txt"));
+ }
// fallback if file for current locale is non-existant
- if (!QFile::exists(infoFile))
- infoFile = datadir->absolutePath() + "/Locale/missions_en.txt";
+ if (!infoFile->exists())
+ {
+ delete infoFile;
+ infoFile = HWDataManager::instance().findFileForRead(QString(
+ "Locale/missions_en.txt"));
+ }
+
// preload mission info for current locale
- m_info = new QSettings(infoFile, QSettings::IniFormat, this);
+ m_info =
+ new QSettings(infoFile->fileName(), QSettings::IniFormat, this);
-// TODO -> this should be done in a tool "DataDir" class
- QDir tmpdir;
- tmpdir.cd(cfgdir->absolutePath());
- tmpdir.cd("Data/Missions/Training");
- QStringList missionList = scriptList(tmpdir);
- missionList.sort();
+ // we don't need infoFile anymore
+ delete infoFile;
- tmpdir.cd(datadir->absolutePath());
- tmpdir.cd("Missions/Training");
- QStringList defaultList = scriptList(tmpdir);
- defaultList.sort();
+ QStringList missionList =
+ HWDataManager::instance().entryList(QString("Missions/Training"),
+ QDir::Files,
+ QStringList("*.lua")
+ ).replaceInStrings(QRegExp("\\.lua$"), "");
- // add non-duplicate default scripts to the list
- foreach (const QString & mission, defaultList)
- {
- if (!missionList.contains(mission))
- missionList.append(mission);
- }
-
- // add default scripts that have names different from detected user scripts
+ // scripts to lost - TODO: model?
foreach (const QString & mission, missionList)
{
QListWidgetItem * item = new QListWidgetItem(mission);
@@ -180,13 +182,6 @@
lstMissions->setCurrentRow(0);
}
-QStringList PageTraining::scriptList(const QDir & scriptDir) const
-{
- QDir dir = scriptDir;
- dir.setFilter(QDir::Files);
- return dir.entryList(QStringList("*.lua")).replaceInStrings(QRegExp("^(.*)\\.lua"), "\\1");
-}
-
void PageTraining::startSelected()
{