--- a/QTfrontend/main.cpp Mon Oct 24 06:10:28 2011 +0200
+++ b/QTfrontend/main.cpp Mon Oct 24 06:54:46 2011 +0200
@@ -186,10 +186,12 @@
}
}
+ HWDataManager & dataMgr = HWDataManager::instance();
+
{
QStringList themes;
- themes.append(HWDataManager::instance().entryList(
+ themes.append(dataMgr.entryList(
"Themes",
QDir::AllDirs | QDir::NoDotAndDotDot)
);
@@ -199,7 +201,7 @@
themes.sort();
for(int i = themes.size() - 1; i >= 0; --i)
{
- QString file = HWDataManager::instance().findFileForRead(
+ QString file = dataMgr.findFileForRead(
QString("Themes/%1/icon.png").arg(themes.at(i))
);
@@ -210,7 +212,7 @@
// load preview icon
ic.second = QIcon(
- HWDataManager::instance().findFileForRead(
+ dataMgr.findFileForRead(
QString("Themes/%1/icon@2x.png").arg(themes.at(i))
)
);
@@ -232,13 +234,13 @@
}
}
- mapList = new QStringList(HWDataManager::instance().entryList(
+ mapList = new QStringList(dataMgr.entryList(
QString("Maps"),
QDir::Dirs | QDir::NoDotAndDotDot
)
);
- scriptList = new QStringList(HWDataManager::instance().entryList(
+ scriptList = new QStringList(dataMgr.entryList(
QString("Scripts/Multiplayer"),
QDir::Files,
QStringList("*.lua")
@@ -254,7 +256,7 @@
// load locale file into translator
Translator.load(
- HWDataManager::instance().findFileForRead(
+ dataMgr.findFileForRead(
QString("Locale/hedgewars_" + cc)
)
);
@@ -278,7 +280,7 @@
QString style = "";
// load external stylesheet if there is any
- QFile extFile(HWDataManager::instance().findFileForRead("css/qt.css"));
+ QFile extFile(dataMgr.findFileForRead("css/qt.css"));
QFile resFile(":/res/css/qt.css");
--- a/QTfrontend/model/hats.cpp Mon Oct 24 06:10:28 2011 +0200
+++ b/QTfrontend/model/hats.cpp Mon Oct 24 06:54:46 2011 +0200
@@ -28,12 +28,14 @@
HatsModel::HatsModel(QObject* parent) :
QAbstractListModel(parent)
{
+ HWDataManager & dataMgr = HWDataManager::instance();
+
QPixmap hhpix = QPixmap(
- HWDataManager::instance().findFileForRead("Graphics/Hedgehog/Idle.png")
+ dataMgr.findFileForRead("Graphics/Hedgehog/Idle.png")
).copy(0, 0, 32, 32);
// my reserved hats
- QStringList hatsList = HWDataManager::instance().entryList(
+ QStringList hatsList = dataMgr.entryList(
"Graphics/Hats/Reserved",
QDir::Files,
QStringList(playerHash+"*.png")
@@ -42,7 +44,7 @@
int nReserved = hatsList.size();
// regular hats
- hatsList.append(HWDataManager::instance().entryList(
+ hatsList.append(dataMgr.entryList(
"Graphics/Hats",
QDir::Files,
QStringList("*.png")
@@ -59,7 +61,7 @@
QString str = hatsList.at(i);
str = str.remove(QRegExp("\\.png$"));
QPixmap pix(
- HWDataManager::instance().findFileForRead(
+ dataMgr.findFileForRead(
"Graphics/Hats/" + QString(isReserved?"Reserved/":"") + str +
".png"
)
--- a/QTfrontend/ui/page/pageeditteam.cpp Mon Oct 24 06:10:28 2011 +0200
+++ b/QTfrontend/ui/page/pageeditteam.cpp Mon Oct 24 06:54:46 2011 +0200
@@ -27,13 +27,15 @@
#include <QToolBox>
#include <QMessageBox>
-#include "pageeditteam.h"
#include "sdlkeys.h"
#include "SquareLabel.h"
#include "hats.h"
#include "HWApplication.h"
+
#include "HWDataManager.h"
+#include "pageeditteam.h"
+
QLayout * PageEditTeam::bodyLayoutDefinition()
{
QGridLayout * pageLayout = new QGridLayout();
@@ -336,18 +338,18 @@
void PageEditTeam::CBFort_activated(const QString & fortname)
{
- QFile tmp;
- tmp.setFileName(cfgdir->absolutePath() + "/Data/Forts/" + fortname + "L.png");
- if (!tmp.exists()) tmp.setFileName(datadir->absolutePath() + "/Forts/" + fortname + "L.png");
- QPixmap pix(QFileInfo(tmp).absoluteFilePath());
+ HWDataManager & dataMgr = HWDataManager::instance();
+ QPixmap pix(dataMgr.findFileForRead("Forts/" + fortname + "L.png"));
FortPreview->setPixmap(pix);
}
void PageEditTeam::testSound()
{
+ HWDataManager & dataMgr = HWDataManager::instance();
+
QString voiceDir = QString("Sounds/voices/") + CBVoicepack->currentText();
- QStringList list = HWDataManager::instance().entryList(
+ QStringList list = dataMgr.entryList(
voiceDir,
QDir::Files,
QStringList() <<
@@ -360,7 +362,7 @@
if (!list.isEmpty())
SDLInteraction::instance().playSoundFile(
- HWDataManager::instance().findFileForRead(voiceDir + "/" +
+ dataMgr.findFileForRead(voiceDir + "/" +
list[rand() % list.size()])
);
}
--- a/QTfrontend/ui/page/pageeditteam.h Mon Oct 24 06:10:28 2011 +0200
+++ b/QTfrontend/ui/page/pageeditteam.h Mon Oct 24 06:54:46 2011 +0200
@@ -22,7 +22,6 @@
#include "AbstractPage.h"
#include "binds.h"
#include "hwconsts.h"
-#include "HWDataManager.h"
#include "namegen.h"
#include "SDLInteraction.h"
--- a/QTfrontend/ui/page/pagetraining.cpp Mon Oct 24 06:10:28 2011 +0200
+++ b/QTfrontend/ui/page/pagetraining.cpp Mon Oct 24 06:54:46 2011 +0200
@@ -28,7 +28,6 @@
#include <QSettings>
#include "hwconsts.h"
-
#include "HWDataManager.h"
#include "pagetraining.h"
@@ -115,6 +114,8 @@
{
initPage();
+ HWDataManager & dataMgr = HWDataManager::instance();
+
// get locale
QSettings settings(cfgdir->absolutePath() + "/hedgewars.ini",
QSettings::IniFormat);
@@ -123,32 +124,27 @@
if (loc.isEmpty())
loc = QLocale::system().name();
- QString infoFile = HWDataManager::instance().findFileForRead(
+ QString infoFile = dataMgr.findFileForRead(
QString("Locale/missions_" + loc + ".txt"));
// if file is non-existant try with language only
if (!QFile::exists(infoFile))
- infoFile = HWDataManager::instance().findFileForRead(QString(
+ infoFile = dataMgr.findFileForRead(QString(
"Locale/missions_" + loc.remove(QRegExp("_.*$")) + ".txt"));
// fallback if file for current locale is non-existant
if (!QFile::exists(infoFile))
- {
- infoFile = HWDataManager::instance().findFileForRead(
- QString("Locale/missions_en.txt"));
- }
+ infoFile = dataMgr.findFileForRead(QString("Locale/missions_en.txt"));
// preload mission info for current locale
m_info = new QSettings(infoFile, QSettings::IniFormat, this);
- QStringList missionList =
- HWDataManager::instance().entryList(
- "Missions/Training",
- QDir::Files,
- QStringList("*.lua")
- ).replaceInStrings(QRegExp("\\.lua$"), "");
+ QStringList missionList = dataMgr.entryList(
+ "Missions/Training",
+ QDir::Files, QStringList("*.lua")).
+ replaceInStrings(QRegExp("\\.lua$"), "");
// scripts to lost - TODO: model?
foreach (const QString & mission, missionList)
@@ -156,7 +152,7 @@
QListWidgetItem * item = new QListWidgetItem(mission);
// fallback name: replace underscores in mission name with spaces
- QString name = item->text().remove("_");
+ QString name = item->text().replace("_", " ");
// see if we can get a prettier/translated name
name = m_info->value(mission + ".name", name).toString();
@@ -188,13 +184,15 @@
void PageTraining::updateInfo()
{
+ HWDataManager & dataMgr = HWDataManager::instance();
+
if (lstMissions->currentItem())
{
// TODO also use .pngs in userdata folder
- QString thumbFile = datadir->absolutePath() +
- "/Graphics/Missions/Training/" +
+ QString thumbFile = dataMgr.findFileForRead(
+ "Graphics/Missions/Training/" +
lstMissions->currentItem()->data(Qt::UserRole).toString() +
- "@2x.png";
+ "@2x.png");
if (QFile::exists(thumbFile))
btnPreview->setIcon(QIcon(thumbFile));
--- a/QTfrontend/ui/page/pagetraining.h Mon Oct 24 06:10:28 2011 +0200
+++ b/QTfrontend/ui/page/pagetraining.h Mon Oct 24 06:54:46 2011 +0200
@@ -19,8 +19,6 @@
#ifndef PAGE_TRAINING_H
#define PAGE_TRAINING_H
-#include <QDir>
-
#include "AbstractPage.h"
class PageTraining : public AbstractPage
@@ -49,8 +47,6 @@
QListWidget * lstMissions;
QSettings * m_info;
- QStringList scriptList(const QDir & scriptDir) const;
-
private slots:
void startSelected();
--- a/QTfrontend/util/HWDataManager.cpp Mon Oct 24 06:10:28 2011 +0200
+++ b/QTfrontend/util/HWDataManager.cpp Mon Oct 24 06:54:46 2011 +0200
@@ -83,18 +83,25 @@
QString HWDataManager::findFileForRead(
const QString & relativeDataFilePath) const
{
- QString path = userData->absolutePath()+"/"+relativeDataFilePath;
+ QString path;
- if (!QFile::exists(path))
+ if (userData != NULL)
+ path = userData->absolutePath()+"/"+relativeDataFilePath;
+
+ if ((!path.isEmpty()) && (!QFile::exists(path)))
path = defaultData->absolutePath()+"/"+relativeDataFilePath;
return path;
}
-QFile * HWDataManager::findFileForWrite(
+QString HWDataManager::findFileForWrite(
const QString & relativeDataFilePath) const
{
- return new QFile(userData->absolutePath()+"/"+relativeDataFilePath);
+ if (userData != NULL)
+ return userData->absolutePath()+"/"+relativeDataFilePath;
+
+
+ return "";
}
--- a/QTfrontend/util/HWDataManager.h Mon Oct 24 06:10:28 2011 +0200
+++ b/QTfrontend/util/HWDataManager.h Mon Oct 24 06:54:46 2011 +0200
@@ -68,7 +68,7 @@
) const;
/**
- * @brief Returns path for the desires data file.
+ * @brief Returns the path for the desires data file.
*
* Use this method if you want to read an existing data file.
*
@@ -79,15 +79,14 @@
/**
- * @brief Creates a file object for the desired data path and
- * returns a pointer to it.
+ * @brief Returns the path for the data file that is to be written.
*
* Use this method if you want to create or write into a data file.
*
- * @param relativeDataFilePath path to the data file.
- * @return respective <code>QFile</code> pointer.
+ * @param relativeDataFilePath relative path of data file write path.
+ * @return destination of path data file.
*/
- QFile * findFileForWrite(const QString & relativeDataFilePath) const;
+ QString findFileForWrite(const QString & relativeDataFilePath) const;
private: