// take a new player from parser void ClientWindow::slot_player(Player *p, bool cmdplayers) { // insert into ListView QListViewItemIterator lv(ListView_players); QPoint pp(0,0); QListViewItem *topViewItem = ListView_players->itemAt(pp); bool deleted_topViewItem = false; if (p->online) { // check if it's an empty list, i.e. all items deleted before if (cmdplayers && !playerListEmpty) { for (PlayerTableItem *lvi; (lvi = static_cast<PlayerTableItem*>(lv.current()));) { lv++; // compare names if (lvi->text(1) == p->name) { // check if new player info is less than old if (p->info != "??") { // new entry has more info lvi->setText(0, p->info); //p->name, lvi->setText(2, p->rank); lvi->setText(3, p->play_str); lvi->setText(4, p->obs_str); lvi->setText(5, p->idle); //mark, lvi->setText(12, rkToKey(p->rank) + p->name.lower()); if (extUserInfo && myAccount->get_gsname() == IGS) { lvi->setText(7, p->extInfo); lvi->setText(8, p->won); lvi->setText(9, p->lost); lvi->setText(10, p->country); lvi->setText(11, p->nmatch_settings); } lvi->set_nmatchSettings(p); //lvi->nmatch = p->nmatch; lvi->ownRepaint(); } if (p->name == myAccount->acc_name) { qDebug("updating my account info... (1)"); // checkbox open bool b = (p->info.contains('X') == 0); slot_checkbox(0, b); // checkbox looking - don't set if closed if (p->info.contains('!') != 0) // "!" found slot_checkbox(1, true); else if (b) // "!" not found && open slot_checkbox(1, false); // checkbox quiet // NOT CORRECT REPORTED BY SERVER! //b = (p->info.contains('Q') != 0); //slot_checkbox(2, b); // -> WORKAROUND if (p->info.contains('Q') != 0) slot_checkbox(2, true); // get rank to calc handicap when matching myAccount->set_rank(p->rank); } return; } } } else if (!cmdplayers && !myAccount->num_players) { qDebug("player skipped because no init table"); // skip players until initial table has loaded return; } QString mark; // check for watched players if (watch && watch.contains(";" + p->name + ";")) { mark = "W"; // sound for entering - no sound while "who" cmd is executing if (!cmdplayers) qgoif->get_qgo()->playEnterSound(); else if (p->name == myAccount->acc_name) // it's me // - only possible if 'who'/'user' cmd is executing // - I am on the watchlist, however // don't count! myAccount->num_watchedplayers--; myAccount->num_watchedplayers++; } // check for excluded players else if (exclude && exclude.contains(";" + p->name + ";")) { mark = "X"; } // check for open/looking state if (cmdplayers) { if (p->name == myAccount->acc_name) { qDebug("updating my account info...(2)"); // checkbox open bool b = (p->info.contains('X') == 0); slot_checkbox(0, b); // checkbox looking b = (p->info.contains('!') != 0); slot_checkbox(1, b); // checkbox quiet // NOT CORRECT REPORTED BY SERVER! //b = (p->info.contains('Q') != 0); //slot_checkbox(2, b); // -> WORKAROUND if (p->info.contains('Q') != 0) slot_checkbox(2, true); // get rank to calc handicap when matching myAccount->set_rank(p->rank); mark = "M"; } } // from WHO command or {... has connected} if (extUserInfo && myAccount->get_gsname() == IGS) { PlayerTableItem *lv1 = new PlayerTableItem(ListView_players, p->info, p->name, p->rank, p->play_str, p->obs_str, p->idle, mark, p->extInfo, p->won, p->lost, p->country, p->nmatch_settings); lv1->setText(12, rkToKey(p->rank) + p->name.lower()); lv1->set_nmatchSettings(p); } else { PlayerTableItem *lv1 = new PlayerTableItem(ListView_players, p->info, p->name, p->rank, p->play_str, p->obs_str, p->idle, mark); lv1->setText(12, rkToKey(p->rank) + p->name.lower()); lv1->set_nmatchSettings(p); } // increase number of players myAccount->num_players++; statusUsers->setText(" P: " + QString::number(myAccount->num_players) + " / " + QString::number(myAccount->num_watchedplayers) + " "); //if (!cmdplayers) // ListView_players->sort() ; } else { // {... has disconnected} bool found = false; for (QListViewItem *lvi; (lvi = lv.current()) && !found;) { lv++; // compare names if (lvi->text(1) == p->name) { // check if it was a watched player if (lvi->text(6) == "W") { qgoif->get_qgo()->playLeaveSound(); myAccount->num_watchedplayers--; } lv++; if (lvi == topViewItem) // are we trying to delete the 'anchor' of the list viewport ? deleted_topViewItem = true ; delete lvi; found = true;; // decrease number of players myAccount->num_players--; statusUsers->setText(" P: " + QString::number(myAccount->num_players) + " / " + QString::number(myAccount->num_watchedplayers) + " "); } } if (!found) qWarning("disconnected player not found: " + p->name); } if (! deleted_topViewItem) //don't try to refer to a deleted element ... { int ip = topViewItem->itemPos(); ListView_players->setContentsPos(0,ip); } }