23 #include "serverlistrowhandler.h" 24 #include "serverlistcolumn.h" 25 #include "serverlistmodel.h" 26 #include "configuration/doomseekerconfig.h" 27 #include "gui/helpers/playersdiagram.h" 28 #include "gui/widgets/serverlistview.h" 29 #include "gui/dockBuddiesList.h" 30 #include "gui/mainwindow.h" 31 #include "gui/serverlist.h" 32 #include "ip2c/ip2c.h" 33 #include "serverapi/playerslist.h" 34 #include "serverapi/server.h" 36 #include "application.h" 42 DClass<ServerListRowHandler>
51 int rowIndex, const ServerPtr &server)
52 : model(parentModel), row(rowIndex)
57 ServerListRowHandler::ServerListRowHandler(
ServerListModel* parentModel,
int rowIndex)
58 : model(parentModel), row(rowIndex)
60 d->server = serverFromList(parentModel, rowIndex);
63 ServerListRowHandler::~ServerListRowHandler()
69 for (
int i = 0; i < NUM_SERVERLIST_COLUMNS; ++i)
71 if(!ServerListColumns::isColumnVital(i))
78 void ServerListRowHandler::emptyItem(QStandardItem* item)
80 item->setData(
"", Qt::DisplayRole);
81 item->setData(QVariant(), Qt::DecorationRole);
82 item->setData(QVariant(), DTSort);
85 QStringList ServerListRowHandler::extractValidGameCVarNames(
const QList<GameCVar> &cvars)
88 foreach (
const GameCVar &cvar, cvars)
92 result << cvar.
name();
98 void ServerListRowHandler::fillAddressColumn()
100 QStandardItem* pItem = item(IDAddress);
101 fillItem(pItem, d->server->address(), d->server->hostName() );
104 void ServerListRowHandler::fillItem(QStandardItem* item,
const QString& str)
106 QString strLowcase = str.toLower();
107 item->setData(str, Qt::DisplayRole);
108 item->setData(strLowcase, DTSort);
111 void ServerListRowHandler::fillItem(QStandardItem* item,
int sort,
const QString& str)
116 item->setData(sort, DTSort);
119 void ServerListRowHandler::fillItem(QStandardItem* item,
int num)
123 item->setData(var, Qt::DisplayRole);
124 item->setData(var, DTSort);
127 void ServerListRowHandler::fillItem(QStandardItem* item,
const QHostAddress& addr,
const QString& actualDisplay)
129 QVariant var = addr.toIPv4Address();
131 if (actualDisplay.isEmpty())
133 item->setData(addr.toString(), Qt::DisplayRole);
137 item->setData(actualDisplay, Qt::DisplayRole);
139 item->setData(var, DTSort);
142 void ServerListRowHandler::fillItem(QStandardItem* item,
const QString& sort,
const QPixmap& icon)
144 item->setIcon(QIcon(icon));
145 item->setData(sort, DTSort);
148 void ServerListRowHandler::fillItem(QStandardItem* item,
int sort,
const QPixmap& image)
150 item->setData(image, Qt::DecorationRole);
151 item->setData(sort, DTSort);
154 void ServerListRowHandler::fillPlayerColumn()
156 QStandardItem* pItem = item(IDPlayers);
158 int style = gConfig.doomseeker.slotStyle;
159 bool botsAreNotPlayers = gConfig.doomseeker.bBotsAreNotPlayers;
164 if (botsAreNotPlayers)
166 sortValue = players.numClientsWithoutBots();
173 if(style != NUM_SLOTSTYLES)
179 fillItem(pItem, sortValue, QString(
"%1/%2").arg(players.
numClients())
180 .arg(d->server->numTotalSlots()));
184 pItem->setData(QVariant(QVariant::Invalid), style == NUM_SLOTSTYLES ? Qt::DecorationRole : Qt::DisplayRole);
185 pItem->setData(style == NUM_SLOTSTYLES ? 0 : USERROLE_RIGHTALIGNDECORATION, Qt::UserRole);
188 void ServerListRowHandler::fillPortIconColumn()
190 QStandardItem* pItem = item(IDPort);
191 QPixmap icon = d->server->icon();
192 if(d->server->isKnown())
194 if(d->server->isLockedAnywhere())
196 QPainter iconPainter(&icon);
197 iconPainter.drawPixmap(0, 0, QPixmap(
":/locked.png"));
200 else if(d->server->isSecure())
202 QPainter iconPainter(&icon);
203 iconPainter.drawPixmap(0, 0, QPixmap(
":/shield.png"));
208 if (d->server->isTestingServer())
210 QPainter iconPainter(&icon);
211 iconPainter.drawPixmap(0, 0, QPixmap(
":/t.png"));
215 fillItem(pItem, d->server->metaObject()->className(), icon);
218 void ServerListRowHandler::fillServerPointerColumn()
220 QStandardItem* pItem = item(IDHiddenServerPointer);
221 QVariant savePointer = qVariantFromValue(d->server);
222 pItem->setData(savePointer, DTPointerToServerStructure);
225 QStandardItem* ServerListRowHandler::item(
int columnIndex)
227 return model->item(row, columnIndex);
230 void ServerListRowHandler::redraw()
239 ServerPtr ServerListRowHandler::server()
244 void ServerListRowHandler::setBackgroundColor()
247 if (d->server->isCustom())
249 color = gConfig.doomseeker.customServersColor;
251 else if (d->server->isLan())
253 color = gConfig.doomseeker.lanServersColor;
255 else if (gApp->mainWindow()->buddiesList()->hasBuddy(d->server))
257 if (gConfig.doomseeker.bMarkServersWithBuddies)
259 color = gConfig.doomseeker.buddyServersColor;
263 for (
int column = 0; column < NUM_SERVERLIST_COLUMNS; ++column)
265 QBrush brush = !color.isEmpty()
266 ? QBrush(QColor(color))
268 QStandardItem* pItem = item(column);
269 pItem->setBackground(brush);
273 void ServerListRowHandler::setBad()
275 QStandardItem* qstdItem;
279 qstdItem = item(IDServerName);
280 fillItem(qstdItem, tr(
"<ERROR>"));
282 qstdItem = item(IDHiddenGroup);
283 fillItem(qstdItem, SGBad);
286 void ServerListRowHandler::setBanned()
288 QStandardItem* qstdItem;
292 qstdItem = item(IDServerName);
293 fillItem(qstdItem, tr(
"You are banned from this server!"));
295 qstdItem = item(IDHiddenGroup);
296 fillItem(qstdItem, SGBanned);
299 void ServerListRowHandler::setCountryFlag()
301 QStandardItem* pItem = item(IDServerName);
303 if (!IP2C::instance()->isDataAccessLocked())
306 if (countryInfo.isValid())
308 QPixmap flag = *countryInfo.flag;
309 pItem->setIcon(flag);
314 void ServerListRowHandler::setFirstQuery()
316 QStandardItem* qstdItem = item(IDHiddenGroup);
317 fillItem(qstdItem, SGFirstQuery);
320 void ServerListRowHandler::setGood()
322 QStandardItem* qstdItem;
327 qstdItem = item(IDPing);
328 fillItem(qstdItem, d->server->ping());
330 qstdItem = item(IDServerName);
331 fillItem(qstdItem, d->server->name());
333 qstdItem = item(IDIwad);
334 fillItem(qstdItem, d->server->iwad());
336 qstdItem = item(IDMap);
337 fillItem(qstdItem, d->server->map());
340 foreach(
const PWad &wad, d->server->wads())
344 strTmp += QString(
"[%1] ").arg(wad.
name());
348 strTmp += wad.
name() +
" ";
352 qstdItem = item(IDWads);
353 fillItem(qstdItem, strTmp);
355 qstdItem = item(IDGametype);
356 QString fullGameModeName = d->server->gameMode().name();
357 QStringList modifierNames = extractValidGameCVarNames(d->server->modifiers());
358 if (!modifierNames.isEmpty())
360 fullGameModeName += QString(
" (%1)").arg(modifierNames.join(
", "));
362 fillItem(qstdItem, fullGameModeName);
364 qstdItem = item(IDHiddenGroup);
365 fillItem(qstdItem, SGNormal);
368 void ServerListRowHandler::setRefreshing()
370 QStandardItem* qstdItem = item(IDServerName);
371 qstdItem->setText(tr(
"<REFRESHING>"));
374 void ServerListRowHandler::setTimeout()
376 QStandardItem* qstdItem;
380 qstdItem = item(IDServerName);
381 fillItem(qstdItem, tr(
"<NO RESPONSE>"));
383 qstdItem = item(IDHiddenGroup);
384 fillItem(qstdItem, SGTimeout);
387 void ServerListRowHandler::setWait()
389 QStandardItem* qstdItem;
393 qstdItem = item(IDServerName);
394 fillItem(qstdItem, tr(
"<Refreshed too soon, wait a while and try again>") );
396 qstdItem = item(IDHiddenGroup);
397 fillItem(qstdItem, SGWait);
400 ServerPtr ServerListRowHandler::serverFromList(
const ServerListModel* parentModel,
int rowIndex)
402 QStandardItem* pItem = parentModel->item(rowIndex, IDHiddenServerPointer);
403 QVariant pointer = pItem->data(DTPointerToServerStructure);
404 if (!pointer.isValid())
408 return pointer.value<ServerPtr>();
411 int ServerListRowHandler::updateServer()
413 fillServerPointerColumn();
414 fillPortIconColumn();
417 switch(d->server->lastResponse())
432 if (d->server->isKnown())
448 if (d->server->isRefreshing())
455 gLog << tr(
"Unkown server response (%1): %2:%3").arg(d->server->lastResponse())
456 .arg(d->server->address().toString()).arg(d->server->port());
460 setBackgroundColor();
const QString & name() const
Nice name to display to user in Create Game dialog and in other widgets.
IP2CCountryInfo obtainCountryInfo(unsigned int ipaddress)
void clearNonVitalFields()
bool isValid() const
'Null' objects are invalid.
Player is banned from that server.
"Dummy" response for servers that weren't refreshed yet.
Response from the server was erroreneous.
Response was parsed properly and Server information is available.
Flag and name of the country.
bool isOptional() const
Is this WAD required to join the server?
Server didn't respond at all.
int numClients() const
Overall number of people and bots on the server.
A general game setting or variable (like fraglimit).
Server responded with "wait", may happen when we refresh too quickly.
const QString & name() const
File name of the WAD.