author | alfadur |
Fri, 09 Aug 2019 20:31:04 +0300 | |
changeset 15306 | 02fa79f62220 |
parent 14874 | 9379ef4fac80 |
child 15447 | 999f82643048 |
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 |
11046 | 3 |
* Copyright (c) 2004-2015 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 |
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
9998
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
6159
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 implementation |
6168 | 22 |
*/ |
23 |
||
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
|
24 |
#include <QMap> |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
25 |
#include <QStringList> |
7258 | 26 |
#include <QStandardItemModel> |
6199
582e85254110
on file save: create parent directories if needed
sheepluva
parents:
6196
diff
changeset
|
27 |
#include <QFileInfo> |
8918
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
28 |
#include <QSettings> |
8920 | 29 |
#include <QColor> |
6199
582e85254110
on file save: create parent directories if needed
sheepluva
parents:
6196
diff
changeset
|
30 |
|
14848
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
31 |
#include <SDL2/SDL.h> |
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
32 |
|
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
33 |
#include "hwconsts.h" |
7260 | 34 |
#include "HWApplication.h" |
35 |
#include "sdlkeys.h" |
|
14848
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
36 |
#include "KeyMap.h" |
12295
ac57d564efce
Add DLC filtering in DataManager.cpp and namegen.cpp
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
37 |
#include "physfs.h" |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
38 |
|
6930 | 39 |
#include "DataManager.h" |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
40 |
|
7258 | 41 |
#include "GameStyleModel.h" |
42 |
#include "HatModel.h" |
|
43 |
#include "MapModel.h" |
|
44 |
#include "ThemeModel.h" |
|
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
45 |
|
6930 | 46 |
DataManager::DataManager() |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
47 |
{ |
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
48 |
m_hatModel = NULL; |
8377 | 49 |
m_staticMapModel = NULL; |
50 |
m_missionMapModel = NULL; |
|
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
51 |
m_themeModel = NULL; |
7258 | 52 |
m_colorsModel = NULL; |
7260 | 53 |
m_bindsModel = NULL; |
10248 | 54 |
m_gameStyleModel = NULL; |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
55 |
} |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
56 |
|
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
57 |
|
6930 | 58 |
DataManager & DataManager::instance() |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
59 |
{ |
6930 | 60 |
static DataManager instance; |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
61 |
return instance; |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
62 |
} |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
63 |
|
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
64 |
|
6930 | 65 |
QStringList DataManager::entryList( |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6199
diff
changeset
|
66 |
const QString & subDirectory, |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6199
diff
changeset
|
67 |
QDir::Filters filters, |
12295
ac57d564efce
Add DLC filtering in DataManager.cpp and namegen.cpp
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
68 |
const QStringList & nameFilters, |
ac57d564efce
Add DLC filtering in DataManager.cpp and namegen.cpp
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
69 |
bool withDLC |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6199
diff
changeset
|
70 |
) const |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
71 |
{ |
7774
27f9b9362f47
Simplify DataManager as physfs partially implements its functions
unc0rr
parents:
7681
diff
changeset
|
72 |
QDir tmpDir(QString("physfs://%1").arg(subDirectory)); |
27f9b9362f47
Simplify DataManager as physfs partially implements its functions
unc0rr
parents:
7681
diff
changeset
|
73 |
QStringList result = tmpDir.entryList(nameFilters, filters); |
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
74 |
|
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
|
75 |
// sort case-insensitive |
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
|
76 |
QMap<QString, QString> sortedFileNames; |
12295
ac57d564efce
Add DLC filtering in DataManager.cpp and namegen.cpp
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
77 |
QString absolutePath = datadir->absolutePath().toLocal8Bit().data(); |
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
|
78 |
foreach ( QString fn, result) |
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
|
79 |
{ |
12295
ac57d564efce
Add DLC filtering in DataManager.cpp and namegen.cpp
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
80 |
// Filter out DLC entries if desired |
ac57d564efce
Add DLC filtering in DataManager.cpp and namegen.cpp
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
81 |
QString realDir = PHYSFS_getRealDir(QString(subDirectory + "/" + fn).toLocal8Bit().data()); |
ac57d564efce
Add DLC filtering in DataManager.cpp and namegen.cpp
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
82 |
if(withDLC || realDir == absolutePath) |
ac57d564efce
Add DLC filtering in DataManager.cpp and namegen.cpp
Wuzzy <almikes@aol.com>
parents:
11046
diff
changeset
|
83 |
sortedFileNames.insert(fn.toLower(), fn); |
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
|
84 |
} |
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
|
85 |
result = sortedFileNames.values(); |
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
|
86 |
|
6159
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
87 |
return result; |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
88 |
} |
c780b8cf4d75
introduce HWDataManager util for transparent access to [user-]data files
sheepluva
parents:
diff
changeset
|
89 |
|
6958 | 90 |
GameStyleModel * DataManager::gameStyleModel() |
91 |
{ |
|
92 |
if (m_gameStyleModel == NULL) { |
|
93 |
m_gameStyleModel = new GameStyleModel(); |
|
94 |
m_gameStyleModel->loadGameStyles(); |
|
95 |
} |
|
96 |
return m_gameStyleModel; |
|
97 |
} |
|
98 |
||
6953
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
99 |
HatModel * DataManager::hatModel() |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
100 |
{ |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
101 |
if (m_hatModel == NULL) { |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
102 |
m_hatModel = new HatModel(); |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
103 |
m_hatModel->loadHats(); |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
104 |
} |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
105 |
return m_hatModel; |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
106 |
} |
4c2dd25630a7
* make HatModel update automatically (also renamed class and files)
sheepluva
parents:
6952
diff
changeset
|
107 |
|
8377 | 108 |
MapModel * DataManager::staticMapModel() |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
6937
diff
changeset
|
109 |
{ |
8377 | 110 |
if (m_staticMapModel == NULL) { |
9744 | 111 |
m_staticMapModel = new MapModel(MapModel::StaticMap, this); |
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
6937
diff
changeset
|
112 |
} |
8377 | 113 |
return m_staticMapModel; |
114 |
} |
|
115 |
||
116 |
MapModel * DataManager::missionMapModel() |
|
117 |
{ |
|
118 |
if (m_missionMapModel == NULL) { |
|
9744 | 119 |
m_missionMapModel = new MapModel(MapModel::MissionMap, this); |
8377 | 120 |
} |
121 |
return m_missionMapModel; |
|
6938
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
6937
diff
changeset
|
122 |
} |
217ed62e872c
MapModel, various cleanups. TODO/FIXME: QComboBox separator not working with custom models
sheepluva
parents:
6937
diff
changeset
|
123 |
|
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
124 |
ThemeModel * DataManager::themeModel() |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
125 |
{ |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
126 |
if (m_themeModel == NULL) { |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
127 |
m_themeModel = new ThemeModel(); |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
128 |
} |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
129 |
return m_themeModel; |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
130 |
} |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6931
diff
changeset
|
131 |
|
7258 | 132 |
QStandardItemModel * DataManager::colorsModel() |
133 |
{ |
|
134 |
if(m_colorsModel == NULL) |
|
135 |
{ |
|
136 |
m_colorsModel = new QStandardItemModel(); |
|
137 |
||
138 |
int i = 0; |
|
139 |
while(colors[i]) |
|
140 |
{ |
|
141 |
QStandardItem * item = new QStandardItem(); |
|
142 |
item->setData(QColor(colors[i])); |
|
143 |
m_colorsModel->appendRow(item); |
|
144 |
++i; |
|
145 |
} |
|
146 |
} |
|
147 |
||
148 |
return m_colorsModel; |
|
149 |
} |
|
150 |
||
7260 | 151 |
QStandardItemModel * DataManager::bindsModel() |
152 |
{ |
|
14848
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
153 |
KeyMap km = KeyMap::instance(); |
7260 | 154 |
if(m_bindsModel == NULL) |
155 |
{ |
|
156 |
m_bindsModel = new QStandardItemModel(); |
|
157 |
||
8346 | 158 |
QStandardItem * firstItem = new QStandardItem(); |
159 |
firstItem->setData(tr("Use Default"), Qt::DisplayRole); |
|
160 |
firstItem->setData("default", Qt::UserRole + 1); |
|
161 |
m_bindsModel->appendRow(firstItem); |
|
162 |
||
7260 | 163 |
for(int j = 0; sdlkeys[j][1][0] != '\0'; j++) |
164 |
{ |
|
165 |
QStandardItem * item = new QStandardItem(); |
|
14532
e1ae6d8e84b0
Allow to leave a control unused (no key binding)
Wuzzy <Wuzzy2@mail.ru>
parents:
13284
diff
changeset
|
166 |
QString keyId = QString(sdlkeys[j][0]); |
14848
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
167 |
QString keyDisplay; |
14867
8bba7492558d
Frontend: Refactor detection of keyboard keys in sdlkeys[]
Wuzzy <Wuzzy2@mail.ru>
parents:
14850
diff
changeset
|
168 |
bool isKeyboard = sdlkeys_iskeyboard[j] == true; |
14848
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
169 |
if (keyId == "none" || (!isKeyboard)) |
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
170 |
keyDisplay = HWApplication::translate("binds (keys)", sdlkeys[j][1]); |
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
171 |
else |
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
172 |
// Get key name with respect to keyboard layout |
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
173 |
keyDisplay = QString(SDL_GetKeyName(SDL_GetKeyFromScancode(km.getScancodeFromKeyname(sdlkeys[j][0])))); |
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
174 |
|
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
175 |
bool kbFallback = keyDisplay.trimmed().isEmpty(); |
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
176 |
if (kbFallback) |
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
177 |
{ |
14873
d17c1a28df17
Frontend controls: Don't show "QWERTY" for F13-F15
Wuzzy <Wuzzy2@mail.ru>
parents:
14867
diff
changeset
|
178 |
keyDisplay = QString(sdlkeys[j][1]); |
d17c1a28df17
Frontend controls: Don't show "QWERTY" for F13-F15
Wuzzy <Wuzzy2@mail.ru>
parents:
14867
diff
changeset
|
179 |
if ((QString(sdlkeys[j][0]) != "f13") && (QString(sdlkeys[j][0]) != "f14") && (QString(sdlkeys[j][0]) != "f15")) |
d17c1a28df17
Frontend controls: Don't show "QWERTY" for F13-F15
Wuzzy <Wuzzy2@mail.ru>
parents:
14867
diff
changeset
|
180 |
{ |
d17c1a28df17
Frontend controls: Don't show "QWERTY" for F13-F15
Wuzzy <Wuzzy2@mail.ru>
parents:
14867
diff
changeset
|
181 |
// If SDL doesn't know a name, show fallback name and a warning |
14874
9379ef4fac80
Frontend controls: Remove hash key
Wuzzy <Wuzzy2@mail.ru>
parents:
14873
diff
changeset
|
182 |
//: Name of QWERTY US keyboard layout |
14873
d17c1a28df17
Frontend controls: Don't show "QWERTY" for F13-F15
Wuzzy <Wuzzy2@mail.ru>
parents:
14867
diff
changeset
|
183 |
keyDisplay = keyDisplay + QString(" ") + HWApplication::translate("binds (keys)", "(QWERTY)"); |
d17c1a28df17
Frontend controls: Don't show "QWERTY" for F13-F15
Wuzzy <Wuzzy2@mail.ru>
parents:
14867
diff
changeset
|
184 |
} |
14848
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
185 |
} |
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
186 |
if (isKeyboard) |
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
187 |
{ |
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
188 |
if (!kbFallback) |
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
189 |
keyDisplay = HWApplication::translate("binds (keys)", keyDisplay.toUtf8().constData()); |
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
190 |
keyDisplay = HWApplication::translate("binds (keys)", "Keyboard") + QString(": ") + keyDisplay; |
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
191 |
} |
bb412d8e435f
Frontend: Fix wrong keyboard key names being displayed with regard to keyboard layout
Wuzzy <Wuzzy2@mail.ru>
parents:
14532
diff
changeset
|
192 |
item->setData(keyDisplay, Qt::DisplayRole); |
7260 | 193 |
item->setData(sdlkeys[j][0], Qt::UserRole + 1); |
194 |
m_bindsModel->appendRow(item); |
|
195 |
} |
|
196 |
} |
|
197 |
||
198 |
return m_bindsModel; |
|
199 |
} |
|
200 |
||
8918
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
201 |
QString DataManager::settingsFileName() |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
202 |
{ |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
203 |
if(m_settingsFileName.isEmpty()) |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
204 |
{ |
13284
b504131f7405
Fix team files and settings not saving properly, and remove FileEngine stuff from DLC
Wuzzy <Wuzzy2@mail.ru>
parents:
12295
diff
changeset
|
205 |
QFile settingsFile(cfgdir->absoluteFilePath("settings.ini")); |
8918
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
206 |
|
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
207 |
if(!settingsFile.exists()) |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
208 |
{ |
13284
b504131f7405
Fix team files and settings not saving properly, and remove FileEngine stuff from DLC
Wuzzy <Wuzzy2@mail.ru>
parents:
12295
diff
changeset
|
209 |
QFile oldSettingsFile(cfgdir->absoluteFilePath("hedgewars.ini")); |
8918
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
210 |
|
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
211 |
settingsFile.open(QFile::WriteOnly); |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
212 |
settingsFile.close(); |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
213 |
|
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
214 |
if(oldSettingsFile.exists()) |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
215 |
{ |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
216 |
QSettings sOld(oldSettingsFile.fileName(), QSettings::IniFormat); |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
217 |
QSettings sNew(settingsFile.fileName(), QSettings::IniFormat); |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
218 |
sNew.setIniCodec("UTF-8"); |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
219 |
|
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
220 |
foreach(const QString & key, sOld.allKeys()) |
8920 | 221 |
{ |
222 |
if(key.startsWith("colors/color")) |
|
223 |
sNew.setValue(key, sOld.value(key).value<QColor>().name()); |
|
224 |
else |
|
225 |
sNew.setValue(key, sOld.value(key)); |
|
226 |
} |
|
8918
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
227 |
} |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
228 |
} |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
229 |
|
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
230 |
m_settingsFileName = settingsFile.fileName(); |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
231 |
} |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
232 |
|
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
233 |
return m_settingsFileName; |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
234 |
} |
512753ea4b1b
Switch to 'settings.ini'. Copies old ini file if necessary on startup.
unc0rr
parents:
8508
diff
changeset
|
235 |
|
9389 | 236 |
QString DataManager::safeFileName(QString fileName) |
237 |
{ |
|
238 |
fileName.replace('\\', '_'); |
|
239 |
fileName.replace('/', '_'); |
|
240 |
fileName.replace(':', '_'); |
|
241 |
||
242 |
return fileName; |
|
243 |
} |
|
244 |
||
6931
86c951cd0f3f
make DataManager a QObject with reload() slot that emits signal updated()
sheepluva
parents:
6930
diff
changeset
|
245 |
void DataManager::reload() |
86c951cd0f3f
make DataManager a QObject with reload() slot that emits signal updated()
sheepluva
parents:
6930
diff
changeset
|
246 |
{ |
7824 | 247 |
// removed for now (also code was a bit unclean, could lead to segfault if |
248 |
// reload() is called before all members are initialized - because currently |
|
249 |
// they are initialized in the getter methods rather than the constructor) |
|
6931
86c951cd0f3f
make DataManager a QObject with reload() slot that emits signal updated()
sheepluva
parents:
6930
diff
changeset
|
250 |
} |
7681 | 251 |
|
252 |
void DataManager::resetColors() |
|
253 |
{ |
|
254 |
for(int i = colorsModel()->rowCount() - 1; i >= 0; --i) |
|
255 |
{ |
|
256 |
m_colorsModel->item(i)->setData(QColor(colors[i])); |
|
257 |
} |
|
258 |
} |
|
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
|
259 |
|
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
|
260 |
bool DataManager::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
|
261 |
{ |
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
|
262 |
QFile tmpfile(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
|
263 |
if (!tmpfile.exists()) |
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
|
264 |
return tmpfile.open(QFile::WriteOnly); |
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
|
265 |
else |
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
|
266 |
return true; |
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
|
267 |
} |