author | Wuzzy <Wuzzy2@mail.ru> |
Mon, 03 Sep 2018 05:05:00 +0200 | |
changeset 13751 | 0e8db74ec585 |
parent 13267 | 48b23e6f26d9 |
child 14849 | 8ed0c3761640 |
permissions | -rw-r--r-- |
6948 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
6948 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
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 |
6948 | 17 |
*/ |
18 |
||
19 |
/** |
|
20 |
* @file |
|
21 |
* @brief ThemeModel class implementation |
|
22 |
*/ |
|
5289
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
23 |
|
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8377
diff
changeset
|
24 |
#include "physfs.h" |
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
25 |
#include "ThemeModel.h" |
8464 | 26 |
#include "hwconsts.h" |
5289
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
27 |
|
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
28 |
ThemeModel::ThemeModel(QObject *parent) : |
5289
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
29 |
QAbstractListModel(parent) |
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
30 |
{ |
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
31 |
m_data = QList<QMap<int, QVariant> >(); |
9745 | 32 |
|
33 |
m_themesLoaded = false; |
|
11757
6874644a2d00
in non-local games, don't include DLC-themes/maps/missions during random selection. thanks to unC0Rr for helping me realize that I was stupid in a different way than I thought :P
sheepluva
parents:
11754
diff
changeset
|
34 |
|
6874644a2d00
in non-local games, don't include DLC-themes/maps/missions during random selection. thanks to unC0Rr for helping me realize that I was stupid in a different way than I thought :P
sheepluva
parents:
11754
diff
changeset
|
35 |
m_filteredNoDLC = NULL; |
13248
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
36 |
m_filteredNoHidden = NULL; |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
37 |
m_filteredNoDLCOrHidden = NULL; |
11757
6874644a2d00
in non-local games, don't include DLC-themes/maps/missions during random selection. thanks to unC0Rr for helping me realize that I was stupid in a different way than I thought :P
sheepluva
parents:
11754
diff
changeset
|
38 |
} |
6874644a2d00
in non-local games, don't include DLC-themes/maps/missions during random selection. thanks to unC0Rr for helping me realize that I was stupid in a different way than I thought :P
sheepluva
parents:
11754
diff
changeset
|
39 |
|
13248
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
40 |
// Filters out DLC themes, e.g. themes which do not come by default |
13247
4df9d8cedf7f
ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
11757
diff
changeset
|
41 |
ThemeFilterProxyModel * ThemeModel::withoutDLC() |
11757
6874644a2d00
in non-local games, don't include DLC-themes/maps/missions during random selection. thanks to unC0Rr for helping me realize that I was stupid in a different way than I thought :P
sheepluva
parents:
11754
diff
changeset
|
42 |
{ |
6874644a2d00
in non-local games, don't include DLC-themes/maps/missions during random selection. thanks to unC0Rr for helping me realize that I was stupid in a different way than I thought :P
sheepluva
parents:
11754
diff
changeset
|
43 |
if (m_filteredNoDLC == NULL) |
6874644a2d00
in non-local games, don't include DLC-themes/maps/missions during random selection. thanks to unC0Rr for helping me realize that I was stupid in a different way than I thought :P
sheepluva
parents:
11754
diff
changeset
|
44 |
{ |
13247
4df9d8cedf7f
ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
11757
diff
changeset
|
45 |
m_filteredNoDLC = new ThemeFilterProxyModel(this); |
11757
6874644a2d00
in non-local games, don't include DLC-themes/maps/missions during random selection. thanks to unC0Rr for helping me realize that I was stupid in a different way than I thought :P
sheepluva
parents:
11754
diff
changeset
|
46 |
m_filteredNoDLC->setSourceModel(this); |
13247
4df9d8cedf7f
ThemeModel: Filter themes based on IsDlcRole rather than string-based
Wuzzy <Wuzzy2@mail.ru>
parents:
11757
diff
changeset
|
47 |
m_filteredNoDLC->setFilterDLC(true); |
11757
6874644a2d00
in non-local games, don't include DLC-themes/maps/missions during random selection. thanks to unC0Rr for helping me realize that I was stupid in a different way than I thought :P
sheepluva
parents:
11754
diff
changeset
|
48 |
} |
6874644a2d00
in non-local games, don't include DLC-themes/maps/missions during random selection. thanks to unC0Rr for helping me realize that I was stupid in a different way than I thought :P
sheepluva
parents:
11754
diff
changeset
|
49 |
return m_filteredNoDLC; |
5289
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
50 |
} |
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
51 |
|
13248
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
52 |
// Filters out hidden themes, these are themes which are not supposed to be |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
53 |
// seen by the user. |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
54 |
ThemeFilterProxyModel * ThemeModel::withoutHidden() |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
55 |
{ |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
56 |
if (m_filteredNoHidden == NULL) |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
57 |
{ |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
58 |
m_filteredNoHidden = new ThemeFilterProxyModel(this); |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
59 |
m_filteredNoHidden->setSourceModel(this); |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
60 |
m_filteredNoHidden->setFilterHidden(true); |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
61 |
} |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
62 |
return m_filteredNoHidden; |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
63 |
} |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
64 |
|
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
65 |
// Combination of the two above for convenience |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
66 |
ThemeFilterProxyModel * ThemeModel::withoutDLCOrHidden() |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
67 |
{ |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
68 |
if (m_filteredNoDLCOrHidden == NULL) |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
69 |
{ |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
70 |
m_filteredNoDLCOrHidden = new ThemeFilterProxyModel(this); |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
71 |
m_filteredNoDLCOrHidden->setSourceModel(this); |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
72 |
m_filteredNoDLCOrHidden->setFilterDLC(true); |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
73 |
m_filteredNoDLCOrHidden->setFilterHidden(true); |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
74 |
} |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
75 |
return m_filteredNoDLCOrHidden; |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
76 |
} |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
77 |
|
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
78 |
int ThemeModel::rowCount(const QModelIndex &parent) const |
5289
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
79 |
{ |
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
80 |
if(parent.isValid()) |
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
81 |
return 0; |
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
82 |
else |
9745 | 83 |
{ |
84 |
if(!m_themesLoaded) |
|
85 |
loadThemes(); |
|
5289
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
86 |
return m_data.size(); |
9745 | 87 |
} |
5289
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
88 |
} |
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
89 |
|
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
90 |
|
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
91 |
QVariant ThemeModel::data(const QModelIndex &index, int role) const |
5289
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
92 |
{ |
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
93 |
if(index.column() > 0 || index.row() >= m_data.size()) |
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
94 |
return QVariant(); |
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
95 |
else |
9745 | 96 |
{ |
97 |
if(!m_themesLoaded) |
|
98 |
loadThemes(); |
|
99 |
||
5289
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
100 |
return m_data.at(index.row()).value(role); |
9745 | 101 |
} |
5289
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
102 |
} |
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
103 |
|
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
104 |
|
9745 | 105 |
void ThemeModel::loadThemes() const |
5289
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
106 |
{ |
9815 | 107 |
qDebug("[LAZINESS] ThemeModel::loadThemes()"); |
9745 | 108 |
|
109 |
m_themesLoaded = true; |
|
110 |
||
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
111 |
|
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
112 |
DataManager & datamgr = DataManager::instance(); |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
113 |
|
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
114 |
QStringList themes = |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
115 |
datamgr.entryList("Themes", QDir::AllDirs | QDir::NoDotAndDotDot); |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
116 |
|
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
117 |
m_data.clear(); |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
118 |
|
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
119 |
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
120 |
m_data.reserve(themes.size()); |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
121 |
#endif |
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
122 |
|
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
123 |
foreach (QString theme, themes) |
5289
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
124 |
{ |
13248
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
125 |
QMap<int, QVariant> dataset; |
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
126 |
|
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
127 |
// themes without icon are supposed to be hidden |
8049 | 128 |
QString iconpath = QString("physfs://Themes/%1/icon.png").arg(theme); |
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
129 |
|
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
130 |
if (!QFile::exists(iconpath)) |
13267
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
131 |
{ |
13248
b0022324fb4e
Add IsHiddenRole to ThemeModel for hidden themes
Wuzzy <Wuzzy2@mail.ru>
parents:
13247
diff
changeset
|
132 |
dataset.insert(IsHiddenRole, true); |
13267
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
133 |
} |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
134 |
else |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
135 |
{ |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
136 |
// themes with the key “hidden” in theme.cfg are hidden, too |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
137 |
QFile themeCfgFile(QString("physfs://Themes/%1/theme.cfg").arg(theme)); |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
138 |
if (themeCfgFile.open(QFile::ReadOnly)) |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
139 |
{ |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
140 |
QTextStream stream(&themeCfgFile); |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
141 |
QString line = stream.readLine(); |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
142 |
QString key; |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
143 |
while (!line.isNull()) |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
144 |
{ |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
145 |
key = QString(line); |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
146 |
int equalsPos = line.indexOf('='); |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
147 |
key.truncate(equalsPos - 1); |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
148 |
key = key.simplified(); |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
149 |
if (!line.startsWith(';') && key == "hidden") |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
150 |
{ |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
151 |
dataset.insert(IsHiddenRole, true); |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
152 |
break; |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
153 |
} |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
154 |
line = stream.readLine(); |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
155 |
} |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
156 |
} |
48b23e6f26d9
Add icons to background themes; allow to hide themes explicitly by adding “hidden” key to theme.cfg
Wuzzy <Wuzzy2@mail.ru>
parents:
13252
diff
changeset
|
157 |
} |
5289
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
158 |
|
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8377
diff
changeset
|
159 |
// detect if theme is dlc |
13249
d2b58cf339fe
Show error icon when selected theme is missing
Wuzzy <Wuzzy2@mail.ru>
parents:
13248
diff
changeset
|
160 |
QString themeDir = PHYSFS_getRealDir(QString("Themes/%1").arg(theme).toLocal8Bit().data()); |
8475
f605bc59c603
Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents:
8464
diff
changeset
|
161 |
bool isDLC = !themeDir.startsWith(datadir->absolutePath()); |
f605bc59c603
Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents:
8464
diff
changeset
|
162 |
dataset.insert(IsDlcRole, isDLC); |
8419
d99f46b676b5
Prepends an asterisk on maps, styles, and themes that are DLC. (Resolves issue 515)
dag10
parents:
8377
diff
changeset
|
163 |
|
8377 | 164 |
// set icon path |
8475
f605bc59c603
Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents:
8464
diff
changeset
|
165 |
dataset.insert(IconPathRole, iconpath); |
8377 | 166 |
|
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
167 |
// set name |
8475
f605bc59c603
Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents:
8464
diff
changeset
|
168 |
dataset.insert(ActualNameRole, theme); |
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
169 |
|
8475
f605bc59c603
Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents:
8464
diff
changeset
|
170 |
// set displayed name |
f605bc59c603
Initial theme selection is now random. Theme prompt now has a search input and no longer uses FlowLayout. (Resolves issue 520)
dag10
parents:
8464
diff
changeset
|
171 |
dataset.insert(Qt::DisplayRole, (isDLC ? "*" : "") + theme); |
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
172 |
|
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
173 |
// load and set preview icon |
13252
5200231eb120
Check existance of theme icon before loading it
Wuzzy <Wuzzy2@mail.ru>
parents:
13249
diff
changeset
|
174 |
iconpath = QString("physfs://Themes/%1/icon@2x.png").arg(theme); |
5200231eb120
Check existance of theme icon before loading it
Wuzzy <Wuzzy2@mail.ru>
parents:
13249
diff
changeset
|
175 |
if (QFile::exists(iconpath)) |
5200231eb120
Check existance of theme icon before loading it
Wuzzy <Wuzzy2@mail.ru>
parents:
13249
diff
changeset
|
176 |
{ |
5200231eb120
Check existance of theme icon before loading it
Wuzzy <Wuzzy2@mail.ru>
parents:
13249
diff
changeset
|
177 |
QIcon preview(QString("physfs://Themes/%1/icon@2x.png").arg(theme)); |
5200231eb120
Check existance of theme icon before loading it
Wuzzy <Wuzzy2@mail.ru>
parents:
13249
diff
changeset
|
178 |
dataset.insert(Qt::DecorationRole, preview); |
5200231eb120
Check existance of theme icon before loading it
Wuzzy <Wuzzy2@mail.ru>
parents:
13249
diff
changeset
|
179 |
} |
6937
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
180 |
|
7f77fa908a4e
messing with the theme model a bit (gets now auto-updated after DLC download too)
sheepluva
parents:
6061
diff
changeset
|
181 |
m_data.append(dataset); |
5289
9d18b61bd3eb
- Implement ThemesModel (load theme icons once, store in memory, don't reload from disk every time selection changes)
unc0rr
parents:
diff
changeset
|
182 |
} |
8436
b89aacebb9db
- Also pass unknown cmds to the server when in room
unc0rr
parents:
8419
diff
changeset
|
183 |
} |