void MainWindow::updateServerList(CatchChallenger::Api_client_real *senderObject) { //do the grouping for characterGroup count { serverByCharacterGroup.clear(); int index=0; int serverByCharacterGroupTempIndexToDisplay=1; while(index<serverOrdenedList.size()) { const CatchChallenger::ServerFromPoolForDisplay &server=*serverOrdenedList.at(index); if(serverByCharacterGroup.contains(server.charactersGroupIndex)) serverByCharacterGroup[server.charactersGroupIndex].first++; else { serverByCharacterGroup[server.charactersGroupIndex].first=1; serverByCharacterGroup[server.charactersGroupIndex].second=serverByCharacterGroupTempIndexToDisplay; serverByCharacterGroupTempIndexToDisplay++; } index++; } } //clear and determine what kind of view ui->serverList->clear(); CatchChallenger::LogicialGroup logicialGroup=senderObject->getLogicialGroup(); bool fullView=true; if(serverOrdenedList.size()>10) fullView=false; const uint64_t ¤t__date=QDateTime::currentDateTime().toTime_t(); addToServerList(logicialGroup,ui->serverList->invisibleRootItem(),current__date,fullView); ui->serverList->expandAll(); }
void ConnectionDialog::on_buttonBox_accepted() { bool ok = 0; int port = ui->portEdit->text().toInt(&ok); if ( !ok || port < 0 || port > 65535 ) port = 0; serverURL = ui->urlEdit->text(); serverPort = (quint16)port; userNick = ui->nickEdit->text(); // now add to server list and make it first QString str; str.sprintf("%d", (int)serverPort); addToServerList( serverURL + ':' + str ); }
void MainWindow::addToServerList(CatchChallenger::LogicialGroup &logicialGroup, QTreeWidgetItem *item, const uint64_t ¤tDate, const bool &fullView) { item->setText(0,logicialGroup.name); { //to order the group QStringList keys=logicialGroup.logicialGroupList.keys(); keys.sort(); //list the group int index=0; while(index<keys.size()) { QTreeWidgetItem * const itemGroup=new QTreeWidgetItem(item); addToServerList(logicialGroup.logicialGroupList[keys.value(index)],itemGroup,currentDate,fullView); index++; } } { qSort(logicialGroup.servers); //list the server int index=0; while(index<logicialGroup.servers.size()) { const CatchChallenger::ServerFromPoolForDisplay &server=logicialGroup.servers.at(index); QTreeWidgetItem *itemServer=new QTreeWidgetItem(item); QString text; QString groupText; if(serverByCharacterGroup.size()>1) groupText=QStringLiteral(" (%1)").arg(serverByCharacterGroup.value(server.charactersGroupIndex).second); QString name=server.name; if(name.isEmpty()) name=tr("Default server"); if(fullView) { text=name+groupText; if(server.playedTime>0) { if(!server.description.isEmpty()) text+=" "+tr("%1 played").arg(CatchChallenger::FacilityLibClient::timeToString(server.playedTime)); else text+="\n"+tr("%1 played").arg(CatchChallenger::FacilityLibClient::timeToString(server.playedTime)); } if(!server.description.isEmpty()) text+="\n"+server.description; } else { if(server.description.isEmpty()) text=name+groupText; else text=name+groupText+" - "+server.description; } itemServer->setText(0,text); //do the icon here if(server.playedTime>5*365*24*3600) itemServer->setToolTip(0,tr("Played time greater than 5y, bug?")); else if(server.lastConnect>0 && server.lastConnect<1420070400) itemServer->setToolTip(0,tr("Played before 2015, bug?")); else if(server.maxPlayer<=65533 && (server.maxPlayer<server.currentPlayer || server.maxPlayer==0)) { if(server.maxPlayer<server.currentPlayer) itemServer->setToolTip(0,tr("maxPlayer<currentPlayer")); else itemServer->setToolTip(0,tr("maxPlayer==0")); } if(server.maxPlayer<=65533) itemServer->setText(1,QStringLiteral("%1/%2").arg(server.currentPlayer).arg(server.maxPlayer)); itemServer->setData(99,99,server.serverOrdenedListIndex); index++; } } }