author | Periklis Ntanasis <pntanasis@gmail.com> |
Tue, 27 Aug 2013 02:41:28 +0300 | |
branch | spacecampaign |
changeset 9585 | d079e1cc2806 |
parent 9080 | 9b42757d7e71 |
child 9389 | 3aae70f72126 |
permissions | -rw-r--r-- |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
1 |
/* |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
2 |
* Hedgewars, a free turn based strategy game |
9080 | 3 |
* Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com> |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
4 |
* |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
7 |
* the Free Software Foundation; version 2 of the License |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
8 |
* |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
13 |
* |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
17 |
*/ |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
18 |
|
6168 | 19 |
/** |
6170 | 20 |
* @file |
6930 | 21 |
* @brief DataManager class definition |
6168 | 22 |
*/ |
23 |
||
6930 | 24 |
#ifndef HEDGEWARS_DATAMANAGER_H |
25 |
#define HEDGEWARS_DATAMANAGER_H |
|
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
26 |
|
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
27 |
#include <QDir> |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
28 |
#include <QFile> |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
29 |
#include <QStringList> |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
30 |
|
6958 | 31 |
class GameStyleModel; |
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
32 |
class HatModel; |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
6937
diff
changeset
|
33 |
class MapModel; |
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
34 |
class ThemeModel; |
7258 | 35 |
class QStandardItemModel; |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
36 |
|
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
37 |
/** |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
38 |
* @brief Offers access to the data files of hedgewars. |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
39 |
* |
6160
863d3edf5690
cleaning up some more, also adding a WIP file. changes: hats in the hat selection are now sorted like this: NoHat, Reserved hats (alphabetically), All other hats (alphabeticall)
sheepluva
parents:
6159
diff
changeset
|
40 |
* @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a> |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
41 |
* |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
42 |
* @author sheepluva |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
43 |
* @since 0.9.17 |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
44 |
*/ |
6931
86c951cd0f3f
make DataManager a QObject with reload() slot that emits signal updated()
sheepluva
parents:
6930
diff
changeset
|
45 |
class DataManager: public QObject |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
46 |
{ |
6931
86c951cd0f3f
make DataManager a QObject with reload() slot that emits signal updated()
sheepluva
parents:
6930
diff
changeset
|
47 |
Q_OBJECT |
86c951cd0f3f
make DataManager a QObject with reload() slot that emits signal updated()
sheepluva
parents:
6930
diff
changeset
|
48 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
49 |
public: |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
50 |
/** |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
51 |
* @brief Returns reference to the <i>singleton</i> instance of this class. |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
52 |
* |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
53 |
* @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a> |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
54 |
* |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
55 |
* @return reference to the instance. |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
56 |
*/ |
6930 | 57 |
static DataManager & instance(); |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
58 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
59 |
/** |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
60 |
* @brief Returns a sorted list of data directory entries. |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
61 |
* |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
62 |
* @param subDirectory sub-directory to search. |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
63 |
* @param filters filters for entry type. |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
64 |
* @param nameFilters filters by name patterns. |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
65 |
* @return a sorted list of matches in the subDirectory of data directory. |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
66 |
*/ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
67 |
QStringList entryList(const QString & subDirectory, |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
68 |
QDir::Filters filters = QDir::NoFilter, |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
69 |
const QStringList & nameFilters = QStringList("*") |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
70 |
) const; |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
71 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
72 |
/** |
6958 | 73 |
* @brief Returns pointer to a model of available game styles. |
74 |
* |
|
75 |
* The model is updated automatically on data reload. |
|
76 |
* |
|
77 |
* @return game style model pointer. |
|
78 |
*/ |
|
79 |
GameStyleModel * gameStyleModel(); |
|
80 |
||
81 |
/** |
|
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
82 |
* @brief Returns pointer to a model of available hats. |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
83 |
* |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
84 |
* The model is updated automatically on data reload. |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
85 |
* |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
86 |
* @return hat model pointer. |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
87 |
*/ |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
88 |
HatModel * hatModel(); |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
89 |
|
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
90 |
/** |
8377 | 91 |
* @brief Returns pointer to a model of available static maps. |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
6937
diff
changeset
|
92 |
* |
6948 | 93 |
* The model is updated automatically on data reload. |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
6937
diff
changeset
|
94 |
* |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
6937
diff
changeset
|
95 |
* @return map model pointer. |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
6937
diff
changeset
|
96 |
*/ |
8377 | 97 |
MapModel * staticMapModel(); |
98 |
||
99 |
/** |
|
100 |
* @brief Returns pointer to a model of available mission maps. |
|
101 |
* |
|
102 |
* The model is updated automatically on data reload. |
|
103 |
* |
|
104 |
* @return map model pointer. |
|
105 |
*/ |
|
106 |
MapModel * missionMapModel(); |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
6937
diff
changeset
|
107 |
|
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
6937
diff
changeset
|
108 |
/** |
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
109 |
* @brief Returns pointer to a model of available themes. |
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
110 |
* |
6948 | 111 |
* The model is updated automatically on data reload. |
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
112 |
* |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
6937
diff
changeset
|
113 |
* @return theme model pointer. |
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
114 |
*/ |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
115 |
ThemeModel * themeModel(); |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
116 |
|
7258 | 117 |
QStandardItemModel * colorsModel(); |
7260 | 118 |
QStandardItemModel * bindsModel(); |
7258 | 119 |
|
8918
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
120 |
QString settingsFileName(); |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
121 |
|
8508
f849b7b3af1d
- Ensure that team file exists before saving into it (same fix as for hedgewars.ini, due to bug in Qt)
unc0rr
parents:
8377
diff
changeset
|
122 |
static bool ensureFileExists(const QString & fileName); |
f849b7b3af1d
- Ensure that team file exists before saving into it (same fix as for hedgewars.ini, due to bug in Qt)
unc0rr
parents:
8377
diff
changeset
|
123 |
|
6931
86c951cd0f3f
make DataManager a QObject with reload() slot that emits signal updated()
sheepluva
parents:
6930
diff
changeset
|
124 |
public slots: |
6948 | 125 |
/// Reloads data from storage. |
6931
86c951cd0f3f
make DataManager a QObject with reload() slot that emits signal updated()
sheepluva
parents:
6930
diff
changeset
|
126 |
void reload(); |
7681 | 127 |
void resetColors(); |
6931
86c951cd0f3f
make DataManager a QObject with reload() slot that emits signal updated()
sheepluva
parents:
6930
diff
changeset
|
128 |
|
86c951cd0f3f
make DataManager a QObject with reload() slot that emits signal updated()
sheepluva
parents:
6930
diff
changeset
|
129 |
|
86c951cd0f3f
make DataManager a QObject with reload() slot that emits signal updated()
sheepluva
parents:
6930
diff
changeset
|
130 |
signals: |
6948 | 131 |
/// This signal is emitted after the data has been updated. |
6931
86c951cd0f3f
make DataManager a QObject with reload() slot that emits signal updated()
sheepluva
parents:
6930
diff
changeset
|
132 |
void updated(); |
86c951cd0f3f
make DataManager a QObject with reload() slot that emits signal updated()
sheepluva
parents:
6930
diff
changeset
|
133 |
|
86c951cd0f3f
make DataManager a QObject with reload() slot that emits signal updated()
sheepluva
parents:
6930
diff
changeset
|
134 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
135 |
private: |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
136 |
/** |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
137 |
* @brief Class constructor of the <i>singleton</i>. |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
138 |
* |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
139 |
* Not to be used from outside the class, |
6930 | 140 |
* use the static {@link DataManager::instance()} instead. |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
141 |
* |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
142 |
* @see <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singleton pattern</a> |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6215
diff
changeset
|
143 |
*/ |
6930 | 144 |
DataManager(); |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
145 |
|
6958 | 146 |
GameStyleModel * m_gameStyleModel; ///< game style model instance |
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
147 |
HatModel * m_hatModel; ///< hat model instance |
8377 | 148 |
MapModel * m_staticMapModel; ///< static map model instance |
149 |
MapModel * m_missionMapModel; ///< mission map model instance |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
6937
diff
changeset
|
150 |
ThemeModel * m_themeModel; ///< theme model instance |
7258 | 151 |
QStandardItemModel * m_colorsModel; |
7260 | 152 |
QStandardItemModel * m_bindsModel; |
8918
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
153 |
QString m_settingsFileName; |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
154 |
}; |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
155 |
|
6930 | 156 |
#endif // HEDGEWARS_DATAMANAGER_H |