author | sheepluva |
Sat, 30 Nov 2013 13:42:14 +0100 | |
changeset 9725 | 68b5d87cfdb0 |
parent 9503 | 8f9b04138456 |
child 9727 | e89ed65f62da |
permissions | -rw-r--r-- |
7725 | 1 |
#include <QModelIndexList> |
2 |
#include <QModelIndex> |
|
3 |
#include <QPainter> |
|
7732 | 4 |
#include <QFile> |
5 |
#include <QTextStream> |
|
7727 | 6 |
#include <QDebug> |
7725 | 7 |
|
7723 | 8 |
#include "playerslistmodel.h" |
7732 | 9 |
#include "hwconsts.h" |
7723 | 10 |
|
11 |
PlayersListModel::PlayersListModel(QObject *parent) : |
|
7725 | 12 |
QAbstractListModel(parent) |
7723 | 13 |
{ |
9503 | 14 |
m_fontInRoom = QFont(); |
15 |
m_fontInRoom.setItalic(true); |
|
7723 | 16 |
} |
17 |
||
7725 | 18 |
|
19 |
int PlayersListModel::rowCount(const QModelIndex &parent) const |
|
20 |
{ |
|
21 |
if(parent.isValid()) |
|
22 |
return 0; |
|
23 |
else |
|
24 |
return m_data.size(); |
|
25 |
} |
|
26 |
||
27 |
||
28 |
QVariant PlayersListModel::data(const QModelIndex &index, int role) const |
|
29 |
{ |
|
7727 | 30 |
if(!index.isValid() || index.row() < 0 || index.row() >= rowCount() || index.column() != 0) |
7725 | 31 |
return QVariant(QVariant::Invalid); |
32 |
||
33 |
return m_data.at(index.row()).value(role); |
|
34 |
} |
|
35 |
||
36 |
||
37 |
bool PlayersListModel::setData(const QModelIndex &index, const QVariant &value, int role) |
|
38 |
{ |
|
39 |
if(!index.isValid() || index.row() < 0 || index.row() >= rowCount() || index.column() != 0) |
|
40 |
return false; |
|
41 |
||
42 |
m_data[index.row()].insert(role, value); |
|
43 |
||
44 |
emit dataChanged(index, index); |
|
45 |
||
46 |
return true; |
|
47 |
} |
|
48 |
||
49 |
||
50 |
bool PlayersListModel::insertRow(int row, const QModelIndex &parent) |
|
51 |
{ |
|
52 |
return insertRows(row, 1, parent); |
|
53 |
} |
|
54 |
||
55 |
||
56 |
bool PlayersListModel::insertRows(int row, int count, const QModelIndex &parent) |
|
57 |
{ |
|
58 |
if(parent.isValid() || row > rowCount() || row < 0 || count < 1) |
|
59 |
return false; |
|
60 |
||
61 |
beginInsertRows(parent, row, row + count - 1); |
|
62 |
||
63 |
for(int i = 0; i < count; ++i) |
|
64 |
m_data.insert(row, DataEntry()); |
|
65 |
||
66 |
endInsertRows(); |
|
67 |
||
68 |
return true; |
|
69 |
} |
|
70 |
||
71 |
||
72 |
bool PlayersListModel::removeRows(int row, int count, const QModelIndex &parent) |
|
73 |
{ |
|
74 |
if(parent.isValid() || row + count > rowCount() || row < 0 || count < 1) |
|
75 |
return false; |
|
76 |
||
77 |
beginRemoveRows(parent, row, row + count - 1); |
|
78 |
||
79 |
for(int i = 0; i < count; ++i) |
|
80 |
m_data.removeAt(row); |
|
81 |
||
82 |
endRemoveRows(); |
|
83 |
||
84 |
return true; |
|
85 |
} |
|
86 |
||
87 |
||
8891
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7842
diff
changeset
|
88 |
void PlayersListModel::addPlayer(const QString & nickname, bool notify) |
7723 | 89 |
{ |
7725 | 90 |
insertRow(rowCount()); |
7723 | 91 |
|
7728 | 92 |
QModelIndex mi = index(rowCount() - 1); |
93 |
setData(mi, nickname); |
|
7725 | 94 |
|
7732 | 95 |
checkFriendIgnore(mi); |
8891
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7842
diff
changeset
|
96 |
|
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7842
diff
changeset
|
97 |
emit nickAddedLobby(nickname, notify); |
7723 | 98 |
} |
7725 | 99 |
|
100 |
||
8891
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7842
diff
changeset
|
101 |
void PlayersListModel::removePlayer(const QString & nickname, const QString &msg) |
7725 | 102 |
{ |
8891
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7842
diff
changeset
|
103 |
if(msg.isEmpty()) |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7842
diff
changeset
|
104 |
emit nickRemovedLobby(nickname); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7842
diff
changeset
|
105 |
else |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7842
diff
changeset
|
106 |
emit nickRemovedLobby(nickname, msg); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7842
diff
changeset
|
107 |
|
7764 | 108 |
QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname, 1, Qt::MatchExactly); |
7725 | 109 |
|
110 |
if(mil.size()) |
|
111 |
removeRow(mil[0].row()); |
|
112 |
} |
|
113 |
||
114 |
||
8891
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7842
diff
changeset
|
115 |
void PlayersListModel::playerJoinedRoom(const QString & nickname, bool notify) |
7731 | 116 |
{ |
7764 | 117 |
QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname, 1, Qt::MatchExactly); |
7731 | 118 |
|
119 |
if(mil.size()) |
|
7764 | 120 |
{ |
7833 | 121 |
setData(mil[0], true, RoomFilterRole); |
7764 | 122 |
updateIcon(mil[0]); |
7833 | 123 |
updateSortData(mil[0]); |
7764 | 124 |
} |
8891
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7842
diff
changeset
|
125 |
|
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7842
diff
changeset
|
126 |
emit nickAdded(nickname, notify); |
7731 | 127 |
} |
128 |
||
129 |
||
130 |
void PlayersListModel::playerLeftRoom(const QString & nickname) |
|
131 |
{ |
|
8891
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7842
diff
changeset
|
132 |
emit nickRemoved(nickname); |
bf67b4d7d7b4
- Better fix to friends joins/quits highlighting problem
unc0rr
parents:
7842
diff
changeset
|
133 |
|
7764 | 134 |
QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname, 1, Qt::MatchExactly); |
7731 | 135 |
|
136 |
if(mil.size()) |
|
7764 | 137 |
{ |
7833 | 138 |
setData(mil[0], false, RoomFilterRole); |
139 |
setData(mil[0], false, RoomAdmin); |
|
140 |
setData(mil[0], false, Ready); |
|
141 |
setData(mil[0], false, InGame); |
|
7764 | 142 |
updateIcon(mil[0]); |
143 |
} |
|
7731 | 144 |
} |
145 |
||
146 |
||
7725 | 147 |
void PlayersListModel::setFlag(const QString &nickname, StateFlag flagType, bool isSet) |
148 |
{ |
|
9725
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
149 |
if(flagType == Friend) |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
150 |
{ |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
151 |
if(isSet) |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
152 |
m_friendsSet.insert(nickname.toLower()); |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
153 |
else |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
154 |
m_friendsSet.remove(nickname.toLower()); |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
155 |
|
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
156 |
saveSet(m_friendsSet, "friends"); |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
157 |
} |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
158 |
else if(flagType == Ignore) |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
159 |
{ |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
160 |
if(isSet) |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
161 |
m_ignoredSet.insert(nickname.toLower()); |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
162 |
else |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
163 |
m_ignoredSet.remove(nickname.toLower()); |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
164 |
|
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
165 |
saveSet(m_ignoredSet, "ignore"); |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
166 |
} |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
167 |
|
7764 | 168 |
QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname, 1, Qt::MatchExactly); |
7725 | 169 |
|
170 |
if(mil.size()) |
|
171 |
{ |
|
7727 | 172 |
setData(mil[0], isSet, flagType); |
7728 | 173 |
|
174 |
if(flagType == Friend || flagType == ServerAdmin |
|
175 |
|| flagType == Ignore || flagType == RoomAdmin) |
|
176 |
updateSortData(mil[0]); |
|
177 |
||
7725 | 178 |
updateIcon(mil[0]); |
179 |
} |
|
180 |
} |
|
181 |
||
182 |
||
7737 | 183 |
bool PlayersListModel::isFlagSet(const QString & nickname, StateFlag flagType) |
184 |
{ |
|
7764 | 185 |
QModelIndexList mil = match(index(0), Qt::DisplayRole, nickname, 1, Qt::MatchExactly); |
7737 | 186 |
|
187 |
if(mil.size()) |
|
188 |
return mil[0].data(flagType).toBool(); |
|
9725
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
189 |
else if(flagType == Friend) |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
190 |
return isFriend(nickname); |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
191 |
else if(flagType == Ignore) |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
192 |
return isIgnored(nickname); |
7737 | 193 |
else |
194 |
return false; |
|
195 |
} |
|
196 |
||
7731 | 197 |
void PlayersListModel::resetRoomFlags() |
198 |
{ |
|
199 |
for(int i = rowCount() - 1; i >= 0; --i) |
|
200 |
{ |
|
201 |
QModelIndex mi = index(i); |
|
202 |
||
7833 | 203 |
if(mi.data(RoomFilterRole).toBool()) |
7731 | 204 |
{ |
7833 | 205 |
setData(mi, false, RoomFilterRole); |
7731 | 206 |
setData(mi, false, RoomAdmin); |
207 |
setData(mi, false, Ready); |
|
7765
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7764
diff
changeset
|
208 |
setData(mi, false, InGame); |
7737 | 209 |
|
210 |
updateSortData(mi); |
|
211 |
updateIcon(mi); |
|
7731 | 212 |
} |
213 |
} |
|
214 |
} |
|
215 |
||
7725 | 216 |
void PlayersListModel::updateIcon(const QModelIndex & index) |
217 |
{ |
|
218 |
quint32 iconNum = 0; |
|
219 |
||
220 |
QList<bool> flags; |
|
221 |
flags |
|
222 |
<< index.data(Ready).toBool() |
|
223 |
<< index.data(ServerAdmin).toBool() |
|
224 |
<< index.data(RoomAdmin).toBool() |
|
225 |
<< index.data(Registered).toBool() |
|
226 |
<< index.data(Friend).toBool() |
|
227 |
<< index.data(Ignore).toBool() |
|
7765
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7764
diff
changeset
|
228 |
<< index.data(InGame).toBool() |
7833 | 229 |
<< index.data(RoomFilterRole).toBool() |
9503 | 230 |
<< index.data(InRoom).toBool() |
7725 | 231 |
; |
232 |
||
233 |
for(int i = flags.size() - 1; i >= 0; --i) |
|
234 |
if(flags[i]) |
|
235 |
iconNum |= 1 << i; |
|
236 |
||
237 |
if(m_icons().contains(iconNum)) |
|
238 |
{ |
|
239 |
setData(index, m_icons().value(iconNum), Qt::DecorationRole); |
|
240 |
} |
|
241 |
else |
|
242 |
{ |
|
243 |
QPixmap result(24, 16); |
|
244 |
result.fill(Qt::transparent); |
|
245 |
||
246 |
QPainter painter(&result); |
|
247 |
||
7833 | 248 |
if(index.data(RoomFilterRole).toBool()) |
7842
d1c0e4341165
- Better fix than the one from rc7f5c3bd7f8c. Now just scrolling back till net/nettype/main page. Not tested aswell.
unc0rr
parents:
7833
diff
changeset
|
249 |
{ |
7765
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7764
diff
changeset
|
250 |
if(index.data(InGame).toBool()) |
7842
d1c0e4341165
- Better fix than the one from rc7f5c3bd7f8c. Now just scrolling back till net/nettype/main page. Not tested aswell.
unc0rr
parents:
7833
diff
changeset
|
251 |
{ |
7765
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7764
diff
changeset
|
252 |
painter.drawPixmap(0, 0, 16, 16, QPixmap(":/res/chat/ingame.png")); |
7842
d1c0e4341165
- Better fix than the one from rc7f5c3bd7f8c. Now just scrolling back till net/nettype/main page. Not tested aswell.
unc0rr
parents:
7833
diff
changeset
|
253 |
} |
7764 | 254 |
else |
7842
d1c0e4341165
- Better fix than the one from rc7f5c3bd7f8c. Now just scrolling back till net/nettype/main page. Not tested aswell.
unc0rr
parents:
7833
diff
changeset
|
255 |
{ |
7765
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7764
diff
changeset
|
256 |
if(index.data(Ready).toBool()) |
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7764
diff
changeset
|
257 |
painter.drawPixmap(0, 0, 16, 16, QPixmap(":/res/chat/lamp.png")); |
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7764
diff
changeset
|
258 |
else |
1e162c1d6dc7
'In game' client flag, both server and frontend support
unc0rr
parents:
7764
diff
changeset
|
259 |
painter.drawPixmap(0, 0, 16, 16, QPixmap(":/res/chat/lamp_off.png")); |
7842
d1c0e4341165
- Better fix than the one from rc7f5c3bd7f8c. Now just scrolling back till net/nettype/main page. Not tested aswell.
unc0rr
parents:
7833
diff
changeset
|
260 |
} |
9503 | 261 |
} else |
262 |
{ // we're in lobby |
|
263 |
if(!index.data(InRoom).toBool()) |
|
264 |
painter.drawPixmap(0, 0, 16, 16, QPixmap(":/res/Flake.png")); |
|
7842
d1c0e4341165
- Better fix than the one from rc7f5c3bd7f8c. Now just scrolling back till net/nettype/main page. Not tested aswell.
unc0rr
parents:
7833
diff
changeset
|
265 |
} |
7725 | 266 |
|
267 |
QString mainIconName(":/res/chat/"); |
|
268 |
||
9503 | 269 |
if(index.data(ServerAdmin).toBool()) |
7725 | 270 |
mainIconName += "serveradmin"; |
271 |
else |
|
9503 | 272 |
{ |
273 |
if(index.data(RoomAdmin).toBool()) |
|
274 |
mainIconName += "roomadmin"; |
|
275 |
else |
|
276 |
mainIconName += "hedgehog"; |
|
277 |
||
278 |
if(index.data(Contributor).toBool()) |
|
279 |
mainIconName += "contributor"; |
|
280 |
} |
|
7725 | 281 |
|
282 |
if(!index.data(Registered).toBool()) |
|
283 |
mainIconName += "_gray"; |
|
284 |
||
285 |
painter.drawPixmap(8, 0, 16, 16, QPixmap(mainIconName + ".png")); |
|
286 |
||
287 |
if(index.data(Ignore).toBool()) |
|
288 |
painter.drawPixmap(8, 0, 16, 16, QPixmap(":/res/chat/ignore.png")); |
|
289 |
else |
|
290 |
if(index.data(Friend).toBool()) |
|
291 |
painter.drawPixmap(8, 0, 16, 16, QPixmap(":/res/chat/friend.png")); |
|
292 |
||
293 |
painter.end(); |
|
294 |
||
295 |
QIcon icon(result); |
|
296 |
||
297 |
setData(index, icon, Qt::DecorationRole); |
|
298 |
m_icons().insert(iconNum, icon); |
|
299 |
} |
|
300 |
||
301 |
if(index.data(Ignore).toBool()) |
|
302 |
setData(index, Qt::gray, Qt::ForegroundRole); |
|
303 |
else |
|
304 |
if(index.data(Friend).toBool()) |
|
305 |
setData(index, Qt::green, Qt::ForegroundRole); |
|
306 |
else |
|
307 |
setData(index, QBrush(QColor(0xff, 0xcc, 0x00)), Qt::ForegroundRole); |
|
308 |
} |
|
309 |
||
310 |
||
311 |
QHash<quint32, QIcon> & PlayersListModel::m_icons() |
|
312 |
{ |
|
313 |
static QHash<quint32, QIcon> iconsCache; |
|
314 |
||
315 |
return iconsCache; |
|
316 |
} |
|
7728 | 317 |
|
7732 | 318 |
|
7728 | 319 |
void PlayersListModel::updateSortData(const QModelIndex & index) |
320 |
{ |
|
7744
75e1d0c0ba72
- Nicks starting from not-letter char go to bottom of the list
unc0rr
parents:
7737
diff
changeset
|
321 |
QString result = QString("%1%2%3%4%5%6") |
75e1d0c0ba72
- Nicks starting from not-letter char go to bottom of the list
unc0rr
parents:
7737
diff
changeset
|
322 |
// room admins go first, then server admins, then friends |
7728 | 323 |
.arg(1 - index.data(RoomAdmin).toInt()) |
324 |
.arg(1 - index.data(ServerAdmin).toInt()) |
|
325 |
.arg(1 - index.data(Friend).toInt()) |
|
7744
75e1d0c0ba72
- Nicks starting from not-letter char go to bottom of the list
unc0rr
parents:
7737
diff
changeset
|
326 |
// ignored at bottom |
7728 | 327 |
.arg(index.data(Ignore).toInt()) |
7744
75e1d0c0ba72
- Nicks starting from not-letter char go to bottom of the list
unc0rr
parents:
7737
diff
changeset
|
328 |
// keep nicknames starting from non-letter character at bottom within group |
75e1d0c0ba72
- Nicks starting from not-letter char go to bottom of the list
unc0rr
parents:
7737
diff
changeset
|
329 |
// assume there are no empty nicks in list |
75e1d0c0ba72
- Nicks starting from not-letter char go to bottom of the list
unc0rr
parents:
7737
diff
changeset
|
330 |
.arg(index.data(Qt::DisplayRole).toString().at(0).isLetter() ? 0 : 1) |
75e1d0c0ba72
- Nicks starting from not-letter char go to bottom of the list
unc0rr
parents:
7737
diff
changeset
|
331 |
// sort ignoring case |
7728 | 332 |
.arg(index.data(Qt::DisplayRole).toString().toLower()) |
333 |
; |
|
334 |
||
335 |
setData(index, result, SortRole); |
|
336 |
} |
|
7732 | 337 |
|
338 |
||
339 |
void PlayersListModel::setNickname(const QString &nickname) |
|
340 |
{ |
|
341 |
m_nickname = nickname; |
|
342 |
||
343 |
loadSet(m_friendsSet, "friends"); |
|
344 |
loadSet(m_ignoredSet, "ignore"); |
|
345 |
||
346 |
for(int i = rowCount() - 1; i >= 0; --i) |
|
347 |
checkFriendIgnore(index(i)); |
|
348 |
} |
|
349 |
||
9725
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
350 |
bool PlayersListModel::isFriend(const QString & nickname) |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
351 |
{ |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
352 |
return m_friendsSet.contains(nickname.toLower()); |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
353 |
} |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
354 |
|
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
355 |
bool PlayersListModel::isIgnored(const QString & nickname) |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
356 |
{ |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
357 |
return m_ignoredSet.contains(nickname.toLower()); |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
358 |
} |
7732 | 359 |
|
360 |
void PlayersListModel::checkFriendIgnore(const QModelIndex &mi) |
|
361 |
{ |
|
9725
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
362 |
setData(mi, isFriend(mi.data().toString()), Friend); |
68b5d87cfdb0
regression fix: reallow offline players to be added to friendslist/ignore list
sheepluva
parents:
9503
diff
changeset
|
363 |
setData(mi, isIgnored(mi.data().toString()), Ignore); |
7732 | 364 |
|
365 |
updateIcon(mi); |
|
7744
75e1d0c0ba72
- Nicks starting from not-letter char go to bottom of the list
unc0rr
parents:
7737
diff
changeset
|
366 |
updateSortData(mi); |
7732 | 367 |
} |
368 |
||
369 |
void PlayersListModel::loadSet(QSet<QString> & set, const QString & suffix) |
|
370 |
{ |
|
371 |
set.clear(); |
|
372 |
||
373 |
QString fileName = QString("%1/%2_%3.txt").arg(cfgdir->absolutePath(), m_nickname.toLower(), suffix); |
|
374 |
||
375 |
QFile txt(fileName); |
|
376 |
if(!txt.open(QIODevice::ReadOnly)) |
|
377 |
return; |
|
378 |
||
379 |
QTextStream stream(&txt); |
|
380 |
stream.setCodec("UTF-8"); |
|
381 |
||
382 |
while(!stream.atEnd()) |
|
383 |
{ |
|
384 |
QString str = stream.readLine(); |
|
385 |
if(str.startsWith(";") || str.isEmpty()) |
|
386 |
continue; |
|
387 |
||
388 |
set.insert(str.trimmed()); |
|
389 |
} |
|
390 |
||
391 |
txt.close(); |
|
392 |
} |
|
393 |
||
394 |
void PlayersListModel::saveSet(const QSet<QString> & set, const QString & suffix) |
|
395 |
{ |
|
7737 | 396 |
qDebug("saving set"); |
397 |
||
7732 | 398 |
QString fileName = QString("%1/%2_%3.txt").arg(cfgdir->absolutePath(), m_nickname.toLower(), suffix); |
399 |
||
400 |
QFile txt(fileName); |
|
401 |
||
402 |
// list empty? => rather have no file for the list than an empty one |
|
403 |
if (set.isEmpty()) |
|
404 |
{ |
|
405 |
if (txt.exists()) |
|
406 |
{ |
|
407 |
// try to remove file, if successful we're done here. |
|
408 |
if (txt.remove()) |
|
409 |
return; |
|
410 |
} |
|
411 |
else |
|
412 |
// there is no file |
|
413 |
return; |
|
414 |
} |
|
415 |
||
416 |
if(!txt.open(QIODevice::WriteOnly | QIODevice::Truncate)) |
|
417 |
return; |
|
418 |
||
419 |
QTextStream stream(&txt); |
|
420 |
stream.setCodec("UTF-8"); |
|
421 |
||
422 |
stream << "; this list is used by Hedgewars - do not edit it unless you know what you're doing!" << endl; |
|
423 |
||
424 |
foreach(const QString & nick, set.values()) |
|
425 |
stream << nick << endl; |
|
426 |
||
427 |
txt.close(); |
|
428 |
} |